Weglot Translate – Translate your WP website - Version 1.6

Version Description

  • Add Freemius
  • Refactor code
  • Replace api ur
  • Add several attributes to translations
Download this release

Release Info

Developer remyb92
Plugin Icon 128x128 Weglot Translate – Translate your WP website
Version 1.6
Comparing to
See all releases

Code changes from version 1.5 to 1.6

Files changed (102) hide show
  1. WGUtils.php +174 -175
  2. WeglotPHPClient/src/Client.php +363 -291
  3. WeglotPHPClient/src/WeglotException.php +2 -2
  4. WeglotPHPClient/weglot.php +1 -1
  5. WeglotWidget.php +23 -20
  6. freemius/LICENSE.txt +674 -0
  7. freemius/README.md +253 -0
  8. freemius/assets/css/admin/account.css +1 -0
  9. freemius/assets/css/admin/add-ons.css +2 -0
  10. freemius/assets/css/admin/checkout.css +1 -0
  11. freemius/assets/css/admin/common.css +2 -0
  12. freemius/assets/css/admin/connect.css +1 -0
  13. freemius/assets/css/admin/deactivation-feedback.css +1 -0
  14. freemius/assets/css/admin/debug.css +1 -0
  15. freemius/assets/css/admin/dialog-boxes.css +2 -0
  16. freemius/assets/css/admin/license-activation.css +1 -0
  17. freemius/assets/css/customizer.css +1 -0
  18. freemius/assets/img/plugin-icon.png +0 -0
  19. freemius/assets/img/theme-icon.png +0 -0
  20. freemius/assets/index.php +3 -0
  21. freemius/assets/js/nojquery.ba-postmessage.js +140 -0
  22. freemius/assets/js/nojquery.ba-postmessage.min.js +12 -0
  23. freemius/assets/js/postmessage.js +135 -0
  24. freemius/assets/scss/_colors.scss +65 -0
  25. freemius/assets/scss/_functions.scss +0 -0
  26. freemius/assets/scss/_load.scss +4 -0
  27. freemius/assets/scss/_mixins.scss +283 -0
  28. freemius/assets/scss/_start.scss +4 -0
  29. freemius/assets/scss/_vars.scss +6 -0
  30. freemius/assets/scss/admin/_ajax-loader.scss +49 -0
  31. freemius/assets/scss/admin/_auto-install.scss +33 -0
  32. freemius/assets/scss/admin/_deactivation-feedback.scss +55 -0
  33. freemius/assets/scss/admin/_license-activation.scss +7 -0
  34. freemius/assets/scss/admin/_license-key-resend.scss +68 -0
  35. freemius/assets/scss/admin/_modal-common.scss +186 -0
  36. freemius/assets/scss/admin/_themes.scss +21 -0
  37. freemius/assets/scss/admin/account.scss +256 -0
  38. freemius/assets/scss/admin/add-ons.scss +449 -0
  39. freemius/assets/scss/admin/checkout.scss +5 -0
  40. freemius/assets/scss/admin/common.scss +218 -0
  41. freemius/assets/scss/admin/connect.scss +520 -0
  42. freemius/assets/scss/admin/debug.scss +135 -0
  43. freemius/assets/scss/admin/dialog-boxes.scss +7 -0
  44. freemius/assets/scss/customizer.scss +125 -0
  45. freemius/config.php +328 -0
  46. freemius/includes/class-freemius-abstract.php +597 -0
  47. freemius/includes/class-freemius.php +13647 -0
  48. freemius/includes/class-fs-api.php +558 -0
  49. freemius/includes/class-fs-logger.php +688 -0
  50. freemius/includes/class-fs-plugin-updater.php +714 -0
  51. freemius/includes/class-fs-security.php +85 -0
  52. freemius/includes/customizer/class-fs-customizer-support-section.php +102 -0
  53. freemius/includes/customizer/class-fs-customizer-upsell-control.php +157 -0
  54. freemius/includes/debug/class-fs-debug-bar-panel.php +64 -0
  55. freemius/includes/debug/debug-bar-start.php +52 -0
  56. freemius/includes/debug/index.php +3 -0
  57. freemius/includes/entities/class-fs-billing.php +95 -0
  58. freemius/includes/entities/class-fs-entity.php +149 -0
  59. freemius/includes/entities/class-fs-payment.php +94 -0
  60. freemius/includes/entities/class-fs-plugin-info.php +34 -0
  61. freemius/includes/entities/class-fs-plugin-license.php +224 -0
  62. freemius/includes/entities/class-fs-plugin-plan.php +145 -0
  63. freemius/includes/entities/class-fs-plugin-tag.php +24 -0
  64. freemius/includes/entities/class-fs-plugin.php +96 -0
  65. freemius/includes/entities/class-fs-pricing.php +141 -0
  66. freemius/includes/entities/class-fs-scope-entity.php +29 -0
  67. freemius/includes/entities/class-fs-site.php +148 -0
  68. freemius/includes/entities/class-fs-subscription.php +125 -0
  69. freemius/includes/entities/class-fs-user.php +62 -0
  70. freemius/includes/entities/index.php +3 -0
  71. freemius/includes/fs-core-functions.php +674 -0
  72. freemius/includes/fs-essential-functions.php +494 -0
  73. freemius/includes/fs-plugin-info-dialog.php +948 -0
  74. freemius/includes/i18n.php +549 -0
  75. freemius/includes/index.php +3 -0
  76. freemius/includes/l10n.php +268 -0
  77. freemius/includes/managers/class-fs-admin-menu-manager.php +849 -0
  78. freemius/includes/managers/class-fs-admin-notice-manager.php +324 -0
  79. freemius/includes/managers/class-fs-cache-manager.php +280 -0
  80. freemius/includes/managers/class-fs-key-value-storage.php +328 -0
  81. freemius/includes/managers/class-fs-license-manager.php +104 -0
  82. freemius/includes/managers/class-fs-option-manager.php +302 -0
  83. freemius/includes/managers/class-fs-plan-manager.php +162 -0
  84. freemius/includes/managers/class-fs-plugin-manager.php +220 -0
  85. freemius/includes/managers/index.php +3 -0
  86. freemius/includes/sdk/Exceptions/ArgumentNotExistException.php +9 -0
  87. freemius/includes/sdk/Exceptions/EmptyArgumentException.php +9 -0
  88. freemius/includes/sdk/Exceptions/Exception.php +74 -0
  89. freemius/includes/sdk/Exceptions/InvalidArgumentException.php +8 -0
  90. freemius/includes/sdk/Exceptions/OAuthException.php +12 -0
  91. freemius/includes/sdk/Exceptions/index.php +3 -0
  92. freemius/includes/sdk/FreemiusBase.php +215 -0
  93. freemius/includes/sdk/FreemiusWordPress.php +695 -0
  94. freemius/includes/sdk/LICENSE.txt +340 -0
  95. freemius/includes/sdk/index.php +3 -0
  96. freemius/includes/supplements/fs-essential-functions-1.1.7.1.php +47 -0
  97. freemius/includes/supplements/index.php +3 -0
  98. freemius/index.php +3 -0
  99. freemius/languages/freemius-da_DK.mo +0 -0
  100. freemius/languages/freemius-da_DK.po +1826 -0
  101. freemius/languages/freemius-en.mo +0 -0
  102. freemius/languages/freemius-en.po +1301 -0
WGUtils.php CHANGED
@@ -1,209 +1,208 @@
1
- <?php
2
 
3
  class WGUtils {
4
 
5
- public static function getLangNameFromCode($code,$english) {
6
- switch ($code) {
7
- case "sq":
8
- return $english ? "Albanian":"Shqip";
9
- case "en":
10
- return $english ? "English":"English";
11
- case "ar":
12
- return $english ? "Arabic":"‏العربية‏";
13
- case "hy":
14
- return $english ? "Armenian":"հայերեն";
15
- case "az":
16
- return $english ? "Azerbaijani":"Azərbaycan dili";
17
- case "af":
18
- return $english ? "Afrikaans":"Afrikaans";
19
- case "eu":
20
- return $english ? "Basque":"Euskara";
21
- case "be":
22
- return $english ? "Belarusian":"Беларуская";
23
- case "bg":
24
- return $english ? "Bulgarian":"български";
25
- case "bs":
26
- return $english ? "Bosnian":"Bosanski";
27
- case "cy":
28
- return $english ? "Welsh":"Cymraeg";
29
- case "vi":
30
- return $english ? "Vietnamese":"Tiếng Việt";
31
- case "hu":
32
- return $english ? "Hungarian":"Magyar";
33
- case "ht":
34
- return $english ? "Haitian":"Kreyòl ayisyen";
35
- case "gl":
36
- return $english ? "Galician":"Galego";
37
- case "nl":
38
- return $english ? "Dutch":"Nederlands";
39
- case "el":
40
- return $english ? "Greek":"Ελληνικά";
41
- case "ka":
42
- return $english ? "Georgian":"ქართული";
43
- case "da":
44
- return $english ? "Danish":"Dansk";
45
- case "he":
46
- return $english ? "Hebrew":"עברית";
47
- case "id":
48
- return $english ? "Indonesian":"Bahasa Indonesia";
49
- case "ga":
50
- return $english ? "Irish":"Gaeilge";
51
- case "it":
52
- return $english ? "Italian":"Italiano";
53
- case "is":
54
- return $english ? "Icelandic":"Íslenska";
55
- case "es":
56
- return $english ? "Spanish":"Español";
57
- case "kk":
58
- return $english ? "Kazakh":"Қазақша";
59
- case "ca":
60
- return $english ? "Catalan":"Català";
61
- case "ky":
62
- return $english ? "Kyrgyz":"кыргызча";
63
- case "zh":
64
- return $english ? "Simplified Chinese":"中文 (简体)";
65
- case "tw":
66
- return $english ? "Traditional Chinese":"中文 (繁體)";
67
- case "ko":
68
- return $english ? "Korean":"한국어";
69
- case "lv":
70
- return $english ? "Latvian":"Latviešu";
71
- case "lt":
72
- return $english ? "Lithuanian":"Lietuvių";
73
- case "mg":
74
- return $english ? "Malagasy":"Malagasy";
75
- case "ms":
76
- return $english ? "Malay":"Bahasa Melayu";
77
- case "mt":
78
- return $english ? "Maltese":"Malti";
79
- case "mk":
80
- return $english ? "Macedonian":"Македонски";
81
- case "mn":
82
- return $english ? "Mongolian":"Монгол";
83
- case "de":
84
- return $english ? "German":"Deutsch";
85
- case "no":
86
- return $english ? "Norwegian":"Norsk";
87
- case "fa":
88
- return $english ? "Persian":"فارسی";
89
- case "pl":
90
- return $english ? "Polish":"Polski";
91
- case "pt":
92
- return $english ? "Portuguese":"Português";
93
- case "ro":
94
- return $english ? "Romanian":"Română";
95
- case "ru":
96
- return $english ? "Russian":"Русский";
97
- case "sr":
98
- return $english ? "Serbian":"Српски";
99
- case "sk":
100
- return $english ? "Slovak":"Slovenčina";
101
- case "sl":
102
- return $english ? "Slovenian":"Slovenščina";
103
- case "sw":
104
- return $english ? "Swahili":"Kiswahili";
105
- case "tg":
106
- return $english ? "Tajik":"Тоҷикӣ";
107
- case "th":
108
- return $english ? "Thai":"ภาษาไทย";
109
- case "tl":
110
- return $english ? "Tagalog":"Tagalog";
111
- case "tt":
112
- return $english ? "Tatar":"Tatar";
113
- case "tr":
114
- return $english ? "Turkish":"Türkçe";
115
- case "uz":
116
- return $english ? "Uzbek":"O'zbek";
117
- case "uk":
118
- return $english ? "Ukrainian":"Українська";
119
- case "fi":
120
- return $english ? "Finnish":"Suomi";
121
- case "fr":
122
- return $english ? "French":"Français";
123
- case "hr":
124
- return $english ? "Croatian":"Hrvatski";
125
- case "cs":
126
- return $english ? "Czech":"Čeština";
127
- case "sv":
128
- return $english ? "Swedish":"Svenska";
129
- case "et":
130
- return $english ? "Estonian":"Eesti";
131
- case "ja":
132
- return $english ? "Japanese":"日本語";
133
- case "hi":
134
- return $english ? "Hindi":"हिंदी";
135
- case "ur":
136
- return $english ? "Urdu":"اردو";
137
  }
138
  }
139
 
140
- public static function str_lreplace($search, $replace, $subject) {
141
- $pos = strrpos($subject, $search);
142
-
143
- if($pos !== false)
144
- {
145
- $subject = substr_replace($subject, $replace, $pos, strlen($search));
146
  }
147
  return $subject;
148
  }
149
 
150
- public static function is_HTML($string) {
151
- return ((preg_match("/<head/",$string,$m) != 0) && !(preg_match("/<xsl/",$string,$m) != 0));
152
  }
153
-
154
- public static function is_AJAX_HTML($string) {
155
- $r = preg_match_all("/<(a|div|span|p|i|aside|input|textarea|select|h1|h2|h3|h4|meta|button|form|li|strong|ul)/",$string,$m,PREG_PATTERN_ORDER);
156
- if($string[0]!='{' && $r && $r>=2)
157
  return true;
158
- else
159
  return false;
 
160
  }
161
-
162
- public static function endsWith($haystack, $needle) {
163
  // search forward starting from end minus needle length characters
164
- return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
165
  }
166
-
167
- public static function isLanguageRTL($code) {
168
- $rtls = array("ar","he","fa");
169
- if(in_array($code,$rtls)) {
170
  return true;
171
  }
172
  return false;
173
  }
174
-
175
- public static function hasLanguageRTL($arrayOfCode) {
176
- foreach($arrayOfCode as $code) {
177
- if(WGUtils::isLanguageRTL($code))
178
  return true;
 
179
  }
180
  return false;
181
  }
182
-
183
- public static function hasLanguageLTR($arrayOfCode) {
184
- foreach($arrayOfCode as $code) {
185
- if(!WGUtils::isLanguageRTL($code))
186
  return true;
 
187
  }
188
  return false;
189
  }
190
-
191
-
192
- public static function is_bot()
193
- {
194
- $ua = array_key_exists('HTTP_USER_AGENT',$_SERVER) ? $_SERVER['HTTP_USER_AGENT']:"Unknown";
195
- if (isset($ua)) {
196
- if (preg_match('/bot|favicon|crawl|facebook|Face|slurp|spider/i', $ua))
197
- {
198
  return true;
199
-
200
- }
201
- else
202
- {
203
  return false;
204
  }
205
- }
206
- else {
207
  return true;
208
  }
209
  }
1
+ <?php
2
 
3
  class WGUtils {
4
 
5
+ public static function getLangNameFromCode( $code, $english ) {
6
+ switch ( $code ) {
7
+ case 'sq':
8
+ return $english ? 'Albanian' : 'Shqip';
9
+ case 'en':
10
+ return $english ? 'English' : 'English';
11
+ case 'ar':
12
+ return $english ? 'Arabic' : '‏العربية‏';
13
+ case 'hy':
14
+ return $english ? 'Armenian' : 'հայերեն';
15
+ case 'az':
16
+ return $english ? 'Azerbaijani' : 'Azərbaycan dili';
17
+ case 'af':
18
+ return $english ? 'Afrikaans' : 'Afrikaans';
19
+ case 'eu':
20
+ return $english ? 'Basque' : 'Euskara';
21
+ case 'be':
22
+ return $english ? 'Belarusian' : 'Беларуская';
23
+ case 'bg':
24
+ return $english ? 'Bulgarian' : 'български';
25
+ case 'bs':
26
+ return $english ? 'Bosnian' : 'Bosanski';
27
+ case 'cy':
28
+ return $english ? 'Welsh' : 'Cymraeg';
29
+ case 'vi':
30
+ return $english ? 'Vietnamese' : 'Tiếng Việt';
31
+ case 'hu':
32
+ return $english ? 'Hungarian' : 'Magyar';
33
+ case 'ht':
34
+ return $english ? 'Haitian' : 'Kreyòl ayisyen';
35
+ case 'gl':
36
+ return $english ? 'Galician' : 'Galego';
37
+ case 'nl':
38
+ return $english ? 'Dutch' : 'Nederlands';
39
+ case 'el':
40
+ return $english ? 'Greek' : 'Ελληνικά';
41
+ case 'ka':
42
+ return $english ? 'Georgian' : 'ქართული';
43
+ case 'da':
44
+ return $english ? 'Danish' : 'Dansk';
45
+ case 'he':
46
+ return $english ? 'Hebrew' : 'עברית';
47
+ case 'id':
48
+ return $english ? 'Indonesian' : 'Bahasa Indonesia';
49
+ case 'ga':
50
+ return $english ? 'Irish' : 'Gaeilge';
51
+ case 'it':
52
+ return $english ? 'Italian' : 'Italiano';
53
+ case 'is':
54
+ return $english ? 'Icelandic' : 'Íslenska';
55
+ case 'es':
56
+ return $english ? 'Spanish' : 'Español';
57
+ case 'kk':
58
+ return $english ? 'Kazakh' : 'Қазақша';
59
+ case 'ca':
60
+ return $english ? 'Catalan' : 'Català';
61
+ case 'ky':
62
+ return $english ? 'Kyrgyz' : 'кыргызча';
63
+ case 'zh':
64
+ return $english ? 'Simplified Chinese' : '中文 (简体)';
65
+ case 'tw':
66
+ return $english ? 'Traditional Chinese' : '中文 (繁體)';
67
+ case 'ko':
68
+ return $english ? 'Korean' : '한국어';
69
+ case 'lv':
70
+ return $english ? 'Latvian' : 'Latviešu';
71
+ case 'lt':
72
+ return $english ? 'Lithuanian' : 'Lietuvių';
73
+ case 'mg':
74
+ return $english ? 'Malagasy' : 'Malagasy';
75
+ case 'ms':
76
+ return $english ? 'Malay' : 'Bahasa Melayu';
77
+ case 'mt':
78
+ return $english ? 'Maltese' : 'Malti';
79
+ case 'mk':
80
+ return $english ? 'Macedonian' : 'Македонски';
81
+ case 'mn':
82
+ return $english ? 'Mongolian' : 'Монгол';
83
+ case 'de':
84
+ return $english ? 'German' : 'Deutsch';
85
+ case 'no':
86
+ return $english ? 'Norwegian' : 'Norsk';
87
+ case 'fa':
88
+ return $english ? 'Persian' : 'فارسی';
89
+ case 'pl':
90
+ return $english ? 'Polish' : 'Polski';
91
+ case 'pt':
92
+ return $english ? 'Portuguese' : 'Português';
93
+ case 'ro':
94
+ return $english ? 'Romanian' : 'Română';
95
+ case 'ru':
96
+ return $english ? 'Russian' : 'Русский';
97
+ case 'sr':
98
+ return $english ? 'Serbian' : 'Српски';
99
+ case 'sk':
100
+ return $english ? 'Slovak' : 'Slovenčina';
101
+ case 'sl':
102
+ return $english ? 'Slovenian' : 'Slovenščina';
103
+ case 'sw':
104
+ return $english ? 'Swahili' : 'Kiswahili';
105
+ case 'tg':
106
+ return $english ? 'Tajik' : 'Тоҷикӣ';
107
+ case 'th':
108
+ return $english ? 'Thai' : 'ภาษาไทย';
109
+ case 'tl':
110
+ return $english ? 'Tagalog' : 'Tagalog';
111
+ case 'tt':
112
+ return $english ? 'Tatar' : 'Tatar';
113
+ case 'tr':
114
+ return $english ? 'Turkish' : 'Türkçe';
115
+ case 'uz':
116
+ return $english ? 'Uzbek' : "O'zbek";
117
+ case 'uk':
118
+ return $english ? 'Ukrainian' : 'Українська';
119
+ case 'fi':
120
+ return $english ? 'Finnish' : 'Suomi';
121
+ case 'fr':
122
+ return $english ? 'French' : 'Français';
123
+ case 'hr':
124
+ return $english ? 'Croatian' : 'Hrvatski';
125
+ case 'cs':
126
+ return $english ? 'Czech' : 'Čeština';
127
+ case 'sv':
128
+ return $english ? 'Swedish' : 'Svenska';
129
+ case 'et':
130
+ return $english ? 'Estonian' : 'Eesti';
131
+ case 'ja':
132
+ return $english ? 'Japanese' : '日本語';
133
+ case 'hi':
134
+ return $english ? 'Hindi' : 'हिंदी';
135
+ case 'ur':
136
+ return $english ? 'Urdu' : 'اردو';
137
  }
138
  }
139
 
140
+ public static function str_lreplace( $search, $replace, $subject ) {
141
+ $pos = strrpos( $subject, $search );
142
+
143
+ if ( $pos !== false ) {
144
+ $subject = substr_replace( $subject, $replace, $pos, strlen( $search ) );
 
145
  }
146
  return $subject;
147
  }
148
 
149
+ public static function is_HTML( $string ) {
150
+ return ((preg_match( '/<head/',$string,$m ) != 0) && ! (preg_match( '/<xsl/',$string,$m ) != 0));
151
  }
152
+
153
+ public static function is_AJAX_HTML( $string ) {
154
+ $r = preg_match_all( '/<(a|div|span|p|i|aside|input|textarea|select|h1|h2|h3|h4|meta|button|form|li|strong|ul)/',$string,$m,PREG_PATTERN_ORDER );
155
+ if ( $string[0] != '{' && $r && $r >= 2 ) {
156
  return true;
157
+ } else {
158
  return false;
159
+ }
160
  }
161
+
162
+ public static function endsWith( $haystack, $needle ) {
163
  // search forward starting from end minus needle length characters
164
+ return $needle === '' || (($temp = strlen( $haystack ) - strlen( $needle )) >= 0 && strpos( $haystack, $needle, $temp ) !== false);
165
  }
166
+
167
+ public static function isLanguageRTL( $code ) {
168
+ $rtls = array( 'ar', 'he', 'fa' );
169
+ if ( in_array( $code,$rtls ) ) {
170
  return true;
171
  }
172
  return false;
173
  }
174
+
175
+ public static function hasLanguageRTL( $arrayOfCode ) {
176
+ foreach ( $arrayOfCode as $code ) {
177
+ if ( WGUtils::isLanguageRTL( $code ) ) {
178
  return true;
179
+ }
180
  }
181
  return false;
182
  }
183
+
184
+ public static function hasLanguageLTR( $arrayOfCode ) {
185
+ foreach ( $arrayOfCode as $code ) {
186
+ if ( ! WGUtils::isLanguageRTL( $code ) ) {
187
  return true;
188
+ }
189
  }
190
  return false;
191
  }
192
+
193
+
194
+ public static function is_bot() {
195
+ $ua = array_key_exists( 'HTTP_USER_AGENT',$_SERVER ) ? sanitize_text_field(
196
+ wp_unslash( $_SERVER['HTTP_USER_AGENT'] )
197
+ ) : 'Unknown';
198
+ if ( isset( $ua ) ) {
199
+ if ( preg_match( '/bot|favicon|crawl|facebook|Face|slurp|spider/i', $ua ) ) {
200
  return true;
201
+
202
+ } else {
 
 
203
  return false;
204
  }
205
+ } else {
 
206
  return true;
207
  }
208
  }
WeglotPHPClient/src/Client.php CHANGED
@@ -1,387 +1,459 @@
1
  <?php
2
  namespace Weglot;
3
  use WeglotSDP;
4
- class Client
5
- {
6
  protected $api_key;
7
 
8
- const API_BASE = 'https://weglot.com/api/';
9
- //const API_BASE = 'http://weglot/api/';
10
-
11
- function __construct($key) {
12
  $this->api_key = $key;
13
-
14
- if ($this->api_key == null || mb_strlen($this->api_key) == 0) {
15
- return null;
16
- }
17
  }
18
-
19
- public function hasAncestorAttribute($node,$attribute) {
20
-
21
  $currentNode = $node;
22
 
23
- if(isset($currentNode->$attribute))
24
- return true;
 
25
 
26
- while($currentNode->parent() && $currentNode->parent()->tag!="html") {
27
 
28
- if(isset($currentNode->parent()->$attribute))
29
  return true;
30
- else
31
  $currentNode = $currentNode->parent();
 
32
  }
33
  return false;
34
  }
35
 
36
 
37
- public function checkText($row) {
38
- return ($row->parent()->tag!="script"
39
- && $row->parent()->tag!="style"
40
- && !is_numeric($this->full_trim($row->outertext))
41
- && !preg_match('/^\d+%$/',$this->full_trim($row->outertext)));
42
- }
 
43
 
44
- public function checkButton($row) {
45
- return (!is_numeric($this->full_trim($row->value))
46
- && !preg_match('/^\d+%$/',$this->full_trim($row->value)));
47
- }
48
 
49
- public function checkInput_dv($row) {
50
  return true;
51
  }
52
 
 
 
 
53
 
54
- public function checkPlaceholder($row) {
55
- return (!is_numeric($this->full_trim($row->placeholder))
56
- && !preg_match('/^\d+%$/',$this->full_trim($row->placeholder)) );
57
  }
58
 
59
- public function checkMeta_desc($row) {
60
- return (!is_numeric($this->full_trim($row->placeholder))
61
- && !preg_match('/^\d+%$/',$this->full_trim($row->placeholder)) );
62
- }
63
 
64
- public function checkIframe_src($row) {
65
- return (strpos($this->full_trim($row->src),'.youtube.') !== false);
66
- }
 
67
 
68
- public function checkImg_src($row) {
69
- return true;
70
- }
 
71
 
72
- public function checkImg_alt($row) {
73
- return true;
74
- }
75
 
76
- public function checkA_pdf($row) {
77
- return (strtolower(substr($this->full_trim($row->href),-4))==".pdf");
78
- }
79
 
80
- public function checkA_title($row) {
81
- return true;
82
- }
 
 
 
 
 
 
 
 
83
 
84
- public function checkA_dv($row) {
 
 
 
 
 
 
 
 
 
 
 
 
85
  return true;
86
  }
87
 
88
- public function checkA_dt($row) {
89
  return true;
90
  }
91
 
92
- function searchForId($id, $array) {
93
- foreach ($array as $key => $val) {
94
- if ($val['uid'] === $id) {
95
- return $key;
96
- }
97
- }
98
- return null;
99
- }
100
 
101
- public function translateDomFromTo($dom,$l_from,$l_to) {
102
- $html = WeglotSDP\str_get_html($dom, true, true, WG_DEFAULT_TARGET_CHARSET, false, WG_DEFAULT_BR_TEXT, WG_DEFAULT_SPAN_TEXT);
103
-
104
- $exceptions = explode(",",get_option("exclude_blocks"));
105
- array_push($exceptions,"#wpadminbar");
106
- foreach ($exceptions as $exception) {
107
- foreach ($html->find($exception) as $k => $row)
108
- {
109
- $attribute = "data-wg-notranslate";
110
- $row->$attribute="";
111
  }
112
  }
113
-
114
-
115
-
116
  $words = array();
117
  $nodes = array();
118
 
119
-
120
-
121
  $elements_to_check = array(
122
- "text"
123
- => array(array("property"=>"outertext",
124
- "t"=>1,
125
- "type"=>"text")),
126
-
127
- "input[type='submit'],input[type='button']"
128
- => array(array("property"=>"value",
129
- "t"=>2,
130
- "type"=>"button"),
131
- array("property"=>"data-value",
132
- "t"=>1,
133
- "type"=>"input_dv")),
134
-
135
- "input[type=\'text\'],input[type=\'password\'],input[type=\'search\'],input[type=\'email\'],input:not([type]),textarea"
136
- => array(array("property"=>"placeholder",
137
- "t"=>3,
138
- "type"=>"placeholder")),
139
-
140
- "meta[name=\"description\"],meta[property=\"og:title\"],meta[property=\"og:description\"],meta[property=\"og:site_name\"],meta[name=\"twitter:title\"],meta[name=\"twitter:description\"]"
141
- => array(array("property"=>"content",
142
- "t"=>4,
143
- "type"=>"meta_desc")),
144
-
145
- "iframe"
146
- => array(array( "property"=>"src",
147
- "t"=>5,
148
- "type"=>"iframe_src")),
149
-
150
- "img"
151
- => array(array("property"=>"src",
152
- "t"=>6,
153
- "type"=>"img_src"),
154
- array("property"=>"alt",
155
- "t"=>7,
156
- "type"=>"img_alt")),
157
-
158
-
159
- "a"
160
- => array(array("property"=>"href",
161
- "t"=>8,
162
- "type"=>"a_pdf"),
163
- array("property"=>"title",
164
- "t"=>1,
165
- "type"=>"a_title"),
166
- array("property"=>"data-value",
167
- "t"=>1,
168
- "type"=>"a_dv"),
169
- array("property"=>"data-title",
170
- "t"=>1,
171
- "type"=>"a_dt")),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
 
 
 
 
 
173
 
174
- );
175
 
176
- foreach($elements_to_check as $key => $elem) {
177
- foreach ($html->find($key) as $k => $row) {
178
-
179
- foreach($elem as $element) {
180
-
181
- $property = $element['property'];
182
- $t = $element['t'];
183
- $type = $element['type'];
184
- $functionName = 'check' . ucfirst($type);
185
-
186
- if ($this->full_trim($row->$property) != "" && !$this->hasAncestorAttribute($row, 'data-wg-notranslate')
187
- && $this->$functionName($row)
188
- ) {
189
- array_push($words, array("t" => $t, "w" => $row->$property));
190
- array_push($nodes, array('node' => $row, 'type' => $type, 'property'=>$property));
191
- }
192
- }
193
- }
194
- }
195
-
196
-
197
-
198
- $title = "";
199
- foreach ($html->find('title') as $k => $row) {
200
- $title = $row->innertext;
201
- }
202
-
203
- $absolute_url = $this->full_url($_SERVER);
204
- if(strpos($absolute_url,'admin-ajax.php') !== false) {
205
- $absolute_url = $_SERVER['HTTP_REFERER'];
206
- $title = "Ajax data";
207
  }
208
-
209
- $bot = $this->bot_detected();
210
- $parameters = array("l_from"=>$l_from,"l_to"=>$l_to,"title"=>$title,"request_url"=>$absolute_url,"bot"=>$bot,"words"=>$words);
211
- $results = $this->doRequest(self::API_BASE."v2/translate?api_key=".$this->api_key,$parameters);
212
- $json = json_decode($results,true);
213
- if(json_last_error() == JSON_ERROR_NONE)
214
- {
215
- if(isset($json['succeeded']) && ($json['succeeded']==0 || $json['succeeded']==1)) {
216
- if($json['succeeded']==1) {
217
- if(isset($json['answer'])) {
218
- $answer = $json['answer'];
219
- if(isset($answer['to_words'])) {
220
- $translated_words = $answer['to_words'];
221
- if(count($nodes)==count($translated_words)) {
222
- for($i=0;$i<count($nodes);$i++) {
223
-
224
- $property = $nodes[$i]['property'];
225
- $nodes[$i]['node']->$property = $translated_words[$i];
226
-
227
- if($nodes[$i]['type']=='image_src') {
228
- $nodes[$i]['node']->src = $translated_words[$i];
229
- if($nodes[$i]['node']->hasAttribute("srcset") && $nodes[$i]['node']->srcset != "" && $translated_words[$i]!=$words[$i]['w']) {
230
- $nodes[$i]['node']->srcset = "";
231
- }
232
- }
233
-
234
- }
235
- return $html->save();
236
  }
237
- else
238
- throw new WeglotException('Unknown error with Weglot Api (0006)');
239
  }
240
- else
241
- throw new WeglotException('Unknown error with Weglot Api (0005)');
242
  }
243
- else
244
- throw new WeglotException('Unknown error with Weglot Api (0004)');
245
- }
246
- else {
247
- $error = isset($json['error']) ? $json['error']:'Unknown error with Weglot Api (0003)';
248
- throw new WeglotException($error);
249
- }
250
  }
251
- else
252
- throw new WeglotException('Unknown error with Weglot Api (0002) : '.$json);
253
  }
254
- else
255
- throw new WeglotException('Unknown error with Weglot Api (0001) : '.json_last_error());
256
  }
257
-
258
  public function getUserInfo() {
259
- $results = $this->doRequest(self::API_BASE."user-info?api_key=".$this->api_key,null);
260
- $json = json_decode($results,true);
261
- if(json_last_error() == JSON_ERROR_NONE)
262
- {
263
- if(isset($json['succeeded']) && ($json['succeeded']==0 || $json['succeeded']==1)) {
264
- if($json['succeeded']==1) {
265
- if(isset($json['answer'])) {
266
  $answer = $json['answer'];
267
  return $answer;
 
 
268
  }
269
- else
270
- throw new WeglotException('Unknown error with Weglot Api (0004)');
 
271
  }
272
- else {
273
- $error = isset($json['error']) ? $json['error']:'Unknown error with Weglot Api (0003)';
274
- throw new WeglotException($error);
275
- }
276
  }
277
- else
278
- throw new WeglotException('Unknown error with Weglot Api (0002) : '.$json);
279
  }
280
- else
281
- throw new WeglotException('Unknown error with Weglot Api (0001) : '.json_last_error());
282
  }
283
-
284
- public function doRequest($url,$parameters) {
285
-
286
- if($parameters) {
287
- $payload = json_encode($parameters);
288
- if(json_last_error() == JSON_ERROR_NONE) {
289
- $response = wp_remote_post( $url, array(
290
- 'method' => 'POST',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  'timeout' => 45,
292
  'redirection' => 5,
293
  'blocking' => true,
294
- 'headers' => array( "Content-type" => "application/json" ),
295
- 'body' => $payload,
 
 
296
  'cookies' => array(),
297
- 'sslverify' => false
298
- )
299
- );
300
- }
301
- else
302
- throw new WeglotException('Cannot json encode parameters: '.json_last_error());
303
-
304
- }
305
- else {
306
- $response = wp_remote_get( $url, array(
307
- 'method' => 'GET',
308
- 'timeout' => 45,
309
- 'redirection' => 5,
310
- 'blocking' => true,
311
- 'headers' => array( "Content-type" => "application/json" ),
312
- 'body' => null,
313
- 'cookies' => array(),
314
- 'sslverify' => false
315
  )
316
  );
317
  }
318
 
319
  if ( is_wp_error( $response ) ) {
320
  $error_message = $response->get_error_message();
321
- throw new WeglotException('Error doing the external request to '.$url.': '.$error_message);
322
  } else {
323
  return $response['body'];
324
  }
325
  }
326
-
327
-
328
-
329
- function bot_detected()
330
- {
331
- $ua = $_SERVER['HTTP_USER_AGENT'];
332
- if (isset($ua))
333
- {
334
- if (preg_match('/bot|favicon|crawl|facebook|slurp|spider/i', $ua))
335
- {
336
- if (strpos($ua, 'Google') !== false || strpos($ua, 'facebook') !== false || strpos($ua, 'wprocketbot') !== false || strpos($ua, 'SemrushBot') !== false) {
337
  return 2;
338
- }
339
- elseif (strpos($ua, 'bing') !== false) {
340
  return 3;
341
- }
342
- elseif (strpos($ua, 'yahoo') !== false) {
343
  return 4;
344
- }
345
- elseif (strpos($ua, 'Baidu') !== false) {
346
  return 5;
347
- }
348
- elseif (strpos($ua, 'Yandex') !== false) {
349
  return 6;
350
- }
351
- else {
352
  return 1;
353
  }
354
-
355
- }
356
- else
357
- {
358
  return 0;
359
  }
360
- }
361
- else
362
- {
363
  return 1;
364
  }
365
  }
366
-
367
- function url_origin($s, $use_forwarded_host=false)
368
- {
369
- $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true:false;
370
- $sp = strtolower($s['SERVER_PROTOCOL']);
371
- $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
372
  $port = $s['SERVER_PORT'];
373
- $port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port;
374
- $host = ($use_forwarded_host && isset($s['HTTP_X_FORWARDED_HOST'])) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null);
375
- $host = isset($host) ? $host : $s['SERVER_NAME'] . $port;
376
  return $protocol . '://' . $host;
377
  }
378
- function full_url($s, $use_forwarded_host=false)
379
- {
380
- return $this->url_origin($s, $use_forwarded_host) . $s['REQUEST_URI'];
381
  }
382
- function full_trim($word) {
383
- return trim($word," \t\n\r\0\x0B\xA0�");
384
  }
385
  }
386
 
387
- ?>
1
  <?php
2
  namespace Weglot;
3
  use WeglotSDP;
4
+ class Client {
5
+
6
  protected $api_key;
7
 
8
+ const API_BASE = 'https://api.weglot.com';
9
+ const API_BASE_OLD = 'https://weglot.com/api/';
10
+
11
+ function __construct( $key ) {
12
  $this->api_key = $key;
13
+
14
+ if ( $this->api_key == null || mb_strlen( $this->api_key ) == 0 ) {
15
+ return null;
16
+ }
17
  }
18
+
19
+ public function hasAncestorAttribute( $node, $attribute ) {
20
+
21
  $currentNode = $node;
22
 
23
+ if ( isset( $currentNode->$attribute ) ) {
24
+ return true;
25
+ }
26
 
27
+ while ( $currentNode->parent() && $currentNode->parent()->tag != 'html' ) {
28
 
29
+ if ( isset( $currentNode->parent()->$attribute ) ) {
30
  return true;
31
+ } else {
32
  $currentNode = $currentNode->parent();
33
+ }
34
  }
35
  return false;
36
  }
37
 
38
 
39
+ public function checkText( $row ) {
40
+ return ($row->parent()->tag != 'script'
41
+ && $row->parent()->tag != 'style'
42
+ && ! is_numeric( $this->full_trim( $row->outertext ) )
43
+ && ! preg_match( '/^\d+%$/',$this->full_trim( $row->outertext ) )
44
+ && strpos( $row->outertext,'[vc_' ) === false);
45
+ }
46
 
47
+ public function checkButton( $row ) {
48
+ return ( ! is_numeric( $this->full_trim( $row->value ) )
49
+ && ! preg_match( '/^\d+%$/',$this->full_trim( $row->value ) ));
50
+ }
51
 
52
+ public function checkTd_dt( $row ) {
53
  return true;
54
  }
55
 
56
+ public function checkInput_dv( $row ) {
57
+ return true;
58
+ }
59
 
60
+ public function checkInput_dobt( $row ) {
61
+ return true;
 
62
  }
63
 
 
 
 
 
64
 
65
+ public function checkPlaceholder( $row ) {
66
+ return ( ! is_numeric( $this->full_trim( $row->placeholder ) )
67
+ && ! preg_match( '/^\d+%$/',$this->full_trim( $row->placeholder ) ) );
68
+ }
69
 
70
+ public function checkMeta_desc( $row ) {
71
+ return ( ! is_numeric( $this->full_trim( $row->placeholder ) )
72
+ && ! preg_match( '/^\d+%$/',$this->full_trim( $row->placeholder ) ) );
73
+ }
74
 
75
+ public function checkIframe_src( $row ) {
76
+ return (strpos( $this->full_trim( $row->src ),'.youtube.' ) !== false);
77
+ }
78
 
79
+ public function checkImg_src( $row ) {
80
+ return true;
81
+ }
82
 
83
+ public function checkImg_alt( $row ) {
84
+ return true;
85
+ }
86
+
87
+ public function checkA_pdf( $row ) {
88
+ return (
89
+ strtolower( substr( $this->full_trim( $row->href ),-4 ) ) == '.pdf'
90
+ || strtolower( substr( $this->full_trim( $row->href ),-4 ) ) == '.rar'
91
+ || strtolower( substr( $this->full_trim( $row->href ),-4 ) ) == '.docx'
92
+ );
93
+ }
94
 
95
+ public function checkA_title( $row ) {
96
+ return true;
97
+ }
98
+
99
+ public function checkA_dv( $row ) {
100
+ return true;
101
+ }
102
+
103
+ public function checkA_dt( $row ) {
104
+ return true;
105
+ }
106
+
107
+ public function checkA_dto( $row ) {
108
  return true;
109
  }
110
 
111
+ public function checkA_dho( $row ) {
112
  return true;
113
  }
114
 
115
+ function searchForId( $id, $array ) {
116
+ foreach ( $array as $key => $val ) {
117
+ if ( $val['uid'] === $id ) {
118
+ return $key;
119
+ }
120
+ }
121
+ return null;
122
+ }
123
 
124
+ public function translateDomFromTo( $dom, $l_from, $l_to ) {
125
+ $html = WeglotSDP\str_get_html( $dom, true, true, WG_DEFAULT_TARGET_CHARSET, false, WG_DEFAULT_BR_TEXT, WG_DEFAULT_SPAN_TEXT );
126
+
127
+ $exceptions = explode( ',',get_option( 'exclude_blocks' ) );
128
+ array_push( $exceptions,'#wpadminbar' );
129
+ foreach ( $exceptions as $exception ) {
130
+ foreach ( $html->find( $exception ) as $k => $row ) {
131
+ $attribute = 'data-wg-notranslate';
132
+ $row->$attribute = '';
 
133
  }
134
  }
135
+
 
 
136
  $words = array();
137
  $nodes = array();
138
 
 
 
139
  $elements_to_check = array(
140
+ 'text'
141
+ => array(
142
+ array(
143
+ 'property' => 'outertext',
144
+ 't' => 1,
145
+ 'type' => 'text',
146
+ ),
147
+ ),
148
+
149
+ "input[type='submit'],input[type='button']"
150
+ => array(
151
+ array(
152
+ 'property' => 'value',
153
+ 't' => 2,
154
+ 'type' => 'button',
155
+ ),
156
+ array(
157
+ 'property' => 'data-value',
158
+ 't' => 1,
159
+ 'type' => 'input_dv',
160
+ ),
161
+ array(
162
+ 'property' => 'data-order_button_text',
163
+ 't' => 1,
164
+ 'type' => 'input_dobt',
165
+ ),
166
+ ),
167
+
168
+
169
+ "td"
170
+ => array(
171
+ array(
172
+ 'property' => 'data-title',
173
+ 't' => 2,
174
+ 'type' => 'td_dt',
175
+ ),
176
+ ),
177
+
178
+ "input[type=\'text\'],input[type=\'password\'],input[type=\'search\'],input[type=\'email\'],input:not([type]),textarea"
179
+ => array(
180
+ array(
181
+ 'property' => 'placeholder',
182
+ 't' => 3,
183
+ 'type' => 'placeholder',
184
+ ),
185
+ ),
186
+
187
+ 'meta[name="description"],meta[property="og:title"],meta[property="og:description"],meta[property="og:site_name"],meta[name="twitter:title"],meta[name="twitter:description"]'
188
+ => array(
189
+ array(
190
+ 'property' => 'content',
191
+ 't' => 4,
192
+ 'type' => 'meta_desc',
193
+ ),
194
+ ),
195
+
196
+ 'iframe'
197
+ => array(
198
+ array(
199
+ 'property' => 'src',
200
+ 't' => 5,
201
+ 'type' => 'iframe_src',
202
+ ),
203
+ ),
204
+
205
+ 'img'
206
+ => array(
207
+ array(
208
+ 'property' => 'src',
209
+ 't' => 6,
210
+ 'type' => 'img_src',
211
+ ),
212
+ array(
213
+ 'property' => 'alt',
214
+ 't' => 7,
215
+ 'type' => 'img_alt',
216
+ ),
217
+ ),
218
+
219
+ 'a'
220
+ => array(
221
+ array(
222
+ 'property' => 'href',
223
+ 't' => 8,
224
+ 'type' => 'a_pdf',
225
+ ),
226
+ array(
227
+ 'property' => 'title',
228
+ 't' => 1,
229
+ 'type' => 'a_title',
230
+ ),
231
+ array(
232
+ 'property' => 'data-value',
233
+ 't' => 1,
234
+ 'type' => 'a_dv',
235
+ ),
236
+ array(
237
+ 'property' => 'data-title',
238
+ 't' => 1,
239
+ 'type' => 'a_dt',
240
+ ),
241
+ array(
242
+ 'property' => 'data-tooltip',
243
+ 't' => 1,
244
+ 'type' => 'a_dto',
245
+ ),
246
+ array(
247
+ 'property' => 'data-hover',
248
+ 't' => 1,
249
+ 'type' => 'a_dho',
250
+ ),
251
+ ),
252
+
253
+ );
254
+
255
+ foreach ( $elements_to_check as $key => $elem ) {
256
+ foreach ( $html->find( $key ) as $k => $row ) {
257
+
258
+ foreach ( $elem as $element ) {
259
+
260
+ $property = $element['property'];
261
+ $t = $element['t'];
262
+ $type = $element['type'];
263
+ $functionName = 'check' . ucfirst( $type );
264
+
265
+ if ( $this->full_trim( $row->$property ) != '' && ! $this->hasAncestorAttribute( $row, 'data-wg-notranslate' )
266
+ && $this->$functionName($row)
267
+ ) {
268
+ array_push(
269
+ $words, array(
270
+ 't' => $t,
271
+ 'w' => $row->$property,
272
+ )
273
+ );
274
+ array_push(
275
+ $nodes, array(
276
+ 'node' => $row,
277
+ 'type' => $type,
278
+ 'property' => $property,
279
+ )
280
+ );
281
+ }
282
+ }
283
+ }
284
+ }
285
 
286
+ $title = 'Empty title';
287
+ foreach ( $html->find( 'title' ) as $k => $row ) {
288
+ if($row->innertext != '')
289
+ $title = $row->innertext;
290
+ }
291
 
 
292
 
293
+ $absolute_url = $this->full_url( $_SERVER );
294
+ if ( strpos( $absolute_url,'admin-ajax.php' ) !== false ) {
295
+ if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
296
+ $absolute_url = sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) );
297
+ }
298
+ $title = 'Ajax data';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  }
300
+
301
+ $bot = $this->bot_detected();
302
+ $parameters = array(
303
+ 'l_from' => $l_from,
304
+ 'l_to' => $l_to,
305
+ 'title' => $title,
306
+ 'request_url' => $absolute_url,
307
+ 'bot' => $bot,
308
+ 'words' => $words,
309
+ );
310
+ $results = $this->doRequest( self::API_BASE . '/translate?api_key=' . $this->api_key,$parameters );
311
+ $json = json_decode( $results,true );
312
+ if ( json_last_error() == JSON_ERROR_NONE ) {
313
+ $answer = $json;
314
+ if ( isset( $answer['to_words'] ) ) {
315
+ $translated_words = $answer['to_words'];
316
+ if ( count( $nodes ) == count( $translated_words ) ) {
317
+ for ( $i = 0;$i < count( $nodes );$i++ ) {
318
+
319
+ $property = $nodes[ $i ]['property'];
320
+ $nodes[ $i ]['node']->$property = $translated_words[ $i ];
321
+
322
+ if ( $nodes[ $i ]['type'] == 'image_src' ) {
323
+ $nodes[ $i ]['node']->src = $translated_words[ $i ];
324
+ if ( $nodes[ $i ]['node']->hasAttribute( 'srcset' ) && $nodes[ $i ]['node']->srcset != '' && $translated_words[ $i ] != $words[ $i ]['w'] ) {
325
+ $nodes[ $i ]['node']->srcset = '';
 
 
326
  }
 
 
327
  }
 
 
328
  }
329
+ return $html->save();
330
+ } else {
331
+ throw new WeglotException( 'Unknown error with Weglot Api (0006)' );
332
+ }
333
+ } else {
334
+ throw new WeglotException( 'Unknown error with Weglot Api (0005) Error is: ' . serialize( $results ) );
 
335
  }
336
+ } else {
337
+ throw new WeglotException( 'Error with Weglot Api (0001) : ' . json_last_error() . ' Error is: ' . serialize( $results ) );
338
  }
 
 
339
  }
340
+
341
  public function getUserInfo() {
342
+ $results = $this->doRequest( self::API_BASE_OLD . 'user-info?api_key=' . $this->api_key,null );
343
+ $json = json_decode( $results,true );
344
+ if ( json_last_error() == JSON_ERROR_NONE ) {
345
+ if ( isset( $json['succeeded'] ) && ($json['succeeded'] == 0 || $json['succeeded'] == 1) ) {
346
+ if ( $json['succeeded'] == 1 ) {
347
+ if ( isset( $json['answer'] ) ) {
 
348
  $answer = $json['answer'];
349
  return $answer;
350
+ } else {
351
+ throw new WeglotException( 'Unknown error with Weglot Api (0004)' );
352
  }
353
+ } else {
354
+ $error = isset( $json['error'] ) ? $json['error'] : 'Unknown error with Weglot Api (0003)';
355
+ throw new WeglotException( $error );
356
  }
357
+ } else {
358
+ throw new WeglotException( 'Unknown error with Weglot Api (0002) : ' . $json );
 
 
359
  }
360
+ } else {
361
+ throw new WeglotException( 'Unknown error with Weglot Api (0001) : ' . json_last_error() );
362
  }
 
 
363
  }
364
+
365
+ public function doRequest( $url, $parameters ) {
366
+
367
+ if ( $parameters ) {
368
+ $payload = json_encode( $parameters );
369
+ if ( json_last_error() == JSON_ERROR_NONE ) {
370
+ $response = wp_remote_post(
371
+ $url, array(
372
+ 'method' => 'POST',
373
+ 'timeout' => 45,
374
+ 'redirection' => 5,
375
+ 'blocking' => true,
376
+ 'headers' => array(
377
+ 'Content-type' => 'application/json',
378
+ ),
379
+ 'body' => $payload,
380
+ 'cookies' => array(),
381
+ 'sslverify' => false,
382
+ )
383
+ );
384
+ } else {
385
+ throw new WeglotException( 'Cannot json encode parameters: ' . json_last_error() );
386
+ }
387
+ } else {
388
+ $response = wp_remote_get(
389
+ $url, array(
390
+ 'method' => 'GET',
391
  'timeout' => 45,
392
  'redirection' => 5,
393
  'blocking' => true,
394
+ 'headers' => array(
395
+ 'Content-type' => 'application/json',
396
+ ),
397
+ 'body' => null,
398
  'cookies' => array(),
399
+ 'sslverify' => false,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
  )
401
  );
402
  }
403
 
404
  if ( is_wp_error( $response ) ) {
405
  $error_message = $response->get_error_message();
406
+ throw new WeglotException( 'Error doing the external request to ' . $url . ': ' . $error_message );
407
  } else {
408
  return $response['body'];
409
  }
410
  }
411
+
412
+
413
+
414
+ function bot_detected() {
415
+ if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
416
+ $ua = sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) );
417
+ }
418
+ if ( isset( $ua ) ) {
419
+ if ( preg_match( '/bot|favicon|crawl|facebook|slurp|spider/i', $ua ) ) {
420
+ if ( strpos( $ua, 'Google' ) !== false || strpos( $ua, 'facebook' ) !== false || strpos( $ua, 'wprocketbot' ) !== false || strpos( $ua, 'SemrushBot' ) !== false ) {
 
421
  return 2;
422
+ } elseif ( strpos( $ua, 'bing' ) !== false ) {
 
423
  return 3;
424
+ } elseif ( strpos( $ua, 'yahoo' ) !== false ) {
 
425
  return 4;
426
+ } elseif ( strpos( $ua, 'Baidu' ) !== false ) {
 
427
  return 5;
428
+ } elseif ( strpos( $ua, 'Yandex' ) !== false ) {
 
429
  return 6;
430
+ } else {
 
431
  return 1;
432
  }
433
+ } else {
 
 
 
434
  return 0;
435
  }
436
+ } else {
 
 
437
  return 1;
438
  }
439
  }
440
+
441
+ function url_origin( $s, $use_forwarded_host = false ) {
442
+ $ssl = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on') ? true : false;
443
+ $sp = strtolower( $s['SERVER_PROTOCOL'] );
444
+ $protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . (($ssl) ? 's' : '');
 
445
  $port = $s['SERVER_PORT'];
446
+ $port = (( ! $ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port;
447
+ $host = ($use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] )) ? $s['HTTP_X_FORWARDED_HOST'] : (isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null);
448
+ $host = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
449
  return $protocol . '://' . $host;
450
  }
451
+ function full_url( $s, $use_forwarded_host = false ) {
452
+ return $this->url_origin( $s, $use_forwarded_host ) . $s['REQUEST_URI'];
 
453
  }
454
+ function full_trim( $word ) {
455
+ return trim( $word," \t\n\r\0\x0B\xA0�" );
456
  }
457
  }
458
 
459
+
WeglotPHPClient/src/WeglotException.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  namespace Weglot;
3
 
4
- class WeglotException extends \Exception
5
- {
6
  }
1
  <?php
2
  namespace Weglot;
3
 
4
+ class WeglotException extends \Exception {
5
+
6
  }
WeglotPHPClient/weglot.php CHANGED
@@ -1,4 +1,4 @@
1
  <?php
2
 
3
  require_once 'src/Client.php';
4
- require_once 'src/WeglotException.php';
1
  <?php
2
 
3
  require_once 'src/Client.php';
4
+ require_once 'src/WeglotException.php';
WeglotWidget.php CHANGED
@@ -3,44 +3,47 @@
3
  class WeglotWidget extends WP_Widget {
4
 
5
  public function __construct() {
6
- parent::__construct(false, $name = __('Weglot Translate', 'weglot') );
7
- }
8
 
9
- public function WeglotWidget() {
10
- parent::__construct(false, $name = __('Weglot Translate', 'weglot') );
11
- }
12
 
13
- public function update( $new_instance, $old_instance ) {
14
  $instance = array();
15
  $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
16
  return $instance;
17
  }
18
 
19
- function widget($args, $instance) {
20
 
21
  $title = apply_filters( 'widget_title', $instance['title'] );
22
 
23
-
24
-
25
- $tt = ( ! empty( $title ) ) ? $args['before_title'] . $title . $args['after_title']:"";
26
 
27
  $button = Weglot::Instance()->returnWidgetCode();
28
- echo $args['before_widget'].$tt.$button.$args['after_widget'];
29
- }
 
 
30
 
31
  public function form( $instance ) {
32
- if ( isset( $instance[ 'title' ] ) ) {
33
- $title = $instance[ 'title' ];
34
- }
35
- else {
36
- $title = "";
37
  }
38
  // Widget admin form
39
  ?>
40
  <p>
41
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'weglot'); ?></label>
42
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
 
 
 
 
43
  </p>
44
  <?php
45
  }
46
- }
3
  class WeglotWidget extends WP_Widget {
4
 
5
  public function __construct() {
6
+ parent::__construct( false, $name = __( 'Weglot Translate', 'weglot' ) );
7
+ }
8
 
9
+ public function WeglotWidget() {
10
+ parent::__construct( false, $name = __( 'Weglot Translate', 'weglot' ) );
11
+ }
12
 
13
+ public function update( $new_instance, $old_instance ) {
14
  $instance = array();
15
  $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
16
  return $instance;
17
  }
18
 
19
+ function widget( $args, $instance ) {
20
 
21
  $title = apply_filters( 'widget_title', $instance['title'] );
22
 
23
+ $tt = ( ! empty( $title ) ) ? $args['before_title'] . $title . $args['after_title'] : '';
 
 
24
 
25
  $button = Weglot::Instance()->returnWidgetCode();
26
+ echo $args['before_widget'] . $tt . wp_kses($button, Weglot::Instance()
27
+ ->getAllowedTags()) .
28
+ $args['after_widget'];
29
+ }
30
 
31
  public function form( $instance ) {
32
+ if ( isset( $instance['title'] ) ) {
33
+ $title = $instance['title'];
34
+ } else {
35
+ $title = '';
 
36
  }
37
  // Widget admin form
38
  ?>
39
  <p>
40
+ <label for="
41
+ <?php
42
+ echo esc_html( $this->get_field_id( 'title' ) );
43
+ ?>
44
+ "><?php esc_html_e( 'Title:', 'weglot' ); ?></label>
45
+ <input class="widefat" id="<?php echo esc_html( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_html( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
46
  </p>
47
  <?php
48
  }
49
+ }
freemius/LICENSE.txt ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ {one line to give the program's name and a brief idea of what it does.}
635
+ Copyright (C) {year} {name of author}
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ {project} Copyright (C) {year} {fullname}
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <http://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
freemius/README.md ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1 @@
 
1
+ #fs_account .postbox,#fs_account .widefat{max-width:700px}#fs_account h3{font-size:1.3em;padding:12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #F1F1F1}#fs_account h3 .dashicons{width:26px;height:26px;font-size:1.3em}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .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 ADDED
@@ -0,0 +1,2 @@
 
 
1
+ #fs_addons .fs-cards-list{list-style:none}#fs_addons .fs-cards-list .fs-card{float:left;height:152px;width:310px;padding:0;margin:0 0 30px 30px;font-size:14px;list-style:none;border:1px solid #ddd;cursor:pointer;position:relative}#fs_addons .fs-cards-list .fs-card .fs-overlay{position:absolute;left:0;right:0;bottom:0;top:0;z-index:9}#fs_addons .fs-cards-list .fs-card .fs-inner{background-color:#fff;overflow:hidden;height:100%;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner ul{-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner li{list-style:none;line-height:18px;padding:0 15px;width:100%;display:block;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner{padding:0;margin:0;line-height:0;display:block;height:100px;background-repeat:repeat-x;background-size:100% 100%;-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-title{margin:10px 0 0 0;height:18px;overflow:hidden;color:#000;white-space:nowrap;text-overflow:ellipsis;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-offer{font-size:0.9em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-description{background-color:#f9f9f9;padding:10px 15px 100px 15px;border-top:1px solid #eee;margin:0 0 10px 0;color:#777}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-tag{position:absolute;top:10px;right:0px;background:greenyellow;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.3);box-shadow:1px 1px 1px rgba(0,0,0,0.3);text-transform:uppercase;font-size:0.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button{position:absolute;top:112px;right:10px}@media screen and (min-width: 960px){#fs_addons .fs-cards-list .fs-card:hover .fs-overlay{border:2px solid #29abe1;margin-left:-1px;margin-top:-1px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner ul{top:-100px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-title,#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-offer{color:#29abe1}}
2
+ #TB_window,#TB_window iframe{width:772px !important}#plugin-information #section-description h2,#plugin-information #section-description h3,#plugin-information #section-description p,#plugin-information #section-description b,#plugin-information #section-description i,#plugin-information #section-description blockquote,#plugin-information #section-description li,#plugin-information #section-description ul,#plugin-information #section-description ol{clear:none}#plugin-information #section-description .fs-selling-points{padding-bottom:10px;border-bottom:1px solid #ddd}#plugin-information #section-description .fs-selling-points ul{margin:0}#plugin-information #section-description .fs-selling-points ul li{padding:0;list-style:none outside none}#plugin-information #section-description .fs-selling-points ul li i.dashicons{color:#71ae00;font-size:3em;vertical-align:middle;line-height:30px;float:left;margin:0 0 0 -15px}#plugin-information #section-description .fs-selling-points ul li h3{margin:1em 30px !important}#plugin-information #section-description .fs-screenshots:after{content:"";display:table;clear:both}#plugin-information #section-description .fs-screenshots ul{list-style:none;margin:0}#plugin-information #section-description .fs-screenshots ul li{width:225px;height:225px;float:left;margin-bottom:20px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}#plugin-information #section-description .fs-screenshots ul li a{display:block;width:100%;height:100%;border:1px solid;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);background-size:cover}#plugin-information #section-description .fs-screenshots ul li.odd{margin-right:20px}#plugin-information .plugin-information-pricing{margin:-16px;border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan h3{margin-top:0;padding:20px;font-size:16px}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper{border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab{cursor:pointer;position:relative;padding:0 10px;font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:greenyellow;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid darkgreen;padding:2px;text-align:center;font-size:0.9em;line-height:1em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab.nav-tab-active{cursor:default;background:#fffeec;border-bottom-color:#fffeec}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle h3{background:#fffeec;margin:0;padding-bottom:0;color:#0073aa}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .nav-tab-wrapper,#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .fs-billing-frequency{display:none}#plugin-information .plugin-information-pricing .fs-plan .fs-pricing-body{background:#fffeec;padding:20px}#plugin-information .plugin-information-pricing .fs-plan .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing .fs-plan label{white-space:nowrap}#plugin-information .plugin-information-pricing .fs-plan var{font-style:normal}#plugin-information .plugin-information-pricing .fs-plan .fs-billing-frequency,#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-align:center;display:block;font-weight:bold;margin-bottom:10px;text-transform:uppercase;background:#F3F3F3;padding:2px;border:1px solid #ccc}#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-transform:none;color:green;background:greenyellow}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms i{float:left;margin:0 0 0 -15px}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms li{margin:10px 0 0 0}#plugin-information #section-features .fs-features{margin:-20px -26px}#plugin-information #section-features table{width:100%;border-spacing:0;border-collapse:separate}#plugin-information #section-features table thead th{padding:10px 0}#plugin-information #section-features table thead .fs-price{color:#71ae00;font-weight:normal;display:block;text-align:center}#plugin-information #section-features table tbody td{border-top:1px solid #ccc;padding:10px 0;text-align:center;width:100px;color:#71ae00}#plugin-information #section-features table tbody td:first-child{text-align:left;width:auto;color:inherit;padding-left:26px}#plugin-information #section-features table tbody tr.fs-odd td{background:#fefefe}#plugin-information #section-features .dashicons-yes{width:30px;height:30px;font-size:30px}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}
freemius/assets/css/admin/checkout.css ADDED
@@ -0,0 +1 @@
 
1
+ @media screen and (max-width: 782px){#wpbody-content{padding-bottom:0 !important}}
freemius/assets/css/admin/common.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .theme-browser .theme .fs-premium-theme-badge{position:absolute;top:10px;right:0;background:#71ae00;color:#fff;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);font-size:1.1em}#iframe{line-height:0;font-size:0}.fs-full-size-wrapper{margin:40px 0 -65px -20px}@media (max-width: 600px){.fs-full-size-wrapper{margin:0 0 -65px -10px}}
2
+ .fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,0.3);color:#fff;padding:2px 10px;position:absolute;top:100%;bottom:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}div.fs-notice.updated,div.fs-notice.success,div.fs-notice.promotion{display:block !important}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;-moz-box-shadow:0 2px 2px rgba(6,113,6,0.3);-webkit-box-shadow:0 2px 2px rgba(6,113,6,0.3);box-shadow:0 2px 2px rgba(6,113,6,0.3);opacity:0.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}.fs-secure-notice a.fs-security-proof{color:green;text-decoration:none}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 600px){.fs-secure-notice{display:none}}@media screen and (max-width: 500px){#fs_promo_tab{display:none}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}.fs-submenu-item.pricing.upgrade-mode{color:greenyellow}.fs-submenu-item.pricing.trial-mode{color:#83e2ff}#adminmenu .update-plugins.fs-trial{background-color:#00b9eb}.fs-ajax-spinner{border:0;width:20px;height:20px;margin-right:5px;vertical-align:sub;display:inline-block;background:url("../../../../../../../wp-admin/images/wpspin_light-2x.gif");background-size:contain}.wrap.fs-section h2{text-align:left}
freemius/assets/css/admin/connect.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,0.3);box-shadow:0px 1px 2px rgba(0,0,0,0.3);margin:20px 0}@media screen and (max-width: 479px){#fs_connect{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;width:auto;margin:0 0 0 -10px}}#fs_connect .fs-content{background:#fff;padding:15px 20px}#fs_connect .fs-content .fs-error{background:snow;color:#d3135a;border:1px solid #d3135a;-moz-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);text-align:center;padding:5px;margin-bottom:10px}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-license-key-container{position:relative;width:280px;margin:10px auto 0 auto}#fs_connect .fs-license-key-container input{width:100%}#fs_connect .fs-license-key-container .dashicons{position:absolute;top:5px;right:5px}#fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}#fs_connect .fs-actions .button{padding:0 10px 1px;line-height:35px;height:37px;font-size:16px;margin-bottom:0}#fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}#fs_connect .fs-actions .button.button-primary{padding-right:15px;padding-left:15px}#fs_connect .fs-actions .button.button-primary:after{content:' \279C'}#fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}#fs_connect .fs-actions .button.button-secondary{float:right}#fs_connect.fs-anonymous-disabled .fs-actions .button.button-primary{width:100%}#fs_connect .fs-permissions{padding:10px 20px;background:#FEFEFE;-moz-transition:background 0.5s ease;-o-transition:background 0.5s ease;-ms-transition:background 0.5s ease;-webkit-transition:background 0.5s ease;transition:background 0.5s ease}#fs_connect .fs-permissions .fs-license-sync-disclaimer{text-align:center;margin-top:0}#fs_connect .fs-permissions .fs-trigger{font-size:0.9em;text-decoration:none;text-align:center;display:block}#fs_connect .fs-permissions ul{height:0;overflow:hidden;margin:0}#fs_connect .fs-permissions ul li{margin-bottom:12px}#fs_connect .fs-permissions ul li:last-child{margin-bottom:0}#fs_connect .fs-permissions ul li i.dashicons{float:left;font-size:40px;width:40px;height:40px}#fs_connect .fs-permissions ul li div{margin-left:55px}#fs_connect .fs-permissions ul li div span{font-weight:bold;text-transform:uppercase;color:#23282d}#fs_connect .fs-permissions ul li div p{margin:2px 0 0 0}#fs_connect .fs-permissions.fs-open{background:#fff}#fs_connect .fs-permissions.fs-open ul{height:auto;margin:20px 20px 10px 20px}@media screen and (max-width: 479px){#fs_connect .fs-permissions{background:#fff}#fs_connect .fs-permissions .fs-trigger{display:none}#fs_connect .fs-permissions ul{height:auto;margin:20px}}#fs_connect .fs-freemium-licensing{padding:8px;background:#777;color:#fff}#fs_connect .fs-freemium-licensing p{text-align:center;display:block;margin:0;padding:0}#fs_connect .fs-freemium-licensing a{color:#C2EEFF;text-decoration:underline}#fs_connect .fs-visual{padding:12px;line-height:0;background:#fafafa;height:80px;position:relative}#fs_connect .fs-visual .fs-site-icon{position:absolute;left:20px;top:10px}#fs_connect .fs-visual .fs-connect-logo{position:absolute;right:20px;top:10px}#fs_connect .fs-visual .fs-plugin-icon{position:absolute;top:10px;left:50%;margin-left:-40px}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-site-icon,#fs_connect .fs-visual img,#fs_connect .fs-visual object{width:80px;height:80px}#fs_connect .fs-visual .dashicons-wordpress{font-size:64px;background:#01749a;color:#fff;width:64px;height:64px;padding:8px}#fs_connect .fs-visual .dashicons-plus{position:absolute;top:50%;font-size:30px;margin-top:-10px;color:#bbb}#fs_connect .fs-visual .dashicons-plus.fs-first{left:28%}#fs_connect .fs-visual .dashicons-plus.fs-second{left:65%}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-connect-logo,#fs_connect .fs-visual .fs-site-icon{border:1px solid #ccc;padding:1px;background:#fff}#fs_connect .fs-terms{text-align:center;font-size:0.85em;padding:5px;background:rgba(0,0,0,0.05)}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:' \000bb'}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-permissions ul li div{margin-right:55px;margin-left:0}.rtl #fs_connect .fs-permissions ul li i.dashicons{float:right}.rtl #fs_connect .fs-visual .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-visual .fs-connect-logo{right:auto;left:20px}#fs_theme_connect_wrapper{position:fixed;top:0;height:100%;width:100%;z-index:99990;background:rgba(0,0,0,0.75);text-align:center;overflow-y:auto}#fs_theme_connect_wrapper:before{content:"";display:inline-block;vertical-align:middle;height:100%}#fs_theme_connect_wrapper>button.close{color:white;cursor:pointer;height:40px;width:40px;position:absolute;right:0;border:0;background-color:transparent;top:32px}#fs_theme_connect_wrapper #fs_connect{top:0;text-align:left;display:inline-block;vertical-align:middle;margin-top:52px;margin-bottom:20px}#fs_theme_connect_wrapper #fs_connect .fs-terms{background:rgba(140,140,140,0.64)}#fs_theme_connect_wrapper #fs_connect .fs-terms,#fs_theme_connect_wrapper #fs_connect .fs-terms a{color:#c5c5c5}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}
freemius/assets/css/admin/deactivation-feedback.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}.fs-modal .fs-modal-dialog li.reason{margin-bottom:10px}.fs-modal .fs-modal-dialog li.reason .reason-input,.fs-modal .fs-modal-dialog li.reason .internal-message{margin-left:29px}.fs-modal .fs-modal-dialog li.reason label{display:table}.fs-modal .fs-modal-dialog li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}.fs-modal .reason-input,.fs-modal .internal-message{margin:3px 0 3px 22px}.fs-modal .reason-input input,.fs-modal .reason-input textarea,.fs-modal .internal-message input,.fs-modal .internal-message textarea{width:100%}.fs-modal li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}body.has-fs-modal{overflow:hidden}#the-list .deactivate>.fs-slug{display:none}
freemius/assets/css/admin/debug.css ADDED
@@ -0,0 +1 @@
 
1
+ .switch{position:relative;display:inline-block;font-size:1.6em;font-weight:bold;color:#ccc;text-shadow:0px 1px 1px rgba(255,255,255,0.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);border-radius:4px;background:#ececec;box-shadow:0px 0px 4px rgba(0,0,0,0.1),inset 0px 1px 3px 0px rgba(0,0,0,0.1);cursor:pointer}.switch span{display:inline-block;width:35px;text-transform:uppercase}.switch span.on{color:#6bc406}.switch .toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.3);border-radius:4px;background:#fff;background:-moz-linear-gradient(top, #ececec 0%, #fff 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));background:-webkit-linear-gradient(top, #ececec 0%, #fff 100%);background:-o-linear-gradient(top, #ececec 0%, #fff 100%);background:-ms-linear-gradient(top, #ececec 0%, #fff 100%);background:linear-gradient(top, #ececec 0%, #fff 100%);box-shadow:inset 0px 1px 0px 0px rgba(255,255,255,0.5);z-index:999;-moz-transition:all 0.15s ease-in-out;-o-transition:all 0.15s ease-in-out;-ms-transition:all 0.15s ease-in-out;-webkit-transition:all 0.15s ease-in-out;transition:all 0.15s ease-in-out}.switch.on .toggle{left:2%}.switch.off .toggle{left:54%}.switch.round{padding:0px 20px;border-radius:40px}.switch.round .toggle{border-radius:40px;width:14px;height:14px}.switch.round.on .toggle{left:3%;background:#6bc406}.switch.round.off .toggle{left:58%}.switch-label{font-size:20px;line-height:31px;margin:0 5px}#fs_log_book table{font-family:Consolas,Monaco,monospace;font-size:12px}#fs_log_book table th{color:#ccc}#fs_log_book table tr{background:#232525}#fs_log_book table tr.alternate{background:#2b2b2b}#fs_log_book table tr td.fs-col--logger{color:#5a7435}#fs_log_book table tr td.fs-col--type{color:#ffc861}#fs_log_book table tr td.fs-col--function{color:#a7b7b1;font-weight:bold}#fs_log_book table tr td.fs-col--message,#fs_log_book table tr td.fs-col--message a{color:#9a73ac !important}#fs_log_book table tr td.fs-col--file{color:#d07922}#fs_log_book table tr td.fs-col--timestamp{color:#6596be}
freemius/assets/css/admin/dialog-boxes.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal.fs-success .fs-modal-header{border-bottom-color:#46b450}.fs-modal.fs-success .fs-modal-body{background-color:#f7fff7}.fs-modal.fs-warn .fs-modal-header{border-bottom-color:#ffb900}.fs-modal.fs-warn .fs-modal-body{background-color:#fff8e5}.fs-modal.fs-error .fs-modal-header{border-bottom-color:#dc3232}.fs-modal.fs-error .fs-modal-body{background-color:#ffeaea}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-header{border-bottom:#eeeeee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative;margin-bottom:-10px}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:0.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all 0.2s ease-in-out;-o-transition:all 0.2s ease-in-out;-ms-transition:all 0.2s ease-in-out;-webkit-transition:all 0.2s ease-in-out;transition:all 0.2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-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 .email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend.fs-freemium input.email-address{width:300px}.fs-modal.fs-modal-license-key-resend.fs-freemium label{display:block;margin-bottom:10px}.fs-modal.fs-modal-license-key-resend.fs-premium input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{float:right;margin-left:7px}@media (max-width: 650px){.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{margin-top:2px}}
2
+ .rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}.fs-ajax-loader{position:relative;width:170px;height:20px;margin:auto}.fs-ajax-loader .fs-ajax-loader-bar{position:absolute;top:0;background-color:#0074a3;width:20px;height:20px;-webkit-animation-name:bounce_ajaxLoader;-moz-animation-name:bounce_ajaxLoader;-ms-animation-name:bounce_ajaxLoader;-o-animation-name:bounce_ajaxLoader;animation-name:bounce_ajaxLoader;-webkit-animation-duration:1.5s;-moz-animation-duration:1.5s;-ms-animation-duration:1.5s;-o-animation-duration:1.5s;animation-duration:1.5s;animation-iteration-count:infinite;-o-animation-iteration-count:infinite;-ms-animation-iteration-count:infinite;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;-webkit-animation-direction:normal;-moz-animation-direction:normal;-ms-animation-direction:normal;-o-animation-direction:normal;animation-direction:normal;-moz-transform:0.3;-o-transform:0.3;-ms-transform:0.3;-webkit-transform:0.3;transform:0.3}.fs-ajax-loader .fs-ajax-loader-bar-1{left:0px;animation-delay:0.6s;-o-animation-delay:0.6s;-ms-animation-delay:0.6s;-webkit-animation-delay:0.6s;-moz-animation-delay:0.6s}.fs-ajax-loader .fs-ajax-loader-bar-2{left:19px;animation-delay:0.75s;-o-animation-delay:0.75s;-ms-animation-delay:0.75s;-webkit-animation-delay:0.75s;-moz-animation-delay:0.75s}.fs-ajax-loader .fs-ajax-loader-bar-3{left:38px;animation-delay:0.9s;-o-animation-delay:0.9s;-ms-animation-delay:0.9s;-webkit-animation-delay:0.9s;-moz-animation-delay:0.9s}.fs-ajax-loader .fs-ajax-loader-bar-4{left:57px;animation-delay:1.05s;-o-animation-delay:1.05s;-ms-animation-delay:1.05s;-webkit-animation-delay:1.05s;-moz-animation-delay:1.05s}.fs-ajax-loader .fs-ajax-loader-bar-5{left:76px;animation-delay:1.2s;-o-animation-delay:1.2s;-ms-animation-delay:1.2s;-webkit-animation-delay:1.2s;-moz-animation-delay:1.2s}.fs-ajax-loader .fs-ajax-loader-bar-6{left:95px;animation-delay:1.35s;-o-animation-delay:1.35s;-ms-animation-delay:1.35s;-webkit-animation-delay:1.35s;-moz-animation-delay:1.35s}.fs-ajax-loader .fs-ajax-loader-bar-7{left:114px;animation-delay:1.5s;-o-animation-delay:1.5s;-ms-animation-delay:1.5s;-webkit-animation-delay:1.5s;-moz-animation-delay:1.5s}.fs-ajax-loader .fs-ajax-loader-bar-8{left:133px;animation-delay:1.65s;-o-animation-delay:1.65s;-ms-animation-delay:1.65s;-webkit-animation-delay:1.65s;-moz-animation-delay:1.65s}@-moz-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-ms-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-o-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-webkit-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}.fs-modal-auto-install #request-filesystem-credentials-form h2,.fs-modal-auto-install #request-filesystem-credentials-form .request-filesystem-credentials-action-buttons{display:none}.fs-modal-auto-install #request-filesystem-credentials-form input[type=password],.fs-modal-auto-install #request-filesystem-credentials-form input[type=email],.fs-modal-auto-install #request-filesystem-credentials-form input[type=text]{-webkit-appearance:none;padding:10px 10px 5px 10px;width:300px;max-width:100%}.fs-modal-auto-install #request-filesystem-credentials-form>div,.fs-modal-auto-install #request-filesystem-credentials-form label,.fs-modal-auto-install #request-filesystem-credentials-form fieldset{width:300px;max-width:100%;margin:0 auto;display:block}
freemius/assets/css/admin/license-activation.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body .license-activation-message{margin:0;display:none}.fs-modal .fs-modal-body input.license_key{width:100%}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}body.has-fs-modal{overflow:hidden}
freemius/assets/css/customizer.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_customizer_upsell .fs-customizer-plan{padding:10px 20px 20px 20px;border-radius:3px;background:#fff}#fs_customizer_upsell .fs-customizer-plan h2{position:relative;margin:0;line-height:2em;text-transform:uppercase}#fs_customizer_upsell .fs-customizer-plan h2 .button-link{top:-2px}#fs_customizer_upsell .fs-feature{position:relative}#fs_customizer_upsell .dashicons-yes{color:#0085ba;font-size:2em;vertical-align:bottom;margin-left:-7px;margin-right:10px}.rtl #fs_customizer_upsell .dashicons-yes{margin-left:10px;margin-right:-7px}#fs_customizer_upsell .dashicons-editor-help{color:#bbb;cursor:help}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:#000;color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{text-align:right}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:#000 transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{right:21px;left:auto}#fs_customizer_upsell .dashicons-editor-help:hover .fs-feature-desc{visibility:visible;opacity:1}#fs_customizer_upsell .button-primary{display:block;text-align:center;margin-top:10px}#fs_customizer_support{display:block !important}#fs_customizer_support .button{float:right}#fs_customizer_support .button-group{width:100%;display:block;margin-top:10px}#fs_customizer_support .button-group .button{float:none;width:50%;text-align:center}
freemius/assets/img/plugin-icon.png ADDED
Binary file
freemius/assets/img/theme-icon.png ADDED
Binary file
freemius/assets/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/assets/js/nojquery.ba-postmessage.js ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ *
9
+ * Non-jQuery fork by Jeff Lee
10
+ *
11
+ * This fork consists of the following changes:
12
+ * 1. Basic code cleanup and restructuring, for legibility.
13
+ * 2. The `postMessage` and `receiveMessage` functions can be bound arbitrarily,
14
+ * in terms of both function names and object scope. Scope is specified by
15
+ * the the "this" context of NoJQueryPostMessageMixin();
16
+ * 3. I've removed the check for Opera 9.64, which used `$.browser`. There were
17
+ * at least three different GitHub users requesting the removal of this
18
+ * "Opera sniff" on the original project's Issues page, so I figured this
19
+ * would be a relatively safe change.
20
+ * 4. `postMessage` no longer uses `$.param` to serialize messages that are not
21
+ * strings. I actually prefer this structure anyway. `receiveMessage` does
22
+ * not implement a corresponding deserialization step, and as such it seems
23
+ * cleaner and more symmetric to leave both data serialization and
24
+ * deserialization to the client.
25
+ * 5. The use of `$.isFunction` is replaced by a functionally-identical check.
26
+ * 6. The `$:nomunge` YUI option is no longer necessary.
27
+ */
28
+
29
+ function NoJQueryPostMessageMixin(postBinding, receiveBinding) {
30
+
31
+ var setMessageCallback, unsetMessageCallback, currentMsgCallback,
32
+ intervalId, lastHash, cacheBust = 1;
33
+
34
+ if (window.postMessage) {
35
+
36
+ if (window.addEventListener) {
37
+ setMessageCallback = function(callback) {
38
+ window.addEventListener('message', callback, false);
39
+ }
40
+
41
+ unsetMessageCallback = function(callback) {
42
+ window.removeEventListener('message', callback, false);
43
+ }
44
+ } else {
45
+ setMessageCallback = function(callback) {
46
+ window.attachEvent('onmessage', callback);
47
+ }
48
+
49
+ unsetMessageCallback = function(callback) {
50
+ window.detachEvent('onmessage', callback);
51
+ }
52
+ }
53
+
54
+ this[postBinding] = function(message, targetUrl, target) {
55
+ if (!targetUrl) {
56
+ return;
57
+ }
58
+
59
+ // The browser supports window.postMessage, so call it with a targetOrigin
60
+ // set appropriately, based on the targetUrl parameter.
61
+ target.postMessage( message, targetUrl.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
62
+ }
63
+
64
+ // Since the browser supports window.postMessage, the callback will be
65
+ // bound to the actual event associated with window.postMessage.
66
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
67
+ // Unbind an existing callback if it exists.
68
+ if (currentMsgCallback) {
69
+ unsetMessageCallback(currentMsgCallback);
70
+ currentMsgCallback = null;
71
+ }
72
+
73
+ if (!callback) {
74
+ return false;
75
+ }
76
+
77
+ // Bind the callback. A reference to the callback is stored for ease of
78
+ // unbinding.
79
+ currentMsgCallback = setMessageCallback(function(e) {
80
+ switch(Object.prototype.toString.call(sourceOrigin)) {
81
+ case '[object String]':
82
+ if (sourceOrigin !== e.origin) {
83
+ return false;
84
+ }
85
+ break;
86
+ case '[object Function]':
87
+ if (sourceOrigin(e.origin)) {
88
+ return false;
89
+ }
90
+ break;
91
+ }
92
+
93
+ callback(e);
94
+ });
95
+ };
96
+
97
+ } else {
98
+
99
+ this[postBinding] = function(message, targetUrl, target) {
100
+ if (!targetUrl) {
101
+ return;
102
+ }
103
+
104
+ // The browser does not support window.postMessage, so set the location
105
+ // of the target to targetUrl#message. A bit ugly, but it works! A cache
106
+ // bust parameter is added to ensure that repeat messages trigger the
107
+ // callback.
108
+ target.location = targetUrl.replace( /#.*$/, '' ) + '#' + (+new Date) + (cacheBust++) + '&' + message;
109
+ }
110
+
111
+ // Since the browser sucks, a polling loop will be started, and the
112
+ // callback will be called whenever the location.hash changes.
113
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
114
+ if (intervalId) {
115
+ clearInterval(intervalId);
116
+ intervalId = null;
117
+ }
118
+
119
+ if (callback) {
120
+ delay = typeof sourceOrigin === 'number'
121
+ ? sourceOrigin
122
+ : typeof delay === 'number'
123
+ ? delay
124
+ : 100;
125
+
126
+ intervalId = setInterval(function(){
127
+ var hash = document.location.hash,
128
+ re = /^#?\d+&/;
129
+ if ( hash !== lastHash && re.test( hash ) ) {
130
+ lastHash = hash;
131
+ callback({ data: hash.replace( re, '' ) });
132
+ }
133
+ }, delay );
134
+ }
135
+ };
136
+
137
+ }
138
+
139
+ return this;
140
+ }
freemius/assets/js/nojquery.ba-postmessage.min.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * nojquery-postmessage by Jeff Lee
3
+ * a non-jQuery fork of:
4
+ *
5
+ * jQuery postMessage - v0.5 - 9/11/2009
6
+ * http://benalman.com/projects/jquery-postmessage-plugin/
7
+ *
8
+ * Copyright (c) 2009 "Cowboy" Ben Alman
9
+ * Dual licensed under the MIT and GPL licenses.
10
+ * http://benalman.com/about/license/
11
+ */
12
+ function NoJQueryPostMessageMixin(g,a){var b,h,e,d,f,c=1;if(window.postMessage){if(window.addEventListener){b=function(i){window.addEventListener("message",i,false)};h=function(i){window.removeEventListener("message",i,false)}}else{b=function(i){window.attachEvent("onmessage",i)};h=function(i){window.detachEvent("onmessage",i)}}this[g]=function(i,k,j){if(!k){return}j.postMessage(i,k.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))};this[a]=function(k,j,i){if(e){h(e);e=null}if(!k){return false}e=b(function(l){switch(Object.prototype.toString.call(j)){case"[object String]":if(j!==l.origin){return false}break;case"[object Function]":if(j(l.origin)){return false}break}k(l)})}}else{this[g]=function(i,k,j){if(!k){return}j.location=k.replace(/#.*$/,"")+"#"+(+new Date)+(c++)+"&"+i};this[a]=function(k,j,i){if(d){clearInterval(d);d=null}if(k){i=typeof j==="number"?j:typeof i==="number"?i:100;d=setInterval(function(){var m=document.location.hash,l=/^#?\d+&/;if(m!==f&&l.test(m)){f=m;k({data:m.replace(l,"")})}},i)}}}return this};
freemius/assets/js/postmessage.js ADDED
@@ -0,0 +1,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);
freemius/assets/scss/_colors.scss ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $menu-hover-color: #333;
2
+ $darkest-color: #000;
3
+ $fms-live-color: #71ae00;
4
+ $fms-test-color: #f7941d;
5
+ $fms-link-color: #29abe1;
6
+ $fms-link-hover-color: darken(#29abe1, 10%);
7
+ $body-bkg: #111;
8
+ $special-color: #d3135a;
9
+ $body-color: #f1f1f1;
10
+ $fms-white: #f1f1f1;
11
+ $container-bkg: #222;
12
+ $container-bkg-odd: #262626;
13
+ $container-border-color: #333;
14
+ $table-head-bkg: #333;
15
+ $table-head-color: #999;
16
+ $info-color: #999;
17
+ $error-color: #ff0000;
18
+
19
+ $fs-logo-blue-color: #29abe1;
20
+ $fs-logo-green-color: #71ae00;
21
+ $fs-logo-magenta-color: #d3135a;
22
+
23
+ // WordPress colors.
24
+ $page-header-bkg: #333;
25
+ $page-header-color: $fms-white;
26
+ $text-dark-color: #333;
27
+ $text-light-color: #666;
28
+ $text-lightest-color: #999;
29
+
30
+ // Notices.
31
+ $wp-notice-success-color: #f7fff7;
32
+ $wp-notice-success-dark-color: #46b450;
33
+ $wp-notice-error-color: #ffeaea;
34
+ $wp-notice-error-dark-color: #dc3232;
35
+ $wp-notice-warn-color: #fff8e5;
36
+ $wp-notice-warn-dark-color: #ffb900;
37
+ $fs-notice-promotion-border-color: #00a0d2;
38
+ $fs-notice-promotion-bkg: #f2fcff;
39
+
40
+ // WP Buttons.
41
+ $button-primary-bkg: #6bc406;
42
+ $button-primary-color: $fms-white;
43
+ $button-secondary-bkg: #333;
44
+ $button-secondary-color: $fms-white;
45
+ $featured-color: #6bc406;
46
+ $wp-selected-color: #0074a3;
47
+
48
+ $wordpress_color: #01749A;
49
+ $blogger_color: #ff8100;
50
+ $wix_color: #fac102;
51
+ $shopify_color: #80d100;
52
+ $addthis_color: #fe6d4e;
53
+ $tumblr_color: #34506b;
54
+ $zepo_color: #00baf2;
55
+ $jquery_color: #000919;
56
+ $javascript_color: #00baf2;
57
+ $squarespace_color: #000;
58
+
59
+ $blog_color: #ff6600;
60
+ $facebook_color: #3b5998;
61
+ $twitter_color: #4099ff;
62
+ $linkedin_color: #4875b4;
63
+ $youtube_color: #ff3333;
64
+ $gplus_color: #c63d2d;
65
+
freemius/assets/scss/_functions.scss ADDED
File without changes
freemius/assets/scss/_load.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import 'mixins';
2
+ @import "vars";
3
+ @import "functions";
4
+ @import "colors";
freemius/assets/scss/_mixins.scss ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ---- CSS3 SASS MIXINS ----
2
+ // https://github.com/madr/css3-sass-mixins
3
+ //
4
+ // Copyright (C) 2011 by Anders Ytterström
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in
14
+ // all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ // THE SOFTWARE.
23
+ //
24
+
25
+ // ---- LEGACY IE SUPPORT USING FILTERS ----
26
+ // Should IE filters be used or not?
27
+ // PROS: gradients, drop shadows etc will be handled by css.
28
+ // CONS: will harm the site performance badly,
29
+ // especially on sites with heavy rendering and scripting.
30
+ $useIEFilters: 0;
31
+ // might be 0 or 1. disabled by default.
32
+ // ---- /LEGACY IE SUPPORT USING FILTERS ----
33
+
34
+
35
+ @mixin background-size ($value) {
36
+ -webkit-background-size: $value;
37
+ background-size: $value;
38
+ }
39
+
40
+ @mixin border-image ($path, $offsets, $repeats) {
41
+ -moz-border-image: $path $offsets $repeats;
42
+ -o-border-image: $path $offsets $repeats;
43
+ -webkit-border-image: $path $offsets $repeats;
44
+ border-image: $path $offsets $repeats;
45
+ }
46
+
47
+ @mixin border-radius ($values...) {
48
+ -moz-border-radius: $values;
49
+ -webkit-border-radius: $values;
50
+ border-radius: $values;
51
+ /*-moz-background-clip: padding;
52
+ -webkit-background-clip: padding-box;
53
+ background-clip: padding-box;*/
54
+ }
55
+
56
+ @mixin box-shadow ($values...) {
57
+ -moz-box-shadow: $values;
58
+ -webkit-box-shadow: $values;
59
+ box-shadow: $values;
60
+ }
61
+
62
+ //@mixin box-shadow ($x, $y, $offset, $hex, $ie: $useIEFilters, $inset: null, $spread:null) {
63
+ // -moz-box-shadow: $x $y $offset $spread $hex $inset;
64
+ // -webkit-box-shadow: $x $y $offset $spread $hex $inset;
65
+ // box-shadow: $x $y $offset $spread $hex $inset;
66
+ //
67
+ // @if $ie == 1 {
68
+ // $iecolor: '#' + red($hex) + green($hex) + blue($hex);
69
+ // filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}');
70
+ // -ms-filter: quote(progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}'));
71
+ // }
72
+ //}
73
+
74
+ @mixin box-sizing($value) {
75
+ -moz-box-sizing: $value;
76
+ -webkit-box-sizing: $value;
77
+ box-sizing: $value;
78
+ }
79
+
80
+ // requires sass 3.2
81
+ @mixin keyframes($name){
82
+ @-moz-keyframes #{$name} { @content; }
83
+ @-ms-keyframes #{$name} { @content; }
84
+ @-o-keyframes #{$name} { @content; }
85
+ @-webkit-keyframes #{$name} { @content; }
86
+ @keyframes #{$name} { @content; }
87
+ }
88
+
89
+ @mixin linear-gradient($from, $to, $ie: $useIEFilters) {
90
+ @if $ie != 1 { background-color: $to; }
91
+
92
+ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, $from),color-stop(1, $to));
93
+ background-image: -webkit-linear-gradient(top, $from, $to);
94
+ background-image: -moz-linear-gradient(top, $from, $to);
95
+ background-image: -ms-linear-gradient(top, $from, $to);
96
+ background-image: -o-linear-gradient(top, $from, $to);
97
+ background-image: linear-gradient(top, bottom, $from, $to);
98
+
99
+ @if $ie == 1 {
100
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
101
+ }
102
+ }
103
+
104
+ @mixin horizontal-gradient($startColor: #555, $endColor: #333, $ie: $useIEFilters) {
105
+ @if $ie != 1 { background-color: $endColor; }
106
+
107
+ background-color: $endColor;
108
+ background-image: -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
109
+ background-image: -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
110
+ background-image: -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
111
+ background-image: -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
112
+ background-image: linear-gradient(to right, $startColor, $endColor); // Standard, IE10
113
+ background-repeat: repeat-x;
114
+ @if $ie == 1 {
115
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$startColor}', endColorstr='#{$endColor}', GradientType=1);
116
+ }
117
+ }
118
+
119
+ @mixin radial-gradient($from, $to, $ie: $useIEFilters) {
120
+ @if $ie != 1 { background-color: $to; }
121
+
122
+ background: -moz-radial-gradient(center, circle cover, $from 0%, $to 100%);
123
+ background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, $from), color-stop(100%, $to));
124
+ background: -webkit-radial-gradient(center, circle cover, $from 0%, $to 100%);
125
+ background: -o-radial-gradient(center, circle cover, $from 0%, $to 100%);
126
+ background: -ms-radial-gradient(center, circle cover, $from 0%, $to 100%);
127
+ background: radial-gradient(center, circle cover, $from 0%, $to 100%);
128
+ background-color: $from;
129
+
130
+ @if $ie == 1 {
131
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}', GradientType=1); /* IE6-9 fallback on horizontal gradient */
132
+ }
133
+ }
134
+
135
+ /*@mixin 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
+ @mixin animation($str) {
196
+ -webkit-animation: #{$str};
197
+ -moz-animation: #{$str};
198
+ -ms-animation: #{$str};
199
+ -o-animation: #{$str};
200
+ animation: #{$str};
201
+ }
202
+
203
+ @mixin animation-name($str) {
204
+ -webkit-animation-name: #{$str};
205
+ -moz-animation-name: #{$str};
206
+ -ms-animation-name: #{$str};
207
+ -o-animation-name: #{$str};
208
+ animation-name: #{$str};
209
+ }
210
+
211
+ @mixin animation-duration($str) {
212
+ -webkit-animation-duration: #{$str};
213
+ -moz-animation-duration: #{$str};
214
+ -ms-animation-duration: #{$str};
215
+ -o-animation-duration: #{$str};
216
+ animation-duration: #{$str};
217
+ }
218
+
219
+ @mixin animation-direction($str) {
220
+ -webkit-animation-direction: #{$str};
221
+ -moz-animation-direction: #{$str};
222
+ -ms-animation-direction: #{$str};
223
+ -o-animation-direction: #{$str};
224
+ animation-direction: #{$str};
225
+ }
226
+
227
+ @mixin animation-delay($str) {
228
+ animation-delay:#{$str};
229
+ -o-animation-delay:#{$str};
230
+ -ms-animation-delay:#{$str};
231
+ -webkit-animation-delay:#{$str};
232
+ -moz-animation-delay:#{$str};
233
+ }
234
+
235
+ @mixin animation-iteration-count($str) {
236
+ animation-iteration-count:#{$str};
237
+ -o-animation-iteration-count:#{$str};
238
+ -ms-animation-iteration-count:#{$str};
239
+ -webkit-animation-iteration-count:#{$str};
240
+ -moz-animation-iteration-count:#{$str};
241
+ }
242
+
243
+ @mixin animation-timing-function($str) {
244
+ -webkit-animation-timing-function: #{$str};
245
+ -moz-animation-timing-function: #{$str};
246
+ -ms-animation-timing-function: #{$str};
247
+ -o-animation-timing-function: #{$str};
248
+ animation-timing-function: #{$str};
249
+ }
250
+
251
+ // ==== /CSS3 SASS MIXINS ====
252
+
253
+ @mixin opacity($opacity) {
254
+ opacity: $opacity;
255
+ $opacity-ie: $opacity * 100;
256
+ filter: alpha(opacity=$opacity-ie); //IE8
257
+ }
258
+
259
+ @mixin size($width, $height: $width)
260
+ {
261
+ width: $width;
262
+ height: $height;
263
+ }
264
+
265
+ @mixin clearfix
266
+ {
267
+ &:after {
268
+ content: "";
269
+ display: table;
270
+ clear: both;
271
+ }
272
+ }
273
+
274
+ // Placeholder text
275
+ @mixin placeholder($color: $input-color-placeholder) {
276
+ // Firefox
277
+ &::-moz-placeholder {
278
+ color: $color;
279
+ opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
280
+ }
281
+ &:-ms-input-placeholder { color: $color; } // Internet Explorer 10+
282
+ &::-webkit-input-placeholder { color: $color; } // Safari and Chrome
283
+ }
freemius/assets/scss/_start.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import "vars";
2
+ @import "colors";
3
+ @import "mixins";
4
+ @import "functions";
freemius/assets/scss/_vars.scss ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ $is_production: true;
2
+
3
+ $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
+
5
+ $layout_width: 960px;
6
+ $admin_mobile_max_width: 782px;
freemius/assets/scss/admin/_ajax-loader.scss ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $color: $wp-selected-color;
2
+ $bkg-color: #fff;
3
+ $size: 20;
4
+
5
+ .fs-ajax-loader
6
+ {
7
+ position: relative;
8
+ width: #{8*$size + 10}px;
9
+ height: #{$size}px;
10
+ margin: auto;
11
+
12
+ .fs-ajax-loader-bar
13
+ {
14
+ position: absolute;
15
+ top: 0;
16
+ background-color: $color;
17
+ width: #{$size}px;
18
+ height: #{$size}px;
19
+ @include animation-name(bounce_ajaxLoader);
20
+ @include animation-duration(1.5s);
21
+ @include animation-iteration-count(infinite);
22
+ @include animation-direction(normal);
23
+ @include transform(.3);
24
+ }
25
+
26
+ @for $i from 0 through 7
27
+ {
28
+ .fs-ajax-loader-bar-#{$i + 1}
29
+ {
30
+ left: #{$i*($size - 1)}px;
31
+ @include animation-delay(#{0.6 + $i*0.15}s);
32
+ }
33
+ }
34
+ }
35
+
36
+ @include keyframes(bounce_ajaxLoader)
37
+ {
38
+ 0%
39
+ {
40
+ @include transform(scale(1));
41
+ background-color: $color;
42
+ }
43
+
44
+ 100%
45
+ {
46
+ @include transform(scale(.3));
47
+ background-color: $bkg-color;
48
+ }
49
+ }
freemius/assets/scss/admin/_auto-install.scss ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal-auto-install
2
+ {
3
+ $max-width: 300px;
4
+
5
+ #request-filesystem-credentials-form
6
+ {
7
+ h2,
8
+ .request-filesystem-credentials-action-buttons
9
+ {
10
+ display: none;
11
+ }
12
+
13
+ input[type=password],
14
+ input[type=email],
15
+ input[type=text]
16
+ {
17
+ -webkit-appearance: none;
18
+ padding: 10px 10px 5px 10px;
19
+ width: $max-width;
20
+ max-width: 100%;
21
+ }
22
+
23
+ > div,
24
+ label,
25
+ fieldset
26
+ {
27
+ width: $max-width;
28
+ max-width: 100%;
29
+ margin: 0 auto;
30
+ display: block;
31
+ }
32
+ }
33
+ }
freemius/assets/scss/admin/_deactivation-feedback.scss ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+
3
+ .fs-modal.fs-modal-deactivation-feedback {
4
+ .reason-input, .internal-message {
5
+ margin: 3px 0 3px 22px;
6
+
7
+ input, textarea {
8
+ width: 100%;
9
+ }
10
+ }
11
+
12
+ li.reason {
13
+ &.has-internal-message .internal-message {
14
+ border: 1px solid lighten($darkest-color, 80%);
15
+ padding: 7px;
16
+ display: none;
17
+ }
18
+
19
+ @media (max-width: 650px) {
20
+ li.reason {
21
+ margin-bottom: 10px;
22
+
23
+ .reason-input, .internal-message {
24
+ margin-left: 29px;
25
+ }
26
+
27
+ label {
28
+ display: table;
29
+
30
+ > span {
31
+ display: table-cell;
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ .anonymous-feedback-label {
40
+ float: left;
41
+ }
42
+
43
+ .fs-modal-panel {
44
+ margin-top: 0 !important;
45
+
46
+ h3 {
47
+ margin-top: 0;
48
+ line-height: 1.5em;
49
+ }
50
+ }
51
+ }
52
+
53
+ #the-list .deactivate > .fs-slug {
54
+ display: none;
55
+ }
freemius/assets/scss/admin/_license-activation.scss ADDED
@@ -0,0 +1,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 ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-key-resend
2
+ {
3
+ .email-address-container
4
+ {
5
+ overflow: hidden;
6
+ padding-right: 2px;
7
+ }
8
+
9
+ &.fs-freemium
10
+ {
11
+ input.email-address
12
+ {
13
+ width: 300px;
14
+ }
15
+
16
+ label
17
+ {
18
+ display: block;
19
+ margin-bottom: 10px;
20
+ }
21
+ }
22
+
23
+ &.fs-premium
24
+ {
25
+ input.email-address
26
+ {
27
+ width: 100%;
28
+ }
29
+
30
+ .button-container
31
+ {
32
+ float: right;
33
+ margin-left: 7px;
34
+
35
+ @media (max-width: 650px) {
36
+ margin-top: 2px;
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ .rtl
43
+ {
44
+ .fs-modal.fs-modal-license-key-resend
45
+ {
46
+ .fs-modal-body
47
+ {
48
+ .input-container > .email-address-container
49
+ {
50
+ padding-left: 2px;
51
+ padding-right: 0;
52
+ }
53
+
54
+ .button-container
55
+ {
56
+ float: left;
57
+ margin-right: 7px;
58
+ margin-left: 0;
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ a.show-license-resend-modal
65
+ {
66
+ margin-top: 4px;
67
+ display: inline-block;
68
+ }
freemius/assets/scss/admin/_modal-common.scss ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+ @import "../mixins";
3
+
4
+ .fs-modal {
5
+ position: fixed;
6
+ overflow: auto;
7
+ height: 100%;
8
+ width: 100%;
9
+ top: 0;
10
+ z-index: 100000;
11
+ display: none;
12
+ background: rgba(0, 0, 0, 0.6);
13
+
14
+ .fs-modal-dialog {
15
+ background: transparent;
16
+ position: absolute;
17
+ left: 50%;
18
+ margin-left: -298px;
19
+ padding-bottom: 30px;
20
+ top: -100%;
21
+ z-index: 100001;
22
+ width: 596px;
23
+
24
+ @media (max-width: 650px) {
25
+ margin-left: -50%;
26
+ box-sizing: border-box;
27
+ padding-left: 10px;
28
+ padding-right: 10px;
29
+ width: 100%;
30
+
31
+ .fs-modal-panel > h3 > strong {
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+
37
+ &.active {
38
+ display: block;
39
+
40
+ &:before {
41
+ display: block;
42
+ }
43
+
44
+ .fs-modal-dialog {
45
+ top: 10%;
46
+ }
47
+ }
48
+
49
+ &.fs-success {
50
+ .fs-modal-header {
51
+ border-bottom-color: $wp-notice-success-dark-color;
52
+ }
53
+
54
+ .fs-modal-body {
55
+ background-color: $wp-notice-success-color;
56
+ }
57
+ }
58
+
59
+ &.fs-warn {
60
+ .fs-modal-header {
61
+ border-bottom-color: $wp-notice-warn-dark-color;
62
+ }
63
+
64
+ .fs-modal-body {
65
+ background-color: $wp-notice-warn-color;
66
+ }
67
+ }
68
+
69
+ &.fs-error {
70
+ .fs-modal-header {
71
+ border-bottom-color: $wp-notice-error-dark-color;
72
+ }
73
+
74
+ .fs-modal-body {
75
+ background-color: $wp-notice-error-color;
76
+ }
77
+ }
78
+
79
+
80
+ .fs-modal-body,
81
+ .fs-modal-footer {
82
+ border: 0;
83
+ background: #fefefe;
84
+ padding: 20px;
85
+ }
86
+
87
+ .fs-modal-header {
88
+ border-bottom: #eeeeee solid 1px;
89
+ background: #fbfbfb;
90
+ padding: 15px 20px;
91
+ position: relative;
92
+ margin-bottom: -10px;
93
+ // z-index: 2;
94
+
95
+ h4 {
96
+ margin: 0;
97
+ padding: 0;
98
+ text-transform: uppercase;
99
+ font-size: 1.2em;
100
+ font-weight: bold;
101
+ color: #cacaca;
102
+ text-shadow: 1px 1px 1px #fff;
103
+ letter-spacing: 0.6px;
104
+ -webkit-font-smoothing: antialiased;
105
+ }
106
+
107
+ .fs-close {
108
+ position: absolute;
109
+ right: 10px;
110
+ top: 12px;
111
+ cursor: pointer;
112
+ color: #bbb;
113
+ @include border-radius(20px);
114
+ padding: 3px;
115
+ @include transition(all 0.2s ease-in-out);
116
+
117
+ &:hover {
118
+ color: #fff;
119
+ background: #aaa;
120
+ }
121
+ }
122
+ }
123
+
124
+ .fs-modal-body {
125
+ border-bottom: 0;
126
+
127
+ p {
128
+ font-size: 14px;
129
+ }
130
+
131
+ h2 {
132
+ font-size: 20px;
133
+ line-height: 1.5em;
134
+ }
135
+
136
+ > div {
137
+ margin-top: 10px;
138
+
139
+ h2 {
140
+ font-weight: bold;
141
+ font-size: 20px;
142
+ margin-top: 0;
143
+ }
144
+ }
145
+ }
146
+
147
+ .fs-modal-footer {
148
+ border-top: #eeeeee solid 1px;
149
+ text-align: right;
150
+
151
+ > .button {
152
+ margin: 0 7px;
153
+
154
+ &:first-child {
155
+ margin: 0;
156
+ }
157
+ }
158
+ }
159
+
160
+ .fs-modal-panel {
161
+ > .notice.inline {
162
+ margin: 0;
163
+ display: none;
164
+ }
165
+
166
+ &:not(.active) {
167
+ display: none;
168
+ }
169
+ }
170
+ }
171
+
172
+ .rtl
173
+ {
174
+ .fs-modal {
175
+ .fs-modal-header {
176
+ .fs-close {
177
+ right: auto;
178
+ left: 20px;
179
+ }
180
+ }
181
+ }
182
+ }
183
+
184
+ body.has-fs-modal {
185
+ overflow: hidden;
186
+ }
freemius/assets/scss/admin/_themes.scss ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .theme-browser
2
+ {
3
+ .theme
4
+ {
5
+ .fs-premium-theme-badge
6
+ {
7
+ position: absolute;
8
+ top: 10px;
9
+ right: 0;
10
+ background: $fs-logo-green-color;
11
+ color: #fff;
12
+ text-transform: uppercase;
13
+ padding: 5px 10px;
14
+ @include border-radius(3px 0 0 3px);
15
+ font-weight: bold;
16
+ border-right: 0;
17
+ @include box-shadow(0 2px 1px -1px rgba(0, 0, 0, .3));
18
+ font-size: 1.1em;
19
+ }
20
+ }
21
+ }
freemius/assets/scss/admin/account.scss ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_account
4
+ {
5
+ .postbox,
6
+ .widefat
7
+ {
8
+ max-width: 700px;
9
+ }
10
+
11
+ h3
12
+ {
13
+ font-size: 1.3em;
14
+ padding: 12px 15px;
15
+ margin: 0 0 12px 0;
16
+ line-height: 1.4;
17
+ border-bottom: 1px solid #F1F1F1;
18
+
19
+ .dashicons {
20
+ width: 26px;
21
+ height: 26px;
22
+ font-size: 1.3em;
23
+ }
24
+ }
25
+
26
+ i.dashicons
27
+ {
28
+ font-size: 1.2em;
29
+ height: 1.2em;
30
+ width: 1.2em;
31
+ }
32
+
33
+ .button
34
+ {
35
+ i.dashicons
36
+ {
37
+ vertical-align: middle;
38
+ }
39
+ }
40
+
41
+ .fs-header-actions
42
+ {
43
+ position: absolute;
44
+ top: 17px;
45
+ right: 15px;
46
+ font-size: 0.9em;
47
+
48
+ ul
49
+ {
50
+ margin: 0;
51
+ }
52
+
53
+ li
54
+ {
55
+ form
56
+ {
57
+ display: inline-block;
58
+ }
59
+
60
+ float: left;
61
+ a
62
+ {
63
+ text-decoration: none;
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ #fs_account_details .button-group {
70
+ float: right;
71
+ }
72
+
73
+ .rtl #fs_account .fs-header-actions
74
+ {
75
+ left: 15px;
76
+ right: auto;
77
+ }
78
+
79
+ .fs-key-value-table
80
+ {
81
+ width: 100%;
82
+
83
+ form
84
+ {
85
+ display: inline-block;
86
+ }
87
+
88
+ tr
89
+ {
90
+ td:first-child
91
+ {
92
+ nobr
93
+ {
94
+ font-weight: bold;
95
+ }
96
+
97
+ text-align: right;
98
+
99
+ form
100
+ {
101
+ display: block;
102
+ }
103
+ }
104
+
105
+ td.fs-right
106
+ {
107
+ text-align: right;
108
+ }
109
+
110
+ &.fs-odd
111
+ {
112
+ background: #ebebeb;
113
+ }
114
+ }
115
+
116
+ td, th
117
+ {
118
+ padding: 10px;
119
+ }
120
+
121
+ code {
122
+ line-height: 28px;
123
+ }
124
+
125
+ var, code, input[type="text"]
126
+ {
127
+ color: #0073AA;
128
+ font-size: 16px;
129
+ background: none;
130
+ }
131
+
132
+ input[type="text"] {
133
+ width: 100%;
134
+ font-weight: bold;
135
+ }
136
+ }
137
+
138
+ label.fs-tag
139
+ {
140
+ background: #ffba00;
141
+ color: #fff;
142
+ display: inline-block;
143
+ border-radius: 3px;
144
+ padding: 5px;
145
+ font-size: 11px;
146
+ line-height: 11px;
147
+ vertical-align: baseline;
148
+
149
+ &.fs-warn
150
+ {
151
+ background: #ffba00;
152
+ }
153
+ &.fs-success
154
+ {
155
+ background: #46b450;
156
+ }
157
+ &.fs-error
158
+ {
159
+ background: #dc3232;
160
+ }
161
+ }
162
+
163
+ #fs_addons
164
+ {
165
+ h3
166
+ {
167
+ border: none;
168
+ margin-bottom: 0;
169
+ padding: 4px 5px;
170
+ }
171
+
172
+ td
173
+ {
174
+ vertical-align: middle;
175
+ }
176
+
177
+ thead {
178
+ white-space: nowrap;
179
+ }
180
+
181
+ td:first-child,
182
+ th:first-child
183
+ {
184
+ text-align: left;
185
+ font-weight: bold;
186
+ }
187
+ td:last-child,
188
+ th:last-child
189
+ {
190
+ text-align: right;
191
+ }
192
+ th
193
+ {
194
+ font-weight: bold;
195
+ }
196
+ }
197
+
198
+ #fs_billing_address {
199
+ width: 100%;
200
+
201
+ tr {
202
+ td {
203
+ width: 50%;
204
+ padding: 5px;
205
+ }
206
+
207
+ &:first-of-type {
208
+ td {
209
+ padding-top: 0;
210
+ }
211
+ }
212
+ }
213
+
214
+ @mixin read-mode {
215
+ border-color: transparent;
216
+ color: #777;
217
+ border-bottom: 1px dashed #ccc;
218
+ padding-left: 0;
219
+ background: none;
220
+ }
221
+
222
+ span {
223
+ font-weight: bold;
224
+ }
225
+
226
+ input, select {
227
+ @include placeholder(transparent);
228
+
229
+ display: block;
230
+ width: 100%;
231
+ margin-top: 5px;
232
+
233
+ &.fs-read-mode {
234
+ @include read-mode();
235
+ }
236
+ }
237
+
238
+
239
+ &.fs-read-mode {
240
+ td span {
241
+ display: none;
242
+ }
243
+
244
+ input, select
245
+ {
246
+ @include read-mode();
247
+ @include placeholder(#ccc);
248
+ }
249
+ }
250
+
251
+
252
+ button {
253
+ display: block;
254
+ width: 100%;
255
+ }
256
+ }
freemius/assets/scss/admin/add-ons.scss ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_addons
4
+ {
5
+ .fs-cards-list
6
+ {
7
+ list-style: none;
8
+
9
+ .fs-card
10
+ {
11
+ float: left;
12
+ // height: 185px; // With reviews/ratings
13
+ height: 152px;
14
+ width: 310px;
15
+ padding: 0;
16
+ margin: 0 0 30px 30px;
17
+ font-size: 14px;
18
+ list-style: none;
19
+ border: 1px solid #ddd;
20
+ cursor: pointer;
21
+ position: relative;
22
+
23
+ .fs-overlay
24
+ {
25
+ position: absolute;
26
+ left: 0;
27
+ right: 0;
28
+ bottom: 0;
29
+ top: 0;
30
+ z-index: 9;
31
+ }
32
+
33
+ .fs-inner
34
+ {
35
+ background-color: #fff;
36
+ overflow: hidden;
37
+ height: 100%;
38
+ position: relative;
39
+
40
+ ul
41
+ {
42
+ @include transition(all, 0.15s);
43
+ left: 0;
44
+ right: 0;
45
+ top: 0;
46
+ position: absolute;
47
+ }
48
+
49
+ li
50
+ {
51
+ list-style: none;
52
+ line-height: 18px;
53
+ padding: 0 15px;
54
+ width: 100%;
55
+ display: block;
56
+ @include box-sizing(border-box);
57
+ }
58
+
59
+ .fs-card-banner
60
+ {
61
+ padding: 0;
62
+ margin: 0;
63
+ line-height: 0;
64
+ display: block;
65
+ height: 100px;
66
+ background-repeat: repeat-x;
67
+ background-size: 100% 100%;
68
+ @include transition(all, 0.15s);
69
+ }
70
+
71
+ .fs-title
72
+ {
73
+ margin: 10px 0 0 0;
74
+ height: 18px;
75
+ overflow: hidden;
76
+ color: #000;
77
+ white-space: nowrap;
78
+ text-overflow: ellipsis;
79
+ font-weight: bold;
80
+ }
81
+
82
+ .fs-offer
83
+ {
84
+ font-size: 0.9em;
85
+ }
86
+
87
+ .fs-description
88
+ {
89
+ background-color: #f9f9f9;
90
+ padding: 10px 15px 100px 15px;
91
+ border-top: 1px solid #eee;
92
+ margin: 0 0 10px 0;
93
+ color: #777;
94
+ }
95
+
96
+ .fs-tag
97
+ {
98
+ position: absolute;
99
+ top: 10px;
100
+ right: 0px;
101
+ background: greenyellow;
102
+ display: block;
103
+ padding: 2px 10px;
104
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.3));
105
+ text-transform: uppercase;
106
+ font-size: 0.9em;
107
+ font-weight: bold;
108
+ }
109
+
110
+ .fs-cta
111
+ {
112
+ .button
113
+ {
114
+ position: absolute;
115
+ top: 112px;
116
+ right: 10px;
117
+ }
118
+ }
119
+ }
120
+
121
+ @media screen and (min-width: 960px) {
122
+ &:hover
123
+ {
124
+ .fs-overlay
125
+ {
126
+ border: 2px solid $fms-link-color;
127
+ margin-left: -1px;
128
+ margin-top: -1px;
129
+ }
130
+
131
+ .fs-inner
132
+ {
133
+ ul
134
+ {
135
+ top: -100px;
136
+ }
137
+
138
+ .fs-card-banner
139
+ {
140
+ // background-position: 50% -100px;
141
+ }
142
+
143
+ .fs-title,
144
+ .fs-offer
145
+ {
146
+ color: $fms-link-color;
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ #TB_window
156
+ {
157
+ &, iframe
158
+ {
159
+ width: 772px !important;
160
+ }
161
+ }
162
+
163
+ #plugin-information
164
+ {
165
+ #section-description
166
+ {
167
+ h2, h3, p, b, i, blockquote, li, ul, ol
168
+ {
169
+ clear: none;
170
+ }
171
+
172
+ .fs-selling-points
173
+ {
174
+ padding-bottom: 10px;
175
+ border-bottom: 1px solid #ddd;
176
+
177
+ ul
178
+ {
179
+ margin: 0;
180
+
181
+ li
182
+ {
183
+ padding: 0;
184
+ list-style: none outside none;
185
+
186
+ i.dashicons
187
+ {
188
+ color: $fs-logo-green-color;
189
+ font-size: 3em;
190
+ vertical-align: middle;
191
+ line-height: 30px;
192
+ float: left;
193
+ margin: 0 0 0 -15px;
194
+ }
195
+
196
+ h3
197
+ {
198
+ margin: 1em 30px !important;
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ .fs-screenshots
205
+ {
206
+ @include clearfix();
207
+ ul
208
+ {
209
+ list-style: none;
210
+ margin: 0;
211
+
212
+ li
213
+ {
214
+ width: 225px;
215
+ height: 225px;
216
+ float: left;
217
+ margin-bottom: 20px;
218
+ @include box-sizing(content-box);
219
+
220
+ a
221
+ {
222
+ display: block;
223
+ width: 100%;
224
+ height: 100%;
225
+ border: 1px solid;
226
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
227
+ background-size: cover;
228
+ }
229
+
230
+ &.odd
231
+ {
232
+ margin-right: 20px;
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ .plugin-information-pricing
240
+ {
241
+ $pricing_color: #FFFEEC;
242
+ $borders_color: #DDD;
243
+ margin: -16px;
244
+ // padding: 20px;
245
+ border-bottom: 1px solid $borders_color;
246
+
247
+ .fs-plan
248
+ {
249
+
250
+ h3
251
+ {
252
+ margin-top: 0;
253
+ padding: 20px;
254
+ font-size: 16px;
255
+ }
256
+
257
+ .nav-tab-wrapper
258
+ {
259
+ border-bottom: 1px solid $borders_color;
260
+
261
+ .nav-tab
262
+ {
263
+ cursor: pointer;
264
+ position: relative;
265
+ padding: 0 10px;
266
+ font-size: 0.9em;
267
+
268
+ label
269
+ {
270
+ text-transform: uppercase;
271
+ color: green;
272
+ background: greenyellow;
273
+ position: absolute;
274
+ left: -1px;
275
+ right: -1px;
276
+ bottom: 100%;
277
+ border: 1px solid darkgreen;
278
+ padding: 2px;
279
+ text-align: center;
280
+ font-size: 0.9em;
281
+ line-height: 1em;
282
+ }
283
+
284
+ &.nav-tab-active
285
+ {
286
+ cursor: default;
287
+ background: $pricing_color;
288
+ border-bottom-color: $pricing_color;
289
+ }
290
+ }
291
+ }
292
+
293
+ &.fs-single-cycle
294
+ {
295
+ h3
296
+ {
297
+ background: $pricing_color;
298
+ margin: 0;
299
+ padding-bottom: 0;
300
+ color: #0073aa;
301
+ }
302
+
303
+ .nav-tab-wrapper,
304
+ .fs-billing-frequency
305
+ {
306
+ display: none;
307
+ }
308
+ }
309
+
310
+ .fs-pricing-body
311
+ {
312
+ background: $pricing_color;
313
+ padding: 20px;
314
+ }
315
+
316
+ .button
317
+ {
318
+ width: 100%;
319
+ text-align: center;
320
+ font-weight: bold;
321
+ text-transform: uppercase;
322
+ font-size: 1.1em;
323
+ }
324
+
325
+ label
326
+ {
327
+ white-space: nowrap;
328
+ }
329
+
330
+ var {
331
+ font-style: normal;
332
+ }
333
+
334
+ .fs-billing-frequency,
335
+ .fs-annual-discount
336
+ {
337
+ text-align: center;
338
+ display: block;
339
+ font-weight: bold;
340
+ margin-bottom: 10px;
341
+ text-transform: uppercase;
342
+ background: #F3F3F3;
343
+ padding: 2px;
344
+ border: 1px solid #ccc;
345
+ }
346
+
347
+ .fs-annual-discount
348
+ {
349
+ text-transform: none;
350
+ color: green;
351
+ background: greenyellow;
352
+ }
353
+
354
+ ul.fs-trial-terms
355
+ {
356
+ font-size: 0.9em;
357
+
358
+ i
359
+ {
360
+ float: left;
361
+ margin: 0 0 0 -15px;
362
+ }
363
+
364
+ li
365
+ {
366
+ margin: 10px 0 0 0;
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ #section-features
373
+ {
374
+ .fs-features
375
+ {
376
+ margin: -20px -26px;
377
+ }
378
+
379
+ table
380
+ {
381
+ width: 100%;
382
+ border-spacing: 0;
383
+ border-collapse: separate;
384
+
385
+ thead
386
+ {
387
+ th
388
+ {
389
+ padding: 10px 0;
390
+ }
391
+
392
+ .fs-price
393
+ {
394
+ color: $fs-logo-green-color;
395
+ font-weight: normal;
396
+ display: block;
397
+ text-align: center;
398
+ }
399
+ }
400
+
401
+ tbody
402
+ {
403
+ td
404
+ {
405
+ border-top: 1px solid #ccc;
406
+ padding: 10px 0;
407
+ text-align: center;
408
+ width: 100px;
409
+ color: $fs-logo-green-color;
410
+
411
+ &:first-child
412
+ {
413
+ text-align: left;
414
+ width: auto;
415
+ color: inherit;
416
+ padding-left: 26px;
417
+ }
418
+ }
419
+ tr.fs-odd
420
+ {
421
+ td
422
+ {
423
+ background: #fefefe;
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ .dashicons-yes
430
+ {
431
+ width: 30px;
432
+ height: 30px;
433
+ font-size: 30px;
434
+ }
435
+ }
436
+ }
437
+
438
+ @media screen and (max-width: 961px) {
439
+ #fs_addons
440
+ {
441
+ .fs-cards-list
442
+ {
443
+ .fs-card
444
+ {
445
+ height: 265px;
446
+ }
447
+ }
448
+ }
449
+ }
freemius/assets/scss/admin/checkout.scss ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ @media screen and (max-width: 782px) {
2
+ #wpbody-content {
3
+ padding-bottom: 0 !important;
4
+ }
5
+ }
freemius/assets/scss/admin/common.scss ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "themes";
3
+
4
+ #iframe
5
+ {
6
+ line-height: 0;
7
+ font-size: 0;
8
+ }
9
+
10
+ .fs-full-size-wrapper
11
+ {
12
+ margin: 40px 0 -65px -20px;
13
+
14
+ @media (max-width: 600px) {
15
+ margin: 0 0 -65px -10px;
16
+ }
17
+ }
18
+
19
+ .fs-notice
20
+ {
21
+ position: relative;
22
+
23
+ &.fs-has-title
24
+ {
25
+ margin-bottom: 30px !important;
26
+ }
27
+
28
+ &.success
29
+ {
30
+ color: green;
31
+ // font-weight: normal;
32
+ }
33
+
34
+ &.promotion
35
+ {
36
+ border-color: $fs-notice-promotion-border-color !important;
37
+ background-color: $fs-notice-promotion-bkg !important;
38
+ }
39
+
40
+ .fs-notice-body
41
+ {
42
+ margin: .5em 0;
43
+ padding: 2px;
44
+ }
45
+
46
+ .fs-close
47
+ {
48
+ // position: absolute;
49
+ // top: 2px;
50
+ // bottom: 2px;
51
+ // right: 2px;
52
+ // min-width: 100px;
53
+ // text-align: center;
54
+ // padding-right: 2px;
55
+ cursor: pointer;
56
+ color: #aaa;
57
+ float: right;
58
+
59
+ &:hover
60
+ {
61
+ color: #666;
62
+ // background: #A9A9A9;
63
+ }
64
+
65
+ > *
66
+ {
67
+ margin-top: 7px;
68
+ display: inline-block;
69
+ }
70
+ }
71
+
72
+ label.fs-plugin-title
73
+ {
74
+ background: rgba(0, 0, 0, 0.3);
75
+ color: #fff;
76
+ padding: 2px 10px;
77
+ position: absolute;
78
+ top: 100%;
79
+ bottom: auto;
80
+ right: auto;
81
+ @include border-radius(0 0 3px 3px);
82
+ left: 10px;
83
+ font-size: 12px;
84
+ font-weight: bold;
85
+ cursor: auto;
86
+ }
87
+ }
88
+
89
+ div.fs-notice
90
+ {
91
+ &.updated,
92
+ &.success,
93
+ &.promotion
94
+ {
95
+ display: block !important;
96
+ }
97
+ }
98
+
99
+ .rtl .fs-notice
100
+ {
101
+ .fs-close
102
+ {
103
+ // left: 2px;
104
+ // right: auto;
105
+ // padding-right: 0;
106
+ // padding-left: 2px;
107
+ float: left;
108
+ }
109
+ }
110
+
111
+ .fs-secure-notice
112
+ {
113
+ position: fixed;
114
+ top: 32px;
115
+ left: 160px;
116
+ right: 0;
117
+ background: rgb(235, 253, 235);
118
+ padding: 10px 20px;
119
+ color: green;
120
+ z-index: 9999;
121
+ @include box-shadow(0 2px 2px rgba(6, 113, 6, 0.3));
122
+ @include opacity(0.95);
123
+
124
+ &:hover
125
+ {
126
+ @include opacity(1);
127
+ }
128
+
129
+ a.fs-security-proof
130
+ {
131
+ color: green;
132
+ text-decoration: none;
133
+ }
134
+ }
135
+
136
+ @media screen and (max-width: 960px) {
137
+ .fs-secure-notice
138
+ {
139
+ left: 36px;
140
+ }
141
+ }
142
+
143
+ @media screen and (max-width: 600px) {
144
+ .fs-secure-notice
145
+ {
146
+ display: none;
147
+ }
148
+ }
149
+
150
+ @media screen and (max-width: 500px) {
151
+ #fs_promo_tab
152
+ {
153
+ display: none;
154
+ }
155
+ }
156
+
157
+ @media screen and (max-width: 782px) {
158
+ .fs-secure-notice
159
+ {
160
+ left: 0;
161
+ top: 46px;
162
+ text-align: center;
163
+ }
164
+ }
165
+
166
+ span.fs-submenu-item.fs-sub:before
167
+ {
168
+ // Add small arrow.
169
+ content: '\21B3';
170
+ padding: 0 5px;
171
+ }
172
+
173
+ .rtl
174
+ {
175
+ span.fs-submenu-item.fs-sub:before
176
+ {
177
+ // Add small RTL arrow.
178
+ content: '\21B2';
179
+ }
180
+ }
181
+
182
+ .fs-submenu-item
183
+ {
184
+ &.pricing
185
+ {
186
+ &.upgrade-mode
187
+ {
188
+ color: greenyellow;
189
+ }
190
+
191
+ &.trial-mode
192
+ {
193
+ color: #83e2ff;
194
+ }
195
+ }
196
+ }
197
+
198
+ #adminmenu .update-plugins.fs-trial
199
+ {
200
+ background-color: #00b9eb;
201
+ }
202
+ .fs-ajax-spinner
203
+ {
204
+ border: 0;
205
+ width: 20px;
206
+ height: 20px;
207
+ margin-right: 5px;
208
+ vertical-align: sub;
209
+ display: inline-block;
210
+ background: url('../../../../../../../wp-admin/images/wpspin_light-2x.gif');
211
+ background-size: contain;
212
+ }
213
+
214
+ .wrap.fs-section {
215
+ h2 {
216
+ text-align: left;
217
+ }
218
+ }
freemius/assets/scss/admin/connect.scss ADDED
@@ -0,0 +1,520 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ $form_width: 480px;
4
+
5
+ #fs_connect
6
+ {
7
+ width: $form_width;
8
+ @include box-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
9
+ margin: 20px 0;
10
+
11
+ @media screen and (max-width: ($form_width - 1)) {
12
+ @include box-shadow(none);
13
+ width: auto;
14
+ margin: 0 0 0 -10px;
15
+ }
16
+
17
+ .fs-content
18
+ {
19
+ background: #fff;
20
+ padding: 15px 20px;
21
+
22
+ .fs-error {
23
+ background: snow;
24
+ color: $fs-logo-magenta-color;
25
+ border: 1px solid $fs-logo-magenta-color;
26
+ @include box-shadow(0 1px 1px 0 rgba(0,0,0,.1));
27
+ text-align: center;
28
+ padding: 5px;
29
+ margin-bottom: 10px;
30
+ }
31
+
32
+ p
33
+ {
34
+ margin: 0;
35
+ padding: 0;
36
+ font-size: 1.2em;
37
+ }
38
+ }
39
+
40
+ .fs-license-key-container {
41
+ position: relative;
42
+ width: 280px;
43
+ margin: 10px auto 0 auto;
44
+
45
+ input {
46
+ width: 100%;
47
+ }
48
+
49
+ .dashicons {
50
+ position: absolute;
51
+ top: 5px;
52
+ right: 5px;
53
+ }
54
+ }
55
+
56
+ .fs-actions
57
+ {
58
+ padding: 10px 20px;
59
+ background: #C0C7CA;
60
+
61
+ .button
62
+ {
63
+ padding: 0 10px 1px;
64
+ line-height: 35px;
65
+ height: 37px;
66
+ font-size: 16px;
67
+ margin-bottom: 0;
68
+
69
+ .dashicons
70
+ {
71
+ font-size: 37px;
72
+ margin-left: -8px;
73
+ margin-right: 12px;
74
+ }
75
+
76
+ &.button-primary
77
+ {
78
+ padding-right: 15px;
79
+ padding-left: 15px;
80
+
81
+ &:after
82
+ {
83
+ content: ' \279C';
84
+ }
85
+
86
+ &.fs-loading
87
+ {
88
+ &:after
89
+ {
90
+ content: '';
91
+ }
92
+ }
93
+ }
94
+
95
+ &.button-secondary
96
+ {
97
+ float: right;
98
+ }
99
+ }
100
+
101
+ // .fs-skip
102
+ // {
103
+ // line-height: 38px;
104
+ // vertical-align: middle;
105
+ // text-decoration: none;
106
+ // margin-left: 10px;
107
+ // }
108
+ }
109
+
110
+ &.fs-anonymous-disabled
111
+ {
112
+ .fs-actions
113
+ {
114
+ .button.button-primary
115
+ {
116
+ width: 100%;
117
+ }
118
+ }
119
+ }
120
+
121
+ .fs-permissions
122
+ {
123
+ padding: 10px 20px;
124
+ background: #FEFEFE;
125
+ // background: #F1F1F1;
126
+ @include transition(background 0.5s ease);
127
+
128
+ .fs-license-sync-disclaimer {
129
+ text-align: center;
130
+ margin-top: 0;
131
+ }
132
+
133
+ .fs-trigger
134
+ {
135
+ font-size: 0.9em;
136
+ text-decoration: none;
137
+ text-align: center;
138
+ display: block;
139
+ }
140
+
141
+ ul
142
+ {
143
+ height: 0;
144
+ overflow: hidden;
145
+ margin: 0;
146
+
147
+ li
148
+ {
149
+ margin-bottom: 12px;
150
+
151
+ &:last-child
152
+ {
153
+ margin-bottom: 0;
154
+ }
155
+
156
+ i.dashicons
157
+ {
158
+ float: left;
159
+ font-size: 40px;
160
+ width: 40px;
161
+ height: 40px;
162
+ }
163
+
164
+ div
165
+ {
166
+ margin-left: 55px;
167
+
168
+ span
169
+ {
170
+ font-weight: bold;
171
+ text-transform: uppercase;
172
+ color: #23282d;
173
+ }
174
+
175
+ p
176
+ {
177
+ margin: 2px 0 0 0;
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ &.fs-open
184
+ {
185
+ background: #fff;
186
+
187
+ ul
188
+ {
189
+ height: auto;
190
+ margin: 20px 20px 10px 20px;
191
+ }
192
+ }
193
+
194
+ @media screen and (max-width: ($form_width - 1)) {
195
+ background: #fff;
196
+
197
+ .fs-trigger
198
+ {
199
+ display: none;
200
+ }
201
+
202
+ ul
203
+ {
204
+ height: auto;
205
+ margin: 20px;
206
+ }
207
+ }
208
+ }
209
+
210
+ .fs-freemium-licensing {
211
+ padding: 8px;
212
+ // background: #0085BA;
213
+ background: #777;
214
+ color: #fff;
215
+
216
+ p {
217
+ text-align: center;
218
+ display: block;
219
+ margin: 0;
220
+ padding: 0;
221
+ }
222
+
223
+ a {
224
+ color: #C2EEFF;
225
+ text-decoration: underline;
226
+ }
227
+ }
228
+
229
+ $icon_size: 80px;
230
+ $wp_logo_padding: $icon_size / 10;
231
+ $icons_top: 10px;
232
+
233
+ .fs-visual
234
+ {
235
+ padding: 12px;
236
+ line-height: 0;
237
+ background: #fafafa;
238
+ height: $icon_size;
239
+ position: relative;
240
+
241
+ .fs-site-icon
242
+ {
243
+ position: absolute;
244
+ left: 20px;
245
+ top: $icons_top;
246
+ }
247
+
248
+ .fs-connect-logo
249
+ {
250
+ position: absolute;
251
+ right: 20px;
252
+ top: $icons_top;
253
+ }
254
+
255
+ .fs-plugin-icon
256
+ {
257
+ position: absolute;
258
+ top: $icons_top;
259
+ left: 50%;
260
+ margin-left: - ($icon_size / 2);
261
+ }
262
+
263
+ .fs-plugin-icon,
264
+ .fs-site-icon,
265
+ img,
266
+ object
267
+ {
268
+ width: $icon_size;
269
+ height: $icon_size;
270
+ }
271
+
272
+ .dashicons-wordpress
273
+ {
274
+ font-size: $icon_size - ($wp_logo_padding * 2);
275
+ background: $wordpress_color;
276
+ color: #fff;
277
+ width: $icon_size - ($wp_logo_padding * 2);
278
+ height: $icon_size - ($wp_logo_padding * 2);
279
+ padding: $wp_logo_padding;
280
+ }
281
+
282
+ .dashicons-plus
283
+ {
284
+ position: absolute;
285
+ top: 50%;
286
+ font-size: 30px;
287
+ margin-top: -10px;
288
+ color: #bbb;
289
+
290
+ &.fs-first
291
+ {
292
+ left: 28%;
293
+ }
294
+ &.fs-second
295
+ {
296
+ left: 65%;
297
+ }
298
+ }
299
+
300
+ .fs-plugin-icon,
301
+ .fs-connect-logo,
302
+ .fs-site-icon
303
+ {
304
+ border: 1px solid #ccc;
305
+ padding: 1px;
306
+ background: #fff;
307
+ }
308
+ }
309
+
310
+ .fs-terms
311
+ {
312
+ text-align: center;
313
+ font-size: 0.85em;
314
+ padding: 5px;
315
+ background: rgba(0, 0, 0, 0.05);
316
+
317
+ &, a
318
+ {
319
+ color: #999;
320
+ }
321
+
322
+ a
323
+ {
324
+ text-decoration: none;
325
+ }
326
+ }
327
+ }
328
+
329
+ .rtl
330
+ {
331
+ #fs_connect
332
+ {
333
+ .fs-actions
334
+ {
335
+ padding: 10px 20px;
336
+ background: #C0C7CA;
337
+
338
+ .button
339
+ {
340
+ .dashicons
341
+ {
342
+ font-size: 37px;
343
+ margin-left: -8px;
344
+ margin-right: 12px;
345
+ }
346
+
347
+ &.button-primary
348
+ {
349
+ &:after
350
+ {
351
+ content: ' \000bb';
352
+ }
353
+
354
+ &.fs-loading
355
+ {
356
+ &:after
357
+ {
358
+ content: '';
359
+ }
360
+ }
361
+ }
362
+
363
+ &.button-secondary
364
+ {
365
+ float: left;
366
+ }
367
+ }
368
+ }
369
+
370
+ .fs-permissions
371
+ {
372
+ ul
373
+ {
374
+ li
375
+ {
376
+ div
377
+ {
378
+ margin-right: 55px;
379
+ margin-left: 0;
380
+ }
381
+
382
+ i.dashicons
383
+ {
384
+ float: right;
385
+ }
386
+
387
+ }
388
+ }
389
+ }
390
+
391
+ .fs-visual
392
+ {
393
+ .fs-site-icon
394
+ {
395
+ right: 20px;
396
+ left: auto;
397
+ }
398
+
399
+ .fs-connect-logo
400
+ {
401
+ right: auto;
402
+ left: 20px;
403
+ }
404
+ }
405
+ }
406
+ }
407
+
408
+ #fs_theme_connect_wrapper {
409
+ position: fixed;
410
+ top: 0;
411
+ height: 100%;
412
+ width: 100%;
413
+ z-index: 99990;
414
+ background: rgba(0, 0, 0, 0.75);
415
+ text-align: center;
416
+ overflow-y: auto;
417
+
418
+ &:before {
419
+ content: "";
420
+ display: inline-block;
421
+ vertical-align: middle;
422
+ height: 100%;
423
+ }
424
+
425
+ > button.close {
426
+ color: white;
427
+ cursor: pointer;
428
+ height: 40px;
429
+ width: 40px;
430
+ position: absolute;
431
+ right: 0;
432
+ border: 0;
433
+ background-color: transparent;
434
+ top: 32px;
435
+ }
436
+
437
+ #fs_connect {
438
+ top: 0;
439
+ text-align: left;
440
+ display: inline-block;
441
+ vertical-align: middle;
442
+ margin-top: 52px;
443
+ margin-bottom: 20px;
444
+
445
+ .fs-terms
446
+ {
447
+ background: rgba(140, 140, 140, 0.64);
448
+
449
+ &, a
450
+ {
451
+ color: #c5c5c5;
452
+ }
453
+ }
454
+ }
455
+ }
456
+
457
+ .wp-pointer-content
458
+ {
459
+ #fs_connect
460
+ {
461
+ margin: 0;
462
+ @include box-shadow(none);
463
+ }
464
+ }
465
+
466
+ .fs-opt-in-pointer
467
+ {
468
+ .wp-pointer-content
469
+ {
470
+ padding: 0;
471
+ }
472
+
473
+ &.wp-pointer-top
474
+ {
475
+ .wp-pointer-arrow
476
+ {
477
+ border-bottom-color: #dfdfdf;
478
+ }
479
+ .wp-pointer-arrow-inner
480
+ {
481
+ border-bottom-color: #fafafa;
482
+ }
483
+ }
484
+
485
+ &.wp-pointer-bottom
486
+ {
487
+ .wp-pointer-arrow
488
+ {
489
+ border-top-color: #dfdfdf;
490
+ }
491
+ .wp-pointer-arrow-inner
492
+ {
493
+ border-top-color: #fafafa;
494
+ }
495
+ }
496
+
497
+ &.wp-pointer-left
498
+ {
499
+ .wp-pointer-arrow
500
+ {
501
+ border-right-color: #dfdfdf;
502
+ }
503
+ .wp-pointer-arrow-inner
504
+ {
505
+ border-right-color: #fafafa;
506
+ }
507
+ }
508
+
509
+ &.wp-pointer-right
510
+ {
511
+ .wp-pointer-arrow
512
+ {
513
+ border-left-color: #dfdfdf;
514
+ }
515
+ .wp-pointer-arrow-inner
516
+ {
517
+ border-left-color: #fafafa;
518
+ }
519
+ }
520
+ }
freemius/assets/scss/admin/debug.scss ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .switch
4
+ {
5
+ position: relative;
6
+ display: inline-block;
7
+ font-size: 1.6em;
8
+ font-weight: bold;
9
+ color: #ccc;
10
+ text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.8);
11
+ height: 18px;
12
+ padding: 6px 6px 5px 6px;
13
+ border: 1px solid #ccc;
14
+ border: 1px solid rgba(0, 0, 0, 0.2);
15
+ border-radius: 4px;
16
+ background: #ececec;
17
+ box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), inset 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
18
+ cursor: pointer;
19
+
20
+ span
21
+ {
22
+ display: inline-block; width: 35px;
23
+ text-transform: uppercase;
24
+
25
+ &.on
26
+ {
27
+ color: $button-primary-bkg;
28
+ }
29
+ }
30
+
31
+ .toggle
32
+ {
33
+ position: absolute;
34
+ top: 1px;
35
+ width: 37px;
36
+ height: 25px;
37
+ border: 1px solid #ccc;
38
+ border: 1px solid rgba(0, 0, 0, 0.3);
39
+ border-radius: 4px;
40
+ background: #fff;
41
+ background: -moz-linear-gradient(top, #ececec 0%, #fff 100%);
42
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));
43
+ background: -webkit-linear-gradient(top, #ececec 0%, #fff 100%);
44
+ background: -o-linear-gradient(top, #ececec 0%, #fff 100%);
45
+ background: -ms-linear-gradient(top, #ececec 0%, #fff 100%);
46
+ background: linear-gradient(top, #ececec 0%, #fff 100%);
47
+ box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, 0.5);
48
+ z-index: 999;
49
+ @include transition(all 0.15s ease-in-out);
50
+ }
51
+
52
+ &.on .toggle
53
+ {
54
+ left: 2%;
55
+ }
56
+ &.off .toggle
57
+ {
58
+ left: 54%;
59
+ }
60
+
61
+ /* Round switch */
62
+ &.round
63
+ {
64
+ padding: 0px 20px;
65
+ border-radius: 40px;
66
+
67
+ .toggle
68
+ {
69
+ border-radius: 40px;
70
+ width: 14px;
71
+ height: 14px;
72
+ }
73
+
74
+ &.on .toggle
75
+ {
76
+ left: 3%;
77
+ background: $button-primary-bkg;
78
+ }
79
+ &.off .toggle
80
+ {
81
+ left: 58%;
82
+ }
83
+ }
84
+ }
85
+
86
+ .switch-label
87
+ {
88
+ font-size: 20px;
89
+ line-height: 31px;
90
+ margin: 0 5px;
91
+ }
92
+
93
+ #fs_log_book {
94
+ table {
95
+ font-family: Consolas,Monaco,monospace;
96
+ font-size: 12px;
97
+
98
+ th {
99
+ color: #ccc;
100
+ }
101
+
102
+ tr {
103
+ background: #232525;
104
+
105
+ &.alternate {
106
+ background: #2b2b2b;
107
+ }
108
+
109
+ td {
110
+ &.fs-col--logger {
111
+ color: #5a7435;
112
+ }
113
+ &.fs-col--type {
114
+ color: #ffc861;
115
+ }
116
+ &.fs-col--function {
117
+ color: #a7b7b1;
118
+ font-weight: bold;
119
+ }
120
+ &.fs-col--message {
121
+ &, a
122
+ {
123
+ color: #9a73ac !important;
124
+ }
125
+ }
126
+ &.fs-col--file {
127
+ color: #d07922;
128
+ }
129
+ &.fs-col--timestamp {
130
+ color: #6596be;
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
freemius/assets/scss/admin/dialog-boxes.scss ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "modal-common";
3
+ @import "deactivation-feedback";
4
+ @import "license-activation";
5
+ @import "license-key-resend";
6
+ @import "ajax-loader";
7
+ @import "auto-install";
freemius/assets/scss/customizer.scss ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "start";
2
+
3
+ #fs_customizer_upsell {
4
+ .fs-customizer-plan {
5
+ padding: 10px 20px 20px 20px;
6
+ border-radius: 3px;
7
+ background: #fff;
8
+
9
+ h2 {
10
+ position: relative;
11
+ margin: 0;
12
+ line-height: 2em;
13
+ text-transform: uppercase;
14
+
15
+ .button-link {
16
+ top: -2px;
17
+ }
18
+ }
19
+ }
20
+
21
+ .fs-feature {
22
+ position: relative;
23
+ }
24
+
25
+ .dashicons-yes {
26
+ color: #0085ba;
27
+ font-size: 2em;
28
+ vertical-align: bottom;
29
+ margin-left: -7px;
30
+ margin-right: 10px;
31
+
32
+ .rtl & {
33
+ margin-left: 10px;
34
+ margin-right: -7px;
35
+ }
36
+ }
37
+
38
+ .dashicons-editor-help
39
+ {
40
+ color: #bbb;
41
+ cursor: help;
42
+
43
+ $tooltip-color: #000;
44
+
45
+ .fs-feature-desc {
46
+ opacity: 0;
47
+ visibility: hidden;
48
+ @include transition(opacity 0.3s ease-in-out);
49
+
50
+ position: absolute;
51
+ background: $tooltip-color;
52
+ color: #fff;
53
+ font-family: 'arial', serif;
54
+ font-size: 12px;
55
+ padding: 10px;
56
+ z-index: 999999;
57
+ bottom: 100%;
58
+ margin-bottom: 5px;
59
+ left: 0;
60
+ right: 0;
61
+ @include border-radius(5px);
62
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.2));
63
+ line-height: 1.3em;
64
+ font-weight: bold;
65
+ text-align: left;
66
+
67
+ .rtl &
68
+ {
69
+ text-align: right;
70
+ }
71
+
72
+ &::after {
73
+ content: ' ';
74
+ display: block;
75
+ width: 0;
76
+ height: 0;
77
+ border-style: solid;
78
+ border-width: 5px 5px 0 5px;
79
+ border-color: $tooltip-color transparent transparent transparent;
80
+ position: absolute;
81
+ top: 100%;
82
+ left: 21px;
83
+
84
+ .rtl & {
85
+ right: 21px;
86
+ left: auto;
87
+ }
88
+ }
89
+ }
90
+
91
+ &:hover {
92
+ .fs-feature-desc {
93
+ visibility: visible;
94
+ opacity: 1;
95
+ }
96
+ }
97
+ }
98
+
99
+ .button-primary {
100
+ display: block;
101
+ text-align: center;
102
+ margin-top: 10px;
103
+ }
104
+ }
105
+
106
+ #fs_customizer_support
107
+ {
108
+ display: block !important;
109
+
110
+ .button {
111
+ float: right;
112
+ }
113
+
114
+ .button-group {
115
+ width: 100%;
116
+ display: block;
117
+ margin-top: 10px;
118
+
119
+ .button {
120
+ float: none;
121
+ width: 50%;
122
+ text-align: center;
123
+ }
124
+ }
125
+ }
freemius/config.php ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! defined( 'WP_FS__SLUG' ) ) {
14
+ define( 'WP_FS__SLUG', 'freemius' );
15
+ }
16
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
17
+ define( 'WP_FS__DEV_MODE', false );
18
+ }
19
+
20
+ #--------------------------------------------------------------------------------
21
+ #region API Connectivity Issues Simulation
22
+ #--------------------------------------------------------------------------------
23
+
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
32
+ }
33
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
34
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_CURL ) {
37
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
41
+ }
42
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
43
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
44
+ }
45
+
46
+ #endregion
47
+
48
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
49
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
50
+ }
51
+
52
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
53
+ /**
54
+ * @since 1.1.7.3
55
+ * @author Vova Feldman (@svovaf)
56
+ *
57
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
58
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
59
+ * between domains on a daily basis. Therefore, to eliminate the risk of
60
+ * multiple unwanted connectivity test pings, temporary ignore domain or
61
+ * server IP changes.
62
+ */
63
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
64
+ }
65
+
66
+ /**
67
+ * If your dev environment supports custom public network IP setup
68
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
69
+ * and uncomment it during dev.
70
+ */
71
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
72
+ // VVV default public network IP.
73
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
74
+
75
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
76
+ }
77
+
78
+ /**
79
+ * If true and running with secret key, the opt-in process
80
+ * will skip the email activation process which is invoked
81
+ * when the email of the context user already exist in Freemius
82
+ * database (as a security precaution, to prevent sharing user
83
+ * secret with unauthorized entity).
84
+ *
85
+ * IMPORTANT:
86
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
87
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
88
+ * CLOCK IS SYNCED.
89
+ */
90
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
91
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
92
+ }
93
+
94
+
95
+ #--------------------------------------------------------------------------------
96
+ #region Directories
97
+ #--------------------------------------------------------------------------------
98
+
99
+ if ( ! defined( 'WP_FS__DIR' ) ) {
100
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
101
+ }
102
+ if ( ! defined( 'WP_FS__DIR_INCLUDES' ) ) {
103
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
104
+ }
105
+ if ( ! defined( 'WP_FS__DIR_TEMPLATES' ) ) {
106
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
107
+ }
108
+ if ( ! defined( 'WP_FS__DIR_ASSETS' ) ) {
109
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
110
+ }
111
+ if ( ! defined( 'WP_FS__DIR_CSS' ) ) {
112
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
113
+ }
114
+ if ( ! defined( 'WP_FS__DIR_JS' ) ) {
115
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
116
+ }
117
+ if ( ! defined( 'WP_FS__DIR_IMG' ) ) {
118
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
119
+ }
120
+ if ( ! defined( 'WP_FS__DIR_SDK' ) ) {
121
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
122
+ }
123
+
124
+ #endregion
125
+
126
+ /**
127
+ * Domain / URL / Address
128
+ */
129
+ define( 'WP_FS__ROOT_DOMAIN_PRODUCTION', 'freemius.com' );
130
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
131
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
132
+
133
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
134
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
135
+ }
136
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
137
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
138
+ }
139
+
140
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
141
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
142
+ }
143
+
144
+ #--------------------------------------------------------------------------------
145
+ #region HTTP
146
+ #--------------------------------------------------------------------------------
147
+
148
+ if ( ! defined( 'WP_FS__IS_HTTP_REQUEST' ) ) {
149
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
150
+ }
151
+
152
+ if ( ! defined( 'WP_FS__IS_HTTPS' ) ) {
153
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
154
+ // Checks if CloudFlare's HTTPS (Flexible SSL support).
155
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
156
+ 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
157
+ ) ||
158
+ // Check if HTTPS request.
159
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
160
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
161
+ );
162
+ }
163
+
164
+ if ( ! defined( 'WP_FS__IS_POST_REQUEST' ) ) {
165
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
166
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
167
+ }
168
+
169
+ if ( ! defined( 'WP_FS__REMOTE_ADDR' ) ) {
170
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
171
+ }
172
+
173
+ if ( ! defined( 'WP_FS__IS_LOCALHOST' ) ) {
174
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
175
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
176
+ } else {
177
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
178
+ is_string( WP_FS__REMOTE_ADDR ) &&
179
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) === '127.' ||
180
+ WP_FS__REMOTE_ADDR === '::1' )
181
+ );
182
+ }
183
+ }
184
+
185
+ if ( ! defined( 'WP_FS__IS_LOCALHOST_FOR_SERVER' ) ) {
186
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
187
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
188
+ }
189
+
190
+ #endregion
191
+
192
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
193
+ // By default, run with Freemius production servers.
194
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
195
+ }
196
+
197
+ if ( ! defined( 'WP_FS__ADDRESS' ) ) {
198
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
199
+ }
200
+
201
+
202
+ #--------------------------------------------------------------------------------
203
+ #region API
204
+ #--------------------------------------------------------------------------------
205
+
206
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
207
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
208
+ }
209
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
210
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
211
+ }
212
+
213
+ // Set API address for local testing.
214
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
215
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
216
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
217
+ }
218
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
219
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
220
+ }
221
+ }
222
+
223
+ #endregion
224
+
225
+ #--------------------------------------------------------------------------------
226
+ #region Checkout
227
+ #--------------------------------------------------------------------------------
228
+
229
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_PRODUCTION' ) ) {
230
+ define( 'FS_CHECKOUT__ADDRESS_PRODUCTION', 'https://checkout.freemius.com' );
231
+ }
232
+
233
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_LOCALHOST' ) ) {
234
+ define( 'FS_CHECKOUT__ADDRESS_LOCALHOST', 'http://checkout.freemius:8080' );
235
+ }
236
+
237
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS' ) ) {
238
+ define( 'FS_CHECKOUT__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? FS_CHECKOUT__ADDRESS_PRODUCTION : FS_CHECKOUT__ADDRESS_LOCALHOST ) );
239
+ }
240
+
241
+ #endregion
242
+
243
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
244
+
245
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
246
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
247
+ }
248
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
249
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
250
+ }
251
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
252
+
253
+ /**
254
+ * Module types
255
+ *
256
+ * @since 1.2.2
257
+ */
258
+ define( 'WP_FS__MODULE_TYPE_PLUGIN', 'plugin' );
259
+ define( 'WP_FS__MODULE_TYPE_THEME', 'theme' );
260
+
261
+ /**
262
+ * Billing Frequencies
263
+ */
264
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
265
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
266
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
267
+
268
+ /**
269
+ * Plans
270
+ */
271
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
272
+ define( 'WP_FS__PLAN_FREE', 'free' );
273
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
274
+
275
+ /**
276
+ * Times in seconds
277
+ */
278
+ if ( ! defined( 'WP_FS__TIME_5_MIN_IN_SEC' ) ) {
279
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
280
+ }
281
+ if ( ! defined( 'WP_FS__TIME_10_MIN_IN_SEC' ) ) {
282
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
283
+ }
284
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
285
+ if ( ! defined( 'WP_FS__TIME_24_HOURS_IN_SEC' ) ) {
286
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', 86400 );
287
+ }
288
+
289
+ #--------------------------------------------------------------------------------
290
+ #region Debugging
291
+ #--------------------------------------------------------------------------------
292
+
293
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
294
+ $debug_mode = get_option( 'fs_debug_mode', null );
295
+
296
+ if ( $debug_mode === null ) {
297
+ $debug_mode = false;
298
+ add_option( 'fs_debug_mode', $debug_mode );
299
+ }
300
+
301
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
302
+ }
303
+
304
+ if ( ! defined( 'WP_FS__ECHO_DEBUG_SDK' ) ) {
305
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
306
+ }
307
+ if ( ! defined( 'WP_FS__LOG_DATETIME_FORMAT' ) ) {
308
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s' );
309
+ }
310
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
311
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
312
+ }
313
+
314
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
315
+ error_reporting( E_ALL );
316
+ }
317
+
318
+ #endregion
319
+
320
+ if ( ! defined( 'WP_FS__SCRIPT_START_TIME' ) ) {
321
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
322
+ }
323
+ if ( ! defined( 'WP_FS__DEFAULT_PRIORITY' ) ) {
324
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
325
+ }
326
+ if ( ! defined( 'WP_FS__LOWEST_PRIORITY' ) ) {
327
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
328
+ }
freemius/includes/class-freemius-abstract.php ADDED
@@ -0,0 +1,597 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+
14
+ /**
15
+ * - Each instance of Freemius class represents a single plugin
16
+ * install by a single user (the installer of the plugin).
17
+ *
18
+ * - Each website can only have one install of the same plugin.
19
+ *
20
+ * - Install entity is only created after a user connects his account with Freemius.
21
+ *
22
+ * Class Freemius_Abstract
23
+ */
24
+ abstract class Freemius_Abstract {
25
+
26
+ #----------------------------------------------------------------------------------
27
+ #region Identity
28
+ #----------------------------------------------------------------------------------
29
+
30
+ /**
31
+ * Check if user has connected his account (opted-in).
32
+ *
33
+ * Note:
34
+ * If the user opted-in and opted-out on a later stage,
35
+ * this will still return true. If you want to check if the
36
+ * user is currently opted-in, use:
37
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
38
+ *
39
+ * @since 1.0.1
40
+ * @return bool
41
+ */
42
+ abstract function is_registered();
43
+
44
+ /**
45
+ * Check if the user skipped connecting the account with Freemius.
46
+ *
47
+ * @since 1.0.7
48
+ *
49
+ * @return bool
50
+ */
51
+ abstract function is_anonymous();
52
+
53
+ /**
54
+ * Check if the user currently in activation mode.
55
+ *
56
+ * @since 1.0.7
57
+ *
58
+ * @return bool
59
+ */
60
+ abstract function is_activation_mode();
61
+
62
+ #endregion
63
+
64
+ #----------------------------------------------------------------------------------
65
+ #region Usage Tracking
66
+ #----------------------------------------------------------------------------------
67
+
68
+ /**
69
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
70
+ *
71
+ * @author Leo Fajardo (@leorw)
72
+ * @since 1.2.1.5
73
+ *
74
+ * @return bool
75
+ */
76
+ abstract function is_tracking_allowed();
77
+
78
+ /**
79
+ * Returns TRUE if the user never opted-in or manually opted-out.
80
+ *
81
+ * @author Vova Feldman (@svovaf)
82
+ * @since 1.2.1.5
83
+ *
84
+ * @return bool
85
+ */
86
+ function is_tracking_prohibited() {
87
+ return ! $this->is_registered() || ! $this->is_tracking_allowed();
88
+ }
89
+
90
+ /**
91
+ * Opt-out from usage tracking.
92
+ *
93
+ * Note: This will not delete the account information but will stop all tracking.
94
+ *
95
+ * Returns:
96
+ * 1. FALSE - If the user never opted-in.
97
+ * 2. TRUE - If successfully opted-out.
98
+ * 3. object - API Result on failure.
99
+ *
100
+ * @author Leo Fajardo (@leorw)
101
+ * @since 1.2.1.5
102
+ *
103
+ * @return bool|object
104
+ */
105
+ abstract function stop_tracking();
106
+
107
+ /**
108
+ * Opt-in back into usage tracking.
109
+ *
110
+ * Note: This will only work if the user opted-in previously.
111
+ *
112
+ * Returns:
113
+ * 1. FALSE - If the user never opted-in.
114
+ * 2. TRUE - If successfully opted-in back to usage tracking.
115
+ * 3. object - API result on failure.
116
+ *
117
+ * @author Leo Fajardo (@leorw)
118
+ * @since 1.2.1.5
119
+ *
120
+ * @return bool|object
121
+ */
122
+ abstract function allow_tracking();
123
+
124
+ #endregion
125
+
126
+ #----------------------------------------------------------------------------------
127
+ #region Module Type
128
+ #----------------------------------------------------------------------------------
129
+
130
+ /**
131
+ * Checks if the plugin's type is "plugin". The other type is "theme".
132
+ *
133
+ * @author Leo Fajardo (@leorw)
134
+ * @since 1.2.2
135
+ *
136
+ * @return bool
137
+ */
138
+ abstract function is_plugin();
139
+
140
+ /**
141
+ * Checks if the module type is "theme". The other type is "plugin".
142
+ *
143
+ * @author Leo Fajardo (@leorw)
144
+ * @since 1.2.2
145
+ *
146
+ * @return bool
147
+ */
148
+ function is_theme() {
149
+ return ( ! $this->is_plugin() );
150
+ }
151
+
152
+ #endregion
153
+
154
+ #----------------------------------------------------------------------------------
155
+ #region Permissions
156
+ #----------------------------------------------------------------------------------
157
+
158
+ /**
159
+ * Check if plugin must be WordPress.org compliant.
160
+ *
161
+ * @since 1.0.7
162
+ *
163
+ * @return bool
164
+ */
165
+ abstract function is_org_repo_compliant();
166
+
167
+ /**
168
+ * Check if plugin is allowed to install executable files.
169
+ *
170
+ * @author Vova Feldman (@svovaf)
171
+ * @since 1.0.5
172
+ *
173
+ * @return bool
174
+ */
175
+ function is_allowed_to_install() {
176
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
177
+ }
178
+
179
+ #endregion
180
+
181
+ /**
182
+ * Check if user in trial or in free plan (not paying).
183
+ *
184
+ * @author Vova Feldman (@svovaf)
185
+ * @since 1.0.4
186
+ *
187
+ * @return bool
188
+ */
189
+ function is_not_paying() {
190
+ return ( $this->is_trial() || $this->is_free_plan() );
191
+ }
192
+
193
+ /**
194
+ * Check if the user has an activated and valid paid license on current plugin's install.
195
+ *
196
+ * @since 1.0.9
197
+ *
198
+ * @return bool
199
+ */
200
+ abstract function is_paying();
201
+
202
+ /**
203
+ * Check if the user is paying or in trial.
204
+ *
205
+ * @since 1.0.9
206
+ *
207
+ * @return bool
208
+ */
209
+ function is_paying_or_trial() {
210
+ return ( $this->is_paying() || $this->is_trial() );
211
+ }
212
+
213
+ /**
214
+ * Check if user in a trial or have feature enabled license.
215
+ *
216
+ * @author Vova Feldman (@svovaf)
217
+ * @since 1.1.7
218
+ *
219
+ * @return bool
220
+ */
221
+ abstract function can_use_premium_code();
222
+
223
+ #----------------------------------------------------------------------------------
224
+ #region Premium Only
225
+ #----------------------------------------------------------------------------------
226
+
227
+ /**
228
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
229
+ * included in the premium code.
230
+ *
231
+ * Example:
232
+ * if ( freemius()->is__premium_only() ) {
233
+ * ...
234
+ * }
235
+ */
236
+
237
+ /**
238
+ * Returns true when running premium plugin code.
239
+ *
240
+ * @since 1.0.9
241
+ *
242
+ * @return bool
243
+ */
244
+ function is__premium_only() {
245
+ return $this->is_premium();
246
+ }
247
+
248
+ /**
249
+ * Check if the user has an activated and valid paid license on current plugin's install.
250
+ *
251
+ * @since 1.0.9
252
+ *
253
+ * @return bool
254
+ *
255
+ */
256
+ function is_paying__premium_only() {
257
+ return ( $this->is__premium_only() && $this->is_paying() );
258
+ }
259
+
260
+ /**
261
+ * All code wrapped in this statement will be only included in the premium code.
262
+ *
263
+ * @since 1.0.9
264
+ *
265
+ * @param string $plan Plan name.
266
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
267
+ *
268
+ * @return bool
269
+ */
270
+ function is_plan__premium_only( $plan, $exact = false ) {
271
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
272
+ }
273
+
274
+ /**
275
+ * Check if plan matches active license' plan or active trial license' plan.
276
+ *
277
+ * All code wrapped in this statement will be only included in the premium code.
278
+ *
279
+ * @since 1.0.9
280
+ *
281
+ * @param string $plan Plan name.
282
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
283
+ *
284
+ * @return bool
285
+ */
286
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
287
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
288
+ }
289
+
290
+ /**
291
+ * Check if the user is paying or in trial.
292
+ *
293
+ * All code wrapped in this statement will be only included in the premium code.
294
+ *
295
+ * @since 1.0.9
296
+ *
297
+ * @return bool
298
+ */
299
+ function is_paying_or_trial__premium_only() {
300
+ return $this->is_premium() && $this->is_paying_or_trial();
301
+ }
302
+
303
+ /**
304
+ * Check if the user has an activated and valid paid license on current plugin's install.
305
+ *
306
+ * @since 1.0.4
307
+ *
308
+ * @return bool
309
+ *
310
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
311
+ * @using Alias to is_paying__premium_only()
312
+ */
313
+ function is_paying__fs__() {
314
+ return $this->is_paying__premium_only();
315
+ }
316
+
317
+ /**
318
+ * Check if user in a trial or have feature enabled license.
319
+ *
320
+ * All code wrapped in this statement will be only included in the premium code.
321
+ *
322
+ * @author Vova Feldman (@svovaf)
323
+ * @since 1.1.9
324
+ *
325
+ * @return bool
326
+ */
327
+ function can_use_premium_code__premium_only() {
328
+ return $this->is_premium() && $this->can_use_premium_code();
329
+ }
330
+
331
+ #endregion
332
+
333
+ #----------------------------------------------------------------------------------
334
+ #region Trial
335
+ #----------------------------------------------------------------------------------
336
+
337
+ /**
338
+ * Check if the user in a trial.
339
+ *
340
+ * @since 1.0.3
341
+ *
342
+ * @return bool
343
+ */
344
+ abstract function is_trial();
345
+
346
+ /**
347
+ * Check if trial already utilized.
348
+ *
349
+ * @since 1.0.9
350
+ *
351
+ * @return bool
352
+ */
353
+ abstract function is_trial_utilized();
354
+
355
+ #endregion
356
+
357
+ #----------------------------------------------------------------------------------
358
+ #region Plans
359
+ #----------------------------------------------------------------------------------
360
+
361
+ /**
362
+ * Check if plugin using the free plan.
363
+ *
364
+ * @since 1.0.4
365
+ *
366
+ * @return bool
367
+ */
368
+ abstract function is_free_plan();
369
+
370
+ /**
371
+ * @since 1.0.2
372
+ *
373
+ * @param string $plan Plan name.
374
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
375
+ *
376
+ * @return bool
377
+ */
378
+ abstract function is_plan( $plan, $exact = false );
379
+
380
+ /**
381
+ * Check if plan based on trial. If not in trial mode, should return false.
382
+ *
383
+ * @since 1.0.9
384
+ *
385
+ * @param string $plan Plan name.
386
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
387
+ *
388
+ * @return bool
389
+ */
390
+ abstract function is_trial_plan( $plan, $exact = false );
391
+
392
+ /**
393
+ * Check if plan matches active license' plan or active trial license' plan.
394
+ *
395
+ * @since 1.0.9
396
+ *
397
+ * @param string $plan Plan name.
398
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
399
+ *
400
+ * @return bool
401
+ */
402
+ function is_plan_or_trial( $plan, $exact = false ) {
403
+ return $this->is_plan( $plan, $exact ) ||
404
+ $this->is_trial_plan( $plan, $exact );
405
+ }
406
+
407
+ /**
408
+ * Check if plugin has any paid plans.
409
+ *
410
+ * @author Vova Feldman (@svovaf)
411
+ * @since 1.0.7
412
+ *
413
+ * @return bool
414
+ */
415
+ abstract function has_paid_plan();
416
+
417
+ /**
418
+ * Check if plugin has any free plan, or is it premium only.
419
+ *
420
+ * Note: If no plans configured, assume plugin is free.
421
+ *
422
+ * @author Vova Feldman (@svovaf)
423
+ * @since 1.0.7
424
+ *
425
+ * @return bool
426
+ */
427
+ abstract function has_free_plan();
428
+
429
+ /**
430
+ * Check if plugin is premium only (no free plans).
431
+ *
432
+ * NOTE: is__premium_only() is very different method, don't get confused.
433
+ *
434
+ * @author Vova Feldman (@svovaf)
435
+ * @since 1.1.9
436
+ *
437
+ * @return bool
438
+ */
439
+ abstract function is_only_premium();
440
+
441
+ /**
442
+ * Check if module has a premium code version.
443
+ *
444
+ * Serviceware module might be freemium without any
445
+ * premium code version, where the paid features
446
+ * are all part of the service.
447
+ *
448
+ * @author Vova Feldman (@svovaf)
449
+ * @since 1.2.1.6
450
+ *
451
+ * @return bool
452
+ */
453
+ abstract function has_premium_version();
454
+
455
+ /**
456
+ * Check if module has any release on Freemius,
457
+ * or all plugin's code is on WordPress.org (Serviceware).
458
+ *
459
+ * @return bool
460
+ */
461
+ function has_release_on_freemius() {
462
+ return ! $this->is_org_repo_compliant() ||
463
+ $this->has_premium_version();
464
+ }
465
+
466
+ /**
467
+ * Checks if it's a freemium plugin.
468
+ *
469
+ * @author Vova Feldman (@svovaf)
470
+ * @since 1.1.9
471
+ *
472
+ * @return bool
473
+ */
474
+ function is_freemium() {
475
+ return $this->has_paid_plan() &&
476
+ $this->has_free_plan();
477
+ }
478
+
479
+ /**
480
+ * Check if module has only one plan.
481
+ *
482
+ * @author Vova Feldman (@svovaf)
483
+ * @since 1.2.1.7
484
+ *
485
+ * @return bool
486
+ */
487
+ abstract function is_single_plan();
488
+
489
+ #endregion
490
+
491
+ /**
492
+ * Check if running payments in sandbox mode.
493
+ *
494
+ * @since 1.0.4
495
+ *
496
+ * @return bool
497
+ */
498
+ abstract function is_payments_sandbox();
499
+
500
+ /**
501
+ * Check if running test vs. live plugin.
502
+ *
503
+ * @since 1.0.5
504
+ *
505
+ * @return bool
506
+ */
507
+ abstract function is_live();
508
+
509
+ /**
510
+ * Check if running premium plugin code.
511
+ *
512
+ * @since 1.0.5
513
+ *
514
+ * @return bool
515
+ */
516
+ abstract function is_premium();
517
+
518
+ /**
519
+ * Get upgrade URL.
520
+ *
521
+ * @author Vova Feldman (@svovaf)
522
+ * @since 1.0.2
523
+ *
524
+ * @param string $period Billing cycle.
525
+ *
526
+ * @return string
527
+ */
528
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
529
+
530
+ /**
531
+ * Check if Freemius was first added in a plugin update.
532
+ *
533
+ * @author Vova Feldman (@svovaf)
534
+ * @since 1.1.5
535
+ *
536
+ * @return bool
537
+ */
538
+ function is_plugin_update() {
539
+ return ! $this->is_plugin_new_install();
540
+ }
541
+
542
+ /**
543
+ * Check if Freemius was part of the plugin when the user installed it first.
544
+ *
545
+ * @author Vova Feldman (@svovaf)
546
+ * @since 1.1.5
547
+ *
548
+ * @return bool
549
+ */
550
+ abstract function is_plugin_new_install();
551
+
552
+ #----------------------------------------------------------------------------------
553
+ #region Marketing
554
+ #----------------------------------------------------------------------------------
555
+
556
+ /**
557
+ * Check if current user purchased any other plugins before.
558
+ *
559
+ * @author Vova Feldman (@svovaf)
560
+ * @since 1.0.9
561
+ *
562
+ * @return bool
563
+ */
564
+ abstract function has_purchased_before();
565
+
566
+ /**
567
+ * Check if current user classified as an agency.
568
+ *
569
+ * @author Vova Feldman (@svovaf)
570
+ * @since 1.0.9
571
+ *
572
+ * @return bool
573
+ */
574
+ abstract function is_agency();
575
+
576
+ /**
577
+ * Check if current user classified as a developer.
578
+ *
579
+ * @author Vova Feldman (@svovaf)
580
+ * @since 1.0.9
581
+ *
582
+ * @return bool
583
+ */
584
+ abstract function is_developer();
585
+
586
+ /**
587
+ * Check if current user classified as a business.
588
+ *
589
+ * @author Vova Feldman (@svovaf)
590
+ * @since 1.0.9
591
+ *
592
+ * @return bool
593
+ */
594
+ abstract function is_business();
595
+
596
+ #endregion
597
+ }
freemius/includes/class-freemius.php ADDED
@@ -0,0 +1,13647 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ // "final class"
13
+ class Freemius extends Freemius_Abstract {
14
+ /**
15
+ * SDK Version
16
+ *
17
+ * @var string
18
+ */
19
+ public $version = WP_FS__SDK_VERSION;
20
+
21
+ #region Plugin Info
22
+
23
+ /**
24
+ * @since 1.0.1
25
+ *
26
+ * @var string
27
+ */
28
+ private $_slug;
29
+
30
+ /**
31
+ * @since 1.0.0
32
+ *
33
+ * @var string
34
+ */
35
+ private $_plugin_basename;
36
+ /**
37
+ * @since 1.0.0
38
+ *
39
+ * @var string
40
+ */
41
+ private $_free_plugin_basename;
42
+ /**
43
+ * @since 1.0.0
44
+ *
45
+ * @var string
46
+ */
47
+ private $_plugin_dir_path;
48
+ /**
49
+ * @since 1.0.0
50
+ *
51
+ * @var string
52
+ */
53
+ private $_plugin_dir_name;
54
+ /**
55
+ * @since 1.0.0
56
+ *
57
+ * @var string
58
+ */
59
+ private $_plugin_main_file_path;
60
+ /**
61
+ * @var string[]
62
+ */
63
+ private $_plugin_data;
64
+ /**
65
+ * @since 1.0.9
66
+ *
67
+ * @var string
68
+ */
69
+ private $_plugin_name;
70
+ /**
71
+ * @since 1.2.2
72
+ *
73
+ * @var string
74
+ */
75
+ private $_module_type;
76
+
77
+ #endregion Plugin Info
78
+
79
+ /**
80
+ * @since 1.0.9
81
+ *
82
+ * @var bool If false, don't turn Freemius on.
83
+ */
84
+ private $_is_on;
85
+
86
+ /**
87
+ * @since 1.1.3
88
+ *
89
+ * @var bool If false, don't turn Freemius on.
90
+ */
91
+ private $_is_anonymous;
92
+
93
+ /**
94
+ * @since 1.0.9
95
+ * @var bool If false, issues with connectivity to Freemius API.
96
+ */
97
+ private $_has_api_connection;
98
+
99
+ /**
100
+ * @since 1.0.9
101
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
102
+ */
103
+ private $_enable_anonymous;
104
+
105
+ /**
106
+ * @since 1.1.7.5
107
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
108
+ */
109
+ private $_anonymous_mode;
110
+
111
+ /**
112
+ * @since 1.1.9
113
+ * @var bool Hints the SDK if plugin have any free plans.
114
+ */
115
+ private $_is_premium_only;
116
+
117
+ /**
118
+ * @since 1.2.1.6
119
+ * @var bool Hints the SDK if plugin have premium code version at all.
120
+ */
121
+ private $_has_premium_version;
122
+
123
+ /**
124
+ * @since 1.2.1.6
125
+ * @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
126
+ */
127
+ private $_ignore_pending_mode;
128
+
129
+ /**
130
+ * @since 1.0.8
131
+ * @var bool Hints the SDK if the plugin has any paid plans.
132
+ */
133
+ private $_has_paid_plans;
134
+
135
+ /**
136
+ * @since 1.2.1.5
137
+ * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
138
+ * without a specified period, if positive - the number of trial days.
139
+ */
140
+ private $_trial_days = - 1;
141
+
142
+ /**
143
+ * @since 1.2.1.5
144
+ * @var bool Hints the SDK if the trial requires a payment method or not.
145
+ */
146
+ private $_is_trial_require_payment = false;
147
+
148
+ /**
149
+ * @since 1.0.7
150
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
151
+ */
152
+ private $_is_org_compliant;
153
+
154
+ /**
155
+ * @since 1.0.7
156
+ * @var bool Hints the SDK if the plugin is has add-ons.
157
+ */
158
+ private $_has_addons;
159
+
160
+ /**
161
+ * @since 1.1.6
162
+ * @var string[]bool.
163
+ */
164
+ private $_permissions;
165
+
166
+ /**
167
+ * @var FS_Key_Value_Storage
168
+ */
169
+ private $_storage;
170
+
171
+ /**
172
+ * @since 1.2.2.7
173
+ * @var FS_Cache_Manager
174
+ */
175
+ private $_cache;
176
+
177
+ /**
178
+ * @since 1.0.0
179
+ *
180
+ * @var FS_Logger
181
+ */
182
+ private $_logger;
183
+ /**
184
+ * @since 1.0.4
185
+ *
186
+ * @var FS_Plugin
187
+ */
188
+ private $_plugin = false;
189
+ /**
190
+ * @since 1.0.4
191
+ *
192
+ * @var FS_Plugin|false
193
+ */
194
+ private $_parent_plugin = false;
195
+ /**
196
+ * @since 1.1.1
197
+ *
198
+ * @var Freemius
199
+ */
200
+ private $_parent = false;
201
+ /**
202
+ * @since 1.0.1
203
+ *
204
+ * @var FS_User
205
+ */
206
+ private $_user = false;
207
+ /**
208
+ * @since 1.0.1
209
+ *
210
+ * @var FS_Site
211
+ */
212
+ private $_site = false;
213
+ /**
214
+ * @since 1.0.1
215
+ *
216
+ * @var FS_Plugin_License
217
+ */
218
+ private $_license;
219
+ /**
220
+ * @since 1.0.2
221
+ *
222
+ * @var FS_Plugin_Plan[]
223
+ */
224
+ private $_plans = false;
225
+ /**
226
+ * @var FS_Plugin_License[]
227
+ * @since 1.0.5
228
+ */
229
+ private $_licenses = false;
230
+
231
+ /**
232
+ * @since 1.0.1
233
+ *
234
+ * @var FS_Admin_Menu_Manager
235
+ */
236
+ private $_menu;
237
+
238
+ /**
239
+ * @var FS_Admin_Notice_Manager
240
+ */
241
+ private $_admin_notices;
242
+
243
+ /**
244
+ * @since 1.1.6
245
+ *
246
+ * @var FS_Admin_Notice_Manager
247
+ */
248
+ private static $_global_admin_notices;
249
+
250
+ /**
251
+ * @var FS_Logger
252
+ * @since 1.0.0
253
+ */
254
+ private static $_static_logger;
255
+
256
+ /**
257
+ * @var FS_Option_Manager
258
+ * @since 1.0.2
259
+ */
260
+ private static $_accounts;
261
+
262
+ /**
263
+ * @since 1.2.2
264
+ *
265
+ * @var number
266
+ */
267
+ private $_module_id;
268
+
269
+ /**
270
+ * @var Freemius[]
271
+ */
272
+ private static $_instances = array();
273
+
274
+ #region Uninstall Reasons IDs
275
+
276
+ const REASON_NO_LONGER_NEEDED = 1;
277
+ const REASON_FOUND_A_BETTER_PLUGIN = 2;
278
+ const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
279
+ const REASON_BROKE_MY_SITE = 4;
280
+ const REASON_SUDDENLY_STOPPED_WORKING = 5;
281
+ const REASON_CANT_PAY_ANYMORE = 6;
282
+ const REASON_OTHER = 7;
283
+ const REASON_DIDNT_WORK = 8;
284
+ const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
285
+ const REASON_COULDNT_MAKE_IT_WORK = 10;
286
+ const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
287
+ const REASON_NOT_WORKING = 12;
288
+ const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
289
+ const REASON_DIDNT_WORK_AS_EXPECTED = 14;
290
+ const REASON_TEMPORARY_DEACTIVATION = 15;
291
+
292
+ #endregion
293
+
294
+ /* Ctor
295
+ ------------------------------------------------------------------------------------------------------------------*/
296
+
297
+ /**
298
+ * Main singleton instance.
299
+ *
300
+ * @author Vova Feldman (@svovaf)
301
+ * @since 1.0.0
302
+ *
303
+ * @param number $module_id
304
+ * @param string|bool $slug
305
+ * @param bool $is_init Since 1.2.1 Is initiation sequence.
306
+ */
307
+ private function __construct( $module_id, $slug = false, $is_init = false ) {
308
+ if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
309
+ $this->store_id_slug_type_path_map( $module_id, $slug );
310
+ }
311
+
312
+ $this->_module_id = $module_id;
313
+ $this->_slug = $this->get_slug();
314
+ $this->_module_type = $this->get_module_type();
315
+
316
+ $this->_storage = FS_Key_Value_Storage::instance( $this->_module_type . '_data', $this->_slug );
317
+ $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
318
+
319
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
320
+
321
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
322
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
323
+ $this->_plugin_basename = $this->get_plugin_basename();
324
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
325
+
326
+ $base_name_split = explode( '/', $this->_plugin_basename );
327
+ $this->_plugin_dir_name = $base_name_split[0];
328
+
329
+ if ( $this->_logger->is_on() ) {
330
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
331
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
332
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
333
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
334
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
335
+ }
336
+
337
+ // Remember link between file to slug.
338
+ $this->store_file_slug_map();
339
+
340
+ // Store plugin's initial install timestamp.
341
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
342
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
343
+ }
344
+
345
+ if ( ! is_object( $this->_plugin ) ) {
346
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
347
+ }
348
+
349
+ $this->_admin_notices = FS_Admin_Notice_Manager::instance(
350
+ $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
351
+ /**
352
+ * Ensure that the admin notice will always have a title by using the stored plugin title if available and
353
+ * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
354
+ *
355
+ * @author Leo Fajardo (@leorw)
356
+ * @since 1.2.2
357
+ */
358
+ ( is_object( $this->_plugin ) ? $this->_plugin->title : $this->get_plugin_name() ),
359
+ $this->get_unique_affix()
360
+ );
361
+
362
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
363
+ 'true' === fs_request_is_action( 'restart_freemius' )
364
+ ) {
365
+ FS_Api::clear_cache();
366
+ $this->_cache->clear();
367
+ }
368
+
369
+ $this->_register_hooks();
370
+
371
+ $this->_load_account();
372
+
373
+ $this->_version_updates_handler();
374
+ }
375
+
376
+ /**
377
+ * Checks whether this module has a settings menu.
378
+ *
379
+ * @author Leo Fajardo (@leorw)
380
+ * @since 1.2.2
381
+ *
382
+ * @return bool
383
+ */
384
+ function has_settings_menu() {
385
+ return $this->_menu->has_menu();
386
+ }
387
+
388
+ /**
389
+ * Check if the context module is free wp.org theme.
390
+ *
391
+ * This method is helpful because:
392
+ * 1. wp.org themes are limited to a single submenu item,
393
+ * and sub-submenu items are most likely not allowed (never verified).
394
+ * 2. wp.org themes are not allowed to redirect the user
395
+ * after the theme activation, therefore, the agreed UX
396
+ * is showing the opt-in as a modal dialog box after
397
+ * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
398
+ *
399
+ * @author Vova Feldman (@svovaf)
400
+ * @since 1.2.2.7
401
+ *
402
+ * @return bool
403
+ */
404
+ function is_free_wp_org_theme() {
405
+ return (
406
+ $this->is_theme() &&
407
+ $this->is_org_repo_compliant() &&
408
+ ! $this->is_premium()
409
+ );
410
+ }
411
+
412
+ /**
413
+ * Checks whether this a submenu item is visible.
414
+ *
415
+ * @author Vova Feldman (@svovaf)
416
+ * @since 1.2.2.6
417
+ * @since 1.2.2.7 Even if the menu item was specified to be hidden, when it is the context page, then show the submenu item so the user will have the right context page.
418
+ *
419
+ * @param string $slug
420
+ *
421
+ * @return bool
422
+ */
423
+ function is_submenu_item_visible( $slug ) {
424
+ if ( $this->is_admin_page( $slug ) ) {
425
+ /**
426
+ * It is the current context page, so show the submenu item
427
+ * so the user will have the right context page, even if it
428
+ * was set to hidden.
429
+ */
430
+ return true;
431
+ }
432
+
433
+ if ( ! $this->has_settings_menu() ) {
434
+ // No menu settings at all.
435
+ return false;
436
+ }
437
+
438
+ if ( $this->is_free_wp_org_theme() ) {
439
+ /**
440
+ * wp.org themes are limited to a single submenu item, and
441
+ * sub-submenu items are most likely not allowed (never verified).
442
+ */
443
+ return false;
444
+ }
445
+
446
+ return $this->_menu->is_submenu_item_visible( $slug );
447
+ }
448
+
449
+ /**
450
+ * Check if a Freemius page should be accessible via the UI.
451
+ *
452
+ * @author Vova Feldman (@svovaf)
453
+ * @since 1.2.2.7
454
+ *
455
+ * @param string $slug
456
+ *
457
+ * @return bool
458
+ */
459
+ function is_page_visible( $slug ) {
460
+ if ( $this->is_admin_page( $slug ) ) {
461
+ return true;
462
+ }
463
+
464
+ return $this->_menu->is_submenu_item_visible( $slug, true, true );
465
+ }
466
+
467
+ /**
468
+ * @author Vova Feldman (@svovaf)
469
+ * @since 1.0.9
470
+ */
471
+ private function _version_updates_handler() {
472
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
473
+ // Freemius version upgrade mode.
474
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
475
+ $this->_storage->sdk_version = $this->version;
476
+
477
+ if ( empty( $this->_storage->sdk_last_version ) ||
478
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
479
+ ) {
480
+ $this->_storage->sdk_upgrade_mode = true;
481
+ $this->_storage->sdk_downgrade_mode = false;
482
+ } else {
483
+ $this->_storage->sdk_downgrade_mode = true;
484
+ $this->_storage->sdk_upgrade_mode = false;
485
+
486
+ }
487
+
488
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
489
+ }
490
+
491
+ $plugin_version = $this->get_plugin_version();
492
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
493
+ // Plugin version upgrade mode.
494
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
495
+ $this->_storage->plugin_version = $plugin_version;
496
+
497
+ if ( empty( $this->_storage->plugin_last_version ) ||
498
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
499
+ ) {
500
+ $this->_storage->plugin_upgrade_mode = true;
501
+ $this->_storage->plugin_downgrade_mode = false;
502
+ } else {
503
+ $this->_storage->plugin_downgrade_mode = true;
504
+ $this->_storage->plugin_upgrade_mode = false;
505
+ }
506
+
507
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
508
+ // Different version of the plugin was installed before, therefore it's an update.
509
+ $this->_storage->is_plugin_new_install = false;
510
+ }
511
+
512
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
513
+ }
514
+ }
515
+
516
+ /**
517
+ * @author Vova Feldman (@svovaf)
518
+ * @since 1.1.5
519
+ *
520
+ * @param string $sdk_prev_version
521
+ * @param string $sdk_version
522
+ */
523
+ function _data_migration( $sdk_prev_version, $sdk_version ) {
524
+ /**
525
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
526
+ */
527
+ if ( empty( $sdk_prev_version ) ) {
528
+ return;
529
+ }
530
+
531
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
532
+ version_compare( $sdk_version, '1.1.5', '>=' )
533
+ ) {
534
+ // On version 1.1.5 merged connectivity and is_on data.
535
+ if ( isset( $this->_storage->connectivity_test ) ) {
536
+ if ( ! isset( $this->_storage->is_on ) ) {
537
+ unset( $this->_storage->connectivity_test );
538
+ } else {
539
+ $connectivity_data = $this->_storage->connectivity_test;
540
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
541
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
542
+
543
+ // Override.
544
+ $this->_storage->connectivity_test = $connectivity_data;
545
+
546
+ // Remove previous structure.
547
+ unset( $this->_storage->is_on );
548
+ }
549
+
550
+ }
551
+ }
552
+ }
553
+
554
+ /**
555
+ * @author Vova Feldman (@svovaf)
556
+ * @since 1.2.2.7
557
+ *
558
+ * @param string $plugin_prev_version
559
+ * @param string $plugin_version
560
+ */
561
+ function _after_version_update( $plugin_prev_version, $plugin_version ) {
562
+ if ( $this->is_theme() ) {
563
+ // Expire the cache of the previous tabs since the theme may
564
+ // have setting updates.
565
+ $this->_cache->expire( 'tabs' );
566
+ $this->_cache->expire( 'tabs_stylesheets' );
567
+ }
568
+ }
569
+
570
+ /**
571
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
572
+ * if this is a new plugin installation or a plugin update.
573
+ *
574
+ * There are 3 different use-cases:
575
+ * 1) New plugin installation right with Freemius:
576
+ * 1.1 _activate_plugin_event_hook() will be executed first
577
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
578
+ * and $this->_storage->plugin_last_version is not set,
579
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
580
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
581
+ * be already set to TRUE.
582
+ *
583
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
584
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
585
+ * the activation hook do NOT fires on updates since WP 3.1.
586
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
587
+ * be empty, therefore, it will be set to FALSE.
588
+ *
589
+ * 3) Plugin update, had Freemius in prev version as well:
590
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
591
+ * before, $this->_storage->plugin_last_version will NOT be empty,
592
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
593
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
594
+ * already set, therefore, it will not be modified.
595
+ *
596
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
597
+ *
598
+ * NOTE:
599
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
600
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
601
+ * show the opt-in right away. The reason it will happen is because Freemius execution
602
+ * will be turned off till the plugin is fully loaded at least once
603
+ * (till $this->_storage->was_plugin_loaded is TRUE).
604
+ *
605
+ * @author Vova Feldman (@svovaf)
606
+ * @since 1.1.9
607
+ *
608
+ */
609
+ function _plugins_loaded() {
610
+ // Update flag that plugin was loaded with Freemius at least once.
611
+ $this->_storage->was_plugin_loaded = true;
612
+
613
+ /**
614
+ * Bug fix - only set to false when it's a plugin, due to the
615
+ * execution sequence of the theme hooks and our methods, if
616
+ * this will be set for themes, Freemius will always assume
617
+ * it's a theme update.
618
+ *
619
+ * @author Vova Feldman (@svovaf)
620
+ * @since 1.2.2.2
621
+ */
622
+ if ( $this->is_plugin() &&
623
+ ! isset( $this->_storage->is_plugin_new_install )
624
+ ) {
625
+ $this->_storage->is_plugin_new_install = false;
626
+ }
627
+ }
628
+
629
+ /**
630
+ * @author Vova Feldman (@svovaf)
631
+ * @since 1.0.9
632
+ */
633
+ private function _register_hooks() {
634
+ $this->_logger->entrance();
635
+
636
+ if ( is_admin() ) {
637
+ if ( $this->is_plugin() ) {
638
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
639
+
640
+ /**
641
+ * @since 1.2.2
642
+ *
643
+ * Hook to both free and premium version activations to support
644
+ * auto deactivation on the other version activation.
645
+ */
646
+ register_activation_hook(
647
+ $plugin_dir . $this->_free_plugin_basename,
648
+ array( &$this, '_activate_plugin_event_hook' )
649
+ );
650
+
651
+ register_activation_hook(
652
+ $plugin_dir . $this->premium_plugin_basename(),
653
+ array( &$this, '_activate_plugin_event_hook' )
654
+ );
655
+ } else {
656
+ add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
657
+
658
+ /**
659
+ * Include the required hooks to capture the theme settings' page tabs
660
+ * and cache them.
661
+ *
662
+ * @author Vova Feldman (@svovaf)
663
+ * @since 1.2.2.7
664
+ */
665
+ if ( ! $this->_cache->has_valid( 'tabs' ) ) {
666
+ add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
667
+ // Add license activation AJAX callback.
668
+ $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
669
+
670
+ add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
671
+ }
672
+
673
+ add_action(
674
+ 'admin_footer',
675
+ array( &$this, '_add_freemius_tabs' ),
676
+ /**
677
+ * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
678
+ * That's why the priority is 11 while the tabs capture logic is added
679
+ * with priority 10.
680
+ *
681
+ * @author Vova Feldman (@svovaf)
682
+ */
683
+ 11
684
+ );
685
+
686
+ add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
687
+ }
688
+
689
+ /**
690
+ * Part of the mechanism to identify new plugin install vs. plugin update.
691
+ *
692
+ * @author Vova Feldman (@svovaf)
693
+ * @since 1.1.9
694
+ */
695
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
696
+ if ( $this->is_plugin() &&
697
+ $this->is_activation_mode( false ) &&
698
+ 0 == did_action( 'plugins_loaded' )
699
+ ) {
700
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
701
+ } else {
702
+ // If was activated before, then it was already loaded before.
703
+ $this->_plugins_loaded();
704
+ }
705
+ }
706
+
707
+ if ( ! self::is_ajax() ) {
708
+ if ( ! $this->is_addon() ) {
709
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
710
+ }
711
+ }
712
+ }
713
+
714
+ if ( $this->is_plugin() ) {
715
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
716
+ }
717
+
718
+ if ( $this->is_theme() && self::is_customizer() ) {
719
+ // Register customizer upsell.
720
+ add_action( 'customize_register', array( &$this, '_customizer_register' ) );
721
+ }
722
+
723
+ add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
724
+
725
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
726
+ add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
727
+ $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
728
+ $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
729
+
730
+ $this->add_ajax_action( 'install_premium_version', array(
731
+ &$this,
732
+ '_install_premium_version_ajax_action'
733
+ ) );
734
+
735
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
736
+
737
+ $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
738
+ $this->add_action( 'plugin_version_update', array( &$this, '_after_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
739
+ $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
740
+
741
+ add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
742
+ add_action( 'admin_init', array( &$this, '_enqueue_common_css' ) );
743
+
744
+ /**
745
+ * Handle request to reset anonymous mode for `get_reconnect_url()`.
746
+ *
747
+ * @author Vova Feldman (@svovaf)
748
+ * @since 1.2.1.5
749
+ */
750
+ if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
751
+ $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
752
+ ) {
753
+ add_action( 'admin_init', array( &$this, 'connect_again' ) );
754
+ }
755
+ }
756
+
757
+ /**
758
+ * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
759
+ * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
760
+ * plugin will trigger inclusion of the free or premium version and if one of them is active during the
761
+ * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
762
+ *
763
+ * @author Leo Fajardo (leorw)
764
+ *
765
+ * @since 1.2.0
766
+ */
767
+ private function unregister_uninstall_hook() {
768
+ $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
769
+ unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
770
+ unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
771
+
772
+ update_option( 'uninstall_plugins', $uninstallable_plugins );
773
+ }
774
+
775
+ /**
776
+ * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
777
+ */
778
+ private function clear_module_main_file_cache() {
779
+ if ( ! isset( $this->_storage->plugin_main_file ) ||
780
+ empty( $this->_storage->plugin_main_file->path )
781
+ ) {
782
+ return;
783
+ }
784
+
785
+ $plugin_main_file = clone $this->_storage->plugin_main_file;
786
+
787
+ // Store cached path (2nd layer cache).
788
+ $plugin_main_file->prev_path = $plugin_main_file->path;
789
+
790
+ // Clear cached path.
791
+ unset( $plugin_main_file->path );
792
+
793
+ $this->_storage->plugin_main_file = $plugin_main_file;
794
+
795
+ /**
796
+ * Clear global cached path.
797
+ *
798
+ * @author Leo Fajardo (@leorw)
799
+ * @since 1.2.2
800
+ */
801
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
802
+ unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
803
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
804
+ }
805
+
806
+ /**
807
+ * @author Vova Feldman (@svovaf)
808
+ * @since 1.0.9
809
+ */
810
+ private function _register_account_hooks() {
811
+ if ( ! is_admin() ) {
812
+ return;
813
+ }
814
+
815
+ /**
816
+ * Always show the deactivation feedback form since we added
817
+ * automatic free version deactivation upon premium code activation.
818
+ *
819
+ * @since 1.2.1.6
820
+ */
821
+ $this->add_ajax_action(
822
+ 'submit_uninstall_reason',
823
+ array( &$this, '_submit_uninstall_reason_action' )
824
+ );
825
+
826
+ if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
827
+ ( $this->is_theme() && self::is_themes_page() )
828
+ ) {
829
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
830
+ }
831
+ }
832
+
833
+ /**
834
+ * Leverage backtrace to find caller plugin file path.
835
+ *
836
+ * @author Vova Feldman (@svovaf)
837
+ * @since 1.0.6
838
+ *
839
+ * @param bool $is_init Is initiation sequence.
840
+ *
841
+ * @return string
842
+ */
843
+ private function _find_caller_plugin_file( $is_init = false ) {
844
+ // Try to load the cached value of the file path.
845
+ if ( isset( $this->_storage->plugin_main_file ) ) {
846
+ $plugin_main_file = $this->_storage->plugin_main_file;
847
+ if ( isset( $plugin_main_file->path ) && file_exists( $plugin_main_file->path ) ) {
848
+ return $plugin_main_file->path;
849
+ }
850
+ }
851
+
852
+ /**
853
+ * @since 1.2.1
854
+ *
855
+ * `clear_module_main_file_cache()` is clearing the plugin's cached path on
856
+ * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
857
+ * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
858
+ *
859
+ * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
860
+ * when the class instantiator isn't the module.
861
+ */
862
+ if ( ! $is_init ) {
863
+ // Fetch prev path cache.
864
+ if ( isset( $this->_storage->plugin_main_file ) &&
865
+ isset( $this->_storage->plugin_main_file->prev_path )
866
+ ) {
867
+ if ( file_exists( $this->_storage->plugin_main_file->prev_path ) ) {
868
+ return $this->_storage->plugin_main_file->prev_path;
869
+ }
870
+ }
871
+
872
+ wp_die(
873
+ $this->get_text( 'failed-finding-main-path' ) .
874
+ " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
875
+ $this->get_text( 'error' ),
876
+ array( 'back_link' => true )
877
+ );
878
+ }
879
+
880
+ /**
881
+ * @since 1.2.1
882
+ *
883
+ * Only the original instantiator that calls dynamic_init can modify the module's path.
884
+ */
885
+ // Find caller module.
886
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
887
+ $this->_storage->plugin_main_file = (object) array(
888
+ 'path' => $id_slug_type_path_map[ $this->_module_id ]['path'],
889
+ );
890
+
891
+ return $id_slug_type_path_map[ $this->_module_id ]['path'];
892
+ }
893
+
894
+ /**
895
+ * @author Leo Fajardo (@leorw)
896
+ *
897
+ * @param number $module_id
898
+ * @param string $slug
899
+ *
900
+ * @since 1.2.2
901
+ */
902
+ private function store_id_slug_type_path_map( $module_id, $slug ) {
903
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
904
+
905
+ $store_option = false;
906
+
907
+ if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
908
+ $id_slug_type_path_map[ $module_id ] = array(
909
+ 'slug' => $slug
910
+ );
911
+
912
+ $store_option = true;
913
+ }
914
+
915
+ if ( ! isset( $id_slug_type_path_map[ $module_id ]['path'] ) ) {
916
+ $caller_main_file_and_type = $this->get_caller_main_file_and_type();
917
+
918
+ $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
919
+ $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
920
+
921
+ $store_option = true;
922
+ }
923
+
924
+ if ( $store_option ) {
925
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
926
+ }
927
+ }
928
+
929
+ /**
930
+ * Identifies the caller type: plugin or theme.
931
+ *
932
+ * @author Leo Fajardo (@leorw)
933
+ * @since 1.2.2
934
+ *
935
+ * @author Vova Feldman (@svovaf)
936
+ * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
937
+ * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
938
+ * SDK an internal file instead of directly from functions.php.
939
+ * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
940
+ */
941
+ private function get_caller_main_file_and_type() {
942
+ self::require_plugin_essentials();
943
+
944
+ $all_plugins = get_plugins();
945
+ $all_plugins_paths = array();
946
+
947
+ // Get active plugin's main files real full names (might be symlinks).
948
+ foreach ( $all_plugins as $relative_path => &$data ) {
949
+ if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
950
+ /**
951
+ * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
952
+ * can't really include the SDK.
953
+ *
954
+ * @author Vova Feldman
955
+ * @since 1.2.1.7
956
+ */
957
+ continue;
958
+ }
959
+
960
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
961
+ }
962
+
963
+ $caller_file_candidate = false;
964
+ $caller_map = array();
965
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
966
+ $themes_dir = fs_normalize_path( get_theme_root() );
967
+
968
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
969
+ if ( empty( $bt[ $i ]['file'] ) ) {
970
+ continue;
971
+ }
972
+
973
+ if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
974
+ // If file same as the prev file in the stack, skip it.
975
+ continue;
976
+ }
977
+
978
+ if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
979
+ 'do_action',
980
+ 'apply_filter',
981
+ // The string split is stupid, but otherwise, theme check
982
+ // throws info notices.
983
+ 'requir' . 'e_once',
984
+ 'requir' . 'e',
985
+ 'includ' . 'e_once',
986
+ 'includ' . 'e'
987
+ ) )
988
+ ) {
989
+ // Ignore call stack hooks and files inclusion.
990
+ continue;
991
+ }
992
+
993
+ $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
994
+
995
+ if ( 'functions.php' === basename( $caller_file_path ) ) {
996
+ /**
997
+ * 1. Assumes that theme's starting execution file is functions.php.
998
+ * 2. This complex logic fixes symlink issues (e.g. with Vargant).
999
+ *
1000
+ * @author Vova Feldman (@svovaf)
1001
+ * @since 1.2.2.5
1002
+ */
1003
+
1004
+ if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
1005
+ $module_type = WP_FS__MODULE_TYPE_THEME;
1006
+ $caller_file_candidate = $caller_file_path;
1007
+ continue;
1008
+ }
1009
+ }
1010
+
1011
+ $caller_file_hash = md5( $caller_file_path );
1012
+
1013
+ if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
1014
+ foreach ( $all_plugins_paths as $plugin_path ) {
1015
+ if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
1016
+ $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
1017
+ break;
1018
+ }
1019
+ }
1020
+ }
1021
+
1022
+ if ( isset( $caller_map[ $caller_file_hash ] ) ) {
1023
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1024
+ $caller_file_candidate = $caller_map[ $caller_file_hash ];
1025
+ }
1026
+ }
1027
+
1028
+ return (object) array(
1029
+ 'module_type' => $module_type,
1030
+ 'path' => $caller_file_candidate
1031
+ );
1032
+ }
1033
+
1034
+ #----------------------------------------------------------------------------------
1035
+ #region Deactivation Feedback Form
1036
+ #----------------------------------------------------------------------------------
1037
+
1038
+ /**
1039
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
1040
+ * page.
1041
+ *
1042
+ * @author Vova Feldman (@svovaf)
1043
+ * @author Leo Fajardo (@leorw)
1044
+ * @since 1.1.2
1045
+ */
1046
+ function _add_deactivation_feedback_dialog_box() {
1047
+ /* Check the type of user:
1048
+ * 1. Long-term (long-term)
1049
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
1050
+ * 3. Short-term (short-term)
1051
+ */
1052
+ $is_long_term_user = true;
1053
+
1054
+ // Check if the site is at least 2 days old.
1055
+ $time_installed = $this->_storage->install_timestamp;
1056
+
1057
+ // Difference in seconds.
1058
+ $date_diff = time() - $time_installed;
1059
+
1060
+ // Convert seconds to days.
1061
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
1062
+
1063
+ if ( $date_diff_days < 2 ) {
1064
+ $is_long_term_user = false;
1065
+ }
1066
+
1067
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
1068
+
1069
+ if ( $is_long_term_user ) {
1070
+ $user_type = 'long-term';
1071
+ } else {
1072
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
1073
+ $user_type = 'non-registered-and-non-anonymous-short-term';
1074
+ } else {
1075
+ $user_type = 'short-term';
1076
+ }
1077
+ }
1078
+
1079
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
1080
+
1081
+ // Load the HTML template for the deactivation feedback dialog box.
1082
+ $vars = array(
1083
+ 'reasons' => $uninstall_reasons,
1084
+ 'id' => $this->_module_id
1085
+ );
1086
+
1087
+ /**
1088
+ * @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.
1089
+ */
1090
+ fs_require_template( 'forms/deactivation/form.php', $vars );
1091
+ }
1092
+
1093
+ /**
1094
+ * @author Leo Fajardo (leorw)
1095
+ * @since 1.1.2
1096
+ *
1097
+ * @param string $user_type
1098
+ *
1099
+ * @return array The uninstall reasons for the specified user type.
1100
+ */
1101
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
1102
+ $module_type = $this->_module_type;
1103
+
1104
+ $internal_message_template_var = array(
1105
+ 'id' => $this->_module_id
1106
+ );
1107
+
1108
+ if ( $this->is_registered() && false !== $this->get_plan() && $this->get_plan()->has_technical_support() ) {
1109
+ $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
1110
+ } else {
1111
+ $contact_support_template = '';
1112
+ }
1113
+
1114
+ $reason_found_better_plugin = array(
1115
+ 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
1116
+ 'text' => sprintf( $this->get_text( 'reason-found-a-better-plugin' ), $module_type ),
1117
+ 'input_type' => 'textfield',
1118
+ 'input_placeholder' => sprintf( $this->get_text( 'placeholder-plugin-name' ), $module_type ),
1119
+ );
1120
+
1121
+ $reason_temporary_deactivation = array(
1122
+ 'id' => self::REASON_TEMPORARY_DEACTIVATION,
1123
+ 'text' => sprintf(
1124
+ $this->get_text( 'reason-temporary-x' ),
1125
+ strtolower( $this->is_plugin() ?
1126
+ $this->get_text( 'deactivation' ) :
1127
+ $this->get_text( 'theme-switch' )
1128
+ )
1129
+ ),
1130
+ 'input_type' => '',
1131
+ 'input_placeholder' => ''
1132
+ );
1133
+
1134
+ $reason_other = array(
1135
+ 'id' => self::REASON_OTHER,
1136
+ 'text' => $this->get_text( 'reason-other' ),
1137
+ 'input_type' => 'textfield',
1138
+ 'input_placeholder' => ''
1139
+ );
1140
+
1141
+ $long_term_user_reasons = array(
1142
+ array(
1143
+ 'id' => self::REASON_NO_LONGER_NEEDED,
1144
+ 'text' => sprintf( $this->get_text( 'reason-no-longer-needed' ), $module_type ),
1145
+ 'input_type' => '',
1146
+ 'input_placeholder' => ''
1147
+ ),
1148
+ $reason_found_better_plugin,
1149
+ array(
1150
+ 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
1151
+ 'text' => sprintf( $this->get_text( 'reason-needed-for-a-short-period' ), $module_type ),
1152
+ 'input_type' => '',
1153
+ 'input_placeholder' => ''
1154
+ ),
1155
+ array(
1156
+ 'id' => self::REASON_BROKE_MY_SITE,
1157
+ 'text' => sprintf( $this->get_text( 'reason-broke-my-site' ), $module_type ),
1158
+ 'input_type' => '',
1159
+ 'input_placeholder' => '',
1160
+ 'internal_message' => $contact_support_template
1161
+ ),
1162
+ array(
1163
+ 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
1164
+ 'text' => sprintf( $this->get_text( 'reason-suddenly-stopped-working' ), $module_type ),
1165
+ 'input_type' => '',
1166
+ 'input_placeholder' => '',
1167
+ 'internal_message' => $contact_support_template
1168
+ )
1169
+ );
1170
+
1171
+ if ( $this->is_paying() ) {
1172
+ $long_term_user_reasons[] = array(
1173
+ 'id' => self::REASON_CANT_PAY_ANYMORE,
1174
+ 'text' => $this->get_text( 'reason-cant-pay-anymore' ),
1175
+ 'input_type' => 'textfield',
1176
+ 'input_placeholder' => $this->get_text( 'placeholder-comfortable-price' )
1177
+ );
1178
+ }
1179
+
1180
+ $reason_dont_share_info = array(
1181
+ 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
1182
+ 'text' => $this->get_text( 'reason-dont-like-to-share-my-information' ),
1183
+ 'input_type' => '',
1184
+ 'input_placeholder' => ''
1185
+ );
1186
+
1187
+ /**
1188
+ * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
1189
+ * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
1190
+ * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
1191
+ * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
1192
+ * button in the opt-in form is shown/hidden).
1193
+ */
1194
+ if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
1195
+ $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
1196
+ }
1197
+
1198
+ $uninstall_reasons = array(
1199
+ 'long-term' => $long_term_user_reasons,
1200
+ 'non-registered-and-non-anonymous-short-term' => array(
1201
+ array(
1202
+ 'id' => self::REASON_DIDNT_WORK,
1203
+ 'text' => sprintf( $this->get_text( 'reason-didnt-work' ), $module_type ),
1204
+ 'input_type' => '',
1205
+ 'input_placeholder' => ''
1206
+ ),
1207
+ $reason_dont_share_info,
1208
+ $reason_found_better_plugin
1209
+ ),
1210
+ 'short-term' => array(
1211
+ array(
1212
+ 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
1213
+ 'text' => $this->get_text( 'reason-couldnt-make-it-work' ),
1214
+ 'input_type' => '',
1215
+ 'input_placeholder' => '',
1216
+ 'internal_message' => $contact_support_template
1217
+ ),
1218
+ $reason_found_better_plugin,
1219
+ array(
1220
+ 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
1221
+ 'text' => sprintf( $this->get_text( 'reason-great-but-need-specific-feature' ), $module_type ),
1222
+ 'input_type' => 'textarea',
1223
+ 'input_placeholder' => $this->get_text( 'placeholder-feature' )
1224
+ ),
1225
+ array(
1226
+ 'id' => self::REASON_NOT_WORKING,
1227
+ 'text' => sprintf( $this->get_text( 'reason-not-working' ), $module_type ),
1228
+ 'input_type' => 'textarea',
1229
+ 'input_placeholder' => $this->get_text( 'placeholder-share-what-didnt-work' )
1230
+ ),
1231
+ array(
1232
+ 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
1233
+ 'text' => $this->get_text( 'reason-not-what-i-was-looking-for' ),
1234
+ 'input_type' => 'textarea',
1235
+ 'input_placeholder' => $this->get_text( 'placeholder-what-youve-been-looking-for' )
1236
+ ),
1237
+ array(
1238
+ 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
1239
+ 'text' => sprintf( $this->get_text( 'reason-didnt-work-as-expected' ), $module_type ),
1240
+ 'input_type' => 'textarea',
1241
+ 'input_placeholder' => $this->get_text( 'placeholder-what-did-you-expect' )
1242
+ )
1243
+ )
1244
+ );
1245
+
1246
+ // Randomize the reasons for the current user type.
1247
+ shuffle( $uninstall_reasons[ $user_type ] );
1248
+
1249
+ // Keep the following reasons as the last items in the list.
1250
+ $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
1251
+ $uninstall_reasons[ $user_type ][] = $reason_other;
1252
+
1253
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
1254
+
1255
+ return $uninstall_reasons[ $user_type ];
1256
+ }
1257
+
1258
+ /**
1259
+ * Called after the user has submitted his reason for deactivating the plugin.
1260
+ *
1261
+ * @author Leo Fajardo (@leorw)
1262
+ * @since 1.1.2
1263
+ */
1264
+ function _submit_uninstall_reason_action() {
1265
+ $this->_logger->entrance();
1266
+
1267
+ $this->check_ajax_referer( 'submit_uninstall_reason' );
1268
+
1269
+ $reason_id = fs_request_get( 'reason_id' );
1270
+
1271
+ // Check if the given reason ID is an unsigned integer.
1272
+ if ( ! ctype_digit( $reason_id ) ) {
1273
+ exit;
1274
+ }
1275
+
1276
+ $reason_info = trim( fs_request_get( 'reason_info', '' ) );
1277
+ if ( ! empty( $reason_info ) ) {
1278
+ $reason_info = substr( $reason_info, 0, 128 );
1279
+ }
1280
+
1281
+ $reason = (object) array(
1282
+ 'id' => $reason_id,
1283
+ 'info' => $reason_info,
1284
+ 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
1285
+ );
1286
+
1287
+ $this->_storage->store( 'uninstall_reason', $reason );
1288
+
1289
+ /**
1290
+ * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
1291
+ * not support uninstall hook.
1292
+ *
1293
+ * @author Leo Fajardo (@leorw)
1294
+ * @since 1.2.2
1295
+ */
1296
+ if ( $this->is_theme() ) {
1297
+ $this->_uninstall_plugin_event( false );
1298
+ $this->remove_sdk_reference();
1299
+ }
1300
+
1301
+ // Print '1' for successful operation.
1302
+ echo 1;
1303
+ exit;
1304
+ }
1305
+
1306
+ #endregion
1307
+
1308
+ #----------------------------------------------------------------------------------
1309
+ #region Instance
1310
+ #----------------------------------------------------------------------------------
1311
+
1312
+ /**
1313
+ * Main singleton instance.
1314
+ *
1315
+ * @author Vova Feldman (@svovaf)
1316
+ * @since 1.0.0
1317
+ *
1318
+ * @param number $module_id
1319
+ * @param string|bool $slug
1320
+ * @param bool $is_init Is initiation sequence.
1321
+ *
1322
+ * @return Freemius|false
1323
+ */
1324
+ static function instance( $module_id, $slug = false, $is_init = false ) {
1325
+ if ( empty( $module_id ) ) {
1326
+ return false;
1327
+ }
1328
+
1329
+ if ( ! is_numeric( $module_id ) ) {
1330
+ if ( ! $is_init && true === $slug ) {
1331
+ $is_init = true;
1332
+ }
1333
+
1334
+ $slug = $module_id;
1335
+
1336
+ $module = FS_Plugin_Manager::instance( $slug )->get();
1337
+
1338
+ if ( is_object( $module ) ) {
1339
+ $module_id = $module->id;
1340
+ }
1341
+ }
1342
+
1343
+ $key = 'm_' . $module_id;
1344
+
1345
+ if ( ! isset( self::$_instances[ $key ] ) ) {
1346
+ if ( 0 === count( self::$_instances ) ) {
1347
+ self::_load_required_static();
1348
+ }
1349
+
1350
+ self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
1351
+ }
1352
+
1353
+ return self::$_instances[ $key ];
1354
+ }
1355
+
1356
+ /**
1357
+ * @author Vova Feldman (@svovaf)
1358
+ * @since 1.0.6
1359
+ *
1360
+ * @param number $addon_id
1361
+ *
1362
+ * @return bool
1363
+ */
1364
+ private static function has_instance( $addon_id ) {
1365
+ return isset( self::$_instances[ 'm_' . $addon_id ] );
1366
+ }
1367
+
1368
+ /**
1369
+ * @author Leo Fajardo (@leorw)
1370
+ * @since 1.2.2
1371
+ *
1372
+ * @param string|number $id_or_slug
1373
+ *
1374
+ * @return number|false
1375
+ */
1376
+ private static function get_module_id( $id_or_slug ) {
1377
+ if ( is_numeric( $id_or_slug ) ) {
1378
+ return $id_or_slug;
1379
+ }
1380
+
1381
+ foreach ( self::$_instances as $instance ) {
1382
+ if ( $instance->is_plugin() && ( $id_or_slug === $instance->get_slug() ) ) {
1383
+ return $instance->get_id();
1384
+ }
1385
+ }
1386
+
1387
+ return false;
1388
+ }
1389
+
1390
+ /**
1391
+ * @author Vova Feldman (@svovaf)
1392
+ * @since 1.0.6
1393
+ *
1394
+ * @param number $id
1395
+ *
1396
+ * @return false|Freemius
1397
+ */
1398
+ static function get_instance_by_id( $id ) {
1399
+ return isset ( self::$_instances[ 'm_' . $id ] ) ?
1400
+ self::$_instances[ 'm_' . $id ] :
1401
+ false;
1402
+ }
1403
+
1404
+ /**
1405
+ *
1406
+ * @author Vova Feldman (@svovaf)
1407
+ * @since 1.0.1
1408
+ *
1409
+ * @param $plugin_file
1410
+ *
1411
+ * @return false|Freemius
1412
+ */
1413
+ static function get_instance_by_file( $plugin_file ) {
1414
+ $slug = self::find_slug_by_basename( $plugin_file );
1415
+
1416
+ return ( false !== $slug ) ?
1417
+ self::instance( self::get_module_id( $slug ) ) :
1418
+ false;
1419
+ }
1420
+
1421
+ /**
1422
+ * @author Vova Feldman (@svovaf)
1423
+ * @since 1.0.6
1424
+ *
1425
+ * @return false|Freemius
1426
+ */
1427
+ function get_parent_instance() {
1428
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
1429
+ }
1430
+
1431
+ /**
1432
+ * @author Vova Feldman (@svovaf)
1433
+ * @since 1.0.6
1434
+ *
1435
+ * @param string|number $id_or_slug
1436
+ *
1437
+ * @return false|Freemius
1438
+ */
1439
+ function get_addon_instance( $id_or_slug ) {
1440
+ $addon_id = self::get_module_id( $id_or_slug );
1441
+
1442
+ return self::instance( $addon_id );
1443
+ }
1444
+
1445
+ #endregion ------------------------------------------------------------------
1446
+
1447
+ /**
1448
+ * @author Vova Feldman (@svovaf)
1449
+ * @since 1.0.6
1450
+ *
1451
+ * @return bool
1452
+ */
1453
+ function is_parent_plugin_installed() {
1454
+ $is_active = self::has_instance( $this->_plugin->parent_plugin_id );
1455
+
1456
+ if ( $is_active ) {
1457
+ return true;
1458
+ }
1459
+
1460
+ /**
1461
+ * Parent module might be a theme. If that's the case, the add-on's FS
1462
+ * instance will be loaded prior to the theme's FS instance, therefore,
1463
+ * we need to check if it's active with a "look ahead".
1464
+ *
1465
+ * @author Vova Feldman
1466
+ * @since 1.2.2.3
1467
+ */
1468
+ global $fs_active_plugins;
1469
+ if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
1470
+ $active_theme = wp_get_theme();
1471
+
1472
+ foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
1473
+ if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
1474
+ if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
1475
+ // Parent module is a theme and it's currently active.
1476
+ return true;
1477
+ }
1478
+ }
1479
+ }
1480
+ }
1481
+
1482
+ return false;
1483
+ }
1484
+
1485
+ /**
1486
+ * Check if add-on parent plugin in activation mode.
1487
+ *
1488
+ * @author Vova Feldman (@svovaf)
1489
+ * @since 1.0.7
1490
+ *
1491
+ * @return bool
1492
+ */
1493
+ function is_parent_in_activation() {
1494
+ $parent_fs = $this->get_parent_instance();
1495
+ if ( ! is_object( $parent_fs ) ) {
1496
+ return false;
1497
+ }
1498
+
1499
+ return ( $parent_fs->is_activation_mode() );
1500
+ }
1501
+
1502
+ /**
1503
+ * Is plugin in activation mode.
1504
+ *
1505
+ * @author Vova Feldman (@svovaf)
1506
+ * @since 1.0.7
1507
+ *
1508
+ * @param bool $and_on
1509
+ *
1510
+ * @return bool
1511
+ */
1512
+ function is_activation_mode( $and_on = true ) {
1513
+ return (
1514
+ ( $this->is_on() || ! $and_on ) &&
1515
+ ( ! $this->is_registered() || ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
1516
+ ( ! $this->is_enable_anonymous() ||
1517
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
1518
+ );
1519
+ }
1520
+
1521
+ /**
1522
+ * Check if current page is the opt-in/pending-activation page.
1523
+ *
1524
+ * @author Vova Feldman (@svovaf)
1525
+ * @since 1.2.1.7
1526
+ *
1527
+ * @return bool
1528
+ */
1529
+ function is_activation_page() {
1530
+ if ( $this->_menu->is_main_settings_page() ) {
1531
+ return true;
1532
+ }
1533
+
1534
+ if ( ! $this->is_activation_mode() ) {
1535
+ return false;
1536
+ }
1537
+
1538
+ // Check if current page is matching the activation page.
1539
+ return $this->is_matching_url( $this->get_activation_url() );
1540
+ }
1541
+
1542
+ /**
1543
+ * Check if URL path's are matching and that all querystring
1544
+ * arguments of the $sub_url exist in the $url with the same values.
1545
+ *
1546
+ * WARNING:
1547
+ * 1. This method doesn't check if the sub/domain are matching.
1548
+ * 2. Ignore case sensitivity.
1549
+ *
1550
+ * @author Vova Feldman (@svovaf)
1551
+ * @since 1.2.1.7
1552
+ *
1553
+ * @param string $sub_url
1554
+ * @param string $url If argument is not set, check if the sub_url matching the current's page URL.
1555
+ *
1556
+ * @return bool
1557
+ */
1558
+ private function is_matching_url( $sub_url, $url = '' ) {
1559
+ if ( empty( $url ) ) {
1560
+ $url = $_SERVER['REQUEST_URI'];
1561
+ }
1562
+
1563
+ $url = strtolower( $url );
1564
+ $sub_url = strtolower( $sub_url );
1565
+
1566
+ if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
1567
+ // Different path - DO NOT OVERRIDE PAGE.
1568
+ return false;
1569
+ }
1570
+
1571
+ $url_params = array();
1572
+ parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
1573
+
1574
+ $sub_url_params = array();
1575
+ parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
1576
+
1577
+ foreach ( $sub_url_params as $key => $val ) {
1578
+ if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
1579
+ // Not matching query string - DO NOT OVERRIDE PAGE.
1580
+ return false;
1581
+ }
1582
+ }
1583
+
1584
+ return true;
1585
+ }
1586
+
1587
+ /**
1588
+ * Get collection of all active plugins.
1589
+ *
1590
+ * @author Vova Feldman (@svovaf)
1591
+ * @since 1.0.9
1592
+ *
1593
+ * @return array[string]array
1594
+ */
1595
+ private static function get_active_plugins() {
1596
+ self::require_plugin_essentials();
1597
+
1598
+ $active_plugin = array();
1599
+ $all_plugins = get_plugins();
1600
+ $active_plugins_basenames = get_option( 'active_plugins' );
1601
+
1602
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
1603
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
1604
+ }
1605
+
1606
+ return $active_plugin;
1607
+ }
1608
+
1609
+ /**
1610
+ * Get collection of all plugins.
1611
+ *
1612
+ * @author Vova Feldman (@svovaf)
1613
+ * @since 1.1.8
1614
+ *
1615
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
1616
+ */
1617
+ private static function get_all_plugins() {
1618
+ self::require_plugin_essentials();
1619
+
1620
+ $all_plugins = get_plugins();
1621
+ $active_plugins_basenames = get_option( 'active_plugins' );
1622
+
1623
+ foreach ( $all_plugins as $basename => &$data ) {
1624
+ // By default set to inactive (next foreach update the active plugins).
1625
+ $data['is_active'] = false;
1626
+ // Enrich with plugin slug.
1627
+ $data['slug'] = self::get_plugin_slug( $basename );
1628
+ }
1629
+
1630
+ // Flag active plugins.
1631
+ foreach ( $active_plugins_basenames as $basename ) {
1632
+ if ( isset( $all_plugins[ $basename ] ) ) {
1633
+ $all_plugins[ $basename ]['is_active'] = true;
1634
+ }
1635
+ }
1636
+
1637
+ return $all_plugins;
1638
+ }
1639
+
1640
+
1641
+ /**
1642
+ * Cached result of get_site_transient( 'update_plugins' )
1643
+ *
1644
+ * @author Vova Feldman (@svovaf)
1645
+ * @since 1.1.8
1646
+ *
1647
+ * @var object
1648
+ */
1649
+ private static $_plugins_info;
1650
+
1651
+ /**
1652
+ * Helper function to get specified plugin's slug.
1653
+ *
1654
+ * @author Vova Feldman (@svovaf)
1655
+ * @since 1.1.8
1656
+ *
1657
+ * @param $basename
1658
+ *
1659
+ * @return string
1660
+ */
1661
+ private static function get_plugin_slug( $basename ) {
1662
+ if ( ! isset( self::$_plugins_info ) ) {
1663
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
1664
+ }
1665
+
1666
+ $slug = '';
1667
+
1668
+ if ( is_object( self::$_plugins_info ) ) {
1669
+ if ( isset( self::$_plugins_info->no_update ) &&
1670
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
1671
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
1672
+ ) {
1673
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
1674
+ } else if ( isset( self::$_plugins_info->response ) &&
1675
+ isset( self::$_plugins_info->response[ $basename ] ) &&
1676
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
1677
+ ) {
1678
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
1679
+ }
1680
+ }
1681
+
1682
+ if ( empty( $slug ) ) {
1683
+ // Try to find slug from FS data.
1684
+ $slug = self::find_slug_by_basename( $basename );
1685
+ }
1686
+
1687
+ if ( empty( $slug ) ) {
1688
+ // Fallback to plugin's folder name.
1689
+ $slug = dirname( $basename );
1690
+ }
1691
+
1692
+ return $slug;
1693
+ }
1694
+
1695
+ private static $_statics_loaded = false;
1696
+
1697
+ /**
1698
+ * Load static resources.
1699
+ *
1700
+ * @author Vova Feldman (@svovaf)
1701
+ * @since 1.0.1
1702
+ */
1703
+ private static function _load_required_static() {
1704
+ if ( self::$_statics_loaded ) {
1705
+ return;
1706
+ }
1707
+
1708
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
1709
+
1710
+ self::$_static_logger->entrance();
1711
+
1712
+ self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
1713
+
1714
+ self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
1715
+
1716
+ add_action( 'admin_menu', array( 'Freemius', '_add_debug_section' ) );
1717
+
1718
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
1719
+
1720
+ self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
1721
+
1722
+ self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
1723
+
1724
+ self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
1725
+
1726
+ if ( 0 == did_action( 'plugins_loaded' ) ) {
1727
+ add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
1728
+ }
1729
+
1730
+ self::$_statics_loaded = true;
1731
+ }
1732
+
1733
+ #----------------------------------------------------------------------------------
1734
+ #region Localization
1735
+ #----------------------------------------------------------------------------------
1736
+
1737
+ /**
1738
+ * Load framework's text domain.
1739
+ *
1740
+ * @author Vova Feldman (@svovaf)
1741
+ * @since 1.2.1
1742
+ */
1743
+ static function _load_textdomain() {
1744
+ if ( ! is_admin() ) {
1745
+ return;
1746
+ }
1747
+
1748
+ global $fs_active_plugins;
1749
+
1750
+ // Works both for plugins and themes.
1751
+ load_plugin_textdomain(
1752
+ 'freemius',
1753
+ false,
1754
+ $fs_active_plugins->newest->sdk_path . '/languages/'
1755
+ );
1756
+ }
1757
+
1758
+ #endregion
1759
+
1760
+ #----------------------------------------------------------------------------------
1761
+ #region Debugging
1762
+ #----------------------------------------------------------------------------------
1763
+
1764
+ /**
1765
+ * @author Vova Feldman (@svovaf)
1766
+ * @since 1.0.8
1767
+ */
1768
+ static function _add_debug_section() {
1769
+ if ( ! current_user_can( 'activate_plugins' )
1770
+ && ! current_user_can( 'switch_themes' )
1771
+ ) {
1772
+ return;
1773
+ }
1774
+
1775
+ self::$_static_logger->entrance();
1776
+
1777
+ $title = sprintf( '%s [v.%s]', fs_text( 'freemius-debug' ), WP_FS__SDK_VERSION );
1778
+
1779
+ if ( WP_FS__DEV_MODE ) {
1780
+ // Add top-level debug menu item.
1781
+ $hook = FS_Admin_Menu_Manager::add_page(
1782
+ $title,
1783
+ $title,
1784
+ 'manage_options',
1785
+ 'freemius',
1786
+ array( 'Freemius', '_debug_page_render' )
1787
+ );
1788
+ } else {
1789
+ // Add hidden debug page.
1790
+ $hook = FS_Admin_Menu_Manager::add_subpage(
1791
+ null,
1792
+ $title,
1793
+ $title,
1794
+ 'manage_options',
1795
+ 'freemius',
1796
+ array( 'Freemius', '_debug_page_render' )
1797
+ );
1798
+ }
1799
+
1800
+ if ( ! empty( $hook ) ) {
1801
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
1802
+ }
1803
+ }
1804
+
1805
+ /**
1806
+ * @author Vova Feldman (@svovaf)
1807
+ * @since 1.1.7.3
1808
+ */
1809
+ static function _toggle_debug_mode() {
1810
+ $is_on = fs_request_get( 'is_on', false, 'post' );
1811
+
1812
+ if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
1813
+ update_option( 'fs_debug_mode', $is_on );
1814
+
1815
+ // Turn on/off storage logging.
1816
+ FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
1817
+ }
1818
+
1819
+ exit;
1820
+ }
1821
+
1822
+ /**
1823
+ * @author Vova Feldman (@svovaf)
1824
+ * @since 1.2.1.6
1825
+ */
1826
+ static function _get_debug_log() {
1827
+ $logs = FS_Logger::load_db_logs(
1828
+ fs_request_get( 'filters', false, 'post' ),
1829
+ ! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? $_POST['limit'] : 200,
1830
+ ! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? $_POST['offset'] : 0
1831
+ );
1832
+
1833
+ self::shoot_ajax_success( $logs );
1834
+ }
1835
+
1836
+ /**
1837
+ * @author Vova Feldman (@svovaf)
1838
+ * @since 1.2.1.7
1839
+ */
1840
+ static function _get_db_option() {
1841
+ $option_name = fs_request_get( 'option_name' );
1842
+
1843
+ $value = get_option( $option_name );
1844
+
1845
+ $result = array(
1846
+ 'name' => $option_name,
1847
+ );
1848
+
1849
+ if ( false !== $value ) {
1850
+ if ( ! is_string( $value ) ) {
1851
+ $value = json_encode( $value );
1852
+ }
1853
+
1854
+ $result['value'] = $value;
1855
+ }
1856
+
1857
+ self::shoot_ajax_success( $result );
1858
+ }
1859
+
1860
+ /**
1861
+ * @author Vova Feldman (@svovaf)
1862
+ * @since 1.2.1.7
1863
+ */
1864
+ static function _set_db_option() {
1865
+ $option_name = fs_request_get( 'option_name' );
1866
+ $option_value = fs_request_get( 'option_value' );
1867
+
1868
+ if ( ! empty( $option_value ) ) {
1869
+ update_option( $option_name, $option_value );
1870
+ }
1871
+
1872
+ self::shoot_ajax_success();
1873
+ }
1874
+
1875
+ /**
1876
+ * @author Vova Feldman (@svovaf)
1877
+ * @since 1.0.8
1878
+ */
1879
+ static function _debug_page_actions() {
1880
+ self::_clean_admin_content_section();
1881
+
1882
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
1883
+ check_admin_referer( 'restart_freemius' );
1884
+
1885
+ // Clear accounts data.
1886
+ self::$_accounts->clear( true );
1887
+
1888
+ // Clear SDK reference cache.
1889
+ delete_option( 'fs_active_plugins' );
1890
+ } else if ( fs_request_is_action( 'simulate_trial' ) ) {
1891
+ check_admin_referer( 'simulate_trial' );
1892
+
1893
+ $fs = freemius( fs_request_get( 'module_id' ) );
1894
+
1895
+ // Update SDK install to at least 24 hours before.
1896
+ $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
1897
+ // Unset the trial shown timestamp.
1898
+ unset( $fs->_storage->trial_promotion_shown );
1899
+ } else if ( fs_request_is_action( 'delete_install' ) ) {
1900
+ check_admin_referer( 'delete_install' );
1901
+
1902
+ self::_delete_site_by_slug(
1903
+ fs_request_get( 'slug' ),
1904
+ fs_request_get( 'module_type' )
1905
+ );
1906
+ } else if ( fs_request_is_action( 'download_logs' ) ) {
1907
+ check_admin_referer( 'download_logs' );
1908
+
1909
+ $download_url = FS_Logger::download_db_logs(
1910
+ fs_request_get( 'filters', false, 'post' )
1911
+ );
1912
+
1913
+ if ( false === $download_url ) {
1914
+ wp_die( 'Oops... there was an error while generating the logs download file. Please try again and if it doesn\'t work contact support@freemius.com.' );
1915
+ }
1916
+
1917
+ fs_redirect( $download_url );
1918
+ }
1919
+ }
1920
+
1921
+ /**
1922
+ * @author Vova Feldman (@svovaf)
1923
+ * @since 1.0.8
1924
+ */
1925
+ static function _debug_page_render() {
1926
+ self::$_static_logger->entrance();
1927
+
1928
+ $vars = array(
1929
+ 'plugin_sites' => self::get_all_sites(),
1930
+ 'theme_sites' => self::get_all_sites( WP_FS__MODULE_TYPE_THEME ),
1931
+ 'users' => self::get_all_users(),
1932
+ 'addons' => self::get_all_addons(),
1933
+ 'account_addons' => self::get_all_account_addons(),
1934
+ 'plugin_licenses' => self::get_all_licenses(),
1935
+ 'theme_licenses' => self::get_all_licenses( WP_FS__MODULE_TYPE_THEME )
1936
+ );
1937
+
1938
+ fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
1939
+ fs_require_once_template( 'debug.php', $vars );
1940
+ }
1941
+
1942
+ #endregion
1943
+
1944
+ #----------------------------------------------------------------------------------
1945
+ #region Connectivity Issues
1946
+ #----------------------------------------------------------------------------------
1947
+
1948
+ /**
1949
+ * Check if Freemius should be turned on for the current plugin install.
1950
+ *
1951
+ * Note:
1952
+ * $this->_is_on is updated in has_api_connectivity()
1953
+ *
1954
+ * @author Vova Feldman (@svovaf)
1955
+ * @since 1.0.9
1956
+ *
1957
+ * @return bool
1958
+ */
1959
+ function is_on() {
1960
+ self::$_static_logger->entrance();
1961
+
1962
+ if ( isset( $this->_is_on ) ) {
1963
+ return $this->_is_on;
1964
+ }
1965
+
1966
+ // If already installed or pending then sure it's on :)
1967
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
1968
+ $this->_is_on = true;
1969
+
1970
+ return true;
1971
+ }
1972
+
1973
+ return false;
1974
+ }
1975
+
1976
+ /**
1977
+ * @author Vova Feldman (@svovaf)
1978
+ * @since 1.1.7.3
1979
+ *
1980
+ * @param bool $flush_if_no_connectivity
1981
+ *
1982
+ * @return bool
1983
+ */
1984
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
1985
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
1986
+ // Connectivity test was never executed, or cache was cleared.
1987
+ return true;
1988
+ }
1989
+
1990
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
1991
+ if ( WP_FS__IS_HTTP_REQUEST ) {
1992
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
1993
+ // Domain changed.
1994
+ return true;
1995
+ }
1996
+
1997
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
1998
+ // Server IP changed.
1999
+ return true;
2000
+ }
2001
+ }
2002
+ }
2003
+
2004
+ if ( $this->_storage->connectivity_test['is_connected'] &&
2005
+ $this->_storage->connectivity_test['is_active']
2006
+ ) {
2007
+ // API connected and Freemius is active - no need to run connectivity check.
2008
+ return false;
2009
+ }
2010
+
2011
+ if ( $flush_if_no_connectivity ) {
2012
+ /**
2013
+ * If explicitly asked to flush when no connectivity - do it only
2014
+ * if at least 10 sec passed from the last API connectivity test.
2015
+ */
2016
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
2017
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
2018
+ }
2019
+
2020
+ /**
2021
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
2022
+ */
2023
+ $version = $this->get_plugin_version();
2024
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
2025
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
2026
+ return true;
2027
+ }
2028
+
2029
+ return false;
2030
+ }
2031
+
2032
+ /**
2033
+ * @author Vova Feldman (@svovaf)
2034
+ * @since 1.1.7.4
2035
+ *
2036
+ * @return object|false
2037
+ */
2038
+ private function ping() {
2039
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
2040
+ return false;
2041
+ }
2042
+
2043
+ $version = $this->get_plugin_version();
2044
+
2045
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
2046
+
2047
+ return $this->get_api_plugin_scope()->ping(
2048
+ $this->get_anonymous_id(),
2049
+ array(
2050
+ 'is_update' => json_encode( $is_update ),
2051
+ 'version' => $version,
2052
+ 'sdk' => $this->version,
2053
+ 'is_admin' => json_encode( is_admin() ),
2054
+ 'is_ajax' => json_encode( self::is_ajax() ),
2055
+ 'is_cron' => json_encode( self::is_cron() ),
2056
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
2057
+ )
2058
+ );
2059
+ }
2060
+
2061
+ /**
2062
+ * Check if there's any connectivity issue to Freemius API.
2063
+ *
2064
+ * @author Vova Feldman (@svovaf)
2065
+ * @since 1.0.9
2066
+ *
2067
+ * @param bool $flush_if_no_connectivity
2068
+ *
2069
+ * @return bool
2070
+ */
2071
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
2072
+ $this->_logger->entrance();
2073
+
2074
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
2075
+ return $this->_has_api_connection;
2076
+ }
2077
+
2078
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
2079
+ isset( $this->_storage->connectivity_test ) &&
2080
+ true === $this->_storage->connectivity_test['is_connected']
2081
+ ) {
2082
+ unset( $this->_storage->connectivity_test );
2083
+ }
2084
+
2085
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
2086
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
2087
+ /**
2088
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
2089
+ *
2090
+ * @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.
2091
+ */
2092
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
2093
+ $this->is_premium() ||
2094
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
2095
+
2096
+ return $this->_has_api_connection;
2097
+ }
2098
+
2099
+ $pong = $this->ping();
2100
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
2101
+
2102
+ if ( ! $is_connected ) {
2103
+ // API failure.
2104
+ $this->_add_connectivity_issue_message( $pong );
2105
+ }
2106
+
2107
+ $this->store_connectivity_info( $pong, $is_connected );
2108
+
2109
+ return $this->_has_api_connection;
2110
+ }
2111
+
2112
+ /**
2113
+ * @author Vova Feldman (@svovaf)
2114
+ * @since 1.1.7.4
2115
+ *
2116
+ * @param object $pong
2117
+ * @param bool $is_connected
2118
+ */
2119
+ private function store_connectivity_info( $pong, $is_connected ) {
2120
+ $this->_logger->entrance();
2121
+
2122
+ $version = $this->get_plugin_version();
2123
+
2124
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
2125
+ $is_active = false;
2126
+ } else {
2127
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
2128
+ }
2129
+
2130
+ $is_active = $this->apply_filters(
2131
+ 'is_on',
2132
+ $is_active,
2133
+ $this->is_plugin_update(),
2134
+ $version
2135
+ );
2136
+
2137
+ $this->_storage->connectivity_test = array(
2138
+ 'is_connected' => $is_connected,
2139
+ 'host' => $_SERVER['HTTP_HOST'],
2140
+ 'server_ip' => WP_FS__REMOTE_ADDR,
2141
+ 'is_active' => $is_active,
2142
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
2143
+ // Last version with connectivity attempt.
2144
+ 'version' => $version,
2145
+ );
2146
+
2147
+ $this->_has_api_connection = $is_connected;
2148
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
2149
+ }
2150
+
2151
+ /**
2152
+ * Force turning Freemius on.
2153
+ *
2154
+ * @author Vova Feldman (@svovaf)
2155
+ * @since 1.1.8.1
2156
+ *
2157
+ * @return bool TRUE if successfully turned on.
2158
+ */
2159
+ private function turn_on() {
2160
+ $this->_logger->entrance();
2161
+
2162
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
2163
+ return false;
2164
+ }
2165
+
2166
+ $updated_connectivity = $this->_storage->connectivity_test;
2167
+ $updated_connectivity['is_active'] = true;
2168
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
2169
+ $this->_storage->connectivity_test = $updated_connectivity;
2170
+
2171
+ $this->_is_on = true;
2172
+
2173
+ return true;
2174
+ }
2175
+
2176
+ /**
2177
+ * Anonymous and unique site identifier (Hash).
2178
+ *
2179
+ * @author Vova Feldman (@svovaf)
2180
+ * @since 1.1.0
2181
+ *
2182
+ * @return string
2183
+ */
2184
+ function get_anonymous_id() {
2185
+ $unique_id = self::$_accounts->get_option( 'unique_id' );
2186
+
2187
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
2188
+ $key = get_site_url();
2189
+
2190
+ // If localhost, assign microtime instead of domain.
2191
+ if ( WP_FS__IS_LOCALHOST ||
2192
+ false !== strpos( $key, 'localhost' ) ||
2193
+ false === strpos( $key, '.' )
2194
+ ) {
2195
+ $key = microtime();
2196
+ }
2197
+
2198
+ $unique_id = md5( $key );
2199
+
2200
+ self::$_accounts->set_option( 'unique_id', $unique_id, true );
2201
+ }
2202
+
2203
+ $this->_logger->departure( $unique_id );
2204
+
2205
+ return $unique_id;
2206
+ }
2207
+
2208
+ /**
2209
+ * @author Vova Feldman (@svovaf)
2210
+ * @since 1.1.7.4
2211
+ *
2212
+ * @return \WP_User
2213
+ */
2214
+ static function _get_current_wp_user() {
2215
+ self::require_pluggable_essentials();
2216
+
2217
+ return wp_get_current_user();
2218
+ }
2219
+
2220
+ /**
2221
+ * @author Vova Feldman (@svovaf)
2222
+ * @since 1.2.1.7
2223
+ *
2224
+ * @param string $email
2225
+ *
2226
+ * @return bool
2227
+ */
2228
+ static function is_valid_email( $email ) {
2229
+ if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
2230
+ return false;
2231
+ }
2232
+
2233
+ $parts = explode( '@', $email );
2234
+
2235
+ if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
2236
+ return false;
2237
+ }
2238
+
2239
+ $blacklist = array(
2240
+ 'admin.',
2241
+ 'webmaster.',
2242
+ 'localhost.',
2243
+ 'dev.',
2244
+ 'development.',
2245
+ 'test.',
2246
+ 'stage.',
2247
+ 'staging.',
2248
+ );
2249
+
2250
+ // Make sure domain is not one of the blacklisted.
2251
+ foreach ( $blacklist as $invalid ) {
2252
+ if ( 0 === strpos( $parts[1], $invalid ) ) {
2253
+ return false;
2254
+ }
2255
+ }
2256
+
2257
+ // Get the UTF encoded domain name.
2258
+ $domain = idn_to_ascii( $parts[1] ) . '.';
2259
+
2260
+ return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
2261
+ }
2262
+
2263
+ /**
2264
+ * Generate API connectivity issue message.
2265
+ *
2266
+ * @author Vova Feldman (@svovaf)
2267
+ * @since 1.0.9
2268
+ *
2269
+ * @param mixed $api_result
2270
+ * @param bool $is_first_failure
2271
+ */
2272
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
2273
+ if ( ! $this->is_premium() && $this->_enable_anonymous ) {
2274
+ // Don't add message if it's the free version and can run anonymously.
2275
+ return;
2276
+ }
2277
+
2278
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
2279
+ require_once ABSPATH . 'wp-includes/functions.php';
2280
+ }
2281
+
2282
+ $current_user = self::_get_current_wp_user();
2283
+ // $admin_email = get_option( 'admin_email' );
2284
+ $admin_email = $current_user->user_email;
2285
+
2286
+ $message = false;
2287
+ if ( is_object( $api_result ) &&
2288
+ isset( $api_result->error ) &&
2289
+ isset( $api_result->error->code )
2290
+ ) {
2291
+ switch ( $api_result->error->code ) {
2292
+ case 'curl_missing':
2293
+ $missing_methods = '';
2294
+ if ( is_array( $api_result->missing_methods ) &&
2295
+ ! empty( $api_result->missing_methods )
2296
+ ) {
2297
+ foreach ( $api_result->missing_methods as $m ) {
2298
+ if ( 'curl_version' === $m ) {
2299
+ continue;
2300
+ }
2301
+
2302
+ if ( ! empty( $missing_methods ) ) {
2303
+ $missing_methods .= ', ';
2304
+ }
2305
+
2306
+ $missing_methods .= sprintf( '<code>%s</code>', $m );
2307
+ }
2308
+
2309
+ if ( ! empty( $missing_methods ) ) {
2310
+ $missing_methods = sprintf(
2311
+ '<br><br><b>%s</b> %s',
2312
+ $this->get_text( 'curl-disabled-methods' ),
2313
+ $missing_methods
2314
+ );
2315
+ }
2316
+ }
2317
+
2318
+ $message = sprintf(
2319
+ $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2320
+ $this->get_text( 'curl-missing-message' ) . ' ' .
2321
+ $missing_methods .
2322
+ ' %s',
2323
+ '<b>' . $this->get_plugin_name() . '</b>',
2324
+ sprintf(
2325
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
2326
+ sprintf(
2327
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
2328
+ $this->get_text( 'curl-missing-no-clue-title' ),
2329
+ ' - ' . sprintf(
2330
+ $this->get_text( 'curl-missing-no-clue-desc' ),
2331
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2332
+ )
2333
+ ),
2334
+ sprintf(
2335
+ '<b>%s</b> - %s',
2336
+ $this->get_text( 'sysadmin-title' ),
2337
+ sprintf( $this->get_text( 'curl-missing-sysadmin-desc' ), $this->_module_type )
2338
+ ),
2339
+ sprintf(
2340
+ '<a href="%s"><b>%s</b></a>%s',
2341
+ 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 ),
2342
+ $this->get_text( 'deactivate-plugin-title' ),
2343
+ ' - ' . $this->get_text( 'deactivate-plugin-desc' )
2344
+ )
2345
+ )
2346
+ );
2347
+ break;
2348
+ case 'cloudflare_ddos_protection':
2349
+ $message = sprintf(
2350
+ $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2351
+ $this->get_text( 'cloudflare-blocks-connection-message' ) . ' ' .
2352
+ $this->get_text( 'happy-to-resolve-issue-asap' ) .
2353
+ ' %s',
2354
+ '<b>' . $this->get_plugin_name() . '</b>',
2355
+ sprintf(
2356
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
2357
+ sprintf(
2358
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
2359
+ $this->get_text( 'fix-issue-title' ),
2360
+ ' - ' . sprintf(
2361
+ $this->get_text( 'fix-issue-desc' ),
2362
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2363
+ )
2364
+ ),
2365
+ sprintf(
2366
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
2367
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
2368
+ $this->get_text( 'install-previous-title' ),
2369
+ ' - ' . $this->get_text( 'install-previous-desc' )
2370
+ ),
2371
+ sprintf(
2372
+ '<a href="%s"><b>%s</b></a>%s',
2373
+ 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 ),
2374
+ $this->get_text( 'deactivate-plugin-title' ),
2375
+ ' - ' . $this->get_text( 'deactivate-plugin-desc' )
2376
+ )
2377
+ )
2378
+ );
2379
+ break;
2380
+ case 'squid_cache_block':
2381
+ $message = sprintf(
2382
+ $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2383
+ $this->get_text( 'squid-blocks-connection-message' ) .
2384
+ ' %s',
2385
+ '<b>' . $this->get_plugin_name() . '</b>',
2386
+ sprintf(
2387
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
2388
+ sprintf(
2389
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
2390
+ $this->get_text( 'squid-no-clue-title' ),
2391
+ ' - ' . sprintf(
2392
+ $this->get_text( 'squid-no-clue-desc' ),
2393
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2394
+ )
2395
+ ),
2396
+ sprintf(
2397
+ '<b>%s</b> - %s',
2398
+ $this->get_text( 'sysadmin-title' ),
2399
+ sprintf(
2400
+ $this->get_text( 'squid-sysadmin-desc' ),
2401
+ // We use a filter since the plugin might require additional API connectivity.
2402
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com', 'wp.freemius.com' ) ) ) . '</b>',
2403
+ $this->_module_type
2404
+ )
2405
+ ),
2406
+ sprintf(
2407
+ '<a href="%s"><b>%s</b></a>%s',
2408
+ 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 ),
2409
+ $this->get_text( 'deactivate-plugin-title' ),
2410
+ ' - ' . $this->get_text( 'deactivate-plugin-desc' )
2411
+ )
2412
+ )
2413
+ );
2414
+ break;
2415
+ // default:
2416
+ // $message = $this->get_text( 'connectivity-test-fails-message' );
2417
+ // break;
2418
+ }
2419
+ }
2420
+
2421
+ $message_id = 'failed_connect_api';
2422
+ $type = 'error';
2423
+
2424
+ if ( false === $message ) {
2425
+ if ( $is_first_failure ) {
2426
+ // First attempt failed.
2427
+ $message = sprintf(
2428
+ $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2429
+ $this->get_text( 'connectivity-test-fails-message' ) . ' ' .
2430
+ $this->get_text( 'connectivity-test-maybe-temporary' ) . '<br><br>' .
2431
+ '%s',
2432
+ '<b>' . $this->get_plugin_name() . '</b>',
2433
+ sprintf(
2434
+ '<div id="fs_firewall_issue_options">%s %s</div>',
2435
+ sprintf(
2436
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
2437
+ $this->get_text( 'yes-do-your-thing' )
2438
+ ),
2439
+ sprintf(
2440
+ '<a href="%s" class="button">%s</a>',
2441
+ 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 ),
2442
+ $this->get_text( 'no-deactivate' )
2443
+ )
2444
+ )
2445
+ );
2446
+
2447
+ $message_id = 'failed_connect_api_first';
2448
+ $type = 'promotion';
2449
+ } else {
2450
+ // Second connectivity attempt failed.
2451
+ $message = sprintf(
2452
+ $this->get_text( 'x-requires-access-to-api' ) . ' ' .
2453
+ $this->get_text( 'connectivity-test-fails-message' ) . ' ' .
2454
+ $this->get_text( 'happy-to-resolve-issue-asap' ) .
2455
+ ' %s',
2456
+ '<b>' . $this->get_plugin_name() . '</b>',
2457
+ sprintf(
2458
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
2459
+ sprintf(
2460
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
2461
+ $this->get_text( 'fix-issue-title' ),
2462
+ ' - ' . sprintf(
2463
+ $this->get_text( 'fix-issue-desc' ),
2464
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2465
+ )
2466
+ ),
2467
+ sprintf(
2468
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
2469
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
2470
+ $this->get_text( 'install-previous-title' ),
2471
+ ' - ' . $this->get_text( 'install-previous-desc' )
2472
+ ),
2473
+ sprintf(
2474
+ '<a href="%s"><b>%s</b></a>%s',
2475
+ 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 ),
2476
+ $this->get_text( 'deactivate-plugin-title' ),
2477
+ ' - ' . $this->get_text( 'deactivate-plugin-desc' )
2478
+ )
2479
+ )
2480
+ );
2481
+ }
2482
+ }
2483
+
2484
+ $this->_admin_notices->add_sticky(
2485
+ $message,
2486
+ $message_id,
2487
+ $this->get_text( 'oops' ) . '...',
2488
+ $type
2489
+ );
2490
+ }
2491
+
2492
+ /**
2493
+ * Handle user request to resolve connectivity issue.
2494
+ * This method will send an email to Freemius API technical staff for resolution.
2495
+ * The email will contain server's info and installed plugins (might be caching issue).
2496
+ *
2497
+ * @author Vova Feldman (@svovaf)
2498
+ * @since 1.0.9
2499
+ */
2500
+ function _email_about_firewall_issue() {
2501
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
2502
+
2503
+ $pong = $this->ping();
2504
+
2505
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
2506
+
2507
+ if ( $is_connected ) {
2508
+ $this->store_connectivity_info( $pong, $is_connected );
2509
+
2510
+ echo $this->get_after_plugin_activation_redirect_url();
2511
+ exit;
2512
+ }
2513
+
2514
+ $current_user = self::_get_current_wp_user();
2515
+ $admin_email = $current_user->user_email;
2516
+
2517
+ $error_type = fs_request_get( 'error_type', 'general' );
2518
+
2519
+ switch ( $error_type ) {
2520
+ case 'squid':
2521
+ $title = 'Squid ACL Blocking Issue';
2522
+ break;
2523
+ case 'cloudflare':
2524
+ $title = 'CloudFlare Blocking Issue';
2525
+ break;
2526
+ default:
2527
+ $title = 'API Connectivity Issue';
2528
+ break;
2529
+ }
2530
+
2531
+ $custom_email_sections = array();
2532
+
2533
+ // Add 'API Error' custom email section.
2534
+ $custom_email_sections['api_error'] = array(
2535
+ 'title' => 'API Error',
2536
+ 'rows' => array(
2537
+ 'ping' => array(
2538
+ 'API Error',
2539
+ is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
2540
+ ),
2541
+ )
2542
+ );
2543
+
2544
+ // Send email with technical details to resolve API connectivity issues.
2545
+ $this->send_email(
2546
+ 'api@freemius.com', // recipient
2547
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
2548
+ $custom_email_sections,
2549
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
2550
+ );
2551
+
2552
+ $this->_admin_notices->add_sticky(
2553
+ sprintf(
2554
+ $this->get_text( 'fix-request-sent-message' ),
2555
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
2556
+ ),
2557
+ 'server_details_sent'
2558
+ );
2559
+
2560
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
2561
+
2562
+ echo "1";
2563
+ exit;
2564
+ }
2565
+
2566
+ /**
2567
+ * Handle connectivity test retry approved by the user.
2568
+ *
2569
+ * @author Vova Feldman (@svovaf)
2570
+ * @since 1.1.7.4
2571
+ */
2572
+ function _retry_connectivity_test() {
2573
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
2574
+
2575
+ $pong = $this->ping();
2576
+
2577
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
2578
+
2579
+ if ( $is_connected ) {
2580
+ $this->store_connectivity_info( $pong, $is_connected );
2581
+
2582
+ echo $this->get_after_plugin_activation_redirect_url();
2583
+ } else {
2584
+ // Add connectivity issue message after 2nd failed attempt.
2585
+ $this->_add_connectivity_issue_message( $pong, false );
2586
+
2587
+ echo "1";
2588
+ }
2589
+
2590
+ exit;
2591
+ }
2592
+
2593
+ static function _add_firewall_issues_javascript() {
2594
+ $params = array();
2595
+ fs_require_once_template( 'firewall-issues-js.php', $params );
2596
+ }
2597
+
2598
+ #endregion
2599
+
2600
+ #----------------------------------------------------------------------------------
2601
+ #region Email
2602
+ #----------------------------------------------------------------------------------
2603
+
2604
+ /**
2605
+ * Generates and sends an HTML email with customizable sections.
2606
+ *
2607
+ * @author Leo Fajardo (@leorw)
2608
+ * @since 1.1.2
2609
+ *
2610
+ * @param string $to_address
2611
+ * @param string $subject
2612
+ * @param array $sections
2613
+ * @param array $headers
2614
+ *
2615
+ * @return bool Whether the email contents were sent successfully.
2616
+ */
2617
+ private function send_email(
2618
+ $to_address,
2619
+ $subject,
2620
+ $sections = array(),
2621
+ $headers = array()
2622
+ ) {
2623
+ $default_sections = $this->get_email_sections();
2624
+
2625
+ // Insert new sections or replace the default email sections.
2626
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
2627
+ foreach ( $sections as $section_id => $custom_section ) {
2628
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
2629
+ // If the section does not exist, add it.
2630
+ $default_sections[ $section_id ] = $custom_section;
2631
+ } else {
2632
+ // If the section already exists, override it.
2633
+ $current_section = $default_sections[ $section_id ];
2634
+
2635
+ // Replace the current section's title if a custom section title exists.
2636
+ if ( isset( $custom_section['title'] ) ) {
2637
+ $current_section['title'] = $custom_section['title'];
2638
+ }
2639
+
2640
+ // Insert new rows under the current section or replace the default rows.
2641
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
2642
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
2643
+ $current_section['rows'][ $row_id ] = $row;
2644
+ }
2645
+ }
2646
+
2647
+ $default_sections[ $section_id ] = $current_section;
2648
+ }
2649
+ }
2650
+ }
2651
+
2652
+ $vars = array( 'sections' => $default_sections );
2653
+ $message = fs_get_template( 'email.php', $vars );
2654
+
2655
+ // Set the type of email to HTML.
2656
+ $headers[] = 'Content-type: text/html; charset=UTF-8';
2657
+
2658
+ $header_string = implode( "\r\n", $headers );
2659
+
2660
+ return wp_mail(
2661
+ $to_address,
2662
+ $subject,
2663
+ $message,
2664
+ $header_string
2665
+ );
2666
+ }
2667
+
2668
+ /**
2669
+ * Generates the data for the sections of the email content.
2670
+ *
2671
+ * @author Leo Fajardo (@leorw)
2672
+ * @since 1.1.2
2673
+ *
2674
+ * @return array
2675
+ */
2676
+ private function get_email_sections() {
2677
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
2678
+ $current_user = self::_get_current_wp_user();
2679
+
2680
+ // Retrieve the cURL version information so that we can get the version number below.
2681
+ $curl_version_information = curl_version();
2682
+
2683
+ $active_plugin = self::get_active_plugins();
2684
+
2685
+ // Generate the list of active plugins separated by new line.
2686
+ $active_plugin_string = '';
2687
+ foreach ( $active_plugin as $plugin ) {
2688
+ $active_plugin_string .= sprintf(
2689
+ '<a href="%s">%s</a> [v%s]<br>',
2690
+ $plugin['PluginURI'],
2691
+ $plugin['Name'],
2692
+ $plugin['Version']
2693
+ );
2694
+ }
2695
+
2696
+ $server_ip = WP_FS__REMOTE_ADDR;
2697
+
2698
+ // Add PHP info for deeper investigation.
2699
+ ob_start();
2700
+ phpinfo();
2701
+ $php_info = ob_get_clean();
2702
+
2703
+ $api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
2704
+
2705
+ // Generate the default email sections.
2706
+ $sections = array(
2707
+ 'sdk' => array(
2708
+ 'title' => 'SDK',
2709
+ 'rows' => array(
2710
+ 'fs_version' => array( 'FS Version', $this->version ),
2711
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
2712
+ )
2713
+ ),
2714
+ 'plugin' => array(
2715
+ 'title' => ucfirst( $this->get_module_type() ),
2716
+ 'rows' => array(
2717
+ 'name' => array( 'Name', $this->get_plugin_name() ),
2718
+ 'version' => array( 'Version', $this->get_plugin_version() )
2719
+ )
2720
+ ),
2721
+ 'api' => array(
2722
+ 'title' => 'API Subdomain',
2723
+ 'rows' => array(
2724
+ 'dns' => array(
2725
+ 'DNS_CNAME',
2726
+ function_exists( 'dns_get_record' ) ?
2727
+ var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
2728
+ 'dns_get_record() disabled/blocked'
2729
+ ),
2730
+ 'ip' => array(
2731
+ 'IP',
2732
+ function_exists( 'gethostbyname' ) ?
2733
+ gethostbyname( $api_domain ) :
2734
+ 'gethostbyname() disabled/blocked'
2735
+ ),
2736
+ ),
2737
+ ),
2738
+ 'site' => array(
2739
+ 'title' => 'Site',
2740
+ 'rows' => array(
2741
+ 'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
2742
+ 'address' => array( 'Address', site_url() ),
2743
+ 'host' => array(
2744
+ 'HTTP_HOST',
2745
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
2746
+ ),
2747
+ 'hosting' => array(
2748
+ 'Hosting Company' => fs_request_has( 'hosting_company' ) ?
2749
+ fs_request_get( 'hosting_company' ) :
2750
+ 'Unknown',
2751
+ ),
2752
+ 'server_addr' => array(
2753
+ 'SERVER_ADDR',
2754
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
2755
+ )
2756
+ )
2757
+ ),
2758
+ 'user' => array(
2759
+ 'title' => 'User',
2760
+ 'rows' => array(
2761
+ 'email' => array( 'Email', $current_user->user_email ),
2762
+ 'first' => array( 'First', $current_user->user_firstname ),
2763
+ 'last' => array( 'Last', $current_user->user_lastname )
2764
+ )
2765
+ ),
2766
+ 'plugins' => array(
2767
+ 'title' => 'Plugins',
2768
+ 'rows' => array(
2769
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
2770
+ )
2771
+ ),
2772
+ 'php_info' => array(
2773
+ 'title' => 'PHP Info',
2774
+ 'rows' => array(
2775
+ 'info' => array( $php_info )
2776
+ ),
2777
+ )
2778
+ );
2779
+
2780
+ // Allow the sections to be modified by other code.
2781
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
2782
+
2783
+ return $sections;
2784
+ }
2785
+
2786
+ #endregion
2787
+
2788
+ #----------------------------------------------------------------------------------
2789
+ #region Initialization
2790
+ #----------------------------------------------------------------------------------
2791
+
2792
+ /**
2793
+ * Init plugin's Freemius instance.
2794
+ *
2795
+ * @author Vova Feldman (@svovaf)
2796
+ * @since 1.0.1
2797
+ *
2798
+ * @param number $id
2799
+ * @param string $public_key
2800
+ * @param bool $is_live
2801
+ * @param bool $is_premium
2802
+ */
2803
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
2804
+ $this->_logger->entrance();
2805
+
2806
+ $this->dynamic_init( array(
2807
+ 'id' => $id,
2808
+ 'public_key' => $public_key,
2809
+ 'is_live' => $is_live,
2810
+ 'is_premium' => $is_premium,
2811
+ ) );
2812
+ }
2813
+
2814
+ /**
2815
+ * Dynamic initiator, originally created to support initiation
2816
+ * with parent_id for add-ons.
2817
+ *
2818
+ * @author Vova Feldman (@svovaf)
2819
+ * @since 1.0.6
2820
+ *
2821
+ * @param array $plugin_info
2822
+ *
2823
+ * @throws Freemius_Exception
2824
+ */
2825
+ function dynamic_init( array $plugin_info ) {
2826
+ $this->_logger->entrance();
2827
+
2828
+ $this->parse_settings( $plugin_info );
2829
+
2830
+ if ( ! self::is_ajax() ) {
2831
+ if ( ! $this->is_addon() || $this->is_only_premium() ) {
2832
+ add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
2833
+ }
2834
+ }
2835
+
2836
+ if ( $this->should_stop_execution() ) {
2837
+ return;
2838
+ }
2839
+
2840
+ if ( ! $this->is_registered() ) {
2841
+ if ( $this->is_anonymous() ) {
2842
+ // If user skipped, no need to test connectivity.
2843
+ $this->_has_api_connection = true;
2844
+ $this->_is_on = true;
2845
+ } else {
2846
+ if ( ! $this->has_api_connectivity() ) {
2847
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
2848
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
2849
+ ) {
2850
+ if ( ! $this->_enable_anonymous || $this->is_premium() ) {
2851
+ // If anonymous mode is disabled, add firewall admin-notice message.
2852
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
2853
+
2854
+ $this->add_ajax_action( 'resolve_firewall_issues', array(
2855
+ &$this,
2856
+ '_email_about_firewall_issue'
2857
+ ) );
2858
+
2859
+ $this->add_ajax_action( 'retry_connectivity_test', array(
2860
+ &$this,
2861
+ '_retry_connectivity_test'
2862
+ ) );
2863
+ }
2864
+ }
2865
+
2866
+ return;
2867
+ } else {
2868
+ $this->_admin_notices->remove_sticky( array(
2869
+ 'failed_connect_api_first',
2870
+ 'failed_connect_api',
2871
+ ) );
2872
+
2873
+ if ( $this->_anonymous_mode ) {
2874
+ // Simulate anonymous mode.
2875
+ $this->_is_anonymous = true;
2876
+ }
2877
+ }
2878
+ }
2879
+
2880
+ // Check if Freemius is on for the current plugin.
2881
+ // This MUST be executed after all the plugin variables has been loaded.
2882
+ if ( ! $this->is_on() ) {
2883
+ return;
2884
+ }
2885
+ }
2886
+
2887
+ if ( $this->has_api_connectivity() ) {
2888
+ if ( self::is_cron() ) {
2889
+ $this->hook_callback_to_sync_cron();
2890
+ } else if ( $this->is_user_in_admin() ) {
2891
+ /**
2892
+ * Schedule daily data sync cron if:
2893
+ *
2894
+ * 1. User opted-in (for tracking).
2895
+ * 2. If skipped, but later upgraded (opted-in via upgrade).
2896
+ *
2897
+ * @author Vova Feldman (@svovaf)
2898
+ * @since 1.1.7.3
2899
+ *
2900
+ */
2901
+ if ( $this->is_registered() ) {
2902
+ if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
2903
+ $this->schedule_sync_cron();
2904
+ }
2905
+ }
2906
+
2907
+ /**
2908
+ * Check if requested for manual blocking background sync.
2909
+ */
2910
+ if ( fs_request_has( 'background_sync' ) ) {
2911
+ $this->run_manual_sync();
2912
+ }
2913
+ }
2914
+ }
2915
+
2916
+ if ( $this->is_registered() ) {
2917
+ $this->hook_callback_to_install_sync();
2918
+ }
2919
+
2920
+ if ( $this->is_addon() ) {
2921
+ if ( $this->is_parent_plugin_installed() ) {
2922
+ // Link to parent FS.
2923
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2924
+
2925
+ // Get parent plugin reference.
2926
+ $this->_parent_plugin = $this->_parent->get_plugin();
2927
+ }
2928
+ }
2929
+
2930
+ if ( $this->is_user_in_admin() ) {
2931
+ if ( self::is_plugins_page() && $this->is_plugin() ) {
2932
+ $this->hook_plugin_action_links();
2933
+ }
2934
+
2935
+ if ( $this->is_addon() ) {
2936
+ if ( ! $this->is_parent_plugin_installed() ) {
2937
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2938
+
2939
+ if ( isset( $plugin_info['parent'] ) ) {
2940
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2941
+ }
2942
+
2943
+ $this->_admin_notices->add(
2944
+ ( ! empty( $parent_name ) ?
2945
+ sprintf( $this->get_text( 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
2946
+ sprintf( $this->get_text( 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
2947
+ ),
2948
+ $this->get_text( 'oops' ) . '...',
2949
+ 'error'
2950
+ );
2951
+
2952
+ return;
2953
+ } else {
2954
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
2955
+ // If parent plugin activated, automatically install add-on for the user.
2956
+ $this->_activate_addon_account( $this->_parent );
2957
+ } else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
2958
+ // If add-on activated and parent not, automatically install parent for the user.
2959
+ $this->activate_parent_account( $this->_parent );
2960
+ }
2961
+
2962
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
2963
+ if ( $this->is_premium() ) {
2964
+ // Remove add-on download admin-notice.
2965
+ $this->_parent->_admin_notices->remove_sticky( array(
2966
+ 'addon_plan_upgraded_' . $this->_slug,
2967
+ 'no_addon_license_' . $this->_slug,
2968
+ ) );
2969
+ }
2970
+
2971
+ // $this->deactivate_premium_only_addon_without_license();
2972
+ }
2973
+ } else {
2974
+ if ( $this->has_addons() &&
2975
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
2976
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
2977
+ ) {
2978
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
2979
+
2980
+ new FS_Plugin_Info_Dialog( $this );
2981
+ }
2982
+ }
2983
+
2984
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
2985
+
2986
+ // if ( $this->is_registered() ||
2987
+ // $this->is_anonymous() ||
2988
+ // $this->is_pending_activation()
2989
+ // ) {
2990
+ // $this->_init_admin();
2991
+ // }
2992
+ }
2993
+
2994
+ /**
2995
+ * Should be called outside `$this->is_user_in_admin()` scope
2996
+ * because the updater has some logic that needs to be executed
2997
+ * during AJAX calls.
2998
+ *
2999
+ * Currently we need to hook to the `http_request_host_is_external` filter.
3000
+ * In the future, there might be additional logic added.
3001
+ *
3002
+ * @author Vova Feldman
3003
+ * @since 1.2.1.6
3004
+ */
3005
+ if ( $this->is_premium() && $this->has_release_on_freemius() ) {
3006
+ new FS_Plugin_Updater( $this );
3007
+ }
3008
+
3009
+ $this->do_action( 'initiated' );
3010
+
3011
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
3012
+ if ( isset( $this->_storage->prev_is_premium ) ) {
3013
+ $this->apply_filters(
3014
+ 'after_code_type_change',
3015
+ // New code type.
3016
+ $this->_plugin->is_premium
3017
+ );
3018
+ } else {
3019
+ // Set for code type for the first time.
3020
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
3021
+ }
3022
+ }
3023
+
3024
+ if ( ! $this->is_addon() ) {
3025
+ if ( $this->is_registered() ) {
3026
+ // Fix for upgrade from versions < 1.0.9.
3027
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
3028
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
3029
+ }
3030
+
3031
+ $this->do_action( 'after_init_plugin_registered' );
3032
+ } else if ( $this->is_anonymous() ) {
3033
+ $this->do_action( 'after_init_plugin_anonymous' );
3034
+ } else if ( $this->is_pending_activation() ) {
3035
+ $this->do_action( 'after_init_plugin_pending_activations' );
3036
+ }
3037
+ } else {
3038
+ if ( $this->is_registered() ) {
3039
+ $this->do_action( 'after_init_addon_registered' );
3040
+ } else if ( $this->is_anonymous() ) {
3041
+ $this->do_action( 'after_init_addon_anonymous' );
3042
+ } else if ( $this->is_pending_activation() ) {
3043
+ $this->do_action( 'after_init_addon_pending_activations' );
3044
+ }
3045
+ }
3046
+ }
3047
+
3048
+ /**
3049
+ * @author Leo Fajardo (@leorw)
3050
+ *
3051
+ * @since 1.2.1.5
3052
+ */
3053
+ function _stop_tracking_callback() {
3054
+ $this->_logger->entrance();
3055
+
3056
+ $this->check_ajax_referer( 'stop_tracking' );
3057
+
3058
+ $result = $this->stop_tracking();
3059
+
3060
+ if ( true === $result ) {
3061
+ self::shoot_ajax_success();
3062
+ }
3063
+
3064
+ $this->_logger->api_error( $result );
3065
+
3066
+ self::shoot_ajax_failure(
3067
+ $this->get_text( 'unexpected-api-error' ) .
3068
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
3069
+ $result->error->message :
3070
+ var_export( $result, true ) )
3071
+ );
3072
+ }
3073
+
3074
+ /**
3075
+ * @author Leo Fajardo (@leorw)
3076
+ * @since 1.2.1.5
3077
+ */
3078
+ function _allow_tracking_callback() {
3079
+ $this->_logger->entrance();
3080
+
3081
+ $this->check_ajax_referer( 'allow_tracking' );
3082
+
3083
+ $result = $this->allow_tracking();
3084
+
3085
+ if ( true === $result ) {
3086
+ self::shoot_ajax_success();
3087
+ }
3088
+
3089
+ $this->_logger->api_error( $result );
3090
+
3091
+ self::shoot_ajax_failure(
3092
+ $this->get_text( 'unexpected-api-error' ) .
3093
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
3094
+ $result->error->message :
3095
+ var_export( $result, true ) )
3096
+ );
3097
+ }
3098
+
3099
+ /**
3100
+ * Opt-out from usage tracking.
3101
+ *
3102
+ * Note: This will not delete the account information but will stop all tracking.
3103
+ *
3104
+ * Returns:
3105
+ * 1. FALSE - If the user never opted-in.
3106
+ * 2. TRUE - If successfully opted-out.
3107
+ * 3. object - API result on failure.
3108
+ *
3109
+ * @author Leo Fajardo (@leorw)
3110
+ * @since 1.2.1.5
3111
+ *
3112
+ * @return bool|object
3113
+ */
3114
+ function stop_tracking() {
3115
+ $this->_logger->entrance();
3116
+
3117
+ if ( ! $this->is_registered() ) {
3118
+ // User never opted-in.
3119
+ return false;
3120
+ }
3121
+
3122
+ if ( $this->is_tracking_prohibited() ) {
3123
+ // Already disconnected.
3124
+ return true;
3125
+ }
3126
+
3127
+ // Send update to FS.
3128
+ $result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
3129
+ 'is_disconnected' => true
3130
+ ) );
3131
+
3132
+ if ( ! $this->is_api_result_entity( $result ) ||
3133
+ ! isset( $result->is_disconnected ) ||
3134
+ ! $result->is_disconnected
3135
+ ) {
3136
+ $this->_logger->api_error( $result );
3137
+
3138
+ return $result;
3139
+ }
3140
+
3141
+ $this->_site->is_disconnected = $result->is_disconnected;
3142
+ $this->_store_site();
3143
+
3144
+ $this->clear_sync_cron();
3145
+
3146
+ // Successfully disconnected.
3147
+ return true;
3148
+ }
3149
+
3150
+ /**
3151
+ * Opt-in back into usage tracking.
3152
+ *
3153
+ * Note: This will only work if the user opted-in previously.
3154
+ *
3155
+ * Returns:
3156
+ * 1. FALSE - If the user never opted-in.
3157
+ * 2. TRUE - If successfully opted-in back to usage tracking.
3158
+ * 3. object - API result on failure.
3159
+ *
3160
+ * @author Leo Fajardo (@leorw)
3161
+ * @since 1.2.1.5
3162
+ *
3163
+ * @return bool|object
3164
+ */
3165
+ function allow_tracking() {
3166
+ $this->_logger->entrance();
3167
+
3168
+ if ( ! $this->is_registered() ) {
3169
+ // User never opted-in.
3170
+ return false;
3171
+ }
3172
+
3173
+ if ( $this->is_tracking_allowed() ) {
3174
+ // Tracking already allowed.
3175
+ return true;
3176
+ }
3177
+
3178
+ $result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
3179
+ 'is_disconnected' => false
3180
+ ) );
3181
+
3182
+ if ( ! $this->is_api_result_entity( $result ) ||
3183
+ ! isset( $result->is_disconnected ) ||
3184
+ $result->is_disconnected
3185
+ ) {
3186
+ $this->_logger->api_error( $result );
3187
+
3188
+ return $result;
3189
+ }
3190
+
3191
+ $this->_site->is_disconnected = $result->is_disconnected;
3192
+ $this->_store_site();
3193
+
3194
+ $this->schedule_sync_cron();
3195
+
3196
+ // Successfully reconnected.
3197
+ return true;
3198
+ }
3199
+
3200
+ /**
3201
+ * If user opted-in and later disabled usage-tracking,
3202
+ * re-allow tracking for licensing and updates.
3203
+ *
3204
+ * @author Leo Fajardo (@leorw)
3205
+ *
3206
+ * @since 1.2.1.5
3207
+ */
3208
+ private function reconnect_locally() {
3209
+ $this->_logger->entrance();
3210
+
3211
+ if ( $this->is_tracking_prohibited() &&
3212
+ $this->is_registered()
3213
+ ) {
3214
+ $this->_site->is_disconnected = false;
3215
+ $this->_store_site();
3216
+ }
3217
+ }
3218
+
3219
+ /**
3220
+ * Parse plugin's settings (as defined by the plugin dev).
3221
+ *
3222
+ * @author Vova Feldman (@svovaf)
3223
+ * @since 1.1.7.3
3224
+ *
3225
+ * @param array $plugin_info
3226
+ *
3227
+ * @throws \Freemius_Exception
3228
+ */
3229
+ private function parse_settings( &$plugin_info ) {
3230
+ $this->_logger->entrance();
3231
+
3232
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
3233
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
3234
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
3235
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
3236
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
3237
+
3238
+ /**
3239
+ * @author Vova Feldman (@svovaf)
3240
+ * @since 1.1.9 Try to pull secret key from external config.
3241
+ */
3242
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
3243
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
3244
+ }
3245
+
3246
+ if ( isset( $plugin_info['parent'] ) ) {
3247
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
3248
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
3249
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
3250
+ // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
3251
+ }
3252
+
3253
+ if ( false === $id ) {
3254
+ throw new Freemius_Exception( array(
3255
+ 'error' => array(
3256
+ 'type' => 'ParameterNotSet',
3257
+ 'message' => 'Plugin id parameter is not set.',
3258
+ 'code' => 'plugin_id_not_set',
3259
+ 'http' => 500,
3260
+ )
3261
+ ) );
3262
+ }
3263
+ if ( false === $public_key ) {
3264
+ throw new Freemius_Exception( array(
3265
+ 'error' => array(
3266
+ 'type' => 'ParameterNotSet',
3267
+ 'message' => 'Plugin public_key parameter is not set.',
3268
+ 'code' => 'plugin_public_key_not_set',
3269
+ 'http' => 500,
3270
+ )
3271
+ ) );
3272
+ }
3273
+
3274
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
3275
+ $this->_plugin :
3276
+ new FS_Plugin();
3277
+
3278
+ $plugin->update( array(
3279
+ 'id' => $id,
3280
+ 'public_key' => $public_key,
3281
+ 'slug' => $this->_slug,
3282
+ 'parent_plugin_id' => $parent_id,
3283
+ 'version' => $this->get_plugin_version(),
3284
+ 'title' => $this->get_plugin_name(),
3285
+ 'file' => $this->_plugin_basename,
3286
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
3287
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
3288
+ 'type' => $this->_module_type,
3289
+ // 'secret_key' => $secret_key,
3290
+ ) );
3291
+
3292
+ if ( $plugin->is_updated() ) {
3293
+ // Update plugin details.
3294
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
3295
+ }
3296
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
3297
+ $this->_plugin->secret_key = $secret_key;
3298
+
3299
+ if ( ! isset( $plugin_info['menu'] ) ) {
3300
+ $plugin_info['menu'] = array();
3301
+
3302
+ if ( ! empty( $this->_storage->sdk_last_version ) &&
3303
+ version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
3304
+ ) {
3305
+ // Backward compatibility to 1.1.2
3306
+ $plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
3307
+ $plugin_info['menu_slug'] :
3308
+ $this->_slug;
3309
+ }
3310
+ }
3311
+
3312
+ $this->_menu = FS_Admin_Menu_Manager::instance(
3313
+ $this->_module_id,
3314
+ $this->_module_type,
3315
+ $this->get_unique_affix()
3316
+ );
3317
+
3318
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
3319
+
3320
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
3321
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
3322
+ $this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
3323
+ $this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
3324
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
3325
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
3326
+ if ( $this->_is_premium_only ) {
3327
+ // If premium only plugin, disable anonymous mode.
3328
+ $this->_enable_anonymous = false;
3329
+ $this->_anonymous_mode = false;
3330
+ } else {
3331
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
3332
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
3333
+ }
3334
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
3335
+
3336
+ if ( ! empty( $plugin_info['trial'] ) ) {
3337
+ $this->_trial_days = $this->get_numeric_option(
3338
+ $plugin_info['trial'],
3339
+ 'days',
3340
+ // Default to 0 - trial without days specification.
3341
+ 0
3342
+ );
3343
+
3344
+ $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
3345
+ }
3346
+ }
3347
+
3348
+ /**
3349
+ * @param string[] $options
3350
+ * @param string $key
3351
+ * @param mixed $default
3352
+ *
3353
+ * @return bool
3354
+ */
3355
+ private function get_option( &$options, $key, $default = false ) {
3356
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
3357
+ }
3358
+
3359
+ private function get_bool_option( &$options, $key, $default = false ) {
3360
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
3361
+ }
3362
+
3363
+ private function get_numeric_option( &$options, $key, $default = false ) {
3364
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
3365
+ }
3366
+
3367
+ /**
3368
+ * Gate keeper.
3369
+ *
3370
+ * @author Vova Feldman (@svovaf)
3371
+ * @since 1.1.7.3
3372
+ *
3373
+ * @return bool
3374
+ */
3375
+ private function should_stop_execution() {
3376
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
3377
+ /**
3378
+ * Don't execute Freemius until plugin was fully loaded at least once,
3379
+ * to give the opportunity for the activation hook to run before pinging
3380
+ * the API for connectivity test. This logic is relevant for the
3381
+ * identification of new plugin install vs. plugin update.
3382
+ *
3383
+ * @author Vova Feldman (@svovaf)
3384
+ * @since 1.1.9
3385
+ */
3386
+ return true;
3387
+ }
3388
+
3389
+ if ( $this->is_activation_mode() ) {
3390
+ if ( ! is_admin() ) {
3391
+ /**
3392
+ * If in activation mode, don't execute Freemius outside of the
3393
+ * admin dashboard.
3394
+ *
3395
+ * @author Vova Feldman (@svovaf)
3396
+ * @since 1.1.7.3
3397
+ */
3398
+ return true;
3399
+ }
3400
+
3401
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
3402
+ /**
3403
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
3404
+ * then don't start Freemius.
3405
+ *
3406
+ * @author Vova Feldman (@svovaf)
3407
+ * @since 1.1.6.3
3408
+ *
3409
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
3410
+ */
3411
+ return true;
3412
+ }
3413
+
3414
+ if ( self::is_cron() ) {
3415
+ /**
3416
+ * If in activation mode, don't execute Freemius during wp crons
3417
+ * (wp crons have HTTP context - called as HTTP request).
3418
+ *
3419
+ * @author Vova Feldman (@svovaf)
3420
+ * @since 1.1.7.3
3421
+ */
3422
+ return true;
3423
+ }
3424
+
3425
+ if ( self::is_ajax() &&
3426
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
3427
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
3428
+ ) {
3429
+ /**
3430
+ * During activation, if running in AJAX mode, unless there's a sticky
3431
+ * connectivity issue notice, don't run Freemius.
3432
+ *
3433
+ * @author Vova Feldman (@svovaf)
3434
+ * @since 1.1.7.3
3435
+ */
3436
+ return true;
3437
+ }
3438
+ }
3439
+
3440
+ return false;
3441
+ }
3442
+
3443
+ /**
3444
+ * Triggered after code type has changed.
3445
+ *
3446
+ * @author Vova Feldman (@svovaf)
3447
+ * @since 1.1.9.1
3448
+ */
3449
+ function _after_code_type_change() {
3450
+ $this->_logger->entrance();
3451
+
3452
+ if ( $this->is_theme() ) {
3453
+ // Expire the cache of the previous tabs since the theme may
3454
+ // have setting updates after code type has changed.
3455
+ $this->_cache->expire( 'tabs' );
3456
+ $this->_cache->expire( 'tabs_stylesheets' );
3457
+ }
3458
+
3459
+ if ( $this->is_registered() ) {
3460
+ if ( ! $this->is_addon() ) {
3461
+ add_action(
3462
+ is_admin() ? 'admin_init' : 'init',
3463
+ array( &$this, '_plugin_code_type_changed' )
3464
+ );
3465
+ }
3466
+
3467
+ if ( $this->is_premium() ) {
3468
+ // Purge cached payments after switching to the premium version.
3469
+ // @todo This logic doesn't handle purging the cache for serviceware module upgrade.
3470
+ $this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
3471
+ }
3472
+ }
3473
+ }
3474
+
3475
+ /**
3476
+ * Handles plugin's code type change (free <--> premium).
3477
+ *
3478
+ * @author Vova Feldman (@svovaf)
3479
+ * @since 1.0.9
3480
+ */
3481
+ function _plugin_code_type_changed() {
3482
+ $this->_logger->entrance();
3483
+
3484
+ if ( $this->is_premium() ) {
3485
+ $this->reconnect_locally();
3486
+
3487
+ // Activated premium code.
3488
+ $this->do_action( 'after_premium_version_activation' );
3489
+
3490
+ // Remove all sticky messages related to download of the premium version.
3491
+ $this->_admin_notices->remove_sticky( array(
3492
+ 'trial_started',
3493
+ 'plan_upgraded',
3494
+ 'plan_changed',
3495
+ 'license_activated',
3496
+ ) );
3497
+
3498
+ $this->_admin_notices->add_sticky(
3499
+ sprintf( $this->get_text( 'premium-activated-message' ), $this->_module_type ),
3500
+ 'premium_activated',
3501
+ $this->get_text( 'woot' ) . '!'
3502
+ );
3503
+ } else {
3504
+ // Remove sticky message related to premium code activation.
3505
+ $this->_admin_notices->remove_sticky( 'premium_activated' );
3506
+
3507
+ // Activated free code (after had the premium before).
3508
+ $this->do_action( 'after_free_version_reactivation' );
3509
+
3510
+ if ( $this->is_paying() && ! $this->is_premium() ) {
3511
+ $this->_admin_notices->add_sticky(
3512
+ sprintf(
3513
+ $this->get_text( 'you-have-x-license' ),
3514
+ $this->_site->plan->title
3515
+ ) . $this->get_complete_upgrade_instructions(),
3516
+ 'plan_upgraded',
3517
+ $this->get_text( 'yee-haw' ) . '!'
3518
+ );
3519
+ }
3520
+ }
3521
+
3522
+ // Schedule code type changes event.
3523
+ $this->schedule_install_sync();
3524
+
3525
+ /**
3526
+ * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
3527
+ * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
3528
+ * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
3529
+ * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
3530
+ * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
3531
+ * free and premium versions are almost identical (same class or have same functions), a fatal error like
3532
+ * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
3533
+ */
3534
+ $this->unregister_uninstall_hook();
3535
+
3536
+ $this->clear_module_main_file_cache();
3537
+
3538
+ // Update is_premium of latest version.
3539
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
3540
+ }
3541
+
3542
+ #endregion
3543
+
3544
+ #----------------------------------------------------------------------------------
3545
+ #region Add-ons
3546
+ #----------------------------------------------------------------------------------
3547
+
3548
+ /**
3549
+ * Check if add-on installed and activated on site.
3550
+ *
3551
+ * @author Vova Feldman (@svovaf)
3552
+ * @since 1.0.6
3553
+ *
3554
+ * @param string|number $id_or_slug
3555
+ * @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
3556
+ *
3557
+ * @return bool
3558
+ */
3559
+ function is_addon_activated( $id_or_slug, $is_premium = null ) {
3560
+ $this->_logger->entrance();
3561
+
3562
+ $addon_id = self::get_module_id( $id_or_slug );
3563
+ $is_activated = self::has_instance( $addon_id );
3564
+
3565
+ if ( ! $is_activated ) {
3566
+ return false;
3567
+ }
3568
+
3569
+ if ( is_bool( $is_premium ) ) {
3570
+ // Check if the specified code version is activate.
3571
+ $addon = $this->get_addon_instance( $addon_id );
3572
+ $is_activated = ( $is_premium === $addon->is_premium() );
3573
+ }
3574
+
3575
+ return $is_activated;
3576
+ }
3577
+
3578
+ /**
3579
+ * Check if add-on was connected to install
3580
+ *
3581
+ * @author Vova Feldman (@svovaf)
3582
+ * @since 1.1.7
3583
+ *
3584
+ * @param string|number $id_or_slug
3585
+ *
3586
+ * @return bool
3587
+ */
3588
+ function is_addon_connected( $id_or_slug ) {
3589
+ $this->_logger->entrance();
3590
+
3591
+ $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
3592
+
3593
+ $addon_id = self::get_module_id( $id_or_slug );
3594
+ $addon = $this->get_addon( $addon_id );
3595
+ $slug = $addon->slug;
3596
+ if ( ! isset( $sites[ $slug ] ) ) {
3597
+ return false;
3598
+ }
3599
+
3600
+ $site = $sites[ $slug ];
3601
+
3602
+ $plugin = FS_Plugin_Manager::instance( $addon_id )->get();
3603
+
3604
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
3605
+ // The given slug do NOT belong to any of the plugin's add-ons.
3606
+ return false;
3607
+ }
3608
+
3609
+ return ( is_object( $site ) &&
3610
+ is_numeric( $site->id ) &&
3611
+ is_numeric( $site->user_id ) &&
3612
+ is_object( $site->plan )
3613
+ );
3614
+ }
3615
+
3616
+ /**
3617
+ * Determines if add-on installed.
3618
+ *
3619
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
3620
+ *
3621
+ * @author Vova Feldman (@svovaf)
3622
+ * @since 1.0.6
3623
+ *
3624
+ * @param string|number $id_or_slug
3625
+ *
3626
+ * @return bool
3627
+ */
3628
+ function is_addon_installed( $id_or_slug ) {
3629
+ $this->_logger->entrance();
3630
+
3631
+ $addon_id = self::get_module_id( $id_or_slug );
3632
+
3633
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
3634
+ }
3635
+
3636
+ /**
3637
+ * Get add-on basename.
3638
+ *
3639
+ * @author Vova Feldman (@svovaf)
3640
+ * @since 1.0.6
3641
+ *
3642
+ * @param string|number $id_or_slug
3643
+ *
3644
+ * @return string
3645
+ */
3646
+ function get_addon_basename( $id_or_slug ) {
3647
+ $addon_id = self::get_module_id( $id_or_slug );
3648
+
3649
+ if ( $this->is_addon_activated( $addon_id ) ) {
3650
+ return self::instance( $addon_id )->get_plugin_basename();
3651
+ }
3652
+
3653
+ $addon = $this->get_addon( $addon_id );
3654
+ $premium_basename = "{$addon->slug}-premium/{$addon->slug}.php";
3655
+
3656
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
3657
+ return $premium_basename;
3658
+ }
3659
+
3660
+ $all_plugins = $this->get_all_plugins();
3661
+
3662
+ foreach ( $all_plugins as $basename => &$data ) {
3663
+ if ( $addon->slug === $data['slug'] ||
3664
+ $addon->slug . '-premium' === $data['slug']
3665
+ ) {
3666
+ return $basename;
3667
+ }
3668
+ }
3669
+
3670
+ $free_basename = "{$addon->slug}/{$addon->slug}.php";
3671
+
3672
+ return $free_basename;
3673
+ }
3674
+
3675
+ /**
3676
+ * Get installed add-ons instances.
3677
+ *
3678
+ * @author Vova Feldman (@svovaf)
3679
+ * @since 1.0.6
3680
+ *
3681
+ * @return Freemius[]
3682
+ */
3683
+ function get_installed_addons() {
3684
+ $installed_addons = array();
3685
+ foreach ( self::$_instances as $instance ) {
3686
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
3687
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
3688
+ $installed_addons[] = $instance;
3689
+ }
3690
+ }
3691
+ }
3692
+
3693
+ return $installed_addons;
3694
+ }
3695
+
3696
+ /**
3697
+ * Check if any add-ons of the plugin are installed.
3698
+ *
3699
+ * @author Leo Fajardo (@leorw)
3700
+ * @since 1.1.1
3701
+ *
3702
+ * @return bool
3703
+ */
3704
+ function has_installed_addons() {
3705
+ if ( ! $this->has_addons() ) {
3706
+ return false;
3707
+ }
3708
+
3709
+ foreach ( self::$_instances as $instance ) {
3710
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
3711
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
3712
+ return true;
3713
+ }
3714
+ }
3715
+ }
3716
+
3717
+ return false;
3718
+ }
3719
+
3720
+ /**
3721
+ * Tell Freemius that the current plugin is an add-on.
3722
+ *
3723
+ * @author Vova Feldman (@svovaf)
3724
+ * @since 1.0.6
3725
+ *
3726
+ * @param number $parent_plugin_id The parent plugin ID
3727
+ */
3728
+ function init_addon( $parent_plugin_id ) {
3729
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
3730
+ }
3731
+
3732
+ /**
3733
+ * @author Vova Feldman (@svovaf)
3734
+ * @since 1.0.6
3735
+ *
3736
+ * @return bool
3737
+ */
3738
+ function is_addon() {
3739
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
3740
+ }
3741
+
3742
+ /**
3743
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
3744
+ *
3745
+ * @param bool $is_after_trial_cancel
3746
+ *
3747
+ * @return bool If add-on was deactivated.
3748
+ */
3749
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
3750
+ if ( ! $this->has_free_plan() &&
3751
+ ! $this->has_features_enabled_license() &&
3752
+ ! $this->_has_premium_license()
3753
+ ) {
3754
+ if ( $this->is_registered() ) {
3755
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
3756
+ // if (empty($this->_storage->activation_timestamp) ||
3757
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
3758
+ // ) {
3759
+ /**
3760
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
3761
+ *
3762
+ * Retry syncing the user add-on licenses.
3763
+ */
3764
+ // Sync licenses.
3765
+ $this->_sync_licenses();
3766
+ // }
3767
+
3768
+ // Try to activate premium license.
3769
+ $this->_activate_license( true );
3770
+ }
3771
+
3772
+ if ( ! $this->has_free_plan() &&
3773
+ ! $this->has_features_enabled_license() &&
3774
+ ! $this->_has_premium_license()
3775
+ ) {
3776
+ // @todo Check if deactivate plugins also call the deactivation hook.
3777
+
3778
+ $this->_parent->_admin_notices->add_sticky(
3779
+ sprintf(
3780
+ $this->_parent->get_text( $is_after_trial_cancel ?
3781
+ 'addon-trial-cancelled-message' :
3782
+ 'addon-no-license-message'
3783
+ ),
3784
+ '<b>' . $this->_plugin->title . '</b>'
3785
+ ) . ' ' . sprintf(
3786
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
3787
+ $this->_parent->addon_url( $this->_slug ),
3788
+ esc_attr( sprintf( $this->_parent->get_text( 'more-information-about-x' ), $this->_plugin->title ) ),
3789
+ $this->_parent->get_text( 'purchase-license' )
3790
+ ),
3791
+ 'no_addon_license_' . $this->_slug,
3792
+ ( $is_after_trial_cancel ? '' : $this->_parent->get_text( 'oops' ) . '...' ),
3793
+ ( $is_after_trial_cancel ? 'success' : 'error' )
3794
+ );
3795
+
3796
+ deactivate_plugins( array( $this->_plugin_basename ), true );
3797
+
3798
+ return true;
3799
+ }
3800
+ }
3801
+
3802
+ return false;
3803
+ }
3804
+
3805
+ #endregion
3806
+
3807
+ #----------------------------------------------------------------------------------
3808
+ #region Sandbox
3809
+ #----------------------------------------------------------------------------------
3810
+
3811
+ /**
3812
+ * Set Freemius into sandbox mode for debugging.
3813
+ *
3814
+ * @author Vova Feldman (@svovaf)
3815
+ * @since 1.0.4
3816
+ *
3817
+ * @param string $secret_key
3818
+ */
3819
+ function init_sandbox( $secret_key ) {
3820
+ $this->_plugin->secret_key = $secret_key;
3821
+
3822
+ // Update plugin details.
3823
+ FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
3824
+ }
3825
+
3826
+ /**
3827
+ * Check if running payments in sandbox mode.
3828
+ *
3829
+ * @author Vova Feldman (@svovaf)
3830
+ * @since 1.0.4
3831
+ *
3832
+ * @return bool
3833
+ */
3834
+ function is_payments_sandbox() {
3835
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
3836
+ }
3837
+
3838
+ #endregion
3839
+
3840
+ /**
3841
+ * Check if running test vs. live plugin.
3842
+ *
3843
+ * @author Vova Feldman (@svovaf)
3844
+ * @since 1.0.5
3845
+ *
3846
+ * @return bool
3847
+ */
3848
+ function is_live() {
3849
+ return $this->_plugin->is_live;
3850
+ }
3851
+
3852
+ /**
3853
+ * Check if the user skipped connecting the account with Freemius.
3854
+ *
3855
+ * @author Vova Feldman (@svovaf)
3856
+ * @since 1.0.7
3857
+ *
3858
+ * @return bool
3859
+ */
3860
+ function is_anonymous() {
3861
+ if ( ! isset( $this->_is_anonymous ) ) {
3862
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
3863
+ // Not skipped.
3864
+ $this->_is_anonymous = false;
3865
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
3866
+ // For back compatibility, since the variable was boolean before.
3867
+ $this->_is_anonymous = $this->_storage->is_anonymous;
3868
+
3869
+ // Upgrade stored data format to 1.1.3 format.
3870
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
3871
+ } else {
3872
+ // Version 1.1.3 and later.
3873
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
3874
+ }
3875
+ }
3876
+
3877
+ return $this->_is_anonymous;
3878
+ }
3879
+
3880
+ /**
3881
+ * Check if user connected his account and install pending email activation.
3882
+ *
3883
+ * @author Vova Feldman (@svovaf)
3884
+ * @since 1.0.7
3885
+ *
3886
+ * @return bool
3887
+ */
3888
+ function is_pending_activation() {
3889
+ return $this->_storage->get( 'is_pending_activation', false );
3890
+ }
3891
+
3892
+ /**
3893
+ * Check if plugin must be WordPress.org compliant.
3894
+ *
3895
+ * @since 1.0.7
3896
+ *
3897
+ * @return bool
3898
+ */
3899
+ function is_org_repo_compliant() {
3900
+ return $this->_is_org_compliant;
3901
+ }
3902
+
3903
+ #----------------------------------------------------------------------------------
3904
+ #region Daily Sync Cron
3905
+ #----------------------------------------------------------------------------------
3906
+
3907
+ /**
3908
+ * @author Vova Feldman (@svovaf)
3909
+ * @since 1.1.7.3
3910
+ */
3911
+ private function run_manual_sync() {
3912
+ self::require_pluggable_essentials();
3913
+
3914
+ if ( ! $this->is_user_admin() ) {
3915
+ return;
3916
+ }
3917
+
3918
+ // Run manual sync.
3919
+ $this->_sync_cron();
3920
+
3921
+ // Reschedule next cron to run 24 hours from now (performance optimization).
3922
+ $this->clear_sync_cron();
3923
+
3924
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
3925
+ }
3926
+
3927
+ /**
3928
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
3929
+ * that doesn't halt page loading.
3930
+ *
3931
+ * @author Vova Feldman (@svovaf)
3932
+ * @since 1.1.7.3
3933
+ */
3934
+ function _sync_cron() {
3935
+ $this->_logger->entrance();
3936
+
3937
+ // Store the last time data sync was executed.
3938
+ $this->_storage->sync_timestamp = time();
3939
+
3940
+ // Check if API is temporary down.
3941
+ if ( FS_Api::is_temporary_down() ) {
3942
+ return;
3943
+ }
3944
+
3945
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
3946
+
3947
+ if ( $this->is_registered() ) {
3948
+ if ( $this->has_paid_plan() ) {
3949
+ // Initiate background plan sync.
3950
+ $this->_sync_license( true );
3951
+
3952
+ if ( $this->is_paying() ) {
3953
+ // Check for premium plugin updates.
3954
+ $this->check_updates( true );
3955
+ }
3956
+ } else {
3957
+ // Sync install (only if something changed locally).
3958
+ $this->sync_install();
3959
+ }
3960
+ }
3961
+
3962
+ $this->do_action( 'after_sync_cron' );
3963
+ }
3964
+
3965
+ /**
3966
+ * Check if sync was executed in the last $period of seconds.
3967
+ *
3968
+ * @author Vova Feldman (@svovaf)
3969
+ * @since 1.1.7.3
3970
+ *
3971
+ * @param int $period In seconds
3972
+ *
3973
+ * @return bool
3974
+ */
3975
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
3976
+ if ( ! isset( $this->_storage->sync_timestamp ) ) {
3977
+ return false;
3978
+ }
3979
+
3980
+ return ( $this->_storage->sync_timestamp > ( WP_FS__SCRIPT_START_TIME - $period ) );
3981
+ }
3982
+
3983
+ /**
3984
+ * @author Vova Feldman (@svovaf)
3985
+ * @since 1.1.7.3
3986
+ *
3987
+ * @return bool
3988
+ */
3989
+ private function is_sync_cron_on() {
3990
+ /**
3991
+ * @var object $sync_cron_data
3992
+ */
3993
+ $sync_cron_data = $this->_storage->get( 'sync_cron', null );
3994
+
3995
+ return ( ! is_null( $sync_cron_data ) && true === $sync_cron_data->on );
3996
+ }
3997
+
3998
+ /**
3999
+ * @author Vova Feldman (@svovaf)
4000
+ * @since 1.1.7.3
4001
+ *
4002
+ * @param int $start_at Defaults to now.
4003
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise,
4004
+ * schedule job to start right away.
4005
+ */
4006
+ private function schedule_sync_cron( $start_at = WP_FS__SCRIPT_START_TIME, $randomize_start = true ) {
4007
+ $this->_logger->entrance();
4008
+
4009
+ if ( $randomize_start ) {
4010
+ // Schedule first sync with a random 12 hour time range from now.
4011
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
4012
+ }
4013
+
4014
+ // Schedule daily WP cron.
4015
+ wp_schedule_event(
4016
+ $start_at,
4017
+ 'daily',
4018
+ $this->get_action_tag( 'data_sync' )
4019
+ );
4020
+
4021
+ $this->_storage->store( 'sync_cron', (object) array(
4022
+ 'version' => $this->get_plugin_version(),
4023
+ 'sdk_version' => $this->version,
4024
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
4025
+ 'on' => true,
4026
+ ) );
4027
+ }
4028
+
4029
+ /**
4030
+ * Add the actual sync function to the cron job hook.
4031
+ *
4032
+ * @author Vova Feldman (@svovaf)
4033
+ * @since 1.1.7.3
4034
+ */
4035
+ private function hook_callback_to_sync_cron() {
4036
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
4037
+ }
4038
+
4039
+ /**
4040
+ * @author Vova Feldman (@svovaf)
4041
+ * @since 1.1.7.3
4042
+ */
4043
+ private function clear_sync_cron() {
4044
+ $this->_logger->entrance();
4045
+
4046
+ if ( ! $this->is_sync_cron_on() ) {
4047
+ return;
4048
+ }
4049
+
4050
+ $this->_storage->remove( 'sync_cron' );
4051
+
4052
+ wp_clear_scheduled_hook( $this->get_action_tag( 'data_sync' ) );
4053
+ }
4054
+
4055
+ /**
4056
+ * Unix timestamp for next sync cron execution or false if not scheduled.
4057
+ *
4058
+ * @author Vova Feldman (@svovaf)
4059
+ * @since 1.1.7.3
4060
+ *
4061
+ * @return int|false
4062
+ */
4063
+ function next_sync_cron() {
4064
+ $this->_logger->entrance();
4065
+
4066
+ if ( ! $this->is_sync_cron_on() ) {
4067
+ return false;
4068
+ }
4069
+
4070
+ return wp_next_scheduled( $this->get_action_tag( 'data_sync' ) );
4071
+ }
4072
+
4073
+ /**
4074
+ * Unix timestamp for previous sync cron execution or false if never executed.
4075
+ *
4076
+ * @author Vova Feldman (@svovaf)
4077
+ * @since 1.1.7.3
4078
+ *
4079
+ * @return int|false
4080
+ */
4081
+ function last_sync_cron() {
4082
+ $this->_logger->entrance();
4083
+
4084
+ return $this->_storage->get( 'sync_timestamp' );
4085
+ }
4086
+
4087
+ #endregion Daily Sync Cron ------------------------------------------------------------------
4088
+
4089
+ #----------------------------------------------------------------------------------
4090
+ #region Async Install Sync
4091
+ #----------------------------------------------------------------------------------
4092
+
4093
+ /**
4094
+ * @author Vova Feldman (@svovaf)
4095
+ * @since 1.1.7.3
4096
+ *
4097
+ * @return bool
4098
+ */
4099
+ private function is_install_sync_scheduled() {
4100
+ /**
4101
+ * @var object $cron_data
4102
+ */
4103
+ $cron_data = $this->_storage->get( 'install_sync_cron', null );
4104
+
4105
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
4106
+ }
4107
+
4108
+ /**
4109
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
4110
+ *
4111
+ * @author Vova Feldman (@svovaf)
4112
+ * @since 1.1.7.3
4113
+ */
4114
+ private function schedule_install_sync() {
4115
+ $this->_logger->entrance();
4116
+
4117
+ $this->clear_install_sync_cron();
4118
+
4119
+ // Schedule immediate install sync.
4120
+ wp_schedule_single_event(
4121
+ WP_FS__SCRIPT_START_TIME,
4122
+ $this->get_action_tag( 'install_sync' )
4123
+ );
4124
+
4125
+ $this->_storage->store( 'install_sync_cron', (object) array(
4126
+ 'version' => $this->get_plugin_version(),
4127
+ 'sdk_version' => $this->version,
4128
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
4129
+ 'on' => true,
4130
+ ) );
4131
+ }
4132
+
4133
+ /**
4134
+ * Unix timestamp for previous install sync cron execution or false if never executed.
4135
+ *
4136
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being
4137
+ * updated. But for sure the sync event is working.
4138
+ *
4139
+ * @author Vova Feldman (@svovaf)
4140
+ * @since 1.1.7.3
4141
+ *
4142
+ * @return int|false
4143
+ */
4144
+ function last_install_sync() {
4145
+ $this->_logger->entrance();
4146
+
4147
+ return $this->_storage->get( 'install_sync_timestamp' );
4148
+ }
4149
+
4150
+ /**
4151
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
4152
+ *
4153
+ * @author Vova Feldman (@svovaf)
4154
+ * @since 1.1.7.3
4155
+ *
4156
+ * @return int|false
4157
+ */
4158
+ function next_install_sync() {
4159
+ $this->_logger->entrance();
4160
+
4161
+ if ( ! $this->is_install_sync_scheduled() ) {
4162
+ return false;
4163
+ }
4164
+
4165
+ return wp_next_scheduled( $this->get_action_tag( 'install_sync' ) );
4166
+ }
4167
+
4168
+ /**
4169
+ * Add the actual install sync function to the cron job hook.
4170
+ *
4171
+ * @author Vova Feldman (@svovaf)
4172
+ * @since 1.1.7.3
4173
+ */
4174
+ private function hook_callback_to_install_sync() {
4175
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
4176
+ }
4177
+
4178
+ /**
4179
+ * @author Vova Feldman (@svovaf)
4180
+ * @since 1.1.7.3
4181
+ */
4182
+ private function clear_install_sync_cron() {
4183
+ $this->_logger->entrance();
4184
+
4185
+ if ( ! $this->is_install_sync_scheduled() ) {
4186
+ return;
4187
+ }
4188
+
4189
+ $this->_storage->remove( 'install_sync_cron' );
4190
+
4191
+ wp_clear_scheduled_hook( $this->get_action_tag( 'install_sync' ) );
4192
+ }
4193
+
4194
+ /**
4195
+ * @author Vova Feldman (@svovaf)
4196
+ * @since 1.1.7.3
4197
+ */
4198
+ public function _run_sync_install() {
4199
+ $this->_logger->entrance();
4200
+
4201
+ // Update last install sync timestamp.
4202
+ $this->_storage->install_sync_timestamp = time();
4203
+
4204
+ $this->sync_install( array(), true );
4205
+ }
4206
+
4207
+ #endregion Async Install Sync ------------------------------------------------------------------
4208
+
4209
+ /**
4210
+ * Show a notice that activation is currently pending.
4211
+ *
4212
+ * @author Vova Feldman (@svovaf)
4213
+ * @since 1.0.7
4214
+ *
4215
+ * @param bool|string $email
4216
+ * @param bool $is_pending_trial Since 1.2.1.5
4217
+ */
4218
+ function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
4219
+ if ( ! is_string( $email ) ) {
4220
+ $current_user = self::_get_current_wp_user();
4221
+ $email = $current_user->user_email;
4222
+ }
4223
+
4224
+ $this->_admin_notices->add_sticky(
4225
+ sprintf(
4226
+ $this->get_text( 'pending-activation-message' ),
4227
+ '<b>' . $this->get_plugin_name() . '</b>',
4228
+ '<b>' . $email . '</b>',
4229
+ $this->get_text( $is_pending_trial ? 'start-the-trial' : 'complete-the-install' )
4230
+ ),
4231
+ 'activation_pending',
4232
+ 'Thanks!'
4233
+ );
4234
+ }
4235
+
4236
+ /**
4237
+ * Check if currently in plugin activation.
4238
+ *
4239
+ * @author Vova Feldman (@svovaf)
4240
+ * @since 1.1.4
4241
+ *
4242
+ * @return bool
4243
+ */
4244
+ function is_plugin_activation() {
4245
+ return get_option( 'fs_'
4246
+ . ( $this->is_plugin() ? '' : $this->_module_type . '_' )
4247
+ . "{$this->_slug}_activated", false );
4248
+ }
4249
+
4250
+ /**
4251
+ *
4252
+ * NOTE: admin_menu action executed before admin_init.
4253
+ *
4254
+ * @author Vova Feldman (@svovaf)
4255
+ * @since 1.0.7
4256
+ */
4257
+ function _admin_init_action() {
4258
+ /**
4259
+ * Automatically redirect to connect/activation page after plugin activation.
4260
+ *
4261
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
4262
+ */
4263
+ if ( $this->is_plugin_activation() ) {
4264
+ delete_option( 'fs_'
4265
+ . ( $this->is_plugin() ? '' : $this->_module_type . '_' )
4266
+ . "{$this->_slug}_activated" );
4267
+
4268
+ if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
4269
+ $this->_redirect_on_activation_hook();
4270
+
4271
+ return;
4272
+ }
4273
+ }
4274
+
4275
+ if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
4276
+ check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
4277
+
4278
+ $this->skip_connection();
4279
+
4280
+ fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
4281
+ }
4282
+
4283
+ if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
4284
+ if ( ! $this->is_pending_activation() ) {
4285
+ if ( ! $this->_menu->is_main_settings_page() ) {
4286
+ /**
4287
+ * If a user visits any other admin page before activating the premium-only theme with a valid
4288
+ * license, reactivate the previous theme.
4289
+ *
4290
+ * @author Leo Fajardo (@leorw)
4291
+ * @since 1.2.2
4292
+ */
4293
+ if ( $this->is_theme()
4294
+ && $this->is_only_premium()
4295
+ && ! $this->has_settings_menu()
4296
+ && ! isset( $_REQUEST['fs_action'] )
4297
+ && $this->can_activate_previous_theme()
4298
+ ) {
4299
+ $this->activate_previous_theme();
4300
+
4301
+ return;
4302
+ }
4303
+
4304
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
4305
+ // Show notice for new plugin installations.
4306
+ $this->_admin_notices->add(
4307
+ sprintf(
4308
+ $this->get_text( 'you-are-step-away' ),
4309
+ sprintf( '<b><a href="%s">%s</a></b>',
4310
+ $this->get_activation_url(),
4311
+ sprintf( $this->get_text( 'activate-x-now' ), $this->get_plugin_name() )
4312
+ )
4313
+ ),
4314
+ '',
4315
+ 'update-nag'
4316
+ );
4317
+ } else {
4318
+ if ( ! isset( $this->_storage->sticky_optin_added ) ) {
4319
+ $this->_storage->sticky_optin_added = true;
4320
+
4321
+ // Show notice for new plugin installations.
4322
+ $this->_admin_notices->add_sticky(
4323
+ sprintf(
4324
+ $this->get_text( 'few-plugin-tweaks' ),
4325
+ $this->_module_type,
4326
+ sprintf( '<b><a href="%s">%s</a></b>',
4327
+ $this->get_activation_url(),
4328
+ sprintf( $this->get_text( 'optin-x-now' ), $this->get_plugin_name() )
4329
+ )
4330
+ ),
4331
+ 'connect_account',
4332
+ '',
4333
+ 'update-nag'
4334
+ );
4335
+ }
4336
+
4337
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
4338
+ // Don't show admin nag if plugin update.
4339
+ wp_enqueue_script( 'wp-pointer' );
4340
+ wp_enqueue_style( 'wp-pointer' );
4341
+
4342
+ $this->_enqueue_connect_essentials();
4343
+
4344
+ add_action( 'admin_print_footer_scripts', array(
4345
+ $this,
4346
+ '_add_connect_pointer_script'
4347
+ ) );
4348
+ }
4349
+ }
4350
+ }
4351
+ }
4352
+
4353
+ if ( $this->is_theme() &&
4354
+ $this->_menu->is_main_settings_page()
4355
+ ) {
4356
+ $this->_show_theme_activation_optin_dialog();
4357
+ }
4358
+ }
4359
+
4360
+ $this->_add_upgrade_action_link();
4361
+ }
4362
+
4363
+ /**
4364
+ * Enqueue connect requires scripts and styles.
4365
+ *
4366
+ * @author Vova Feldman (@svovaf)
4367
+ * @since 1.1.4
4368
+ */
4369
+ function _enqueue_connect_essentials() {
4370
+ wp_enqueue_script( 'jquery' );
4371
+ wp_enqueue_script( 'json2' );
4372
+
4373
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
4374
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
4375
+
4376
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
4377
+ }
4378
+
4379
+ /**
4380
+ * Add connect / opt-in pointer.
4381
+ *
4382
+ * @author Vova Feldman (@svovaf)
4383
+ * @since 1.1.4
4384
+ */
4385
+ function _add_connect_pointer_script() {
4386
+ $vars = array( 'id' => $this->_module_id );
4387
+ $pointer_content = fs_get_template( 'connect.php', $vars );
4388
+ ?>
4389
+ <script type="text/javascript">// <![CDATA[
4390
+ jQuery(document).ready(function ($) {
4391
+ if ('undefined' !== typeof(jQuery().pointer)) {
4392
+
4393
+ var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
4394
+
4395
+ if (element.length > 0) {
4396
+ var optin = $(element).pointer($.extend(true, {}, {
4397
+ content : <?php echo json_encode( $pointer_content ) ?>,
4398
+ position : {
4399
+ edge : 'left',
4400
+ align: 'center'
4401
+ },
4402
+ buttons : function () {
4403
+ // Don't show pointer buttons.
4404
+ return '';
4405
+ },
4406
+ pointerWidth: 482
4407
+ }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
4408
+
4409
+ <?php
4410
+ echo $this->apply_filters( 'optin_pointer_execute', "
4411
+
4412
+ optin.pointer('open');
4413
+
4414
+ // Tag the opt-in pointer with custom class.
4415
+ $('.wp-pointer #fs_connect')
4416
+ .parents('.wp-pointer.wp-pointer-top')
4417
+ .addClass('fs-opt-in-pointer');
4418
+
4419
+ ", 'element', 'optin' ) ?>
4420
+ }
4421
+ }
4422
+ });
4423
+ // ]]></script>
4424
+ <?php
4425
+ }
4426
+
4427
+ /**
4428
+ * Return current page's URL.
4429
+ *
4430
+ * @author Vova Feldman (@svovaf)
4431
+ * @since 1.0.7
4432
+ *
4433
+ * @return string
4434
+ */
4435
+ function current_page_url() {
4436
+ $url = 'http';
4437
+
4438
+ if ( isset( $_SERVER["HTTPS"] ) ) {
4439
+ if ( $_SERVER["HTTPS"] == "on" ) {
4440
+ $url .= "s";
4441
+ }
4442
+ }
4443
+ $url .= "://";
4444
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
4445
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
4446
+ } else {
4447
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
4448
+ }
4449
+
4450
+ return esc_url( $url );
4451
+ }
4452
+
4453
+ /**
4454
+ * Check if the current page is the plugin's main admin settings page.
4455
+ *
4456
+ * @author Vova Feldman (@svovaf)
4457
+ * @since 1.0.7
4458
+ *
4459
+ * @return bool
4460
+ */
4461
+ function _is_plugin_page() {
4462
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
4463
+ fs_is_plugin_page( $this->_slug );
4464
+ }
4465
+
4466
+ /* Events
4467
+ ------------------------------------------------------------------------------------------------------------------*/
4468
+ /**
4469
+ * Delete site install from Database.
4470
+ *
4471
+ * @author Vova Feldman (@svovaf)
4472
+ * @since 1.0.1
4473
+ *
4474
+ * @param bool $store
4475
+ */
4476
+ function _delete_site( $store = true ) {
4477
+ self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store );
4478
+ }
4479
+
4480
+ /**
4481
+ * Delete site install from Database.
4482
+ *
4483
+ * @author Vova Feldman (@svovaf)
4484
+ * @since 1.2.2.7
4485
+ *
4486
+ * @param string $slug
4487
+ * @param string $module_type
4488
+ * @param bool $store
4489
+ */
4490
+ static function _delete_site_by_slug($slug, $module_type, $store = true ) {
4491
+ $sites = self::get_all_sites( $module_type );
4492
+
4493
+ if ( isset( $sites[ $slug ] ) ) {
4494
+ unset( $sites[ $slug ] );
4495
+ }
4496
+
4497
+ self::set_account_option_by_module( $module_type, 'sites', $sites, $store );
4498
+ }
4499
+
4500
+ /**
4501
+ * Delete plugin's plans information.
4502
+ *
4503
+ * @param bool $store Flush to Database if true.
4504
+ *
4505
+ * @author Vova Feldman (@svovaf)
4506
+ * @since 1.0.9
4507
+ */
4508
+ private function _delete_plans( $store = true ) {
4509
+ $this->_logger->entrance();
4510
+
4511
+ $plans = self::get_all_plans( $this->_module_type );
4512
+
4513
+ unset( $plans[ $this->_slug ] );
4514
+
4515
+ $this->set_account_option( 'plans', $plans, $store );
4516
+ }
4517
+
4518
+ /**
4519
+ * Delete all plugin licenses.
4520
+ *
4521
+ * @author Vova Feldman (@svovaf)
4522
+ * @since 1.0.9
4523
+ *
4524
+ * @param bool $store
4525
+ * @param string|bool $plugin_slug
4526
+ */
4527
+ private function _delete_licenses( $store = true, $plugin_slug = false ) {
4528
+ $this->_logger->entrance();
4529
+
4530
+ $all_licenses = self::get_all_licenses( $this->_module_type );
4531
+
4532
+ if ( ! is_string( $plugin_slug ) ) {
4533
+ $plugin_slug = $this->_slug;
4534
+ }
4535
+
4536
+ unset( $all_licenses[ $plugin_slug ] );
4537
+
4538
+ $this->set_account_option( 'licenses', $all_licenses, $store );
4539
+ }
4540
+
4541
+ /**
4542
+ * Check if Freemius was added on new plugin installation.
4543
+ *
4544
+ * @author Vova Feldman (@svovaf)
4545
+ * @since 1.1.5
4546
+ *
4547
+ * @return bool
4548
+ */
4549
+ function is_plugin_new_install() {
4550
+ return isset( $this->_storage->is_plugin_new_install ) &&
4551
+ $this->_storage->is_plugin_new_install;
4552
+ }
4553
+
4554
+ /**
4555
+ * Check if it's the first plugin release that is running Freemius.
4556
+ *
4557
+ * @author Vova Feldman (@svovaf)
4558
+ * @since 1.2.1.5
4559
+ *
4560
+ * @return bool
4561
+ */
4562
+ function is_first_freemius_powered_version() {
4563
+ return empty( $this->_storage->plugin_last_version );
4564
+ }
4565
+
4566
+ /**
4567
+ * @author Leo Fajardo (@leorw)
4568
+ * @since 1.2.2
4569
+ *
4570
+ * @return bool|string
4571
+ */
4572
+ private function get_previous_theme_slug() {
4573
+ return isset( $this->_storage->previous_theme ) ?
4574
+ $this->_storage->previous_theme :
4575
+ false;
4576
+ }
4577
+
4578
+ /**
4579
+ * @author Leo Fajardo (@leorw)
4580
+ * @since 1.2.2
4581
+ *
4582
+ * @return string
4583
+ */
4584
+ private function can_activate_previous_theme() {
4585
+ $slug = $this->get_previous_theme_slug();
4586
+ if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
4587
+ $theme_instance = wp_get_theme( $slug );
4588
+
4589
+ return $theme_instance->exists();
4590
+ }
4591
+
4592
+ return false;
4593
+ }
4594
+
4595
+ /**
4596
+ * @author Leo Fajardo (@leorw)
4597
+ * @since 1.2.2
4598
+ *
4599
+ * @return string
4600
+ */
4601
+ private function activate_previous_theme() {
4602
+ switch_theme( $this->get_previous_theme_slug() );
4603
+ unset( $this->_storage->previous_theme );
4604
+
4605
+ global $pagenow;
4606
+ if ( 'themes.php' === $pagenow ) {
4607
+ /**
4608
+ * Refresh the active theme information.
4609
+ *
4610
+ * @author Leo Fajardo (@leorw)
4611
+ * @since 1.2.2
4612
+ */
4613
+ fs_redirect( admin_url( $pagenow ) );
4614
+ }
4615
+ }
4616
+
4617
+ /**
4618
+ * @author Leo Fajardo (@leorw)
4619
+ * @since 1.2.2
4620
+ *
4621
+ * @return string
4622
+ */
4623
+ function get_previous_theme_activation_url() {
4624
+ if ( ! $this->can_activate_previous_theme() ) {
4625
+ return '';
4626
+ }
4627
+
4628
+ /**
4629
+ * Activation URL
4630
+ *
4631
+ * @author Leo Fajardo (@leorw)
4632
+ * @since 1.2.2
4633
+ */
4634
+ return wp_nonce_url(
4635
+ admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
4636
+ 'switch-theme_' . $this->get_previous_theme_slug()
4637
+ );
4638
+ }
4639
+
4640
+ /**
4641
+ * Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
4642
+ * form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
4643
+ * activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
4644
+ * theme doesn't exist, then there will be no close button.
4645
+ *
4646
+ * @author Leo Fajardo (@leorw)
4647
+ * @since 1.2.2
4648
+ *
4649
+ * @param string $slug_or_name Old theme's slug or name.
4650
+ * @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
4651
+ */
4652
+ function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
4653
+ $this->_storage->previous_theme = ( false !== $old_theme ) ?
4654
+ $old_theme->get_stylesheet() :
4655
+ $slug_or_name;
4656
+
4657
+ $this->_activate_plugin_event_hook();
4658
+ }
4659
+
4660
+ /**
4661
+ * Plugin activated hook.
4662
+ *
4663
+ * @author Vova Feldman (@svovaf)
4664
+ * @since 1.0.1
4665
+ *
4666
+ * @uses FS_Api
4667
+ */
4668
+ function _activate_plugin_event_hook() {
4669
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
4670
+
4671
+ if ( ! $this->is_user_admin() ) {
4672
+ return;
4673
+ }
4674
+
4675
+ $this->unregister_uninstall_hook();
4676
+
4677
+ // Clear API cache on activation.
4678
+ FS_Api::clear_cache();
4679
+
4680
+ $is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );
4681
+
4682
+ $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
4683
+
4684
+ // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
4685
+ // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
4686
+ $other_version_basename = $is_premium_version_activation ?
4687
+ $this->_free_plugin_basename :
4688
+ $this->premium_plugin_basename();
4689
+
4690
+ /**
4691
+ * If the other module version is activate, deactivate it.
4692
+ *
4693
+ * @author Leo Fajardo (@leorw)
4694
+ * @since 1.2.2
4695
+ */
4696
+ if ( is_plugin_active( $other_version_basename ) ) {
4697
+ deactivate_plugins( $other_version_basename );
4698
+ }
4699
+
4700
+ if ( $this->is_registered() ) {
4701
+ if ( $is_premium_version_activation ) {
4702
+ $this->reconnect_locally();
4703
+ }
4704
+
4705
+
4706
+ // Schedule re-activation event and sync.
4707
+ // $this->sync_install( array(), true );
4708
+ $this->schedule_install_sync();
4709
+
4710
+ // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
4711
+ if ( $is_premium_version_activation ) {
4712
+ $this->_admin_notices->add(
4713
+ sprintf( $this->get_text( 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
4714
+ $this->get_text( 'woot' ) . '!'
4715
+ );
4716
+ }
4717
+ } else if ( $this->is_anonymous() ) {
4718
+ /**
4719
+ * Reset "skipped" click cache on the following:
4720
+ * 1. Freemius DEV mode.
4721
+ * 2. WordPress DEBUG mode.
4722
+ * 3. If a plugin and the user skipped the exact same version before.
4723
+ *
4724
+ * @since 1.2.2.7 Ulrich Pogson (@grapplerulrich) asked to not reset the SKIPPED flag if the exact same THEME version was activated before unless the developer is running with WP_DEBUG on, or Freemius debug mode on (WP_FS__DEV_MODE).
4725
+ *
4726
+ * @todo 4. If explicitly asked to retry after every activation.
4727
+ */
4728
+ if ( WP_FS__DEV_MODE ||
4729
+ (
4730
+ ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
4731
+ $this->get_plugin_version() == $this->_storage->is_anonymous['version']
4732
+ )
4733
+ ) {
4734
+ $this->reset_anonymous_mode();
4735
+ }
4736
+ }
4737
+
4738
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
4739
+ /**
4740
+ * If no previous version of plugin's version exist, it means that it's either
4741
+ * the first time that the plugin installed on the site, or the plugin was installed
4742
+ * before but didn't have Freemius integrated.
4743
+ *
4744
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
4745
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
4746
+ * only after immediate activation.
4747
+ *
4748
+ * @since 1.1.4
4749
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
4750
+ */
4751
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
4752
+ }
4753
+
4754
+ if ( ! $this->_anonymous_mode &&
4755
+ $this->has_api_connectivity( WP_FS__DEV_MODE ) &&
4756
+ ! $this->_isAutoInstall
4757
+ ) {
4758
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
4759
+ add_option( 'fs_'
4760
+ . ( $this->is_plugin() ? '' : $this->_module_type . '_' )
4761
+ . "{$this->_slug}_activated", true );
4762
+ }
4763
+
4764
+ /**
4765
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
4766
+ * after the plugin was loaded. The logic is located at activate_plugin()
4767
+ * ./wp-admin/includes/plugin.php.
4768
+ *
4769
+ * @author Vova Feldman (@svovaf)
4770
+ * @since 1.1.9
4771
+ */
4772
+ $this->_storage->was_plugin_loaded = true;
4773
+ }
4774
+
4775
+ /**
4776
+ * Delete account.
4777
+ *
4778
+ * @author Vova Feldman (@svovaf)
4779
+ * @since 1.0.3
4780
+ *
4781
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
4782
+ */
4783
+ function delete_account_event( $check_user = true ) {
4784
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
4785
+
4786
+ if ( $check_user && ! $this->is_user_admin() ) {
4787
+ return;
4788
+ }
4789
+
4790
+ $this->do_action( 'before_account_delete' );
4791
+
4792
+ // Clear all admin notices.
4793
+ $this->_admin_notices->clear_all_sticky();
4794
+
4795
+ $this->_delete_site( false );
4796
+
4797
+ $this->_delete_plans( false );
4798
+
4799
+ $this->_delete_licenses( false );
4800
+
4801
+ // Delete add-ons related to plugin's account.
4802
+ $this->_delete_account_addons( false );
4803
+
4804
+ // @todo Delete plans and licenses of add-ons.
4805
+
4806
+ self::$_accounts->store();
4807
+
4808
+ /**
4809
+ * IMPORTANT:
4810
+ * Clear crons must be executed before clearing all storage.
4811
+ * Otherwise, the cron will not be cleared.
4812
+ */
4813
+ $this->clear_sync_cron();
4814
+ $this->clear_install_sync_cron();
4815
+
4816
+ // Clear all storage data.
4817
+ $this->_storage->clear_all( true, array(
4818
+ 'connectivity_test',
4819
+ 'is_on',
4820
+ ) );
4821
+
4822
+ // Send delete event.
4823
+ $this->get_api_site_scope()->call( '/', 'delete' );
4824
+
4825
+ $this->do_action( 'after_account_delete' );
4826
+ }
4827
+
4828
+ /**
4829
+ * Plugin deactivation hook.
4830
+ *
4831
+ * @author Vova Feldman (@svovaf)
4832
+ * @since 1.0.1
4833
+ */
4834
+ function _deactivate_plugin_hook() {
4835
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
4836
+
4837
+ if ( ! current_user_can( 'activate_plugins' ) ) {
4838
+ return;
4839
+ }
4840
+
4841
+ $this->_admin_notices->clear_all_sticky();
4842
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
4843
+ unset( $this->_storage->sticky_optin_added );
4844
+ }
4845
+
4846
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
4847
+ // Remember that plugin was already installed.
4848
+ $this->_storage->is_plugin_new_install = false;
4849
+ }
4850
+
4851
+ // Hook to plugin uninstall.
4852
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
4853
+
4854
+ $this->clear_module_main_file_cache();
4855
+ $this->clear_sync_cron();
4856
+ $this->clear_install_sync_cron();
4857
+
4858
+ if ( $this->is_registered() ) {
4859
+ // Send deactivation event.
4860
+ $this->sync_install( array(
4861
+ 'is_active' => false,
4862
+ ) );
4863
+ } else {
4864
+ if ( ! $this->has_api_connectivity() ) {
4865
+ // Reset connectivity test cache.
4866
+ unset( $this->_storage->connectivity_test );
4867
+ }
4868
+ }
4869
+
4870
+ // Clear API cache on deactivation.
4871
+ FS_Api::clear_cache();
4872
+
4873
+ $this->remove_sdk_reference();
4874
+ }
4875
+
4876
+ /**
4877
+ * @author Vova Feldman (@svovaf)
4878
+ * @since 1.1.6
4879
+ */
4880
+ private function remove_sdk_reference() {
4881
+ global $fs_active_plugins;
4882
+
4883
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
4884
+ if ( $this->_plugin_basename == $data->plugin_path ) {
4885
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
4886
+ break;
4887
+ }
4888
+ }
4889
+
4890
+ fs_fallback_to_newest_active_sdk();
4891
+ }
4892
+
4893
+ /**
4894
+ * @author Vova Feldman (@svovaf)
4895
+ * @since 1.1.3
4896
+ *
4897
+ * @param bool $is_anonymous
4898
+ */
4899
+ private function set_anonymous_mode( $is_anonymous = true ) {
4900
+ // Store information regarding skip to try and opt-in the user
4901
+ // again in the future.
4902
+ $this->_storage->is_anonymous = array(
4903
+ 'is' => $is_anonymous,
4904
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
4905
+ 'version' => $this->get_plugin_version(),
4906
+ );
4907
+
4908
+ // Update anonymous mode cache.
4909
+ $this->_is_anonymous = $is_anonymous;
4910
+ }
4911
+
4912
+ /**
4913
+ * @author Vova Feldman (@svovaf)
4914
+ * @since 1.1.3
4915
+ */
4916
+ private function reset_anonymous_mode() {
4917
+ unset( $this->_storage->is_anonymous );
4918
+
4919
+ /**
4920
+ * Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
4921
+ * has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
4922
+ * on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
4923
+ *
4924
+ * @author Leo Fajardo (@leorw)
4925
+ * @since 1.2.2
4926
+ */
4927
+ unset( $this->_is_anonymous );
4928
+ }
4929
+
4930
+ /**
4931
+ * Clears the anonymous mode and redirects to the opt-in screen.
4932
+ *
4933
+ * @author Vova Feldman (@svovaf)
4934
+ * @since 1.1.7
4935
+ */
4936
+ function connect_again() {
4937
+ if ( ! $this->is_anonymous() ) {
4938
+ return;
4939
+ }
4940
+
4941
+ $this->reset_anonymous_mode();
4942
+
4943
+ fs_redirect( $this->get_activation_url() );
4944
+ }
4945
+
4946
+ /**
4947
+ * Skip account connect, and set anonymous mode.
4948
+ *
4949
+ * @author Vova Feldman (@svovaf)
4950
+ * @since 1.1.1
4951
+ */
4952
+ private function skip_connection() {
4953
+ $this->_logger->entrance();
4954
+
4955
+ $this->_admin_notices->remove_sticky( 'connect_account' );
4956
+
4957
+ $this->set_anonymous_mode();
4958
+
4959
+ // Send anonymous skip event.
4960
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
4961
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
4962
+ 'uid' => $this->get_anonymous_id(),
4963
+ ) );
4964
+ }
4965
+
4966
+ /**
4967
+ * Plugin version update hook.
4968
+ *
4969
+ * @author Vova Feldman (@svovaf)
4970
+ * @since 1.0.4
4971
+ */
4972
+ private function update_plugin_version_event() {
4973
+ $this->_logger->entrance();
4974
+
4975
+ if ( ! $this->is_registered() ) {
4976
+ return;
4977
+ }
4978
+
4979
+ $this->schedule_install_sync();
4980
+ // $this->sync_install( array(), true );
4981
+ }
4982
+
4983
+ /**
4984
+ * Return a list of modified plugins since the last sync.
4985
+ *
4986
+ * Note:
4987
+ * There's no point to store a plugins counter since even if the number of
4988
+ * plugins didn't change, we still need to check if the versions are all the
4989
+ * same and the activity state is similar.
4990
+ *
4991
+ * @author Vova Feldman (@svovaf)
4992
+ * @since 1.1.8
4993
+ *
4994
+ * @return array|false
4995
+ */
4996
+ private function get_plugins_data_for_api() {
4997
+ // Alias.
4998
+ $option_name = 'all_plugins';
4999
+
5000
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
5001
+
5002
+ if ( ! is_object( $all_cached_plugins ) ) {
5003
+ $all_cached_plugins = (object) array(
5004
+ 'timestamp' => '',
5005
+ 'md5' => '',
5006
+ 'plugins' => array(),
5007
+ );
5008
+ }
5009
+
5010
+ $time = time();
5011
+
5012
+ if ( ! empty( $all_cached_plugins->timestamp ) &&
5013
+ ( $time - $all_cached_plugins->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
5014
+ ) {
5015
+ // Don't send plugin updates if last update was in the past 5 min.
5016
+ return false;
5017
+ }
5018
+
5019
+ // Write timestamp to lock the logic.
5020
+ $all_cached_plugins->timestamp = $time;
5021
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
5022
+
5023
+ // Reload options from DB.
5024
+ self::$_accounts->load( true );
5025
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
5026
+
5027
+ if ( $time != $all_cached_plugins->timestamp ) {
5028
+ // If timestamp is different, then another thread captured the lock.
5029
+ return false;
5030
+ }
5031
+
5032
+ // Check if there's a change in plugins.
5033
+ $all_plugins = self::get_all_plugins();
5034
+
5035
+ // Check if plugins changed.
5036
+ ksort( $all_plugins );
5037
+
5038
+ $plugins_signature = '';
5039
+ foreach ( $all_plugins as $basename => $data ) {
5040
+ $plugins_signature .= $data['slug'] . ',' .
5041
+ $data['Version'] . ',' .
5042
+ ( $data['is_active'] ? '1' : '0' ) . ';';
5043
+ }
5044
+
5045
+ // Check if plugins status changed (version or active/inactive).
5046
+ $plugins_changed = ( $all_cached_plugins->md5 !== md5( $plugins_signature ) );
5047
+
5048
+ $plugins_update_data = array();
5049
+
5050
+ if ( $plugins_changed ) {
5051
+ // Change in plugins, report changes.
5052
+
5053
+ // Update existing plugins info.
5054
+ foreach ( $all_cached_plugins->plugins as $basename => $data ) {
5055
+ if ( ! isset( $all_plugins[ $basename ] ) ) {
5056
+ // Plugin uninstalled.
5057
+ $uninstalled_plugin_data = $data;
5058
+ $uninstalled_plugin_data['is_active'] = false;
5059
+ $uninstalled_plugin_data['is_uninstalled'] = true;
5060
+ $plugins_update_data[] = $uninstalled_plugin_data;
5061
+
5062
+ unset( $all_plugins[ $basename ] );
5063
+ unset( $all_cached_plugins->plugins[ $basename ] );
5064
+ } else if ( $data['is_active'] !== $all_plugins[ $basename ]['is_active'] ||
5065
+ $data['version'] !== $all_plugins[ $basename ]['Version']
5066
+ ) {
5067
+ // Plugin activated or deactivated, or version changed.
5068
+ $all_cached_plugins->plugins[ $basename ]['is_active'] = $all_plugins[ $basename ]['is_active'];
5069
+ $all_cached_plugins->plugins[ $basename ]['version'] = $all_plugins[ $basename ]['Version'];
5070
+
5071
+ $plugins_update_data[] = $all_cached_plugins->plugins[ $basename ];
5072
+ }
5073
+ }
5074
+
5075
+ // Find new plugins that weren't yet seen before.
5076
+ foreach ( $all_plugins as $basename => $data ) {
5077
+ if ( ! isset( $all_cached_plugins->plugins[ $basename ] ) ) {
5078
+ // New plugin.
5079
+ $new_plugin = array(
5080
+ 'slug' => $data['slug'],
5081
+ 'version' => $data['Version'],
5082
+ 'title' => $data['Name'],
5083
+ 'is_active' => $data['is_active'],
5084
+ 'is_uninstalled' => false,
5085
+ );
5086
+
5087
+ $plugins_update_data[] = $new_plugin;
5088
+ $all_cached_plugins->plugins[ $basename ] = $new_plugin;
5089
+ }
5090
+ }
5091
+
5092
+ $all_cached_plugins->md5 = md5( $plugins_signature );
5093
+ $all_cached_plugins->timestamp = $time;
5094
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
5095
+ }
5096
+
5097
+ return $plugins_update_data;
5098
+ }
5099
+
5100
+ /**
5101
+ * Return a list of modified themes since the last sync.
5102
+ *
5103
+ * Note:
5104
+ * There's no point to store a themes counter since even if the number of
5105
+ * themes didn't change, we still need to check if the versions are all the
5106
+ * same and the activity state is similar.
5107
+ *
5108
+ * @author Vova Feldman (@svovaf)
5109
+ * @since 1.1.8
5110
+ *
5111
+ * @return array|false
5112
+ */
5113
+ private function get_themes_data_for_api() {
5114
+ // Alias.
5115
+ $option_name = 'all_themes';
5116
+
5117
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
5118
+
5119
+ if ( ! is_object( $all_cached_themes ) ) {
5120
+ $all_cached_themes = (object) array(
5121
+ 'timestamp' => '',
5122
+ 'md5' => '',
5123
+ 'themes' => array(),
5124
+ );
5125
+ }
5126
+
5127
+ $time = time();
5128
+
5129
+ if ( ! empty( $all_cached_themes->timestamp ) &&
5130
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
5131
+ ) {
5132
+ // Don't send theme updates if last update was in the past 5 min.
5133
+ return false;
5134
+ }
5135
+
5136
+ // Write timestamp to lock the logic.
5137
+ $all_cached_themes->timestamp = $time;
5138
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
5139
+
5140
+ // Reload options from DB.
5141
+ self::$_accounts->load( true );
5142
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
5143
+
5144
+ if ( $time != $all_cached_themes->timestamp ) {
5145
+ // If timestamp is different, then another thread captured the lock.
5146
+ return false;
5147
+ }
5148
+
5149
+ // Get active theme.
5150
+ $active_theme = wp_get_theme();
5151
+ $active_theme_stylesheet = $active_theme->get_stylesheet();
5152
+
5153
+ // Check if there's a change in themes.
5154
+ $all_themes = wp_get_themes();
5155
+
5156
+ // Check if themes changed.
5157
+ ksort( $all_themes );
5158
+
5159
+ $themes_signature = '';
5160
+ foreach ( $all_themes as $slug => $data ) {
5161
+ $is_active = ( $slug === $active_theme_stylesheet );
5162
+ $themes_signature .= $slug . ',' .
5163
+ $data->version . ',' .
5164
+ ( $is_active ? '1' : '0' ) . ';';
5165
+ }
5166
+
5167
+ // Check if themes status changed (version or active/inactive).
5168
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
5169
+
5170
+ $themes_update_data = array();
5171
+
5172
+ if ( $themes_changed ) {
5173
+ // Change in themes, report changes.
5174
+
5175
+ // Update existing themes info.
5176
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
5177
+ $is_active = ( $slug === $active_theme_stylesheet );
5178
+
5179
+ if ( ! isset( $all_themes[ $slug ] ) ) {
5180
+ // Plugin uninstalled.
5181
+ $uninstalled_theme_data = $data;
5182
+ $uninstalled_theme_data['is_active'] = false;
5183
+ $uninstalled_theme_data['is_uninstalled'] = true;
5184
+ $themes_update_data[] = $uninstalled_theme_data;
5185
+
5186
+ unset( $all_themes[ $slug ] );
5187
+ unset( $all_cached_themes->themes[ $slug ] );
5188
+ } else if ( $data['is_active'] !== $is_active ||
5189
+ $data['version'] !== $all_themes[ $slug ]->version
5190
+ ) {
5191
+ // Plugin activated or deactivated, or version changed.
5192
+
5193
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
5194
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
5195
+
5196
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
5197
+ }
5198
+ }
5199
+
5200
+ // Find new themes that weren't yet seen before.
5201
+ foreach ( $all_themes as $slug => $data ) {
5202
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
5203
+ $is_active = ( $slug === $active_theme_stylesheet );
5204
+
5205
+ // New plugin.
5206
+ $new_plugin = array(
5207
+ 'slug' => $slug,
5208
+ 'version' => $data->version,
5209
+ 'title' => $data->name,
5210
+ 'is_active' => $is_active,
5211
+ 'is_uninstalled' => false,
5212
+ );
5213
+
5214
+ $themes_update_data[] = $new_plugin;
5215
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
5216
+ }
5217
+ }
5218
+
5219
+ $all_cached_themes->md5 = md5( $themes_signature );
5220
+ $all_cached_themes->timestamp = time();
5221
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
5222
+ }
5223
+
5224
+ return $themes_update_data;
5225
+ }
5226
+
5227
+ /**
5228
+ * Update install details.
5229
+ *
5230
+ * @author Vova Feldman (@svovaf)
5231
+ * @since 1.1.2
5232
+ *
5233
+ * @param string[] string $override
5234
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
5235
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
5236
+ *
5237
+ * @return array
5238
+ */
5239
+ private function get_install_data_for_api(
5240
+ array $override,
5241
+ $include_plugins = true,
5242
+ $include_themes = true
5243
+ ) {
5244
+ /**
5245
+ * @since 1.1.8 Also send plugin updates.
5246
+ */
5247
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
5248
+ $plugins = $this->get_plugins_data_for_api();
5249
+ if ( ! empty( $plugins ) ) {
5250
+ $override['plugins'] = $plugins;
5251
+ }
5252
+ }
5253
+ /**
5254
+ * @since 1.1.8 Also send themes updates.
5255
+ */
5256
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
5257
+ $themes = $this->get_themes_data_for_api();
5258
+ if ( ! empty( $themes ) ) {
5259
+ $override['themes'] = $themes;
5260
+ }
5261
+ }
5262
+
5263
+ return array_merge( array(
5264
+ 'version' => $this->get_plugin_version(),
5265
+ 'is_premium' => $this->is_premium(),
5266
+ 'language' => get_bloginfo( 'language' ),
5267
+ 'charset' => get_bloginfo( 'charset' ),
5268
+ 'platform_version' => get_bloginfo( 'version' ),
5269
+ 'sdk_version' => $this->version,
5270
+ 'programming_language_version' => phpversion(),
5271
+ 'title' => get_bloginfo( 'name' ),
5272
+ 'url' => get_site_url(),
5273
+ // Special params.
5274
+ 'is_active' => true,
5275
+ 'is_disconnected' => $this->is_tracking_prohibited(),
5276
+ 'is_uninstalled' => false,
5277
+ ), $override );
5278
+ }
5279
+
5280
+ /**
5281
+ * Update install only if changed.
5282
+ *
5283
+ * @author Vova Feldman (@svovaf)
5284
+ * @since 1.0.9
5285
+ *
5286
+ * @param string[] string $override
5287
+ * @param bool $flush
5288
+ *
5289
+ * @return false|object|string
5290
+ */
5291
+ private function send_install_update( $override = array(), $flush = false ) {
5292
+ $this->_logger->entrance();
5293
+
5294
+ $check_properties = $this->get_install_data_for_api( $override );
5295
+
5296
+ if ( $flush ) {
5297
+ $params = $check_properties;
5298
+ } else {
5299
+ $params = array();
5300
+ $special = array();
5301
+ $special_override = false;
5302
+
5303
+ foreach ( $check_properties as $p => $v ) {
5304
+ if ( property_exists( $this->_site, $p ) ) {
5305
+ if ( ( is_bool( $this->_site->{$p} ) || ! empty( $this->_site->{$p} ) ) &&
5306
+ $this->_site->{$p} != $v
5307
+ ) {
5308
+ $this->_site->{$p} = $v;
5309
+ $params[ $p ] = $v;
5310
+ }
5311
+ } else {
5312
+ $special[ $p ] = $v;
5313
+
5314
+ if ( isset( $override[ $p ] ) ||
5315
+ 'plugins' === $p ||
5316
+ 'themes' === $p
5317
+ ) {
5318
+ $special_override = true;
5319
+ }
5320
+ }
5321
+ }
5322
+
5323
+ if ( $special_override || 0 < count( $params ) ) {
5324
+ // Add special params only if has at least one
5325
+ // standard param, or if explicitly requested to
5326
+ // override a special param or a param which is not exist
5327
+ // in the install object.
5328
+ $params = array_merge( $params, $special );
5329
+ }
5330
+ }
5331
+
5332
+ if ( 0 < count( $params ) ) {
5333
+ // Update last install sync timestamp.
5334
+ $this->_storage->install_sync_timestamp = time();
5335
+
5336
+ $params['uid'] = $this->get_anonymous_id();
5337
+
5338
+ // Send updated values to FS.
5339
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
5340
+
5341
+ if ( $this->is_api_result_entity( $site ) ) {
5342
+ // I successfully sent install update, clear scheduled sync if exist.
5343
+ $this->clear_install_sync_cron();
5344
+ }
5345
+
5346
+ return $site;
5347
+ }
5348
+
5349
+ return false;
5350
+ }
5351
+
5352
+ /**
5353
+ * Update install only if changed.
5354
+ *
5355
+ * @author Vova Feldman (@svovaf)
5356
+ * @since 1.0.9
5357
+ *
5358
+ * @param string[] string $override
5359
+ * @param bool $flush
5360
+ */
5361
+ private function sync_install( $override = array(), $flush = false ) {
5362
+ $this->_logger->entrance();
5363
+
5364
+ $site = $this->send_install_update( $override, $flush );
5365
+
5366
+ if ( false === $site ) {
5367
+ // No sync required.
5368
+ return;
5369
+ }
5370
+
5371
+ if ( ! $this->is_api_result_entity( $site ) ) {
5372
+ // Failed to sync, don't update locally.
5373
+ return;
5374
+ }
5375
+
5376
+ $plan = $this->get_plan();
5377
+ $this->_site = new FS_Site( $site );
5378
+ $this->_site->plan = $plan;
5379
+
5380
+ $this->_store_site( true );
5381
+ }
5382
+
5383
+ /**
5384
+ * Track install's custom event.
5385
+ *
5386
+ * IMPORTANT:
5387
+ * Custom event tracking is currently only supported for specific clients.
5388
+ * If you are not one of them, please don't use this method. If you will,
5389
+ * the API will simply ignore your request based on the plugin ID.
5390
+ *
5391
+ * Need custom tracking for your plugin or theme?
5392
+ * If you are interested in custom event tracking please contact yo@freemius.com
5393
+ * for further details.
5394
+ *
5395
+ * @author Vova Feldman (@svovaf)
5396
+ * @since 1.2.1
5397
+ *
5398
+ * @param string $name Event name.
5399
+ * @param array $properties Associative key/value array with primitive values only
5400
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
5401
+ * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
5402
+ *
5403
+ * @return object|false Event data or FALSE on failure.
5404
+ *
5405
+ * @throws \Freemius_InvalidArgumentException
5406
+ */
5407
+ public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
5408
+ $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
5409
+
5410
+ if ( ! $this->is_registered() ) {
5411
+ return false;
5412
+ }
5413
+
5414
+ $event = array( 'type' => $name );
5415
+
5416
+ if ( is_numeric( $process_at ) && $process_at > time() ) {
5417
+ $event['process_at'] = $process_at;
5418
+ }
5419
+
5420
+ if ( $once ) {
5421
+ $event['once'] = true;
5422
+ }
5423
+
5424
+ if ( ! empty( $properties ) ) {
5425
+ // Verify associative array values are primitive.
5426
+ foreach ( $properties as $k => $v ) {
5427
+ if ( ! is_scalar( $v ) ) {
5428
+ throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
5429
+ }
5430
+ }
5431
+
5432
+ $event['properties'] = $properties;
5433
+ }
5434
+
5435
+ $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
5436
+
5437
+ return $this->is_api_error( $result ) ?
5438
+ false :
5439
+ $result;
5440
+ }
5441
+
5442
+ /**
5443
+ * Track install's custom event only once, but it still triggers the API call.
5444
+ *
5445
+ * IMPORTANT:
5446
+ * Custom event tracking is currently only supported for specific clients.
5447
+ * If you are not one of them, please don't use this method. If you will,
5448
+ * the API will simply ignore your request based on the plugin ID.
5449
+ *
5450
+ * Need custom tracking for your plugin or theme?
5451
+ * If you are interested in custom event tracking please contact yo@freemius.com
5452
+ * for further details.
5453
+ *
5454
+ * @author Vova Feldman (@svovaf)
5455
+ * @since 1.2.1
5456
+ *
5457
+ * @param string $name Event name.
5458
+ * @param array $properties Associative key/value array with primitive values only
5459
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
5460
+ *
5461
+ * @return object|false Event data or FALSE on failure.
5462
+ *
5463
+ * @throws \Freemius_InvalidArgumentException
5464
+ *
5465
+ * @user Freemius::track_event()
5466
+ */
5467
+ public function track_event_once( $name, $properties = array(), $process_at = false ) {
5468
+ return $this->track_event( $name, $properties, $process_at, true );
5469
+ }
5470
+
5471
+ /**
5472
+ * Plugin uninstall hook.
5473
+ *
5474
+ * @author Vova Feldman (@svovaf)
5475
+ * @since 1.0.1
5476
+ *
5477
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
5478
+ */
5479
+ function _uninstall_plugin_event( $check_user = true ) {
5480
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
5481
+
5482
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
5483
+ return;
5484
+ }
5485
+
5486
+ $params = array();
5487
+ $uninstall_reason = null;
5488
+ if ( isset( $this->_storage->uninstall_reason ) ) {
5489
+ $uninstall_reason = $this->_storage->uninstall_reason;
5490
+ $params['reason_id'] = $uninstall_reason->id;
5491
+ $params['reason_info'] = $uninstall_reason->info;
5492
+ }
5493
+
5494
+ if ( ! $this->is_registered() ) {
5495
+ // Send anonymous uninstall event only if user submitted a feedback.
5496
+ if ( isset( $uninstall_reason ) ) {
5497
+ if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
5498
+ $this->opt_in( false, false, false, false, true );
5499
+ } else {
5500
+ $params['uid'] = $this->get_anonymous_id();
5501
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
5502
+ }
5503
+ }
5504
+ } else {
5505
+ // Send uninstall event.
5506
+ $this->send_install_update( array_merge( $params, array(
5507
+ 'is_active' => false,
5508
+ 'is_uninstalled' => true,
5509
+ ) ) );
5510
+ }
5511
+
5512
+ // @todo Decide if we want to delete plugin information from db.
5513
+ }
5514
+
5515
+ /**
5516
+ * @author Vova Feldman (@svovaf)
5517
+ * @since 1.1.1
5518
+ *
5519
+ * @return string
5520
+ */
5521
+ function premium_plugin_basename() {
5522
+ return "{$this->_slug}-premium/" . basename( $this->_free_plugin_basename );
5523
+ }
5524
+
5525
+ /**
5526
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
5527
+ *
5528
+ * @author Vova Feldman (@svovaf)
5529
+ * @since 1.0.2
5530
+ */
5531
+ public static function _uninstall_plugin_hook() {
5532
+ self::_load_required_static();
5533
+
5534
+ self::$_static_logger->entrance();
5535
+
5536
+ if ( ! current_user_can( 'activate_plugins' ) ) {
5537
+ return;
5538
+ }
5539
+
5540
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
5541
+
5542
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
5543
+
5544
+ define( 'WP_FS__UNINSTALL_MODE', true );
5545
+
5546
+ $fs = self::get_instance_by_file( $plugin_file );
5547
+
5548
+ if ( is_object( $fs ) ) {
5549
+ self::require_plugin_essentials();
5550
+
5551
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
5552
+ is_plugin_active( $fs->premium_plugin_basename() )
5553
+ ) {
5554
+ // Deleting Free or Premium plugin version while the other version still installed.
5555
+ return;
5556
+ }
5557
+
5558
+ $fs->_uninstall_plugin_event();
5559
+
5560
+ $fs->do_action( 'after_uninstall' );
5561
+ }
5562
+ }
5563
+
5564
+ #----------------------------------------------------------------------------------
5565
+ #region Plugin Information
5566
+ #----------------------------------------------------------------------------------
5567
+
5568
+ /**
5569
+ * Load WordPress core plugin.php essential module.
5570
+ *
5571
+ * @author Vova Feldman (@svovaf)
5572
+ * @since 1.1.1
5573
+ */
5574
+ private static function require_plugin_essentials() {
5575
+ if ( ! function_exists( 'get_plugins' ) ) {
5576
+ self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
5577
+
5578
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
5579
+ }
5580
+ }
5581
+
5582
+ /**
5583
+ * Load WordPress core pluggable.php module.
5584
+ *
5585
+ * @author Vova Feldman (@svovaf)
5586
+ * @since 1.1.2
5587
+ */
5588
+ private static function require_pluggable_essentials() {
5589
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
5590
+ require_once ABSPATH . 'wp-includes/pluggable.php';
5591
+ }
5592
+ }
5593
+
5594
+ /**
5595
+ * Return plugin data.
5596
+ *
5597
+ * @author Vova Feldman (@svovaf)
5598
+ * @since 1.0.1
5599
+ *
5600
+ * @return array
5601
+ */
5602
+ function get_plugin_data() {
5603
+ if ( ! isset( $this->_plugin_data ) ) {
5604
+ self::require_plugin_essentials();
5605
+
5606
+ if ( $this->is_plugin() ) {
5607
+ /**
5608
+ * @author Vova Feldman (@svovaf)
5609
+ * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
5610
+ *
5611
+ * @link https://github.com/Freemius/wordpress-sdk/issues/77
5612
+ */
5613
+ $plugin_data = get_plugin_data(
5614
+ $this->_plugin_main_file_path,
5615
+ false,
5616
+ false
5617
+ );
5618
+ } else {
5619
+ $theme_data = wp_get_theme();
5620
+
5621
+ $plugin_data = array(
5622
+ 'Name' => $theme_data->get( 'Name' ),
5623
+ 'Version' => $theme_data->get( 'Version' ),
5624
+ 'Author' => $theme_data->get( 'Author' ),
5625
+ 'Description' => $theme_data->get( 'Description' ),
5626
+ 'PluginURI' => $theme_data->get( 'ThemeURI' ),
5627
+ );
5628
+ }
5629
+
5630
+ $this->_plugin_data = $plugin_data;
5631
+ }
5632
+
5633
+ return $this->_plugin_data;
5634
+ }
5635
+
5636
+ /**
5637
+ * @author Vova Feldman (@svovaf)
5638
+ * @since 1.0.1
5639
+ * @since 1.2.2.5 If slug not set load slug by module ID.
5640
+ *
5641
+ * @return string Plugin slug.
5642
+ */
5643
+ function get_slug() {
5644
+ if ( ! isset( $this->_slug ) ) {
5645
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
5646
+ $this->_slug = $id_slug_type_path_map[ $this->_module_id ]['slug'];
5647
+ }
5648
+
5649
+ return $this->_slug;
5650
+ }
5651
+
5652
+ /**
5653
+ * @author Vova Feldman (@svovaf)
5654
+ * @since 1.2.1.7
5655
+ *
5656
+ * @return string Plugin slug.
5657
+ */
5658
+ function get_target_folder_name() {
5659
+ return $this->_slug . ( $this->can_use_premium_code() ? '-premium' : '' );
5660
+ }
5661
+
5662
+ /**
5663
+ * @author Vova Feldman (@svovaf)
5664
+ * @since 1.0.1
5665
+ *
5666
+ * @return number Plugin ID.
5667
+ */
5668
+ function get_id() {
5669
+ return $this->_plugin->id;
5670
+ }
5671
+
5672
+ /**
5673
+ * @author Vova Feldman (@svovaf)
5674
+ * @since 1.2.1.5
5675
+ *
5676
+ * @return string Freemius SDK version
5677
+ */
5678
+ function get_sdk_version() {
5679
+ return $this->version;
5680
+ }
5681
+
5682
+ /**
5683
+ * @author Vova Feldman (@svovaf)
5684
+ * @since 1.2.1.5
5685
+ *
5686
+ * @return number Parent plugin ID (if parent exist).
5687
+ */
5688
+ function get_parent_id() {
5689
+ return $this->is_addon() ?
5690
+ $this->get_parent_instance()->get_id() :
5691
+ $this->_plugin->id;
5692
+ }
5693
+
5694
+ /**
5695
+ * @author Vova Feldman (@svovaf)
5696
+ * @since 1.0.1
5697
+ *
5698
+ * @return string Plugin public key.
5699
+ */
5700
+ function get_public_key() {
5701
+ return $this->_plugin->public_key;
5702
+ }
5703
+
5704
+ /**
5705
+ * Will be available only on sandbox mode.
5706
+ *
5707
+ * @author Vova Feldman (@svovaf)
5708
+ * @since 1.0.4
5709
+ *
5710
+ * @return mixed Plugin secret key.
5711
+ */
5712
+ function get_secret_key() {
5713
+ return $this->_plugin->secret_key;
5714
+ }
5715
+
5716
+ /**
5717
+ * @author Vova Feldman (@svovaf)
5718
+ * @since 1.1.1
5719
+ *
5720
+ * @return bool
5721
+ */
5722
+ function has_secret_key() {
5723
+ return ! empty( $this->_plugin->secret_key );
5724
+ }
5725
+
5726
+ /**
5727
+ * @author Vova Feldman (@svovaf)
5728
+ * @since 1.0.9
5729
+ *
5730
+ * @return string
5731
+ */
5732
+ function get_plugin_name() {
5733
+ $this->_logger->entrance();
5734
+
5735
+ if ( ! isset( $this->_plugin_name ) ) {
5736
+ $plugin_data = $this->get_plugin_data();
5737
+
5738
+ // Get name.
5739
+ $this->_plugin_name = $plugin_data['Name'];
5740
+
5741
+ // Check if plugin name contains "(Premium)" suffix and remove it.
5742
+ $suffix = ' (premium)';
5743
+ $suffix_len = strlen( $suffix );
5744
+
5745
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
5746
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
5747
+ ) {
5748
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
5749
+ }
5750
+
5751
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
5752
+ }
5753
+
5754
+ return $this->_plugin_name;
5755
+ }
5756
+
5757
+ /**
5758
+ * @author Vova Feldman (@svovaf)
5759
+ * @since 1.0.0
5760
+ *
5761
+ * @return string
5762
+ */
5763
+ function get_plugin_version() {
5764
+ $this->_logger->entrance();
5765
+
5766
+ $plugin_data = $this->get_plugin_data();
5767
+
5768
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
5769
+
5770
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
5771
+ }
5772
+
5773
+ /**
5774
+ * @author Vova Feldman (@svovaf)
5775
+ * @since 1.2.1.7
5776
+ *
5777
+ * @return string
5778
+ */
5779
+ function get_plugin_title() {
5780
+ $this->_logger->entrance();
5781
+
5782
+ $title = $this->_plugin->title;
5783
+
5784
+ return $this->apply_filters( 'plugin_title', $title );
5785
+ }
5786
+
5787
+ /**
5788
+ * @author Vova Feldman (@svovaf)
5789
+ * @since 1.2.2.7
5790
+ *
5791
+ * @param bool $lowercase
5792
+ *
5793
+ * @return string
5794
+ */
5795
+ function get_module_label( $lowercase = false ) {
5796
+ $label = $this->is_addon() ?
5797
+ $this->get_text( 'addon' ) :
5798
+ ( $this->is_plugin() ?
5799
+ $this->get_text( 'plugin' ) :
5800
+ $this->get_text( 'theme' ) );
5801
+
5802
+ if ( $lowercase ) {
5803
+ $label = strtolower( $lowercase );
5804
+ }
5805
+
5806
+ return $label;
5807
+ }
5808
+
5809
+ /**
5810
+ * @author Vova Feldman (@svovaf)
5811
+ * @since 1.0.4
5812
+ *
5813
+ * @return string
5814
+ */
5815
+ function get_plugin_basename() {
5816
+ if ( ! isset( $this->_plugin_basename ) ) {
5817
+ if ( $this->is_plugin() ) {
5818
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
5819
+ } else {
5820
+ $this->_plugin_basename = basename( dirname( $this->_plugin_main_file_path ) );
5821
+ }
5822
+ }
5823
+
5824
+ return $this->_plugin_basename;
5825
+ }
5826
+
5827
+ function get_plugin_folder_name() {
5828
+ $this->_logger->entrance();
5829
+
5830
+ $plugin_folder = $this->_plugin_basename;
5831
+
5832
+ while ( '.' !== dirname( $plugin_folder ) ) {
5833
+ $plugin_folder = dirname( $plugin_folder );
5834
+ }
5835
+
5836
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
5837
+
5838
+ return $plugin_folder;
5839
+ }
5840
+
5841
+ #endregion ------------------------------------------------------------------
5842
+
5843
+ /* Account
5844
+ ------------------------------------------------------------------------------------------------------------------*/
5845
+
5846
+ /**
5847
+ * Find plugin's slug by plugin's basename.
5848
+ *
5849
+ * @author Vova Feldman (@svovaf)
5850
+ * @since 1.0.9
5851
+ *
5852
+ * @param string $plugin_base_name
5853
+ *
5854
+ * @return false|string
5855
+ */
5856
+ private static function find_slug_by_basename( $plugin_base_name ) {
5857
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
5858
+
5859
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
5860
+ return false;
5861
+ }
5862
+
5863
+ return $file_slug_map[ $plugin_base_name ];
5864
+ }
5865
+
5866
+ /**
5867
+ * Store the map between the plugin's basename to the slug.
5868
+ *
5869
+ * @author Vova Feldman (@svovaf)
5870
+ * @since 1.0.9
5871
+ */
5872
+ private function store_file_slug_map() {
5873
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
5874
+
5875
+ if ( ! array( $file_slug_map ) ) {
5876
+ $file_slug_map = array();
5877
+ }
5878
+
5879
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
5880
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
5881
+ ) {
5882
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
5883
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
5884
+ }
5885
+ }
5886
+
5887
+ /**
5888
+ * @return FS_User[]
5889
+ */
5890
+ static function get_all_users() {
5891
+ $users = self::$_accounts->get_option( 'users', array() );
5892
+
5893
+ if ( ! is_array( $users ) ) {
5894
+ $users = array();
5895
+ }
5896
+
5897
+ return $users;
5898
+ }
5899
+
5900
+ /**
5901
+ * @param string $module_type
5902
+ *
5903
+ * @return FS_Site[]
5904
+ */
5905
+ private static function get_all_sites( $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
5906
+ $sites = self::get_account_option( 'sites', $module_type );
5907
+
5908
+ if ( ! is_array( $sites ) ) {
5909
+ $sites = array();
5910
+ }
5911
+
5912
+ return $sites;
5913
+ }
5914
+
5915
+ /**
5916
+ * @author Leo Fajardo (@leorw)
5917
+ *
5918
+ * @since 1.2.2
5919
+ *
5920
+ * @param string $option_name
5921
+ * @param string $module_type
5922
+ *
5923
+ * @return mixed
5924
+ */
5925
+ private static function get_account_option( $option_name, $module_type ) {
5926
+ if ( WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
5927
+ $option_name = $module_type . '_' . $option_name;
5928
+ }
5929
+
5930
+ return self::$_accounts->get_option( $option_name, array() );
5931
+ }
5932
+
5933
+ /**
5934
+ * @author Leo Fajardo (@leorw)
5935
+ *
5936
+ * @since 1.2.2
5937
+ *
5938
+ * @param string $option_name
5939
+ * @param mixed $option_value
5940
+ * @param bool $store
5941
+ */
5942
+ private function set_account_option( $option_name, $option_value, $store ) {
5943
+ self::set_account_option_by_module(
5944
+ $this->_module_type,
5945
+ $option_name,
5946
+ $option_value,
5947
+ $store
5948
+ );
5949
+ }
5950
+
5951
+ /**
5952
+ * @author Vova Feldman (@svovaf)
5953
+ *
5954
+ * @since 1.2.2.7
5955
+ *
5956
+ * @param string $module_type
5957
+ * @param string $option_name
5958
+ * @param mixed $option_value
5959
+ * @param bool $store
5960
+ */
5961
+ private static function set_account_option_by_module( $module_type, $option_name, $option_value, $store ) {
5962
+ if ( WP_FS__MODULE_TYPE_PLUGIN != $module_type ) {
5963
+ $option_name = $module_type . '_' . $option_name;
5964
+ }
5965
+
5966
+ self::$_accounts->set_option( $option_name, $option_value, $store );
5967
+ }
5968
+
5969
+ /**
5970
+ * @author Vova Feldman (@svovaf)
5971
+ * @since 1.0.6
5972
+ *
5973
+ * @param string $module_type
5974
+ *
5975
+ * @return FS_Plugin_License[]
5976
+ */
5977
+ private static function get_all_licenses( $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
5978
+ $licenses = self::get_account_option( 'licenses', $module_type );
5979
+
5980
+ if ( ! is_array( $licenses ) ) {
5981
+ $licenses = array();
5982
+ }
5983
+
5984
+ return $licenses;
5985
+ }
5986
+
5987
+ /**
5988
+ * @param string|bool $module_type
5989
+ *
5990
+ * @return FS_Plugin_Plan[]
5991
+ */
5992
+ private static function get_all_plans( $module_type = false ) {
5993
+ $plans = self::get_account_option( 'plans', $module_type );
5994
+
5995
+ if ( ! is_array( $plans ) ) {
5996
+ $plans = array();
5997
+ }
5998
+
5999
+ return $plans;
6000
+ }
6001
+
6002
+ /**
6003
+ * @author Vova Feldman (@svovaf)
6004
+ * @since 1.0.4
6005
+ *
6006
+ * @return FS_Plugin_Tag[]
6007
+ */
6008
+ private static function get_all_updates() {
6009
+ $updates = self::$_accounts->get_option( 'updates', array() );
6010
+
6011
+ if ( ! is_array( $updates ) ) {
6012
+ $updates = array();
6013
+ }
6014
+
6015
+ return $updates;
6016
+ }
6017
+
6018
+ /**
6019
+ * @author Vova Feldman (@svovaf)
6020
+ * @since 1.0.6
6021
+ *
6022
+ * @return array<number,FS_Plugin[]>|false
6023
+ */
6024
+ private static function get_all_addons() {
6025
+ $addons = self::$_accounts->get_option( 'addons', array() );
6026
+
6027
+ if ( ! is_array( $addons ) ) {
6028
+ $addons = array();
6029
+ }
6030
+
6031
+ return $addons;
6032
+ }
6033
+
6034
+ /**
6035
+ * @author Vova Feldman (@svovaf)
6036
+ * @since 1.0.6
6037
+ *
6038
+ * @return FS_Plugin[]|false
6039
+ */
6040
+ private static function get_all_account_addons() {
6041
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
6042
+
6043
+ if ( ! is_array( $addons ) ) {
6044
+ $addons = array();
6045
+ }
6046
+
6047
+ return $addons;
6048
+ }
6049
+
6050
+ /**
6051
+ * Check if user has connected his account (opted-in).
6052
+ *
6053
+ * Note:
6054
+ * If the user opted-in and opted-out on a later stage,
6055
+ * this will still return true. If you want to check if the
6056
+ * user is currently opted-in, use:
6057
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
6058
+ *
6059
+ * @author Vova Feldman (@svovaf)
6060
+ * @since 1.0.1
6061
+ * @return bool
6062
+ */
6063
+ function is_registered() {
6064
+ return is_object( $this->_user );
6065
+ }
6066
+
6067
+ /**
6068
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
6069
+ *
6070
+ * @author Leo Fajardo (@leorw)
6071
+ * @since 1.2.1.5
6072
+ *
6073
+ * @return bool
6074
+ */
6075
+ function is_tracking_allowed() {
6076
+ return ( is_object( $this->_site ) && true !== $this->_site->is_disconnected );
6077
+ }
6078
+
6079
+ /**
6080
+ * @author Vova Feldman (@svovaf)
6081
+ * @since 1.0.4
6082
+ *
6083
+ * @return FS_Plugin
6084
+ */
6085
+ function get_plugin() {
6086
+ return $this->_plugin;
6087
+ }
6088
+
6089
+ /**
6090
+ * @author Vova Feldman (@svovaf)
6091
+ * @since 1.0.3
6092
+ *
6093
+ * @return FS_User
6094
+ */
6095
+ function get_user() {
6096
+ return $this->_user;
6097
+ }
6098
+
6099
+ /**
6100
+ * @author Vova Feldman (@svovaf)
6101
+ * @since 1.0.3
6102
+ *
6103
+ * @return FS_Site
6104
+ */
6105
+ function get_site() {
6106
+ return $this->_site;
6107
+ }
6108
+
6109
+ /**
6110
+ * Get plugin add-ons.
6111
+ *
6112
+ * @author Vova Feldman (@svovaf)
6113
+ * @since 1.0.6
6114
+ *
6115
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
6116
+ *
6117
+ * @param bool $flush
6118
+ *
6119
+ * @return FS_Plugin[]|false
6120
+ */
6121
+ function get_addons( $flush = false ) {
6122
+ $this->_logger->entrance();
6123
+
6124
+ if ( ! $this->_has_addons ) {
6125
+ return false;
6126
+ }
6127
+
6128
+ $addons = $this->sync_addons( $flush );
6129
+
6130
+ return ( ! is_array( $addons ) || empty( $addons ) ) ?
6131
+ false :
6132
+ $addons;
6133
+ }
6134
+
6135
+ /**
6136
+ * @author Vova Feldman (@svovaf)
6137
+ * @since 1.0.6
6138
+ *
6139
+ * @return FS_Plugin[]|false
6140
+ */
6141
+ function get_account_addons() {
6142
+ $this->_logger->entrance();
6143
+
6144
+ $addons = self::get_all_account_addons();
6145
+
6146
+ if ( ! is_array( $addons ) ||
6147
+ ! isset( $addons[ $this->_plugin->id ] ) ||
6148
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
6149
+ 0 === count( $addons[ $this->_plugin->id ] )
6150
+ ) {
6151
+ return false;
6152
+ }
6153
+
6154
+ return $addons[ $this->_plugin->id ];
6155
+ }
6156
+
6157
+ /**
6158
+ * Check if user has any
6159
+ *
6160
+ * @author Vova Feldman (@svovaf)
6161
+ * @since 1.1.6
6162
+ *
6163
+ * @return bool
6164
+ */
6165
+ function has_account_addons() {
6166
+ $addons = $this->get_account_addons();
6167
+
6168
+ return is_array( $addons ) && ( 0 < count( $addons ) );
6169
+ }
6170
+
6171
+
6172
+ /**
6173
+ * Get add-on by ID (from local data).
6174
+ *
6175
+ * @author Vova Feldman (@svovaf)
6176
+ * @since 1.0.6
6177
+ *
6178
+ * @param number $id
6179
+ *
6180
+ * @return FS_Plugin|false
6181
+ */
6182
+ function get_addon( $id ) {
6183
+ $this->_logger->entrance();
6184
+
6185
+ $addons = $this->get_addons();
6186
+
6187
+ if ( is_array( $addons ) ) {
6188
+ foreach ( $addons as $addon ) {
6189
+ if ( $id == $addon->id ) {
6190
+ return $addon;
6191
+ }
6192
+ }
6193
+ }
6194
+
6195
+ return false;
6196
+ }
6197
+
6198
+ /**
6199
+ * Get add-on by slug (from local data).
6200
+ *
6201
+ * @author Vova Feldman (@svovaf)
6202
+ * @since 1.0.6
6203
+ *
6204
+ * @param string $slug
6205
+ *
6206
+ * @param bool $flush
6207
+ *
6208
+ * @return FS_Plugin|false
6209
+ */
6210
+ function get_addon_by_slug( $slug, $flush = false ) {
6211
+ $this->_logger->entrance();
6212
+
6213
+ $addons = $this->get_addons( $flush );
6214
+
6215
+ if ( is_array( $addons ) ) {
6216
+ foreach ( $addons as $addon ) {
6217
+ if ( $slug === $addon->slug ) {
6218
+ return $addon;
6219
+ }
6220
+ }
6221
+ }
6222
+
6223
+ return false;
6224
+ }
6225
+
6226
+ #----------------------------------------------------------------------------------
6227
+ #region Plans & Licensing
6228
+ #----------------------------------------------------------------------------------
6229
+
6230
+ /**
6231
+ * Check if running premium plugin code.
6232
+ *
6233
+ * @author Vova Feldman (@svovaf)
6234
+ * @since 1.0.5
6235
+ *
6236
+ * @return bool
6237
+ */
6238
+ function is_premium() {
6239
+ return $this->_plugin->is_premium;
6240
+ }
6241
+
6242
+ /**
6243
+ * Get site's plan ID.
6244
+ *
6245
+ * @author Vova Feldman (@svovaf)
6246
+ * @since 1.0.2
6247
+ *
6248
+ * @return number
6249
+ */
6250
+ function get_plan_id() {
6251
+ return $this->_site->plan->id;
6252
+ }
6253
+
6254
+ /**
6255
+ * Get site's plan title.
6256
+ *
6257
+ * @author Vova Feldman (@svovaf)
6258
+ * @since 1.0.2
6259
+ *
6260
+ * @return string
6261
+ */
6262
+ function get_plan_title() {
6263
+ return $this->_site->plan->title;
6264
+ }
6265
+
6266
+ /**
6267
+ * @author Vova Feldman (@svovaf)
6268
+ * @since 1.0.9
6269
+ *
6270
+ * @return FS_Plugin_Plan|false
6271
+ */
6272
+ function get_plan() {
6273
+ return is_object( $this->_site->plan ) ?
6274
+ $this->_site->plan :
6275
+ false;
6276
+ }
6277
+
6278
+ /**
6279
+ * @author Vova Feldman (@svovaf)
6280
+ * @since 1.0.3
6281
+ *
6282
+ * @return bool
6283
+ */
6284
+ function is_trial() {
6285
+ $this->_logger->entrance();
6286
+
6287
+ if ( ! $this->is_registered() ) {
6288
+ return false;
6289
+ }
6290
+
6291
+ return $this->_site->is_trial();
6292
+ }
6293
+
6294
+ /**
6295
+ * Check if currently in a trial with payment method (credit card or paypal).
6296
+ *
6297
+ * @author Vova Feldman (@svovaf)
6298
+ * @since 1.1.7
6299
+ *
6300
+ * @return bool
6301
+ */
6302
+ function is_paid_trial() {
6303
+ $this->_logger->entrance();
6304
+
6305
+ if ( ! $this->is_trial() ) {
6306
+ return false;
6307
+ }
6308
+
6309
+ return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
6310
+ }
6311
+
6312
+ /**
6313
+ * Check if trial already utilized.
6314
+ *
6315
+ * @since 1.0.9
6316
+ *
6317
+ * @return bool
6318
+ */
6319
+ function is_trial_utilized() {
6320
+ $this->_logger->entrance();
6321
+
6322
+ if ( ! $this->is_registered() ) {
6323
+ return false;
6324
+ }
6325
+
6326
+ return $this->_site->is_trial_utilized();
6327
+ }
6328
+
6329
+ /**
6330
+ * Get trial plan information (if in trial).
6331
+ *
6332
+ * @author Vova Feldman (@svovaf)
6333
+ * @since 1.0.9
6334
+ *
6335
+ * @return bool|FS_Plugin_Plan
6336
+ */
6337
+ function get_trial_plan() {
6338
+ $this->_logger->entrance();
6339
+
6340
+ if ( ! $this->is_trial() ) {
6341
+ return false;
6342
+ }
6343
+
6344
+ return $this->_storage->trial_plan;
6345
+ }
6346
+
6347
+ /**
6348
+ * Check if the user has an activate, non-expired license on current plugin's install.
6349
+ *
6350
+ * @since 1.0.9
6351
+ *
6352
+ * @return bool
6353
+ */
6354
+ function is_paying() {
6355
+ $this->_logger->entrance();
6356
+
6357
+ if ( ! $this->is_registered() ) {
6358
+ return false;
6359
+ }
6360
+
6361
+ if ( ! $this->has_paid_plan() ) {
6362
+ return false;
6363
+ }
6364
+
6365
+ return (
6366
+ ! $this->is_trial() &&
6367
+ 'free' !== $this->_site->plan->name &&
6368
+ $this->has_active_valid_license()
6369
+ );
6370
+ }
6371
+
6372
+ /**
6373
+ * @author Vova Feldman (@svovaf)
6374
+ * @since 1.0.4
6375
+ *
6376
+ * @return bool
6377
+ */
6378
+ function is_free_plan() {
6379
+ if ( ! $this->is_registered() ) {
6380
+ return true;
6381
+ }
6382
+
6383
+ if ( ! $this->has_paid_plan() ) {
6384
+ return true;
6385
+ }
6386
+
6387
+ return (
6388
+ 'free' === $this->_site->plan->name ||
6389
+ ! $this->has_features_enabled_license()
6390
+ );
6391
+ }
6392
+
6393
+ /**
6394
+ * @author Vova Feldman (@svovaf)
6395
+ * @since 1.0.5
6396
+ *
6397
+ * @return bool
6398
+ */
6399
+ function _has_premium_license() {
6400
+ $this->_logger->entrance();
6401
+
6402
+ $premium_license = $this->_get_available_premium_license();
6403
+
6404
+ return ( false !== $premium_license );
6405
+ }
6406
+
6407
+ /**
6408
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
6409
+ *
6410
+ * @author Vova Feldman (@svovaf)
6411
+ * @since 1.1.7.3
6412
+ *
6413
+ * @return bool
6414
+ */
6415
+ private function has_any_license() {
6416
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
6417
+ }
6418
+
6419
+ /**
6420
+ * @author Vova Feldman (@svovaf)
6421
+ * @since 1.0.5
6422
+ *
6423
+ * @return FS_Plugin_License|false
6424
+ */
6425
+ function _get_available_premium_license() {
6426
+ $this->_logger->entrance();
6427
+
6428
+ if ( ! $this->has_paid_plan() ) {
6429
+ return false;
6430
+ }
6431
+
6432
+ if ( is_array( $this->_licenses ) ) {
6433
+ foreach ( $this->_licenses as $license ) {
6434
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
6435
+ return $license;
6436
+ }
6437
+ }
6438
+ }
6439
+
6440
+ return false;
6441
+ }
6442
+
6443
+ /**
6444
+ * Sync local plugin plans with remote server.
6445
+ *
6446
+ * @author Vova Feldman (@svovaf)
6447
+ * @since 1.0.5
6448
+ *
6449
+ * @return FS_Plugin_Plan[]|object
6450
+ */
6451
+ function _sync_plans() {
6452
+ $plans = $this->_fetch_plugin_plans();
6453
+
6454
+ if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
6455
+ $this->_plans = $plans;
6456
+ $this->_store_plans();
6457
+ }
6458
+
6459
+ $this->do_action( 'after_plans_sync', $plans );
6460
+
6461
+ return $this->_plans;
6462
+ }
6463
+
6464
+ /**
6465
+ * @author Vova Feldman (@svovaf)
6466
+ * @since 1.0.5
6467
+ *
6468
+ * @param number $id
6469
+ *
6470
+ * @return FS_Plugin_Plan|false
6471
+ */
6472
+ function _get_plan_by_id( $id ) {
6473
+ $this->_logger->entrance();
6474
+
6475
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
6476
+ $this->_sync_plans();
6477
+ }
6478
+
6479
+ foreach ( $this->_plans as $plan ) {
6480
+ if ( $id == $plan->id ) {
6481
+ return $plan;
6482
+ }
6483
+ }
6484
+
6485
+ return false;
6486
+ }
6487
+
6488
+ /**
6489
+ * @author Vova Feldman (@svovaf)
6490
+ * @since 1.1.8.1
6491
+ *
6492
+ * @param string $name
6493
+ *
6494
+ * @return FS_Plugin_Plan|false
6495
+ */
6496
+ private function get_plan_by_name( $name ) {
6497
+ $this->_logger->entrance();
6498
+
6499
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
6500
+ $this->_sync_plans();
6501
+ }
6502
+
6503
+ foreach ( $this->_plans as $plan ) {
6504
+ if ( $name == $plan->name ) {
6505
+ return $plan;
6506
+ }
6507
+ }
6508
+
6509
+ return false;
6510
+ }
6511
+
6512
+ /**
6513
+ * Sync local plugin plans with remote server.
6514
+ *
6515
+ * @author Vova Feldman (@svovaf)
6516
+ * @since 1.0.6
6517
+ *
6518
+ * @param number|bool $site_license_id
6519
+ *
6520
+ * @return FS_Plugin_License[]|object
6521
+ */
6522
+ function _sync_licenses( $site_license_id = false ) {
6523
+ $licenses = $this->_fetch_licenses( false, $site_license_id );
6524
+
6525
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
6526
+ $this->_licenses = $licenses;
6527
+ $this->_store_licenses();
6528
+ }
6529
+
6530
+ // Update current license.
6531
+ if ( is_object( $this->_license ) ) {
6532
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
6533
+ }
6534
+
6535
+ return $this->_licenses;
6536
+ }
6537
+
6538
+ /**
6539
+ * @author Vova Feldman (@svovaf)
6540
+ * @since 1.0.5
6541
+ *
6542
+ * @param number $id
6543
+ *
6544
+ * @return FS_Plugin_License|false
6545
+ */
6546
+ function _get_license_by_id( $id ) {
6547
+ $this->_logger->entrance();
6548
+
6549
+ if ( ! is_numeric( $id ) ) {
6550
+ return false;
6551
+ }
6552
+
6553
+ if ( ! $this->has_any_license() ) {
6554
+ $this->_sync_licenses();
6555
+ }
6556
+
6557
+ foreach ( $this->_licenses as $license ) {
6558
+ if ( $id == $license->id ) {
6559
+ return $license;
6560
+ }
6561
+ }
6562
+
6563
+ return false;
6564
+ }
6565
+
6566
+ /**
6567
+ * Sync site's license with user licenses.
6568
+ *
6569
+ * @author Vova Feldman (@svovaf)
6570
+ * @since 1.0.6
6571
+ *
6572
+ * @param FS_Plugin_License|null $new_license
6573
+ */
6574
+ function _update_site_license( $new_license ) {
6575
+ $this->_logger->entrance();
6576
+
6577
+ $this->_license = $new_license;
6578
+
6579
+ if ( ! is_object( $new_license ) ) {
6580
+ $this->_site->license_id = null;
6581
+ $this->_sync_site_subscription( null );
6582
+
6583
+ return;
6584
+ }
6585
+
6586
+ $this->_site->license_id = $this->_license->id;
6587
+
6588
+ if ( ! is_array( $this->_licenses ) ) {
6589
+ $this->_licenses = array();
6590
+ }
6591
+
6592
+ $is_license_found = false;
6593
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
6594
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
6595
+ $this->_licenses[ $i ] = $new_license;
6596
+
6597
+ $is_license_found = true;
6598
+ break;
6599
+ }
6600
+ }
6601
+
6602
+ // If new license just append.
6603
+ if ( ! $is_license_found ) {
6604
+ $this->_licenses[] = $new_license;
6605
+ }
6606
+
6607
+ $this->_sync_site_subscription( $new_license );
6608
+ }
6609
+
6610
+ /**
6611
+ * Sync site's subscription.
6612
+ *
6613
+ * @author Vova Feldman (@svovaf)
6614
+ * @since 1.0.9
6615
+ *
6616
+ * @param FS_Plugin_License|null $license
6617
+ *
6618
+ * @return bool|\FS_Subscription
6619
+ */
6620
+ private function _sync_site_subscription( $license ) {
6621
+ if ( ! is_object( $license ) ) {
6622
+ unset( $this->_storage->subscription );
6623
+
6624
+ return false;
6625
+ }
6626
+
6627
+ // Load subscription details if not lifetime.
6628
+ $subscription = $license->is_lifetime() ?
6629
+ false :
6630
+ $this->_fetch_site_license_subscription();
6631
+
6632
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
6633
+ $this->_storage->subscription = $subscription;
6634
+ } else {
6635
+ unset( $this->_storage->subscription );
6636
+ }
6637
+
6638
+ return $subscription;
6639
+ }
6640
+
6641
+ /**
6642
+ * @author Vova Feldman (@svovaf)
6643
+ * @since 1.0.6
6644
+ *
6645
+ * @return bool|\FS_Plugin_License
6646
+ */
6647
+ function _get_license() {
6648
+ return $this->_license;
6649
+ }
6650
+
6651
+ /**
6652
+ * @return bool|\FS_Subscription
6653
+ */
6654
+ function _get_subscription() {
6655
+ return isset( $this->_storage->subscription ) ?
6656
+ $this->_storage->subscription :
6657
+ false;
6658
+ }
6659
+
6660
+ /**
6661
+ * @author Vova Feldman (@svovaf)
6662
+ * @since 1.0.2
6663
+ *
6664
+ * @param string $plan Plan name
6665
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
6666
+ *
6667
+ * @return bool
6668
+ */
6669
+ function is_plan( $plan, $exact = false ) {
6670
+ $this->_logger->entrance();
6671
+
6672
+ if ( ! $this->is_registered() ) {
6673
+ return false;
6674
+ }
6675
+
6676
+ $plan = strtolower( $plan );
6677
+
6678
+ if ( $this->_site->plan->name === $plan ) // Exact plan.
6679
+ {
6680
+ return true;
6681
+ } else if ( $exact ) // Required exact, but plans are different.
6682
+ {
6683
+ return false;
6684
+ }
6685
+
6686
+ $current_plan_order = - 1;
6687
+ $required_plan_order = - 1;
6688
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6689
+ if ( $plan === $this->_plans[ $i ]->name ) {
6690
+ $required_plan_order = $i;
6691
+ } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
6692
+ $current_plan_order = $i;
6693
+ }
6694
+ }
6695
+
6696
+ return ( $current_plan_order > $required_plan_order );
6697
+ }
6698
+
6699
+ /**
6700
+ * Check if module has only one plan.
6701
+ *
6702
+ * @author Vova Feldman (@svovaf)
6703
+ * @since 1.2.1.7
6704
+ *
6705
+ * @return bool
6706
+ */
6707
+ function is_single_plan() {
6708
+ $this->_logger->entrance();
6709
+
6710
+ if ( ! $this->is_registered() ||
6711
+ ! is_array( $this->_plans ) ||
6712
+ 0 === count( $this->_plans )
6713
+ ) {
6714
+ return true;
6715
+ }
6716
+
6717
+ return ( 1 === count( $this->_plans ) );
6718
+ }
6719
+
6720
+ /**
6721
+ * Check if plan based on trial. If not in trial mode, should return false.
6722
+ *
6723
+ * @since 1.0.9
6724
+ *
6725
+ * @param string $plan Plan name
6726
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
6727
+ *
6728
+ * @return bool
6729
+ */
6730
+ function is_trial_plan( $plan, $exact = false ) {
6731
+ $this->_logger->entrance();
6732
+
6733
+ if ( ! $this->is_registered() ) {
6734
+ return false;
6735
+ }
6736
+
6737
+ if ( ! $this->is_trial() ) {
6738
+ return false;
6739
+ }
6740
+
6741
+ if ( ! isset( $this->_storage->trial_plan ) ) {
6742
+ // Store trial plan information.
6743
+ $this->_enrich_site_trial_plan( true );
6744
+ }
6745
+
6746
+ if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
6747
+ {
6748
+ return true;
6749
+ } else if ( $exact ) // Required exact, but plans are different.
6750
+ {
6751
+ return false;
6752
+ }
6753
+
6754
+ $current_plan_order = - 1;
6755
+ $required_plan_order = - 1;
6756
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6757
+ if ( $plan === $this->_plans[ $i ]->name ) {
6758
+ $required_plan_order = $i;
6759
+ } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
6760
+ $current_plan_order = $i;
6761
+ }
6762
+ }
6763
+
6764
+ return ( $current_plan_order > $required_plan_order );
6765
+ }
6766
+
6767
+ /**
6768
+ * Check if plugin has any paid plans.
6769
+ *
6770
+ * @author Vova Feldman (@svovaf)
6771
+ * @since 1.0.7
6772
+ *
6773
+ * @return bool
6774
+ */
6775
+ function has_paid_plan() {
6776
+ return $this->_has_paid_plans ||
6777
+ FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
6778
+ }
6779
+
6780
+ /**
6781
+ * Check if plugin has any plan with a trail.
6782
+ *
6783
+ * @author Vova Feldman (@svovaf)
6784
+ * @since 1.0.9
6785
+ *
6786
+ * @return bool
6787
+ */
6788
+ function has_trial_plan() {
6789
+ if ( ! $this->is_registered() ) {
6790
+ /**
6791
+ * @author Vova Feldman(@svovaf)
6792
+ * @since 1.2.1.5
6793
+ *
6794
+ * Allow setting a trial from the SDK without calling the API.
6795
+ * But, if the user did opt-in, continue using the real data from the API.
6796
+ */
6797
+ if ( $this->_trial_days >= 0 ) {
6798
+ return true;
6799
+ }
6800
+
6801
+ return false;
6802
+ }
6803
+
6804
+ return $this->_storage->get( 'has_trial_plan', false );
6805
+ }
6806
+
6807
+ /**
6808
+ * Check if plugin has any free plan, or is it premium only.
6809
+ *
6810
+ * Note: If no plans configured, assume plugin is free.
6811
+ *
6812
+ * @author Vova Feldman (@svovaf)
6813
+ * @since 1.0.7
6814
+ *
6815
+ * @return bool
6816
+ */
6817
+ function has_free_plan() {
6818
+ return ! $this->is_only_premium();
6819
+ }
6820
+
6821
+ /**
6822
+ * Displays a license activation dialog box when the user clicks on the "Activate License"
6823
+ * or "Change License" link on the plugins
6824
+ * page.
6825
+ *
6826
+ * @author Leo Fajardo (@leorw)
6827
+ * @since 1.1.9
6828
+ */
6829
+ function _add_license_activation_dialog_box() {
6830
+ $vars = array(
6831
+ 'id' => $this->_module_id,
6832
+ );
6833
+
6834
+ fs_require_template( 'forms/license-activation.php', $vars );
6835
+ fs_require_template( 'forms/resend-key.php', $vars );
6836
+ }
6837
+
6838
+ /**
6839
+ * Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
6840
+ * page.
6841
+ *
6842
+ * @author Leo Fajardo (@leorw)
6843
+ * @since 1.2.1.5
6844
+ */
6845
+ function _add_optout_dialog() {
6846
+ if ( $this->is_theme() ) {
6847
+ $vars = null;
6848
+ fs_require_once_template( '/js/jquery.content-change.php', $vars );
6849
+ }
6850
+
6851
+ $vars = array( 'id' => $this->_module_id );
6852
+ fs_require_template( 'forms/optout.php', $vars );
6853
+ }
6854
+
6855
+ /**
6856
+ * Prepare page to include all required UI and logic for the license activation dialog.
6857
+ *
6858
+ * @author Vova Feldman (@svovaf)
6859
+ * @since 1.2.0
6860
+ */
6861
+ function _add_license_activation() {
6862
+ if ( ! $this->is_user_admin() ) {
6863
+ // Only admins can activate a license.
6864
+ return;
6865
+ }
6866
+
6867
+ if ( ! $this->has_paid_plan() ) {
6868
+ // Module doesn't have any paid plans.
6869
+ return;
6870
+ }
6871
+
6872
+ if ( ! $this->is_premium() ) {
6873
+ // Only add license activation logic to the premium version.
6874
+ return;
6875
+ }
6876
+
6877
+ // Add license activation link and AJAX request handler.
6878
+ if ( self::is_plugins_page() ) {
6879
+ /**
6880
+ * @since 1.2.0 Add license action link only on plugins page.
6881
+ */
6882
+ $this->_add_license_action_link();
6883
+ }
6884
+
6885
+ // Add license activation AJAX callback.
6886
+ $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
6887
+
6888
+ // Add resend license AJAX callback.
6889
+ $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
6890
+ }
6891
+
6892
+ /**
6893
+ * @author Leo Fajardo (@leorw)
6894
+ * @since 1.1.9
6895
+ */
6896
+ function _activate_license_ajax_action() {
6897
+ $this->_logger->entrance();
6898
+
6899
+ $this->check_ajax_referer( 'activate_license' );
6900
+
6901
+ $license_key = trim( fs_request_get( 'license_key' ) );
6902
+
6903
+ if ( empty( $license_key ) ) {
6904
+ exit;
6905
+ }
6906
+
6907
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
6908
+ $fs = ( $plugin_id == $this->_module_id ) ?
6909
+ $this :
6910
+ $this->get_addon_instance( $plugin_id );
6911
+
6912
+ $error = false;
6913
+ $next_page = false;
6914
+
6915
+ if ( $fs->is_registered() ) {
6916
+ $api = $fs->get_api_site_scope();
6917
+ $install = $api->call( '/', 'put', array(
6918
+ 'license_key' => $fs->apply_filters( 'license_key', $license_key )
6919
+ ) );
6920
+
6921
+ if ( isset( $install->error ) ) {
6922
+ $error = $install->error->message;
6923
+ } else {
6924
+ $parent_fs = $fs->is_addon() ?
6925
+ $fs->get_parent_instance() :
6926
+ $fs;
6927
+
6928
+ $next_page = $parent_fs->_get_sync_license_url( $fs->get_id(), true );
6929
+
6930
+ $fs->reconnect_locally();
6931
+ }
6932
+ } else {
6933
+ $next_page = $fs->opt_in( false, false, false, $license_key );
6934
+
6935
+ if ( isset( $next_page->error ) ) {
6936
+ $error = $next_page->error;
6937
+ }
6938
+ }
6939
+
6940
+ $result = array(
6941
+ 'success' => ( false === $error )
6942
+ );
6943
+
6944
+ if ( false !== $error ) {
6945
+ $result['error'] = $error;
6946
+ } else {
6947
+ $result['next_page'] = $next_page;
6948
+ }
6949
+
6950
+ echo json_encode( $result );
6951
+
6952
+ exit;
6953
+ }
6954
+
6955
+ /**
6956
+ * Billing update AJAX callback.
6957
+ *
6958
+ * @author Vova Feldman (@svovaf)
6959
+ * @since 1.2.1.5
6960
+ */
6961
+ function _update_billing_ajax_action() {
6962
+ $this->_logger->entrance();
6963
+
6964
+ $this->check_ajax_referer( 'update_billing' );
6965
+
6966
+ if ( ! $this->is_user_admin() ) {
6967
+ // Only for admins.
6968
+ self::shoot_ajax_failure();
6969
+ }
6970
+
6971
+ $billing = fs_request_get( 'billing' );
6972
+
6973
+ $api = $this->get_api_user_scope();
6974
+ $result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
6975
+ 'plugin_id' => $this->get_parent_id(),
6976
+ ) ) );
6977
+
6978
+ if ( ! $this->is_api_result_entity( $result ) ) {
6979
+ self::shoot_ajax_failure();
6980
+ }
6981
+
6982
+ // Purge cached billing.
6983
+ $this->get_api_user_scope()->purge_cache( 'billing.json' );
6984
+
6985
+ self::shoot_ajax_success();
6986
+ }
6987
+
6988
+ /**
6989
+ * Trial start for anonymous users (AJAX callback).
6990
+ *
6991
+ * @author Vova Feldman (@svovaf)
6992
+ * @since 1.2.1.5
6993
+ */
6994
+ function _start_trial_ajax_action() {
6995
+ $this->_logger->entrance();
6996
+
6997
+ $this->check_ajax_referer( 'start_trial' );
6998
+
6999
+ if ( ! $this->is_user_admin() ) {
7000
+ // Only for admins.
7001
+ self::shoot_ajax_failure();
7002
+ }
7003
+
7004
+ $trial_data = fs_request_get( 'trial' );
7005
+
7006
+ $next_page = $this->opt_in(
7007
+ false,
7008
+ false,
7009
+ false,
7010
+ false,
7011
+ false,
7012
+ $trial_data['plan_id']
7013
+ );
7014
+
7015
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
7016
+ self::shoot_ajax_failure(
7017
+ isset( $next_page->error ) ?
7018
+ $next_page->error->message :
7019
+ var_export( $next_page, true )
7020
+ );
7021
+ }
7022
+
7023
+ $this->shoot_ajax_success( array(
7024
+ 'next_page' => $next_page,
7025
+ ) );
7026
+ }
7027
+
7028
+ /**
7029
+ * @author Leo Fajardo (@leorw)
7030
+ * @since 1.2.0
7031
+ */
7032
+ function _resend_license_key_ajax_action() {
7033
+ $this->_logger->entrance();
7034
+
7035
+ $this->check_ajax_referer( 'resend_license_key' );
7036
+
7037
+ $email_address = sanitize_email( trim( fs_request_get( 'email', '', 'post' ) ) );
7038
+
7039
+ if ( empty( $email_address ) ) {
7040
+ exit;
7041
+ }
7042
+
7043
+ $error = false;
7044
+
7045
+ $api = $this->get_api_plugin_scope();
7046
+ $result = $api->call( '/licenses/resend.json', 'post',
7047
+ array(
7048
+ 'email' => $email_address,
7049
+ 'url' => home_url(),
7050
+ )
7051
+ );
7052
+
7053
+ if ( is_object( $result ) && isset( $result->error ) ) {
7054
+ $error = $result->error;
7055
+
7056
+ if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
7057
+ $error = $this->get_text( 'email-not-found' );
7058
+ } else if ( 'no_license' === $error->code ) {
7059
+ $error = $this->get_text( 'no-active-licenses' );
7060
+ } else {
7061
+ $error = $error->message;
7062
+ }
7063
+ }
7064
+
7065
+ $licenses = array(
7066
+ 'success' => ( false === $error )
7067
+ );
7068
+
7069
+ if ( false !== $error ) {
7070
+ $licenses['error'] = sprintf( '%s... %s', $this->get_text( 'oops' ), strtolower( $error ) );
7071
+ }
7072
+
7073
+ echo json_encode( $licenses );
7074
+
7075
+ exit;
7076
+ }
7077
+
7078
+ /**
7079
+ * @author Vova Feldman (@svovaf)
7080
+ * @since 1.2.1.8
7081
+ *
7082
+ * @var string
7083
+ */
7084
+ private static $_pagenow;
7085
+
7086
+ /**
7087
+ * Get current page or the referer if executing a WP AJAX request.
7088
+ *
7089
+ * @author Vova Feldman (@svovaf)
7090
+ * @since 1.2.1.8
7091
+ *
7092
+ * @return string
7093
+ */
7094
+ static function get_current_page() {
7095
+ if ( ! isset( self::$_pagenow ) ) {
7096
+ global $pagenow;
7097
+
7098
+ self::$_pagenow = $pagenow;
7099
+
7100
+ if ( self::is_ajax() &&
7101
+ 'admin-ajax.php' === $pagenow
7102
+ ) {
7103
+ $referer = wp_get_raw_referer();
7104
+
7105
+ if ( is_string( $referer ) ) {
7106
+ $parts = explode( '?', $referer );
7107
+
7108
+ self::$_pagenow = basename( $parts[0] );
7109
+ }
7110
+ }
7111
+ }
7112
+
7113
+ return self::$_pagenow;
7114
+ }
7115
+
7116
+ /**
7117
+ * Helper method to check if user in the plugins page.
7118
+ *
7119
+ * @author Vova Feldman (@svovaf)
7120
+ * @since 1.2.1.5
7121
+ *
7122
+ * @return bool
7123
+ */
7124
+ static function is_plugins_page() {
7125
+ return ( 'plugins.php' === self::get_current_page() );
7126
+ }
7127
+
7128
+ /**
7129
+ * Helper method to check if user in the themes page.
7130
+ *
7131
+ * @author Vova Feldman (@svovaf)
7132
+ * @since 1.2.2.6
7133
+ *
7134
+ * @return bool
7135
+ */
7136
+ static function is_themes_page() {
7137
+ return ( 'themes.php' === self::get_current_page() );
7138
+ }
7139
+
7140
+ #----------------------------------------------------------------------------------
7141
+ #region URL Generators
7142
+ #----------------------------------------------------------------------------------
7143
+
7144
+ /**
7145
+ * Alias to pricing_url().
7146
+ *
7147
+ * @author Vova Feldman (@svovaf)
7148
+ * @since 1.0.2
7149
+ *
7150
+ * @uses pricing_url()
7151
+ *
7152
+ * @param string $period Billing cycle
7153
+ * @param bool $is_trial
7154
+ *
7155
+ * @return string
7156
+ */
7157
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
7158
+ return $this->pricing_url( $period, $is_trial );
7159
+ }
7160
+
7161
+ /**
7162
+ * @author Vova Feldman (@svovaf)
7163
+ * @since 1.0.9
7164
+ *
7165
+ * @uses get_upgrade_url()
7166
+ *
7167
+ * @return string
7168
+ */
7169
+ function get_trial_url() {
7170
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
7171
+ }
7172
+
7173
+ /**
7174
+ * Plugin's pricing URL.
7175
+ *
7176
+ * @author Vova Feldman (@svovaf)
7177
+ * @since 1.0.4
7178
+ *
7179
+ * @param string $billing_cycle Billing cycle
7180
+ *
7181
+ * @param bool $is_trial
7182
+ *
7183
+ * @return string
7184
+ */
7185
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
7186
+ $this->_logger->entrance();
7187
+
7188
+ $params = array(
7189
+ 'billing_cycle' => $billing_cycle
7190
+ );
7191
+
7192
+ if ( $is_trial ) {
7193
+ $params['trial'] = 'true';
7194
+ }
7195
+
7196
+ return $this->_get_admin_page_url( 'pricing', $params );
7197
+ }
7198
+
7199
+ /**
7200
+ * Checkout page URL.
7201
+ *
7202
+ * @author Vova Feldman (@svovaf)
7203
+ * @since 1.0.6
7204
+ *
7205
+ * @param string $billing_cycle Billing cycle
7206
+ * @param bool $is_trial
7207
+ * @param array $extra (optional) Extra parameters, override other query params.
7208
+ *
7209
+ * @return string
7210
+ */
7211
+ function checkout_url(
7212
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
7213
+ $is_trial = false,
7214
+ $extra = array()
7215
+ ) {
7216
+ $this->_logger->entrance();
7217
+
7218
+ $params = array(
7219
+ 'checkout' => 'true',
7220
+ 'billing_cycle' => $billing_cycle,
7221
+ );
7222
+
7223
+ if ( $is_trial ) {
7224
+ $params['trial'] = 'true';
7225
+ }
7226
+
7227
+ /**
7228
+ * Params in extra override other params.
7229
+ */
7230
+ $params = array_merge( $params, $extra );
7231
+
7232
+ return $this->_get_admin_page_url( 'pricing', $params );
7233
+ }
7234
+
7235
+ /**
7236
+ * Add-on checkout URL.
7237
+ *
7238
+ * @author Vova Feldman (@svovaf)
7239
+ * @since 1.1.7
7240
+ *
7241
+ * @param number $addon_id
7242
+ * @param number $pricing_id
7243
+ * @param string $billing_cycle
7244
+ * @param bool $is_trial
7245
+ *
7246
+ * @return string
7247
+ */
7248
+ function addon_checkout_url(
7249
+ $addon_id,
7250
+ $pricing_id,
7251
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
7252
+ $is_trial = false
7253
+ ) {
7254
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
7255
+ 'plugin_id' => $addon_id,
7256
+ 'pricing_id' => $pricing_id,
7257
+ ) );
7258
+ }
7259
+
7260
+ #endregion
7261
+
7262
+ #endregion ------------------------------------------------------------------
7263
+
7264
+ /**
7265
+ * Check if plugin has any add-ons.
7266
+ *
7267
+ * @author Vova Feldman (@svovaf)
7268
+ * @since 1.0.5
7269
+ *
7270
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
7271
+ *
7272
+ * @return bool
7273
+ */
7274
+ function has_addons() {
7275
+ $this->_logger->entrance();
7276
+
7277
+ return $this->_has_addons;
7278
+ }
7279
+
7280
+ /**
7281
+ * Check if plugin can work in anonymous mode.
7282
+ *
7283
+ * @author Vova Feldman (@svovaf)
7284
+ * @since 1.0.9
7285
+ *
7286
+ * @return bool
7287
+ *
7288
+ * @deprecated Please use is_enable_anonymous() instead
7289
+ */
7290
+ function enable_anonymous() {
7291
+ return $this->_enable_anonymous;
7292
+ }
7293
+
7294
+ /**
7295
+ * Check if plugin can work in anonymous mode.
7296
+ *
7297
+ * @author Vova Feldman (@svovaf)
7298
+ * @since 1.1.9
7299
+ *
7300
+ * @return bool
7301
+ */
7302
+ function is_enable_anonymous() {
7303
+ return $this->_enable_anonymous;
7304
+ }
7305
+
7306
+ /**
7307
+ * Check if plugin is premium only (no free plans).
7308
+ *
7309
+ * @author Vova Feldman (@svovaf)
7310
+ * @since 1.1.9
7311
+ *
7312
+ * @return bool
7313
+ */
7314
+ function is_only_premium() {
7315
+ return $this->_is_premium_only;
7316
+ }
7317
+
7318
+ /**
7319
+ * Checks if the plugin's type is "plugin". The other type is "theme".
7320
+ *
7321
+ * @author Leo Fajardo (@leorw)
7322
+ * @since 1.2.2
7323
+ *
7324
+ * @return bool
7325
+ */
7326
+ function is_plugin() {
7327
+ return ( WP_FS__MODULE_TYPE_PLUGIN === $this->_module_type );
7328
+ }
7329
+
7330
+ /**
7331
+ * @author Leo Fajardo (@leorw)
7332
+ * @since 1.2.2
7333
+ *
7334
+ * @return string
7335
+ */
7336
+ function get_module_type() {
7337
+ if ( ! isset( $this->_module_type ) ) {
7338
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
7339
+ $this->_module_type = $id_slug_type_path_map[ $this->_module_id ]['type'];
7340
+ }
7341
+
7342
+ return $this->_module_type;
7343
+ }
7344
+
7345
+ /**
7346
+ * @author Leo Fajardo (@leorw)
7347
+ * @since 1.2.2
7348
+ *
7349
+ * @return string
7350
+ */
7351
+ function get_plugin_main_file_path() {
7352
+ return $this->_plugin_main_file_path;
7353
+ }
7354
+
7355
+ /**
7356
+ * Check if module has a premium code version.
7357
+ *
7358
+ * Serviceware module might be freemium without any
7359
+ * premium code version, where the paid features
7360
+ * are all part of the service.
7361
+ *
7362
+ * @author Vova Feldman (@svovaf)
7363
+ * @since 1.2.1.6
7364
+ *
7365
+ * @return bool
7366
+ */
7367
+ function has_premium_version() {
7368
+ return $this->_has_premium_version;
7369
+ }
7370
+
7371
+ /**
7372
+ * Check if feature supported with current site's plan.
7373
+ *
7374
+ * @author Vova Feldman (@svovaf)
7375
+ * @since 1.0.1
7376
+ *
7377
+ * @todo IMPLEMENT
7378
+ *
7379
+ * @param number $feature_id
7380
+ *
7381
+ * @throws Exception
7382
+ */
7383
+ function is_feature_supported( $feature_id ) {
7384
+ throw new Exception( 'not implemented' );
7385
+ }
7386
+
7387
+ /**
7388
+ * @author Vova Feldman (@svovaf)
7389
+ * @since 1.0.1
7390
+ *
7391
+ * @return bool Is running in SSL/HTTPS
7392
+ */
7393
+ function is_ssl() {
7394
+ return WP_FS__IS_HTTPS;
7395
+ }
7396
+
7397
+ /**
7398
+ * @author Vova Feldman (@svovaf)
7399
+ * @since 1.0.9
7400
+ *
7401
+ * @return bool Is running in AJAX call.
7402
+ *
7403
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
7404
+ */
7405
+ static function is_ajax() {
7406
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
7407
+ }
7408
+
7409
+ /**
7410
+ * Check if it's an AJAX call targeted for the current module.
7411
+ *
7412
+ * @author Vova Feldman (@svovaf)
7413
+ * @since 1.2.0
7414
+ *
7415
+ * @param array|string $actions Collection of AJAX actions.
7416
+ *
7417
+ * @return bool
7418
+ */
7419
+ function is_ajax_action( $actions ) {
7420
+ // Verify it's an ajax call.
7421
+ if ( ! self::is_ajax() ) {
7422
+ return false;
7423
+ }
7424
+
7425
+ // Verify the call is relevant for the plugin.
7426
+ if ( $this->_module_id != fs_request_get( 'module_id' ) ) {
7427
+ return false;
7428
+ }
7429
+
7430
+ // Verify it's one of the specified actions.
7431
+ if ( is_string( $actions ) ) {
7432
+ $actions = explode( ',', $actions );
7433
+ }
7434
+
7435
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
7436
+ $ajax_action = fs_request_get( 'action' );
7437
+
7438
+ foreach ( $actions as $action ) {
7439
+ if ( $ajax_action === $this->get_action_tag( $action ) ) {
7440
+ return true;
7441
+ }
7442
+ }
7443
+ }
7444
+
7445
+ return false;
7446
+ }
7447
+
7448
+ /**
7449
+ * Check if it's an AJAX call targeted for current request.
7450
+ *
7451
+ * @author Vova Feldman (@svovaf)
7452
+ * @since 1.2.0
7453
+ *
7454
+ * @param array|string $actions Collection of AJAX actions.
7455
+ * @param number|null $module_id
7456
+ *
7457
+ * @return bool
7458
+ */
7459
+ static function is_ajax_action_static( $actions, $module_id = null ) {
7460
+ // Verify it's an ajax call.
7461
+ if ( ! self::is_ajax() ) {
7462
+ return false;
7463
+ }
7464
+
7465
+
7466
+ if ( ! empty( $module_id ) ) {
7467
+ // Verify the call is relevant for the plugin.
7468
+ if ( $module_id != fs_request_get( 'module_id' ) ) {
7469
+ return false;
7470
+ }
7471
+ }
7472
+
7473
+ // Verify it's one of the specified actions.
7474
+ if ( is_string( $actions ) ) {
7475
+ $actions = explode( ',', $actions );
7476
+ }
7477
+
7478
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
7479
+ $ajax_action = fs_request_get( 'action' );
7480
+
7481
+ foreach ( $actions as $action ) {
7482
+ if ( $ajax_action === self::get_ajax_action_static( $action, $module_id ) ) {
7483
+ return true;
7484
+ }
7485
+ }
7486
+ }
7487
+
7488
+ return false;
7489
+ }
7490
+
7491
+ /**
7492
+ * @author Vova Feldman (@svovaf)
7493
+ * @since 1.1.7
7494
+ *
7495
+ * @return bool
7496
+ */
7497
+ static function is_cron() {
7498
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
7499
+ }
7500
+
7501
+ /**
7502
+ * Check if a real user is visiting the admin dashboard.
7503
+ *
7504
+ * @author Vova Feldman (@svovaf)
7505
+ * @since 1.1.7
7506
+ *
7507
+ * @return bool
7508
+ */
7509
+ function is_user_in_admin() {
7510
+ return is_admin() && ! self::is_ajax() && ! self::is_cron();
7511
+ }
7512
+
7513
+ /**
7514
+ * Check if a real user is in the customizer view.
7515
+ *
7516
+ * @author Vova Feldman (@svovaf)
7517
+ * @since 1.2.2.7
7518
+ *
7519
+ * @return bool
7520
+ */
7521
+ static function is_customizer() {
7522
+ return is_customize_preview();
7523
+ }
7524
+
7525
+ /**
7526
+ * Check if running in HTTPS and if site's plan matching the specified plan.
7527
+ *
7528
+ * @param string $plan
7529
+ * @param bool $exact
7530
+ *
7531
+ * @return bool
7532
+ */
7533
+ function is_ssl_and_plan( $plan, $exact = false ) {
7534
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
7535
+ }
7536
+
7537
+ /**
7538
+ * Construct plugin's settings page URL.
7539
+ *
7540
+ * @author Vova Feldman (@svovaf)
7541
+ * @since 1.0.4
7542
+ *
7543
+ * @param string $page
7544
+ * @param array $params
7545
+ *
7546
+ * @return string
7547
+ */
7548
+ function _get_admin_page_url( $page = '', $params = array() ) {
7549
+ if ( 0 < count( $params ) ) {
7550
+ foreach ( $params as $k => $v ) {
7551
+ $params[ $k ] = urlencode( $v );
7552
+ }
7553
+ }
7554
+
7555
+ $page_param = $this->_menu->get_slug( $page );
7556
+
7557
+ if ( empty( $page ) &&
7558
+ $this->is_theme() &&
7559
+ // Show the opt-in as an overlay for free wp.org themes or themes without any settings page.
7560
+ ( $this->is_free_wp_org_theme() || ! $this->has_settings_menu() ) ) {
7561
+ $params[ $this->get_unique_affix() . '_show_optin' ] = 'true';
7562
+
7563
+ return add_query_arg(
7564
+ $params,
7565
+ admin_url( 'themes.php' )
7566
+ );
7567
+ }
7568
+
7569
+ if ( ! $this->has_settings_menu() ) {
7570
+ if ( ! empty( $page ) ) {
7571
+ // Module doesn't have a setting page, but since the request is for
7572
+ // a specific Freemius page, use the admin.php path.
7573
+ return add_query_arg( array_merge( $params, array(
7574
+ 'page' => $page_param,
7575
+ ) ), admin_url( 'admin.php' ) );
7576
+ } else {
7577
+ if ( $this->is_activation_mode() ) {
7578
+ /**
7579
+ * @author Vova Feldman
7580
+ * @since 1.2.1.6
7581
+ *
7582
+ * If plugin doesn't have a settings page, create one for the opt-in screen.
7583
+ */
7584
+ return add_query_arg( array_merge( $params, array(
7585
+ 'page' => $this->_slug,
7586
+ ) ), admin_url( 'admin.php', 'admin' ) );
7587
+ } else {
7588
+ // Plugin without a settings page.
7589
+ return admin_url( 'plugins.php' );
7590
+ }
7591
+ }
7592
+ }
7593
+
7594
+ // Module has a submenu settings page.
7595
+ if ( ! $this->_menu->is_top_level() ) {
7596
+ $parent_slug = $this->_menu->get_parent_slug();
7597
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
7598
+ $parent_slug :
7599
+ 'admin.php';
7600
+
7601
+ return add_query_arg( array_merge( $params, array(
7602
+ 'page' => $page_param,
7603
+ ) ), admin_url( $menu_file, 'admin' ) );
7604
+ }
7605
+
7606
+ // Module has a top level CPT settings page.
7607
+ if ( $this->_menu->is_cpt() ) {
7608
+ if ( empty( $page ) && $this->is_activation_mode() ) {
7609
+ return add_query_arg( array_merge( $params, array(
7610
+ 'page' => $page_param
7611
+ ) ), admin_url( 'admin.php', 'admin' ) );
7612
+ } else {
7613
+ if ( ! empty( $page ) ) {
7614
+ $params['page'] = $page_param;
7615
+ }
7616
+
7617
+ return add_query_arg(
7618
+ $params,
7619
+ admin_url( $this->_menu->get_raw_slug(), 'admin' )
7620
+ );
7621
+ }
7622
+ }
7623
+
7624
+ // Module has a custom top level settings page.
7625
+ return add_query_arg( array_merge( $params, array(
7626
+ 'page' => $page_param,
7627
+ ) ), admin_url( 'admin.php', 'admin' ) );
7628
+ }
7629
+
7630
+ /**
7631
+ * Check if currently in a specified admin page.
7632
+ *
7633
+ * @author Vova Feldman (@svovaf)
7634
+ * @since 1.2.2.7
7635
+ *
7636
+ * @param string $page
7637
+ *
7638
+ * @return bool
7639
+ */
7640
+ function is_admin_page( $page ) {
7641
+ return ( $this->_menu->get_slug( $page ) === fs_request_get( 'page', '', 'get' ) );
7642
+ }
7643
+
7644
+ /**
7645
+ * Get module's main admin setting page URL.
7646
+ *
7647
+ * @author Vova Feldman (@svovaf)
7648
+ * @since 1.2.2.7
7649
+ *
7650
+ * @return string
7651
+ */
7652
+ function main_menu_url() {
7653
+ return $this->_menu->main_menu_url();
7654
+ }
7655
+
7656
+ /**
7657
+ * Check if currently on the theme's setting page or
7658
+ * on any of the Freemius added pages (via tabs).
7659
+ *
7660
+ * @author Vova Feldman (@svovaf)
7661
+ * @since 1.2.2.7
7662
+ *
7663
+ * @return bool
7664
+ */
7665
+ function is_theme_settings_page() {
7666
+ return fs_starts_with(
7667
+ fs_request_get( 'page', '', 'get' ),
7668
+ $this->_menu->get_slug()
7669
+ );
7670
+ }
7671
+
7672
+ /**
7673
+ * Plugin's account page + sync license URL.
7674
+ *
7675
+ * @author Vova Feldman (@svovaf)
7676
+ * @since 1.1.9.1
7677
+ *
7678
+ * @param bool|number $plugin_id
7679
+ * @param bool $add_action_nonce
7680
+ * @param array $params
7681
+ *
7682
+ * @return string
7683
+ */
7684
+ function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true, $params = array() ) {
7685
+ if ( is_numeric( $plugin_id ) ) {
7686
+ $params['plugin_id'] = $plugin_id;
7687
+ }
7688
+
7689
+ return $this->get_account_url(
7690
+ $this->get_unique_affix() . '_sync_license',
7691
+ $params,
7692
+ $add_action_nonce
7693
+ );
7694
+ }
7695
+
7696
+ /**
7697
+ * Plugin's account URL.
7698
+ *
7699
+ * @author Vova Feldman (@svovaf)
7700
+ * @since 1.0.4
7701
+ *
7702
+ * @param bool|string $action
7703
+ * @param array $params
7704
+ *
7705
+ * @param bool $add_action_nonce
7706
+ *
7707
+ * @return string
7708
+ */
7709
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
7710
+ if ( is_string( $action ) ) {
7711
+ $params['fs_action'] = $action;
7712
+ }
7713
+
7714
+ self::require_pluggable_essentials();
7715
+
7716
+ return ( $add_action_nonce && is_string( $action ) ) ?
7717
+ fs_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
7718
+ $this->_get_admin_page_url( 'account', $params );
7719
+ }
7720
+
7721
+ /**
7722
+ * @author Vova Feldman (@svovaf)
7723
+ * @since 1.2.0
7724
+ *
7725
+ * @param string $tab
7726
+ * @param bool $action
7727
+ * @param array $params
7728
+ * @param bool $add_action_nonce
7729
+ *
7730
+ * @return string
7731
+ *
7732
+ * @uses get_account_url()
7733
+ */
7734
+ function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
7735
+ $params['tab'] = $tab;
7736
+
7737
+ return $this->get_account_url( $action, $params, $add_action_nonce );
7738
+ }
7739
+
7740
+ /**
7741
+ * Plugin's account URL.
7742
+ *
7743
+ * @author Vova Feldman (@svovaf)
7744
+ * @since 1.0.4
7745
+ *
7746
+ * @param bool|string $topic
7747
+ * @param bool|string $message
7748
+ *
7749
+ * @return string
7750
+ */
7751
+ function contact_url( $topic = false, $message = false ) {
7752
+ $params = array();
7753
+ if ( is_string( $topic ) ) {
7754
+ $params['topic'] = $topic;
7755
+ }
7756
+ if ( is_string( $message ) ) {
7757
+ $params['message'] = $message;
7758
+ }
7759
+
7760
+ if ( $this->is_addon() ) {
7761
+ $params['addon_id'] = $this->get_id();
7762
+
7763
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
7764
+ } else {
7765
+ return $this->_get_admin_page_url( 'contact', $params );
7766
+ }
7767
+ }
7768
+
7769
+ /**
7770
+ * Add-on direct info URL.
7771
+ *
7772
+ * @author Vova Feldman (@svovaf)
7773
+ * @since 1.1.0
7774
+ *
7775
+ * @param string $slug
7776
+ *
7777
+ * @return string
7778
+ */
7779
+ function addon_url( $slug ) {
7780
+ return $this->_get_admin_page_url( 'addons', array(
7781
+ 'slug' => $slug
7782
+ ) );
7783
+ }
7784
+
7785
+ /* Logger
7786
+ ------------------------------------------------------------------------------------------------------------------*/
7787
+ /**
7788
+ * @param string $id
7789
+ * @param bool $prefix_slug
7790
+ *
7791
+ * @return FS_Logger
7792
+ */
7793
+ function get_logger( $id = '', $prefix_slug = true ) {
7794
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
7795
+ }
7796
+
7797
+ /**
7798
+ * @param $id
7799
+ * @param bool $load_options
7800
+ * @param bool $prefix_slug
7801
+ *
7802
+ * @return FS_Option_Manager
7803
+ */
7804
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
7805
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
7806
+ }
7807
+
7808
+ /* Security
7809
+ ------------------------------------------------------------------------------------------------------------------*/
7810
+ private static function _encrypt( $str ) {
7811
+ if ( is_null( $str ) ) {
7812
+ return null;
7813
+ }
7814
+
7815
+ /**
7816
+ * The encrypt/decrypt functions are used to protect
7817
+ * the user from messing up with some of the sensitive
7818
+ * data stored for the module as a JSON in the database.
7819
+ *
7820
+ * I used the same suggested hack by the theme review team.
7821
+ * For more details, look at the function `Base64UrlDecode()`
7822
+ * in `./sdk/FreemiusBase.php`.
7823
+ *
7824
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
7825
+ *
7826
+ * @author Vova Feldman (@svovaf)
7827
+ * @since 1.2.2
7828
+ */
7829
+ $fn = 'base64' . '_encode';
7830
+
7831
+ return $fn( $str );
7832
+ }
7833
+
7834
+ static function _decrypt( $str ) {
7835
+ if ( is_null( $str ) ) {
7836
+ return null;
7837
+ }
7838
+
7839
+ /**
7840
+ * The encrypt/decrypt functions are used to protect
7841
+ * the user from messing up with some of the sensitive
7842
+ * data stored for the module as a JSON in the database.
7843
+ *
7844
+ * I used the same suggested hack by the theme review team.
7845
+ * For more details, look at the function `Base64UrlDecode()`
7846
+ * in `./sdk/FreemiusBase.php`.
7847
+ *
7848
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
7849
+ *
7850
+ * @author Vova Feldman (@svovaf)
7851
+ * @since 1.2.2
7852
+ */
7853
+ $fn = 'base64' . '_decode';
7854
+
7855
+ return $fn( $str );
7856
+ }
7857
+
7858
+ /**
7859
+ * @author Vova Feldman (@svovaf)
7860
+ * @since 1.0.5
7861
+ *
7862
+ * @param FS_Entity $entity
7863
+ *
7864
+ * @return FS_Entity Return an encrypted clone entity.
7865
+ */
7866
+ private static function _encrypt_entity( FS_Entity $entity ) {
7867
+ $clone = clone $entity;
7868
+ $props = get_object_vars( $entity );
7869
+
7870
+ foreach ( $props as $key => $val ) {
7871
+ $clone->{$key} = self::_encrypt( $val );
7872
+ }
7873
+
7874
+ return $clone;
7875
+ }
7876
+
7877
+ /**
7878
+ * @author Vova Feldman (@svovaf)
7879
+ * @since 1.0.5
7880
+ *
7881
+ * @param FS_Entity $entity
7882
+ *
7883
+ * @return FS_Entity Return an decrypted clone entity.
7884
+ */
7885
+ private static function decrypt_entity( FS_Entity $entity ) {
7886
+ $clone = clone $entity;
7887
+ $props = get_object_vars( $entity );
7888
+
7889
+ foreach ( $props as $key => $val ) {
7890
+ $clone->{$key} = self::_decrypt( $val );
7891
+ }
7892
+
7893
+ return $clone;
7894
+ }
7895
+
7896
+ /**
7897
+ * Tries to activate account based on POST params.
7898
+ *
7899
+ * @author Vova Feldman (@svovaf)
7900
+ * @since 1.0.2
7901
+ */
7902
+ function _activate_account() {
7903
+ if ( $this->is_registered() ) {
7904
+ // Already activated.
7905
+ return;
7906
+ }
7907
+
7908
+ self::_clean_admin_content_section();
7909
+
7910
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
7911
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
7912
+
7913
+ // Verify matching plugin details.
7914
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
7915
+ return;
7916
+ }
7917
+
7918
+ $user = new FS_User();
7919
+ $user->id = fs_request_get( 'user_id' );
7920
+ $user->public_key = fs_request_get( 'user_public_key' );
7921
+ $user->secret_key = fs_request_get( 'user_secret_key' );
7922
+ $user->email = fs_request_get( 'user_email' );
7923
+ $user->first = fs_request_get( 'user_first' );
7924
+ $user->last = fs_request_get( 'user_last' );
7925
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
7926
+
7927
+ $site = new FS_Site();
7928
+ $site->id = fs_request_get( 'install_id' );
7929
+ $site->public_key = fs_request_get( 'install_public_key' );
7930
+ $site->secret_key = fs_request_get( 'install_secret_key' );
7931
+ $site->plan->id = fs_request_get( 'plan_id' );
7932
+ $site->plan->title = fs_request_get( 'plan_title' );
7933
+ $site->plan->name = fs_request_get( 'plan_name' );
7934
+
7935
+ $plans = array();
7936
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
7937
+ foreach ( $plans_data as $p ) {
7938
+ $plans[] = new FS_Plugin_Plan( $p );
7939
+ }
7940
+
7941
+ $this->_set_account( $user, $site, $plans );
7942
+
7943
+ // Reload the page with the keys.
7944
+ fs_redirect( $this->_get_admin_page_url() );
7945
+ }
7946
+ }
7947
+
7948
+ /**
7949
+ * @author Vova Feldman (@svovaf)
7950
+ * @since 1.0.7
7951
+ *
7952
+ * @param string $email
7953
+ *
7954
+ * @return FS_User|bool
7955
+ */
7956
+ static function _get_user_by_email( $email ) {
7957
+ self::$_static_logger->entrance();
7958
+
7959
+ $email = trim( strtolower( $email ) );
7960
+ $users = self::get_all_users();
7961
+ if ( is_array( $users ) ) {
7962
+ foreach ( $users as $u ) {
7963
+ if ( $email === trim( strtolower( $u->email ) ) ) {
7964
+ return $u;
7965
+ }
7966
+ }
7967
+ }
7968
+
7969
+ return false;
7970
+ }
7971
+
7972
+ #----------------------------------------------------------------------------------
7973
+ #region Account (Loading, Updates & Activation)
7974
+ #----------------------------------------------------------------------------------
7975
+
7976
+ /***
7977
+ * Load account information (user + site).
7978
+ *
7979
+ * @author Vova Feldman (@svovaf)
7980
+ * @since 1.0.1
7981
+ */
7982
+ private function _load_account() {
7983
+ $this->_logger->entrance();
7984
+
7985
+ $this->do_action( 'before_account_load' );
7986
+
7987
+ $sites = self::get_all_sites( $this->_module_type );
7988
+ $users = self::get_all_users();
7989
+ $plans = self::get_all_plans( $this->_module_type );
7990
+ $licenses = self::get_all_licenses( $this->_module_type );
7991
+
7992
+ if ( $this->_logger->is_on() && is_admin() ) {
7993
+ $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
7994
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
7995
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
7996
+ $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
7997
+ }
7998
+
7999
+ $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
8000
+
8001
+ if ( is_object( $site ) &&
8002
+ is_numeric( $site->id ) &&
8003
+ is_numeric( $site->user_id ) &&
8004
+ is_object( $site->plan )
8005
+ ) {
8006
+ // Load site.
8007
+ $this->_site = clone $site;
8008
+ $this->_site->plan = self::decrypt_entity( $this->_site->plan );
8009
+
8010
+ // Load relevant user.
8011
+ $this->_user = clone $users[ $this->_site->user_id ];
8012
+
8013
+ // Load plans.
8014
+ $this->_plans = $plans[ $this->_slug ];
8015
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
8016
+ $this->_sync_plans();
8017
+ } else {
8018
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
8019
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
8020
+ $this->_plans[ $i ] = self::decrypt_entity( $this->_plans[ $i ] );
8021
+ } else {
8022
+ unset( $this->_plans[ $i ] );
8023
+ }
8024
+ }
8025
+ }
8026
+
8027
+ // Load licenses.
8028
+ $this->_licenses = array();
8029
+ if ( is_array( $licenses ) &&
8030
+ isset( $licenses[ $this->_slug ] ) &&
8031
+ isset( $licenses[ $this->_slug ][ $this->_user->id ] )
8032
+ ) {
8033
+ $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
8034
+ }
8035
+
8036
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
8037
+
8038
+ if ( $this->_site->version != $this->get_plugin_version() ) {
8039
+ // If stored install version is different than current installed plugin version,
8040
+ // then update plugin version event.
8041
+ $this->update_plugin_version_event();
8042
+ }
8043
+ }
8044
+
8045
+ $this->_register_account_hooks();
8046
+ }
8047
+
8048
+ /**
8049
+ * @author Vova Feldman (@svovaf)
8050
+ * @since 1.0.1
8051
+ *
8052
+ * @param FS_User $user
8053
+ * @param FS_Site $site
8054
+ * @param bool|array $plans
8055
+ */
8056
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
8057
+ $site->slug = $this->_slug;
8058
+ $site->user_id = $user->id;
8059
+
8060
+ $this->_site = $site;
8061
+ $this->_user = $user;
8062
+ if ( false !== $plans ) {
8063
+ $this->_plans = $plans;
8064
+ }
8065
+
8066
+ $this->send_install_update();
8067
+
8068
+ $this->_store_account();
8069
+
8070
+ }
8071
+
8072
+ /**
8073
+ * @author Vova Feldman (@svovaf)
8074
+ * @since 1.1.7.4
8075
+ *
8076
+ * @param array $override_with
8077
+ *
8078
+ * @return array
8079
+ */
8080
+ function get_opt_in_params( $override_with = array() ) {
8081
+ $this->_logger->entrance();
8082
+
8083
+ $current_user = self::_get_current_wp_user();
8084
+
8085
+ $activation_action = $this->get_unique_affix() . '_activate_new';
8086
+ $return_url = $this->is_anonymous() ?
8087
+ // If skipped already, then return to the account page.
8088
+ $this->get_account_url( $activation_action, array(), false ) :
8089
+ // Return to the module's main page.
8090
+ $this->get_after_activation_url( 'after_connect_url', array( 'fs_action' => $activation_action ) );
8091
+
8092
+ $params = array(
8093
+ 'user_firstname' => $current_user->user_firstname,
8094
+ 'user_lastname' => $current_user->user_lastname,
8095
+ 'user_nickname' => $current_user->user_nicename,
8096
+ 'user_email' => $current_user->user_email,
8097
+ 'user_ip' => WP_FS__REMOTE_ADDR,
8098
+ 'plugin_slug' => $this->_slug,
8099
+ 'plugin_id' => $this->get_id(),
8100
+ 'plugin_public_key' => $this->get_public_key(),
8101
+ 'plugin_version' => $this->get_plugin_version(),
8102
+ 'return_url' => fs_nonce_url( $return_url, $activation_action ),
8103
+ 'account_url' => fs_nonce_url( $this->_get_admin_page_url(
8104
+ 'account',
8105
+ array( 'fs_action' => 'sync_user' )
8106
+ ), 'sync_user' ),
8107
+ 'site_uid' => $this->get_anonymous_id(),
8108
+ 'site_url' => get_site_url(),
8109
+ 'site_name' => get_bloginfo( 'name' ),
8110
+ 'platform_version' => get_bloginfo( 'version' ),
8111
+ 'sdk_version' => $this->version,
8112
+ 'programming_language_version' => phpversion(),
8113
+ 'language' => get_bloginfo( 'language' ),
8114
+ 'charset' => get_bloginfo( 'charset' ),
8115
+ 'is_premium' => $this->is_premium(),
8116
+ 'is_active' => true,
8117
+ 'is_uninstalled' => false,
8118
+ );
8119
+
8120
+ if ( $this->is_pending_activation() &&
8121
+ ! empty( $this->_storage->pending_license_key )
8122
+ ) {
8123
+ $params['license_key'] = $this->_storage->pending_license_key;
8124
+ }
8125
+
8126
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
8127
+ // Even though rand() is known for its security issues,
8128
+ // the timestamp adds another layer of protection.
8129
+ // It would be very hard for an attacker to get the secret key form here.
8130
+ // Plus, this should never run in production since the secret should never
8131
+ // be included in the production version.
8132
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
8133
+ $params['salt'] = md5( uniqid( rand() ) );
8134
+ $params['secure'] = md5(
8135
+ $params['ts'] .
8136
+ $params['salt'] .
8137
+ $this->get_secret_key()
8138
+ );
8139
+ }
8140
+
8141
+ return array_merge( $params, $override_with );
8142
+ }
8143
+
8144
+ /**
8145
+ * 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
8146
+ * 2. If there was an API error, return the API result.
8147
+ *
8148
+ * @author Vova Feldman (@svovaf)
8149
+ * @since 1.1.7.4
8150
+ *
8151
+ * @param string|bool $email
8152
+ * @param string|bool $first
8153
+ * @param string|bool $last
8154
+ * @param string|bool $license_key
8155
+ * @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
8156
+ * In this case, the user and site info will be sent to the server but no
8157
+ * data will be saved to the WP installation's database.
8158
+ * @param number|bool $trial_plan_id
8159
+ *
8160
+ * @return string|object
8161
+ * @use WP_Error
8162
+ */
8163
+ function opt_in(
8164
+ $email = false,
8165
+ $first = false,
8166
+ $last = false,
8167
+ $license_key = false,
8168
+ $is_uninstall = false,
8169
+ $trial_plan_id = false
8170
+ ) {
8171
+ $this->_logger->entrance();
8172
+
8173
+ if ( false === $email ) {
8174
+ $current_user = self::_get_current_wp_user();
8175
+ $email = $current_user->user_email;
8176
+ }
8177
+
8178
+ /**
8179
+ * @since 1.2.1 If activating with license key, ignore the context-user
8180
+ * since the user will be automatically loaded from the license.
8181
+ */
8182
+ if ( empty( $license_key ) ) {
8183
+ // Clean up pending license if opt-ing in again.
8184
+ $this->_storage->remove( 'pending_license_key' );
8185
+
8186
+ if ( ! $is_uninstall ) {
8187
+ $fs_user = Freemius::_get_user_by_email( $email );
8188
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
8189
+ return $this->install_with_current_user( false, $trial_plan_id );
8190
+ }
8191
+ }
8192
+ }
8193
+
8194
+ $user_info = array();
8195
+ if ( ! empty( $email ) ) {
8196
+ $user_info['user_email'] = $email;
8197
+ }
8198
+ if ( ! empty( $first ) ) {
8199
+ $user_info['user_firstname'] = $first;
8200
+ }
8201
+ if ( ! empty( $last ) ) {
8202
+ $user_info['user_lastname'] = $last;
8203
+ }
8204
+
8205
+ $params = $this->get_opt_in_params( $user_info );
8206
+
8207
+ $filtered_license_key = false;
8208
+ if ( is_string( $license_key ) ) {
8209
+ $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
8210
+ $params['license_key'] = $filtered_license_key;
8211
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
8212
+ $params['trial_plan_id'] = $trial_plan_id;
8213
+ }
8214
+
8215
+ if ( $is_uninstall ) {
8216
+ $params['uninstall_params'] = array(
8217
+ 'reason_id' => $this->_storage->uninstall_reason->id,
8218
+ 'reason_info' => $this->_storage->uninstall_reason->info
8219
+ );
8220
+ }
8221
+
8222
+ $params['format'] = 'json';
8223
+
8224
+ $url = WP_FS__ADDRESS . '/action/service/user/install/';
8225
+ if ( isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
8226
+ $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
8227
+ }
8228
+
8229
+ $response = wp_remote_post( $url, array(
8230
+ 'method' => 'POST',
8231
+ 'body' => $params,
8232
+ 'timeout' => 15,
8233
+ ) );
8234
+
8235
+ if ( $response instanceof WP_Error ) {
8236
+ if ( 'https://' === substr( $url, 0, 8 ) &&
8237
+ isset( $response->errors ) &&
8238
+ isset( $response->errors['http_request_failed'] )
8239
+ ) {
8240
+ $http_error = strtolower( $response->errors['http_request_failed'][0] );
8241
+
8242
+ if ( false !== strpos( $http_error, 'ssl' ) ) {
8243
+ // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
8244
+ $url = 'http://' . substr( $url, 8 );
8245
+
8246
+ $response = wp_remote_post( $url, array(
8247
+ 'method' => 'POST',
8248
+ 'body' => $params,
8249
+ 'timeout' => 15,
8250
+ ) );
8251
+ }
8252
+ }
8253
+ }
8254
+
8255
+ if ( is_wp_error( $response ) ) {
8256
+ /**
8257
+ * @var WP_Error $response
8258
+ */
8259
+ $result = new stdClass();
8260
+
8261
+ $error_code = $response->get_error_code();
8262
+ $error_type = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $error_code ) ) );
8263
+
8264
+ $result->error = (object) array(
8265
+ 'type' => $error_type,
8266
+ 'message' => $response->get_error_message(),
8267
+ 'code' => $error_code,
8268
+ 'http' => 402
8269
+ );
8270
+
8271
+ return $result;
8272
+ }
8273
+
8274
+ // Module is being uninstalled, don't handle the returned data.
8275
+ if ( $is_uninstall ) {
8276
+ return true;
8277
+ }
8278
+
8279
+ $decoded = @json_decode( $response['body'] );
8280
+
8281
+ if ( empty( $decoded ) ) {
8282
+ return false;
8283
+ }
8284
+
8285
+ if ( ! $this->is_api_result_object( $decoded ) ) {
8286
+ if ( ! empty( $params['license_key'] ) ) {
8287
+ // Pass the fully entered license key to the failure handler.
8288
+ $params['license_key'] = $license_key;
8289
+ }
8290
+
8291
+ return $is_uninstall ?
8292
+ $decoded :
8293
+ $this->apply_filters( 'after_install_failure', $decoded, $params );
8294
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
8295
+ // Pending activation, add message.
8296
+ return $this->set_pending_confirmation(
8297
+ true,
8298
+ false,
8299
+ $filtered_license_key,
8300
+ ! empty( $params['trial_plan_id'] )
8301
+ );
8302
+ } else if ( isset( $decoded->install_secret_key ) ) {
8303
+ return $this->install_with_new_user(
8304
+ $decoded->user_id,
8305
+ $decoded->user_public_key,
8306
+ $decoded->user_secret_key,
8307
+ $decoded->install_id,
8308
+ $decoded->install_public_key,
8309
+ $decoded->install_secret_key,
8310
+ false
8311
+ );
8312
+ }
8313
+
8314
+ return $decoded;
8315
+ }
8316
+
8317
+ /**
8318
+ * Set user and site identities.
8319
+ *
8320
+ * @author Vova Feldman (@svovaf)
8321
+ * @since 1.0.9
8322
+ *
8323
+ * @param FS_User $user
8324
+ * @param FS_Site $site
8325
+ * @param bool $redirect
8326
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
8327
+ * redirect (or return a URL) to the account page with a special parameter to
8328
+ * trigger the auto installation processes.
8329
+ *
8330
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
8331
+ */
8332
+ function setup_account(
8333
+ FS_User $user,
8334
+ FS_Site $site,
8335
+ $redirect = true,
8336
+ $auto_install = false
8337
+ ) {
8338
+ $this->_user = $user;
8339
+ $this->_site = $site;
8340
+
8341
+ $this->_sync_plans();
8342
+
8343
+ $this->_enrich_site_plan( false );
8344
+
8345
+ $this->_set_account( $user, $site );
8346
+
8347
+ if ( $this->is_trial() ) {
8348
+ // Store trial plan information.
8349
+ $this->_enrich_site_trial_plan( true );
8350
+ }
8351
+
8352
+ // If Freemius was OFF before, turn it on.
8353
+ $this->turn_on();
8354
+
8355
+ $this->do_action( 'after_account_connection', $user, $site );
8356
+
8357
+ if ( is_numeric( $site->license_id ) ) {
8358
+ $this->_license = $this->_get_license_by_id( $site->license_id );
8359
+ }
8360
+
8361
+ $this->_admin_notices->remove_sticky( 'connect_account' );
8362
+
8363
+ if ( $this->is_pending_activation() ) {
8364
+ // Remove pending activation sticky notice (if still exist).
8365
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
8366
+
8367
+ // Remove plugin from pending activation mode.
8368
+ unset( $this->_storage->is_pending_activation );
8369
+
8370
+ if ( ! $this->is_paying_or_trial() ) {
8371
+ $this->_admin_notices->add_sticky(
8372
+ sprintf( $this->get_text( 'plugin-x-activation-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
8373
+ 'activation_complete'
8374
+ );
8375
+ }
8376
+ }
8377
+
8378
+ if ( $this->is_paying_or_trial() ) {
8379
+ if ( ! $this->is_premium() || ! $this->has_premium_version() ) {
8380
+ if ( $this->is_paying() ) {
8381
+ $this->_admin_notices->add_sticky(
8382
+ sprintf(
8383
+ $this->get_text( 'activation-with-plan-x-message' ),
8384
+ $this->_site->plan->title
8385
+ ) . $this->get_complete_upgrade_instructions(),
8386
+ 'plan_upgraded',
8387
+ $this->get_text( 'yee-haw' ) . '!'
8388
+ );
8389
+ } else {
8390
+ $this->_admin_notices->add_sticky(
8391
+ sprintf(
8392
+ $this->get_text( 'trial-started-message' ),
8393
+ '<i>' . $this->get_plugin_name() . '</i>'
8394
+ ) . $this->get_complete_upgrade_instructions( $this->_storage->trial_plan->title ),
8395
+ 'trial_started',
8396
+ $this->get_text( 'yee-haw' ) . '!'
8397
+ );
8398
+ }
8399
+ }
8400
+
8401
+ $this->_admin_notices->remove_sticky( array(
8402
+ 'trial_promotion',
8403
+ ) );
8404
+ }
8405
+
8406
+ $plugin_id = fs_request_get( 'plugin_id', false );
8407
+
8408
+ // Store activation time ONLY for plugins (not add-ons).
8409
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
8410
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
8411
+ }
8412
+
8413
+ $next_page = '';
8414
+
8415
+ $extra = array();
8416
+ if ( $auto_install ) {
8417
+ $extra['auto_install'] = 'true';
8418
+ }
8419
+
8420
+ if ( is_numeric( $plugin_id ) ) {
8421
+ /**
8422
+ * @author Leo Fajardo
8423
+ * @since 1.2.1.6
8424
+ *
8425
+ * Also sync the license after an anonymous user subscribes.
8426
+ */
8427
+ if ( $this->is_anonymous() || $plugin_id != $this->_plugin->id ) {
8428
+ // Add-on was installed - sync license right after install.
8429
+ $next_page = $this->_get_sync_license_url( $plugin_id, true, $extra );
8430
+ }
8431
+ } else {
8432
+ /**
8433
+ * @author Vova Feldman (@svovaf)
8434
+ * @since 1.1.9 If site installed with a valid license, sync license.
8435
+ */
8436
+ if ( $this->is_paying() ) {
8437
+ $this->_sync_plugin_license( true );
8438
+ }
8439
+
8440
+ // Reload the page with the keys.
8441
+ $next_page = $this->is_anonymous() ?
8442
+ // If user previously skipped, redirect to account page.
8443
+ $this->get_account_url( false, $extra ) :
8444
+ $this->get_after_activation_url( 'after_connect_url' );
8445
+ }
8446
+
8447
+ if ( ! empty( $next_page ) && $redirect ) {
8448
+ fs_redirect( $next_page );
8449
+ }
8450
+
8451
+ return $next_page;
8452
+ }
8453
+
8454
+ /**
8455
+ * Install plugin with new user information after approval.
8456
+ *
8457
+ * @author Vova Feldman (@svovaf)
8458
+ * @since 1.0.7
8459
+ */
8460
+ function _install_with_new_user() {
8461
+ $this->_logger->entrance();
8462
+
8463
+ if ( $this->is_registered() ) {
8464
+ return;
8465
+ }
8466
+
8467
+ if ( ( $this->is_plugin() && fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) ||
8468
+ // @todo This logic should be improved because it's executed on every load of a theme.
8469
+ $this->is_theme()
8470
+ ) {
8471
+ // check_admin_referer( $this->_slug . '_activate_new' );
8472
+
8473
+ if ( fs_request_has( 'user_secret_key' ) ) {
8474
+ $this->install_with_new_user(
8475
+ fs_request_get( 'user_id' ),
8476
+ fs_request_get( 'user_public_key' ),
8477
+ fs_request_get( 'user_secret_key' ),
8478
+ fs_request_get( 'install_id' ),
8479
+ fs_request_get( 'install_public_key' ),
8480
+ fs_request_get( 'install_secret_key' ),
8481
+ true,
8482
+ fs_request_get_bool( 'auto_install' )
8483
+ );
8484
+ } else if ( fs_request_has( 'pending_activation' ) ) {
8485
+ $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
8486
+ }
8487
+ }
8488
+ }
8489
+
8490
+ /**
8491
+ * Install plugin with new user.
8492
+ *
8493
+ * @author Vova Feldman (@svovaf)
8494
+ * @since 1.1.7.4
8495
+ *
8496
+ * @param number $user_id
8497
+ * @param string $user_public_key
8498
+ * @param string $user_secret_key
8499
+ * @param number $install_id
8500
+ * @param string $install_public_key
8501
+ * @param string $install_secret_key
8502
+ * @param bool $redirect
8503
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
8504
+ * redirect (or return a URL) to the account page with a special parameter to
8505
+ * trigger the auto installation processes.
8506
+ *
8507
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
8508
+ */
8509
+ private function install_with_new_user(
8510
+ $user_id,
8511
+ $user_public_key,
8512
+ $user_secret_key,
8513
+ $install_id,
8514
+ $install_public_key,
8515
+ $install_secret_key,
8516
+ $redirect = true,
8517
+ $auto_install = false
8518
+ ) {
8519
+ $user = new FS_User();
8520
+ $user->id = $user_id;
8521
+ $user->public_key = $user_public_key;
8522
+ $user->secret_key = $user_secret_key;
8523
+
8524
+ $this->_user = $user;
8525
+ $user_result = $this->get_api_user_scope()->get();
8526
+ $user = new FS_User( $user_result );
8527
+ $this->_user = $user;
8528
+
8529
+ $site = new FS_Site();
8530
+ $site->id = $install_id;
8531
+ $site->public_key = $install_public_key;
8532
+ $site->secret_key = $install_secret_key;
8533
+
8534
+ $this->_site = $site;
8535
+ $site_result = $this->get_api_site_scope()->get();
8536
+ $site = new FS_Site( $site_result );
8537
+ $this->_site = $site;
8538
+
8539
+ return $this->setup_account(
8540
+ $this->_user,
8541
+ $this->_site,
8542
+ $redirect,
8543
+ $auto_install
8544
+ );
8545
+ }
8546
+
8547
+ /**
8548
+ * @author Vova Feldman (@svovaf)
8549
+ * @since 1.1.7.4
8550
+ *
8551
+ * @param string|bool $email
8552
+ * @param bool $redirect
8553
+ * @param string|bool $license_key Since 1.2.1.5
8554
+ * @param bool $is_pending_trial Since 1.2.1.5
8555
+ *
8556
+ * @return string Since 1.2.1.5 if $redirect is `false`, return the pending activation page.
8557
+ */
8558
+ private function set_pending_confirmation(
8559
+ $email = false,
8560
+ $redirect = true,
8561
+ $license_key = false,
8562
+ $is_pending_trial = false
8563
+ ) {
8564
+ if ( $this->_ignore_pending_mode ) {
8565
+ /**
8566
+ * If explicitly asked to ignore pending mode, set to anonymous mode
8567
+ * if require confirmation before finalizing the opt-in.
8568
+ *
8569
+ * @author Vova Feldman
8570
+ * @since 1.2.1.6
8571
+ */
8572
+ $this->skip_connection();
8573
+ } else {
8574
+ // Install must be activated via email since
8575
+ // user with the same email already exist.
8576
+ $this->_storage->is_pending_activation = true;
8577
+ $this->_add_pending_activation_notice( $email, $is_pending_trial );
8578
+ }
8579
+
8580
+ if ( ! empty( $license_key ) ) {
8581
+ $this->_storage->pending_license_key = $license_key;
8582
+ }
8583
+
8584
+ // Remove the opt-in sticky notice.
8585
+ $this->_admin_notices->remove_sticky( array(
8586
+ 'connect_account',
8587
+ 'trial_promotion',
8588
+ ) );
8589
+
8590
+ $next_page = $this->get_after_activation_url( 'after_pending_connect_url' );
8591
+
8592
+ // Reload the page with with pending activation message.
8593
+ if ( $redirect ) {
8594
+ fs_redirect( $next_page );
8595
+ }
8596
+
8597
+ return $next_page;
8598
+ }
8599
+
8600
+ /**
8601
+ * Install plugin with current logged WP user info.
8602
+ *
8603
+ * @author Vova Feldman (@svovaf)
8604
+ * @since 1.0.7
8605
+ */
8606
+ function _install_with_current_user() {
8607
+ $this->_logger->entrance();
8608
+
8609
+ if ( $this->is_registered() ) {
8610
+ return;
8611
+ }
8612
+
8613
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
8614
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
8615
+
8616
+ /**
8617
+ * @author Vova Feldman (@svovaf)
8618
+ * @since 1.1.9 Add license key if given.
8619
+ */
8620
+ $license_key = fs_request_get( 'license_secret_key' );
8621
+
8622
+ $this->install_with_current_user( $license_key );
8623
+ }
8624
+ }
8625
+
8626
+
8627
+ /**
8628
+ * @author Vova Feldman (@svovaf)
8629
+ * @since 1.1.7.4
8630
+ *
8631
+ * @param string|bool $license_key
8632
+ * @param number|bool $trial_plan_id
8633
+ * @param bool $redirect
8634
+ *
8635
+ * @return string|object If redirect is `false`, returns the next page the user should be redirected to, or the
8636
+ * API error object if failed to install.
8637
+ */
8638
+ private function install_with_current_user(
8639
+ $license_key = false,
8640
+ $trial_plan_id = false,
8641
+ $redirect = true
8642
+ ) {
8643
+ // Get current logged WP user.
8644
+ $current_user = self::_get_current_wp_user();
8645
+
8646
+ // Find the relevant FS user by the email.
8647
+ $user = self::_get_user_by_email( $current_user->user_email );
8648
+
8649
+ // We have to set the user before getting user scope API handler.
8650
+ $this->_user = $user;
8651
+
8652
+ $extra_install_params = array(
8653
+ 'uid' => $this->get_anonymous_id(),
8654
+ );
8655
+
8656
+ if ( ! empty( $license_key ) ) {
8657
+ $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
8658
+ $extra_install_params['license_key'] = $filtered_license_key;
8659
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
8660
+ $extra_install_params['trial_plan_id'] = $trial_plan_id;
8661
+ }
8662
+
8663
+ $args = $this->get_install_data_for_api( $extra_install_params, false, false );
8664
+
8665
+ // Install the plugin.
8666
+ $install = $this->get_api_user_scope()->call(
8667
+ "/plugins/{$this->get_id()}/installs.json",
8668
+ 'post',
8669
+ $args
8670
+ );
8671
+
8672
+ if ( ! $this->is_api_result_entity( $install ) ) {
8673
+ if ( ! empty( $args['license_key'] ) ) {
8674
+ // Pass full the fully entered license key to the failure handler.
8675
+ $args['license_key'] = $license_key;
8676
+ }
8677
+
8678
+ $install = $this->apply_filters( 'after_install_failure', $install, $args );
8679
+
8680
+ $this->_admin_notices->add(
8681
+ sprintf( $this->get_text( 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
8682
+ $this->get_text( 'contact-us-with-error-message' ) . ' ' . '<b>' . $install->error->message . '</b>',
8683
+ $this->get_text( 'oops' ) . '...',
8684
+ 'error'
8685
+ );
8686
+
8687
+ if ( $redirect ) {
8688
+ fs_redirect( $this->get_activation_url( array( 'error' => $install->error->message ) ) );
8689
+ }
8690
+
8691
+ return $install;
8692
+ }
8693
+
8694
+ $site = new FS_Site( $install );
8695
+ $this->_site = $site;
8696
+
8697
+ return $this->setup_account( $this->_user, $this->_site, $redirect );
8698
+ }
8699
+
8700
+ /**
8701
+ * Tries to activate add-on account based on parent plugin info.
8702
+ *
8703
+ * @author Vova Feldman (@svovaf)
8704
+ * @since 1.0.6
8705
+ *
8706
+ * @param Freemius $parent_fs
8707
+ */
8708
+ private function _activate_addon_account( Freemius $parent_fs ) {
8709
+ if ( $this->is_registered() ) {
8710
+ // Already activated.
8711
+ return;
8712
+ }
8713
+
8714
+ // Activate add-on with parent plugin credentials.
8715
+ $addon_install = $parent_fs->get_api_site_scope()->call(
8716
+ "/addons/{$this->_plugin->id}/installs.json",
8717
+ 'post',
8718
+ $this->get_install_data_for_api( array(
8719
+ 'uid' => $this->get_anonymous_id(),
8720
+ ), false, false )
8721
+ );
8722
+
8723
+ if ( isset( $addon_install->error ) ) {
8724
+ $this->_admin_notices->add(
8725
+ sprintf( $this->get_text( 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
8726
+ $this->get_text( 'contact-us-with-error-message' ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
8727
+ $this->get_text( 'oops' ) . '...',
8728
+ 'error'
8729
+ );
8730
+
8731
+ return;
8732
+ }
8733
+
8734
+ // First of all, set site info - otherwise we won't
8735
+ // be able to invoke API calls.
8736
+ $this->_site = new FS_Site( $addon_install );
8737
+
8738
+ // Sync add-on plans.
8739
+ $this->_sync_plans();
8740
+
8741
+ // Get site's current plan.
8742
+ $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
8743
+
8744
+ // Get user information based on parent's plugin.
8745
+ $user = $parent_fs->get_user();
8746
+
8747
+ $this->_set_account( $user, $this->_site );
8748
+
8749
+ // Sync licenses.
8750
+ $this->_sync_licenses();
8751
+
8752
+ // Try to activate premium license.
8753
+ $this->_activate_license( true );
8754
+ }
8755
+
8756
+ /**
8757
+ * Tries to activate parent account based on add-on's info.
8758
+ *
8759
+ * @author Vova Feldman (@svovaf)
8760
+ * @since 1.2.2.7
8761
+ *
8762
+ * @param Freemius $parent_fs
8763
+ */
8764
+ private function activate_parent_account( Freemius $parent_fs ) {
8765
+ if ( ! $this->is_addon() ) {
8766
+ // This is not an add-on.
8767
+ return;
8768
+ }
8769
+
8770
+ if ( $parent_fs->is_registered() ) {
8771
+ // Already activated.
8772
+ return;
8773
+ }
8774
+
8775
+ // Activate parent with add-on's user credentials.
8776
+ $parent_install = $this->get_api_user_scope()->call(
8777
+ "/plugins/{$parent_fs->_plugin->id}/installs.json",
8778
+ 'post',
8779
+ $parent_fs->get_install_data_for_api( array(
8780
+ 'uid' => $parent_fs->get_anonymous_id(),
8781
+ ), false, false )
8782
+ );
8783
+
8784
+ if ( isset( $parent_install->error ) ) {
8785
+ $this->_admin_notices->add(
8786
+ sprintf( $this->get_text( 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
8787
+ $this->get_text( 'contact-us-with-error-message' ) . ' ' . '<b>' . $parent_install->error->message . '</b>',
8788
+ $this->get_text( 'oops' ) . '...',
8789
+ 'error'
8790
+ );
8791
+
8792
+ return;
8793
+ }
8794
+
8795
+ // First of all, set site info - otherwise we won't
8796
+ // be able to invoke API calls.
8797
+ $parent_fs->_site = new FS_Site( $parent_install );
8798
+
8799
+ // Sync add-on plans.
8800
+ $parent_fs->_sync_plans();
8801
+
8802
+ // Get site's current plan.
8803
+ $parent_fs->_site->plan = $parent_fs->_get_plan_by_id( $parent_fs->_site->plan->id );
8804
+
8805
+ // Get user information based on parent's plugin.
8806
+ $user = $this->get_user();
8807
+
8808
+ $parent_fs->_set_account( $user, $parent_fs->_site );
8809
+ }
8810
+
8811
+ #endregion
8812
+
8813
+ #----------------------------------------------------------------------------------
8814
+ #region Admin Menu Items
8815
+ #----------------------------------------------------------------------------------
8816
+
8817
+ private $_menu_items = array();
8818
+
8819
+ /**
8820
+ * @author Vova Feldman (@svovaf)
8821
+ * @since 1.2.1.8
8822
+ *
8823
+ * @return array
8824
+ */
8825
+ function get_menu_items() {
8826
+ return $this->_menu_items;
8827
+ }
8828
+
8829
+ /**
8830
+ * @author Vova Feldman (@svovaf)
8831
+ * @since 1.0.7
8832
+ *
8833
+ * @return string
8834
+ */
8835
+ function get_menu_slug() {
8836
+ return $this->_menu->get_slug();
8837
+ }
8838
+
8839
+ /**
8840
+ * @author Vova Feldman (@svovaf)
8841
+ * @since 1.0.9
8842
+ */
8843
+ function _prepare_admin_menu() {
8844
+ // if ( ! $this->is_on() ) {
8845
+ // return;
8846
+ // }
8847
+
8848
+ if ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) {
8849
+ $this->_menu->remove_menu_item();
8850
+ } else {
8851
+ $this->do_action( 'before_admin_menu_init' );
8852
+
8853
+ $this->add_menu_action();
8854
+ $this->add_submenu_items();
8855
+ }
8856
+ }
8857
+
8858
+ /**
8859
+ * Admin dashboard menu items modifications.
8860
+ *
8861
+ * NOTE: admin_menu action executed before admin_init.
8862
+ *
8863
+ * @author Vova Feldman (@svovaf)
8864
+ * @since 1.0.7
8865
+ *
8866
+ */
8867
+ private function add_menu_action() {
8868
+ if ( $this->is_activation_mode() ) {
8869
+ if ( $this->is_plugin() || ( $this->has_settings_menu() && ! $this->is_free_wp_org_theme() ) ) {
8870
+ $this->override_plugin_menu_with_activation();
8871
+ } else {
8872
+ /**
8873
+ * Handle theme opt-in when the opt-in form shows as a dialog box in the themes page.
8874
+ */
8875
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
8876
+ add_action( 'load-themes.php', array( &$this, '_install_with_current_user' ) );
8877
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ||
8878
+ fs_request_get_bool( 'pending_activation' )
8879
+ ) {
8880
+ add_action( 'load-themes.php', array( &$this, '_install_with_new_user' ) );
8881
+ }
8882
+ }
8883
+ } else {
8884
+ if ( ! $this->is_registered() ) {
8885
+ // If not registered try to install user.
8886
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
8887
+ $this->_install_with_new_user();
8888
+ }
8889
+ } else if (
8890
+ fs_request_is_action( 'sync_user' ) &&
8891
+ ( ! $this->has_settings_menu() || $this->is_free_wp_org_theme() )
8892
+ ) {
8893
+ $this->_handle_account_user_sync();
8894
+ }
8895
+ }
8896
+ }
8897
+
8898
+ /**
8899
+ * @author Vova Feldman (@svovaf)
8900
+ * @since 1.0.1
8901
+ */
8902
+ function _redirect_on_clicked_menu_link() {
8903
+ $this->_logger->entrance();
8904
+
8905
+ $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
8906
+
8907
+ $this->_logger->log( 'page = ' . $page );
8908
+
8909
+ foreach ( $this->_menu_items as $priority => $items ) {
8910
+ foreach ( $items as $item ) {
8911
+ if ( isset( $item['url'] ) ) {
8912
+ if ( $page === $this->_menu->get_slug( strtolower( $item['menu_slug'] ) ) ) {
8913
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
8914
+
8915
+ fs_redirect( $item['url'] );
8916
+ }
8917
+ }
8918
+ }
8919
+ }
8920
+ }
8921
+
8922
+ /**
8923
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
8924
+ *
8925
+ * @author Vova Feldman (@svovaf)
8926
+ * @since 1.0.1
8927
+ */
8928
+ private function override_plugin_menu_with_activation() {
8929
+ $this->_logger->entrance();
8930
+
8931
+ $hook = false;
8932
+
8933
+ if ( ! $this->_menu->has_menu() ) {
8934
+ // Add the opt-in page without a menu item.
8935
+ $hook = FS_Admin_Menu_Manager::add_subpage(
8936
+ null,
8937
+ $this->get_plugin_name(),
8938
+ $this->get_plugin_name(),
8939
+ 'manage_options',
8940
+ $this->_slug,
8941
+ array( &$this, '_connect_page_render' )
8942
+ );
8943
+ } else if ( $this->_menu->is_top_level() ) {
8944
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
8945
+
8946
+ if ( false === $hook ) {
8947
+ // Create new menu item just for the opt-in.
8948
+ $hook = FS_Admin_Menu_Manager::add_page(
8949
+ $this->get_plugin_name(),
8950
+ $this->get_plugin_name(),
8951
+ 'manage_options',
8952
+ $this->_menu->get_slug(),
8953
+ array( &$this, '_connect_page_render' )
8954
+ );
8955
+ }
8956
+ } else {
8957
+ $menus = array( $this->_menu->get_parent_slug() );
8958
+
8959
+ if ( $this->_menu->is_override_exact() ) {
8960
+ // Make sure the current page is matching the activation page.
8961
+ if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
8962
+ return;
8963
+ }
8964
+ }
8965
+
8966
+ foreach ( $menus as $parent_slug ) {
8967
+ $hook = $this->_menu->override_submenu_action(
8968
+ $parent_slug,
8969
+ $this->_menu->get_raw_slug(),
8970
+ array( &$this, '_connect_page_render' )
8971
+ );
8972
+
8973
+ if ( false !== $hook ) {
8974
+ // Found plugin's submenu item.
8975
+ break;
8976
+ }
8977
+ }
8978
+ }
8979
+
8980
+ if ( $this->is_activation_page() ) {
8981
+ // Clean admin page from distracting content.
8982
+ self::_clean_admin_content_section();
8983
+ }
8984
+
8985
+ if ( false !== $hook ) {
8986
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
8987
+ add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
8988
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
8989
+ add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
8990
+ }
8991
+ }
8992
+ }
8993
+
8994
+ /**
8995
+ * @author Leo Fajardo (leorw)
8996
+ * @since 1.2.1
8997
+ *
8998
+ * return string
8999
+ */
9000
+ function get_top_level_menu_capability() {
9001
+ global $menu;
9002
+
9003
+ $top_level_menu_slug = $this->get_top_level_menu_slug();
9004
+
9005
+ foreach ( $menu as $menu_info ) {
9006
+ /**
9007
+ * The second element in the menu info array is the capability/role that has access to the menu and the
9008
+ * third element is the menu slug.
9009
+ */
9010
+ if ( $menu_info[2] === $top_level_menu_slug ) {
9011
+ return $menu_info[1];
9012
+ }
9013
+ }
9014
+
9015
+ return 'read';
9016
+ }
9017
+
9018
+ /**
9019
+ * @author Vova Feldman (@svovaf)
9020
+ * @since 1.0.0
9021
+ *
9022
+ * @return string
9023
+ */
9024
+ private function get_top_level_menu_slug() {
9025
+ return ( $this->is_addon() ?
9026
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
9027
+ $this->_menu->get_top_level_menu_slug() );
9028
+ }
9029
+
9030
+ /**
9031
+ * @author Vova Feldman (@svovaf)
9032
+ * @since 1.2.2.7
9033
+ *
9034
+ * @return string
9035
+ */
9036
+ function get_pricing_cta_label() {
9037
+ $label = 'upgrade';
9038
+
9039
+ if ( $this->is_in_trial_promotion() &&
9040
+ ! $this->is_paying_or_trial()
9041
+ ) {
9042
+ // If running a trial promotion, modify the pricing to load the trial.
9043
+ $label = 'start-trial';
9044
+ } else if ( $this->is_paying() ) {
9045
+ $label = 'pricing';
9046
+ }
9047
+
9048
+ return $label;
9049
+ }
9050
+
9051
+ /**
9052
+ * @author Vova Feldman (@svovaf)
9053
+ * @since 1.2.2.7
9054
+ *
9055
+ * @return bool
9056
+ */
9057
+ function is_pricing_page_visible() {
9058
+ return (
9059
+ // Has at least one paid plan.
9060
+ $this->has_paid_plan() &&
9061
+ // Didn't ask to hide the pricing page.
9062
+ $this->is_page_visible( 'pricing' ) &&
9063
+ // Don't have a valid active license or has more than one plan.
9064
+ ( ! $this->is_paying() || ! $this->is_single_plan() )
9065
+ );
9066
+ }
9067
+
9068
+ /**
9069
+ * Add default Freemius menu items.
9070
+ *
9071
+ * @author Vova Feldman (@svovaf)
9072
+ * @since 1.0.0
9073
+ */
9074
+ private function add_submenu_items() {
9075
+ $this->_logger->entrance();
9076
+
9077
+ if ( ! $this->is_addon() ) {
9078
+ /**
9079
+ * @since 1.2.2.7 Also add submenu items when running in a free .org theme so the tabs will be visible.
9080
+ */
9081
+ if ( ! $this->is_activation_mode() || $this->is_free_wp_org_theme() ) {
9082
+ if ( $this->is_registered() ) {
9083
+ $show_account = (
9084
+ $this->is_submenu_item_visible( 'account' ) &&
9085
+ /**
9086
+ * @since 1.2.2.7 Don't show the Account for free WP.org themes without any paid plans.
9087
+ */
9088
+ ( ! $this->is_free_wp_org_theme() || $this->has_paid_plan() )
9089
+ );
9090
+
9091
+ // Add user account page.
9092
+ $this->add_submenu_item(
9093
+ $this->get_text( 'account' ),
9094
+ array( &$this, '_account_page_render' ),
9095
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text( 'account' ),
9096
+ 'manage_options',
9097
+ 'account',
9098
+ array( &$this, '_account_page_load' ),
9099
+ WP_FS__DEFAULT_PRIORITY,
9100
+ $show_account
9101
+ );
9102
+ }
9103
+
9104
+ // Add contact page.
9105
+ $this->add_submenu_item(
9106
+ $this->get_text( 'contact-us' ),
9107
+ array( &$this, '_contact_page_render' ),
9108
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text( 'contact-us' ),
9109
+ 'manage_options',
9110
+ 'contact',
9111
+ 'Freemius::_clean_admin_content_section',
9112
+ WP_FS__DEFAULT_PRIORITY,
9113
+ $this->is_submenu_item_visible( 'contact' )
9114
+ );
9115
+
9116
+ if ( $this->has_addons() ) {
9117
+ $this->add_submenu_item(
9118
+ $this->get_text( 'add-ons' ),
9119
+ array( &$this, '_addons_page_render' ),
9120
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text( 'add-ons' ),
9121
+ 'manage_options',
9122
+ 'addons',
9123
+ array( &$this, '_addons_page_load' ),
9124
+ WP_FS__LOWEST_PRIORITY - 1,
9125
+ $this->is_submenu_item_visible( 'addons' )
9126
+ );
9127
+ }
9128
+
9129
+ $show_pricing = (
9130
+ $this->is_submenu_item_visible( 'pricing' ) &&
9131
+ $this->is_pricing_page_visible()
9132
+ );
9133
+
9134
+ $pricing_cta_slug = $this->get_pricing_cta_label();
9135
+ $pricing_class = 'upgrade-mode';
9136
+ if ( $show_pricing ) {
9137
+ if ( $this->is_in_trial_promotion() &&
9138
+ ! $this->is_paying_or_trial()
9139
+ ) {
9140
+ // If running a trial promotion, modify the pricing to load the trial.
9141
+ $pricing_class = 'trial-mode';
9142
+ } else if ( $this->is_paying() ) {
9143
+ $pricing_class = '';
9144
+ }
9145
+ }
9146
+
9147
+ // Add upgrade/pricing page.
9148
+ $this->add_submenu_item(
9149
+ $this->get_text( $pricing_cta_slug ) . '&nbsp;&nbsp;' . ( is_rtl() ? '&#x2190;' : '&#x27a4;' ),
9150
+ array( &$this, '_pricing_page_render' ),
9151
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text( 'pricing' ),
9152
+ 'manage_options',
9153
+ 'pricing',
9154
+ 'Freemius::_clean_admin_content_section',
9155
+ WP_FS__LOWEST_PRIORITY,
9156
+ $show_pricing,
9157
+ $pricing_class
9158
+ );
9159
+ }
9160
+ }
9161
+
9162
+
9163
+ if ( 0 < count( $this->_menu_items ) ) {
9164
+ if ( ! $this->_menu->is_top_level() ) {
9165
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
9166
+
9167
+ // Append submenu items right after the plugin's submenu item.
9168
+ $this->order_sub_submenu_items();
9169
+ } else {
9170
+ // Append submenu items.
9171
+ $this->embed_submenu_items();
9172
+ }
9173
+ }
9174
+ }
9175
+
9176
+ /**
9177
+ * Moved the actual submenu item additions to a separated function,
9178
+ * in order to support sub-submenu items when the plugin's settings
9179
+ * only have a submenu and not top-level menu item.
9180
+ *
9181
+ * @author Vova Feldman (@svovaf)
9182
+ * @since 1.1.4
9183
+ */
9184
+ private function embed_submenu_items() {
9185
+ $item_template = $this->_menu->is_top_level() ?
9186
+ '<span class="fs-submenu-item %s %s %s">%s</span>' :
9187
+ '<span class="fs-submenu-item fs-sub %s %s %s">%s</span>';
9188
+
9189
+ $top_level_menu_capability = $this->get_top_level_menu_capability();
9190
+
9191
+ ksort( $this->_menu_items );
9192
+
9193
+ foreach ( $this->_menu_items as $priority => $items ) {
9194
+ foreach ( $items as $item ) {
9195
+ $capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
9196
+
9197
+ $menu_item = sprintf(
9198
+ $item_template,
9199
+ $this->get_unique_affix(),
9200
+ $item['menu_slug'],
9201
+ ! empty( $item['class'] ) ? $item['class'] : '',
9202
+ $item['menu_title']
9203
+ );
9204
+
9205
+ $menu_slug = $this->_menu->get_slug( $item['menu_slug'] );
9206
+
9207
+ if ( ! isset( $item['url'] ) ) {
9208
+ $hook = FS_Admin_Menu_Manager::add_subpage(
9209
+ $item['show_submenu'] ?
9210
+ $this->get_top_level_menu_slug() :
9211
+ null,
9212
+ $item['page_title'],
9213
+ $menu_item,
9214
+ $capability,
9215
+ $menu_slug,
9216
+ $item['render_function']
9217
+ );
9218
+
9219
+ if ( false !== $item['before_render_function'] ) {
9220
+ add_action( "load-$hook", $item['before_render_function'] );
9221
+ }
9222
+ } else {
9223
+ FS_Admin_Menu_Manager::add_subpage(
9224
+ $item['show_submenu'] ?
9225
+ $this->get_top_level_menu_slug() :
9226
+ null,
9227
+ $item['page_title'],
9228
+ $menu_item,
9229
+ $capability,
9230
+ $menu_slug,
9231
+ array( $this, '' )
9232
+ );
9233
+ }
9234
+ }
9235
+ }
9236
+ }
9237
+
9238
+ /**
9239
+ * Re-order the submenu items so all Freemius added new submenu items
9240
+ * are added right after the plugin's settings submenu item.
9241
+ *
9242
+ * @author Vova Feldman (@svovaf)
9243
+ * @since 1.1.4
9244
+ */
9245
+ private function order_sub_submenu_items() {
9246
+ global $submenu;
9247
+
9248
+ $menu_slug = $this->_menu->get_top_level_menu_slug();
9249
+
9250
+ /**
9251
+ * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
9252
+ * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
9253
+ * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
9254
+ * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
9255
+ *
9256
+ * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
9257
+ * of another plugin, only users that have the right role can access its sub-submenus since we will use the
9258
+ * capability needed to access the parent menu as the capability for the submenus that we will add.
9259
+ */
9260
+ if ( empty( $submenu[ $menu_slug ] ) ) {
9261
+ return;
9262
+ }
9263
+
9264
+ $top_level_menu = &$submenu[ $menu_slug ];
9265
+
9266
+ $all_submenu_items_after = array();
9267
+
9268
+ $found_submenu_item = false;
9269
+
9270
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
9271
+ if ( $found_submenu_item ) {
9272
+ // Remove all submenu items after the plugin's submenu item.
9273
+ $all_submenu_items_after[] = $meta;
9274
+ unset( $top_level_menu[ $submenu_id ] );
9275
+ }
9276
+
9277
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
9278
+ // Found the submenu item, put all below.
9279
+ $found_submenu_item = true;
9280
+ continue;
9281
+ }
9282
+ }
9283
+
9284
+ // Embed all plugin's new submenu items.
9285
+ $this->embed_submenu_items();
9286
+
9287
+ // Start with specially high number to make sure it's appended.
9288
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
9289
+ foreach ( $all_submenu_items_after as $meta ) {
9290
+ $top_level_menu[ $i ] = $meta;
9291
+ $i ++;
9292
+ }
9293
+
9294
+ // Sort submenu items.
9295
+ ksort( $top_level_menu );
9296
+ }
9297
+
9298
+ /**
9299
+ * Helper method to return the module's support forum URL.
9300
+ *
9301
+ * @author Vova Feldman (@svovaf)
9302
+ * @since 1.2.2.7
9303
+ *
9304
+ * @return string
9305
+ */
9306
+ function get_support_forum_url() {
9307
+ return $this->apply_filters( 'support_forum_url', "https://wordpress.org/support/{$this->_module_type}/{$this->_slug}" );
9308
+ }
9309
+
9310
+ /**
9311
+ * Displays the Support Forum link when enabled.
9312
+ *
9313
+ * Can be filtered like so:
9314
+ *
9315
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
9316
+ * if ( 'support' === $menu_id ) {
9317
+ * return _fs->is_registered();
9318
+ * }
9319
+ * return $is_visible;
9320
+ * }
9321
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
9322
+ *
9323
+ */
9324
+ function _add_default_submenu_items() {
9325
+ if ( ! $this->is_on() ) {
9326
+ return;
9327
+ }
9328
+
9329
+ if ( ! $this->is_activation_mode() ) {
9330
+ $this->add_submenu_link_item(
9331
+ $this->apply_filters( 'support_forum_submenu', $this->get_text( 'support-forum' ) ),
9332
+ $this->get_support_forum_url(),
9333
+ 'wp-support-forum',
9334
+ null,
9335
+ 50,
9336
+ $this->is_submenu_item_visible( 'support' )
9337
+ );
9338
+ }
9339
+ }
9340
+
9341
+ /**
9342
+ * @author Vova Feldman (@svovaf)
9343
+ * @since 1.0.1
9344
+ *
9345
+ * @param string $menu_title
9346
+ * @param callable $render_function
9347
+ * @param bool|string $page_title
9348
+ * @param string $capability
9349
+ * @param bool|string $menu_slug
9350
+ * @param bool|callable $before_render_function
9351
+ * @param int $priority
9352
+ * @param bool $show_submenu
9353
+ * @param string $class Since 1.2.1.5 can add custom classes to menu items.
9354
+ */
9355
+ function add_submenu_item(
9356
+ $menu_title,
9357
+ $render_function,
9358
+ $page_title = false,
9359
+ $capability = 'manage_options',
9360
+ $menu_slug = false,
9361
+ $before_render_function = false,
9362
+ $priority = WP_FS__DEFAULT_PRIORITY,
9363
+ $show_submenu = true,
9364
+ $class = ''
9365
+ ) {
9366
+ $this->_logger->entrance( 'Title = ' . $menu_title );
9367
+
9368
+ if ( $this->is_addon() ) {
9369
+ $parent_fs = $this->get_parent_instance();
9370
+
9371
+ if ( is_object( $parent_fs ) ) {
9372
+ $parent_fs->add_submenu_item(
9373
+ $menu_title,
9374
+ $render_function,
9375
+ $page_title,
9376
+ $capability,
9377
+ $menu_slug,
9378
+ $before_render_function,
9379
+ $priority,
9380
+ $show_submenu,
9381
+ $class
9382
+ );
9383
+
9384
+ return;
9385
+ }
9386
+ }
9387
+
9388
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
9389
+ $this->_menu_items[ $priority ] = array();
9390
+ }
9391
+
9392
+ $this->_menu_items[ $priority ][] = array(
9393
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
9394
+ 'menu_title' => $menu_title,
9395
+ 'capability' => $capability,
9396
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
9397
+ 'render_function' => $render_function,
9398
+ 'before_render_function' => $before_render_function,
9399
+ 'show_submenu' => $show_submenu,
9400
+ 'class' => $class,
9401
+ );
9402
+ }
9403
+
9404
+ /**
9405
+ * @author Vova Feldman (@svovaf)
9406
+ * @since 1.0.1
9407
+ *
9408
+ * @param string $menu_title
9409
+ * @param string $url
9410
+ * @param bool $menu_slug
9411
+ * @param string $capability
9412
+ * @param int $priority
9413
+ * @param bool $show_submenu
9414
+ */
9415
+ function add_submenu_link_item(
9416
+ $menu_title,
9417
+ $url,
9418
+ $menu_slug = false,
9419
+ $capability = 'read',
9420
+ $priority = WP_FS__DEFAULT_PRIORITY,
9421
+ $show_submenu = true
9422
+ ) {
9423
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
9424
+
9425
+ if ( $this->is_addon() ) {
9426
+ $parent_fs = $this->get_parent_instance();
9427
+
9428
+ if ( is_object( $parent_fs ) ) {
9429
+ $parent_fs->add_submenu_link_item(
9430
+ $menu_title,
9431
+ $url,
9432
+ $menu_slug,
9433
+ $capability,
9434
+ $priority,
9435
+ $show_submenu
9436
+ );
9437
+
9438
+ return;
9439
+ }
9440
+ }
9441
+
9442
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
9443
+ $this->_menu_items[ $priority ] = array();
9444
+ }
9445
+
9446
+ $this->_menu_items[ $priority ][] = array(
9447
+ 'menu_title' => $menu_title,
9448
+ 'capability' => $capability,
9449
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
9450
+ 'url' => $url,
9451
+ 'page_title' => $menu_title,
9452
+ 'render_function' => 'fs_dummy',
9453
+ 'before_render_function' => '',
9454
+ 'show_submenu' => $show_submenu,
9455
+ );
9456
+ }
9457
+
9458
+ #endregion ------------------------------------------------------------------
9459
+
9460
+
9461
+ #--------------------------------------------------------------------------------
9462
+ #region Actions / Hooks / Filters
9463
+ #--------------------------------------------------------------------------------
9464
+
9465
+ /**
9466
+ * @author Vova Feldman (@svovaf)
9467
+ * @since 1.1.7
9468
+ *
9469
+ * @param string $tag
9470
+ *
9471
+ * @return string
9472
+ */
9473
+ public function get_action_tag( $tag ) {
9474
+ return self::get_action_tag_static( $tag, $this->_slug, $this->is_plugin() );
9475
+ }
9476
+
9477
+ /**
9478
+ * @author Vova Feldman (@svovaf)
9479
+ * @since 1.2.1.6
9480
+ *
9481
+ * @param string $tag
9482
+ * @param string $slug
9483
+ * @param bool $is_plugin
9484
+ *
9485
+ * @return string
9486
+ */
9487
+ static function get_action_tag_static( $tag, $slug = '', $is_plugin = true ) {
9488
+ $action = "fs_{$tag}";
9489
+
9490
+ if ( ! empty( $slug ) ) {
9491
+ $action .= '_' . self::get_module_unique_affix( $slug, $is_plugin );
9492
+ }
9493
+
9494
+ return $action;
9495
+ }
9496
+
9497
+ /**
9498
+ * Returns a string that can be used to generate a unique action name,
9499
+ * option name, HTML element ID, or HTML element class.
9500
+ *
9501
+ * @author Leo Fajardo (@leorw)
9502
+ * @since 1.2.2
9503
+ *
9504
+ * @return string
9505
+ */
9506
+ public function get_unique_affix() {
9507
+ return self::get_module_unique_affix( $this->_slug, $this->is_plugin() );
9508
+ }
9509
+
9510
+ /**
9511
+ * Returns a string that can be used to generate a unique action name,
9512
+ * option name, HTML element ID, or HTML element class.
9513
+ *
9514
+ * @author Vova Feldman (@svovaf)
9515
+ * @since 1.2.2.5
9516
+ *
9517
+ * @param string $slug
9518
+ * @param bool $is_plugin
9519
+ *
9520
+ * @return string
9521
+ */
9522
+ static function get_module_unique_affix( $slug, $is_plugin = true ) {
9523
+ $affix = $slug;
9524
+
9525
+ if ( ! $is_plugin ) {
9526
+ $affix .= '-' . WP_FS__MODULE_TYPE_THEME;
9527
+ }
9528
+
9529
+ return $affix;
9530
+ }
9531
+
9532
+ /**
9533
+ * @author Vova Feldman (@svovaf)
9534
+ * @since 1.2.1
9535
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
9536
+ * based on the slug for backward compatibility.
9537
+ *
9538
+ * @param string $tag
9539
+ *
9540
+ * @return string
9541
+ */
9542
+ function get_ajax_action( $tag ) {
9543
+ return self::get_ajax_action_static( $tag, $this->_module_id );
9544
+ }
9545
+
9546
+ /**
9547
+ * @author Vova Feldman (@svovaf)
9548
+ * @since 1.2.1.7
9549
+ *
9550
+ * @param string $tag
9551
+ *
9552
+ * @return string
9553
+ */
9554
+ function get_ajax_security( $tag ) {
9555
+ return wp_create_nonce( $this->get_ajax_action( $tag ) );
9556
+ }
9557
+
9558
+ /**
9559
+ * @author Vova Feldman (@svovaf)
9560
+ * @since 1.2.1.7
9561
+ *
9562
+ * @param string $tag
9563
+ */
9564
+ function check_ajax_referer( $tag ) {
9565
+ check_ajax_referer( $this->get_ajax_action( $tag ), 'security' );
9566
+ }
9567
+
9568
+ /**
9569
+ * @author Vova Feldman (@svovaf)
9570
+ * @since 1.2.1.6
9571
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
9572
+ * based on the slug for backward compatibility.
9573
+ *
9574
+ * @param string $tag
9575
+ * @param number|null $module_id
9576
+ *
9577
+ * @return string
9578
+ */
9579
+ private static function get_ajax_action_static( $tag, $module_id = null ) {
9580
+ $action = "fs_{$tag}";
9581
+
9582
+ if ( ! empty( $module_id ) ) {
9583
+ $action .= "_{$module_id}";
9584
+ }
9585
+
9586
+ return $action;
9587
+ }
9588
+
9589
+ /**
9590
+ * Do action, specific for the current context plugin.
9591
+ *
9592
+ * @author Vova Feldman (@svovaf)
9593
+ * @since 1.0.1
9594
+ *
9595
+ * @param string $tag The name of the action to be executed.
9596
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
9597
+ * functions hooked to the action. Default empty.
9598
+ *
9599
+ * @uses do_action()
9600
+ */
9601
+ function do_action( $tag, $arg = '' ) {
9602
+ $this->_logger->entrance( $tag );
9603
+
9604
+ $args = func_get_args();
9605
+
9606
+ call_user_func_array( 'do_action', array_merge(
9607
+ array( $this->get_action_tag( $tag ) ),
9608
+ array_slice( $args, 1 ) )
9609
+ );
9610
+ }
9611
+
9612
+ /**
9613
+ * Add action, specific for the current context plugin.
9614
+ *
9615
+ * @author Vova Feldman (@svovaf)
9616
+ * @since 1.0.1
9617
+ *
9618
+ * @param string $tag
9619
+ * @param callable $function_to_add
9620
+ * @param int $priority
9621
+ * @param int $accepted_args
9622
+ *
9623
+ * @uses add_action()
9624
+ */
9625
+ function add_action(
9626
+ $tag,
9627
+ $function_to_add,
9628
+ $priority = WP_FS__DEFAULT_PRIORITY,
9629
+ $accepted_args = 1
9630
+ ) {
9631
+ $this->_logger->entrance( $tag );
9632
+
9633
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
9634
+ }
9635
+
9636
+ /**
9637
+ * Add AJAX action, specific for the current context plugin.
9638
+ *
9639
+ * @author Vova Feldman (@svovaf)
9640
+ * @since 1.2.1
9641
+ *
9642
+ * @param string $tag
9643
+ * @param callable $function_to_add
9644
+ * @param int $priority
9645
+ *
9646
+ * @uses add_action()
9647
+ *
9648
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
9649
+ */
9650
+ function add_ajax_action(
9651
+ $tag,
9652
+ $function_to_add,
9653
+ $priority = WP_FS__DEFAULT_PRIORITY
9654
+ ) {
9655
+ $this->_logger->entrance( $tag );
9656
+
9657
+ return self::add_ajax_action_static(
9658
+ $tag,
9659
+ $function_to_add,
9660
+ $priority,
9661
+ $this->_module_id
9662
+ );
9663
+ }
9664
+
9665
+ /**
9666
+ * Add AJAX action.
9667
+ *
9668
+ * @author Vova Feldman (@svovaf)
9669
+ * @since 1.2.1.6
9670
+ *
9671
+ * @param string $tag
9672
+ * @param callable $function_to_add
9673
+ * @param int $priority
9674
+ * @param number|null $module_id
9675
+ *
9676
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
9677
+ * @uses add_action()
9678
+ *
9679
+ */
9680
+ static function add_ajax_action_static(
9681
+ $tag,
9682
+ $function_to_add,
9683
+ $priority = WP_FS__DEFAULT_PRIORITY,
9684
+ $module_id = null
9685
+ ) {
9686
+ self::$_static_logger->entrance( $tag );
9687
+
9688
+ if ( ! self::is_ajax_action_static( $tag, $module_id ) ) {
9689
+ return false;
9690
+ }
9691
+
9692
+ add_action(
9693
+ 'wp_ajax_' . self::get_ajax_action_static( $tag, $module_id ),
9694
+ $function_to_add,
9695
+ $priority,
9696
+ 0
9697
+ );
9698
+
9699
+ self::$_static_logger->info( "$tag AJAX callback action added." );
9700
+
9701
+ return true;
9702
+ }
9703
+
9704
+ /**
9705
+ * Send a JSON response back to an Ajax request.
9706
+ *
9707
+ * @author Vova Feldman (@svovaf)
9708
+ * @since 1.2.1.5
9709
+ *
9710
+ * @param mixed $response
9711
+ */
9712
+ static function shoot_ajax_response( $response ) {
9713
+ wp_send_json( $response );
9714
+ }
9715
+
9716
+ /**
9717
+ * Send a JSON response back to an Ajax request, indicating success.
9718
+ *
9719
+ * @author Vova Feldman (@svovaf)
9720
+ * @since 1.2.1.5
9721
+ *
9722
+ * @param mixed $data Data to encode as JSON, then print and exit.
9723
+ */
9724
+ static function shoot_ajax_success( $data = null ) {
9725
+ wp_send_json_success( $data );
9726
+ }
9727
+
9728
+ /**
9729
+ * Send a JSON response back to an Ajax request, indicating failure.
9730
+ *
9731
+ * @author Vova Feldman (@svovaf)
9732
+ * @since 1.2.1.5
9733
+ *
9734
+ * @param mixed $error Optional error message.
9735
+ */
9736
+ static function shoot_ajax_failure( $error = '' ) {
9737
+ $result = array( 'success' => false );
9738
+ if ( ! empty( $error ) ) {
9739
+ $result['error'] = $error;
9740
+ }
9741
+
9742
+ wp_send_json( $result );
9743
+ }
9744
+
9745
+ /**
9746
+ * Apply filter, specific for the current context plugin.
9747
+ *
9748
+ * @author Vova Feldman (@svovaf)
9749
+ * @since 1.0.9
9750
+ *
9751
+ * @param string $tag The name of the filter hook.
9752
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
9753
+ *
9754
+ * @return mixed The filtered value after all hooked functions are applied to it.
9755
+ *
9756
+ * @uses apply_filters()
9757
+ */
9758
+ function apply_filters( $tag, $value ) {
9759
+ $this->_logger->entrance( $tag );
9760
+
9761
+ $args = func_get_args();
9762
+ array_unshift( $args, $this->get_unique_affix() );
9763
+
9764
+ return call_user_func_array( 'fs_apply_filter', $args );
9765
+ }
9766
+
9767
+ /**
9768
+ * Add filter, specific for the current context plugin.
9769
+ *
9770
+ * @author Vova Feldman (@svovaf)
9771
+ * @since 1.0.9
9772
+ *
9773
+ * @param string $tag
9774
+ * @param callable $function_to_add
9775
+ * @param int $priority
9776
+ * @param int $accepted_args
9777
+ *
9778
+ * @uses add_filter()
9779
+ */
9780
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
9781
+ $this->_logger->entrance( $tag );
9782
+
9783
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
9784
+ }
9785
+
9786
+ /**
9787
+ * Check if has filter.
9788
+ *
9789
+ * @author Vova Feldman (@svovaf)
9790
+ * @since 1.1.4
9791
+ *
9792
+ * @param string $tag
9793
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
9794
+ *
9795
+ * @return false|int
9796
+ *
9797
+ * @uses has_filter()
9798
+ */
9799
+ function has_filter( $tag, $function_to_check = false ) {
9800
+ $this->_logger->entrance( $tag );
9801
+
9802
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
9803
+ }
9804
+
9805
+ #endregion
9806
+
9807
+ /**
9808
+ * Override default i18n text phrases.
9809
+ *
9810
+ * @author Vova Feldman (@svovaf)
9811
+ * @since 1.1.6
9812
+ *
9813
+ * @param string[] string $key_value
9814
+ *
9815
+ * @uses fs_override_i18n()
9816
+ */
9817
+ function override_i18n( $key_value ) {
9818
+ fs_override_i18n( $key_value, $this->_slug );
9819
+ }
9820
+
9821
+ /* Account Page
9822
+ ------------------------------------------------------------------------------------------------------------------*/
9823
+ /**
9824
+ * Update site information.
9825
+ *
9826
+ * @author Vova Feldman (@svovaf)
9827
+ * @since 1.0.1
9828
+ *
9829
+ * @param bool $store Flush to Database if true.
9830
+ */
9831
+ private function _store_site( $store = true ) {
9832
+ $this->_logger->entrance();
9833
+
9834
+ if ( empty( $this->_site->id ) ) {
9835
+ $this->_logger->error( "Empty install ID, can't store site." );
9836
+
9837
+ return;
9838
+ }
9839
+
9840
+ $encrypted_site = clone $this->_site;
9841
+ $encrypted_site->plan = self::_encrypt_entity( $this->_site->plan );
9842
+
9843
+ $sites = self::get_all_sites( $this->_module_type );
9844
+ $sites[ $this->_slug ] = $encrypted_site;
9845
+
9846
+ $this->set_account_option( 'sites', $sites, $store );
9847
+ }
9848
+
9849
+ /**
9850
+ * Update plugin's plans information.
9851
+ *
9852
+ * @author Vova Feldman (@svovaf)
9853
+ * @since 1.0.2
9854
+ *
9855
+ * @param bool $store Flush to Database if true.
9856
+ */
9857
+ private function _store_plans( $store = true ) {
9858
+ $this->_logger->entrance();
9859
+
9860
+ $plans = self::get_all_plans( $this->_module_type );
9861
+
9862
+ // Copy plans.
9863
+ $encrypted_plans = array();
9864
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
9865
+ $encrypted_plans[] = self::_encrypt_entity( $this->_plans[ $i ] );
9866
+ }
9867
+
9868
+ $plans[ $this->_slug ] = $encrypted_plans;
9869
+
9870
+ $this->set_account_option( 'plans', $plans, $store );
9871
+ }
9872
+
9873
+ /**
9874
+ * Update user's plugin licenses.
9875
+ *
9876
+ * @author Vova Feldman (@svovaf)
9877
+ * @since 1.0.5
9878
+ *
9879
+ * @param bool $store
9880
+ * @param string|bool $plugin_slug
9881
+ * @param FS_Plugin_License[] $licenses
9882
+ */
9883
+ private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
9884
+ $this->_logger->entrance();
9885
+
9886
+ $all_licenses = self::get_all_licenses( $this->_module_type );
9887
+
9888
+ if ( ! is_string( $plugin_slug ) ) {
9889
+ $plugin_slug = $this->_slug;
9890
+ $licenses = $this->_licenses;
9891
+ }
9892
+
9893
+ if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
9894
+ $all_licenses[ $plugin_slug ] = array();
9895
+ }
9896
+
9897
+ $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
9898
+
9899
+ $this->set_account_option( 'licenses', $all_licenses, $store );
9900
+ }
9901
+
9902
+ /**
9903
+ * Update user information.
9904
+ *
9905
+ * @author Vova Feldman (@svovaf)
9906
+ * @since 1.0.1
9907
+ *
9908
+ * @param bool $store Flush to Database if true.
9909
+ */
9910
+ private function _store_user( $store = true ) {
9911
+ $this->_logger->entrance();
9912
+
9913
+ if ( empty( $this->_user->id ) ) {
9914
+ $this->_logger->error( "Empty user ID, can't store user." );
9915
+
9916
+ return;
9917
+ }
9918
+
9919
+ $users = self::get_all_users();
9920
+ $users[ $this->_user->id ] = $this->_user;
9921
+ self::$_accounts->set_option( 'users', $users, $store );
9922
+ }
9923
+
9924
+ /**
9925
+ * Update new updates information.
9926
+ *
9927
+ * @author Vova Feldman (@svovaf)
9928
+ * @since 1.0.4
9929
+ *
9930
+ * @param FS_Plugin_Tag|null $update
9931
+ * @param bool $store Flush to Database if true.
9932
+ * @param bool|number $plugin_id
9933
+ */
9934
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
9935
+ $this->_logger->entrance();
9936
+
9937
+ if ( $update instanceof FS_Plugin_Tag ) {
9938
+ $update->updated = time();
9939
+ }
9940
+
9941
+ if ( ! is_numeric( $plugin_id ) ) {
9942
+ $plugin_id = $this->_plugin->id;
9943
+ }
9944
+
9945
+ $updates = self::get_all_updates();
9946
+ $updates[ $plugin_id ] = $update;
9947
+ self::$_accounts->set_option( 'updates', $updates, $store );
9948
+ }
9949
+
9950
+ /**
9951
+ * Update new updates information.
9952
+ *
9953
+ * @author Vova Feldman (@svovaf)
9954
+ * @since 1.0.6
9955
+ *
9956
+ * @param FS_Plugin[] $plugin_addons
9957
+ * @param bool $store Flush to Database if true.
9958
+ */
9959
+ private function _store_addons( $plugin_addons, $store = true ) {
9960
+ $this->_logger->entrance();
9961
+
9962
+ $addons = self::get_all_addons();
9963
+ $addons[ $this->_plugin->id ] = $plugin_addons;
9964
+ self::$_accounts->set_option( 'addons', $addons, $store );
9965
+ }
9966
+
9967
+ /**
9968
+ * Delete plugin's associated add-ons.
9969
+ *
9970
+ * @author Vova Feldman (@svovaf)
9971
+ * @since 1.0.8
9972
+ *
9973
+ * @param bool $store
9974
+ *
9975
+ * @return bool
9976
+ */
9977
+ private function _delete_account_addons( $store = true ) {
9978
+ $all_addons = self::get_all_account_addons();
9979
+
9980
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
9981
+ return false;
9982
+ }
9983
+
9984
+ unset( $all_addons[ $this->_plugin->id ] );
9985
+
9986
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
9987
+
9988
+ return true;
9989
+ }
9990
+
9991
+ /**
9992
+ * Update account add-ons list.
9993
+ *
9994
+ * @author Vova Feldman (@svovaf)
9995
+ * @since 1.0.6
9996
+ *
9997
+ * @param FS_Plugin[] $addons
9998
+ * @param bool $store Flush to Database if true.
9999
+ */
10000
+ private function _store_account_addons( $addons, $store = true ) {
10001
+ $this->_logger->entrance();
10002
+
10003
+ $all_addons = self::get_all_account_addons();
10004
+ $all_addons[ $this->_plugin->id ] = $addons;
10005
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
10006
+ }
10007
+
10008
+ /**
10009
+ * Store account params in the Database.
10010
+ *
10011
+ * @author Vova Feldman (@svovaf)
10012
+ * @since 1.0.1
10013
+ */
10014
+ private function _store_account() {
10015
+ $this->_logger->entrance();
10016
+
10017
+ $this->_store_site( false );
10018
+ $this->_store_user( false );
10019
+ $this->_store_plans( false );
10020
+ $this->_store_licenses( false );
10021
+
10022
+ self::$_accounts->store();
10023
+ }
10024
+
10025
+ /**
10026
+ * Sync user's information.
10027
+ *
10028
+ * @author Vova Feldman (@svovaf)
10029
+ * @since 1.0.3
10030
+ * @uses FS_Api
10031
+ */
10032
+ private function _handle_account_user_sync() {
10033
+ $this->_logger->entrance();
10034
+
10035
+ $api = $this->get_api_user_scope();
10036
+
10037
+ // Get user's information.
10038
+ $user = $api->get( '/', true );
10039
+
10040
+ if ( isset( $user->id ) ) {
10041
+ $this->_user->first = $user->first;
10042
+ $this->_user->last = $user->last;
10043
+ $this->_user->email = $user->email;
10044
+
10045
+ $is_menu_item_account_visible = $this->is_submenu_item_visible( 'account' );
10046
+
10047
+ if ( $user->is_verified &&
10048
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
10049
+ ) {
10050
+ $this->_user->is_verified = true;
10051
+
10052
+ $this->do_action( 'account_email_verified', $user->email );
10053
+
10054
+ $this->_admin_notices->add(
10055
+ $this->get_text( 'email-verified-message' ),
10056
+ $this->get_text( 'right-on' ) . '!',
10057
+ 'success',
10058
+ // Make admin sticky if account menu item is invisible,
10059
+ // since the page will be auto redirected to the plugin's
10060
+ // main settings page, and the non-sticky message
10061
+ // will disappear.
10062
+ ! $is_menu_item_account_visible,
10063
+ false,
10064
+ 'email_verified'
10065
+ );
10066
+ }
10067
+
10068
+ // Flush user details to DB.
10069
+ $this->_store_user();
10070
+
10071
+ $this->do_action( 'after_account_user_sync', $user );
10072
+
10073
+ /**
10074
+ * If account menu item is hidden, redirect to plugin's main settings page.
10075
+ *
10076
+ * @author Vova Feldman (@svovaf)
10077
+ * @since 1.1.6
10078
+ *
10079
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
10080
+ */
10081
+ if ( ! $is_menu_item_account_visible ) {
10082
+ fs_redirect( $this->_get_admin_page_url() );
10083
+ }
10084
+ }
10085
+ }
10086
+
10087
+ /**
10088
+ * @param bool $store
10089
+ *
10090
+ * @return FS_Plugin_Plan|object|false
10091
+ */
10092
+ private function _enrich_site_plan( $store = true ) {
10093
+ // Try to load plan from local cache.
10094
+ $plan = $this->_get_plan_by_id( $this->_site->plan->id );
10095
+
10096
+ if ( false === $plan ) {
10097
+ $plan = $this->_fetch_site_plan();
10098
+ }
10099
+
10100
+ if ( $plan instanceof FS_Plugin_Plan ) {
10101
+ $this->_update_plan( $plan, $store );
10102
+ }
10103
+
10104
+ return $plan;
10105
+ }
10106
+
10107
+ /**
10108
+ * @author Vova Feldman (@svovaf)
10109
+ * @since 1.0.9
10110
+ * @uses FS_Api
10111
+ *
10112
+ * @param bool $store
10113
+ *
10114
+ * @return FS_Plugin_Plan|object|false
10115
+ */
10116
+ private function _enrich_site_trial_plan( $store = true ) {
10117
+ // Try to load plan from local cache.
10118
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
10119
+
10120
+ if ( false === $trial_plan ) {
10121
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
10122
+ }
10123
+
10124
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
10125
+ $this->_storage->store( 'trial_plan', $trial_plan, $store );
10126
+ }
10127
+
10128
+ return $trial_plan;
10129
+ }
10130
+
10131
+ /**
10132
+ * @author Vova Feldman (@svovaf)
10133
+ * @since 1.0.9
10134
+ * @uses FS_Api
10135
+ *
10136
+ * @param number|bool $license_id
10137
+ *
10138
+ * @return FS_Subscription|object|bool
10139
+ */
10140
+ private function _fetch_site_license_subscription( $license_id = false ) {
10141
+ $this->_logger->entrance();
10142
+ $api = $this->get_api_site_scope();
10143
+
10144
+ if ( ! is_numeric( $license_id ) ) {
10145
+ $license_id = $this->_license->id;
10146
+ }
10147
+
10148
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
10149
+
10150
+ return ! isset( $result->error ) ?
10151
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
10152
+ new FS_Subscription( $result->subscriptions[0] ) :
10153
+ false
10154
+ ) :
10155
+ $result;
10156
+ }
10157
+
10158
+ /**
10159
+ * @author Vova Feldman (@svovaf)
10160
+ * @since 1.0.4
10161
+ * @uses FS_Api
10162
+ *
10163
+ * @param number|bool $plan_id
10164
+ *
10165
+ * @return FS_Plugin_Plan|object
10166
+ */
10167
+ private function _fetch_site_plan( $plan_id = false ) {
10168
+ $this->_logger->entrance();
10169
+ $api = $this->get_api_site_scope();
10170
+
10171
+ if ( ! is_numeric( $plan_id ) ) {
10172
+ $plan_id = $this->_site->plan->id;
10173
+ }
10174
+
10175
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
10176
+
10177
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
10178
+ }
10179
+
10180
+ /**
10181
+ * @author Vova Feldman (@svovaf)
10182
+ * @since 1.0.5
10183
+ * @uses FS_Api
10184
+ *
10185
+ * @return FS_Plugin_Plan[]|object
10186
+ */
10187
+ private function _fetch_plugin_plans() {
10188
+ $this->_logger->entrance();
10189
+ $api = $this->get_api_site_scope();
10190
+
10191
+ $result = $api->get( '/plans.json', true );
10192
+
10193
+ if ( $this->is_api_result_object( $result, 'plans' ) && is_array( $result->plans ) ) {
10194
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
10195
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
10196
+ }
10197
+
10198
+ $result = $result->plans;
10199
+ }
10200
+
10201
+ return $result;
10202
+ }
10203
+
10204
+ /**
10205
+ * @author Vova Feldman (@svovaf)
10206
+ * @since 1.0.5
10207
+ * @uses FS_Api
10208
+ *
10209
+ * @param number|bool $plugin_id
10210
+ * @param number|bool $site_license_id
10211
+ *
10212
+ * @return FS_Plugin_License[]|object
10213
+ */
10214
+ private function _fetch_licenses( $plugin_id = false, $site_license_id = false ) {
10215
+ $this->_logger->entrance();
10216
+
10217
+ $api = $this->get_api_user_scope();
10218
+
10219
+ if ( ! is_numeric( $plugin_id ) ) {
10220
+ $plugin_id = $this->_plugin->id;
10221
+ }
10222
+
10223
+ $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
10224
+
10225
+ $is_site_license_synced = false;
10226
+
10227
+ $api_errors = array();
10228
+
10229
+ if ( $this->is_api_result_object( $result, 'licenses' ) &&
10230
+ is_array( $result->licenses )
10231
+ ) {
10232
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
10233
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
10234
+
10235
+ if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
10236
+ $is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
10237
+ }
10238
+ }
10239
+
10240
+ $result = $result->licenses;
10241
+ } else {
10242
+ $api_errors[] = $result;
10243
+ $result = array();
10244
+ }
10245
+
10246
+ if ( ! $is_site_license_synced ) {
10247
+ $api = $this->get_api_site_scope();
10248
+
10249
+ if ( is_numeric( $site_license_id ) ) {
10250
+ // Try to retrieve a foreign license that is linked to the install.
10251
+ $api_result = $api->call( '/licenses.json' );
10252
+
10253
+ if ( $this->is_api_result_object( $api_result, 'licenses' ) &&
10254
+ is_array( $api_result->licenses )
10255
+ ) {
10256
+ $licenses = $api_result->licenses;
10257
+
10258
+ if ( ! empty( $licenses ) ) {
10259
+ $result[] = new FS_Plugin_License( $licenses[0] );
10260
+ }
10261
+ } else {
10262
+ $api_errors[] = $api_result;
10263
+ }
10264
+ } else if ( is_object( $this->_license ) ) {
10265
+ // Fetch foreign license by ID and license key.
10266
+ $license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
10267
+ urlencode( $this->_license->secret_key ) );
10268
+
10269
+ if ( $this->is_api_result_entity( $license ) ) {
10270
+ $result[] = new FS_Plugin_License( $license );
10271
+ } else {
10272
+ $api_errors[] = $license;
10273
+ }
10274
+ }
10275
+ }
10276
+
10277
+ if ( is_array( $result ) && 0 < count( $result ) ) {
10278
+ // If found at least one license, return license collection even if there are errors.
10279
+ return $result;
10280
+ }
10281
+
10282
+ if ( ! empty( $api_errors ) ) {
10283
+ // If found any errors and no licenses, return first error.
10284
+ return $api_errors[0];
10285
+ }
10286
+
10287
+ // Fallback to empty licenses list.
10288
+ return $result;
10289
+ }
10290
+
10291
+ /**
10292
+ * @author Vova Feldman (@svovaf)
10293
+ * @since 1.2.0
10294
+ * @uses FS_Api
10295
+ *
10296
+ * @param number|bool $plugin_id
10297
+ * @param bool $flush
10298
+ *
10299
+ * @return FS_Payment[]|object
10300
+ */
10301
+ function _fetch_payments( $plugin_id = false, $flush = false ) {
10302
+ $this->_logger->entrance();
10303
+
10304
+ $api = $this->get_api_user_scope();
10305
+
10306
+ if ( ! is_numeric( $plugin_id ) ) {
10307
+ $plugin_id = $this->_plugin->id;
10308
+ }
10309
+
10310
+ $result = $api->get( "/plugins/{$plugin_id}/payments.json?include_addons=true", $flush );
10311
+
10312
+ if ( ! isset( $result->error ) ) {
10313
+ for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
10314
+ $result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
10315
+ }
10316
+ $result = $result->payments;
10317
+ }
10318
+
10319
+ return $result;
10320
+ }
10321
+
10322
+ /**
10323
+ * @author Vova Feldman (@svovaf)
10324
+ * @since 1.2.1.5
10325
+ * @uses FS_Api
10326
+ *
10327
+ * @param bool $flush
10328
+ *
10329
+ * @return \FS_Billing|mixed
10330
+ */
10331
+ function _fetch_billing( $flush = false ) {
10332
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-billing.php';
10333
+
10334
+ $billing = $this->get_api_user_scope()->get( 'billing.json', $flush );
10335
+
10336
+ if ( $this->is_api_result_entity( $billing ) ) {
10337
+ $billing = new FS_Billing( $billing );
10338
+ }
10339
+
10340
+ return $billing;
10341
+ }
10342
+
10343
+ /**
10344
+ * @author Vova Feldman (@svovaf)
10345
+ * @since 1.0.4
10346
+ *
10347
+ * @param FS_Plugin_Plan $plan
10348
+ * @param bool $store
10349
+ */
10350
+ private function _update_plan( $plan, $store = false ) {
10351
+ $this->_logger->entrance();
10352
+
10353
+ $this->_site->plan = $plan;
10354
+ $this->_store_site( $store );
10355
+ }
10356
+
10357
+ /**
10358
+ * @author Vova Feldman (@svovaf)
10359
+ * @since 1.0.5
10360
+ *
10361
+ * @param FS_Plugin_License[] $licenses
10362
+ * @param string|bool $plugin_slug
10363
+ */
10364
+ private function _update_licenses( $licenses, $plugin_slug = false ) {
10365
+ $this->_logger->entrance();
10366
+
10367
+ if ( is_array( $licenses ) ) {
10368
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
10369
+ $licenses[ $i ]->updated = time();
10370
+ }
10371
+ }
10372
+
10373
+ if ( ! is_string( $plugin_slug ) ) {
10374
+ $this->_licenses = $licenses;
10375
+ }
10376
+
10377
+ $this->_store_licenses( true, $plugin_slug, $licenses );
10378
+ }
10379
+
10380
+ /**
10381
+ * @author Vova Feldman (@svovaf)
10382
+ * @since 1.0.4
10383
+ *
10384
+ * @param bool|number $plugin_id
10385
+ * @param bool $flush Since 1.1.7.3
10386
+ * @param int $expiration Since 1.2.2.7
10387
+ *
10388
+ * @return object|false New plugin tag info if exist.
10389
+ */
10390
+ private function _fetch_newer_version( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
10391
+ $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush, $expiration );
10392
+
10393
+ if ( ! is_object( $latest_tag ) ) {
10394
+ return false;
10395
+ }
10396
+
10397
+ // Check if version is actually newer.
10398
+ $has_new_version =
10399
+ // If it's an non-installed add-on then always return latest.
10400
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
10401
+ // Compare versions.
10402
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
10403
+
10404
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
10405
+
10406
+ return $has_new_version ? $latest_tag : false;
10407
+ }
10408
+
10409
+ /**
10410
+ * @author Vova Feldman (@svovaf)
10411
+ * @since 1.0.5
10412
+ *
10413
+ * @param bool|number $plugin_id
10414
+ * @param bool $flush Since 1.1.7.3
10415
+ * @param int $expiration Since 1.2.2.7
10416
+ *
10417
+ * @return bool|FS_Plugin_Tag
10418
+ */
10419
+ function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
10420
+ $this->_logger->entrance();
10421
+
10422
+ if ( ! is_numeric( $plugin_id ) ) {
10423
+ $plugin_id = $this->_plugin->id;
10424
+ }
10425
+
10426
+ $this->check_updates( true, $plugin_id, $flush, $expiration );
10427
+ $updates = $this->get_all_updates();
10428
+
10429
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
10430
+ }
10431
+
10432
+ /**
10433
+ * Check if site assigned with active license.
10434
+ *
10435
+ * @author Vova Feldman (@svovaf)
10436
+ * @since 1.0.6
10437
+ *
10438
+ * @deprecated Please use has_active_valid_license() instead because license can be cancelled.
10439
+ */
10440
+ function has_active_license() {
10441
+ return (
10442
+ is_object( $this->_license ) &&
10443
+ is_numeric( $this->_license->id ) &&
10444
+ ! $this->_license->is_expired()
10445
+ );
10446
+ }
10447
+
10448
+ /**
10449
+ * Check if site assigned with active & valid (not expired) license.
10450
+ *
10451
+ * @author Vova Feldman (@svovaf)
10452
+ * @since 1.2.1
10453
+ */
10454
+ function has_active_valid_license() {
10455
+ return (
10456
+ is_object( $this->_license ) &&
10457
+ is_numeric( $this->_license->id ) &&
10458
+ $this->_license->is_active() &&
10459
+ $this->_license->is_valid()
10460
+ );
10461
+ }
10462
+
10463
+ /**
10464
+ * Check if site assigned with license with enabled features.
10465
+ *
10466
+ * @author Vova Feldman (@svovaf)
10467
+ * @since 1.0.6
10468
+ *
10469
+ * @return bool
10470
+ */
10471
+ function has_features_enabled_license() {
10472
+ return (
10473
+ is_object( $this->_license ) &&
10474
+ is_numeric( $this->_license->id ) &&
10475
+ $this->_license->is_features_enabled()
10476
+ );
10477
+ }
10478
+
10479
+ /**
10480
+ * Check if user is a trial or have feature enabled license.
10481
+ *
10482
+ * @author Vova Feldman (@svovaf)
10483
+ * @since 1.1.7
10484
+ *
10485
+ * @return bool
10486
+ */
10487
+ function can_use_premium_code() {
10488
+ return $this->is_trial() || $this->has_features_enabled_license();
10489
+ }
10490
+
10491
+ /**
10492
+ * Checks if the current user can activate plugins or switch themes. Note that this method should only be used
10493
+ * after the `init` action is triggered because it is using `current_user_can()` which is only functional after
10494
+ * the context user is authenticated.
10495
+ *
10496
+ * @author Leo Fajardo (@leorw)
10497
+ * @since 1.2.2
10498
+ *
10499
+ * @return bool
10500
+ */
10501
+ function is_user_admin() {
10502
+ return ( $this->is_plugin() && current_user_can( 'activate_plugins' ) )
10503
+ || ( $this->is_theme() && current_user_can( 'switch_themes' ) );
10504
+ }
10505
+
10506
+ /**
10507
+ * Sync site's plan.
10508
+ *
10509
+ * @author Vova Feldman (@svovaf)
10510
+ * @since 1.0.3
10511
+ *
10512
+ * @uses FS_Api
10513
+ *
10514
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
10515
+ * the admin.
10516
+ */
10517
+ private function _sync_license( $background = false ) {
10518
+ $this->_logger->entrance();
10519
+
10520
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
10521
+
10522
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
10523
+
10524
+ if ( $is_addon_sync ) {
10525
+ $this->_sync_addon_license( $plugin_id, $background );
10526
+ } else {
10527
+ $this->_sync_plugin_license( $background );
10528
+ }
10529
+
10530
+ $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
10531
+ }
10532
+
10533
+ /**
10534
+ * Sync plugin's add-on license.
10535
+ *
10536
+ * @author Vova Feldman (@svovaf)
10537
+ * @since 1.0.6
10538
+ * @uses FS_Api
10539
+ *
10540
+ * @param number $addon_id
10541
+ * @param bool $background
10542
+ */
10543
+ private function _sync_addon_license( $addon_id, $background ) {
10544
+ $this->_logger->entrance();
10545
+
10546
+ if ( $this->is_addon_activated( $addon_id ) ) {
10547
+ // If already installed, use add-on sync.
10548
+ $fs_addon = self::get_instance_by_id( $addon_id );
10549
+ $fs_addon->_sync_license( $background );
10550
+
10551
+ return;
10552
+ }
10553
+
10554
+ // Validate add-on exists.
10555
+ $addon = $this->get_addon( $addon_id );
10556
+
10557
+ if ( ! is_object( $addon ) ) {
10558
+ return;
10559
+ }
10560
+
10561
+ // Add add-on into account add-ons.
10562
+ $account_addons = $this->get_account_addons();
10563
+ if ( ! is_array( $account_addons ) ) {
10564
+ $account_addons = array();
10565
+ }
10566
+ $account_addons[] = $addon->id;
10567
+ $account_addons = array_unique( $account_addons );
10568
+ $this->_store_account_addons( $account_addons );
10569
+
10570
+ // Load add-on licenses.
10571
+ $licenses = $this->_fetch_licenses( $addon->id );
10572
+
10573
+ // Sync add-on licenses.
10574
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
10575
+ $this->_update_licenses( $licenses, $addon->slug );
10576
+
10577
+ if ( ! $this->is_addon_installed( $addon->id ) && FS_License_Manager::has_premium_license( $licenses ) ) {
10578
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
10579
+
10580
+ if ( ! isset( $plans_result->error ) ) {
10581
+ $plans = array();
10582
+ foreach ( $plans_result->plans as $plan ) {
10583
+ $plans[] = new FS_Plugin_Plan( $plan );
10584
+ }
10585
+
10586
+ $this->_admin_notices->add_sticky(
10587
+ FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
10588
+ sprintf(
10589
+ $this->get_text( 'addon-successfully-upgraded-message' ),
10590
+ $addon->title
10591
+ ) . ' ' . $this->get_latest_download_link(
10592
+ $this->get_text( 'download-latest-version' ),
10593
+ $addon_id
10594
+ )
10595
+ :
10596
+ sprintf(
10597
+ $this->get_text( 'addon-successfully-purchased-message' ),
10598
+ $addon->title
10599
+ ) . ' ' . $this->get_latest_download_link(
10600
+ $this->get_text( 'download-latest-version' ),
10601
+ $addon_id
10602
+ ),
10603
+ 'addon_plan_upgraded_' . $addon->slug,
10604
+ $this->get_text( 'yee-haw' ) . '!'
10605
+ );
10606
+ }
10607
+ }
10608
+ }
10609
+ }
10610
+
10611
+ /**
10612
+ * Sync site's plugin plan.
10613
+ *
10614
+ * @author Vova Feldman (@svovaf)
10615
+ * @since 1.0.6
10616
+ * @uses FS_Api
10617
+ *
10618
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
10619
+ * the admin.
10620
+ */
10621
+ private function _sync_plugin_license( $background = false ) {
10622
+ $this->_logger->entrance();
10623
+
10624
+ /**
10625
+ * Sync site info.
10626
+ *
10627
+ * @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.
10628
+ */
10629
+ $site = $this->send_install_update( array(), true );
10630
+
10631
+ $plan_change = 'none';
10632
+
10633
+ if ( ! $this->is_api_result_entity( $site ) ) {
10634
+ // Show API messages only if not background sync or if paying customer.
10635
+ if ( ! $background || $this->is_paying() ) {
10636
+ // Try to ping API to see if not blocked.
10637
+ if ( ! FS_Api::test() ) {
10638
+ /**
10639
+ * Failed to ping API - blocked!
10640
+ *
10641
+ * @author Vova Feldman (@svovaf)
10642
+ * @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.
10643
+ */
10644
+ $api = $this->get_api_site_scope();
10645
+
10646
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
10647
+ self::$_global_admin_notices->add(
10648
+ sprintf(
10649
+ $this->get_text( 'server-blocking-access' ),
10650
+ $this->get_plugin_name(),
10651
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
10652
+ ) . '<br> ' . $this->get_text( 'server-error-message' ) . var_export( $site->error, true ),
10653
+ $this->get_text( 'oops' ) . '...',
10654
+ 'error',
10655
+ $background,
10656
+ false,
10657
+ 'api_blocked'
10658
+ );
10659
+ }
10660
+ } else {
10661
+ // Authentication params are broken.
10662
+ $this->_admin_notices->add(
10663
+ $this->get_text( 'wrong-authentication-param-message' ),
10664
+ $this->get_text( 'oops' ) . '...',
10665
+ 'error'
10666
+ );
10667
+ }
10668
+ }
10669
+
10670
+ // No reason to continue with license sync while there are API issues.
10671
+ return;
10672
+ }
10673
+
10674
+ // Remove sticky API connectivity message.
10675
+ self::$_global_admin_notices->remove_sticky( 'api_blocked' );
10676
+
10677
+ $site = new FS_Site( $site );
10678
+
10679
+ // Sync plans.
10680
+ $this->_sync_plans();
10681
+
10682
+ if ( ! $this->has_paid_plan() ) {
10683
+ $this->_site = $site;
10684
+ $this->_enrich_site_plan( true );
10685
+ $this->_store_site();
10686
+ } else {
10687
+ /**
10688
+ * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
10689
+ * associated with that ID is not included in the user's licenses collection.
10690
+ */
10691
+ $this->_sync_licenses( $site->license_id );
10692
+
10693
+ // Check if plan / license changed.
10694
+ if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
10695
+ // Check if trial started.
10696
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
10697
+ $site->trial_ends != $this->_site->trial_ends ||
10698
+ // Check if license changed.
10699
+ $site->license_id != $this->_site->license_id
10700
+ ) {
10701
+ if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
10702
+ // New trial started.
10703
+ $this->_site = $site;
10704
+ $plan_change = 'trial_started';
10705
+
10706
+ // Store trial plan information.
10707
+ $this->_enrich_site_trial_plan( true );
10708
+
10709
+ // For trial with subscription use-case.
10710
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
10711
+
10712
+ if ( is_object( $new_license ) && $new_license->is_valid() ) {
10713
+ $this->_site = $site;
10714
+ $this->_update_site_license( $new_license );
10715
+ $this->_store_licenses();
10716
+ $this->_enrich_site_plan( true );
10717
+
10718
+ $this->_sync_site_subscription( $this->_license );
10719
+ }
10720
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
10721
+ // Was in trial, but now trial expired and no license ID.
10722
+ // New trial started.
10723
+ $this->_site = $site;
10724
+ $plan_change = 'trial_expired';
10725
+
10726
+ // Clear trial plan information.
10727
+ $this->_storage->trial_plan = null;
10728
+
10729
+ } else {
10730
+ $is_free = $this->is_free_plan();
10731
+
10732
+ // Make sure license exist and not expired.
10733
+ $new_license = is_null( $site->license_id ) ?
10734
+ null :
10735
+ $this->_get_license_by_id( $site->license_id );
10736
+
10737
+ if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
10738
+ // License cancelled.
10739
+ $this->_site = $site;
10740
+ $this->_update_site_license( $new_license );
10741
+ $this->_store_licenses();
10742
+ $this->_enrich_site_plan( true );
10743
+
10744
+ $plan_change = 'cancelled';
10745
+ } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
10746
+ // The license is expired, so ignore upgrade method.
10747
+ } else {
10748
+ // License changed.
10749
+ $this->_site = $site;
10750
+ $this->_update_site_license( $new_license );
10751
+ $this->_store_licenses();
10752
+ $this->_enrich_site_plan( true );
10753
+
10754
+ $plan_change = $is_free ?
10755
+ 'upgraded' :
10756
+ ( is_object( $new_license ) ?
10757
+ 'changed' :
10758
+ 'downgraded' );
10759
+ }
10760
+ }
10761
+
10762
+ // Store updated site info.
10763
+ $this->_store_site();
10764
+ } else {
10765
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
10766
+ if ( ! $this->has_features_enabled_license() ) {
10767
+ $this->_deactivate_license();
10768
+ $plan_change = 'downgraded';
10769
+ } else {
10770
+ $plan_change = 'expired';
10771
+ }
10772
+ }
10773
+
10774
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
10775
+ $this->_sync_site_subscription( $this->_license );
10776
+ }
10777
+ }
10778
+ }
10779
+
10780
+ if ( $this->has_paid_plan() ) {
10781
+ switch ( $plan_change ) {
10782
+ case 'none':
10783
+ if ( ! $background && is_admin() ) {
10784
+ $plan = $this->is_trial() ?
10785
+ $this->_storage->trial_plan :
10786
+ $this->_site->plan;
10787
+
10788
+ if ( $plan->is_free() ) {
10789
+ $this->_admin_notices->add(
10790
+ sprintf(
10791
+ $this->get_text( 'plan-did-not-change-message' ),
10792
+ '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . $this->get_text( 'trial' ) : '' ) . '</b></i>'
10793
+ ) . ' ' . sprintf(
10794
+ '<a href="%s">%s</a>',
10795
+ $this->contact_url(
10796
+ 'bug',
10797
+ sprintf( $this->get_text( 'plan-did-not-change-email-message' ),
10798
+ strtoupper( $plan->name )
10799
+ )
10800
+ ),
10801
+ $this->get_text( 'contact-us-here' )
10802
+ ),
10803
+ $this->get_text( 'hmm' ) . '...'
10804
+ );
10805
+ }
10806
+ }
10807
+ break;
10808
+ case 'upgraded':
10809
+ $this->_admin_notices->add_sticky(
10810
+ sprintf(
10811
+ $this->get_text( 'plan-upgraded-message' ),
10812
+ '<i>' . $this->get_plugin_name() . '</i>'
10813
+ ) . $this->get_complete_upgrade_instructions(),
10814
+ 'plan_upgraded',
10815
+ $this->get_text( 'yee-haw' ) . '!'
10816
+ );
10817
+
10818
+ $this->_admin_notices->remove_sticky( array(
10819
+ 'trial_started',
10820
+ 'trial_promotion',
10821
+ 'trial_expired',
10822
+ 'activation_complete',
10823
+ ) );
10824
+ break;
10825
+ case 'changed':
10826
+ $this->_admin_notices->add_sticky(
10827
+ sprintf(
10828
+ $this->get_text( 'plan-changed-to-x-message' ),
10829
+ $this->_site->plan->title
10830
+ ),
10831
+ 'plan_changed'
10832
+ );
10833
+
10834
+ $this->_admin_notices->remove_sticky( array(
10835
+ 'trial_started',
10836
+ 'trial_promotion',
10837
+ 'trial_expired',
10838
+ 'activation_complete',
10839
+ ) );
10840
+ break;
10841
+ case 'downgraded':
10842
+ $this->_admin_notices->add_sticky(
10843
+ sprintf( $this->get_text( 'license-expired-blocking-message' ), $this->_module_type ),
10844
+ 'license_expired',
10845
+ $this->get_text( 'hmm' ) . '...'
10846
+ );
10847
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
10848
+ break;
10849
+ case 'cancelled':
10850
+ $this->_admin_notices->add(
10851
+ $this->get_text( 'license-cancelled' ) . ' ' .
10852
+ sprintf(
10853
+ '<a href="%s">%s</a>',
10854
+ $this->contact_url( 'bug' ),
10855
+ $this->get_text( 'contact-us-here' )
10856
+ ),
10857
+ $this->get_text( 'hmm' ) . '...',
10858
+ 'error'
10859
+ );
10860
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
10861
+ break;
10862
+ case 'expired':
10863
+ $this->_admin_notices->add_sticky(
10864
+ sprintf( $this->get_text( 'license-expired-non-blocking-message' ), $this->_site->plan->title ),
10865
+ 'license_expired',
10866
+ $this->get_text( 'hmm' ) . '...'
10867
+ );
10868
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
10869
+ break;
10870
+ case 'trial_started':
10871
+ $this->_admin_notices->add_sticky(
10872
+ sprintf(
10873
+ $this->get_text( 'trial-started-message' ),
10874
+ '<i>' . $this->get_plugin_name() . '</i>'
10875
+ ) . $this->get_complete_upgrade_instructions( $this->_storage->trial_plan->title ),
10876
+ 'trial_started',
10877
+ $this->get_text( 'yee-haw' ) . '!'
10878
+ );
10879
+
10880
+ $this->_admin_notices->remove_sticky( array(
10881
+ 'trial_promotion',
10882
+ ) );
10883
+ break;
10884
+ case 'trial_expired':
10885
+ $this->_admin_notices->add_sticky(
10886
+ $this->get_text( 'trial-expired-message' ),
10887
+ 'trial_expired',
10888
+ $this->get_text( 'hmm' ) . '...'
10889
+ );
10890
+ $this->_admin_notices->remove_sticky( array(
10891
+ 'trial_started',
10892
+ 'trial_promotion',
10893
+ 'plan_upgraded',
10894
+ ) );
10895
+ break;
10896
+ }
10897
+ }
10898
+
10899
+ if ( 'none' !== $plan_change ) {
10900
+ $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
10901
+ }
10902
+ }
10903
+
10904
+ /**
10905
+ * @author Vova Feldman (@svovaf)
10906
+ * @since 1.0.5
10907
+ *
10908
+ * @param bool $background
10909
+ */
10910
+ protected function _activate_license( $background = false ) {
10911
+ $this->_logger->entrance();
10912
+
10913
+ $license_id = fs_request_get( 'license_id' );
10914
+
10915
+ if ( FS_Plugin_License::is_valid_id( $license_id ) && $license_id == $this->_site->license_id ) {
10916
+ // License is already activated.
10917
+ return;
10918
+ }
10919
+
10920
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
10921
+ $this->_get_license_by_id( $license_id ) :
10922
+ $this->_get_available_premium_license();
10923
+
10924
+ if ( ! is_object( $premium_license ) ) {
10925
+ return;
10926
+ }
10927
+
10928
+ /**
10929
+ * If the premium license is already associated with the install, just
10930
+ * update the license reference (activation is not required).
10931
+ *
10932
+ * @since 1.1.9
10933
+ */
10934
+ if ( $premium_license->id == $this->_site->license_id ) {
10935
+ // License is already activated.
10936
+ $this->_update_site_license( $premium_license );
10937
+ $this->_enrich_site_plan( false );
10938
+ $this->_store_account();
10939
+
10940
+ return;
10941
+ }
10942
+
10943
+ if ( $this->_site->user_id != $premium_license->user_id ) {
10944
+ $api_request_params = array( 'license_key' => $premium_license->secret_key );
10945
+ } else {
10946
+ $api_request_params = array();
10947
+ }
10948
+
10949
+ $api = $this->get_api_site_scope();
10950
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );
10951
+
10952
+ if ( ! $this->is_api_result_entity( $license ) ) {
10953
+ if ( ! $background ) {
10954
+ $this->_admin_notices->add( sprintf(
10955
+ '%s %s',
10956
+ $this->get_text( 'license-activation-failed-message' ),
10957
+ ( is_object( $license ) && isset( $license->error ) ?
10958
+ $license->error->message :
10959
+ sprintf( '%s<br><code>%s</code>',
10960
+ $this->get_text( 'server-error-message' ),
10961
+ var_export( $license, true )
10962
+ )
10963
+ )
10964
+ ),
10965
+ $this->get_text( 'hmm' ) . '...',
10966
+ 'error'
10967
+ );
10968
+ }
10969
+
10970
+ return;
10971
+ }
10972
+
10973
+ $premium_license = new FS_Plugin_License( $license );
10974
+
10975
+ // Updated site plan.
10976
+ $site = $this->get_api_site_scope()->get( '/', true );
10977
+ if ( $this->is_api_result_entity( $site ) ) {
10978
+ $this->_site = new FS_Site( $site );
10979
+ }
10980
+ $this->_update_site_license( $premium_license );
10981
+ $this->_enrich_site_plan( false );
10982
+
10983
+ $this->_store_account();
10984
+
10985
+ if ( ! $background ) {
10986
+ $this->_admin_notices->add_sticky(
10987
+ $this->get_text( 'license-activated-message' ) .
10988
+ $this->get_complete_upgrade_instructions(),
10989
+ 'license_activated',
10990
+ $this->get_text( 'yee-haw' ) . '!'
10991
+ );
10992
+ }
10993
+
10994
+ $this->_admin_notices->remove_sticky( array(
10995
+ 'trial_promotion',
10996
+ 'license_expired',
10997
+ ) );
10998
+ }
10999
+
11000
+ /**
11001
+ * @author Vova Feldman (@svovaf)
11002
+ * @since 1.0.5
11003
+ *
11004
+ * @param bool $show_notice
11005
+ */
11006
+ protected function _deactivate_license( $show_notice = true ) {
11007
+ $this->_logger->entrance();
11008
+
11009
+ if ( ! is_object( $this->_license ) ) {
11010
+ $this->_admin_notices->add(
11011
+ sprintf( $this->get_text( 'no-active-license-message' ), $this->_site->plan->title ),
11012
+ $this->get_text( 'hmm' ) . '...'
11013
+ );
11014
+
11015
+ return;
11016
+ }
11017
+
11018
+ $api = $this->get_api_site_scope();
11019
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
11020
+
11021
+ if ( isset( $license->error ) ) {
11022
+ $this->_admin_notices->add(
11023
+ $this->get_text( 'license-deactivation-failed-message' ) . '<br> ' .
11024
+ $this->get_text( 'server-error-message' ) . ' ' . var_export( $license->error, true ),
11025
+ $this->get_text( 'hmm' ) . '...',
11026
+ 'error'
11027
+ );
11028
+
11029
+ return;
11030
+ }
11031
+
11032
+ // Update license cache.
11033
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
11034
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
11035
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
11036
+ }
11037
+ }
11038
+
11039
+ // Updated site plan to default.
11040
+ $this->_sync_plans();
11041
+ $this->_site->plan->id = $this->_plans[0]->id;
11042
+ // Unlink license from site.
11043
+ $this->_update_site_license( null );
11044
+ $this->_enrich_site_plan( false );
11045
+
11046
+ $this->_store_account();
11047
+
11048
+ if ( $show_notice ) {
11049
+ $this->_admin_notices->add(
11050
+ sprintf( $this->get_text( 'license-deactivation-message' ), $this->_site->plan->title ),
11051
+ $this->get_text( 'ok' )
11052
+ );
11053
+ }
11054
+
11055
+ $this->_admin_notices->remove_sticky( array(
11056
+ 'plan_upgraded',
11057
+ 'license_activated',
11058
+ ) );
11059
+ }
11060
+
11061
+ /**
11062
+ * Site plan downgrade.
11063
+ *
11064
+ * @author Vova Feldman (@svovaf)
11065
+ * @since 1.0.4
11066
+ *
11067
+ * @uses FS_Api
11068
+ */
11069
+ private function _downgrade_site() {
11070
+ $this->_logger->entrance();
11071
+
11072
+ $api = $this->get_api_site_scope();
11073
+ $site = $api->call( 'downgrade.json', 'put' );
11074
+
11075
+ $plan_downgraded = false;
11076
+ $plan = false;
11077
+ if ( $this->is_api_result_entity( $site ) ) {
11078
+ $prev_plan_id = $this->_site->plan->id;
11079
+
11080
+ // Update new site plan id.
11081
+ $this->_site->plan->id = $site->plan_id;
11082
+
11083
+ $plan = $this->_enrich_site_plan();
11084
+ $subscription = $this->_sync_site_subscription( $this->_license );
11085
+
11086
+ // Plan downgraded if plan was changed or subscription was cancelled.
11087
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
11088
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
11089
+ } else {
11090
+ // handle different error cases.
11091
+
11092
+ }
11093
+
11094
+ if ( $plan_downgraded ) {
11095
+ // Remove previous sticky message about upgrade (if exist).
11096
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
11097
+
11098
+ $this->_admin_notices->add(
11099
+ sprintf( $this->get_text( 'plan-x-downgraded-message' ),
11100
+ $plan->title,
11101
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
11102
+ )
11103
+ );
11104
+
11105
+ // Store site updates.
11106
+ $this->_store_site();
11107
+ } else {
11108
+ $this->_admin_notices->add(
11109
+ $this->get_text( 'plan-downgraded-failure-message' ),
11110
+ $this->get_text( 'oops' ) . '...',
11111
+ 'error'
11112
+ );
11113
+ }
11114
+ }
11115
+
11116
+ /**
11117
+ * @author Vova Feldman (@svovaf)
11118
+ * @since 1.1.8.1
11119
+ *
11120
+ * @param bool|string $plan_name
11121
+ *
11122
+ * @return bool If trial was successfully started.
11123
+ */
11124
+ function start_trial( $plan_name = false ) {
11125
+ $this->_logger->entrance();
11126
+
11127
+ if ( $this->is_trial() ) {
11128
+ // Already in trial mode.
11129
+ $this->_admin_notices->add(
11130
+ sprintf( $this->get_text( 'in-trial-mode' ), $this->_module_type ),
11131
+ $this->get_text( 'oops' ) . '...',
11132
+ 'error'
11133
+ );
11134
+
11135
+ return false;
11136
+ }
11137
+
11138
+ if ( $this->_site->is_trial_utilized() ) {
11139
+ // Trial was already utilized.
11140
+ $this->_admin_notices->add(
11141
+ $this->get_text( 'trial-utilized' ),
11142
+ $this->get_text( 'oops' ) . '...',
11143
+ 'error'
11144
+ );
11145
+
11146
+ return false;
11147
+ }
11148
+
11149
+ if ( false !== $plan_name ) {
11150
+ $plan = $this->get_plan_by_name( $plan_name );
11151
+
11152
+ if ( false === $plan ) {
11153
+ // Plan doesn't exist.
11154
+ $this->_admin_notices->add(
11155
+ sprintf( $this->get_text( 'trial-plan-x-not-exist' ), $plan_name ),
11156
+ $this->get_text( 'oops' ) . '...',
11157
+ 'error'
11158
+ );
11159
+
11160
+ return false;
11161
+ }
11162
+
11163
+ if ( ! $plan->has_trial() ) {
11164
+ // Plan doesn't exist.
11165
+ $this->_admin_notices->add(
11166
+ sprintf( $this->get_text( 'plan-x-no-trial' ), $plan_name ),
11167
+ $this->get_text( 'oops' ) . '...',
11168
+ 'error'
11169
+ );
11170
+
11171
+ return false;
11172
+ }
11173
+ } else {
11174
+ if ( ! $this->has_trial_plan() ) {
11175
+ // None of the plans have a trial.
11176
+ $this->_admin_notices->add(
11177
+ sprintf( $this->get_text( 'no-trials' ), $this->_module_type ),
11178
+ $this->get_text( 'oops' ) . '...',
11179
+ 'error'
11180
+ );
11181
+
11182
+ return false;
11183
+ }
11184
+
11185
+ $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
11186
+
11187
+ $plan = $plans_with_trial[0];
11188
+ }
11189
+
11190
+ $api = $this->get_api_site_scope();
11191
+ $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
11192
+
11193
+ if ( ! $this->is_api_result_entity( $plan ) ) {
11194
+ // Some API error while trying to start the trial.
11195
+ $this->_admin_notices->add(
11196
+ sprintf( $this->get_text( 'unexpected-api-error' ), $this->_module_type )
11197
+ . ' ' . var_export( $plan, true ),
11198
+ $this->get_text( 'oops' ) . '...',
11199
+ 'error'
11200
+ );
11201
+
11202
+ return false;
11203
+ }
11204
+
11205
+ // Sync license.
11206
+ $this->_sync_license();
11207
+
11208
+ return $this->is_trial();
11209
+ }
11210
+
11211
+ /**
11212
+ * Cancel site trial.
11213
+ *
11214
+ * @author Vova Feldman (@svovaf)
11215
+ * @since 1.0.9
11216
+ *
11217
+ * @uses FS_Api
11218
+ */
11219
+ private function _cancel_trial() {
11220
+ $this->_logger->entrance();
11221
+
11222
+ if ( ! $this->is_trial() ) {
11223
+ $this->_admin_notices->add(
11224
+ $this->get_text( 'trial-cancel-no-trial-message' ),
11225
+ $this->get_text( 'oops' ) . '...',
11226
+ 'error'
11227
+ );
11228
+
11229
+ return;
11230
+ }
11231
+
11232
+ $api = $this->get_api_site_scope();
11233
+ $site = $api->call( 'trials.json', 'delete' );
11234
+
11235
+ $trial_cancelled = false;
11236
+
11237
+ if ( $this->is_api_result_entity( $site ) ) {
11238
+ $prev_trial_ends = $this->_site->trial_ends;
11239
+
11240
+ if ( $this->is_paid_trial() ) {
11241
+ $this->_license->expiration = $site->trial_ends;
11242
+ $this->_license->is_cancelled = true;
11243
+ $this->_update_site_license( $this->_license );
11244
+ $this->_store_licenses();
11245
+
11246
+ // Clear subscription reference.
11247
+ $this->_sync_site_subscription( null );
11248
+ }
11249
+
11250
+ // Update site info.
11251
+ $this->_site = new FS_Site( $site );
11252
+ $this->_enrich_site_plan();
11253
+
11254
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
11255
+ } else {
11256
+ // handle different error cases.
11257
+
11258
+ }
11259
+
11260
+ if ( $trial_cancelled ) {
11261
+ // Remove previous sticky messages about upgrade or trial (if exist).
11262
+ $this->_admin_notices->remove_sticky( array(
11263
+ 'trial_started',
11264
+ 'trial_promotion',
11265
+ 'plan_upgraded',
11266
+ ) );
11267
+
11268
+ // Store site updates.
11269
+ $this->_store_site();
11270
+
11271
+ if ( ! $this->is_addon() ||
11272
+ ! $this->deactivate_premium_only_addon_without_license( true )
11273
+ ) {
11274
+ $this->_admin_notices->add(
11275
+ sprintf( $this->get_text( 'trial-cancel-message' ), $this->_storage->trial_plan->title )
11276
+ );
11277
+ }
11278
+
11279
+ // Clear trial plan information.
11280
+ unset( $this->_storage->trial_plan );
11281
+ } else {
11282
+ $this->_admin_notices->add(
11283
+ $this->get_text( 'trial-cancel-failure-message' ),
11284
+ $this->get_text( 'oops' ) . '...',
11285
+ 'error'
11286
+ );
11287
+ }
11288
+ }
11289
+
11290
+ /**
11291
+ * @author Vova Feldman (@svovaf)
11292
+ * @since 1.0.6
11293
+ *
11294
+ * @param bool|number $plugin_id
11295
+ *
11296
+ * @return bool
11297
+ */
11298
+ private function _is_addon_id( $plugin_id ) {
11299
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
11300
+ }
11301
+
11302
+ /**
11303
+ * Check if user eligible to download premium version updates.
11304
+ *
11305
+ * @author Vova Feldman (@svovaf)
11306
+ * @since 1.0.6
11307
+ *
11308
+ * @return bool
11309
+ */
11310
+ private function _can_download_premium() {
11311
+ return $this->has_active_valid_license() ||
11312
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
11313
+ }
11314
+
11315
+ /**
11316
+ *
11317
+ * @author Vova Feldman (@svovaf)
11318
+ * @since 1.0.6
11319
+ *
11320
+ * @param bool|number $addon_id
11321
+ * @param string $type "json" or "zip"
11322
+ *
11323
+ * @return string
11324
+ */
11325
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
11326
+
11327
+ $is_addon = $this->_is_addon_id( $addon_id );
11328
+
11329
+ $is_premium = null;
11330
+ if ( ! $is_addon ) {
11331
+ $is_premium = $this->_can_download_premium();
11332
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
11333
+ $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
11334
+ }
11335
+
11336
+ // If add-on, then append add-on ID.
11337
+ $endpoint = ( $is_addon ? "/addons/$addon_id" : '' ) .
11338
+ '/updates/latest.' . $type;
11339
+
11340
+ // If add-on and not yet activated, try to fetch based on server licensing.
11341
+ if ( is_bool( $is_premium ) ) {
11342
+ $endpoint = add_query_arg( 'is_premium', json_encode( $is_premium ), $endpoint );
11343
+ }
11344
+
11345
+ if ( $this->has_secret_key() ) {
11346
+ $endpoint = add_query_arg( 'type', 'all', $endpoint );
11347
+ }
11348
+
11349
+ return $endpoint;
11350
+ }
11351
+
11352
+ /**
11353
+ * @author Vova Feldman (@svovaf)
11354
+ * @since 1.0.4
11355
+ *
11356
+ * @param bool|number $addon_id
11357
+ * @param bool $flush Since 1.1.7.3
11358
+ * @param int $expiration Since 1.2.2.7
11359
+ *
11360
+ * @return object|false Plugin latest tag info.
11361
+ */
11362
+ function _fetch_latest_version( $addon_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
11363
+ $this->_logger->entrance();
11364
+
11365
+ /**
11366
+ * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
11367
+ * @since 1.1.7.4 Also check updates for add-ons.
11368
+ */
11369
+ if ( ! $this->is_registered() &&
11370
+ ! $this->_is_addon_id( $addon_id )
11371
+ ) {
11372
+ return false;
11373
+ }
11374
+
11375
+ $tag = $this->get_api_site_or_plugin_scope()->get(
11376
+ $this->_get_latest_version_endpoint( $addon_id, 'json' ),
11377
+ $flush,
11378
+ $expiration
11379
+ );
11380
+
11381
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
11382
+
11383
+ $this->_logger->departure( 'Latest version ' . $latest_version );
11384
+
11385
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
11386
+ }
11387
+
11388
+ #----------------------------------------------------------------------------------
11389
+ #region Download Plugin
11390
+ #----------------------------------------------------------------------------------
11391
+
11392
+ /**
11393
+ * Download latest plugin version, based on plan.
11394
+ *
11395
+ * Not like _download_latest(), this will redirect the page
11396
+ * to secure download url to prevent dual download (from FS to WP server,
11397
+ * and then from WP server to the client / browser).
11398
+ *
11399
+ * @author Vova Feldman (@svovaf)
11400
+ * @since 1.0.9
11401
+ *
11402
+ * @param bool|number $plugin_id
11403
+ *
11404
+ * @uses FS_Api
11405
+ * @uses wp_redirect()
11406
+ */
11407
+ private function download_latest_directly( $plugin_id = false ) {
11408
+ $this->_logger->entrance();
11409
+
11410
+ wp_redirect( $this->get_latest_download_api_url( $plugin_id ) );
11411
+ }
11412
+
11413
+ /**
11414
+ * Get latest plugin FS API download URL.
11415
+ *
11416
+ * @author Vova Feldman (@svovaf)
11417
+ * @since 1.0.9
11418
+ *
11419
+ * @param bool|number $plugin_id
11420
+ *
11421
+ * @return string
11422
+ */
11423
+ private function get_latest_download_api_url( $plugin_id = false ) {
11424
+ $this->_logger->entrance();
11425
+
11426
+ return $this->get_api_site_scope()->get_signed_url(
11427
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
11428
+ );
11429
+ }
11430
+
11431
+ /**
11432
+ * Get payment invoice URL.
11433
+ *
11434
+ * @author Vova Feldman (@svovaf)
11435
+ * @since 1.2.0
11436
+ *
11437
+ * @param bool|number $payment_id
11438
+ *
11439
+ * @return string
11440
+ */
11441
+ function _get_invoice_api_url( $payment_id = false ) {
11442
+ $this->_logger->entrance();
11443
+
11444
+ return $this->get_api_user_scope()->get_signed_url(
11445
+ "/payments/{$payment_id}/invoice.pdf"
11446
+ );
11447
+ }
11448
+
11449
+ /**
11450
+ * Get latest plugin download link.
11451
+ *
11452
+ * @author Vova Feldman (@svovaf)
11453
+ * @since 1.0.9
11454
+ *
11455
+ * @param string $label
11456
+ * @param bool|number $plugin_id
11457
+ *
11458
+ * @return string
11459
+ */
11460
+ private function get_latest_download_link( $label, $plugin_id = false ) {
11461
+ return sprintf(
11462
+ '<a target="_blank" href="%s">%s</a>',
11463
+ $this->_get_latest_download_local_url( $plugin_id ),
11464
+ $label
11465
+ );
11466
+ }
11467
+
11468
+ /**
11469
+ * Get latest plugin download local URL.
11470
+ *
11471
+ * @author Vova Feldman (@svovaf)
11472
+ * @since 1.0.9
11473
+ *
11474
+ * @param bool|number $plugin_id
11475
+ *
11476
+ * @return string
11477
+ */
11478
+ function _get_latest_download_local_url( $plugin_id = false ) {
11479
+ // Add timestamp to protect from caching.
11480
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
11481
+
11482
+ if ( ! empty( $plugin_id ) ) {
11483
+ $params['plugin_id'] = $plugin_id;
11484
+ }
11485
+
11486
+ return $this->get_account_url( 'download_latest', $params );
11487
+ }
11488
+
11489
+ #endregion Download Plugin ------------------------------------------------------------------
11490
+
11491
+ /**
11492
+ * @author Vova Feldman (@svovaf)
11493
+ * @since 1.0.4
11494
+ *
11495
+ * @uses FS_Api
11496
+ *
11497
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
11498
+ * was initiated by the admin.
11499
+ * @param bool|number $plugin_id
11500
+ * @param bool $flush Since 1.1.7.3
11501
+ * @param int $expiration Since 1.2.2.7
11502
+ */
11503
+ private function check_updates(
11504
+ $background = false,
11505
+ $plugin_id = false,
11506
+ $flush = true,
11507
+ $expiration = WP_FS__TIME_24_HOURS_IN_SEC
11508
+ ) {
11509
+ $this->_logger->entrance();
11510
+
11511
+ // Check if there's a newer version for download.
11512
+ $new_version = $this->_fetch_newer_version( $plugin_id, $flush, $expiration );
11513
+
11514
+ $update = null;
11515
+ if ( is_object( $new_version ) ) {
11516
+ $update = new FS_Plugin_Tag( $new_version );
11517
+
11518
+ if ( ! $background ) {
11519
+ $this->_admin_notices->add(
11520
+ sprintf(
11521
+ $this->get_text( 'version-x-released' ) . ' ' . $this->get_text( 'please-download-x' ),
11522
+ $update->version,
11523
+ sprintf(
11524
+ '<a href="%s" target="_blank">%s</a>',
11525
+ $this->get_account_url( 'download_latest' ),
11526
+ sprintf( $this->get_text( 'latest-x-version' ), $this->_site->plan->title )
11527
+ )
11528
+ ),
11529
+ $this->get_text( 'new' ) . '!'
11530
+ );
11531
+ }
11532
+ } else if ( false === $new_version && ! $background ) {
11533
+ $this->_admin_notices->add(
11534
+ $this->get_text( 'you-have-latest' ),
11535
+ $this->get_text( 'you-are-good' )
11536
+ );
11537
+ }
11538
+
11539
+ $this->_store_update( $update, true, $plugin_id );
11540
+ }
11541
+
11542
+ /**
11543
+ * @author Vova Feldman (@svovaf)
11544
+ * @since 1.0.4
11545
+ *
11546
+ * @param bool $flush Since 1.1.7.3 add 24 hour cache by default.
11547
+ *
11548
+ * @return FS_Plugin[]
11549
+ *
11550
+ * @uses FS_Api
11551
+ */
11552
+ private function sync_addons( $flush = false ) {
11553
+ $this->_logger->entrance();
11554
+
11555
+ $api = $this->get_api_site_or_plugin_scope();
11556
+
11557
+ /**
11558
+ * @since 1.2.1
11559
+ *
11560
+ * If there's a cached version of the add-ons and not asking
11561
+ * for a flush, just use the currently stored add-ons.
11562
+ */
11563
+ if ( ! $flush && $api->is_cached( '/addons.json?enriched=true' ) ) {
11564
+ $addons = self::get_all_addons();
11565
+
11566
+ return $addons[ $this->_plugin->id ];
11567
+ }
11568
+
11569
+ $result = $api->get( '/addons.json?enriched=true', $flush );
11570
+
11571
+ $addons = array();
11572
+ if ( $this->is_api_result_object( $result, 'plugins' ) &&
11573
+ is_array( $result->plugins )
11574
+ ) {
11575
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
11576
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
11577
+ }
11578
+
11579
+ $this->_store_addons( $addons, true );
11580
+ }
11581
+
11582
+ return $addons;
11583
+ }
11584
+
11585
+ /**
11586
+ * Handle user email update.
11587
+ *
11588
+ * @author Vova Feldman (@svovaf)
11589
+ * @since 1.0.3
11590
+ * @uses FS_Api
11591
+ *
11592
+ * @param string $new_email
11593
+ *
11594
+ * @return object
11595
+ */
11596
+ private function update_email( $new_email ) {
11597
+ $this->_logger->entrance();
11598
+
11599
+
11600
+ $api = $this->get_api_user_scope();
11601
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
11602
+ 'email' => $new_email,
11603
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
11604
+ 'account',
11605
+ array( 'fs_action' => 'sync_user' )
11606
+ ),
11607
+ ) );
11608
+
11609
+ if ( ! isset( $user->error ) ) {
11610
+ $this->_user->email = $user->email;
11611
+ $this->_user->is_verified = $user->is_verified;
11612
+ $this->_store_user();
11613
+ } else {
11614
+ // handle different error cases.
11615
+
11616
+ }
11617
+
11618
+ return $user;
11619
+ }
11620
+
11621
+ #----------------------------------------------------------------------------------
11622
+ #region API Error Handling
11623
+ #----------------------------------------------------------------------------------
11624
+
11625
+ /**
11626
+ * @author Vova Feldman (@svovaf)
11627
+ * @since 1.1.1
11628
+ *
11629
+ * @param mixed $result
11630
+ *
11631
+ * @return bool Is API result contains an error.
11632
+ */
11633
+ private function is_api_error( $result ) {
11634
+ return FS_Api::is_api_error( $result );
11635
+ }
11636
+
11637
+ /**
11638
+ * Checks if given API result is a non-empty and not an error object.
11639
+ *
11640
+ * @author Vova Feldman (@svovaf)
11641
+ * @since 1.2.1.5
11642
+ *
11643
+ * @param mixed $result
11644
+ * @param string|null $required_property Optional property we want to verify that is set.
11645
+ *
11646
+ * @return bool
11647
+ */
11648
+ function is_api_result_object( $result, $required_property = null ) {
11649
+ return FS_Api::is_api_result_object( $result, $required_property );
11650
+ }
11651
+
11652
+ /**
11653
+ * Checks if given API result is a non-empty entity object with non-empty ID.
11654
+ *
11655
+ * @author Vova Feldman (@svovaf)
11656
+ * @since 1.2.1.5
11657
+ *
11658
+ * @param mixed $result
11659
+ *
11660
+ * @return bool
11661
+ */
11662
+ private function is_api_result_entity( $result ) {
11663
+ return FS_Api::is_api_result_entity( $result );
11664
+ }
11665
+
11666
+ #endregion
11667
+
11668
+ /**
11669
+ * Make sure a given argument is an array of a specific type.
11670
+ *
11671
+ * @author Vova Feldman (@svovaf)
11672
+ * @since 1.2.1.5
11673
+ *
11674
+ * @param mixed $array
11675
+ * @param string $class
11676
+ *
11677
+ * @return bool
11678
+ */
11679
+ private function is_array_instanceof( $array, $class ) {
11680
+ return ( is_array( $array ) && ( empty( $array ) || $array[0] instanceof $class ) );
11681
+ }
11682
+
11683
+ /**
11684
+ * Start install ownership change.
11685
+ *
11686
+ * @author Vova Feldman (@svovaf)
11687
+ * @since 1.1.1
11688
+ * @uses FS_Api
11689
+ *
11690
+ * @param string $candidate_email
11691
+ *
11692
+ * @return bool Is ownership change successfully initiated.
11693
+ */
11694
+ private function init_change_owner( $candidate_email ) {
11695
+ $this->_logger->entrance();
11696
+
11697
+ $api = $this->get_api_site_scope();
11698
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
11699
+ 'email' => $candidate_email,
11700
+ 'after_confirm_url' => $this->_get_admin_page_url(
11701
+ 'account',
11702
+ array( 'fs_action' => 'change_owner' )
11703
+ ),
11704
+ ) );
11705
+
11706
+ return ! $this->is_api_error( $result );
11707
+ }
11708
+
11709
+ /**
11710
+ * Handle install ownership change.
11711
+ *
11712
+ * @author Vova Feldman (@svovaf)
11713
+ * @since 1.1.1
11714
+ * @uses FS_Api
11715
+ *
11716
+ * @return bool Was ownership change successfully complete.
11717
+ */
11718
+ private function complete_change_owner() {
11719
+ $this->_logger->entrance();
11720
+
11721
+ $site_result = $this->get_api_site_scope( true )->get();
11722
+ $site = new FS_Site( $site_result );
11723
+ $this->_site = $site;
11724
+
11725
+ $user = new FS_User();
11726
+ $user->id = fs_request_get( 'user_id' );
11727
+
11728
+ // Validate install's user and given user.
11729
+ if ( $user->id != $this->_site->user_id ) {
11730
+ return false;
11731
+ }
11732
+
11733
+ $user->public_key = fs_request_get( 'user_public_key' );
11734
+ $user->secret_key = fs_request_get( 'user_secret_key' );
11735
+
11736
+ // Fetch new user information.
11737
+ $this->_user = $user;
11738
+ $user_result = $this->get_api_user_scope( true )->get();
11739
+ $user = new FS_User( $user_result );
11740
+ $this->_user = $user;
11741
+
11742
+ $this->_set_account( $user, $site );
11743
+
11744
+ return true;
11745
+ }
11746
+
11747
+ /**
11748
+ * Handle user name update.
11749
+ *
11750
+ * @author Vova Feldman (@svovaf)
11751
+ * @since 1.0.9
11752
+ * @uses FS_Api
11753
+ *
11754
+ * @return object
11755
+ */
11756
+ private function update_user_name() {
11757
+ $this->_logger->entrance();
11758
+ $name = fs_request_get( 'fs_user_name_' . $this->get_unique_affix(), '' );
11759
+
11760
+ $api = $this->get_api_user_scope();
11761
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
11762
+ 'name' => $name,
11763
+ ) );
11764
+
11765
+ if ( ! isset( $user->error ) ) {
11766
+ $this->_user->first = $user->first;
11767
+ $this->_user->last = $user->last;
11768
+ $this->_store_user();
11769
+ } else {
11770
+ // handle different error cases.
11771
+
11772
+ }
11773
+
11774
+ return $user;
11775
+ }
11776
+
11777
+ /**
11778
+ * Verify user email.
11779
+ *
11780
+ * @author Vova Feldman (@svovaf)
11781
+ * @since 1.0.3
11782
+ * @uses FS_Api
11783
+ */
11784
+ private function verify_email() {
11785
+ $this->_handle_account_user_sync();
11786
+
11787
+ if ( $this->_user->is_verified() ) {
11788
+ return;
11789
+ }
11790
+
11791
+ $api = $this->get_api_site_scope();
11792
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
11793
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
11794
+ 'account',
11795
+ array( 'fs_action' => 'sync_user' )
11796
+ )
11797
+ ) );
11798
+
11799
+ if ( ! isset( $result->error ) ) {
11800
+ $this->_admin_notices->add( sprintf(
11801
+ $this->get_text( 'verification-email-sent-message' ),
11802
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
11803
+ ) );
11804
+ } else {
11805
+ // handle different error cases.
11806
+
11807
+ }
11808
+ }
11809
+
11810
+ /**
11811
+ * @author Vova Feldman (@svovaf)
11812
+ * @since 1.1.2
11813
+ *
11814
+ * @param array $params
11815
+ *
11816
+ * @return string
11817
+ */
11818
+ function get_activation_url( $params = array() ) {
11819
+ if ( $this->is_addon() && $this->has_free_plan() ) {
11820
+ /**
11821
+ * @author Vova Feldman (@svovaf)
11822
+ * @since 1.2.1.7 Add-on's activation is the parent's module activation.
11823
+ */
11824
+ return $this->get_parent_instance()->get_activation_url( $params );
11825
+ }
11826
+
11827
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params ) );
11828
+ }
11829
+
11830
+ /**
11831
+ * @author Vova Feldman (@svovaf)
11832
+ * @since 1.2.1.5
11833
+ *
11834
+ * @param array $params
11835
+ *
11836
+ * @return string
11837
+ */
11838
+ function get_reconnect_url( $params = array() ) {
11839
+ $params['fs_action'] = 'reset_anonymous_mode';
11840
+ $params['fs_unique_affix'] = $this->get_unique_affix();
11841
+
11842
+ return $this->get_activation_url( $params );
11843
+ }
11844
+
11845
+ /**
11846
+ * Get the URL of the page that should be loaded after the user connect
11847
+ * or skip in the opt-in screen.
11848
+ *
11849
+ * @author Vova Feldman (@svovaf)
11850
+ * @since 1.1.3
11851
+ *
11852
+ * @param string $filter Filter name.
11853
+ * @param array $params Since 1.2.2.7
11854
+ *
11855
+ * @return string
11856
+ */
11857
+ function get_after_activation_url( $filter, $params = array() ) {
11858
+ if ( $this->is_free_wp_org_theme() &&
11859
+ fs_request_has( 'pending_activation' )
11860
+ ) {
11861
+ $first_time_path = '';
11862
+ } else {
11863
+ $first_time_path = $this->_menu->get_first_time_path();
11864
+ }
11865
+
11866
+ return add_query_arg( $params, $this->apply_filters(
11867
+ $filter,
11868
+ empty( $first_time_path ) ?
11869
+ $this->_get_admin_page_url() :
11870
+ $first_time_path
11871
+ ) );
11872
+ }
11873
+
11874
+ /**
11875
+ * Handle account page updates / edits / actions.
11876
+ *
11877
+ * @author Vova Feldman (@svovaf)
11878
+ * @since 1.0.2
11879
+ *
11880
+ */
11881
+ private function _handle_account_edits() {
11882
+ if ( ! $this->is_user_admin() ) {
11883
+ return;
11884
+ }
11885
+
11886
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
11887
+ $action = fs_get_action();
11888
+
11889
+ switch ( $action ) {
11890
+ case 'delete_account':
11891
+ check_admin_referer( $action );
11892
+
11893
+ if ( $plugin_id == $this->get_id() ) {
11894
+ $this->delete_account_event();
11895
+
11896
+ // Clear user and site.
11897
+ $this->_site = null;
11898
+ $this->_user = null;
11899
+
11900
+ fs_redirect( $this->get_activation_url() );
11901
+ } else {
11902
+ if ( $this->is_addon_activated( $plugin_id ) ) {
11903
+ $fs_addon = self::get_instance_by_id( $plugin_id );
11904
+ $fs_addon->delete_account_event();
11905
+
11906
+ fs_redirect( $this->_get_admin_page_url( 'account' ) );
11907
+ }
11908
+ }
11909
+
11910
+ return;
11911
+
11912
+ case 'downgrade_account':
11913
+ check_admin_referer( $action );
11914
+
11915
+ if ( $plugin_id == $this->get_id() ) {
11916
+ $this->_downgrade_site();
11917
+ } else if ( $this->is_addon_activated( $plugin_id ) ) {
11918
+ $fs_addon = self::get_instance_by_id( $plugin_id );
11919
+ $fs_addon->_downgrade_site();
11920
+ }
11921
+
11922
+ return;
11923
+
11924
+ case 'activate_license':
11925
+ check_admin_referer( $action );
11926
+
11927
+ if ( $plugin_id == $this->get_id() ) {
11928
+ $this->_activate_license();
11929
+ } else {
11930
+ if ( $this->is_addon_activated( $plugin_id ) ) {
11931
+ $fs_addon = self::get_instance_by_id( $plugin_id );
11932
+ $fs_addon->_activate_license();
11933
+ }
11934
+ }
11935
+
11936
+ return;
11937
+
11938
+ case 'deactivate_license':
11939
+ check_admin_referer( $action );
11940
+
11941
+ if ( $plugin_id == $this->get_id() ) {
11942
+ $this->_deactivate_license();
11943
+ } else {
11944
+ if ( $this->is_addon_activated( $plugin_id ) ) {
11945
+ $fs_addon = self::get_instance_by_id( $plugin_id );
11946
+ $fs_addon->_deactivate_license();
11947
+ }
11948
+ }
11949
+
11950
+ return;
11951
+
11952
+ case 'check_updates':
11953
+ check_admin_referer( $action );
11954
+ $this->check_updates();
11955
+
11956
+ return;
11957
+
11958
+ case 'change_owner':
11959
+ $state = fs_request_get( 'state', 'init' );
11960
+ switch ( $state ) {
11961
+ case 'init':
11962
+ $candidate_email = fs_request_get( 'candidate_email', '' );
11963
+
11964
+ if ( $this->init_change_owner( $candidate_email ) ) {
11965
+ $this->_admin_notices->add( sprintf( $this->get_text( 'change-owner-request-sent-x' ), '<b>' . $this->_user->email . '</b>' ) );
11966
+ }
11967
+ break;
11968
+ case 'owner_confirmed':
11969
+ $candidate_email = fs_request_get( 'candidate_email', '' );
11970
+
11971
+ $this->_admin_notices->add( sprintf( $this->get_text( 'change-owner-request_owner-confirmed' ), '<b>' . $candidate_email . '</b>' ) );
11972
+ break;
11973
+ case 'candidate_confirmed':
11974
+ if ( $this->complete_change_owner() ) {
11975
+ $this->_admin_notices->add_sticky(
11976
+ sprintf( $this->get_text( 'change-owner-request_candidate-confirmed' ), '<b>' . $this->_user->email . '</b>' ),
11977
+ 'ownership_changed',
11978
+ $this->get_text( 'congrats' ) . '!'
11979
+ );
11980
+ } else {
11981
+ // @todo Handle failed ownership change message.
11982
+ }
11983
+ break;
11984
+ }
11985
+
11986
+ return;
11987
+
11988
+ case 'update_email':
11989
+ check_admin_referer( 'update_email' );
11990
+
11991
+ $new_email = fs_request_get( 'fs_email_' . $this->get_unique_affix(), '' );
11992
+ $result = $this->update_email( $new_email );
11993
+
11994
+ if ( isset( $result->error ) ) {
11995
+ switch ( $result->error->code ) {
11996
+ case 'user_exist':
11997
+ $this->_admin_notices->add(
11998
+ $this->get_text( 'user-exist-message' ) . ' ' .
11999
+ sprintf( $this->get_text( 'user-exist-message_ownership' ), $this->_module_type, '<b>' . $new_email . '</b>' ) .
12000
+ sprintf(
12001
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
12002
+ $this->get_account_url( 'change_owner', array(
12003
+ 'state' => 'init',
12004
+ 'candidate_email' => $new_email
12005
+ ) ),
12006
+ $this->get_text( 'change-ownership' )
12007
+ ),
12008
+ $this->get_text( 'oops' ) . '...',
12009
+ 'error'
12010
+ );
12011
+ break;
12012
+ }
12013
+ } else {
12014
+ $this->_admin_notices->add( $this->get_text( 'email-updated-message' ) );
12015
+ }
12016
+
12017
+ return;
12018
+
12019
+ case 'update_user_name':
12020
+ check_admin_referer( 'update_user_name' );
12021
+
12022
+ $result = $this->update_user_name();
12023
+
12024
+ if ( isset( $result->error ) ) {
12025
+ $this->_admin_notices->add(
12026
+ $this->get_text( 'name-update-failed-message' ),
12027
+ $this->get_text( 'oops' ) . '...',
12028
+ 'error'
12029
+ );
12030
+ } else {
12031
+ $this->_admin_notices->add( $this->get_text( 'name-updated-message' ) );
12032
+ }
12033
+
12034
+ return;
12035
+
12036
+ #region Actions that might be called from external links (e.g. email)
12037
+
12038
+ case 'cancel_trial':
12039
+ if ( $plugin_id == $this->get_id() ) {
12040
+ $this->_cancel_trial();
12041
+ } else {
12042
+ if ( $this->is_addon_activated( $plugin_id ) ) {
12043
+ $fs_addon = self::get_instance_by_id( $plugin_id );
12044
+ $fs_addon->_cancel_trial();
12045
+ }
12046
+ }
12047
+
12048
+ return;
12049
+
12050
+ case 'verify_email':
12051
+ $this->verify_email();
12052
+
12053
+ return;
12054
+
12055
+ case 'sync_user':
12056
+ $this->_handle_account_user_sync();
12057
+
12058
+ return;
12059
+
12060
+ case $this->get_unique_affix() . '_sync_license':
12061
+ $this->_sync_license();
12062
+
12063
+ return;
12064
+
12065
+ case 'download_latest':
12066
+ $this->download_latest_directly( $plugin_id );
12067
+
12068
+ return;
12069
+
12070
+ #endregion
12071
+ }
12072
+
12073
+ if ( WP_FS__IS_POST_REQUEST ) {
12074
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
12075
+ foreach ( $properties as $p ) {
12076
+ if ( 'update_' . $p === $action ) {
12077
+ check_admin_referer( $action );
12078
+
12079
+ $this->_logger->log( $action );
12080
+
12081
+ $site_property = substr( $p, strlen( 'site_' ) );
12082
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->get_unique_affix(), '' );
12083
+ $this->get_site()->{$site_property} = $site_property_value;
12084
+
12085
+ // Store account after modification.
12086
+ $this->_store_site();
12087
+
12088
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
12089
+
12090
+ $this->_admin_notices->add( sprintf(
12091
+ $this->get_text( 'x-updated' ),
12092
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
12093
+
12094
+ return;
12095
+ }
12096
+ }
12097
+ }
12098
+ }
12099
+
12100
+ /**
12101
+ * Account page resources load.
12102
+ *
12103
+ * @author Vova Feldman (@svovaf)
12104
+ * @since 1.0.6
12105
+ */
12106
+ function _account_page_load() {
12107
+ $this->_logger->entrance();
12108
+
12109
+ $this->_logger->info( var_export( $_REQUEST, true ) );
12110
+
12111
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
12112
+
12113
+ if ( $this->has_addons() ) {
12114
+ wp_enqueue_script( 'plugin-install' );
12115
+ add_thickbox();
12116
+
12117
+ function fs_addons_body_class( $classes ) {
12118
+ $classes .= ' plugins-php';
12119
+
12120
+ return $classes;
12121
+ }
12122
+
12123
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
12124
+ }
12125
+
12126
+ if ( $this->has_paid_plan() &&
12127
+ ! $this->has_any_license() &&
12128
+ ! $this->is_sync_executed() &&
12129
+ $this->is_tracking_allowed()
12130
+ ) {
12131
+ /**
12132
+ * If no licenses found and no sync job was executed during the last 24 hours,
12133
+ * just execute the sync job right away (blocking execution).
12134
+ *
12135
+ * @since 1.1.7.3
12136
+ */
12137
+ $this->run_manual_sync();
12138
+ }
12139
+
12140
+ $this->_handle_account_edits();
12141
+
12142
+ $this->do_action( 'account_page_load_before_departure' );
12143
+ }
12144
+
12145
+ /**
12146
+ * Render account page.
12147
+ *
12148
+ * @author Vova Feldman (@svovaf)
12149
+ * @since 1.0.0
12150
+ */
12151
+ function _account_page_render() {
12152
+ $this->_logger->entrance();
12153
+
12154
+ $template = 'account.php';
12155
+ if ( 'billing' === fs_request_get( 'tab' ) ) {
12156
+ $template = 'billing.php';
12157
+ }
12158
+
12159
+ $vars = array( 'id' => $this->_module_id );
12160
+
12161
+ /**
12162
+ * Added filter to the template to allow developers wrapping the template
12163
+ * in custom HTML (e.g. within a wizard/tabs).
12164
+ *
12165
+ * @author Vova Feldman (@svovaf)
12166
+ * @since 1.2.1.6
12167
+ */
12168
+ echo $this->apply_filters( "templates/{$template}", fs_get_template( $template, $vars ) );
12169
+ }
12170
+
12171
+ /**
12172
+ * Render account connect page.
12173
+ *
12174
+ * @author Vova Feldman (@svovaf)
12175
+ * @since 1.0.7
12176
+ */
12177
+ function _connect_page_render() {
12178
+ $this->_logger->entrance();
12179
+
12180
+ $vars = array( 'id' => $this->_module_id );
12181
+
12182
+ /**
12183
+ * Added filter to the template to allow developers wrapping the template
12184
+ * in custom HTML (e.g. within a wizard/tabs).
12185
+ *
12186
+ * @author Vova Feldman (@svovaf)
12187
+ * @since 1.2.1.6
12188
+ */
12189
+ echo $this->apply_filters( 'templates/connect.php', fs_get_template( 'connect.php', $vars ) );
12190
+ }
12191
+
12192
+ /**
12193
+ * Load required resources before add-ons page render.
12194
+ *
12195
+ * @author Vova Feldman (@svovaf)
12196
+ * @since 1.0.6
12197
+ */
12198
+ function _addons_page_load() {
12199
+ $this->_logger->entrance();
12200
+
12201
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
12202
+
12203
+ wp_enqueue_script( 'plugin-install' );
12204
+ add_thickbox();
12205
+
12206
+ function fs_addons_body_class( $classes ) {
12207
+ $classes .= ' plugins-php';
12208
+
12209
+ return $classes;
12210
+ }
12211
+
12212
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
12213
+
12214
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
12215
+ $this->_admin_notices->add(
12216
+ sprintf( $this->get_text( 'addons-info-external-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
12217
+ $this->get_text( 'heads-up' ),
12218
+ 'update-nag'
12219
+ );
12220
+ }
12221
+ }
12222
+
12223
+ /**
12224
+ * Render add-ons page.
12225
+ *
12226
+ * @author Vova Feldman (@svovaf)
12227
+ * @since 1.0.6
12228
+ */
12229
+ function _addons_page_render() {
12230
+ $this->_logger->entrance();
12231
+
12232
+ $vars = array( 'id' => $this->_module_id );
12233
+
12234
+ /**
12235
+ * Added filter to the template to allow developers wrapping the template
12236
+ * in custom HTML (e.g. within a wizard/tabs).
12237
+ *
12238
+ * @author Vova Feldman (@svovaf)
12239
+ * @since 1.2.1.6
12240
+ */
12241
+ echo $this->apply_filters( 'templates/add-ons.php', fs_get_template( 'add-ons.php', $vars ) );
12242
+ }
12243
+
12244
+ /* Pricing & Upgrade
12245
+ ------------------------------------------------------------------------------------------------------------------*/
12246
+ /**
12247
+ * Render pricing page.
12248
+ *
12249
+ * @author Vova Feldman (@svovaf)
12250
+ * @since 1.0.0
12251
+ */
12252
+ function _pricing_page_render() {
12253
+ $this->_logger->entrance();
12254
+
12255
+ $vars = array( 'id' => $this->_module_id );
12256
+
12257
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
12258
+ fs_require_once_template( 'checkout.php', $vars );
12259
+ } else {
12260
+ fs_require_once_template( 'pricing.php', $vars );
12261
+ }
12262
+ }
12263
+
12264
+ #----------------------------------------------------------------------------------
12265
+ #region Contact Us
12266
+ #----------------------------------------------------------------------------------
12267
+
12268
+ /**
12269
+ * Render contact-us page.
12270
+ *
12271
+ * @author Vova Feldman (@svovaf)
12272
+ * @since 1.0.3
12273
+ */
12274
+ function _contact_page_render() {
12275
+ $this->_logger->entrance();
12276
+
12277
+ $vars = array( 'id' => $this->_module_id );
12278
+ fs_require_once_template( 'contact.php', $vars );
12279
+ }
12280
+
12281
+ #endregion ------------------------------------------------------------------------
12282
+
12283
+ /**
12284
+ * Hide all admin notices to prevent distractions.
12285
+ *
12286
+ * @author Vova Feldman (@svovaf)
12287
+ * @since 1.0.3
12288
+ *
12289
+ * @uses remove_all_actions()
12290
+ */
12291
+ private static function _hide_admin_notices() {
12292
+ remove_all_actions( 'admin_notices' );
12293
+ remove_all_actions( 'network_admin_notices' );
12294
+ remove_all_actions( 'all_admin_notices' );
12295
+ remove_all_actions( 'user_admin_notices' );
12296
+ }
12297
+
12298
+ static function _clean_admin_content_section_hook() {
12299
+ self::_hide_admin_notices();
12300
+
12301
+ // Hide footer.
12302
+ echo '<style>#wpfooter { display: none !important; }</style>';
12303
+ }
12304
+
12305
+ /**
12306
+ * Attach to admin_head hook to hide all admin notices.
12307
+ *
12308
+ * @author Vova Feldman (@svovaf)
12309
+ * @since 1.0.3
12310
+ */
12311
+ static function _clean_admin_content_section() {
12312
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
12313
+ }
12314
+
12315
+ /* CSS & JavaScript
12316
+ ------------------------------------------------------------------------------------------------------------------*/
12317
+ /* function _enqueue_script($handle, $src) {
12318
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
12319
+
12320
+ $this->_logger->entrance( 'script = ' . $url );
12321
+
12322
+ wp_enqueue_script( $handle, $url );
12323
+ }*/
12324
+
12325
+ /* SDK
12326
+ ------------------------------------------------------------------------------------------------------------------*/
12327
+ private $_user_api;
12328
+
12329
+ /**
12330
+ *
12331
+ * @author Vova Feldman (@svovaf)
12332
+ * @since 1.0.2
12333
+ *
12334
+ * @param bool $flush
12335
+ *
12336
+ * @return FS_Api
12337
+ */
12338
+ function get_api_user_scope( $flush = false ) {
12339
+ if ( ! isset( $this->_user_api ) || $flush ) {
12340
+ $this->_user_api = FS_Api::instance(
12341
+ $this->_module_id,
12342
+ 'user',
12343
+ $this->_user->id,
12344
+ $this->_user->public_key,
12345
+ ! $this->is_live(),
12346
+ $this->_user->secret_key
12347
+ );
12348
+ }
12349
+
12350
+ return $this->_user_api;
12351
+ }
12352
+
12353
+ private $_site_api;
12354
+
12355
+ /**
12356
+ *
12357
+ * @author Vova Feldman (@svovaf)
12358
+ * @since 1.0.2
12359
+ *
12360
+ * @param bool $flush
12361
+ *
12362
+ * @return FS_Api
12363
+ */
12364
+ function get_api_site_scope( $flush = false ) {
12365
+ if ( ! isset( $this->_site_api ) || $flush ) {
12366
+ $this->_site_api = FS_Api::instance(
12367
+ $this->_module_id,
12368
+ 'install',
12369
+ $this->_site->id,
12370
+ $this->_site->public_key,
12371
+ ! $this->is_live(),
12372
+ $this->_site->secret_key
12373
+ );
12374
+ }
12375
+
12376
+ return $this->_site_api;
12377
+ }
12378
+
12379
+ private $_plugin_api;
12380
+
12381
+ /**
12382
+ * Get plugin public API scope.
12383
+ *
12384
+ * @author Vova Feldman (@svovaf)
12385
+ * @since 1.0.7
12386
+ *
12387
+ * @return FS_Api
12388
+ */
12389
+ function get_api_plugin_scope() {
12390
+ if ( ! isset( $this->_plugin_api ) ) {
12391
+ $this->_plugin_api = FS_Api::instance(
12392
+ $this->_module_id,
12393
+ 'plugin',
12394
+ $this->_plugin->id,
12395
+ $this->_plugin->public_key,
12396
+ ! $this->is_live()
12397
+ );
12398
+ }
12399
+
12400
+ return $this->_plugin_api;
12401
+ }
12402
+
12403
+ /**
12404
+ * Get site API scope object (fallback to public plugin scope when not registered).
12405
+ *
12406
+ * @author Vova Feldman (@svovaf)
12407
+ * @since 1.0.7
12408
+ *
12409
+ * @return FS_Api
12410
+ */
12411
+ function get_api_site_or_plugin_scope() {
12412
+ return $this->is_registered() ?
12413
+ $this->get_api_site_scope() :
12414
+ $this->get_api_plugin_scope();
12415
+ }
12416
+
12417
+ /**
12418
+ * Show trial promotional notice (if any trial exist).
12419
+ *
12420
+ * @author Vova Feldman (@svovaf)
12421
+ * @since 1.0.9
12422
+ *
12423
+ * @param $plans
12424
+ */
12425
+ function _check_for_trial_plans( $plans ) {
12426
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
12427
+ }
12428
+
12429
+ /**
12430
+ * During trial promotion the "upgrade" submenu item turns to
12431
+ * "start trial" to encourage the trial. Since we want to keep
12432
+ * the same menu item handler and there's no robust way to
12433
+ * add new arguments to the menu item link's querystring,
12434
+ * use JavaScript to find the menu item and update the href of
12435
+ * the link.
12436
+ *
12437
+ * @author Vova Feldman (@svovaf)
12438
+ * @since 1.2.1.5
12439
+ */
12440
+ function _fix_start_trial_menu_item_url() {
12441
+ $template_args = array( 'id' => $this->_module_id );
12442
+ fs_require_template( 'add-trial-to-pricing.php', $template_args );
12443
+ }
12444
+
12445
+ /**
12446
+ * Check if module is currently in a trial promotion mode.
12447
+ *
12448
+ * @author Vova Feldman (@svovaf)
12449
+ * @since 1.2.2.7
12450
+ *
12451
+ * @return bool
12452
+ */
12453
+ function is_in_trial_promotion() {
12454
+ return $this->_admin_notices->has_sticky( 'trial_promotion' );
12455
+ }
12456
+
12457
+ /**
12458
+ * Show trial promotional notice (if any trial exist).
12459
+ *
12460
+ * @author Vova Feldman (@svovaf)
12461
+ * @since 1.0.9
12462
+ *
12463
+ * @return bool If trial notice added.
12464
+ */
12465
+ function _add_trial_notice() {
12466
+ if ( ! $this->is_user_admin() ) {
12467
+ return false;
12468
+ }
12469
+
12470
+ if ( ! $this->is_user_in_admin() ) {
12471
+ return false;
12472
+ }
12473
+
12474
+ // Check if trial message is already shown.
12475
+ if ( $this->is_in_trial_promotion() ) {
12476
+ add_action( 'admin_footer', array( &$this, '_fix_start_trial_menu_item_url' ) );
12477
+
12478
+ $this->_menu->add_counter_to_menu_item( 1, 'fs-trial' );
12479
+
12480
+ return false;
12481
+ }
12482
+
12483
+ if ( $this->is_premium() && ! WP_FS__DEV_MODE ) {
12484
+ // Don't show trial if running the premium code, unless running in DEV mode.
12485
+ return false;
12486
+ }
12487
+
12488
+ if ( ! $this->has_trial_plan() ) {
12489
+ // No plans with trial.
12490
+ return false;
12491
+ }
12492
+
12493
+ if ( ! $this->apply_filters( 'show_trial', true ) ) {
12494
+ // Developer explicitly asked not to show the trial promo.
12495
+ return false;
12496
+ }
12497
+
12498
+ if ( $this->is_registered() ) {
12499
+ // Check if trial already utilized.
12500
+ if ( $this->_site->is_trial_utilized() ) {
12501
+ return false;
12502
+ }
12503
+
12504
+ if ( $this->is_paying_or_trial() ) {
12505
+ // Don't show trial if paying or already in trial.
12506
+ return false;
12507
+ }
12508
+ }
12509
+
12510
+ if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
12511
+ // If not yet opted-in/skipped, or pending activation, don't show trial.
12512
+ return false;
12513
+ }
12514
+
12515
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
12516
+ $was_promotion_shown_before = ( false !== $last_time_trial_promotion_shown );
12517
+
12518
+ // Show promotion if never shown before and 24 hours after initial activation with FS.
12519
+ if ( ! $was_promotion_shown_before &&
12520
+ $this->_storage->install_timestamp > ( time() - WP_FS__TIME_24_HOURS_IN_SEC )
12521
+ ) {
12522
+ return false;
12523
+ }
12524
+
12525
+ // OR if promotion was shown before, try showing it every 30 days.
12526
+ if ( $was_promotion_shown_before &&
12527
+ 30 * WP_FS__TIME_24_HOURS_IN_SEC > time() - $last_time_trial_promotion_shown
12528
+ ) {
12529
+ return false;
12530
+ }
12531
+
12532
+ $trial_period = $this->_trial_days;
12533
+ $require_payment = $this->_is_trial_require_payment;
12534
+ $trial_url = $this->get_trial_url();
12535
+ $plans_string = strtolower( $this->get_text( 'awesome' ) );
12536
+
12537
+ if ( $this->is_registered() ) {
12538
+ // If opted-in, override trial with up to date data from API.
12539
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
12540
+ $trial_plans_count = count( $trial_plans );
12541
+
12542
+ if ( 0 === $trial_plans_count ) {
12543
+ // If there's no plans with a trial just exit.
12544
+ return false;
12545
+ }
12546
+
12547
+ /**
12548
+ * @var FS_Plugin_Plan $paid_plan
12549
+ */
12550
+ $paid_plan = $trial_plans[0];
12551
+ $require_payment = $paid_plan->is_require_subscription;
12552
+ $trial_period = $paid_plan->trial_period;
12553
+
12554
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
12555
+
12556
+ if ( $total_paid_plans !== $trial_plans_count ) {
12557
+ // Not all paid plans have a trial - generate a string of those that have it.
12558
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
12559
+ $plans_string .= sprintf(
12560
+ ' <a href="%s">%s</a>',
12561
+ $trial_url,
12562
+ $trial_plans[ $i ]->title
12563
+ );
12564
+
12565
+ if ( $i < $trial_plans_count - 2 ) {
12566
+ $plans_string .= ', ';
12567
+ } else if ( $i == $trial_plans_count - 2 ) {
12568
+ $plans_string .= ' and ';
12569
+ }
12570
+ }
12571
+ }
12572
+ }
12573
+
12574
+ $message = sprintf(
12575
+ $this->get_text( 'hey' ) . '! ' . $this->get_text( 'trial-x-promotion-message' ),
12576
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
12577
+ $plans_string,
12578
+ $trial_period
12579
+ );
12580
+
12581
+ // "No Credit-Card Required" or "No Commitment for N Days".
12582
+ $cc_string = $require_payment ?
12583
+ sprintf( $this->get_text( 'no-commitment-for-x-days' ), $trial_period ) :
12584
+ $this->get_text( 'no-cc-required' ) . '!';
12585
+
12586
+
12587
+ // Start trial button.
12588
+ $button = ' ' . sprintf(
12589
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
12590
+ $trial_url,
12591
+ $this->get_text( 'start-free-trial' )
12592
+ );
12593
+
12594
+ $this->_admin_notices->add_sticky(
12595
+ $this->apply_filters( 'trial_promotion_message', "{$message} {$cc_string} {$button}" ),
12596
+ 'trial_promotion',
12597
+ '',
12598
+ 'promotion'
12599
+ );
12600
+
12601
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
12602
+
12603
+ return true;
12604
+ }
12605
+
12606
+ /**
12607
+ * @author Vova Feldman (@svovaf)
12608
+ * @since 1.2.1.5
12609
+ */
12610
+ function _enqueue_common_css() {
12611
+ if ( $this->has_paid_plan() && ! $this->is_paying() ) {
12612
+ // Add basic CSS for admin-notices and menu-item colors.
12613
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
12614
+ }
12615
+ }
12616
+
12617
+ /**
12618
+ * @author Leo Fajardo (leorw)
12619
+ * @since 1.2.2
12620
+ */
12621
+ function _show_theme_activation_optin_dialog() {
12622
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
12623
+
12624
+ add_action( 'admin_footer-themes.php', array( &$this, '_add_fs_theme_activation_dialog' ) );
12625
+ }
12626
+
12627
+ /**
12628
+ * @author Leo Fajardo (leorw)
12629
+ * @since 1.2.2
12630
+ */
12631
+ function _add_fs_theme_activation_dialog() {
12632
+ $vars = array( 'id' => $this->_module_id );
12633
+ fs_require_once_template( 'connect.php', $vars );
12634
+ }
12635
+
12636
+ /* Action Links
12637
+ ------------------------------------------------------------------------------------------------------------------*/
12638
+ private $_action_links_hooked = false;
12639
+ private $_action_links = array();
12640
+
12641
+ /**
12642
+ * Hook to plugin action links filter.
12643
+ *
12644
+ * @author Vova Feldman (@svovaf)
12645
+ * @since 1.0.0
12646
+ */
12647
+ private function hook_plugin_action_links() {
12648
+ $this->_logger->entrance();
12649
+
12650
+ $this->_action_links_hooked = true;
12651
+
12652
+ $this->_logger->log( 'Adding action links hooks.' );
12653
+
12654
+ // Add action link to settings page.
12655
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
12656
+ &$this,
12657
+ '_modify_plugin_action_links_hook'
12658
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
12659
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
12660
+ &$this,
12661
+ '_modify_plugin_action_links_hook'
12662
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
12663
+ }
12664
+
12665
+ /**
12666
+ * Add plugin action link.
12667
+ *
12668
+ * @author Vova Feldman (@svovaf)
12669
+ * @since 1.0.0
12670
+ *
12671
+ * @param $label
12672
+ * @param $url
12673
+ * @param bool $external
12674
+ * @param int $priority
12675
+ * @param bool $key
12676
+ */
12677
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
12678
+ $this->_logger->entrance();
12679
+
12680
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
12681
+ $this->_action_links[ $priority ] = array();
12682
+ }
12683
+
12684
+ if ( false === $key ) {
12685
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
12686
+ }
12687
+
12688
+ $this->_action_links[ $priority ][] = array(
12689
+ 'label' => $label,
12690
+ 'href' => $url,
12691
+ 'key' => $key,
12692
+ 'external' => $external
12693
+ );
12694
+ }
12695
+
12696
+ /**
12697
+ * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
12698
+ *
12699
+ * @author Vova Feldman (@svovaf)
12700
+ * @since 1.0.0
12701
+ */
12702
+ function _add_upgrade_action_link() {
12703
+ $this->_logger->entrance();
12704
+
12705
+ if ( $this->is_registered() ) {
12706
+ if ( ! $this->is_paying() && $this->has_paid_plan() ) {
12707
+ $this->add_plugin_action_link(
12708
+ $this->get_text( 'upgrade' ),
12709
+ $this->get_upgrade_url(),
12710
+ false,
12711
+ 7,
12712
+ 'upgrade'
12713
+ );
12714
+ }
12715
+
12716
+ if ( $this->has_addons() ) {
12717
+ $this->add_plugin_action_link(
12718
+ $this->get_text( 'add-ons' ),
12719
+ $this->_get_admin_page_url( 'addons' ),
12720
+ false,
12721
+ 9,
12722
+ 'addons'
12723
+ );
12724
+ }
12725
+ }
12726
+ }
12727
+
12728
+ /**
12729
+ * Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
12730
+ *
12731
+ * @author Leo Fajardo (@leorw)
12732
+ * @since 1.1.9
12733
+ */
12734
+ function _add_license_action_link() {
12735
+ $this->_logger->entrance();
12736
+
12737
+ if ( $this->is_free_plan() && $this->is_addon() ) {
12738
+ return;
12739
+ }
12740
+
12741
+ if ( ! self::is_ajax() ) {
12742
+ // Inject license activation dialog UI and client side code.
12743
+ add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
12744
+ }
12745
+
12746
+ $link_text = $this->get_text(
12747
+ $this->is_free_plan() ?
12748
+ 'activate-license' :
12749
+ 'change-license'
12750
+ );
12751
+
12752
+ $this->add_plugin_action_link(
12753
+ $link_text,
12754
+ '#',
12755
+ false,
12756
+ 11,
12757
+ ( 'activate-license ' . $this->get_unique_affix() )
12758
+ );
12759
+ }
12760
+
12761
+ /**
12762
+ * Adds "Opt in" or "Opt out" link to the main "Plugins" page link actions collection.
12763
+ *
12764
+ * @author Leo Fajardo (@leorw)
12765
+ * @since 1.2.1.5
12766
+ */
12767
+ function _add_tracking_links() {
12768
+ if ( ! current_user_can( 'activate_plugins' ) ) {
12769
+ return;
12770
+ }
12771
+
12772
+ $this->_logger->entrance();
12773
+
12774
+ if ( fs_request_is_action_secure( $this->get_unique_affix() . '_reconnect' ) ) {
12775
+ if ( ! $this->is_registered() && $this->is_anonymous() ) {
12776
+ $this->connect_again();
12777
+
12778
+ return;
12779
+ }
12780
+ }
12781
+
12782
+ if ( ( $this->is_plugin() && ! self::is_plugins_page() ) ||
12783
+ ( $this->is_theme() && ! self::is_themes_page() )
12784
+ ) {
12785
+ // Only show tracking links on the plugins and themes pages.
12786
+ return;
12787
+ }
12788
+
12789
+ if ( ! $this->is_enable_anonymous() ) {
12790
+ // Don't allow to opt-out if anonymous mode is disabled.
12791
+ return;
12792
+ }
12793
+
12794
+ if ( ! $this->is_free_plan() ) {
12795
+ // Don't allow to opt-out if running in paid plan.
12796
+ return;
12797
+ }
12798
+
12799
+ if ( $this->add_ajax_action( 'stop_tracking', array( &$this, '_stop_tracking_callback' ) ) ) {
12800
+ return;
12801
+ }
12802
+
12803
+ if ( $this->add_ajax_action( 'allow_tracking', array( &$this, '_allow_tracking_callback' ) ) ) {
12804
+ return;
12805
+ }
12806
+
12807
+ $url = '#';
12808
+
12809
+ if ( $this->is_registered() ) {
12810
+ if ( $this->is_tracking_allowed() ) {
12811
+ $link_text_id = 'opt-out';
12812
+ } else {
12813
+ $link_text_id = 'opt-in';
12814
+ }
12815
+
12816
+ add_action( 'admin_footer', array( &$this, '_add_optout_dialog' ) );
12817
+ } else {
12818
+ $link_text_id = 'opt-in';
12819
+
12820
+ $params = ! $this->is_anonymous() ?
12821
+ array() :
12822
+ array(
12823
+ 'nonce' => wp_create_nonce( $this->get_unique_affix() . '_reconnect' ),
12824
+ 'fs_action' => ( $this->get_unique_affix() . '_reconnect' ),
12825
+ );
12826
+
12827
+ $url = $this->get_activation_url( $params );
12828
+ }
12829
+
12830
+ if ( $this->is_plugin() && self::is_plugins_page() ) {
12831
+ $this->add_plugin_action_link(
12832
+ $this->get_text( $link_text_id ),
12833
+ $url,
12834
+ false,
12835
+ 13,
12836
+ "opt-in-or-opt-out {$this->_slug}"
12837
+ );
12838
+ }
12839
+ }
12840
+
12841
+ /**
12842
+ * Get the URL of the page that should be loaded right after the plugin activation.
12843
+ *
12844
+ * @author Vova Feldman (@svovaf)
12845
+ * @since 1.1.7.4
12846
+ *
12847
+ * @return string
12848
+ */
12849
+ function get_after_plugin_activation_redirect_url() {
12850
+ $url = false;
12851
+
12852
+ if ( ! $this->is_addon() || ! $this->has_free_plan() ) {
12853
+ $first_time_path = $this->_menu->get_first_time_path();
12854
+ $url = $this->is_activation_mode() ?
12855
+ $this->get_activation_url() :
12856
+ ( empty( $first_time_path ) ?
12857
+ $this->_get_admin_page_url() :
12858
+ $first_time_path );
12859
+ } else {
12860
+ $plugin_fs = false;
12861
+
12862
+ if ( $this->is_parent_plugin_installed() ) {
12863
+ $plugin_fs = self::get_parent_instance();
12864
+ }
12865
+
12866
+ if ( is_object( $plugin_fs ) ) {
12867
+ if ( ! $plugin_fs->is_registered() ) {
12868
+ // Forward to parent plugin connect when parent not registered.
12869
+ $url = $plugin_fs->get_activation_url();
12870
+ } else {
12871
+ // Forward to account page.
12872
+ $url = $plugin_fs->_get_admin_page_url( 'account' );
12873
+ }
12874
+ }
12875
+ }
12876
+
12877
+ return $url;
12878
+ }
12879
+
12880
+ /**
12881
+ * Forward page to activation page.
12882
+ *
12883
+ * @author Vova Feldman (@svovaf)
12884
+ * @since 1.0.3
12885
+ */
12886
+ function _redirect_on_activation_hook() {
12887
+ $url = $this->get_after_plugin_activation_redirect_url();
12888
+
12889
+ if ( is_string( $url ) ) {
12890
+ fs_redirect( $url );
12891
+ }
12892
+ }
12893
+
12894
+ /**
12895
+ * Modify plugin's page action links collection.
12896
+ *
12897
+ * @author Vova Feldman (@svovaf)
12898
+ * @since 1.0.0
12899
+ *
12900
+ * @param array $links
12901
+ * @param $file
12902
+ *
12903
+ * @return array
12904
+ */
12905
+ function _modify_plugin_action_links_hook( $links, $file ) {
12906
+ $this->_logger->entrance();
12907
+
12908
+ $passed_deactivate = false;
12909
+ $deactivate_link = '';
12910
+ $before_deactivate = array();
12911
+ $after_deactivate = array();
12912
+ foreach ( $links as $key => $link ) {
12913
+ if ( 'deactivate' === $key ) {
12914
+ $deactivate_link = $link;
12915
+ $passed_deactivate = true;
12916
+ continue;
12917
+ }
12918
+
12919
+ if ( ! $passed_deactivate ) {
12920
+ $before_deactivate[ $key ] = $link;
12921
+ } else {
12922
+ $after_deactivate[ $key ] = $link;
12923
+ }
12924
+ }
12925
+
12926
+ ksort( $this->_action_links );
12927
+
12928
+ foreach ( $this->_action_links as $new_links ) {
12929
+ foreach ( $new_links as $link ) {
12930
+ $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
12931
+ }
12932
+ }
12933
+
12934
+ if ( ! empty( $deactivate_link ) ) {
12935
+ /**
12936
+ * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
12937
+ *
12938
+ * @since 1.2.1.6 Always show the deactivation feedback form since we added automatic free version deactivation upon premium code activation.
12939
+ */
12940
+ $deactivate_link .= '<i class="fs-module-id" data-module-id="' . $this->_module_id . '"></i>';
12941
+
12942
+ // Append deactivation link.
12943
+ $before_deactivate['deactivate'] = $deactivate_link;
12944
+ }
12945
+
12946
+ return array_merge( $before_deactivate, $after_deactivate );
12947
+ }
12948
+
12949
+ /**
12950
+ * Adds admin message.
12951
+ *
12952
+ * @author Vova Feldman (@svovaf)
12953
+ * @since 1.0.4
12954
+ *
12955
+ * @param string $message
12956
+ * @param string $title
12957
+ * @param string $type
12958
+ */
12959
+ function add_admin_message( $message, $title = '', $type = 'success' ) {
12960
+ $this->_admin_notices->add( $message, $title, $type );
12961
+ }
12962
+
12963
+ /**
12964
+ * Adds sticky admin message.
12965
+ *
12966
+ * @author Vova Feldman (@svovaf)
12967
+ * @since 1.1.0
12968
+ *
12969
+ * @param string $message
12970
+ * @param string $id
12971
+ * @param string $title
12972
+ * @param string $type
12973
+ */
12974
+ function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
12975
+ $this->_admin_notices->add_sticky( $message, $id, $title, $type );
12976
+ }
12977
+
12978
+ /**
12979
+ * Helper function that returns the final steps for the upgrade completion.
12980
+ *
12981
+ * If the module is already running the premium code, returns an empty string.
12982
+ *
12983
+ * @author Vova Feldman (@svovaf)
12984
+ * @since 1.2.1
12985
+ *
12986
+ * @param string $plan_title
12987
+ *
12988
+ * @return string
12989
+ */
12990
+ private function get_complete_upgrade_instructions( $plan_title = '' ) {
12991
+ if ( ! $this->has_premium_version() || $this->is_premium() ) {
12992
+ return '';
12993
+ }
12994
+
12995
+ if ( empty( $plan_title ) ) {
12996
+ $plan_title = $this->_site->plan->title;
12997
+ }
12998
+
12999
+ // @since 1.2.1.5 The free version is auto deactivated.
13000
+ $deactivation_step = version_compare( $this->version, '1.2.1.5', '<' ) ?
13001
+ ( '<li>' . $this->get_text( 'deactivate-free-version' ) . '.</li>' ) :
13002
+ '';
13003
+
13004
+ return sprintf(
13005
+ ' %s: <ol><li>%s.</li>%s<li>%s (<a href="%s" target="_blank">%s</a>).</li></ol>',
13006
+ $this->get_text( 'follow-steps-to-complete-upgrade' ),
13007
+ $this->get_latest_download_link( sprintf(
13008
+ $this->get_text( 'download-latest-x-version' ),
13009
+ $plan_title
13010
+ ) ),
13011
+ $deactivation_step,
13012
+ $this->get_text( 'upload-and-activate' ),
13013
+ '//bit.ly/upload-wp-' . $this->_module_type . 's',
13014
+ $this->get_text( 'howto-upload-activate' )
13015
+ );
13016
+ }
13017
+
13018
+ /**
13019
+ * @author Vova Feldman (@svovaf)
13020
+ * @since 1.2.1.7
13021
+ *
13022
+ * @param string $key
13023
+ *
13024
+ * @return string
13025
+ */
13026
+ function get_text( $key ) {
13027
+ return fs_text( $key, $this->_slug );
13028
+ }
13029
+
13030
+ #----------------------------------------------------------------------------------
13031
+ #region Versioning
13032
+ #----------------------------------------------------------------------------------
13033
+
13034
+ /**
13035
+ * Check if Freemius in SDK upgrade mode.
13036
+ *
13037
+ * @author Vova Feldman (@svovaf)
13038
+ * @since 1.0.9
13039
+ *
13040
+ * @return bool
13041
+ */
13042
+ function is_sdk_upgrade_mode() {
13043
+ return isset( $this->_storage->sdk_upgrade_mode ) ?
13044
+ $this->_storage->sdk_upgrade_mode :
13045
+ false;
13046
+ }
13047
+
13048
+ /**
13049
+ * Turn SDK upgrade mode off.
13050
+ *
13051
+ * @author Vova Feldman (@svovaf)
13052
+ * @since 1.0.9
13053
+ */
13054
+ function set_sdk_upgrade_complete() {
13055
+ $this->_storage->sdk_upgrade_mode = false;
13056
+ }
13057
+
13058
+ /**
13059
+ * Check if plugin upgrade mode.
13060
+ *
13061
+ * @author Vova Feldman (@svovaf)
13062
+ * @since 1.0.9
13063
+ *
13064
+ * @return bool
13065
+ */
13066
+ function is_plugin_upgrade_mode() {
13067
+ return isset( $this->_storage->plugin_upgrade_mode ) ?
13068
+ $this->_storage->plugin_upgrade_mode :
13069
+ false;
13070
+ }
13071
+
13072
+ /**
13073
+ * Turn plugin upgrade mode off.
13074
+ *
13075
+ * @author Vova Feldman (@svovaf)
13076
+ * @since 1.0.9
13077
+ */
13078
+ function set_plugin_upgrade_complete() {
13079
+ $this->_storage->plugin_upgrade_mode = false;
13080
+ }
13081
+
13082
+ #endregion
13083
+
13084
+ #----------------------------------------------------------------------------------
13085
+ #region Permissions
13086
+ #----------------------------------------------------------------------------------
13087
+
13088
+ /**
13089
+ * Check if specific permission requested.
13090
+ *
13091
+ * @author Vova Feldman (@svovaf)
13092
+ * @since 1.1.6
13093
+ *
13094
+ * @param string $permission
13095
+ *
13096
+ * @return bool
13097
+ */
13098
+ function is_permission_requested( $permission ) {
13099
+ return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
13100
+ }
13101
+
13102
+ #endregion
13103
+
13104
+ #----------------------------------------------------------------------------------
13105
+ #region Auto Activation
13106
+ #----------------------------------------------------------------------------------
13107
+
13108
+ /**
13109
+ * Hints the SDK if running an auto-installation.
13110
+ *
13111
+ * @var bool
13112
+ */
13113
+ private $_isAutoInstall = false;
13114
+
13115
+ /**
13116
+ * After upgrade callback to install and auto activate a plugin.
13117
+ * This code will only be executed on explicit request from the user,
13118
+ * following the practice Jetpack are using with their theme installations.
13119
+ *
13120
+ * @link https://make.wordpress.org/plugins/2017/03/16/clarification-of-guideline-8-executable-code-and-installs/
13121
+ *
13122
+ * @author Vova Feldman (@svovaf)
13123
+ * @since 1.2.1.7
13124
+ */
13125
+ function _install_premium_version_ajax_action() {
13126
+ $this->_logger->entrance();
13127
+
13128
+ $this->check_ajax_referer( 'install_premium_version' );
13129
+
13130
+ if ( ! $this->is_registered() ) {
13131
+ // Not registered.
13132
+ self::shoot_ajax_failure( array(
13133
+ 'message' => $this->get_text( 'auto-install-error-not-opted-in' ),
13134
+ 'code' => 'premium_installed',
13135
+ ) );
13136
+ }
13137
+
13138
+ $plugin_id = fs_request_get( 'module_id', $this->get_id() );
13139
+
13140
+ if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
13141
+ // Invalid ID.
13142
+ self::shoot_ajax_failure( array(
13143
+ 'message' => $this->get_text( 'auto-install-error-invalid-id' ),
13144
+ 'code' => 'invalid_module_id',
13145
+ ) );
13146
+ }
13147
+
13148
+ if ( $plugin_id == $this->get_id() ) {
13149
+ if ( $this->is_premium() ) {
13150
+ // Already using the premium code version.
13151
+ self::shoot_ajax_failure( array(
13152
+ 'message' => $this->get_text( 'auto-install-error-premium-activated' ),
13153
+ 'code' => 'premium_installed',
13154
+ ) );
13155
+ }
13156
+ if ( ! $this->can_use_premium_code() ) {
13157
+ // Don't have access to the premium code.
13158
+ self::shoot_ajax_failure( array(
13159
+ 'message' => $this->get_text( 'auto-install-error-invalid-license' ),
13160
+ 'code' => 'invalid_license',
13161
+ ) );
13162
+ }
13163
+ if ( ! $this->has_release_on_freemius() ) {
13164
+ // Plugin is a serviceware, no premium code version.
13165
+ self::shoot_ajax_failure( array(
13166
+ 'message' => $this->get_text( 'auto-install-error-serviceware' ),
13167
+ 'code' => 'premium_version_missing',
13168
+ ) );
13169
+ }
13170
+ } else {
13171
+ $addon = $this->get_addon( $plugin_id );
13172
+
13173
+ if ( ! is_object( $addon ) ) {
13174
+ // Invalid add-on ID.
13175
+ self::shoot_ajax_failure( array(
13176
+ 'message' => $this->get_text( 'auto-install-error-invalid-id' ),
13177
+ 'code' => 'invalid_module_id',
13178
+ ) );
13179
+ }
13180
+
13181
+ if ( $this->is_addon_activated( $plugin_id, true ) ) {
13182
+ // Premium add-on version is already activated.
13183
+ self::shoot_ajax_failure( array(
13184
+ 'message' => $this->get_text( 'auto-install-error-premium-addon-activated' ),
13185
+ 'code' => 'premium_installed',
13186
+ ) );
13187
+ }
13188
+ }
13189
+
13190
+ $this->_isAutoInstall = true;
13191
+
13192
+ // Try to install and activate.
13193
+ $updater = new FS_Plugin_Updater( $this );
13194
+ $result = $updater->install_and_activate_plugin( $plugin_id );
13195
+
13196
+ if ( is_array( $result ) && ! empty( $result['message'] ) ) {
13197
+ self::shoot_ajax_failure( array(
13198
+ 'message' => $result['message'],
13199
+ 'code' => $result['code'],
13200
+ ) );
13201
+ }
13202
+
13203
+ self::shoot_ajax_success( $result );
13204
+ }
13205
+
13206
+ /**
13207
+ * Displays module activation dialog box after a successful upgrade
13208
+ * where the user explicitly requested to auto download and install
13209
+ * the premium version.
13210
+ *
13211
+ * @author Vova Feldman (@svovaf)
13212
+ * @since 1.2.1.7
13213
+ */
13214
+ function _add_auto_installation_dialog_box() {
13215
+ $this->_logger->entrance();
13216
+
13217
+ if ( ! $this->is_registered() ) {
13218
+ // Not registered.
13219
+ return;
13220
+ }
13221
+
13222
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
13223
+
13224
+ if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
13225
+ // Invalid module ID.
13226
+ return;
13227
+ }
13228
+
13229
+ if ( $plugin_id == $this->get_id() ) {
13230
+ if ( $this->is_premium() ) {
13231
+ // Already using the premium code version.
13232
+ return;
13233
+ }
13234
+ if ( ! $this->can_use_premium_code() ) {
13235
+ // Don't have access to the premium code.
13236
+ return;
13237
+ }
13238
+ if ( ! $this->has_release_on_freemius() ) {
13239
+ // Plugin is a serviceware, no premium code version.
13240
+ return;
13241
+ }
13242
+ } else {
13243
+ $addon = $this->get_addon( $plugin_id );
13244
+
13245
+ if ( ! is_object( $addon ) ) {
13246
+ // Invalid add-on ID.
13247
+ return;
13248
+ }
13249
+
13250
+ if ( $this->is_addon_activated( $plugin_id, true ) ) {
13251
+ // Premium add-on version is already activated.
13252
+ return;
13253
+ }
13254
+ }
13255
+
13256
+ $vars = array(
13257
+ 'id' => $plugin_id,
13258
+ 'slug' => $this->_slug,
13259
+ );
13260
+
13261
+ fs_require_template( 'auto-installation.php', $vars );
13262
+ }
13263
+
13264
+ #endregion
13265
+
13266
+ #--------------------------------------------------------------------------------
13267
+ #region Tabs Integration
13268
+ #--------------------------------------------------------------------------------
13269
+
13270
+ #region Module's Original Tabs
13271
+
13272
+ /**
13273
+ * Inject a JavaScript logic to capture the theme tabs HTML.
13274
+ *
13275
+ * @author Vova Feldman (@svovaf)
13276
+ * @since 1.2.2.7
13277
+ */
13278
+ function _tabs_capture() {
13279
+ $this->_logger->entrance();
13280
+
13281
+ if ( ! $this->is_theme_settings_page() ||
13282
+ ! $this->is_matching_url( $this->main_menu_url() )
13283
+ ) {
13284
+ return;
13285
+ }
13286
+
13287
+ $params = array(
13288
+ 'id' => $this->_module_id,
13289
+ );
13290
+
13291
+ fs_require_once_template( 'tabs-capture-js.php', $params );
13292
+ }
13293
+
13294
+ /**
13295
+ * Cache theme's tabs HTML for a week. The cache will also be set as expired
13296
+ * after version and type (free/premium) changes, in addition to the week period.
13297
+ *
13298
+ * @author Vova Feldman (@svovaf)
13299
+ * @since 1.2.2.7
13300
+ */
13301
+ function _store_tabs_ajax_action() {
13302
+ $this->_logger->entrance();
13303
+
13304
+ $this->check_ajax_referer( 'store_tabs' );
13305
+
13306
+ // Init filesystem if not yet initiated.
13307
+ WP_Filesystem();
13308
+
13309
+ // Get POST body HTML data.
13310
+ global $wp_filesystem;
13311
+ $tabs_html = $wp_filesystem->get_contents( "php://input" );
13312
+
13313
+ if ( is_string( $tabs_html ) ) {
13314
+ $tabs_html = trim( $tabs_html );
13315
+ }
13316
+
13317
+ if ( ! is_string( $tabs_html ) || empty( $tabs_html ) ) {
13318
+ self::shoot_ajax_failure();
13319
+ }
13320
+
13321
+ $this->_cache->set( 'tabs', $tabs_html, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
13322
+
13323
+ self::shoot_ajax_success();
13324
+ }
13325
+
13326
+ /**
13327
+ * Cache theme's settings page custom styles. The cache will also be set as expired
13328
+ * after version and type (free/premium) changes, in addition to the week period.
13329
+ *
13330
+ * @author Vova Feldman (@svovaf)
13331
+ * @since 1.2.2.7
13332
+ */
13333
+ function _store_tabs_styles() {
13334
+ $this->_logger->entrance();
13335
+
13336
+ if ( ! $this->is_theme_settings_page() ||
13337
+ ! $this->is_matching_url( $this->main_menu_url() )
13338
+ ) {
13339
+ return;
13340
+ }
13341
+
13342
+ $wp_styles = wp_styles();
13343
+
13344
+ $theme_styles_url = get_template_directory_uri();
13345
+
13346
+ $stylesheets = array();
13347
+ foreach ( $wp_styles->queue as $handler ) {
13348
+ if ( fs_starts_with( $handler, 'fs_' ) ) {
13349
+ // Assume that stylesheets that their handler starts with "fs_" belong to the SDK.
13350
+ continue;
13351
+ }
13352
+
13353
+ /**
13354
+ * @var _WP_Dependency $stylesheet
13355
+ */
13356
+ $stylesheet = $wp_styles->registered[ $handler ];
13357
+
13358
+ if ( fs_starts_with( $stylesheet->src, $theme_styles_url ) ) {
13359
+ $stylesheets[] = $stylesheet->src;
13360
+ }
13361
+ }
13362
+
13363
+ if ( ! empty( $stylesheets ) ) {
13364
+ $this->_cache->set( 'tabs_stylesheets', $stylesheets, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
13365
+ }
13366
+ }
13367
+
13368
+ /**
13369
+ * Check if module's original settings page has any tabs.
13370
+ *
13371
+ * @author Vova Feldman (@svovaf)
13372
+ * @since 1.2.2.7
13373
+ *
13374
+ * @return bool
13375
+ */
13376
+ private function has_tabs() {
13377
+ return $this->_cache->has( 'tabs' );
13378
+ }
13379
+
13380
+ /**
13381
+ * Get module's settings page HTML content, starting
13382
+ * from the beginning of the <div class="wrap"> element,
13383
+ * until the tabs HTML (including).
13384
+ *
13385
+ * @author Vova Feldman (@svovaf)
13386
+ * @since 1.2.2.7
13387
+ *
13388
+ * @return string
13389
+ */
13390
+ private function get_tabs_html() {
13391
+ $this->_logger->entrance();
13392
+
13393
+ return $this->_cache->get( 'tabs' );
13394
+ }
13395
+
13396
+ /**
13397
+ * Check if page should include tabs.
13398
+ *
13399
+ * @author Vova Feldman (@svovaf)
13400
+ * @since 1.2.2.7
13401
+ *
13402
+ * @return bool
13403
+ */
13404
+ private function should_page_include_tabs()
13405
+ {
13406
+ if ( ! $this->has_settings_menu() ) {
13407
+ // Don't add tabs if no settings at all.
13408
+ return false;
13409
+ }
13410
+
13411
+ if ( ! $this->is_theme() ) {
13412
+ // Only add tabs to themes for now.
13413
+ return false;
13414
+ }
13415
+
13416
+ if ( ! $this->has_paid_plan() && ! $this->has_addons() ) {
13417
+ // Only add tabs to monetizing themes.
13418
+ return false;
13419
+ }
13420
+
13421
+ if ( ! $this->is_theme_settings_page() ) {
13422
+ // Only add tabs if browsing one of the theme's setting pages.
13423
+ return false;
13424
+ }
13425
+
13426
+ if ( $this->is_admin_page( 'pricing' ) && fs_request_get_bool( 'checkout' ) ) {
13427
+ // Don't add tabs on checkout page, we want to reduce distractions
13428
+ // as much as possible.
13429
+ return false;
13430
+ }
13431
+
13432
+ return true;
13433
+ }
13434
+
13435
+ /**
13436
+ * Add the tabs HTML before the setting's page content and
13437
+ * enqueue any required stylesheets.
13438
+ *
13439
+ * @author Vova Feldman (@svovaf)
13440
+ * @since 1.2.2.7
13441
+ *
13442
+ * @return bool If tabs were included.
13443
+ */
13444
+ function _add_tabs_before_content() {
13445
+ $this->_logger->entrance();
13446
+
13447
+ if ( ! $this->should_page_include_tabs() ) {
13448
+ return false;
13449
+ }
13450
+
13451
+ /**
13452
+ * Enqueue the original stylesheets that are included in the
13453
+ * theme settings page. That way, if the theme settings has
13454
+ * some custom _styled_ content above the tabs UI, this
13455
+ * will make sure that the styling is preserved.
13456
+ */
13457
+ $stylesheets = $this->_cache->get( 'tabs_stylesheets', array() );
13458
+ if ( is_array( $stylesheets ) ) {
13459
+ for ( $i = 0, $len = count( $stylesheets ); $i < $len; $i ++ ) {
13460
+ wp_enqueue_style( "fs_{$this->_module_id}_tabs_{$i}", $stylesheets[ $i ] );
13461
+ }
13462
+ }
13463
+
13464
+ // Cut closing </div> tag.
13465
+ echo substr( trim( $this->get_tabs_html() ), 0, - 6 );
13466
+
13467
+ return true;
13468
+ }
13469
+
13470
+ /**
13471
+ * Add the tabs closing HTML after the setting's page content.
13472
+ *
13473
+ * @author Vova Feldman (@svovaf)
13474
+ * @since 1.2.2.7
13475
+ *
13476
+ * @return bool If tabs closing HTML was included.
13477
+ */
13478
+ function _add_tabs_after_content() {
13479
+ $this->_logger->entrance();
13480
+
13481
+ if ( ! $this->should_page_include_tabs() ) {
13482
+ return false;
13483
+ }
13484
+
13485
+ echo '</div>';
13486
+
13487
+ return true;
13488
+ }
13489
+
13490
+ #endregion
13491
+
13492
+ /**
13493
+ * Add in-page JavaScript to inject the Freemius tabs into
13494
+ * the module's setting tabs section.
13495
+ *
13496
+ * @author Vova Feldman (@svovaf)
13497
+ * @since 1.2.2.7
13498
+ */
13499
+ function _add_freemius_tabs() {
13500
+ $this->_logger->entrance();
13501
+
13502
+ if ( ! $this->should_page_include_tabs() ) {
13503
+ return;
13504
+ }
13505
+
13506
+ $params = array( 'id' => $this->_module_id );
13507
+ fs_require_once_template( 'tabs.php', $params );
13508
+ }
13509
+
13510
+ #endregion
13511
+
13512
+ #--------------------------------------------------------------------------------
13513
+ #region Customizer Integration for Themes
13514
+ #--------------------------------------------------------------------------------
13515
+
13516
+ /**
13517
+ * @author Vova Feldman (@svovaf)
13518
+ * @since 1.2.2.7
13519
+ *
13520
+ * @param WP_Customize_Manager $customizer
13521
+ */
13522
+ function _customizer_register($customizer) {
13523
+ $this->_logger->entrance();
13524
+
13525
+ if ( $this->is_pricing_page_visible() ) {
13526
+ require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-upsell-control.php';
13527
+
13528
+ $customizer->add_section( 'freemius_upsell', array(
13529
+ 'title' => '&#9733; ' . $this->get_text( 'view-paid-features' ),
13530
+ 'priority' => 1,
13531
+ ) );
13532
+ $customizer->add_setting( 'freemius_upsell', array(
13533
+ 'sanitize_callback' => 'esc_html',
13534
+ ) );
13535
+
13536
+ $customizer->add_control( new FS_Customizer_Upsell_Control( $customizer, 'freemius_upsell', array(
13537
+ 'fs' => $this,
13538
+ 'section' => 'freemius_upsell',
13539
+ 'priority' => 100,
13540
+ ) ) );
13541
+ }
13542
+
13543
+ if ( $this->is_page_visible( 'contact' ) || $this->is_page_visible( 'support' ) ) {
13544
+ require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-support-section.php';
13545
+
13546
+ // Main Documentation Link In Customizer Root.
13547
+ $customizer->add_section( new FS_Customizer_Support_Section( $customizer, 'freemius_support', array(
13548
+ 'fs' => $this,
13549
+ 'priority' => 1000,
13550
+ ) ) );
13551
+ }
13552
+ }
13553
+
13554
+ #endregion
13555
+
13556
+ /**
13557
+ * If the theme has a paid version, add some custom
13558
+ * styling to the theme's premium version (if exists)
13559
+ * to highlight that it's the premium version of the
13560
+ * same theme, making it easier for identification
13561
+ * after the user upgrades and upload it to the site.
13562
+ *
13563
+ * @author Vova Feldman (@svovaf)
13564
+ * @since 1.2.2.7
13565
+ */
13566
+ function _style_premium_theme() {
13567
+ $this->_logger->entrance();
13568
+
13569
+ if ( ! self::is_themes_page() ) {
13570
+ // Only include in the themes page.
13571
+ return;
13572
+ }
13573
+
13574
+ if ( ! $this->has_paid_plan() ) {
13575
+ // Only include if has any paid plans.
13576
+ return;
13577
+ }
13578
+
13579
+ $params = null;
13580
+ fs_require_once_template( '/js/jquery.content-change.php', $params );
13581
+
13582
+ $params = array(
13583
+ 'slug' => $this->_slug,
13584
+ 'id' => $this->_module_id,
13585
+ );
13586
+
13587
+ fs_require_template( '/js/style-premium-theme.php', $params );
13588
+ }
13589
+
13590
+ #----------------------------------------------------------------------------------
13591
+ #region Marketing
13592
+ #----------------------------------------------------------------------------------
13593
+
13594
+ /**
13595
+ * Check if current user purchased any other plugins before.
13596
+ *
13597
+ * @author Vova Feldman (@svovaf)
13598
+ * @since 1.0.9
13599
+ *
13600
+ * @return bool
13601
+ */
13602
+ function has_purchased_before() {
13603
+ // TODO: Implement has_purchased_before() method.
13604
+ throw new Exception( 'not implemented' );
13605
+ }
13606
+
13607
+ /**
13608
+ * Check if current user classified as an agency.
13609
+ *
13610
+ * @author Vova Feldman (@svovaf)
13611
+ * @since 1.0.9
13612
+ *
13613
+ * @return bool
13614
+ */
13615
+ function is_agency() {
13616
+ // TODO: Implement is_agency() method.
13617
+ throw new Exception( 'not implemented' );
13618
+ }
13619
+
13620
+ /**
13621
+ * Check if current user classified as a developer.
13622
+ *
13623
+ * @author Vova Feldman (@svovaf)
13624
+ * @since 1.0.9
13625
+ *
13626
+ * @return bool
13627
+ */
13628
+ function is_developer() {
13629
+ // TODO: Implement is_developer() method.
13630
+ throw new Exception( 'not implemented' );
13631
+ }
13632
+
13633
+ /**
13634
+ * Check if current user classified as a business.
13635
+ *
13636
+ * @author Vova Feldman (@svovaf)
13637
+ * @since 1.0.9
13638
+ *
13639
+ * @return bool
13640
+ */
13641
+ function is_business() {
13642
+ // TODO: Implement is_business() method.
13643
+ throw new Exception( 'not implemented' );
13644
+ }
13645
+
13646
+ #endregion
13647
+ }
freemius/includes/class-fs-api.php ADDED
@@ -0,0 +1,558 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Api
15
+ *
16
+ * Wraps Freemius API SDK to handle:
17
+ * 1. Clock sync.
18
+ * 2. Fallback to HTTP when HTTPS fails.
19
+ * 3. Adds caching layer to GET requests.
20
+ * 4. Adds consistency for failed requests by using last cached version.
21
+ */
22
+ class FS_Api {
23
+ /**
24
+ * @var FS_Api[]
25
+ */
26
+ private static $_instances = array();
27
+
28
+ /**
29
+ * @var FS_Option_Manager Freemius options, options-manager.
30
+ */
31
+ private static $_options;
32
+
33
+ /**
34
+ * @var FS_Cache_Manager API Caching layer
35
+ */
36
+ private static $_cache;
37
+
38
+ /**
39
+ * @var int Clock diff in seconds between current server to API server.
40
+ */
41
+ private static $_clock_diff;
42
+
43
+ /**
44
+ * @var Freemius_Api_WordPress
45
+ */
46
+ private $_api;
47
+
48
+ /**
49
+ * @var string
50
+ */
51
+ private $_slug;
52
+
53
+ /**
54
+ * @var FS_Logger
55
+ * @since 1.0.4
56
+ */
57
+ private $_logger;
58
+
59
+ /**
60
+ * @param string $slug
61
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
62
+ * @param number $id Element's id.
63
+ * @param string $public_key Public key.
64
+ * @param bool $is_sandbox
65
+ * @param bool|string $secret_key Element's secret key.
66
+ *
67
+ * @return FS_Api
68
+ */
69
+ static function instance( $slug, $scope, $id, $public_key, $is_sandbox, $secret_key = false ) {
70
+ $identifier = md5( $slug . $scope . $id . $public_key . ( is_string( $secret_key ) ? $secret_key : '' ) . json_encode( $is_sandbox ) );
71
+
72
+ if ( ! isset( self::$_instances[ $identifier ] ) ) {
73
+ self::_init();
74
+
75
+ self::$_instances[ $identifier ] = new FS_Api( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox );
76
+ }
77
+
78
+ return self::$_instances[ $identifier ];
79
+ }
80
+
81
+ private static function _init() {
82
+ if ( isset( self::$_options ) ) {
83
+ return;
84
+ }
85
+
86
+ if ( ! class_exists( 'Freemius_Api_WordPress' ) ) {
87
+ require_once WP_FS__DIR_SDK . '/FreemiusWordPress.php';
88
+ }
89
+
90
+ self::$_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true );
91
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
92
+
93
+ self::$_clock_diff = self::$_options->get_option( 'api_clock_diff', 0 );
94
+ Freemius_Api_WordPress::SetClockDiff( self::$_clock_diff );
95
+
96
+ if ( self::$_options->get_option( 'api_force_http', false ) ) {
97
+ Freemius_Api_WordPress::SetHttp();
98
+ }
99
+ }
100
+
101
+ /**
102
+ * @param string $slug
103
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
104
+ * @param number $id Element's id.
105
+ * @param string $public_key Public key.
106
+ * @param bool|string $secret_key Element's secret key.
107
+ * @param bool $is_sandbox
108
+ */
109
+ private function __construct( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox ) {
110
+ $this->_api = new Freemius_Api_WordPress( $scope, $id, $public_key, $secret_key, $is_sandbox );
111
+
112
+ $this->_slug = $slug;
113
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_api', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
114
+ }
115
+
116
+ /**
117
+ * Find clock diff between server and API server, and store the diff locally.
118
+ *
119
+ * @param bool|int $diff
120
+ *
121
+ * @return bool|int False if clock diff didn't change, otherwise returns the clock diff in seconds.
122
+ */
123
+ private function _sync_clock_diff( $diff = false ) {
124
+ $this->_logger->entrance();
125
+
126
+ // Sync clock and store.
127
+ $new_clock_diff = ( false === $diff ) ?
128
+ Freemius_Api_WordPress::FindClockDiff() :
129
+ $diff;
130
+
131
+ if ( $new_clock_diff === self::$_clock_diff ) {
132
+ return false;
133
+ }
134
+
135
+ self::$_clock_diff = $new_clock_diff;
136
+
137
+ // Update API clock's diff.
138
+ Freemius_Api_WordPress::SetClockDiff( self::$_clock_diff );
139
+
140
+ // Store new clock diff in storage.
141
+ self::$_options->set_option( 'api_clock_diff', self::$_clock_diff, true );
142
+
143
+ return $new_clock_diff;
144
+ }
145
+
146
+ /**
147
+ * Override API call to enable retry with servers' clock auto sync method.
148
+ *
149
+ * @param string $path
150
+ * @param string $method
151
+ * @param array $params
152
+ * @param bool $retry Is in retry or first call attempt.
153
+ *
154
+ * @return array|mixed|string|void
155
+ */
156
+ private function _call( $path, $method = 'GET', $params = array(), $retry = false ) {
157
+ $this->_logger->entrance( $method . ':' . $path );
158
+
159
+ if ( self::is_temporary_down() ) {
160
+ $result = $this->get_temporary_unavailable_error();
161
+ } else {
162
+ $result = $this->_api->Api( $path, $method, $params );
163
+
164
+ if ( null !== $result &&
165
+ isset( $result->error ) &&
166
+ isset( $result->error->code ) &&
167
+ 'request_expired' === $result->error->code
168
+ ) {
169
+ if ( ! $retry ) {
170
+ $diff = isset( $result->error->timestamp ) ?
171
+ ( time() - strtotime( $result->error->timestamp ) ) :
172
+ false;
173
+
174
+ // Try to sync clock diff.
175
+ if ( false !== $this->_sync_clock_diff( $diff ) ) {
176
+ // Retry call with new synced clock.
177
+ return $this->_call( $path, $method, $params, true );
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ if ( $this->_logger->is_on() && self::is_api_error( $result ) ) {
184
+ // Log API errors.
185
+ $this->_logger->api_error( $result );
186
+ }
187
+
188
+ return $result;
189
+ }
190
+
191
+ /**
192
+ * Override API call to wrap it in servers' clock sync method.
193
+ *
194
+ * @param string $path
195
+ * @param string $method
196
+ * @param array $params
197
+ *
198
+ * @return array|mixed|string|void
199
+ * @throws Freemius_Exception
200
+ */
201
+ function call( $path, $method = 'GET', $params = array() ) {
202
+ return $this->_call( $path, $method, $params );
203
+ }
204
+
205
+ /**
206
+ * Get API request URL signed via query string.
207
+ *
208
+ * @param string $path
209
+ *
210
+ * @return string
211
+ */
212
+ function get_signed_url( $path ) {
213
+ return $this->_api->GetSignedUrl( $path );
214
+ }
215
+
216
+ /**
217
+ * @param string $path
218
+ * @param bool $flush
219
+ * @param int $expiration (optional) Time until expiration in seconds from now, defaults to 24 hours
220
+ *
221
+ * @return stdClass|mixed
222
+ */
223
+ function get( $path = '/', $flush = false, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
224
+ $this->_logger->entrance( $path );
225
+
226
+ $cache_key = $this->get_cache_key( $path );
227
+
228
+ // Always flush during development.
229
+ if ( WP_FS__DEV_MODE || $this->_api->IsSandbox() ) {
230
+ $flush = true;
231
+ }
232
+
233
+ $cached_result = self::$_cache->get( $cache_key );
234
+
235
+ if ( $flush || ! self::$_cache->has_valid( $cache_key, $expiration ) ) {
236
+ $result = $this->call( $path );
237
+
238
+ if ( ! is_object( $result ) || isset( $result->error ) ) {
239
+ // Api returned an error.
240
+ if ( is_object( $cached_result ) &&
241
+ ! isset( $cached_result )
242
+ ) {
243
+ // If there was an error during a newer data fetch,
244
+ // fallback to older data version.
245
+ $result = $cached_result;
246
+
247
+ if ( $this->_logger->is_on() ) {
248
+ $this->_logger->warn( 'Fallback to cached API result: ' . var_export( $cached_result, true ) );
249
+ }
250
+ } else {
251
+ // If no older data version, return result without
252
+ // caching the error.
253
+ return $result;
254
+ }
255
+ }
256
+
257
+ self::$_cache->set( $cache_key, $result, $expiration );
258
+
259
+ $cached_result = $result;
260
+ } else {
261
+ $this->_logger->log( 'Using cached API result.' );
262
+ }
263
+
264
+ return $cached_result;
265
+ }
266
+
267
+ /**
268
+ * Check if there's a cached version of the API request.
269
+ *
270
+ * @author Vova Feldman (@svovaf)
271
+ * @since 1.2.1
272
+ *
273
+ * @param string $path
274
+ * @param string $method
275
+ * @param array $params
276
+ *
277
+ * @return bool
278
+ */
279
+ function is_cached( $path, $method = 'GET', $params = array() ) {
280
+ $cache_key = $this->get_cache_key( $path, $method, $params );
281
+
282
+ return self::$_cache->has_valid( $cache_key );
283
+ }
284
+
285
+ /**
286
+ * Invalidate a cached version of the API request.
287
+ *
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.2.1.5
290
+ *
291
+ * @param string $path
292
+ * @param string $method
293
+ * @param array $params
294
+ */
295
+ function purge_cache( $path, $method = 'GET', $params = array() ) {
296
+ $this->_logger->entrance( "{$method}:{$path}" );
297
+
298
+ $cache_key = $this->get_cache_key( $path, $method, $params );
299
+
300
+ self::$_cache->purge( $cache_key );
301
+ }
302
+
303
+ /**
304
+ * @param string $path
305
+ * @param string $method
306
+ * @param array $params
307
+ *
308
+ * @return string
309
+ * @throws \Freemius_Exception
310
+ */
311
+ private function get_cache_key( $path, $method = 'GET', $params = array() ) {
312
+ $canonized = $this->_api->CanonizePath( $path );
313
+ // $exploded = explode('/', $canonized);
314
+ // return $method . '_' . array_pop($exploded) . '_' . md5($canonized . json_encode($params));
315
+ return strtolower( $method . ':' . $canonized ) . ( ! empty( $params ) ? '#' . md5( json_encode( $params ) ) : '' );
316
+ }
317
+
318
+ /**
319
+ * Test API connectivity.
320
+ *
321
+ * @author Vova Feldman (@svovaf)
322
+ * @since 1.0.9 If fails, try to fallback to HTTP.
323
+ * @since 1.1.6 Added a 5-min caching mechanism, to prevent from overloading the server if the API if
324
+ * temporary down.
325
+ *
326
+ * @return bool True if successful connectivity to the API.
327
+ */
328
+ static function test() {
329
+ self::_init();
330
+
331
+ $cache_key = 'ping_test';
332
+
333
+ $test = self::$_cache->get_valid( $cache_key, null );
334
+
335
+ if ( is_null( $test ) ) {
336
+ $test = Freemius_Api_WordPress::Test();
337
+
338
+ if ( false === $test && Freemius_Api_WordPress::IsHttps() ) {
339
+ // Fallback to HTTP, since HTTPS fails.
340
+ Freemius_Api_WordPress::SetHttp();
341
+
342
+ self::$_options->set_option( 'api_force_http', true, true );
343
+
344
+ $test = Freemius_Api_WordPress::Test();
345
+
346
+ if ( false === $test ) {
347
+ /**
348
+ * API connectivity test fail also in HTTP request, therefore,
349
+ * fallback to HTTPS to keep connection secure.
350
+ *
351
+ * @since 1.1.6
352
+ */
353
+ self::$_options->set_option( 'api_force_http', false, true );
354
+ }
355
+ }
356
+
357
+ self::$_cache->set( $cache_key, $test, WP_FS__TIME_5_MIN_IN_SEC );
358
+ }
359
+
360
+ return $test;
361
+ }
362
+
363
+ /**
364
+ * Check if API is temporary down.
365
+ *
366
+ * @author Vova Feldman (@svovaf)
367
+ * @since 1.1.6
368
+ *
369
+ * @return bool
370
+ */
371
+ static function is_temporary_down() {
372
+ self::_init();
373
+
374
+ $test = self::$_cache->get_valid( 'ping_test', null );
375
+
376
+ return ( false === $test );
377
+ }
378
+
379
+ /**
380
+ * @author Vova Feldman (@svovaf)
381
+ * @since 1.1.6
382
+ *
383
+ * @return object
384
+ */
385
+ private function get_temporary_unavailable_error() {
386
+ return (object) array(
387
+ 'error' => (object) array(
388
+ 'type' => 'TemporaryUnavailable',
389
+ 'message' => 'API is temporary unavailable, please retry in ' . ( self::$_cache->get_record_expiration( 'ping_test' ) - WP_FS__SCRIPT_START_TIME ) . ' sec.',
390
+ 'code' => 'temporary_unavailable',
391
+ 'http' => 503
392
+ )
393
+ );
394
+ }
395
+
396
+ /**
397
+ * Ping API for connectivity test, and return result object.
398
+ *
399
+ * @author Vova Feldman (@svovaf)
400
+ * @since 1.0.9
401
+ *
402
+ * @param null|string $unique_anonymous_id
403
+ * @param array $params
404
+ *
405
+ * @return object
406
+ */
407
+ function ping( $unique_anonymous_id = null, $params = array() ) {
408
+ $this->_logger->entrance();
409
+
410
+ if ( self::is_temporary_down() ) {
411
+ return $this->get_temporary_unavailable_error();
412
+ }
413
+
414
+ $pong = is_null( $unique_anonymous_id ) ?
415
+ Freemius_Api_WordPress::Ping() :
416
+ $this->_call( 'ping.json?' . http_build_query( array_merge(
417
+ array( 'uid' => $unique_anonymous_id ),
418
+ $params
419
+ ) ) );
420
+
421
+ if ( $this->is_valid_ping( $pong ) ) {
422
+ return $pong;
423
+ }
424
+
425
+ if ( self::should_try_with_http( $pong ) ) {
426
+ // Fallback to HTTP, since HTTPS fails.
427
+ Freemius_Api_WordPress::SetHttp();
428
+
429
+ self::$_options->set_option( 'api_force_http', true, true );
430
+
431
+ $pong = is_null( $unique_anonymous_id ) ?
432
+ Freemius_Api_WordPress::Ping() :
433
+ $this->_call( 'ping.json?' . http_build_query( array_merge(
434
+ array( 'uid' => $unique_anonymous_id ),
435
+ $params
436
+ ) ) );
437
+
438
+ if ( ! $this->is_valid_ping( $pong ) ) {
439
+ self::$_options->set_option( 'api_force_http', false, true );
440
+ }
441
+ }
442
+
443
+ return $pong;
444
+ }
445
+
446
+ /**
447
+ * Check if based on the API result we should try
448
+ * to re-run the same request with HTTP instead of HTTPS.
449
+ *
450
+ * @author Vova Feldman (@svovaf)
451
+ * @since 1.1.6
452
+ *
453
+ * @param $result
454
+ *
455
+ * @return bool
456
+ */
457
+ private static function should_try_with_http( $result ) {
458
+ if ( ! Freemius_Api_WordPress::IsHttps() ) {
459
+ return false;
460
+ }
461
+
462
+ return ( ! is_object( $result ) ||
463
+ ! isset( $result->error ) ||
464
+ ! isset( $result->error->code ) ||
465
+ ! in_array( $result->error->code, array(
466
+ 'curl_missing',
467
+ 'cloudflare_ddos_protection',
468
+ 'maintenance_mode',
469
+ 'squid_cache_block',
470
+ 'too_many_requests',
471
+ ) ) );
472
+
473
+ }
474
+
475
+ /**
476
+ * Check if valid ping request result.
477
+ *
478
+ * @author Vova Feldman (@svovaf)
479
+ * @since 1.1.1
480
+ *
481
+ * @param mixed $pong
482
+ *
483
+ * @return bool
484
+ */
485
+ function is_valid_ping( $pong ) {
486
+ return Freemius_Api_WordPress::Test( $pong );
487
+ }
488
+
489
+ function get_url( $path = '' ) {
490
+ return Freemius_Api_WordPress::GetUrl( $path, $this->_api->IsSandbox() );
491
+ }
492
+
493
+ /**
494
+ * Clear API cache.
495
+ *
496
+ * @author Vova Feldman (@svovaf)
497
+ * @since 1.0.9
498
+ */
499
+ static function clear_cache() {
500
+ self::_init();
501
+
502
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
503
+ self::$_cache->clear();
504
+ }
505
+
506
+ #----------------------------------------------------------------------------------
507
+ #region Error Handling
508
+ #----------------------------------------------------------------------------------
509
+
510
+ /**
511
+ * @author Vova Feldman (@svovaf)
512
+ * @since 1.2.1.5
513
+ *
514
+ * @param mixed $result
515
+ *
516
+ * @return bool Is API result contains an error.
517
+ */
518
+ static function is_api_error( $result ) {
519
+ return ( is_object( $result ) && isset( $result->error ) ) ||
520
+ is_string( $result );
521
+ }
522
+
523
+ /**
524
+ * Checks if given API result is a non-empty and not an error object.
525
+ *
526
+ * @author Vova Feldman (@svovaf)
527
+ * @since 1.2.1.5
528
+ *
529
+ * @param mixed $result
530
+ * @param string|null $required_property Optional property we want to verify that is set.
531
+ *
532
+ * @return bool
533
+ */
534
+ static function is_api_result_object( $result, $required_property = null ) {
535
+ return (
536
+ is_object( $result ) &&
537
+ ! isset( $result->error ) &&
538
+ ( empty( $required_property ) || isset( $result->{$required_property} ) )
539
+ );
540
+ }
541
+
542
+ /**
543
+ * Checks if given API result is a non-empty entity object with non-empty ID.
544
+ *
545
+ * @author Vova Feldman (@svovaf)
546
+ * @since 1.2.1.5
547
+ *
548
+ * @param mixed $result
549
+ *
550
+ * @return bool
551
+ */
552
+ static function is_api_result_entity( $result ) {
553
+ return self::is_api_result_object( $result, 'id' ) &&
554
+ FS_Entity::is_valid_id( $result->id );
555
+ }
556
+
557
+ #endregion
558
+ }
freemius/includes/class-fs-logger.php ADDED
@@ -0,0 +1,688 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Logger {
14
+ private $_id;
15
+ private $_on = false;
16
+ private $_echo = false;
17
+ private $_file_start = 0;
18
+ /**
19
+ * @var int PHP Process ID.
20
+ */
21
+ private static $_processID;
22
+ /**
23
+ * @var string PHP Script user name.
24
+ */
25
+ private static $_ownerName;
26
+ /**
27
+ * @var bool Is storage logging turned on.
28
+ */
29
+ private static $_isStorageLoggingOn;
30
+ /**
31
+ * @var int ABSPATH length.
32
+ */
33
+ private static $_abspathLength;
34
+
35
+ private static $LOGGERS = array();
36
+ private static $LOG = array();
37
+ private static $CNT = 0;
38
+ private static $_HOOKED_FOOTER = false;
39
+
40
+ private function __construct( $id, $on = false, $echo = false ) {
41
+ $this->_id = $id;
42
+
43
+ $bt = debug_backtrace();
44
+ $caller = $bt[2];
45
+
46
+ if ( false !== strpos( $caller['file'], 'plugins' ) ) {
47
+ $this->_file_start = strpos( $caller['file'], 'plugins' ) + strlen( 'plugins/' );
48
+ } else {
49
+ $this->_file_start = strpos( $caller['file'], 'themes' ) + strlen( 'themes/' );
50
+ }
51
+
52
+ if ( $on ) {
53
+ $this->on();
54
+ }
55
+ if ( $echo ) {
56
+ $this->echo_on();
57
+ }
58
+ }
59
+
60
+ /**
61
+ * @param string $id
62
+ * @param bool $on
63
+ * @param bool $echo
64
+ *
65
+ * @return FS_Logger
66
+ */
67
+ public static function get_logger( $id, $on = false, $echo = false ) {
68
+ $id = strtolower( $id );
69
+
70
+ if ( ! isset( self::$_processID ) ) {
71
+ self::init();
72
+ }
73
+
74
+ if ( ! isset( self::$LOGGERS[ $id ] ) ) {
75
+ self::$LOGGERS[ $id ] = new FS_Logger( $id, $on, $echo );
76
+ }
77
+
78
+ return self::$LOGGERS[ $id ];
79
+ }
80
+
81
+ /**
82
+ * Initialize logging global info.
83
+ *
84
+ * @author Vova Feldman (@svovaf)
85
+ * @since 1.2.1.6
86
+ */
87
+ private static function init() {
88
+ self::$_ownerName = function_exists( 'get_current_user' ) ?
89
+ get_current_user() :
90
+ 'unknown';
91
+ self::$_isStorageLoggingOn = ( 1 == get_option( 'fs_storage_logger', 0 ) );
92
+ self::$_abspathLength = strlen( ABSPATH );
93
+ self::$_processID = mt_rand( 0, 32000 );
94
+
95
+ // Process ID may be `false` on errors.
96
+ if ( ! is_numeric( self::$_processID ) ) {
97
+ self::$_processID = 0;
98
+ }
99
+ }
100
+
101
+ private static function hook_footer() {
102
+ if ( self::$_HOOKED_FOOTER ) {
103
+ return;
104
+ }
105
+
106
+ if ( is_admin() ) {
107
+ add_action( 'admin_footer', 'FS_Logger::dump', 100 );
108
+ } else {
109
+ add_action( 'wp_footer', 'FS_Logger::dump', 100 );
110
+ }
111
+ }
112
+
113
+ function is_on() {
114
+ return $this->_on;
115
+ }
116
+
117
+ function on() {
118
+ $this->_on = true;
119
+
120
+ if ( ! function_exists( 'dbDelta' ) ) {
121
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
122
+ }
123
+
124
+ self::hook_footer();
125
+ }
126
+
127
+ function echo_on() {
128
+ $this->on();
129
+
130
+ $this->_echo = true;
131
+ }
132
+
133
+ function is_echo_on() {
134
+ return $this->_echo;
135
+ }
136
+
137
+ function get_id() {
138
+ return $this->_id;
139
+ }
140
+
141
+ function get_file() {
142
+ return $this->_file_start;
143
+ }
144
+
145
+ private function _log( &$message, $type = 'log', $wrapper ) {
146
+ if ( ! $this->is_on() ) {
147
+ return;
148
+ }
149
+
150
+ $bt = debug_backtrace();
151
+ $depth = $wrapper ? 3 : 2;
152
+ while ( $depth < count( $bt ) - 1 && 'eval' === $bt[ $depth ]['function'] ) {
153
+ $depth ++;
154
+ }
155
+
156
+ $caller = $bt[ $depth ];
157
+
158
+ /**
159
+ * Retrieve the correct call file & line number from backtrace
160
+ * when logging from a wrapper method.
161
+ *
162
+ * @author Vova Feldman
163
+ * @since 1.2.1.6
164
+ */
165
+ if ( empty( $caller['line'] ) ) {
166
+ $depth --;
167
+
168
+ while ( $depth >= 0 ) {
169
+ if ( ! empty( $bt[ $depth ]['line'] ) ) {
170
+ $caller['line'] = $bt[ $depth ]['line'];
171
+ $caller['file'] = $bt[ $depth ]['file'];
172
+ break;
173
+ }
174
+ }
175
+ }
176
+
177
+ $log = array_merge( $caller, array(
178
+ 'cnt' => self::$CNT ++,
179
+ 'logger' => $this,
180
+ 'timestamp' => microtime( true ),
181
+ 'log_type' => $type,
182
+ 'msg' => $message,
183
+ ) );
184
+
185
+ if ( self::$_isStorageLoggingOn ) {
186
+ $this->db_log( $type, $message, self::$CNT, $caller );
187
+ }
188
+
189
+ self::$LOG[] = $log;
190
+
191
+ if ( $this->is_echo_on() && ! Freemius::is_ajax() ) {
192
+ echo self::format_html( $log ) . "\n";
193
+ }
194
+ }
195
+
196
+ function log( $message, $wrapper = false ) {
197
+ $this->_log( $message, 'log', $wrapper );
198
+ }
199
+
200
+ function info( $message, $wrapper = false ) {
201
+ $this->_log( $message, 'info', $wrapper );
202
+ }
203
+
204
+ function warn( $message, $wrapper = false ) {
205
+ $this->_log( $message, 'warn', $wrapper );
206
+ }
207
+
208
+ function error( $message, $wrapper = false ) {
209
+ $this->_log( $message, 'error', $wrapper );
210
+ }
211
+
212
+ /**
213
+ * Log API error.
214
+ *
215
+ * @author Vova Feldman (@svovaf)
216
+ * @since 1.2.1.5
217
+ *
218
+ * @param mixed $api_result
219
+ * @param bool $wrapper
220
+ */
221
+ function api_error( $api_result, $wrapper = false ) {
222
+ $message = '';
223
+ if ( is_object( $api_result ) && isset( $api_result->error ) ) {
224
+ $message = $api_result->error->message;
225
+ } else if ( is_object( $api_result ) ) {
226
+ $message = var_export( $api_result, true );
227
+ } else if ( is_string( $api_result ) ) {
228
+ $message = $api_result;
229
+ } else if ( empty( $api_result ) ) {
230
+ $message = 'Empty API result.';
231
+ }
232
+
233
+ $message = 'API Error: ' . $message;
234
+
235
+ $this->_log( $message, 'error', $wrapper );
236
+ }
237
+
238
+ function entrance( $message = '', $wrapper = false ) {
239
+ $msg = 'Entrance' . ( empty( $message ) ? '' : ' > ' ) . $message;
240
+
241
+ $this->_log( $msg, 'log', $wrapper );
242
+ }
243
+
244
+ function departure( $message = '', $wrapper = false ) {
245
+ $msg = 'Departure' . ( empty( $message ) ? '' : ' > ' ) . $message;
246
+
247
+ $this->_log( $msg, 'log', $wrapper );
248
+ }
249
+
250
+ #--------------------------------------------------------------------------------
251
+ #region Log Formatting
252
+ #--------------------------------------------------------------------------------
253
+
254
+ private static function format( $log, $show_type = true ) {
255
+ return '[' . str_pad( $log['cnt'], strlen( self::$CNT ), '0', STR_PAD_LEFT ) . '] [' . $log['logger']->_id . '] ' . ( $show_type ? '[' . $log['log_type'] . ']' : '' ) . ( ! empty( $log['class'] ) ? $log['class'] . $log['type'] : '' ) . $log['function'] . ' >> ' . $log['msg'] . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ') ' : '' ) . ' [' . $log['timestamp'] . ']';
256
+ }
257
+
258
+ private static function format_html( $log ) {
259
+ return '<div style="font-size: 13px; font-family: monospace; color: #7da767; padding: 8px 3px; background: #000; border-bottom: 1px solid #555;">[' . $log['cnt'] . '] [' . $log['logger']->_id . '] [' . $log['log_type'] . '] <b><code style="color: #c4b1e0;">' . ( ! empty( $log['class'] ) ? $log['class'] . $log['type'] : '' ) . $log['function'] . '</code> >> <b style="color: #f59330;">' . esc_html( $log['msg'] ) . '</b></b>' . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ')' : '' ) . ' [' . $log['timestamp'] . ']</div>';
260
+ }
261
+
262
+ #endregion
263
+
264
+ static function dump() {
265
+ ?>
266
+ <!-- BEGIN: Freemius PHP Console Log -->
267
+ <script type="text/javascript">
268
+ <?php
269
+ foreach ( self::$LOG as $log ) {
270
+ echo 'console.' . $log['log_type'] . '(' . json_encode( self::format( $log, false ) ) . ')' . "\n";
271
+ }
272
+ ?>
273
+ </script>
274
+ <!-- END: Freemius PHP Console Log -->
275
+ <?php
276
+ }
277
+
278
+ static function get_log() {
279
+ return self::$LOG;
280
+ }
281
+
282
+ #--------------------------------------------------------------------------------
283
+ #region Database Logging
284
+ #--------------------------------------------------------------------------------
285
+
286
+ /**
287
+ * @author Vova Feldman (@svovaf)
288
+ * @since 1.2.1.6
289
+ *
290
+ * @return bool
291
+ */
292
+ public static function is_storage_logging_on() {
293
+ if ( ! isset( self::$_isStorageLoggingOn ) ) {
294
+ self::$_isStorageLoggingOn = ( 1 == get_option( 'fs_storage_logger', 0 ) );
295
+ }
296
+
297
+ return self::$_isStorageLoggingOn;
298
+ }
299
+
300
+ /**
301
+ * Turns on/off database persistent debugging to capture
302
+ * multi-session logs to debug complex flows like
303
+ * plugin auto-deactivate on premium version activation.
304
+ *
305
+ * @todo Check if Theme Check has issues with DB tables for themes.
306
+ *
307
+ * @author Vova Feldman (@svovaf)
308
+ * @since 1.2.1.6
309
+ *
310
+ * @param bool $is_on
311
+ *
312
+ * @return bool
313
+ */
314
+ public static function _set_storage_logging( $is_on = true ) {
315
+ global $wpdb;
316
+
317
+ $table = "{$wpdb->prefix}fs_logger";
318
+
319
+ if ( $is_on ) {
320
+ /**
321
+ * Create logging table.
322
+ *
323
+ * NOTE:
324
+ * dbDelta must use KEY and not INDEX for indexes.
325
+ *
326
+ * @link https://core.trac.wordpress.org/ticket/2695
327
+ */
328
+ $result = $wpdb->query( "CREATE TABLE {$table} (
329
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
330
+ `process_id` INT UNSIGNED NOT NULL,
331
+ `user_name` VARCHAR(64) NOT NULL,
332
+ `logger` VARCHAR(128) NOT NULL,
333
+ `log_order` INT UNSIGNED NOT NULL,
334
+ `type` ENUM('log','info','warn','error') NOT NULL DEFAULT 'log',
335
+ `message` TEXT NOT NULL,
336
+ `file` VARCHAR(256) NOT NULL,
337
+ `line` INT UNSIGNED NOT NULL,
338
+ `function` VARCHAR(256) NOT NULL,
339
+ `request_type` ENUM('call','ajax','cron') NOT NULL DEFAULT 'call',
340
+ `request_url` VARCHAR(1024) NOT NULL,
341
+ `created` DECIMAL(16, 6) NOT NULL,
342
+ PRIMARY KEY (`id`),
343
+ KEY `process_id` (`process_id` ASC),
344
+ KEY `process_logger` (`process_id` ASC, `logger` ASC),
345
+ KEY `function` (`function` ASC),
346
+ KEY `type` (`type` ASC))" );
347
+ } else {
348
+ /**
349
+ * Drop logging table.
350
+ */
351
+ $result = $wpdb->query( "DROP TABLE IF EXISTS $table;" );
352
+ }
353
+
354
+ if ( false !== $result ) {
355
+ update_option( 'fs_storage_logger', ( $is_on ? 1 : 0 ) );
356
+ }
357
+
358
+ return ( false !== $result );
359
+ }
360
+
361
+ /**
362
+ * @author Vova Feldman (@svovaf)
363
+ * @since 1.2.1.6
364
+ *
365
+ * @param string $type
366
+ * @param string $message
367
+ * @param int $log_order
368
+ * @param array $caller
369
+ *
370
+ * @return false|int
371
+ */
372
+ private function db_log(
373
+ &$type,
374
+ &$message,
375
+ &$log_order,
376
+ &$caller
377
+ ) {
378
+ global $wpdb;
379
+
380
+ $request_type = 'call';
381
+ if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
382
+ $request_type = 'cron';
383
+ } else if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
384
+ $request_type = 'ajax';
385
+ }
386
+
387
+ $request_url = WP_FS__IS_HTTP_REQUEST ?
388
+ $_SERVER['REQUEST_URI'] :
389
+ '';
390
+
391
+ return $wpdb->insert(
392
+ "{$wpdb->prefix}fs_logger",
393
+ array(
394
+ 'process_id' => self::$_processID,
395
+ 'user_name' => self::$_ownerName,
396
+ 'logger' => $this->_id,
397
+ 'log_order' => $log_order,
398
+ 'type' => $type,
399
+ 'request_type' => $request_type,
400
+ 'request_url' => $request_url,
401
+ 'message' => $message,
402
+ 'file' => isset( $caller['file'] ) ?
403
+ substr( $caller['file'], self::$_abspathLength ) :
404
+ '',
405
+ 'line' => $caller['line'],
406
+ 'function' => ( ! empty( $caller['class'] ) ? $caller['class'] . $caller['type'] : '' ) . $caller['function'],
407
+ 'created' => microtime( true ),
408
+ )
409
+ );
410
+ }
411
+
412
+ /**
413
+ * Persistent DB logger columns.
414
+ *
415
+ * @var array
416
+ */
417
+ private static $_log_columns = array(
418
+ 'id',
419
+ 'process_id',
420
+ 'user_name',
421
+ 'logger',
422
+ 'log_order',
423
+ 'type',
424
+ 'message',
425
+ 'file',
426
+ 'line',
427
+ 'function',
428
+ 'request_type',
429
+ 'request_url',
430
+ 'created',
431
+ );
432
+
433
+ /**
434
+ * Create DB logs query.
435
+ *
436
+ * @author Vova Feldman (@svovaf)
437
+ * @since 1.2.1.6
438
+ *
439
+ * @param bool $filters
440
+ * @param int $limit
441
+ * @param int $offset
442
+ * @param bool $order
443
+ * @param bool $escape_eol
444
+ *
445
+ * @return string
446
+ */
447
+ private static function build_db_logs_query(
448
+ $filters = false,
449
+ $limit = 200,
450
+ $offset = 0,
451
+ $order = false,
452
+ $escape_eol = false
453
+ ) {
454
+ global $wpdb;
455
+
456
+ $select = '*';
457
+
458
+ if ( $escape_eol ) {
459
+ $select = '';
460
+ for ( $i = 0, $len = count( self::$_log_columns ); $i < $len; $i ++ ) {
461
+ if ( $i > 0 ) {
462
+ $select .= ', ';
463
+ }
464
+
465
+ if ( 'message' !== self::$_log_columns[ $i ] ) {
466
+ $select .= self::$_log_columns[ $i ];
467
+ } else {
468
+ $select .= 'REPLACE(message , \'\n\', \' \') AS message';
469
+ }
470
+ }
471
+ }
472
+
473
+ $query = "SELECT {$select} FROM {$wpdb->prefix}fs_logger";
474
+ if ( is_array( $filters ) ) {
475
+ $criteria = array();
476
+
477
+ if ( ! empty( $filters['type'] ) && 'all' !== $filters['type'] ) {
478
+ $filters['type'] = strtolower( $filters['type'] );
479
+
480
+ switch ( $filters['type'] ) {
481
+ case 'warn_error':
482
+ $criteria[] = array( 'col' => 'type', 'val' => array( 'warn', 'error' ) );
483
+ break;
484
+ case 'error':
485
+ case 'warn':
486
+ $criteria[] = array( 'col' => 'type', 'val' => $filters['type'] );
487
+ break;
488
+ case 'info':
489
+ default:
490
+ $criteria[] = array( 'col' => 'type', 'val' => array( 'info', 'log' ) );
491
+ break;
492
+ }
493
+ }
494
+
495
+ if ( ! empty( $filters['request_type'] ) ) {
496
+ $filters['request_type'] = strtolower( $filters['request_type'] );
497
+
498
+ if ( in_array( $filters['request_type'], array( 'call', 'ajax', 'cron' ) ) ) {
499
+ $criteria[] = array( 'col' => 'request_type', 'val' => $filters['request_type'] );
500
+ }
501
+ }
502
+
503
+ if ( ! empty( $filters['file'] ) ) {
504
+ $criteria[] = array(
505
+ 'col' => 'file',
506
+ 'op' => 'LIKE',
507
+ 'val' => '%' . esc_sql( $filters['file'] ),
508
+ );
509
+ }
510
+
511
+ if ( ! empty( $filters['function'] ) ) {
512
+ $criteria[] = array(
513
+ 'col' => 'function',
514
+ 'op' => 'LIKE',
515
+ 'val' => '%' . esc_sql( $filters['function'] ),
516
+ );
517
+ }
518
+
519
+ if ( ! empty( $filters['process_id'] ) && is_numeric( $filters['process_id'] ) ) {
520
+ $criteria[] = array( 'col' => 'process_id', 'val' => $filters['process_id'] );
521
+ }
522
+
523
+ if ( ! empty( $filters['logger'] ) ) {
524
+ $criteria[] = array(
525
+ 'col' => 'logger',
526
+ 'op' => 'LIKE',
527
+ 'val' => '%' . esc_sql( $filters['logger'] ) . '%',
528
+ );
529
+ }
530
+
531
+ if ( ! empty( $filters['message'] ) ) {
532
+ $criteria[] = array(
533
+ 'col' => 'message',
534
+ 'op' => 'LIKE',
535
+ 'val' => '%' . esc_sql( $filters['message'] ) . '%',
536
+ );
537
+ }
538
+
539
+ if ( 0 < count( $criteria ) ) {
540
+ $query .= "\nWHERE\n";
541
+
542
+ $first = true;
543
+ foreach ( $criteria as $c ) {
544
+ if ( ! $first ) {
545
+ $query .= "AND\n";
546
+ }
547
+
548
+ if ( is_array( $c['val'] ) ) {
549
+ $operator = 'IN';
550
+
551
+ for ( $i = 0, $len = count( $c['val'] ); $i < $len; $i ++ ) {
552
+ $c['val'][ $i ] = "'" . esc_sql( $c['val'][ $i ] ) . "'";
553
+ }
554
+
555
+ $val = '(' . implode( ',', $c['val'] ) . ')';
556
+ } else {
557
+ $operator = ! empty( $c['op'] ) ? $c['op'] : '=';
558
+ $val = "'" . esc_sql( $c['val'] ) . "'";
559
+ }
560
+
561
+ $query .= "`{$c['col']}` {$operator} {$val}\n";
562
+
563
+ $first = false;
564
+ }
565
+ }
566
+ }
567
+
568
+ if ( ! is_array( $order ) ) {
569
+ $order = array(
570
+ 'col' => 'id',
571
+ 'order' => 'desc'
572
+ );
573
+ }
574
+
575
+ $query .= " ORDER BY {$order['col']} {$order['order']} LIMIT {$offset},{$limit}";
576
+
577
+ return $query;
578
+ }
579
+
580
+ /**
581
+ * Load logs from DB.
582
+ *
583
+ * @author Vova Feldman (@svovaf)
584
+ * @since 1.2.1.6
585
+ *
586
+ * @param bool $filters
587
+ * @param int $limit
588
+ * @param int $offset
589
+ * @param bool $order
590
+ *
591
+ * @return object[]|null
592
+ */
593
+ public static function load_db_logs(
594
+ $filters = false,
595
+ $limit = 200,
596
+ $offset = 0,
597
+ $order = false
598
+ ) {
599
+ global $wpdb;
600
+
601
+ $query = self::build_db_logs_query(
602
+ $filters,
603
+ $limit,
604
+ $offset,
605
+ $order
606
+ );
607
+
608
+ return $wpdb->get_results( $query );
609
+ }
610
+
611
+ /**
612
+ * Load logs from DB.
613
+ *
614
+ * @author Vova Feldman (@svovaf)
615
+ * @since 1.2.1.6
616
+ *
617
+ * @param bool $filters
618
+ * @param string $filename
619
+ * @param int $limit
620
+ * @param int $offset
621
+ * @param bool $order
622
+ *
623
+ * @return false|string File download URL or false on failure.
624
+ */
625
+ public static function download_db_logs(
626
+ $filters = false,
627
+ $filename = '',
628
+ $limit = 10000,
629
+ $offset = 0,
630
+ $order = false
631
+ ) {
632
+ global $wpdb;
633
+
634
+ $query = self::build_db_logs_query(
635
+ $filters,
636
+ $limit,
637
+ $offset,
638
+ $order,
639
+ true
640
+ );
641
+
642
+ $upload_dir = wp_upload_dir();
643
+ if ( empty( $filename ) ) {
644
+ $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
645
+ }
646
+ $filepath = rtrim( $upload_dir['path'], '/' ) . "/{$filename}";
647
+
648
+ $query .= " INTO OUTFILE '{$filepath}' FIELDS TERMINATED BY '\t' ESCAPED BY '\\\\' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n'";
649
+
650
+ $columns = '';
651
+ for ( $i = 0, $len = count( self::$_log_columns ); $i < $len; $i ++ ) {
652
+ if ( $i > 0 ) {
653
+ $columns .= ', ';
654
+ }
655
+
656
+ $columns .= "'" . self::$_log_columns[ $i ] . "'";
657
+ }
658
+
659
+ $query = "SELECT {$columns} UNION ALL " . $query;
660
+
661
+ $result = $wpdb->query( $query );
662
+
663
+ if ( false === $result ) {
664
+ return false;
665
+ }
666
+
667
+ return rtrim( $upload_dir['url'], '/' ) . '/' . $filename;
668
+ }
669
+
670
+ /**
671
+ * @author Vova Feldman (@svovaf)
672
+ * @since 1.2.1.6
673
+ *
674
+ * @param string $filename
675
+ *
676
+ * @return string
677
+ */
678
+ public static function get_logs_download_url( $filename = '' ) {
679
+ $upload_dir = wp_upload_dir();
680
+ if ( empty( $filename ) ) {
681
+ $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
682
+ }
683
+
684
+ return rtrim( $upload_dir['url'], '/' ) . $filename;
685
+ }
686
+
687
+ #endregion
688
+ }
freemius/includes/class-fs-plugin-updater.php ADDED
@@ -0,0 +1,714 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.4
7
+ *
8
+ * @link https://github.com/easydigitaldownloads/EDD-License-handler/blob/master/EDD_SL_Plugin_Updater.php
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ // Uncomment this line for testing.
16
+ // set_site_transient( 'update_plugins', null );
17
+
18
+ class FS_Plugin_Updater {
19
+
20
+ /**
21
+ * @var Freemius
22
+ * @since 1.0.4
23
+ */
24
+ private $_fs;
25
+ /**
26
+ * @var FS_Logger
27
+ * @since 1.0.4
28
+ */
29
+ private $_logger;
30
+ /**
31
+ * @var object
32
+ * @since 1.1.8.1
33
+ */
34
+ private $_update_details;
35
+
36
+ function __construct( Freemius $freemius ) {
37
+ $this->_fs = $freemius;
38
+
39
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $freemius->get_slug() . '_updater', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
40
+
41
+ $this->_filters();
42
+ }
43
+
44
+ /**
45
+ * Initiate required filters.
46
+ *
47
+ * @author Vova Feldman (@svovaf)
48
+ * @since 1.0.4
49
+ */
50
+ private function _filters() {
51
+ // Override request for plugin information
52
+ add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
53
+
54
+ // WP 3.0+
55
+ add_filter( 'pre_set_site_transient_update_plugins', array(
56
+ &$this,
57
+ 'pre_set_site_transient_update_plugins_filter'
58
+ ) );
59
+
60
+ add_filter( 'pre_set_site_transient_update_themes', array(
61
+ &$this,
62
+ 'pre_set_site_transient_update_plugins_filter'
63
+ ) );
64
+
65
+ if ( ! $this->_fs->has_active_valid_license() ) {
66
+ /**
67
+ * If user has the premium plugin's code but do NOT have an active license,
68
+ * encourage him to upgrade by showing that there's a new release, but instead
69
+ * of showing an update link, show upgrade link to the pricing page.
70
+ *
71
+ * @since 1.1.6
72
+ *
73
+ */
74
+ // WP 2.9+
75
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
76
+ &$this,
77
+ 'catch_plugin_update_row'
78
+ ), 9 );
79
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
80
+ &$this,
81
+ 'edit_and_echo_plugin_update_row'
82
+ ), 11, 2 );
83
+ }
84
+
85
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
86
+ add_filter( 'http_request_host_is_external', array(
87
+ $this,
88
+ 'http_request_host_is_external_filter'
89
+ ), 10, 3 );
90
+ }
91
+
92
+ if ( $this->_fs->is_premium() && $this->is_correct_folder_name() ) {
93
+ add_filter( 'upgrader_post_install', array( &$this, '_maybe_update_folder_name' ), 10, 3 );
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Capture plugin update row by turning output buffering.
99
+ *
100
+ * @author Vova Feldman (@svovaf)
101
+ * @since 1.1.6
102
+ */
103
+ function catch_plugin_update_row() {
104
+ ob_start();
105
+ }
106
+
107
+ /**
108
+ * Overrides default update message format with "renew your license" message.
109
+ *
110
+ * @author Vova Feldman (@svovaf)
111
+ * @since 1.1.6
112
+ *
113
+ * @param string $file
114
+ * @param array $plugin_data
115
+ */
116
+ function edit_and_echo_plugin_update_row( $file, $plugin_data ) {
117
+ $plugin_update_row = ob_get_clean();
118
+
119
+ $current = get_site_transient( 'update_plugins' );
120
+ if ( ! isset( $current->response[ $file ] ) ) {
121
+ echo $plugin_update_row;
122
+
123
+ return;
124
+ }
125
+
126
+ $r = $current->response[ $file ];
127
+
128
+ $plugin_update_row = preg_replace(
129
+ '/(\<div.+>)(.+)(\<a.+\<a.+)\<\/div\>/is',
130
+ '$1 $2 ' . sprintf(
131
+ $this->_fs->get_text( 'renew-license-now' ),
132
+ '<a href="' . $this->_fs->pricing_url() . '">', '</a>',
133
+ $r->new_version ) .
134
+ '$4',
135
+ $plugin_update_row
136
+ );
137
+
138
+ echo $plugin_update_row;
139
+ }
140
+
141
+ /**
142
+ * Since WP version 3.6, a new security feature was added that denies access to repository with a local ip.
143
+ * During development mode we want to be able updating plugin versions via our localhost repository. This
144
+ * filter white-list all domains including "api.freemius".
145
+ *
146
+ * @link http://www.emanueletessore.com/wordpress-download-failed-valid-url-provided/
147
+ *
148
+ * @author Vova Feldman (@svovaf)
149
+ * @since 1.0.4
150
+ *
151
+ * @param bool $allow
152
+ * @param string $host
153
+ * @param string $url
154
+ *
155
+ * @return bool
156
+ */
157
+ function http_request_host_is_external_filter( $allow, $host, $url ) {
158
+ return ( false !== strpos( $host, 'freemius' ) ) ? true : $allow;
159
+ }
160
+
161
+ /**
162
+ * Check for Updates at the defined API endpoint and modify the update array.
163
+ *
164
+ * This function dives into the update api just when WordPress creates its update array,
165
+ * then adds a custom API call and injects the custom plugin data retrieved from the API.
166
+ * It is reassembled from parts of the native WordPress plugin update code.
167
+ * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
168
+ *
169
+ * @author Vova Feldman (@svovaf)
170
+ * @since 1.0.4
171
+ *
172
+ * @uses FS_Api
173
+ *
174
+ * @param object $transient_data Update array build by WordPress.
175
+ *
176
+ * @return object Modified update array with custom plugin data.
177
+ */
178
+ function pre_set_site_transient_update_plugins_filter( $transient_data ) {
179
+ $this->_logger->entrance();
180
+
181
+ /**
182
+ * "plugins" or "themes".
183
+ *
184
+ * @author Leo Fajardo (@leorw)
185
+ * @since 1.2.2
186
+ */
187
+ $module_type = $this->_fs->get_module_type() . 's';
188
+
189
+ /**
190
+ * Ensure that we don't mix plugins update info with themes update info.
191
+ *
192
+ * @author Leo Fajardo (@leorw)
193
+ * @since 1.2.2
194
+ */
195
+ if ( "pre_set_site_transient_update_{$module_type}" !== current_filter() ) {
196
+ return $transient_data;
197
+ }
198
+
199
+ if ( empty( $transient_data ) ||
200
+ defined( 'WP_FS__UNINSTALL_MODE' )
201
+ ) {
202
+ return $transient_data;
203
+ }
204
+
205
+ if ( ! isset( $this->_update_details ) ) {
206
+ // Get plugin's newest update.
207
+ $new_version = $this->_fs->get_update(
208
+ false,
209
+ fs_request_get_bool( 'force-check' ),
210
+ WP_FS__TIME_24_HOURS_IN_SEC / 24
211
+ );
212
+
213
+ $this->_update_details = false;
214
+
215
+ if ( is_object( $new_version ) ) {
216
+ $this->_logger->log( 'Found newer plugin version ' . $new_version->version );
217
+
218
+ $plugin_details = new stdClass();
219
+ $plugin_details->slug = $this->_fs->get_slug();
220
+ $plugin_details->new_version = $new_version->version;
221
+ $plugin_details->url = WP_FS__ADDRESS;
222
+ $plugin_details->package = $new_version->url;
223
+ $plugin_details->{ $this->_fs->get_module_type() } = $this->_fs->get_plugin_basename();
224
+
225
+ /**
226
+ * Cache plugin details locally since set_site_transient( 'update_plugins' )
227
+ * called multiple times and the non wp.org plugins are filtered after the
228
+ * call to .org.
229
+ *
230
+ * @since 1.1.8.1
231
+ */
232
+ $this->_update_details = $plugin_details;
233
+ }
234
+ }
235
+
236
+ if ( is_object( $this->_update_details ) ) {
237
+ // Add plugin to transient data.
238
+ if ( $this->_fs->is_plugin() ) {
239
+ $transient_data->response[ $this->_fs->get_plugin_basename() ] = $this->_update_details;
240
+ } else {
241
+ $transient_data->response[ $this->_update_details->theme ] = (array) $this->_update_details;
242
+ }
243
+ }
244
+
245
+ return $transient_data;
246
+ }
247
+
248
+ /**
249
+ * Try to fetch plugin's info from .org repository.
250
+ *
251
+ * @author Vova Feldman (@svovaf)
252
+ * @since 1.0.5
253
+ *
254
+ * @param string $action
255
+ * @param object $args
256
+ *
257
+ * @return bool|mixed
258
+ */
259
+ static function _fetch_plugin_info_from_repository( $action, $args ) {
260
+ $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
261
+ if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
262
+ $url = set_url_scheme( $url, 'https' );
263
+ }
264
+
265
+ $args = array(
266
+ 'timeout' => 15,
267
+ 'body' => array(
268
+ 'action' => $action,
269
+ 'request' => serialize( $args )
270
+ )
271
+ );
272
+
273
+ $request = wp_remote_post( $url, $args );
274
+
275
+ if ( is_wp_error( $request ) ) {
276
+ return false;
277
+ }
278
+
279
+ $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
280
+
281
+ if ( ! is_object( $res ) && ! is_array( $res ) ) {
282
+ return false;
283
+ }
284
+
285
+ return $res;
286
+ }
287
+
288
+ /**
289
+ * Updates information on the "View version x.x details" page with custom data.
290
+ *
291
+ * @author Vova Feldman (@svovaf)
292
+ * @since 1.0.4
293
+ *
294
+ * @uses FS_Api
295
+ *
296
+ * @param object $data
297
+ * @param string $action
298
+ * @param mixed $args
299
+ *
300
+ * @return object
301
+ */
302
+ function plugins_api_filter( $data, $action = '', $args = null ) {
303
+ $this->_logger->entrance();
304
+
305
+ if ( ( 'plugin_information' !== $action ) ||
306
+ ! isset( $args->slug )
307
+ ) {
308
+ return $data;
309
+ }
310
+
311
+ $addon = false;
312
+ $is_addon = false;
313
+
314
+ if ( $this->_fs->get_slug() !== $args->slug ) {
315
+ $addon = $this->_fs->get_addon_by_slug( $args->slug );
316
+
317
+ if ( ! is_object( $addon ) ) {
318
+ return $data;
319
+ }
320
+
321
+ $is_addon = true;
322
+ }
323
+
324
+ $plugin_in_repo = false;
325
+ if ( ! $is_addon ) {
326
+ // Try to fetch info from .org repository.
327
+ $data = self::_fetch_plugin_info_from_repository( $action, $args );
328
+
329
+ $plugin_in_repo = ( false !== $data );
330
+ }
331
+
332
+ if ( ! $plugin_in_repo ) {
333
+ $data = $args;
334
+
335
+ // Fetch as much as possible info from local files.
336
+ $plugin_local_data = $this->_fs->get_plugin_data();
337
+ $data->name = $plugin_local_data['Name'];
338
+ $data->author = $plugin_local_data['Author'];
339
+ $data->sections = array(
340
+ 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.',
341
+ );
342
+
343
+ // @todo Store extra plugin info on Freemius or parse readme.txt markup.
344
+ /*$info = $this->_fs->get_api_site_scope()->call('/information.json');
345
+
346
+ if ( !isset($info->error) ) {
347
+ $data = $info;
348
+ }*/
349
+ }
350
+
351
+ // Get plugin's newest update.
352
+ $new_version = $this->get_latest_download_details( $is_addon ? $addon->id : false );
353
+
354
+ if ( ! is_object( $new_version ) || empty( $new_version->version ) ) {
355
+ $data->version = $this->_fs->get_plugin_version();
356
+ } else {
357
+ if ( $is_addon ) {
358
+ $data->name = $addon->title . ' ' . $this->_fs->get_text( 'addon' );
359
+ $data->slug = $addon->slug;
360
+ $data->url = WP_FS__ADDRESS;
361
+ $data->package = $new_version->url;
362
+ }
363
+
364
+ if ( ! $plugin_in_repo ) {
365
+ $data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
366
+ $data->requires = $new_version->requires_platform_version;
367
+ $data->tested = $new_version->tested_up_to_version;
368
+ }
369
+
370
+ $data->version = $new_version->version;
371
+ $data->download_link = $new_version->url;
372
+ }
373
+
374
+ return $data;
375
+ }
376
+
377
+ /**
378
+ * @author Vova Feldman (@svovaf)
379
+ * @since 1.2.1.7
380
+ *
381
+ * @param number|bool $addon_id
382
+ *
383
+ * @return object
384
+ */
385
+ private function get_latest_download_details( $addon_id = false ) {
386
+ return $this->_fs->_fetch_latest_version( $addon_id );
387
+ }
388
+
389
+ /**
390
+ * Checks if a given basename has a matching folder name
391
+ * with the current context plugin.
392
+ *
393
+ * @author Vova Feldman (@svovaf)
394
+ * @since 1.2.1.6
395
+ *
396
+ * @param string $basename Current plugin's basename.
397
+ *
398
+ * @return bool
399
+ */
400
+ private function is_correct_folder_name( $basename = '' ) {
401
+ if ( empty( $basename ) ) {
402
+ $basename = $this->_fs->get_plugin_basename();
403
+ }
404
+
405
+ return ( $this->_fs->get_target_folder_name() != trim( dirname( $basename ), '/\\' ) );
406
+ }
407
+
408
+ /**
409
+ * This is a special after upgrade handler for migrating modules
410
+ * that didn't use the '-premium' suffix folder structure before
411
+ * the migration.
412
+ *
413
+ * @author Vova Feldman (@svovaf)
414
+ * @since 1.2.1.6
415
+ *
416
+ * @param bool $response Install response.
417
+ * @param array $hook_extra Extra arguments passed to hooked filters.
418
+ * @param array $result Installation result data.
419
+ *
420
+ * @return bool
421
+ */
422
+ function _maybe_update_folder_name( $response, $hook_extra, $result ) {
423
+ $basename = $this->_fs->get_plugin_basename();
424
+
425
+ if ( true !== $response ||
426
+ empty( $hook_extra ) ||
427
+ empty( $hook_extra['plugin'] ) ||
428
+ $basename !== $hook_extra['plugin']
429
+ ) {
430
+ return $response;
431
+ }
432
+
433
+ $active_plugins_basenames = get_option( 'active_plugins' );
434
+
435
+ for ( $i = 0, $len = count( $active_plugins_basenames ); $i < $len; $i ++ ) {
436
+ if ( $basename === $active_plugins_basenames[ $i ] ) {
437
+ // Get filename including extension.
438
+ $filename = basename( $basename );
439
+
440
+ $new_basename = plugin_basename(
441
+ trailingslashit( $this->_fs->get_slug() . ( $this->_fs->is_premium() ? '-premium' : '' ) ) .
442
+ $filename
443
+ );
444
+
445
+ // Verify that the expected correct path exists.
446
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $new_basename ) ) ) {
447
+ // Override active plugin name.
448
+ $active_plugins_basenames[ $i ] = $new_basename;
449
+ update_option( 'active_plugins', $active_plugins_basenames );
450
+ }
451
+
452
+ break;
453
+ }
454
+ }
455
+
456
+ return $response;
457
+ }
458
+
459
+ #----------------------------------------------------------------------------------
460
+ #region Auto Activation
461
+ #----------------------------------------------------------------------------------
462
+
463
+ /**
464
+ * Installs and active a plugin when explicitly requested that from a 3rd party service.
465
+ *
466
+ * This logic was inspired by the TGMPA GPL licensed library by Thomas Griffin.
467
+ *
468
+ * @link http://tgmpluginactivation.com/
469
+ *
470
+ * @author Vova Feldman
471
+ * @since 1.2.1.7
472
+ *
473
+ * @link https://make.wordpress.org/plugins/2017/03/16/clarification-of-guideline-8-executable-code-and-installs/
474
+ *
475
+ * @uses WP_Filesystem
476
+ * @uses WP_Error
477
+ * @uses WP_Upgrader
478
+ * @uses Plugin_Upgrader
479
+ * @uses Plugin_Installer_Skin
480
+ * @uses Plugin_Upgrader_Skin
481
+ *
482
+ * @param number|bool $plugin_id
483
+ *
484
+ * @return array
485
+ */
486
+ function install_and_activate_plugin( $plugin_id = false ) {
487
+ if ( ! empty( $plugin_id ) && ! FS_Plugin::is_valid_id( $plugin_id ) ) {
488
+ // Invalid plugin ID.
489
+ return array(
490
+ 'message' => $this->_fs->get_text( 'auto-install-error-invalid-id' ),
491
+ 'code' => 'invalid_module_id',
492
+ );
493
+ }
494
+
495
+ $is_addon = false;
496
+ if ( FS_Plugin::is_valid_id( $plugin_id ) &&
497
+ $plugin_id != $this->_fs->get_id()
498
+ ) {
499
+ $addon = $this->_fs->get_addon( $plugin_id );
500
+
501
+ if ( ! is_object( $addon ) ) {
502
+ // Invalid add-on ID.
503
+ return array(
504
+ 'message' => $this->_fs->get_text( 'auto-install-error-invalid-id' ),
505
+ 'code' => 'invalid_module_id',
506
+ );
507
+ }
508
+
509
+ $slug = $addon->slug;
510
+ $title = $addon->title . ' ' . $this->_fs->get_text( 'addon' );
511
+
512
+ $is_addon = true;
513
+ } else {
514
+ $slug = $this->_fs->get_slug();
515
+ $title = $this->_fs->get_plugin_title() .
516
+ ( $this->_fs->is_addon() ? ' ' . $this->_fs->get_text( 'addon' ) : '' );
517
+ }
518
+
519
+ if ( $this->is_premium_plugin_active( $plugin_id ) ) {
520
+ // Premium version already activated.
521
+ return array(
522
+ 'message' => $this->_fs->get_text(
523
+ $is_addon ?
524
+ 'auto-install-error-premium-addon-activated' :
525
+ 'auto-install-error-premium-activated'
526
+ ),
527
+ 'code' => 'premium_installed',
528
+ );
529
+ }
530
+
531
+ $latest_version = $this->get_latest_download_details( $plugin_id );
532
+ $target_folder = "{$slug}-premium";
533
+
534
+ // Prep variables for Plugin_Installer_Skin class.
535
+ $extra = array();
536
+ $extra['slug'] = $target_folder;
537
+ $source = $latest_version->url;
538
+ $api = null;
539
+
540
+ $install_url = add_query_arg(
541
+ array(
542
+ 'action' => 'install-plugin',
543
+ 'plugin' => urlencode( $slug ),
544
+ ),
545
+ 'update.php'
546
+ );
547
+
548
+ if ( ! class_exists( 'Plugin_Upgrader', false ) ) {
549
+ // Include required resources for the installation.
550
+ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
551
+ }
552
+
553
+ $skin_args = array(
554
+ 'type' => 'web',
555
+ 'title' => sprintf( $this->_fs->get_text( 'installing-plugin-x' ), $title ),
556
+ 'url' => esc_url_raw( $install_url ),
557
+ 'nonce' => 'install-plugin_' . $slug,
558
+ 'plugin' => '',
559
+ 'api' => $api,
560
+ 'extra' => $extra,
561
+ );
562
+
563
+ // $skin = new Automatic_Upgrader_Skin( $skin_args );
564
+ // $skin = new Plugin_Installer_Skin( $skin_args );
565
+ $skin = new WP_Ajax_Upgrader_Skin( $skin_args );
566
+
567
+ // Create a new instance of Plugin_Upgrader.
568
+ $upgrader = new Plugin_Upgrader( $skin );
569
+
570
+ // Perform the action and install the plugin from the $source urldecode().
571
+ add_filter( 'upgrader_source_selection', array( &$this, '_maybe_adjust_source_dir' ), 1, 3 );
572
+
573
+ $install_result = $upgrader->install( $source );
574
+
575
+ remove_filter( 'upgrader_source_selection', array( &$this, '_maybe_adjust_source_dir' ), 1 );
576
+
577
+ if ( is_wp_error( $install_result ) ) {
578
+ return array(
579
+ 'message' => $install_result->get_error_message(),
580
+ 'code' => $install_result->get_error_code(),
581
+ );
582
+ } elseif ( is_wp_error( $skin->result ) ) {
583
+ return array(
584
+ 'message' => $skin->result->get_error_message(),
585
+ 'code' => $skin->result->get_error_code(),
586
+ );
587
+ } elseif ( $skin->get_errors()->get_error_code() ) {
588
+ return array(
589
+ 'message' => $skin->get_error_messages(),
590
+ 'code' => 'unknown',
591
+ );
592
+ } elseif ( is_null( $install_result ) ) {
593
+ global $wp_filesystem;
594
+
595
+ $error_code = 'unable_to_connect_to_filesystem';
596
+ $error_message = $this->_fs->get_text( 'Unable to connect to the filesystem. Please confirm your credentials.' );
597
+
598
+ // Pass through the error from WP_Filesystem if one was raised.
599
+ if ( $wp_filesystem instanceof WP_Filesystem_Base &&
600
+ is_wp_error( $wp_filesystem->errors ) &&
601
+ $wp_filesystem->errors->get_error_code()
602
+ ) {
603
+ $error_message = $wp_filesystem->errors->get_error_message();
604
+ }
605
+
606
+ return array(
607
+ 'message' => $error_message,
608
+ 'code' => $error_code,
609
+ );
610
+ }
611
+
612
+ // Grab the full path to the main plugin's file.
613
+ $plugin_activate = $upgrader->plugin_info();
614
+
615
+ // Try to activate the plugin.
616
+ $activation_result = $this->try_activate_plugin( $plugin_activate );
617
+
618
+ if ( is_wp_error( $activation_result ) ) {
619
+ return array(
620
+ 'message' => $activation_result->get_error_message(),
621
+ 'code' => $activation_result->get_error_code(),
622
+ );
623
+ }
624
+
625
+ return $skin->get_upgrade_messages();
626
+ }
627
+
628
+ /**
629
+ * Tries to activate a plugin. If fails, returns the error.
630
+ *
631
+ * @author Vova Feldman
632
+ * @since 1.2.1.7
633
+ *
634
+ * @param string $file_path Path within wp-plugins/ to main plugin file.
635
+ * This determines the styling of the output messages.
636
+ *
637
+ * @return bool|WP_Error
638
+ */
639
+ protected function try_activate_plugin( $file_path ) {
640
+ $activate = activate_plugin( $file_path );
641
+
642
+ return is_wp_error( $activate ) ?
643
+ $activate :
644
+ true;
645
+ }
646
+
647
+ /**
648
+ * Check if a premium module version is already active.
649
+ *
650
+ * @author Vova Feldman
651
+ * @since 1.2.1.7
652
+ *
653
+ * @param number|bool $plugin_id
654
+ *
655
+ * @return bool
656
+ */
657
+ private function is_premium_plugin_active( $plugin_id = false ) {
658
+ if ( $plugin_id != $this->_fs->get_id() ) {
659
+ return $this->_fs->is_addon_activated( $plugin_id, true );
660
+ }
661
+
662
+ return is_plugin_active( $this->_fs->premium_plugin_basename() );
663
+ }
664
+
665
+ /**
666
+ * Adjust the plugin directory name if necessary.
667
+ * Assumes plugin has a folder (not a single file plugin).
668
+ *
669
+ * The final destination directory of a plugin is based on the subdirectory name found in the
670
+ * (un)zipped source. In some cases this subdirectory name is not the same as the expected
671
+ * slug and the plugin will not be recognized as installed. This is fixed by adjusting
672
+ * the temporary unzipped source subdirectory name to the expected plugin slug.
673
+ *
674
+ * @author Vova Feldman
675
+ * @since 1.2.1.7
676
+ *
677
+ * @param string $source Path to upgrade/zip-file-name.tmp/subdirectory/.
678
+ * @param string $remote_source Path to upgrade/zip-file-name.tmp.
679
+ * @param \WP_Upgrader $upgrader Instance of the upgrader which installs the plugin.
680
+ *
681
+ * @return string|WP_Error
682
+ */
683
+ function _maybe_adjust_source_dir( $source, $remote_source, $upgrader ) {
684
+ if ( ! is_object( $GLOBALS['wp_filesystem'] ) ) {
685
+ return $source;
686
+ }
687
+
688
+ // Figure out what the slug is supposed to be.
689
+ $desired_slug = $upgrader->skin->options['extra']['slug'];
690
+
691
+ $subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) );
692
+
693
+ if ( ! empty( $subdir_name ) && $subdir_name !== $desired_slug ) {
694
+ $from_path = untrailingslashit( $source );
695
+ $to_path = trailingslashit( $remote_source ) . $desired_slug;
696
+
697
+ if ( true === $GLOBALS['wp_filesystem']->move( $from_path, $to_path ) ) {
698
+ return trailingslashit( $to_path );
699
+ } else {
700
+ return new WP_Error(
701
+ 'rename_failed',
702
+ $this->_fs->get_text( 'module-package-rename-failure' ),
703
+ array(
704
+ 'found' => $subdir_name,
705
+ 'expected' => $desired_slug
706
+ ) );
707
+ }
708
+ }
709
+
710
+ return $source;
711
+ }
712
+
713
+ #endregion
714
+ }
freemius/includes/class-fs-security.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ define( 'WP_FS__SECURITY_PARAMS_PREFIX', 's_' );
14
+
15
+ /**
16
+ * Class FS_Security
17
+ */
18
+ class FS_Security {
19
+ /**
20
+ * @var FS_Security
21
+ * @since 1.0.3
22
+ */
23
+ private static $_instance;
24
+ /**
25
+ * @var FS_Logger
26
+ * @since 1.0.3
27
+ */
28
+ private static $_logger;
29
+
30
+ /**
31
+ * @return \FS_Security
32
+ */
33
+ public static function instance() {
34
+ if ( ! isset( self::$_instance ) ) {
35
+ self::$_instance = new FS_Security();
36
+ self::$_logger = FS_Logger::get_logger(
37
+ WP_FS__SLUG,
38
+ WP_FS__DEBUG_SDK,
39
+ WP_FS__ECHO_DEBUG_SDK
40
+ );
41
+ }
42
+
43
+ return self::$_instance;
44
+ }
45
+
46
+ private function __construct() {
47
+ }
48
+
49
+ /**
50
+ * @param \FS_Scope_Entity $entity
51
+ * @param int $timestamp
52
+ * @param string $action
53
+ *
54
+ * @return string
55
+ */
56
+ function get_secure_token( FS_Scope_Entity $entity, $timestamp, $action = '' ) {
57
+ return md5(
58
+ $timestamp .
59
+ $entity->id .
60
+ $entity->secret_key .
61
+ $entity->public_key .
62
+ $action
63
+ );
64
+ }
65
+
66
+ /**
67
+ * @param \FS_Scope_Entity $entity
68
+ * @param int|bool $timestamp
69
+ * @param string $action
70
+ *
71
+ * @return array
72
+ */
73
+ function get_context_params( FS_Scope_Entity $entity, $timestamp = false, $action = '' ) {
74
+ if ( false === $timestamp ) {
75
+ $timestamp = time();
76
+ }
77
+
78
+ return array(
79
+ 's_ctx_type' => $entity->get_type(),
80
+ 's_ctx_id' => $entity->id,
81
+ 's_ctx_ts' => $timestamp,
82
+ 's_ctx_secure' => $this->get_secure_token( $entity, $timestamp, $action ),
83
+ );
84
+ }
85
+ }
freemius/includes/customizer/class-fs-customizer-support-section.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.2.2.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class Zerif_Customizer_Theme_Info_Main
15
+ *
16
+ * @since 1.0.0
17
+ * @access public
18
+ */
19
+ class FS_Customizer_Support_Section extends WP_Customize_Section {
20
+
21
+ function __construct( $manager, $id, $args = array() ) {
22
+ $manager->register_section_type( 'FS_Customizer_Support_Section' );
23
+
24
+ parent::__construct( $manager, $id, $args );
25
+ }
26
+
27
+ /**
28
+ * The type of customize section being rendered.
29
+ *
30
+ * @since 1.0.0
31
+ * @access public
32
+ * @var string
33
+ */
34
+ public $type = 'freemius-support-section';
35
+
36
+ /**
37
+ * @var Freemius
38
+ */
39
+ public $fs = null;
40
+
41
+ /**
42
+ * Add custom parameters to pass to the JS via JSON.
43
+ *
44
+ * @since 1.0.0
45
+ */
46
+ public function json() {
47
+ $json = parent::json();
48
+
49
+ $is_contact_visible = $this->fs->is_page_visible( 'contact' );
50
+ $is_support_visible = $this->fs->is_page_visible( 'support' );
51
+
52
+ $json['theme_title'] = $this->fs->get_plugin_name();
53
+
54
+ if ( $is_contact_visible && $is_support_visible ) {
55
+ $json['theme_title'] .= ' ' . $this->fs->get_text( 'support' );
56
+ }
57
+
58
+ if ( $is_contact_visible ) {
59
+ $json['contact'] = array(
60
+ 'label' => $this->fs->get_text( 'contact-us' ),
61
+ 'url' => $this->fs->contact_url(),
62
+ );
63
+ }
64
+
65
+ if ( $is_support_visible ) {
66
+ $json['support'] = array(
67
+ 'label' => $this->fs->get_text( 'support-forum' ),
68
+ 'url' => $this->fs->get_support_forum_url()
69
+ );
70
+ }
71
+
72
+ return $json;
73
+ }
74
+
75
+ /**
76
+ * Outputs the Underscore.js template.
77
+ *
78
+ * @since 1.0.0
79
+ */
80
+ protected function render_template() {
81
+ ?>
82
+ <li id="fs_customizer_support"
83
+ class="accordion-section control-section control-section-{{ data.type }} cannot-expand">
84
+ <h3 class="accordion-section-title">
85
+ <span>{{ data.theme_title }}</span>
86
+ <# if ( data.contact && data.support ) { #>
87
+ <div class="button-group">
88
+ <# } #>
89
+ <# if ( data.contact ) { #>
90
+ <a class="button" href="{{ data.contact.url }}" target="_blank">{{ data.contact.label }} </a>
91
+ <# } #>
92
+ <# if ( data.support ) { #>
93
+ <a class="button" href="{{ data.support.url }}" target="_blank">{{ data.support.label }} </a>
94
+ <# } #>
95
+ <# if ( data.contact && data.support ) { #>
96
+ </div>
97
+ <# } #>
98
+ </h3>
99
+ </li>
100
+ <?php
101
+ }
102
+ }
freemius/includes/customizer/class-fs-customizer-upsell-control.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.2.2.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Customizer_Upsell_Control
15
+ */
16
+ class FS_Customizer_Upsell_Control extends WP_Customize_Control {
17
+
18
+ /**
19
+ * Control type
20
+ *
21
+ * @var string control type
22
+ */
23
+ public $type = 'freemius-upsell-control';
24
+
25
+ /**
26
+ * @var Freemius
27
+ */
28
+ public $fs = null;
29
+
30
+ /**
31
+ * @param WP_Customize_Manager $manager the customize manager class.
32
+ * @param string $id id.
33
+ * @param array $args customizer manager parameters.
34
+ */
35
+ public function __construct( WP_Customize_Manager $manager, $id, array $args ) {
36
+ $manager->register_control_type( 'FS_Customizer_Upsell_Control' );
37
+
38
+ parent::__construct( $manager, $id, $args );
39
+ }
40
+
41
+ /**
42
+ * Enqueue resources for the control.
43
+ */
44
+ public function enqueue() {
45
+ fs_enqueue_local_style( 'fs_customizer', 'customizer.css' );
46
+ }
47
+
48
+ /**
49
+ * Json conversion
50
+ */
51
+ public function to_json() {
52
+ $pricing_cta = esc_html( $this->fs->get_text( $this->fs->get_pricing_cta_label() ) ) . '&nbsp;&nbsp;' . ( is_rtl() ? '&#x2190;' : '&#x27a4;' );
53
+
54
+ parent::to_json();
55
+
56
+ $this->json['button_text'] = $pricing_cta;
57
+ $this->json['button_url'] = $this->fs->is_in_trial_promotion() ?
58
+ $this->fs->get_trial_url() :
59
+ $this->fs->get_upgrade_url();
60
+
61
+ // Load features.
62
+ $pricing = $this->fs->get_api_plugin_scope()->get( 'pricing.json' );
63
+
64
+ if ( $this->fs->is_api_result_object( $pricing, 'plans' ) ) {
65
+ // Add support features.
66
+ if ( is_array( $pricing->plans ) && 0 < count( $pricing->plans ) ) {
67
+ $support_features = array(
68
+ 'kb' => 'Help Center',
69
+ 'forum' => 'Support Forum',
70
+ 'email' => 'Priority Email Support',
71
+ 'phone' => 'Phone Support',
72
+ 'skype' => 'Skype Support',
73
+ 'is_success_manager' => 'Personal Success Manager',
74
+ );
75
+
76
+ for ( $i = 0, $len = count( $pricing->plans ); $i < $len; $i ++ ) {
77
+ if ( 'free' == $pricing->plans[$i]->name ) {
78
+ continue;
79
+ }
80
+
81
+ if ( ! isset( $pricing->plans[ $i ]->features ) ||
82
+ ! is_array( $pricing->plans[ $i ]->features ) ) {
83
+ $pricing->plans[$i]->features = array();
84
+ }
85
+
86
+ foreach ( $support_features as $key => $label ) {
87
+ $key = ( 'is_success_manager' !== $key ) ?
88
+ "support_{$key}" :
89
+ $key;
90
+
91
+ if ( ! empty( $pricing->plans[ $i ]->{$key} ) ) {
92
+
93
+ $support_feature = new stdClass();
94
+ $support_feature->title = $label;
95
+
96
+ $pricing->plans[ $i ]->features[] = $support_feature;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ $this->json['plans'] = $pricing->plans;
104
+
105
+ $this->json['strings'] = array(
106
+ 'plan' => $this->fs->get_text( 'plan' ),
107
+ );
108
+ }
109
+
110
+ /**
111
+ * Control content
112
+ */
113
+ public function content_template() {
114
+ ?>
115
+ <div id="fs_customizer_upsell">
116
+ <# if ( data.plans ) { #>
117
+ <ul class="fs-customizer-plans">
118
+ <# for (i in data.plans) { #>
119
+ <# if ( 'free' != data.plans[i].name && (null != data.plans[i].features && 0 < data.plans[i].features.length) ) { #>
120
+ <li class="fs-customizer-plan">
121
+ <div class="fs-accordion-section-open">
122
+ <h2 class="fs-accordion-section-title menu-item">
123
+ <span>{{ data.plans[i].title }}</span>
124
+ <button type="button" class="button-link item-edit" aria-expanded="true">
125
+ <span class="screen-reader-text">Toggle section: {{ data.plans[i].title }} {{ data.strings.plan }}</span>
126
+ <span class="toggle-indicator" aria-hidden="true"></span>
127
+ </button>
128
+ </h2>
129
+ <div class="fs-accordion-section-content">
130
+ <# if ( data.plans[i].description ) { #>
131
+ <h3>{{ data.plans[i].description }}</h3>
132
+ <# } #>
133
+ <# if ( data.plans[i].features ) { #>
134
+ <ul>
135
+ <# for ( j in data.plans[i].features ) { #>
136
+ <li><div class="fs-feature">
137
+ <span class="dashicons dashicons-yes"></span><span><# if ( data.plans[i].features[j].value ) { #>{{ data.plans[i].features[j].value }} <# } #>{{ data.plans[i].features[j].title }}</span>
138
+ <# if ( data.plans[i].features[j].description ) { #>
139
+ <span class="dashicons dashicons-editor-help"><span class="fs-feature-desc">{{ data.plans[i].features[j].description }}</span></span>
140
+ <# } #>
141
+ </div></li>
142
+ <# } #>
143
+ </ul>
144
+ <# } #>
145
+ <# if ( 'free' != data.plans[i].name ) { #>
146
+ <a href="{{ data.button_url }}" class="button button-primary" target="_blank">{{{ data.button_text }}}</a>
147
+ <# } #>
148
+ </div>
149
+ </div>
150
+ </li>
151
+ <# } #>
152
+ <# } #>
153
+ </ul>
154
+ <# } #>
155
+ </div>
156
+ <?php }
157
+ }
freemius/includes/debug/class-fs-debug-bar-panel.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Extends Debug Bar plugin by adding a panel to show all Freemius API requests.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7.3
18
+ *
19
+ * Class Freemius_Debug_Bar_Panel
20
+ */
21
+ class Freemius_Debug_Bar_Panel extends Debug_Bar_Panel {
22
+ function init() {
23
+ $this->title( 'Freemius' );
24
+ }
25
+
26
+ static function requests_count() {
27
+ if ( class_exists( 'Freemius_Api_WordPress' ) ) {
28
+ $logger = Freemius_Api_WordPress::GetLogger();
29
+ } else {
30
+ $logger = array();
31
+ }
32
+
33
+ return number_format( count( $logger ) );
34
+ }
35
+
36
+ static function total_time() {
37
+ if ( class_exists( 'Freemius_Api_WordPress' ) ) {
38
+ $logger = Freemius_Api_WordPress::GetLogger();
39
+ } else {
40
+ $logger = array();
41
+ }
42
+
43
+ $total_time = .0;
44
+ foreach ( $logger as $l ) {
45
+ $total_time += $l['total'];
46
+ }
47
+
48
+ return number_format( 100 * $total_time, 2 ) . ' ' . fs_text( 'ms' );
49
+ }
50
+
51
+ function render() {
52
+ ?>
53
+ <div id='debug-bar-php'>
54
+ <?php fs_require_template( '/debug/api-calls.php' ) ?>
55
+ <br>
56
+ <?php fs_require_template( '/debug/scheduled-crons.php' ) ?>
57
+ <br>
58
+ <?php fs_require_template( '/debug/plugins-themes-sync.php' ) ?>
59
+ <br>
60
+ <?php fs_require_template( '/debug/logger.php' ) ?>
61
+ </div>
62
+ <?php
63
+ }
64
+ }
freemius/includes/debug/debug-bar-start.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! WP_FS__DEBUG_SDK ) {
14
+ return;
15
+ }
16
+
17
+ /**
18
+ * Initialize Freemius custom debug panels.
19
+ *
20
+ * @param array $panels Debug bar panels objects
21
+ *
22
+ * @return array Debug bar panels with your custom panels
23
+ */
24
+ function fs_custom_panels_init( $panels ) {
25
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
26
+ if ( FS_API__LOGGER_ON ) {
27
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
28
+ $panels[] = new Freemius_Debug_Bar_Panel();
29
+ }
30
+ }
31
+
32
+ return $panels;
33
+ }
34
+
35
+ function fs_custom_status_init( $statuses ) {
36
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
37
+ if ( FS_API__LOGGER_ON ) {
38
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
39
+ $statuses[] = array(
40
+ 'fs_api_requests',
41
+ fs_text( 'Freemius API' ),
42
+ Freemius_Debug_Bar_Panel::requests_count() . ' ' . fs_text( 'Requests' ) .
43
+ ' (' . Freemius_Debug_Bar_Panel::total_time() . ')'
44
+ );
45
+ }
46
+ }
47
+
48
+ return $statuses;
49
+ }
50
+
51
+ add_filter( 'debug_bar_panels', 'fs_custom_panels_init' );
52
+ add_filter( 'debug_bar_statuses', 'fs_custom_status_init' );
freemius/includes/debug/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/includes/entities/class-fs-billing.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius for EDD Add-On
4
+ * @copyright Copyright (c) 2016, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Billing extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var int
19
+ */
20
+ public $entity_id;
21
+ /**
22
+ * @var string (Enum) Linked entity type. One of: developer, plugin, user, install
23
+ */
24
+ public $entity_type;
25
+ /**
26
+ * @var string
27
+ */
28
+ public $business_name;
29
+ /**
30
+ * @var string
31
+ */
32
+ public $first;
33
+ /**
34
+ * @var string
35
+ */
36
+ public $last;
37
+ /**
38
+ * @var string
39
+ */
40
+ public $email;
41
+ /**
42
+ * @var string
43
+ */
44
+ public $phone;
45
+ /**
46
+ * @var string
47
+ */
48
+ public $website;
49
+ /**
50
+ * @var string Tax or VAT ID.
51
+ */
52
+ public $tax_id;
53
+ /**
54
+ * @var string
55
+ */
56
+ public $address_street;
57
+ /**
58
+ * @var string
59
+ */
60
+ public $address_apt;
61
+ /**
62
+ * @var string
63
+ */
64
+ public $address_city;
65
+ /**
66
+ * @var string
67
+ */
68
+ public $address_country;
69
+ /**
70
+ * @var string Two chars country code.
71
+ */
72
+ public $address_country_code;
73
+ /**
74
+ * @var string
75
+ */
76
+ public $address_state;
77
+ /**
78
+ * @var number Numeric ZIP code (cab be with leading zeros).
79
+ */
80
+ public $address_zip;
81
+
82
+ #endregion Properties
83
+
84
+
85
+ /**
86
+ * @param object|bool $event
87
+ */
88
+ function __construct( $event = false ) {
89
+ parent::__construct( $event );
90
+ }
91
+
92
+ static function get_type() {
93
+ return 'billing';
94
+ }
95
+ }
freemius/includes/entities/class-fs-entity.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Get object's public variables.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.0.0
18
+ *
19
+ * @param object $object
20
+ *
21
+ * @return array
22
+ */
23
+ function fs_get_object_public_vars( $object ) {
24
+ return get_object_vars( $object );
25
+ }
26
+
27
+ class FS_Entity {
28
+ /**
29
+ * @var number
30
+ */
31
+ public $id;
32
+ /**
33
+ * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format.
34
+ */
35
+ public $updated;
36
+ /**
37
+ * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format.
38
+ */
39
+ public $created;
40
+
41
+ /**
42
+ * @param bool|object $entity
43
+ */
44
+ function __construct( $entity = false ) {
45
+ if ( ! ( $entity instanceof stdClass ) ) {
46
+ return;
47
+ }
48
+
49
+ $props = fs_get_object_public_vars( $this );
50
+
51
+ foreach ( $props as $key => $def_value ) {
52
+ $this->{$key} = isset( $entity->{$key} ) ?
53
+ $entity->{$key} :
54
+ $def_value;
55
+ }
56
+ }
57
+
58
+ static function get_type() {
59
+ return 'type';
60
+ }
61
+
62
+ /**
63
+ * @author Vova Feldman (@svovaf)
64
+ * @since 1.0.6
65
+ *
66
+ * @param FS_Entity $entity1
67
+ * @param FS_Entity $entity2
68
+ *
69
+ * @return bool
70
+ */
71
+ static function equals( $entity1, $entity2 ) {
72
+ if ( is_null( $entity1 ) && is_null( $entity2 ) ) {
73
+ return true;
74
+ } else if ( is_object( $entity1 ) && is_object( $entity2 ) ) {
75
+ return ( $entity1->id == $entity2->id );
76
+ } else if ( is_object( $entity1 ) ) {
77
+ return is_null( $entity1->id );
78
+ } else {
79
+ return is_null( $entity2->id );
80
+ }
81
+ }
82
+
83
+ private $_is_updated = false;
84
+
85
+ /**
86
+ * Update object property.
87
+ *
88
+ * @author Vova Feldman (@svovaf)
89
+ * @since 1.0.9
90
+ *
91
+ * @param string|array[string]mixed $key
92
+ * @param string|bool $val
93
+ *
94
+ * @return bool
95
+ */
96
+ function update( $key, $val = false ) {
97
+ if ( ! is_array( $key ) ) {
98
+ $key = array( $key => $val );
99
+ }
100
+
101
+ $is_updated = false;
102
+
103
+ foreach ( $key as $k => $v ) {
104
+ if ( $this->{$k} === $v ) {
105
+ continue;
106
+ }
107
+
108
+ if ( ( is_string( $this->{$k} ) && is_numeric( $v ) ||
109
+ ( is_numeric( $this->{$k} ) && is_string( $v ) ) ) &&
110
+ $this->{$k} == $v
111
+ ) {
112
+ continue;
113
+ }
114
+
115
+ // Update value.
116
+ $this->{$k} = $v;
117
+
118
+ $is_updated = true;
119
+ }
120
+
121
+ $this->_is_updated = $is_updated;
122
+
123
+ return $is_updated;
124
+ }
125
+
126
+ /**
127
+ * Checks if entity was updated.
128
+ *
129
+ * @author Vova Feldman (@svovaf)
130
+ * @since 1.0.9
131
+ *
132
+ * @return bool
133
+ */
134
+ function is_updated() {
135
+ return $this->_is_updated;
136
+ }
137
+
138
+ /**
139
+ * @param $id
140
+ *
141
+ * @author Vova Feldman (@svovaf)
142
+ * @since 1.1.2
143
+ *
144
+ * @return bool
145
+ */
146
+ static function is_valid_id($id){
147
+ return is_numeric($id);
148
+ }
149
+ }
freemius/includes/entities/class-fs-payment.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2016, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Payment extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plugin_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $user_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $install_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $subscription_id;
33
+ /**
34
+ * @var number
35
+ */
36
+ public $plan_id;
37
+ /**
38
+ * @var number
39
+ */
40
+ public $license_id;
41
+ /**
42
+ * @var float
43
+ */
44
+ public $gross;
45
+ /**
46
+ * @var number
47
+ */
48
+ public $bound_payment_id;
49
+ /**
50
+ * @var string
51
+ */
52
+ public $external_id;
53
+ /**
54
+ * @var string
55
+ */
56
+ public $gateway;
57
+ /**
58
+ * @var string ISO 3166-1 alpha-2 - two-letter country code.
59
+ *
60
+ * @link http://www.wikiwand.com/en/ISO_3166-1_alpha-2
61
+ */
62
+ public $country_code;
63
+ /**
64
+ * @var string
65
+ */
66
+ public $vat_id;
67
+ /**
68
+ * @var float Actual Tax / VAT in $$$
69
+ */
70
+ public $vat;
71
+
72
+ #endregion Properties
73
+
74
+ /**
75
+ * @param object|bool $payment
76
+ */
77
+ function __construct( $payment = false ) {
78
+ parent::__construct( $payment );
79
+ }
80
+
81
+ static function get_type() {
82
+ return 'payment';
83
+ }
84
+
85
+ /**
86
+ * @author Vova Feldman (@svovaf)
87
+ * @since 1.0.0
88
+ *
89
+ * @return bool
90
+ */
91
+ function is_refund() {
92
+ return ( parent::is_valid_id( $this->bound_payment_id ) && 0 > $this->gross );
93
+ }
94
+ }
freemius/includes/entities/class-fs-plugin-info.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Info extends FS_Entity {
14
+ public $plugin_id;
15
+ public $description;
16
+ public $short_description;
17
+ public $banner_url;
18
+ public $card_banner_url;
19
+ public $selling_point_0;
20
+ public $selling_point_1;
21
+ public $selling_point_2;
22
+ public $screenshots;
23
+
24
+ /**
25
+ * @param stdClass|bool $plugin_info
26
+ */
27
+ function __construct( $plugin_info = false ) {
28
+ parent::__construct( $plugin_info );
29
+ }
30
+
31
+ static function get_type() {
32
+ return 'plugin';
33
+ }
34
+ }
freemius/includes/entities/class-fs-plugin-license.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Plugin_License
15
+ */
16
+ class FS_Plugin_License extends FS_Entity {
17
+
18
+ #region Properties
19
+
20
+ /**
21
+ * @var number
22
+ */
23
+ public $plugin_id;
24
+ /**
25
+ * @var number
26
+ */
27
+ public $user_id;
28
+ /**
29
+ * @var number
30
+ */
31
+ public $plan_id;
32
+ /**
33
+ * @var number
34
+ */
35
+ public $pricing_id;
36
+ /**
37
+ * @var int|null
38
+ */
39
+ public $quota;
40
+ /**
41
+ * @var int
42
+ */
43
+ public $activated;
44
+ /**
45
+ * @var int
46
+ */
47
+ public $activated_local;
48
+ /**
49
+ * @var string
50
+ */
51
+ public $expiration;
52
+ /**
53
+ * @var string
54
+ */
55
+ public $secret_key;
56
+ /**
57
+ * @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
58
+ * license.
59
+ */
60
+ public $is_free_localhost;
61
+ /**
62
+ * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
63
+ * block updates and support.
64
+ */
65
+ public $is_block_features;
66
+ /**
67
+ * @var bool
68
+ */
69
+ public $is_cancelled;
70
+
71
+ #endregion Properties
72
+
73
+ /**
74
+ * @param stdClass|bool $license
75
+ */
76
+ function __construct( $license = false ) {
77
+ parent::__construct( $license );
78
+ }
79
+
80
+ /**
81
+ * Get entity type.
82
+ *
83
+ * @return string
84
+ */
85
+ static function get_type() {
86
+ return 'license';
87
+ }
88
+
89
+ /**
90
+ * Check how many site activations left.
91
+ *
92
+ * @author Vova Feldman (@svovaf)
93
+ * @since 1.0.5
94
+ *
95
+ * @return int
96
+ */
97
+ function left() {
98
+ if ( ! $this->is_active() || $this->is_expired() ) {
99
+ return 0;
100
+ }
101
+
102
+ if ( $this->is_unlimited() ) {
103
+ return 999;
104
+ }
105
+
106
+ return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
107
+ }
108
+
109
+ /**
110
+ * Check if single site license.
111
+ *
112
+ * @author Vova Feldman (@svovaf)
113
+ * @since 1.1.8.1
114
+ *
115
+ * @return bool
116
+ */
117
+ function is_single_site() {
118
+ return ( is_numeric( $this->quota ) && 1 == $this->quota );
119
+ }
120
+
121
+ /**
122
+ * @author Vova Feldman (@svovaf)
123
+ * @since 1.0.5
124
+ *
125
+ * @return bool
126
+ */
127
+ function is_expired() {
128
+ return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
129
+ }
130
+
131
+ /**
132
+ * Check if license is not expired.
133
+ *
134
+ * @author Vova Feldman (@svovaf)
135
+ * @since 1.2.1
136
+ *
137
+ * @return bool
138
+ */
139
+ function is_valid() {
140
+ return ! $this->is_expired();
141
+ }
142
+
143
+ /**
144
+ * @author Vova Feldman (@svovaf)
145
+ * @since 1.0.6
146
+ *
147
+ * @return bool
148
+ */
149
+ function is_lifetime() {
150
+ return is_null( $this->expiration );
151
+ }
152
+
153
+ /**
154
+ * @author Vova Feldman (@svovaf)
155
+ * @since 1.2.0
156
+ *
157
+ * @return bool
158
+ */
159
+ function is_unlimited() {
160
+ return is_null( $this->quota );
161
+ }
162
+
163
+ /**
164
+ * Check if license is fully utilized.
165
+ *
166
+ * @author Vova Feldman (@svovaf)
167
+ * @since 1.0.6
168
+ *
169
+ * @param bool $is_localhost
170
+ *
171
+ * @return bool
172
+ */
173
+ function is_utilized( $is_localhost = null ) {
174
+ if ( is_null( $is_localhost ) ) {
175
+ $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
176
+ }
177
+
178
+ if ( $this->is_unlimited() ) {
179
+ return false;
180
+ }
181
+
182
+ return ! ( $this->is_free_localhost && $is_localhost ) &&
183
+ ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
184
+ }
185
+
186
+ /**
187
+ * @author Vova Feldman (@svovaf)
188
+ * @since 1.2.1
189
+ *
190
+ * @return bool
191
+ */
192
+ function is_active() {
193
+ return ( ! $this->is_cancelled );
194
+ }
195
+
196
+ /**
197
+ * Check if license's plan features are enabled.
198
+ *
199
+ * - Either if plan not expired
200
+ * - If expired, based on the configuration to block features or not.
201
+ *
202
+ * @author Vova Feldman (@svovaf)
203
+ * @since 1.0.6
204
+ *
205
+ * @return bool
206
+ */
207
+ function is_features_enabled() {
208
+ return $this->is_active() && ( ! $this->is_block_features || ! $this->is_expired() );
209
+ }
210
+
211
+ /**
212
+ * Subscription considered to be new without any payments
213
+ * if the license expires in less than 24 hours
214
+ * from the license creation.
215
+ *
216
+ * @author Vova Feldman (@svovaf)
217
+ * @since 1.0.9
218
+ *
219
+ * @return bool
220
+ */
221
+ function is_first_payment_pending() {
222
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
223
+ }
224
+ }
freemius/includes/entities/class-fs-plugin-plan.php ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Plugin_Plan
15
+ *
16
+ * @property FS_Pricing[] $pricing
17
+ */
18
+ class FS_Plugin_Plan extends FS_Entity {
19
+
20
+ #region Properties
21
+
22
+ /**
23
+ * @var number
24
+ */
25
+ public $plugin_id;
26
+ /**
27
+ * @var string
28
+ */
29
+ public $name;
30
+ /**
31
+ * @var string
32
+ */
33
+ public $title;
34
+ /**
35
+ * @var string
36
+ */
37
+ public $description;
38
+ /**
39
+ * @var bool Defaults to true. If true, allow unlimited localhost installs with the same license.
40
+ */
41
+ public $is_free_localhost;
42
+ /**
43
+ * @var bool Defaults to true. If false, don't block features after license expiry - only block updates and
44
+ * support.
45
+ */
46
+ public $is_block_features;
47
+ /**
48
+ * @var int
49
+ */
50
+ public $license_type;
51
+ /**
52
+ * @var bool
53
+ */
54
+ public $is_https_support;
55
+ /**
56
+ * @var int Trial days.
57
+ */
58
+ public $trial_period;
59
+ /**
60
+ * @var string If true, require payment for trial.
61
+ */
62
+ public $is_require_subscription;
63
+ /**
64
+ * @var string Knowledge Base URL.
65
+ */
66
+ public $support_kb;
67
+ /**
68
+ * @var string Support Forum URL.
69
+ */
70
+ public $support_forum;
71
+ /**
72
+ * @var string Support email address.
73
+ */
74
+ public $support_email;
75
+ /**
76
+ * @var string Support phone.
77
+ */
78
+ public $support_phone;
79
+ /**
80
+ * @var string Support skype username.
81
+ */
82
+ public $support_skype;
83
+ /**
84
+ * @var bool Is personal success manager supported with the plan.
85
+ */
86
+ public $is_success_manager;
87
+ /**
88
+ * @var bool Is featured plan.
89
+ */
90
+ public $is_featured;
91
+
92
+ #endregion Properties
93
+
94
+ /**
95
+ * @param object|bool $plan
96
+ */
97
+ function __construct( $plan = false ) {
98
+ parent::__construct( $plan );
99
+
100
+ if ( is_object( $plan ) ) {
101
+ $this->name = strtolower( $plan->name );
102
+ }
103
+ }
104
+
105
+ static function get_type() {
106
+ return 'plan';
107
+ }
108
+
109
+ /**
110
+ * @author Vova Feldman (@svovaf)
111
+ * @since 1.0.9
112
+ *
113
+ * @return bool
114
+ */
115
+ function is_free() {
116
+ return ( 'free' === $this->name );
117
+ }
118
+
119
+ /**
120
+ * Checks if this plan supports "Technical Support".
121
+ *
122
+ * @author Leo Fajardo (leorw)
123
+ * @since 1.2.0
124
+ *
125
+ * @return bool
126
+ */
127
+ function has_technical_support() {
128
+ return ( ! empty( $this->support_email ) ||
129
+ ! empty( $this->support_skype ) ||
130
+ ! empty( $this->support_phone ) ||
131
+ ! empty( $this->is_success_manager )
132
+ );
133
+ }
134
+
135
+ /**
136
+ * @author Vova Feldman (@svovaf)
137
+ * @since 1.0.9
138
+ *
139
+ * @return bool
140
+ */
141
+ function has_trial() {
142
+ return ! $this->is_free() &&
143
+ is_numeric( $this->trial_period ) && ( $this->trial_period > 0 );
144
+ }
145
+ }
freemius/includes/entities/class-fs-plugin-tag.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Tag extends FS_Entity {
14
+ public $version;
15
+ public $url;
16
+
17
+ function __construct( $tag = false ) {
18
+ parent::__construct( $tag );
19
+ }
20
+
21
+ static function get_type() {
22
+ return 'tag';
23
+ }
24
+ }
freemius/includes/entities/class-fs-plugin.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin extends FS_Scope_Entity {
14
+ /**
15
+ * @since 1.0.6
16
+ * @var null|number
17
+ */
18
+ public $parent_plugin_id;
19
+ /**
20
+ * @var string
21
+ */
22
+ public $title;
23
+ /**
24
+ * @var string
25
+ */
26
+ public $slug;
27
+ /**
28
+ * @since 1.2.2
29
+ *
30
+ * @var string 'plugin' or 'theme'
31
+ */
32
+ public $type;
33
+
34
+ #region Install Specific Properties
35
+
36
+ /**
37
+ * @var string
38
+ */
39
+ public $file;
40
+ /**
41
+ * @var string
42
+ */
43
+ public $version;
44
+ /**
45
+ * @var bool
46
+ */
47
+ public $auto_update;
48
+ /**
49
+ * @var FS_Plugin_Info
50
+ */
51
+ public $info;
52
+ /**
53
+ * @since 1.0.9
54
+ *
55
+ * @var bool
56
+ */
57
+ public $is_premium;
58
+ /**
59
+ * @since 1.0.9
60
+ *
61
+ * @var bool
62
+ */
63
+ public $is_live;
64
+
65
+ #endregion Install Specific Properties
66
+
67
+ /**
68
+ * @param stdClass|bool $plugin
69
+ */
70
+ function __construct( $plugin = false ) {
71
+ parent::__construct( $plugin );
72
+
73
+ $this->is_premium = false;
74
+ $this->is_live = true;
75
+
76
+ if ( isset( $plugin->info ) && is_object( $plugin->info ) ) {
77
+ $this->info = new FS_Plugin_Info( $plugin->info );
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Check if plugin is an add-on (has parent).
83
+ *
84
+ * @author Vova Feldman (@svovaf)
85
+ * @since 1.0.6
86
+ *
87
+ * @return bool
88
+ */
89
+ function is_addon() {
90
+ return isset( $this->parent_plugin_id ) && is_numeric( $this->parent_plugin_id );
91
+ }
92
+
93
+ static function get_type() {
94
+ return 'plugin';
95
+ }
96
+ }
freemius/includes/entities/class-fs-pricing.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius for EDD Add-On
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Pricing extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plan_id;
21
+ /**
22
+ * @var int
23
+ */
24
+ public $licenses;
25
+ /**
26
+ * @var null|float
27
+ */
28
+ public $monthly_price;
29
+ /**
30
+ * @var null|float
31
+ */
32
+ public $annual_price;
33
+ /**
34
+ * @var null|float
35
+ */
36
+ public $lifetime_price;
37
+
38
+ #endregion Properties
39
+
40
+ /**
41
+ * @param object|bool $pricing
42
+ */
43
+ function __construct( $pricing = false ) {
44
+ parent::__construct( $pricing );
45
+ }
46
+
47
+ static function get_type() {
48
+ return 'pricing';
49
+ }
50
+
51
+ /**
52
+ * @author Vova Feldman (@svovaf)
53
+ * @since 1.1.8
54
+ *
55
+ * @return bool
56
+ */
57
+ function has_monthly() {
58
+ return ( is_numeric( $this->monthly_price ) && $this->monthly_price > 0 );
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.8
64
+ *
65
+ * @return bool
66
+ */
67
+ function has_annual() {
68
+ return ( is_numeric( $this->annual_price ) && $this->annual_price > 0 );
69
+ }
70
+
71
+ /**
72
+ * @author Vova Feldman (@svovaf)
73
+ * @since 1.1.8
74
+ *
75
+ * @return bool
76
+ */
77
+ function has_lifetime() {
78
+ return ( is_numeric( $this->lifetime_price ) && $this->lifetime_price > 0 );
79
+ }
80
+
81
+ /**
82
+ * Check if unlimited licenses pricing.
83
+ *
84
+ * @author Vova Feldman (@svovaf)
85
+ * @since 1.1.8
86
+ *
87
+ * @return bool
88
+ */
89
+ function is_unlimited() {
90
+ return is_null( $this->licenses );
91
+ }
92
+
93
+
94
+ /**
95
+ * Check if pricing has more than one billing cycle.
96
+ *
97
+ * @author Vova Feldman (@svovaf)
98
+ * @since 1.1.8
99
+ *
100
+ * @return bool
101
+ */
102
+ function is_multi_cycle() {
103
+ $cycles = 0;
104
+ if ( $this->has_monthly() ) {
105
+ $cycles ++;
106
+ }
107
+ if ( $this->has_annual() ) {
108
+ $cycles ++;
109
+ }
110
+ if ( $this->has_lifetime() ) {
111
+ $cycles ++;
112
+ }
113
+
114
+ return $cycles > 1;
115
+ }
116
+
117
+ /**
118
+ * Get annual over monthly discount.
119
+ *
120
+ * @author Vova Feldman (@svovaf)
121
+ * @since 1.1.8
122
+ *
123
+ * @return int
124
+ */
125
+ function annual_discount_percentage() {
126
+ return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 );
127
+ }
128
+
129
+ /**
130
+ * Get annual over monthly savings.
131
+ *
132
+ * @author Vova Feldman (@svovaf)
133
+ * @since 1.1.8
134
+ *
135
+ * @return float
136
+ */
137
+ function annual_savings() {
138
+ return ( $this->monthly_price * 12 - $this->annual_price ) * ( $this->is_unlimited() ? 1 : $this->licenses );
139
+ }
140
+
141
+ }
freemius/includes/entities/class-fs-scope-entity.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Scope_Entity extends FS_Entity {
14
+ /**
15
+ * @var string
16
+ */
17
+ public $public_key;
18
+ /**
19
+ * @var string
20
+ */
21
+ public $secret_key;
22
+
23
+ /**
24
+ * @param bool|stdClass $scope_entity
25
+ */
26
+ function __construct( $scope_entity = false ) {
27
+ parent::__construct( $scope_entity );
28
+ }
29
+ }
freemius/includes/entities/class-fs-site.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Site extends FS_Scope_Entity {
14
+ /**
15
+ * @var string
16
+ */
17
+ public $slug;
18
+ /**
19
+ * @var number
20
+ */
21
+ public $site_id;
22
+ /**
23
+ * @var number
24
+ */
25
+ public $plugin_id;
26
+ /**
27
+ * @var number
28
+ */
29
+ public $user_id;
30
+ /**
31
+ * @var string
32
+ */
33
+ public $title;
34
+ /**
35
+ * @var string
36
+ */
37
+ public $url;
38
+ /**
39
+ * @var string
40
+ */
41
+ public $version;
42
+ /**
43
+ * @var string E.g. en-GB
44
+ */
45
+ public $language;
46
+ /**
47
+ * @var string E.g. UTF-8
48
+ */
49
+ public $charset;
50
+ /**
51
+ * @var string Platform version (e.g WordPress version).
52
+ */
53
+ public $platform_version;
54
+ /**
55
+ * Freemius SDK version
56
+ *
57
+ * @author Leo Fajardo (@leorw)
58
+ * @since 1.2.2
59
+ *
60
+ * @var string SDK version (e.g.: 1.2.2)
61
+ */
62
+ public $sdk_version;
63
+ /**
64
+ * @var string Programming language version (e.g PHP version).
65
+ */
66
+ public $programming_language_version;
67
+ /**
68
+ * @var FS_Plugin_Plan $plan
69
+ */
70
+ public $plan;
71
+ /**
72
+ * @var number|null
73
+ */
74
+ public $license_id;
75
+ /**
76
+ * @var number|null
77
+ */
78
+ public $trial_plan_id;
79
+ /**
80
+ * @var string|null
81
+ */
82
+ public $trial_ends;
83
+ /**
84
+ * @since 1.0.9
85
+ *
86
+ * @var bool
87
+ */
88
+ public $is_premium = false;
89
+ /**
90
+ * @author Leo Fajardo (@leorw)
91
+ *
92
+ * @since 1.2.1.5
93
+ *
94
+ * @var bool
95
+ */
96
+ public $is_disconnected = false;
97
+
98
+ /**
99
+ * @param stdClass|bool $site
100
+ */
101
+ function __construct( $site = false ) {
102
+ $this->plan = new FS_Plugin_Plan();
103
+
104
+ parent::__construct( $site );
105
+
106
+ if ( is_object( $site ) ) {
107
+ $this->plan->id = $site->plan_id;
108
+ }
109
+
110
+ if ( ! is_bool( $this->is_disconnected ) ) {
111
+ $this->is_disconnected = false;
112
+ }
113
+ }
114
+
115
+ static function get_type() {
116
+ return 'install';
117
+ }
118
+
119
+ function is_localhost() {
120
+ // The server has no way to verify if localhost unless localhost appears in domain.
121
+ return WP_FS__IS_LOCALHOST_FOR_SERVER;
122
+ // return (substr($_SERVER['REMOTE_ADDR'], 0, 4) == '127.' || $_SERVER['REMOTE_ADDR'] == '::1');
123
+ }
124
+
125
+ /**
126
+ * Check if site in trial.
127
+ *
128
+ * @author Vova Feldman (@svovaf)
129
+ * @since 1.0.9
130
+ *
131
+ * @return bool
132
+ */
133
+ function is_trial() {
134
+ return is_numeric( $this->trial_plan_id ) && ( strtotime( $this->trial_ends ) > WP_FS__SCRIPT_START_TIME );
135
+ }
136
+
137
+ /**
138
+ * Check if user already utilized the trial with the current install.
139
+ *
140
+ * @author Vova Feldman (@svovaf)
141
+ * @since 1.0.9
142
+ *
143
+ * @return bool
144
+ */
145
+ function is_trial_utilized() {
146
+ return is_numeric( $this->trial_plan_id );
147
+ }
148
+ }
freemius/includes/entities/class-fs-subscription.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.9
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Subscription extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $user_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $install_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $plan_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $license_id;
33
+ /**
34
+ * @var float
35
+ */
36
+ public $total_gross;
37
+ /**
38
+ * @var float
39
+ */
40
+ public $amount_per_cycle;
41
+ /**
42
+ * @var int # of months
43
+ */
44
+ public $billing_cycle;
45
+ /**
46
+ * @var float
47
+ */
48
+ public $outstanding_balance;
49
+ /**
50
+ * @var int
51
+ */
52
+ public $failed_payments;
53
+ /**
54
+ * @var string
55
+ */
56
+ public $gateway;
57
+ /**
58
+ * @var string
59
+ */
60
+ public $external_id;
61
+ /**
62
+ * @var string|null
63
+ */
64
+ public $trial_ends;
65
+ /**
66
+ * @var string|null Datetime of the next payment, or null if cancelled
67
+ */
68
+ public $next_payment;
69
+ /**
70
+ * @var string|null
71
+ */
72
+ public $vat_id;
73
+ /**
74
+ * @var string Two characters country code
75
+ */
76
+ public $country_code;
77
+
78
+ #endregion Properties
79
+
80
+ /**
81
+ * @param object|bool $subscription
82
+ */
83
+ function __construct( $subscription = false ) {
84
+ parent::__construct( $subscription );
85
+ }
86
+
87
+ static function get_type() {
88
+ return 'subscription';
89
+ }
90
+
91
+ /**
92
+ * Check if subscription is active.
93
+ *
94
+ * @author Vova Feldman (@svovaf)
95
+ * @since 1.0.9
96
+ *
97
+ * @return bool
98
+ */
99
+ function is_active() {
100
+ return ! empty( $this->next_payment ) &&
101
+ ( strtotime( $this->next_payment ) > WP_FS__SCRIPT_START_TIME );
102
+ }
103
+
104
+ /**
105
+ * Subscription considered to be new without any payments
106
+ * if the next payment should be made within less than 24 hours
107
+ * from the subscription creation.
108
+ *
109
+ * @author Vova Feldman (@svovaf)
110
+ * @since 1.0.9
111
+ *
112
+ * @return bool
113
+ */
114
+ function is_first_payment_pending() {
115
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->next_payment ) - strtotime( $this->created ) );
116
+ }
117
+
118
+ /**
119
+ * @author Vova Feldman (@svovaf)
120
+ * @since 1.1.7
121
+ */
122
+ function has_trial() {
123
+ return ! is_null( $this->trial_ends );
124
+ }
125
+ }
freemius/includes/entities/class-fs-user.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_User extends FS_Scope_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ public $email;
21
+ /**
22
+ * @var string
23
+ */
24
+ public $first;
25
+ /**
26
+ * @var string
27
+ */
28
+ public $last;
29
+ /**
30
+ * @var bool
31
+ */
32
+ public $is_verified;
33
+ /**
34
+ * @var string|null
35
+ */
36
+ public $customer_id;
37
+ /**
38
+ * @var float
39
+ */
40
+ public $gross;
41
+
42
+ #endregion Properties
43
+
44
+ /**
45
+ * @param object|bool $user
46
+ */
47
+ function __construct( $user = false ) {
48
+ parent::__construct( $user );
49
+ }
50
+
51
+ function get_name() {
52
+ return trim( ucfirst( trim( is_string( $this->first ) ? $this->first : '' ) ) . ' ' . ucfirst( trim( is_string( $this->last ) ? $this->last : '' ) ) );
53
+ }
54
+
55
+ function is_verified() {
56
+ return ( isset( $this->is_verified ) && true === $this->is_verified );
57
+ }
58
+
59
+ static function get_type() {
60
+ return 'user';
61
+ }
62
+ }
freemius/includes/entities/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/includes/fs-core-functions.php ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! function_exists( 'fs_dummy' ) ) {
14
+ function fs_dummy() {
15
+ }
16
+ }
17
+
18
+ /* Url.
19
+ --------------------------------------------------------------------------------------------*/
20
+ function fs_get_url_daily_cache_killer() {
21
+ return date( '\YY\Mm\Dd' );
22
+ }
23
+
24
+ /* Templates / Views.
25
+ --------------------------------------------------------------------------------------------*/
26
+ if ( ! function_exists( 'fs_get_template_path' ) ) {
27
+ function fs_get_template_path( $path ) {
28
+ return WP_FS__DIR_TEMPLATES . '/' . trim( $path, '/' );
29
+ }
30
+
31
+ function fs_include_template( $path, &$params = null ) {
32
+ $VARS = &$params;
33
+ include fs_get_template_path( $path );
34
+ }
35
+
36
+ function fs_include_once_template( $path, &$params = null ) {
37
+ $VARS = &$params;
38
+ include_once fs_get_template_path( $path );
39
+ }
40
+
41
+ function fs_require_template( $path, &$params = null ) {
42
+ $VARS = &$params;
43
+ require fs_get_template_path( $path );
44
+ }
45
+
46
+ function fs_require_once_template( $path, &$params = null ) {
47
+ $VARS = &$params;
48
+ require_once fs_get_template_path( $path );
49
+ }
50
+
51
+ function fs_get_template( $path, &$params = null ) {
52
+ ob_start();
53
+
54
+ $VARS = &$params;
55
+ require fs_get_template_path( $path );
56
+
57
+ return ob_get_clean();
58
+ }
59
+ }
60
+
61
+ /* Scripts and styles including.
62
+ --------------------------------------------------------------------------------------------*/
63
+
64
+ /**
65
+ * Generates an absolute URL to the given path. This function ensures that the URL will be correct whether the asset
66
+ * is inside a plugin's folder or a theme's folder.
67
+ *
68
+ * Examples:
69
+ * 1. "themes" folder
70
+ * Path: C:/xampp/htdocs/fswp/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css
71
+ * URL: http://fswp:8080/wp-content/themes/twentytwelve/freemius/assets/css/admin/common.css
72
+ *
73
+ * 2. "plugins" folder
74
+ * Path: C:/xampp/htdocs/fswp/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css
75
+ * URL: http://fswp:8080/wp-content/plugins/rating-widget-premium/freemius/assets/css/admin/common.css
76
+ *
77
+ * @author Leo Fajardo (@leorw)
78
+ * @since 1.2.2
79
+ *
80
+ * @param string $asset_abs_path Asset's absolute path.
81
+ *
82
+ * @return string Asset's URL.
83
+ */
84
+ function fs_asset_url( $asset_abs_path ) {
85
+ $wp_content_dir = fs_normalize_path( WP_CONTENT_DIR );
86
+ $asset_abs_path = fs_normalize_path( $asset_abs_path );
87
+ $asset_rel_path = str_replace( $wp_content_dir, '', $asset_abs_path );
88
+
89
+ $asset_url = content_url( fs_normalize_path( $asset_rel_path ) );
90
+
91
+ return $asset_url;
92
+ }
93
+
94
+ function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) {
95
+ wp_enqueue_style( $handle, fs_asset_url( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ), $deps, $ver, $media );
96
+ }
97
+
98
+ function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) {
99
+ wp_enqueue_script( $handle, fs_asset_url( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ), $deps, $ver, $in_footer );
100
+ }
101
+
102
+ function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) {
103
+ return ( fs_asset_url( $img_dir . '/' . trim( $path, '/' ) ) );
104
+ }
105
+
106
+ /* Request handlers.
107
+ --------------------------------------------------------------------------------------------*/
108
+ /**
109
+ * @param string $key
110
+ * @param mixed $def
111
+ * @param string|bool $type Since 1.2.1.7 - when set to 'get' will look for the value passed via querystring, when
112
+ * set to 'post' will look for the value passed via the POST request's body, otherwise,
113
+ * will check if the parameter was passed in any of the two.
114
+ *
115
+ * @return mixed
116
+ */
117
+ function fs_request_get( $key, $def = false, $type = false ) {
118
+ if ( is_string( $type ) ) {
119
+ $type = strtolower( $type );
120
+ }
121
+
122
+ switch ( $type ) {
123
+ case 'post':
124
+ $value = isset( $_POST[ $key ] ) ? $_POST[ $key ] : $def;
125
+ break;
126
+ case 'get':
127
+ $value = isset( $_GET[ $key ] ) ? $_GET[ $key ] : $def;
128
+ break;
129
+ default:
130
+ $value = isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def;
131
+ break;
132
+ }
133
+
134
+ return $value;
135
+ }
136
+
137
+ function fs_request_has( $key ) {
138
+ return isset( $_REQUEST[ $key ] );
139
+ }
140
+
141
+ function fs_request_get_bool( $key, $def = false ) {
142
+ if ( ! isset( $_REQUEST[ $key ] ) ) {
143
+ return $def;
144
+ }
145
+
146
+ if ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) {
147
+ return true;
148
+ }
149
+
150
+ if ( 0 == $_REQUEST[ $key ] || 'false' === strtolower( $_REQUEST[ $key ] ) ) {
151
+ return false;
152
+ }
153
+
154
+ return $def;
155
+ }
156
+
157
+ function fs_request_is_post() {
158
+ return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
159
+ }
160
+
161
+ function fs_request_is_get() {
162
+ return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
163
+ }
164
+
165
+ function fs_get_action( $action_key = 'action' ) {
166
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
167
+ return strtolower( $_REQUEST[ $action_key ] );
168
+ }
169
+
170
+ if ( 'action' == $action_key ) {
171
+ $action_key = 'fs_action';
172
+
173
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
174
+ return strtolower( $_REQUEST[ $action_key ] );
175
+ }
176
+ }
177
+
178
+ return false;
179
+ }
180
+
181
+ function fs_request_is_action( $action, $action_key = 'action' ) {
182
+ return ( strtolower( $action ) === fs_get_action( $action_key ) );
183
+ }
184
+
185
+ /**
186
+ * @author Vova Feldman (@svovaf)
187
+ * @since 1.0.0
188
+ *
189
+ * @since 1.2.1.5 Allow nonce verification.
190
+ *
191
+ * @param string $action
192
+ * @param string $action_key
193
+ * @param string $nonce_key
194
+ *
195
+ * @return bool
196
+ */
197
+ function fs_request_is_action_secure(
198
+ $action,
199
+ $action_key = 'action',
200
+ $nonce_key = 'nonce'
201
+ ) {
202
+ if ( strtolower( $action ) !== fs_get_action( $action_key ) ) {
203
+ return false;
204
+ }
205
+
206
+ $nonce = ! empty( $_REQUEST[ $nonce_key ] ) ?
207
+ $_REQUEST[ $nonce_key ] :
208
+ '';
209
+
210
+ if ( empty( $nonce ) ||
211
+ ( false === wp_verify_nonce( $nonce, $action ) )
212
+ ) {
213
+ return false;
214
+ }
215
+
216
+ return true;
217
+ }
218
+
219
+ function fs_is_plugin_page( $page_slug ) {
220
+ return ( is_admin() && $page_slug === fs_request_get( 'page' ) );
221
+ }
222
+
223
+ /* Core UI.
224
+ --------------------------------------------------------------------------------------------*/
225
+ /**
226
+ * @param number $module_id
227
+ * @param string $page
228
+ * @param string $action
229
+ * @param string $title
230
+ * @param array $params
231
+ * @param bool $is_primary
232
+ * @param string|bool $icon_class Optional class for an icon (since 1.1.7).
233
+ * @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7).
234
+ * @param string $method Since 1.1.7
235
+ *
236
+ * @uses fs_ui_get_action_button()
237
+ */
238
+ function fs_ui_action_button(
239
+ $module_id,
240
+ $page,
241
+ $action,
242
+ $title,
243
+ $params = array(),
244
+ $is_primary = true,
245
+ $icon_class = false,
246
+ $confirmation = false,
247
+ $method = 'GET'
248
+ ) {
249
+ echo fs_ui_get_action_button(
250
+ $module_id,
251
+ $page,
252
+ $action,
253
+ $title,
254
+ $params,
255
+ $is_primary,
256
+ $icon_class,
257
+ $confirmation,
258
+ $method
259
+ );
260
+ }
261
+
262
+ /**
263
+ * @author Vova Feldman (@svovaf)
264
+ * @since 1.1.7
265
+ *
266
+ * @param number $module_id
267
+ * @param string $page
268
+ * @param string $action
269
+ * @param string $title
270
+ * @param array $params
271
+ * @param bool $is_primary
272
+ * @param string|bool $icon_class Optional class for an icon.
273
+ * @param string|bool $confirmation Optional confirmation message before submit.
274
+ * @param string $method
275
+ *
276
+ * @return string
277
+ */
278
+ function fs_ui_get_action_button(
279
+ $module_id,
280
+ $page,
281
+ $action,
282
+ $title,
283
+ $params = array(),
284
+ $is_primary = true,
285
+ $icon_class = false,
286
+ $confirmation = false,
287
+ $method = 'GET'
288
+ ) {
289
+ // Prepend icon (if set).
290
+ $title = ( is_string( $icon_class ) ? '<i class="' . $icon_class . '"></i> ' : '' ) . $title;
291
+
292
+ if ( is_string( $confirmation ) ) {
293
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="if (confirm(\'%s\')) this.parentNode.submit(); return false;">%s</a></form>',
294
+ freemius( $module_id )->_get_admin_page_url( $page, $params ),
295
+ $method,
296
+ $action,
297
+ wp_nonce_field( $action, '_wpnonce', true, false ),
298
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
299
+ $confirmation,
300
+ $title
301
+ );
302
+ } else if ( 'GET' !== strtoupper( $method ) ) {
303
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="this.parentNode.submit(); return false;">%s</a></form>',
304
+ freemius( $module_id )->_get_admin_page_url( $page, $params ),
305
+ $method,
306
+ $action,
307
+ wp_nonce_field( $action, '_wpnonce', true, false ),
308
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
309
+ $title
310
+ );
311
+ } else {
312
+ return sprintf( '<a href="%s" class="%s">%s</a></form>',
313
+ wp_nonce_url( freemius( $module_id )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ),
314
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
315
+ $title
316
+ );
317
+ }
318
+ }
319
+
320
+ function fs_ui_action_link( $module_id, $page, $action, $title, $params = array() ) {
321
+ ?><a class=""
322
+ href="<?php echo wp_nonce_url( freemius( $module_id )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php
323
+ }
324
+
325
+ /*function fs_error_handler($errno, $errstr, $errfile, $errline)
326
+ {
327
+ if (false === strpos($errfile, 'freemius/'))
328
+ {
329
+ // @todo Dump Freemius errors to local log.
330
+ }
331
+
332
+ // switch ($errno) {
333
+ // case E_USER_ERROR:
334
+ // break;
335
+ // case E_WARNING:
336
+ // case E_USER_WARNING:
337
+ // break;
338
+ // case E_NOTICE:
339
+ // case E_USER_NOTICE:
340
+ // break;
341
+ // default:
342
+ // break;
343
+ // }
344
+ }
345
+
346
+ set_error_handler('fs_error_handler');*/
347
+
348
+ if ( ! function_exists( 'fs_nonce_url' ) ) {
349
+ /**
350
+ * Retrieve URL with nonce added to URL query.
351
+ *
352
+ * Originally was using `wp_nonce_url()` but the new version
353
+ * changed the return value to escaped URL, that's not the expected
354
+ * behaviour.
355
+ *
356
+ * @author Vova Feldman (@svovaf)
357
+ * @since ~1.1.3
358
+ *
359
+ * @param string $actionurl URL to add nonce action.
360
+ * @param int|string $action Optional. Nonce action name. Default -1.
361
+ * @param string $name Optional. Nonce name. Default '_wpnonce'.
362
+ *
363
+ * @return string Escaped URL with nonce action added.
364
+ */
365
+ function fs_nonce_url( $actionurl, $action = - 1, $name = '_wpnonce' ) {
366
+ return add_query_arg( $name, wp_create_nonce( $action ), $actionurl );
367
+ }
368
+ }
369
+
370
+ if ( ! function_exists( 'fs_starts_with' ) ) {
371
+ /**
372
+ * Check if string starts with.
373
+ *
374
+ * @author Vova Feldman (@svovaf)
375
+ * @since 1.1.3
376
+ *
377
+ * @param string $haystack
378
+ * @param string $needle
379
+ *
380
+ * @return bool
381
+ */
382
+ function fs_starts_with( $haystack, $needle ) {
383
+ $length = strlen( $needle );
384
+
385
+ return ( substr( $haystack, 0, $length ) === $needle );
386
+ }
387
+ }
388
+
389
+ #region Url Canonization ------------------------------------------------------------------
390
+
391
+ if ( ! function_exists( 'fs_canonize_url' ) ) {
392
+ /**
393
+ * @author Vova Feldman (@svovaf)
394
+ * @since 1.1.3
395
+ *
396
+ * @param string $url
397
+ * @param bool $omit_host
398
+ * @param array $ignore_params
399
+ *
400
+ * @return string
401
+ */
402
+ function fs_canonize_url( $url, $omit_host = false, $ignore_params = array() ) {
403
+ $parsed_url = parse_url( strtolower( $url ) );
404
+
405
+ // if ( ! isset( $parsed_url['host'] ) ) {
406
+ // return $url;
407
+ // }
408
+
409
+ $canonical = ( ( $omit_host || ! isset( $parsed_url['host'] ) ) ? '' : $parsed_url['host'] ) . $parsed_url['path'];
410
+
411
+ if ( isset( $parsed_url['query'] ) ) {
412
+ parse_str( $parsed_url['query'], $queryString );
413
+ $canonical .= '?' . fs_canonize_query_string( $queryString, $ignore_params );
414
+ }
415
+
416
+ return $canonical;
417
+ }
418
+ }
419
+
420
+ if ( ! function_exists( 'fs_canonize_query_string' ) ) {
421
+ /**
422
+ * @author Vova Feldman (@svovaf)
423
+ * @since 1.1.3
424
+ *
425
+ * @param array $params
426
+ * @param array $ignore_params
427
+ * @param bool $params_prefix
428
+ *
429
+ * @return string
430
+ */
431
+ function fs_canonize_query_string( array $params, array &$ignore_params, $params_prefix = false ) {
432
+ if ( ! is_array( $params ) || 0 === count( $params ) ) {
433
+ return '';
434
+ }
435
+
436
+ // Url encode both keys and values
437
+ $keys = fs_urlencode_rfc3986( array_keys( $params ) );
438
+ $values = fs_urlencode_rfc3986( array_values( $params ) );
439
+ $params = array_combine( $keys, $values );
440
+
441
+ // Parameters are sorted by name, using lexicographical byte value ordering.
442
+ // Ref: Spec: 9.1.1 (1)
443
+ uksort( $params, 'strcmp' );
444
+
445
+ $pairs = array();
446
+ foreach ( $params as $parameter => $value ) {
447
+ $lower_param = strtolower( $parameter );
448
+
449
+ // Skip ignore params.
450
+ if ( in_array( $lower_param, $ignore_params ) ||
451
+ ( false !== $params_prefix && fs_starts_with( $lower_param, $params_prefix ) )
452
+ ) {
453
+ continue;
454
+ }
455
+
456
+ if ( is_array( $value ) ) {
457
+ // If two or more parameters share the same name, they are sorted by their value
458
+ // Ref: Spec: 9.1.1 (1)
459
+ natsort( $value );
460
+ foreach ( $value as $duplicate_value ) {
461
+ $pairs[] = $lower_param . '=' . $duplicate_value;
462
+ }
463
+ } else {
464
+ $pairs[] = $lower_param . '=' . $value;
465
+ }
466
+ }
467
+
468
+ if ( 0 === count( $pairs ) ) {
469
+ return '';
470
+ }
471
+
472
+ return implode( "&", $pairs );
473
+ }
474
+ }
475
+
476
+ if ( ! function_exists( 'fs_urlencode_rfc3986' ) ) {
477
+ /**
478
+ * @author Vova Feldman (@svovaf)
479
+ * @since 1.1.3
480
+ *
481
+ * @param string|string[] $input
482
+ *
483
+ * @return array|mixed|string
484
+ */
485
+ function fs_urlencode_rfc3986( $input ) {
486
+ if ( is_array( $input ) ) {
487
+ return array_map( 'fs_urlencode_rfc3986', $input );
488
+ } else if ( is_scalar( $input ) ) {
489
+ return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $input ) ) );
490
+ }
491
+
492
+ return '';
493
+ }
494
+ }
495
+
496
+ #endregion Url Canonization ------------------------------------------------------------------
497
+
498
+ /**
499
+ * @author Vova Feldman (@svovaf)
500
+ *
501
+ * @since 1.2.2 Changed to usage of WP_Filesystem_Direct.
502
+ *
503
+ * @param string $from URL
504
+ * @param string $to File path.
505
+ */
506
+ function fs_download_image( $from, $to ) {
507
+ $dir = dirname( $to );
508
+
509
+ if ( 'direct' !== get_filesystem_method( array(), $dir ) ) {
510
+ return;
511
+ }
512
+
513
+ if ( ! class_exists( 'WP_Filesystem_Direct' ) ) {
514
+ require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
515
+ require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
516
+ }
517
+
518
+ $fs = new WP_Filesystem_Direct( '' );
519
+ $tmpfile = download_url( $from );
520
+ $fs->copy( $tmpfile, $to );
521
+ $fs->delete( $tmpfile );
522
+ }
523
+
524
+ /* General Utilities
525
+ --------------------------------------------------------------------------------------------*/
526
+
527
+ /**
528
+ * Sorts an array by the value of the priority key.
529
+ *
530
+ * @author Daniel Iser (@danieliser)
531
+ * @since 1.1.7
532
+ *
533
+ * @param $a
534
+ * @param $b
535
+ *
536
+ * @return int
537
+ */
538
+ function fs_sort_by_priority( $a, $b ) {
539
+
540
+ // If b has a priority and a does not, b wins.
541
+ if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) {
542
+ return 1;
543
+ } // If b has a priority and a does not, b wins.
544
+ elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) {
545
+ return - 1;
546
+ } // If neither has a priority or both priorities are equal its a tie.
547
+ elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) {
548
+ return 0;
549
+ }
550
+
551
+ // If both have priority return the winner.
552
+ return ( $a['priority'] < $b['priority'] ) ? - 1 : 1;
553
+ }
554
+
555
+ #--------------------------------------------------------------------------------
556
+ #region Localization
557
+ #--------------------------------------------------------------------------------
558
+
559
+ if ( ! function_exists( 'fs_text' ) ) {
560
+ /**
561
+ * Retrieve a translated text by key.
562
+ *
563
+ * @author Vova Feldman (@svovaf)
564
+ * @since 1.2.1.7
565
+ *
566
+ * @param string $key
567
+ * @param string $slug
568
+ *
569
+ * @return string
570
+ *
571
+ * @global $fs_text, $fs_text_overrides
572
+ */
573
+ function fs_text( $key, $slug = 'freemius' ) {
574
+ return __fs( $key, $slug );
575
+ }
576
+
577
+ /**
578
+ * Output a translated text by key.
579
+ *
580
+ * @author Vova Feldman (@svovaf)
581
+ * @since 1.2.1.7
582
+ *
583
+ * @param string $key
584
+ * @param string $slug
585
+ */
586
+ function fs_echo( $key, $slug = 'freemius' ) {
587
+ echo fs_text( $key, $slug );
588
+ }
589
+ }
590
+
591
+ /**
592
+ * @author Vova Feldman
593
+ * @since 1.2.1.6
594
+ *
595
+ * @param string $key
596
+ * @param string $slug
597
+ *
598
+ * @return string
599
+ */
600
+ function fs_esc_attr( $key, $slug ) {
601
+ return esc_attr( fs_text( $key, $slug ) );
602
+ }
603
+
604
+ /**
605
+ * @author Vova Feldman
606
+ * @since 1.2.1.6
607
+ *
608
+ * @param string $key
609
+ * @param string $slug
610
+ */
611
+ function fs_esc_attr_echo( $key, $slug ) {
612
+ echo esc_attr( fs_text( $key, $slug ) );
613
+ }
614
+
615
+ /**
616
+ * @author Vova Feldman
617
+ * @since 1.2.1.6
618
+ *
619
+ * @param string $key
620
+ * @param string $slug
621
+ *
622
+ * @return string
623
+ */
624
+ function fs_esc_js( $key, $slug ) {
625
+ return esc_js( fs_text( $key, $slug ) );
626
+ }
627
+
628
+ /**
629
+ * @author Vova Feldman
630
+ * @since 1.2.1.6
631
+ *
632
+ * @param string $key
633
+ * @param string $slug
634
+ */
635
+ function fs_esc_js_echo( $key, $slug ) {
636
+ echo esc_js( fs_text( $key, $slug ) );
637
+ }
638
+
639
+ /**
640
+ * @author Vova Feldman
641
+ * @since 1.2.1.6
642
+ *
643
+ * @param string $key
644
+ * @param string $slug
645
+ */
646
+ function fs_json_encode_echo( $key, $slug ) {
647
+ echo json_encode( fs_text( $key, $slug ) );
648
+ }
649
+
650
+ /**
651
+ * @author Vova Feldman
652
+ * @since 1.2.1.6
653
+ *
654
+ * @param string $key
655
+ * @param string $slug
656
+ *
657
+ * @return string
658
+ */
659
+ function fs_esc_html( $key, $slug ) {
660
+ return esc_html( fs_text( $key, $slug ) );
661
+ }
662
+
663
+ /**
664
+ * @author Vova Feldman
665
+ * @since 1.2.1.6
666
+ *
667
+ * @param string $key
668
+ * @param string $slug
669
+ */
670
+ function fs_esc_html_echo( $key, $slug ) {
671
+ echo esc_html( fs_text( $key, $slug ) );
672
+ }
673
+
674
+ #endregion
freemius/includes/fs-essential-functions.php ADDED
@@ -0,0 +1,494 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * IMPORTANT:
4
+ * This file will be loaded based on the order of the plugins/themes load.
5
+ * If there's a theme and a plugin using Freemius, the plugin's essential
6
+ * file will always load first.
7
+ *
8
+ * @package Freemius
9
+ * @copyright Copyright (c) 2015, Freemius, Inc.
10
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
11
+ * @since 1.1.5
12
+ */
13
+
14
+ if ( ! function_exists( 'fs_normalize_path' ) ) {
15
+ if ( function_exists( 'wp_normalize_path' ) ) {
16
+ /**
17
+ * Normalize a filesystem path.
18
+ *
19
+ * Replaces backslashes with forward slashes for Windows systems, and ensures
20
+ * no duplicate slashes exist.
21
+ *
22
+ * @param string $path Path to normalize.
23
+ *
24
+ * @return string Normalized path.
25
+ */
26
+ function fs_normalize_path( $path ) {
27
+ return wp_normalize_path( $path );
28
+ }
29
+ } else {
30
+ function fs_normalize_path( $path ) {
31
+ $path = str_replace( '\\', '/', $path );
32
+ $path = preg_replace( '|/+|', '/', $path );
33
+
34
+ return $path;
35
+ }
36
+ }
37
+ }
38
+
39
+ #region Core Redirect (copied from BuddyPress) -----------------------------------------
40
+
41
+ if ( ! function_exists( 'fs_redirect' ) ) {
42
+ /**
43
+ * Redirects to another page, with a workaround for the IIS Set-Cookie bug.
44
+ *
45
+ * @link http://support.microsoft.com/kb/q176113/
46
+ * @since 1.5.1
47
+ * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
48
+ *
49
+ * @param string $location The path to redirect to.
50
+ * @param bool $exit If true, exit after redirect (Since 1.2.1.5).
51
+ * @param int $status Status code to use.
52
+ *
53
+ * @return bool False if $location is not set
54
+ */
55
+ function fs_redirect( $location, $exit = true, $status = 302 ) {
56
+ global $is_IIS;
57
+
58
+ $file = '';
59
+ $line = '';
60
+ if ( headers_sent($file, $line) ) {
61
+ if ( WP_FS__DEBUG_SDK && class_exists( 'FS_Admin_Notice_Manager' ) ) {
62
+ $notices = FS_Admin_Notice_Manager::instance( 'global' );
63
+
64
+ $notices->add( "Freemius failed to redirect the page because the headers have been already sent from line <b><code>{$line}</code></b> in file <b><code>{$file}</code></b>. If it's unexpected, it usually happens due to invalid space and/or EOL character(s).", 'Oops...', 'error' );
65
+ }
66
+
67
+ return false;
68
+ }
69
+
70
+ if ( defined( 'DOING_AJAX' ) ) {
71
+ // Don't redirect on AJAX calls.
72
+ return false;
73
+ }
74
+
75
+ if ( ! $location ) // allows the wp_redirect filter to cancel a redirect
76
+ {
77
+ return false;
78
+ }
79
+
80
+ $location = fs_sanitize_redirect( $location );
81
+
82
+ if ( $is_IIS ) {
83
+ header( "Refresh: 0;url=$location" );
84
+ } else {
85
+ if ( php_sapi_name() != 'cgi-fcgi' ) {
86
+ status_header( $status );
87
+ } // This causes problems on IIS and some FastCGI setups
88
+ header( "Location: $location" );
89
+ }
90
+
91
+ if ( $exit ) {
92
+ exit();
93
+ }
94
+
95
+ return true;
96
+ }
97
+
98
+ if ( ! function_exists( 'fs_sanitize_redirect' ) ) {
99
+ /**
100
+ * Sanitizes a URL for use in a redirect.
101
+ *
102
+ * @since 2.3
103
+ *
104
+ * @param string $location
105
+ *
106
+ * @return string redirect-sanitized URL
107
+ */
108
+ function fs_sanitize_redirect( $location ) {
109
+ $location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location );
110
+ $location = fs_kses_no_null( $location );
111
+
112
+ // remove %0d and %0a from location
113
+ $strip = array( '%0d', '%0a' );
114
+ $found = true;
115
+ while ( $found ) {
116
+ $found = false;
117
+ foreach ( (array) $strip as $val ) {
118
+ while ( strpos( $location, $val ) !== false ) {
119
+ $found = true;
120
+ $location = str_replace( $val, '', $location );
121
+ }
122
+ }
123
+ }
124
+
125
+ return $location;
126
+ }
127
+ }
128
+
129
+ if ( ! function_exists( 'fs_kses_no_null' ) ) {
130
+ /**
131
+ * Removes any NULL characters in $string.
132
+ *
133
+ * @since 1.0.0
134
+ *
135
+ * @param string $string
136
+ *
137
+ * @return string
138
+ */
139
+ function fs_kses_no_null( $string ) {
140
+ $string = preg_replace( '/\0+/', '', $string );
141
+ $string = preg_replace( '/(\\\\0)+/', '', $string );
142
+
143
+ return $string;
144
+ }
145
+ }
146
+ }
147
+
148
+ #endregion Core Redirect (copied from BuddyPress) -----------------------------------------
149
+
150
+ if ( ! function_exists( '__fs' ) ) {
151
+ global $fs_text_overrides;
152
+
153
+ if ( ! isset( $fs_text_overrides ) ) {
154
+ $fs_text_overrides = array();
155
+ }
156
+
157
+ /**
158
+ * Retrieve a translated text by key.
159
+ *
160
+ * @deprecated Use `fs_text()` instead since methods starting with `__` trigger warnings in Php 7.
161
+ *
162
+ * @author Vova Feldman (@svovaf)
163
+ * @since 1.1.4
164
+ *
165
+ * @param string $key
166
+ * @param string $slug
167
+ *
168
+ * @return string
169
+ *
170
+ * @global $fs_text, $fs_text_overrides
171
+ */
172
+ function __fs( $key, $slug = 'freemius' ) {
173
+ global $fs_text,
174
+ $fs_module_info_text,
175
+ $fs_text_overrides;
176
+
177
+ if ( isset( $fs_text_overrides[ $slug ] ) ) {
178
+ if ( isset( $fs_text_overrides[ $slug ][ $key ] ) ) {
179
+ return $fs_text_overrides[ $slug ][ $key ];
180
+ }
181
+
182
+ $lower_key = strtolower( $key );
183
+ if ( isset( $fs_text_overrides[ $slug ][ $lower_key ] ) ) {
184
+ return $fs_text_overrides[ $slug ][ $lower_key ];
185
+ }
186
+ }
187
+
188
+ if ( ! isset( $fs_text ) ) {
189
+ $dir = defined( 'WP_FS__DIR_INCLUDES' ) ?
190
+ WP_FS__DIR_INCLUDES :
191
+ dirname( __FILE__ );
192
+
193
+ require_once $dir . '/i18n.php';
194
+ }
195
+
196
+ if ( isset( $fs_text[ $key ] ) ) {
197
+ return $fs_text[ $key ];
198
+ }
199
+
200
+ if ( isset( $fs_module_info_text[ $key ] ) ) {
201
+ return $fs_module_info_text[ $key ];
202
+ }
203
+
204
+ return $key;
205
+ }
206
+
207
+ /**
208
+ * Output a translated text by key.
209
+ *
210
+ * @deprecated Use `fs_echo()` instead for consistency with `fs_text()`.
211
+ *
212
+ * @author Vova Feldman (@svovaf)
213
+ * @since 1.1.4
214
+ *
215
+ * @param string $key
216
+ * @param string $slug
217
+ */
218
+ function _efs( $key, $slug = 'freemius' ) {
219
+ fs_echo( $key, $slug );
220
+ }
221
+ }
222
+
223
+ if ( ! function_exists( 'fs_override_i18n' ) ) {
224
+ /**
225
+ * Override default i18n text phrases.
226
+ *
227
+ * @author Vova Feldman (@svovaf)
228
+ * @since 1.1.6
229
+ *
230
+ * @param string[] $key_value
231
+ * @param string $slug
232
+ *
233
+ * @global $fs_text_overrides
234
+ */
235
+ function fs_override_i18n( array $key_value, $slug = 'freemius' ) {
236
+ global $fs_text_overrides;
237
+
238
+ if ( ! isset( $fs_text_overrides[ $slug ] ) ) {
239
+ $fs_text_overrides[ $slug ] = array();
240
+ }
241
+
242
+ foreach ( $key_value as $key => $value ) {
243
+ $fs_text_overrides[ $slug ][ $key ] = $value;
244
+ }
245
+ }
246
+ }
247
+
248
+ if ( ! function_exists( 'fs_get_ip' ) ) {
249
+ /**
250
+ * Get client IP.
251
+ *
252
+ * @author Vova Feldman (@svovaf)
253
+ * @since 1.1.2
254
+ *
255
+ * @return string|null
256
+ */
257
+ function fs_get_ip() {
258
+ $fields = array(
259
+ 'HTTP_CF_CONNECTING_IP',
260
+ 'HTTP_CLIENT_IP',
261
+ 'HTTP_X_FORWARDED_FOR',
262
+ 'HTTP_X_FORWARDED',
263
+ 'HTTP_FORWARDED_FOR',
264
+ 'HTTP_FORWARDED',
265
+ 'REMOTE_ADDR',
266
+ );
267
+
268
+ foreach ( $fields as $ip_field ) {
269
+ if ( ! empty( $_SERVER[ $ip_field ] ) ) {
270
+ return $_SERVER[ $ip_field ];
271
+ }
272
+ }
273
+
274
+ return null;
275
+ }
276
+ }
277
+
278
+ /**
279
+ * Leverage backtrace to find caller plugin main file path.
280
+ *
281
+ * @author Vova Feldman (@svovaf)
282
+ * @since 1.0.6
283
+ *
284
+ * @return string
285
+ */
286
+ function fs_find_caller_plugin_file() {
287
+ /**
288
+ * All the code below will be executed once on activation.
289
+ * If the user changes the main plugin's file name, the file_exists()
290
+ * will catch it.
291
+ */
292
+ if ( ! function_exists( 'get_plugins' ) ) {
293
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
294
+ }
295
+
296
+ $all_plugins = get_plugins();
297
+ $all_plugins_paths = array();
298
+
299
+ // Get active plugin's main files real full names (might be symlinks).
300
+ foreach ( $all_plugins as $relative_path => &$data ) {
301
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
302
+ }
303
+
304
+ $plugin_file = null;
305
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
306
+ if ( empty( $bt[ $i ]['file'] ) ) {
307
+ continue;
308
+ }
309
+
310
+ if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
311
+ $plugin_file = $bt[ $i ]['file'];
312
+ break;
313
+ }
314
+ }
315
+
316
+ if ( is_null( $plugin_file ) ) {
317
+ // Throw an error to the developer in case of some edge case dev environment.
318
+ wp_die(
319
+ 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.',
320
+ 'Error',
321
+ array( 'back_link' => true )
322
+ );
323
+ }
324
+
325
+ return $plugin_file;
326
+ }
327
+
328
+ require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
329
+
330
+ /**
331
+ * Update SDK newest version reference.
332
+ *
333
+ * @author Vova Feldman (@svovaf)
334
+ * @since 1.1.6
335
+ *
336
+ * @param string $sdk_relative_path
337
+ * @param string|bool $plugin_file
338
+ *
339
+ * @global $fs_active_plugins
340
+ */
341
+ function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
342
+ /**
343
+ * If there is a plugin running an older version of FS (1.2.1 or below), the `fs_update_sdk_newest_version()`
344
+ * function in the older version will be used instead of this one. But since the older version is using
345
+ * the `is_plugin_active` function to check if a plugin is active, passing the theme's `plugin_path` to the
346
+ * `is_plugin_active` function will return false since the path is not a plugin path, so `in_activation` will be
347
+ * `true` for theme modules and the upgrading of the SDK version to 1.2.2 or newer version will work fine.
348
+ *
349
+ * Future versions that will call this function will use the proper logic here instead of just relying on the
350
+ * `is_plugin_active` function to fail for themes.
351
+ *
352
+ * @author Leo Fajardo (@leorw)
353
+ * @since 1.2.2
354
+ */
355
+
356
+ global $fs_active_plugins;
357
+
358
+ $newest_sdk = $fs_active_plugins->plugins[ $sdk_relative_path ];
359
+
360
+ if ( ! is_string( $plugin_file ) ) {
361
+ $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
362
+ }
363
+
364
+ if ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) {
365
+ $in_activation = ( ! is_plugin_active( $plugin_file ) );
366
+ } else {
367
+ $theme = wp_get_theme();
368
+ $in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet );
369
+ }
370
+
371
+ $fs_active_plugins->newest = (object) array(
372
+ 'plugin_path' => $plugin_file,
373
+ 'sdk_path' => $sdk_relative_path,
374
+ 'version' => $newest_sdk->version,
375
+ 'in_activation' => $in_activation,
376
+ 'timestamp' => time(),
377
+ );
378
+
379
+ // Update DB with latest SDK version and path.
380
+ update_option( 'fs_active_plugins', $fs_active_plugins );
381
+ }
382
+
383
+ /**
384
+ * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
385
+ *
386
+ * @author Vova Feldman (@svovaf)
387
+ * @since 1.1.6
388
+ *
389
+ * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
390
+ *
391
+ * @global $fs_active_plugins
392
+ */
393
+ function fs_newest_sdk_plugin_first() {
394
+ global $fs_active_plugins;
395
+
396
+ /**
397
+ * @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins).
398
+ *
399
+ * @link https://github.com/Freemius/wordpress-sdk/issues/26
400
+ */
401
+ // $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
402
+
403
+ $active_plugins = get_option( 'active_plugins' );
404
+ $newest_sdk_plugin_key = array_search( $fs_active_plugins->newest->plugin_path, $active_plugins );
405
+ if ( 0 == $newest_sdk_plugin_key ) {
406
+ // if it's 0 it's the first plugin already, no need to continue
407
+ return false;
408
+ }
409
+
410
+ array_splice( $active_plugins, $newest_sdk_plugin_key, 1 );
411
+ array_unshift( $active_plugins, $fs_active_plugins->newest->plugin_path );
412
+ update_option( 'active_plugins', $active_plugins );
413
+
414
+ return true;
415
+ }
416
+
417
+ /**
418
+ * Go over all Freemius SDKs in the system and find and "remember"
419
+ * the newest SDK which is associated with an active plugin.
420
+ *
421
+ * @author Vova Feldman (@svovaf)
422
+ * @since 1.1.6
423
+ *
424
+ * @global $fs_active_plugins
425
+ */
426
+ function fs_fallback_to_newest_active_sdk() {
427
+ global $fs_active_plugins;
428
+
429
+ /**
430
+ * @var object $newest_sdk_data
431
+ */
432
+ $newest_sdk_data = null;
433
+ $newest_sdk_path = null;
434
+
435
+ foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
436
+ if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
437
+ ) {
438
+ // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
439
+ if ( 'plugin' === $data->type ) {
440
+ $is_module_active = is_plugin_active( $data->plugin_path );
441
+ } else {
442
+ $active_theme = wp_get_theme();
443
+ $is_module_active = ( $data->plugin_path === $active_theme->get_template() );
444
+ }
445
+
446
+ $is_sdk_exists = file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) );
447
+
448
+ if ( ! $is_module_active || ! $is_sdk_exists ) {
449
+ unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
450
+
451
+ // No need to store the data since it will be stored in fs_update_sdk_newest_version()
452
+ // or explicitly with update_option().
453
+ } else {
454
+ $newest_sdk_data = $data;
455
+ $newest_sdk_path = $sdk_relative_path;
456
+ }
457
+ }
458
+ }
459
+
460
+ if ( is_null( $newest_sdk_data ) ) {
461
+ // Couldn't find any SDK reference.
462
+ $fs_active_plugins = new stdClass();
463
+ update_option( 'fs_active_plugins', $fs_active_plugins );
464
+ } else {
465
+ fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
466
+ }
467
+ }
468
+
469
+ #region Actions / Filters -----------------------------------------
470
+
471
+ /**
472
+ * Apply filter for specific plugin.
473
+ *
474
+ * @author Vova Feldman (@svovaf)
475
+ * @since 1.0.9
476
+ *
477
+ * @param string $module_unique_affix Module's unique affix.
478
+ * @param string $tag The name of the filter hook.
479
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
480
+ *
481
+ * @return mixed The filtered value after all hooked functions are applied to it.
482
+ *
483
+ * @uses apply_filters()
484
+ */
485
+ function fs_apply_filter( $module_unique_affix, $tag, $value ) {
486
+ $args = func_get_args();
487
+
488
+ return call_user_func_array( 'apply_filters', array_merge(
489
+ array( "fs_{$tag}_{$module_unique_affix}" ),
490
+ array_slice( $args, 2 ) )
491
+ );
492
+ }
493
+
494
+ #endregion Actions / Filters -----------------------------------------
freemius/includes/fs-plugin-info-dialog.php ADDED
@@ -0,0 +1,948 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Plugin_Info_Dialog
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7
18
+ */
19
+ class FS_Plugin_Info_Dialog {
20
+ /**
21
+ * @since 1.1.7
22
+ *
23
+ * @var FS_Logger
24
+ */
25
+ private $_logger;
26
+
27
+ /**
28
+ * @since 1.1.7
29
+ *
30
+ * @var Freemius
31
+ */
32
+ private $_fs;
33
+
34
+ function __construct( Freemius $fs ) {
35
+ $this->_fs = $fs;
36
+
37
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $fs->get_slug() . '_info', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
38
+
39
+ // Remove default plugin information action.
40
+ remove_all_actions( 'install_plugins_pre_plugin-information' );
41
+
42
+ // Override action with custom plugins function for add-ons.
43
+ add_action( 'install_plugins_pre_plugin-information', array( &$this, 'install_plugin_information' ) );
44
+
45
+ // Override request for plugin information for Add-ons.
46
+ add_filter(
47
+ 'fs_plugins_api',
48
+ array( &$this, '_get_addon_info_filter' ),
49
+ WP_FS__DEFAULT_PRIORITY, 3 );
50
+ }
51
+
52
+ /**
53
+ * Generate add-on plugin information.
54
+ *
55
+ * @author Vova Feldman (@svovaf)
56
+ * @since 1.0.6
57
+ *
58
+ * @param array $data
59
+ * @param string $action
60
+ * @param object|null $args
61
+ *
62
+ * @return array|null
63
+ */
64
+ function _get_addon_info_filter( $data, $action = '', $args = null ) {
65
+ $this->_logger->entrance();
66
+
67
+ $parent_plugin_id = fs_request_get( 'parent_plugin_id', false );
68
+
69
+ if ( $this->_fs->get_id() != $parent_plugin_id ||
70
+ ( 'plugin_information' !== $action ) ||
71
+ ! isset( $args->slug )
72
+ ) {
73
+ return $data;
74
+ }
75
+
76
+ // Find add-on by slug.
77
+ $selected_addon = $this->_fs->get_addon_by_slug($args->slug, WP_FS__DEV_MODE);
78
+
79
+ if ( false === $selected_addon ) {
80
+ return $data;
81
+ }
82
+
83
+ if ( ! isset( $selected_addon->info ) ) {
84
+ // Setup some default info.
85
+ $selected_addon->info = new stdClass();
86
+ $selected_addon->info->selling_point_0 = 'Selling Point 1';
87
+ $selected_addon->info->selling_point_1 = 'Selling Point 2';
88
+ $selected_addon->info->selling_point_2 = 'Selling Point 3';
89
+ $selected_addon->info->description = '<p>Tell your users all about your add-on</p>';
90
+ }
91
+
92
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
93
+
94
+ $data = $args;
95
+
96
+ $is_free = true;
97
+
98
+ // Load add-on pricing.
99
+ $has_pricing = false;
100
+ $has_features = false;
101
+ $plans = false;
102
+
103
+ $result = $this->_fs->get_api_plugin_scope()->get( "/addons/{$selected_addon->id}/pricing.json?type=visible" );
104
+
105
+ if ( ! isset( $result->error ) ) {
106
+ $plans = $result->plans;
107
+
108
+ if ( is_array( $plans ) ) {
109
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
110
+ $pricing = isset( $plans[ $i ]->pricing ) ? $plans[ $i ]->pricing : null;
111
+ $features = isset( $plans[ $i ]->features ) ? $plans[ $i ]->features : null;
112
+
113
+ $plans[ $i ] = new FS_Plugin_Plan( $plans[ $i ] );
114
+ $plan = $plans[ $i ];
115
+
116
+ if ( is_array( $pricing ) && 0 < count( $pricing ) ) {
117
+ $is_free = false;
118
+
119
+ foreach ( $pricing as &$prices ) {
120
+ $prices = new FS_Pricing( $prices );
121
+ }
122
+
123
+ $plan->pricing = $pricing;
124
+
125
+ $has_pricing = true;
126
+ }
127
+
128
+ if ( is_array( $features ) && 0 < count( $features ) ) {
129
+ $plan->features = $features;
130
+
131
+ $has_features = true;
132
+ }
133
+ }
134
+ }
135
+ }
136
+
137
+ // Fetch latest version from Freemius.
138
+ $latest = $this->_fs->_fetch_latest_version( $selected_addon->id );
139
+
140
+ if ( ! $is_free ) {
141
+ // If paid add-on, then it's not on wordpress.org
142
+ $is_wordpress_org = false;
143
+ } else {
144
+ // If no versions found, then assume it's a .org plugin.
145
+ $is_wordpress_org = ( false === $latest );
146
+ }
147
+
148
+ if ( $is_wordpress_org ) {
149
+ $repo_data = FS_Plugin_Updater::_fetch_plugin_info_from_repository(
150
+ 'plugin_information', (object) array(
151
+ 'slug' => $selected_addon->slug,
152
+ 'is_ssl' => is_ssl(),
153
+ 'fields' => array(
154
+ 'banners' => true,
155
+ 'reviews' => true,
156
+ 'downloaded' => false,
157
+ 'active_installs' => true
158
+ )
159
+ ) );
160
+
161
+ if ( ! empty( $repo_data ) ) {
162
+ $data = $repo_data;
163
+ $data->wp_org_missing = false;
164
+ } else {
165
+ // Couldn't find plugin on .org.
166
+ $is_wordpress_org = false;
167
+
168
+ // Plugin is missing, not on Freemius nor WP.org.
169
+ $data->wp_org_missing = true;
170
+ }
171
+ }
172
+
173
+ if ( ! $is_wordpress_org ) {
174
+ $data->checkout_link = $this->_fs->checkout_url();
175
+ $data->fs_missing = ( false === $latest );
176
+
177
+ if ( $is_free ) {
178
+ $data->download_link = $this->_fs->_get_latest_download_local_url( $selected_addon->id );
179
+ }
180
+ }
181
+
182
+ if ( ! $is_wordpress_org ) {
183
+ // Fetch as much as possible info from local files.
184
+ $plugin_local_data = $this->_fs->get_plugin_data();
185
+ $data->name = $selected_addon->title;
186
+ $data->author = $plugin_local_data['Author'];
187
+ $view_vars = array( 'plugin' => $selected_addon );
188
+ $data->sections = array(
189
+ 'description' => fs_get_template( '/plugin-info/description.php', $view_vars ),
190
+ );
191
+
192
+ if ( ! empty( $selected_addon->info->banner_url ) ) {
193
+ $data->banners = array(
194
+ 'low' => $selected_addon->info->banner_url,
195
+ );
196
+ }
197
+
198
+ if ( ! empty( $selected_addon->info->screenshots ) ) {
199
+ $view_vars = array(
200
+ 'screenshots' => $selected_addon->info->screenshots,
201
+ 'plugin' => $selected_addon,
202
+ );
203
+ $data->sections['screenshots'] = fs_get_template( '/plugin-info/screenshots.php', $view_vars );
204
+ }
205
+
206
+ if ( is_object( $latest ) ) {
207
+ $data->version = $latest->version;
208
+ $data->last_updated = ! is_null( $latest->updated ) ? $latest->updated : $latest->created;
209
+ $data->requires = $latest->requires_platform_version;
210
+ $data->tested = $latest->tested_up_to_version;
211
+ } else {
212
+ // Add dummy version.
213
+ $data->version = '1.0.0';
214
+
215
+ // Add message to developer to deploy the plugin through Freemius.
216
+ }
217
+ }
218
+
219
+ if ( $has_pricing ) {
220
+ // Add plans to data.
221
+ $data->plans = $plans;
222
+
223
+ if ( $has_features ) {
224
+ $view_vars = array(
225
+ 'plans' => $plans,
226
+ 'plugin' => $selected_addon,
227
+ );
228
+ $data->sections['features'] = fs_get_template( '/plugin-info/features.php', $view_vars );
229
+ }
230
+ }
231
+
232
+ $data->is_paid = ! $is_free;
233
+ $data->external = ! $is_wordpress_org;
234
+
235
+ return $data;
236
+ }
237
+
238
+ /**
239
+ * @author Vova Feldman (@svovaf)
240
+ * @since 1.1.7
241
+ *
242
+ * @param FS_Plugin_Plan $plan
243
+ *
244
+ * @return string
245
+ */
246
+ private function get_billing_cycle( FS_Plugin_Plan $plan ) {
247
+ $billing_cycle = null;
248
+
249
+ if ( 1 === count( $plan->pricing ) && 1 == $plan->pricing[0]->licenses ) {
250
+ $pricing = $plan->pricing[0];
251
+ if ( isset( $pricing->annual_price ) ) {
252
+ $billing_cycle = 'annual';
253
+ } else if ( isset( $pricing->monthly_price ) ) {
254
+ $billing_cycle = 'monthly';
255
+ } else if ( isset( $pricing->lifetime_price ) ) {
256
+ $billing_cycle = 'lifetime';
257
+ }
258
+ } else {
259
+ foreach ( $plan->pricing as $pricing ) {
260
+ if ( isset( $pricing->annual_price ) ) {
261
+ $billing_cycle = 'annual';
262
+ } else if ( isset( $pricing->monthly_price ) ) {
263
+ $billing_cycle = 'monthly';
264
+ } else if ( isset( $pricing->lifetime_price ) ) {
265
+ $billing_cycle = 'lifetime';
266
+ }
267
+
268
+ if ( ! is_null( $billing_cycle ) ) {
269
+ break;
270
+ }
271
+ }
272
+ }
273
+
274
+ return $billing_cycle;
275
+ }
276
+
277
+ /**
278
+ * @author Vova Feldman (@svovaf)
279
+ * @since 1.1.7
280
+ *
281
+ * @param FS_Plugin_Plan $plan
282
+ * @param FS_Pricing $pricing
283
+ *
284
+ * @return float|null|string
285
+ */
286
+ private function get_price_tag( FS_Plugin_Plan $plan, FS_Pricing $pricing ) {
287
+ $price_tag = '';
288
+ if ( isset( $pricing->annual_price ) ) {
289
+ $price_tag = $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' );
290
+ } else if ( isset( $pricing->monthly_price ) ) {
291
+ $price_tag = $pricing->monthly_price . ' / mo';
292
+ } else if ( isset( $pricing->lifetime_price ) ) {
293
+ $price_tag = $pricing->lifetime_price;
294
+ }
295
+
296
+ return '$' . $price_tag;
297
+ }
298
+
299
+ /**
300
+ * @author Vova Feldman (@svovaf)
301
+ * @since 1.1.7
302
+ *
303
+ * @param object $api
304
+ * @param FS_Plugin_Plan|null $plan
305
+ *
306
+ * @return string
307
+ */
308
+ private function get_plugin_cta( $api, $plan = null ) {
309
+ if ( ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
310
+
311
+ if ( ! empty( $api->checkout_link ) && isset( $api->plans ) && 0 < is_array( $api->plans ) ) {
312
+ if ( is_null( $plan ) ) {
313
+ foreach ($api->plans as $p) {
314
+ if (!empty($p->pricing)) {
315
+ $plan = $p;
316
+ break;
317
+ }
318
+ }
319
+ }
320
+
321
+ return ' <a class="button button-primary right" href="' . $this->_fs->addon_checkout_url(
322
+ $plan->plugin_id,
323
+ $plan->pricing[0]->id,
324
+ $this->get_billing_cycle( $plan ),
325
+ $plan->has_trial()
326
+ ) . '" target="_parent">' .
327
+ ( ! $plan->has_trial() ?
328
+ fs_text( 'purchase', $api->slug ) :
329
+ sprintf( fs_text( 'start-free-x', $api->slug ), $this->get_trial_period( $plan ) )
330
+ ) .
331
+ '</a>';
332
+
333
+ // @todo Add Cart concept.
334
+ // echo ' <a class="button right" href="' . $status['url'] . '" target="_parent">' . __( 'Add to Cart' ) . '</a>';
335
+
336
+ } else if ( ! empty( $api->download_link ) ) {
337
+ $status = install_plugin_install_status( $api );
338
+
339
+ // Hosted on WordPress.org.
340
+ switch ( $status['status'] ) {
341
+ case 'install':
342
+ if ( $api->external &&
343
+ $this->_fs->is_org_repo_compliant() ||
344
+ ! $this->_fs->is_premium()
345
+ ) {
346
+ /**
347
+ * Add-on hosted on Freemius, not yet installed, and core
348
+ * plugin is wordpress.org compliant. Therefore, require a download
349
+ * since installing external plugins is not allowed by the wp.org guidelines.
350
+ */
351
+ return ' <a class="button button-primary right" href="' . esc_url( $api->download_link ) . '" target="_blank">' . fs_text( 'download-latest', $api->slug ) . '</a>';
352
+ } else {
353
+ if ( $status['url'] ) {
354
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . fs_text( 'install-now', $api->slug ) . '</a>';
355
+ }
356
+ }
357
+ break;
358
+ case 'update_available':
359
+ if ( $status['url'] ) {
360
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . fs_text( 'install-update-now', $api->slug ) . '</a>';
361
+ }
362
+ break;
363
+ case 'newer_installed':
364
+ return '<a class="button button-primary right disabled">' . sprintf( fs_text( 'newer-installed', $api->slug ), $status['version'] ) . '</a>';
365
+ break;
366
+ case 'latest_installed':
367
+ return '<a class="button button-primary right disabled">' . fs_text( 'latest-installed', $api->slug ) . '</a>';
368
+ break;
369
+ }
370
+
371
+ }
372
+ }
373
+
374
+ return '';
375
+ }
376
+
377
+ /**
378
+ * @author Vova Feldman (@svovaf)
379
+ * @since 1.1.7
380
+ *
381
+ * @param FS_Plugin_Plan $plan
382
+ *
383
+ * @return string
384
+ */
385
+ private function get_trial_period( $plan ) {
386
+ $trial_period = (int) $plan->trial_period;
387
+
388
+ switch ( $trial_period ) {
389
+ case 30:
390
+ return 'month';
391
+ case 60:
392
+ return '2 months';
393
+ default:
394
+ return "{$plan->trial_period} days";
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Display plugin information in dialog box form.
400
+ *
401
+ * Based on core install_plugin_information() function.
402
+ *
403
+ * @author Vova Feldman (@svovaf)
404
+ * @since 1.0.6
405
+ */
406
+ function install_plugin_information() {
407
+ global $tab;
408
+
409
+ if ( empty( $_REQUEST['plugin'] ) ) {
410
+ return;
411
+ }
412
+
413
+ $args = array(
414
+ 'slug' => wp_unslash( $_REQUEST['plugin'] ),
415
+ 'is_ssl' => is_ssl(),
416
+ 'fields' => array(
417
+ 'banners' => true,
418
+ 'reviews' => true,
419
+ 'downloaded' => false,
420
+ 'active_installs' => true
421
+ )
422
+ );
423
+
424
+ if ( is_array( $args ) ) {
425
+ $args = (object) $args;
426
+ }
427
+
428
+ if ( ! isset( $args->per_page ) ) {
429
+ $args->per_page = 24;
430
+ }
431
+
432
+ if ( ! isset( $args->locale ) ) {
433
+ $args->locale = get_locale();
434
+ }
435
+
436
+ $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args );
437
+
438
+ if ( is_wp_error( $api ) ) {
439
+ wp_die( $api );
440
+ }
441
+
442
+ $plugins_allowedtags = array(
443
+ 'a' => array(
444
+ 'href' => array(),
445
+ 'title' => array(),
446
+ 'target' => array(),
447
+ // Add image style for screenshots.
448
+ 'class' => array()
449
+ ),
450
+ 'style' => array(),
451
+ 'abbr' => array( 'title' => array() ),
452
+ 'acronym' => array( 'title' => array() ),
453
+ 'code' => array(),
454
+ 'pre' => array(),
455
+ 'em' => array(),
456
+ 'strong' => array(),
457
+ 'div' => array( 'class' => array() ),
458
+ 'span' => array( 'class' => array() ),
459
+ 'p' => array(),
460
+ 'ul' => array(),
461
+ 'ol' => array(),
462
+ 'li' => array( 'class' => array() ),
463
+ 'i' => array( 'class' => array() ),
464
+ 'h1' => array(),
465
+ 'h2' => array(),
466
+ 'h3' => array(),
467
+ 'h4' => array(),
468
+ 'h5' => array(),
469
+ 'h6' => array(),
470
+ 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
471
+ // 'table' => array(),
472
+ // 'td' => array(),
473
+ // 'tr' => array(),
474
+ // 'th' => array(),
475
+ // 'thead' => array(),
476
+ // 'tbody' => array(),
477
+ );
478
+
479
+ $plugins_section_titles = array(
480
+ 'description' => fs_text( 'description', $api->slug ),
481
+ 'installation' => fs_text( 'installation', $api->slug ),
482
+ 'faq' => fs_text( 'faq', $api->slug ),
483
+ 'screenshots' => fs_text( 'screenshots', $api->slug ),
484
+ 'changelog' => fs_text( 'changelog', $api->slug ),
485
+ 'reviews' => fs_text( 'reviews', $api->slug ),
486
+ 'other_notes' => fs_text( 'other_notes', $api->slug ),
487
+ );
488
+
489
+ // Sanitize HTML
490
+ // foreach ( (array) $api->sections as $section_name => $content ) {
491
+ // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
492
+ // }
493
+
494
+ foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
495
+ if ( isset( $api->$key ) ) {
496
+ $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
497
+ }
498
+ }
499
+
500
+ // Add after $api->slug is ready.
501
+ $plugins_section_titles['features'] = fs_text( 'features-and-pricing', $api->slug );
502
+
503
+ $_tab = esc_attr( $tab );
504
+
505
+ $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
506
+ if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
507
+ $section_titles = array_keys( (array) $api->sections );
508
+ $section = array_shift( $section_titles );
509
+ }
510
+
511
+ iframe_header( fs_text( 'plugin-install', $api->slug ) );
512
+
513
+ $_with_banner = '';
514
+
515
+ // var_dump($api->banners);
516
+ if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
517
+ $_with_banner = 'with-banner';
518
+ $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
519
+ $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
520
+ ?>
521
+ <style type="text/css">
522
+ #plugin-information-title.with-banner
523
+ {
524
+ background-image: url( <?php echo esc_url( $low ); ?> );
525
+ }
526
+
527
+ @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 )
528
+ {
529
+ #plugin-information-title.with-banner
530
+ {
531
+ background-image: url( <?php echo esc_url( $high ); ?> );
532
+ }
533
+ }
534
+ </style>
535
+ <?php
536
+ }
537
+
538
+ echo '<div id="plugin-information-scrollable">';
539
+ echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
540
+ echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
541
+
542
+ foreach ( (array) $api->sections as $section_name => $content ) {
543
+ if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
544
+ continue;
545
+ }
546
+
547
+ if ( isset( $plugins_section_titles[ $section_name ] ) ) {
548
+ $title = $plugins_section_titles[ $section_name ];
549
+ } else {
550
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
551
+ }
552
+
553
+ $class = ( $section_name === $section ) ? ' class="current"' : '';
554
+ $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) );
555
+ $href = esc_url( $href );
556
+ $san_section = esc_attr( $section_name );
557
+ echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
558
+ }
559
+
560
+ echo "</div>\n";
561
+
562
+ ?>
563
+ <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
564
+ <div class="fyi">
565
+ <?php if ( $api->is_paid ) : ?>
566
+ <?php if ( isset( $api->plans ) ) : ?>
567
+ <div class="plugin-information-pricing">
568
+ <?php foreach ( $api->plans as $plan ) : ?>
569
+ <?php
570
+ if ( empty( $plan->pricing ) ) {
571
+ continue;
572
+ }
573
+
574
+ /**
575
+ * @var FS_Plugin_Plan $plan
576
+ */
577
+ ?>
578
+ <?php $first_pricing = $plan->pricing[0] ?>
579
+ <?php $is_multi_cycle = $first_pricing->is_multi_cycle() ?>
580
+ <div class="fs-plan<?php if ( ! $is_multi_cycle ) {
581
+ echo ' fs-single-cycle';
582
+ } ?>" data-plan-id="<?php echo $plan->id ?>">
583
+ <h3 data-plan="<?php echo $plan->id ?>"><?php printf( fs_text( 'x-plan', $api->slug ), $plan->title ) ?></h3>
584
+ <?php $has_annual = $first_pricing->has_annual() ?>
585
+ <?php $has_monthly = $first_pricing->has_monthly() ?>
586
+ <div class="nav-tab-wrapper">
587
+ <?php $billing_cycles = array( 'monthly', 'annual', 'lifetime' ) ?>
588
+ <?php $i = 0;
589
+ foreach ( $billing_cycles as $cycle ) : ?>
590
+ <?php $prop = "{$cycle}_price";
591
+ if ( isset( $first_pricing->{$prop} ) ) : ?>
592
+ <?php $is_featured = ( 'annual' === $cycle && $is_multi_cycle ) ?>
593
+ <?php
594
+ $prices = array();
595
+ foreach ( $plan->pricing as $pricing ) {
596
+ if ( isset( $pricing->{$prop} ) ) {
597
+ $prices[] = array(
598
+ 'id' => $pricing->id,
599
+ 'licenses' => $pricing->licenses,
600
+ 'price' => $pricing->{$prop}
601
+ );
602
+ }
603
+ }
604
+ ?>
605
+ <a class="nav-tab" data-billing-cycle="<?php echo $cycle ?>"
606
+ data-pricing="<?php echo esc_attr( json_encode( $prices ) ) ?>">
607
+ <?php if ( $is_featured ) : ?>
608
+ <label>&#9733; <?php fs_echo( 'best', $api->slug ) ?> &#9733;</label>
609
+ <?php endif ?>
610
+ <?php fs_echo( $cycle, $api->slug ) ?>
611
+ </a>
612
+ <?php endif ?>
613
+ <?php $i ++; endforeach ?>
614
+ <?php wp_enqueue_script( 'jquery' ) ?>
615
+ <script type="text/javascript">
616
+ (function ($, undef) {
617
+ var
618
+ _formatBillingFrequency = function (cycle) {
619
+ switch (cycle) {
620
+ case 'monthly':
621
+ return '<?php printf(fs_text('billed-x', $api->slug), fs_text('monthly', $api->slug)) ?>';
622
+ case 'annual':
623
+ return '<?php printf(fs_text('billed-x', $api->slug), fs_text('annually', $api->slug)) ?>';
624
+ case 'lifetime':
625
+ return '<?php printf(fs_text('billed-x', $api->slug), fs_text('once', $api->slug)) ?>';
626
+ }
627
+ },
628
+ _formatLicensesTitle = function (pricing) {
629
+ switch (pricing.licenses) {
630
+ case 1:
631
+ return '<?php fs_echo( 'license-single-site', $api->slug ) ?>';
632
+ case null:
633
+ return '<?php fs_echo( 'license-unlimited', $api->slug ) ?>';
634
+ default:
635
+ return '<?php fs_echo( 'license-x-sites', $api->slug ) ?>'.replace('%s', pricing.licenses);
636
+ }
637
+ },
638
+ _formatPrice = function (pricing, cycle, multipleLicenses) {
639
+ if (undef === multipleLicenses)
640
+ multipleLicenses = true;
641
+
642
+ var priceCycle;
643
+ switch (cycle) {
644
+ case 'monthly':
645
+ priceCycle = ' / <?php fs_echo('mo', $api->slug) ?>';
646
+ break;
647
+ case 'lifetime':
648
+ priceCycle = '';
649
+ break;
650
+ case 'annual':
651
+ default:
652
+ priceCycle = ' / <?php fs_echo('year', $api->slug) ?>';
653
+ break;
654
+ }
655
+
656
+ if (!multipleLicenses && 1 == pricing.licenses) {
657
+ return '$' + pricing.price + priceCycle;
658
+ }
659
+
660
+ return _formatLicensesTitle(pricing) + ' - <var class="fs-price">$' + pricing.price + priceCycle + '</var>';
661
+ },
662
+ _checkoutUrl = function (plan, pricing, cycle) {
663
+ return '<?php echo esc_url_raw(remove_query_arg('billing_cycle', add_query_arg(array('plugin_id' => $plan->plugin_id), $api->checkout_link))) ?>' +
664
+ '&plan_id=' + plan +
665
+ '&pricing_id=' + pricing +
666
+ '&billing_cycle=' + cycle<?php if ($plan->has_trial()) { echo " + '&trial=true'"; }?>;
667
+ },
668
+ _updateCtaUrl = function (plan, pricing, cycle) {
669
+ $('.plugin-information-pricing .button, #plugin-information-footer .button').attr('href', _checkoutUrl(plan, pricing, cycle));
670
+ };
671
+
672
+ $(document).ready(function () {
673
+ var $plan = $('.plugin-information-pricing .fs-plan[data-plan-id=<?php echo $plan->id ?>]');
674
+ $plan.find('input[type=radio]').live('click', function () {
675
+ _updateCtaUrl(
676
+ $plan.attr('data-plan-id'),
677
+ $(this).val(),
678
+ $plan.find('.nav-tab-active').attr('data-billing-cycle')
679
+ );
680
+
681
+ $plan.find('.fs-trial-terms .fs-price').html(
682
+ $(this).parents('label').find('.fs-price').html()
683
+ );
684
+ });
685
+
686
+ $plan.find('.nav-tab').click(function () {
687
+ if ($(this).hasClass('nav-tab-active'))
688
+ return;
689
+
690
+ var $this = $(this),
691
+ billingCycle = $this.attr('data-billing-cycle'),
692
+ pricing = JSON.parse($this.attr('data-pricing')),
693
+ $pricesList = $this.parents('.fs-plan').find('.fs-pricing-body .fs-licenses'),
694
+ html = '';
695
+
696
+ // Un-select previously selected tab.
697
+ $plan.find('.nav-tab').removeClass('nav-tab-active');
698
+
699
+ // Select current tab.
700
+ $this.addClass('nav-tab-active');
701
+
702
+ // Render licenses prices.
703
+ if (1 == pricing.length) {
704
+ html = '<li><label><?php fs_echo( 'price', $api->slug ) ?>: ' + _formatPrice(pricing[0], billingCycle, false) + '</label></li>';
705
+ } else {
706
+ for (var i = 0; i < pricing.length; i++) {
707
+ html += '<li><label><input name="pricing-<?php echo $plan->id ?>" type="radio" value="' + pricing[i].id + '">' + _formatPrice(pricing[i], billingCycle) + '</label></li>';
708
+ }
709
+ }
710
+ $pricesList.html(html);
711
+
712
+ if (1 < pricing.length) {
713
+ // Select first license option.
714
+ $pricesList.find('li:first input').click();
715
+ }
716
+ else {
717
+ _updateCtaUrl(
718
+ $plan.attr('data-plan-id'),
719
+ pricing[0].id,
720
+ billingCycle
721
+ );
722
+ }
723
+
724
+ // Update billing frequency.
725
+ $plan.find('.fs-billing-frequency').html(_formatBillingFrequency(billingCycle));
726
+
727
+ if ('annual' === billingCycle) {
728
+ $plan.find('.fs-annual-discount').show();
729
+ } else {
730
+ $plan.find('.fs-annual-discount').hide();
731
+ }
732
+ });
733
+
734
+ <?php if ( $has_annual ) : ?>
735
+ // Select annual by default.
736
+ $plan.find('.nav-tab[data-billing-cycle=annual]').click();
737
+ <?php else : ?>
738
+ // Select first tab.
739
+ $plan.find('.nav-tab:first').click();
740
+ <?php endif ?>
741
+ });
742
+ }(jQuery));
743
+ </script>
744
+ </div>
745
+ <div class="fs-pricing-body">
746
+ <span class="fs-billing-frequency"></span>
747
+ <?php $annual_discount = ( $has_annual && $has_monthly ) ? $plan->pricing[0]->annual_discount_percentage() : 0 ?>
748
+ <?php if ( $annual_discount > 0 ) : ?>
749
+ <span
750
+ class="fs-annual-discount"><?php printf( fs_text( 'save-x', $api->slug ), $annual_discount . '%' ) ?></span>
751
+ <?php endif ?>
752
+ <ul class="fs-licenses">
753
+ </ul>
754
+ <?php echo $this->get_plugin_cta( $api, $plan ) ?>
755
+ <div style="clear:both"></div>
756
+ <?php if ( $plan->has_trial() ) : ?>
757
+ <?php $trial_period = $this->get_trial_period( $plan ) ?>
758
+ <ul class="fs-trial-terms">
759
+ <li>
760
+ <i class="dashicons dashicons-yes"></i><?php printf( fs_text( 'no-commitment-x', $api->slug ), $trial_period ) ?>
761
+ </li>
762
+ <li>
763
+ <i class="dashicons dashicons-yes"></i><?php printf( fs_text( 'after-x-pay-as-little-y', $api->slug ), $trial_period, '<var class="fs-price">' . $this->get_price_tag( $plan, $plan->pricing[0] ) . '</var>' ) ?>
764
+ </li>
765
+ </ul>
766
+ <?php endif ?>
767
+ </div>
768
+ </div>
769
+ </div>
770
+ <?php endforeach ?>
771
+ <?php endif ?>
772
+ <?php endif ?>
773
+ <div>
774
+ <h3><?php fs_echo( 'details', $api->slug ) ?></h3>
775
+ <ul>
776
+ <?php if ( ! empty( $api->version ) ) { ?>
777
+ <li><strong><?php fs_echo( 'version', $api->slug ); ?>:</strong> <?php echo $api->version; ?></li>
778
+ <?php
779
+ }
780
+ if ( ! empty( $api->author ) ) {
781
+ ?>
782
+ <li>
783
+ <strong><?php fs_echo( 'author:', $api->slug ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?>
784
+ </li>
785
+ <?php
786
+ }
787
+ if ( ! empty( $api->last_updated ) ) {
788
+ ?>
789
+ <li><strong><?php fs_echo( 'last-updated:', $api->slug ); ?></strong> <span
790
+ title="<?php echo $api->last_updated; ?>">
791
+ <?php printf( fs_text( 'x-ago', $api->slug ), human_time_diff( strtotime( $api->last_updated ) ) ); ?>
792
+ </span></li>
793
+ <?php
794
+ }
795
+ if ( ! empty( $api->requires ) ) {
796
+ ?>
797
+ <li>
798
+ <strong><?php fs_echo( 'requires-wordpress-version:', $api->slug ); ?></strong> <?php printf( fs_text( 'x-or-higher', $api->slug ), $api->requires ); ?>
799
+ </li>
800
+ <?php
801
+ }
802
+ if ( ! empty( $api->tested ) ) {
803
+ ?>
804
+ <li><strong><?php fs_echo( 'compatible-up-to:', $api->slug ); ?></strong> <?php echo $api->tested; ?>
805
+ </li>
806
+ <?php
807
+ }
808
+ if ( ! empty( $api->downloaded ) ) {
809
+ ?>
810
+ <li>
811
+ <strong><?php fs_echo( 'downloaded:', $api->slug ); ?></strong> <?php printf(
812
+ fs_text( ( 1 == $api->downloaded ) ? 'x-time' : 'x-times', $api->slug ),
813
+ number_format_i18n( $api->downloaded )
814
+ ); ?>
815
+ </li>
816
+ <?php
817
+ }
818
+ if ( ! empty( $api->slug ) && empty( $api->external ) ) {
819
+ ?>
820
+ <li><a target="_blank"
821
+ href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php fs_echo( 'wp-org-plugin-page', $api->slug ); ?> &#187;</a>
822
+ </li>
823
+ <?php
824
+ }
825
+ if ( ! empty( $api->homepage ) ) {
826
+ ?>
827
+ <li><a target="_blank"
828
+ href="<?php echo esc_url( $api->homepage ); ?>"><?php fs_echo( 'plugin-homepage', $api->slug ); ?> &#187;</a>
829
+ </li>
830
+ <?php
831
+ }
832
+ if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) {
833
+ ?>
834
+ <li><a target="_blank"
835
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php fs_echo( 'donate-to-plugin', $api->slug ); ?> &#187;</a>
836
+ </li>
837
+ <?php } ?>
838
+ </ul>
839
+ </div>
840
+ <?php if ( ! empty( $api->rating ) ) { ?>
841
+ <h3><?php fs_echo( 'average-rating', $api->slug ); ?></h3>
842
+ <?php wp_star_rating( array(
843
+ 'rating' => $api->rating,
844
+ 'type' => 'percent',
845
+ 'number' => $api->num_ratings
846
+ ) ); ?>
847
+ <small>(<?php printf(
848
+ fs_text( 'based-on-x', $api->slug ),
849
+ sprintf(
850
+ fs_text( ( 1 == $api->num_ratings ) ? 'x-rating' : 'x-ratings', $api->slug ),
851
+ number_format_i18n( $api->num_ratings )
852
+ ) ); ?>)</small>
853
+ <?php
854
+ }
855
+
856
+ if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
857
+ foreach ( $api->ratings as $key => $ratecount ) {
858
+ // Avoid div-by-zero.
859
+ $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
860
+ $stars_label = sprintf(
861
+ fs_text( ( 1 == $key ) ? 'x-star' : 'x-stars', $api->slug ),
862
+ number_format_i18n( $key )
863
+ );
864
+ ?>
865
+ <div class="counter-container">
866
+ <span class="counter-label"><a
867
+ href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>"
868
+ target="_blank"
869
+ title="<?php echo esc_attr( sprintf( fs_text('click-to-reviews', $api->slug), $stars_label) ) ?>"><?php echo $stars_label ?></a></span>
870
+ <span class="counter-back">
871
+ <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
872
+ </span>
873
+ <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span>
874
+ </div>
875
+ <?php
876
+ }
877
+ }
878
+ if ( ! empty( $api->contributors ) ) {
879
+ ?>
880
+ <h3><?php fs_echo( 'contributors', $api->slug ); ?></h3>
881
+ <ul class="contributors">
882
+ <?php
883
+ foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
884
+ if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
885
+ continue;
886
+ }
887
+ if ( empty( $contrib_username ) ) {
888
+ $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
889
+ }
890
+ $contrib_username = sanitize_user( $contrib_username );
891
+ if ( empty( $contrib_profile ) ) {
892
+ echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</li>";
893
+ } else {
894
+ echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</a></li>";
895
+ }
896
+ }
897
+ ?>
898
+ </ul>
899
+ <?php if ( ! empty( $api->donate_link ) ) { ?>
900
+ <a target="_blank"
901
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php fs_echo( 'donate-to-plugin', $api->slug ) ?> &#187;</a>
902
+ <?php } ?>
903
+ <?php } ?>
904
+ </div>
905
+ <div id="section-holder" class="wrap">
906
+ <?php
907
+ if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
908
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . fs_text( 'warning:', $api->slug ) . '</strong> ' . fs_text( 'not-tested-warning', $api->slug ) . '</p></div>';
909
+ } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
910
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . fs_text( 'warning:', $api->slug ) . '</strong> ' . fs_text( 'not-compatible-warning', $api->slug ) . '</p></div>';
911
+ }
912
+
913
+ foreach ( (array) $api->sections as $section_name => $content ) {
914
+ $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
915
+ $content = links_add_target( $content, '_blank' );
916
+
917
+ $san_section = esc_attr( $section_name );
918
+
919
+ $display = ( $section_name === $section ) ? 'block' : 'none';
920
+
921
+ if ( 'description' === $section_name &&
922
+ ( ( ! $api->external && $api->wp_org_missing ) ||
923
+ ( $api->external && $api->fs_missing ) )
924
+ ) {
925
+ $missing_notice = array(
926
+ 'type' => 'error',
927
+ 'id' => md5( microtime() ),
928
+ 'message' => fs_text( ( $api->is_paid ? 'paid-addon-not-deployed' : 'free-addon-not-deployed' ), $api->slug ),
929
+ );
930
+ fs_require_template( 'admin-notice.php', $missing_notice );
931
+ }
932
+ echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
933
+ echo $content;
934
+ echo "\t</div>\n";
935
+ }
936
+ echo "</div>\n";
937
+ echo "</div>\n";
938
+ echo "</div>\n"; // #plugin-information-scrollable
939
+ echo "<div id='$tab-footer'>\n";
940
+
941
+ echo $this->get_plugin_cta( $api );
942
+
943
+ echo "</div>\n";
944
+
945
+ iframe_footer();
946
+ exit;
947
+ }
948
+ }
freemius/includes/i18n.php ADDED
@@ -0,0 +1,549 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.1.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ require_once dirname( __FILE__ ) . '/l10n.php';
14
+
15
+ /**
16
+ * All strings can now be overridden.
17
+ *
18
+ * For example, if we want to override:
19
+ * 'you-are-step-away' => 'You are just one step away - %s',
20
+ *
21
+ * We can use the filter:
22
+ * fs_override_i18n( array(
23
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
24
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
25
+ * ), '{plugin_slug}' );
26
+ *
27
+ * Or with the Freemius instance:
28
+ *
29
+ * my_freemius->override_i18n( array(
30
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
31
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
32
+ * );
33
+ */
34
+ global $fs_text;
35
+
36
+ $fs_text = array(
37
+ 'account' => _fs_text( 'Account' ),
38
+ 'addon' => _fs_text( 'Add-On' ),
39
+ 'contact-us' => _fs_text( 'Contact Us' ),
40
+ 'contact-support' => _fs_text( 'Contact Support' ),
41
+ 'change-ownership' => _fs_text( 'Change Ownership' ),
42
+ 'support' => _fs_text( 'Support' ),
43
+ 'support-forum' => _fs_text( 'Support Forum' ),
44
+ 'add-ons' => _fs_text( 'Add-Ons' ),
45
+ 'upgrade' => _fs_x( 'Upgrade', 'verb' ),
46
+ 'awesome' => _fs_text( 'Awesome' ),
47
+ 'pricing' => _fs_x( 'Pricing', 'noun' ),
48
+ 'price' => _fs_x( 'Price', 'noun' ),
49
+ 'unlimited-updates' => _fs_text( 'Unlimited Updates' ),
50
+ 'downgrade' => _fs_x( 'Downgrade', 'verb' ),
51
+ 'cancel-subscription' => _fs_x( 'Cancel Subscription', 'verb' ),
52
+ 'cancel-trial' => _fs_text( 'Cancel Trial' ),
53
+ 'free-trial' => _fs_text( 'Free Trial' ),
54
+ 'start-free-x' => _fs_text( 'Start my free %s' ),
55
+ 'no-commitment-x' => _fs_text( 'No commitment for %s - cancel anytime' ),
56
+ 'after-x-pay-as-little-y' => _fs_text( 'After your free %s, pay as little as %s' ),
57
+ 'details' => _fs_text( 'Details' ),
58
+ 'account-details' => _fs_text( 'Account Details' ),
59
+ 'delete' => _fs_x( 'Delete', 'verb' ),
60
+ 'show' => _fs_x( 'Show', 'verb' ),
61
+ 'hide' => _fs_x( 'Hide', 'verb' ),
62
+ 'edit' => _fs_x( 'Edit', 'verb' ),
63
+ 'update' => _fs_x( 'Update', 'verb' ),
64
+ 'date' => _fs_text( 'Date' ),
65
+ 'amount' => _fs_text( 'Amount' ),
66
+ 'invoice' => _fs_text( 'Invoice' ),
67
+ 'billing' => _fs_text( 'Billing' ),
68
+ 'payments' => _fs_text( 'Payments' ),
69
+ 'delete-account' => _fs_text( 'Delete Account' ),
70
+ 'dismiss' => _fs_x( 'Dismiss', 'as close a window' ),
71
+ 'plan' => _fs_x( 'Plan', 'as product pricing plan' ),
72
+ 'change-plan' => _fs_text( 'Change Plan' ),
73
+ 'download-x-version' => _fs_x( 'Download %s Version', 'as download professional version' ),
74
+ 'download-x-version-now' => _fs_x( 'Download %s version now', 'as download professional version now' ),
75
+ 'download-latest' => _fs_x( 'Download Latest', 'as download latest version' ),
76
+ 'you-have-x-license' => _fs_x( 'You have a %s license.', 'E.g. you have a professional license.' ),
77
+ 'new' => _fs_text( 'New' ),
78
+ 'free' => _fs_text( 'Free' ),
79
+ 'trial' => _fs_x( 'Trial', 'as trial plan' ),
80
+ 'start-trial' => _fs_x( 'Start Trial', 'as starting a trial plan' ),
81
+ 'purchase' => _fs_x( 'Purchase', 'verb' ),
82
+ 'purchase-license' => _fs_text( 'Purchase License' ),
83
+ 'buy' => _fs_x( 'Buy', 'verb' ),
84
+ 'buy-license' => _fs_text( 'Buy License' ),
85
+ 'license-single-site' => _fs_text( 'Single Site License' ),
86
+ 'license-unlimited' => _fs_text( 'Unlimited Licenses' ),
87
+ 'license-x-sites' => _fs_text( 'Up to %s Sites' ),
88
+ 'renew-license-now' => _fs_text( '%sRenew your license now%s to access version %s features and support.' ),
89
+ 'ask-for-upgrade-email-address' => _fs_text( "Enter the email address you've used for the upgrade below and we will resend you the license key." ),
90
+ 'x-plan' => _fs_x( '%s Plan', 'e.g. Professional Plan' ),
91
+ 'you-are-step-away' => _fs_text( 'You are just one step away - %s' ),
92
+ 'activate-x-now' => _fs_x( 'Complete "%s" Activation Now',
93
+ '%s - plugin name. As complete "Jetpack" activation now' ),
94
+ 'few-plugin-tweaks' => _fs_text( 'We made a few tweaks to the %s, %s' ),
95
+ 'optin-x-now' => _fs_text( 'Opt in to make "%s" Better!' ),
96
+ 'error' => _fs_text( 'Error' ),
97
+ 'failed-finding-main-path' => _fs_text( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.' ),
98
+ #region Account
99
+
100
+ 'expiration' => _fs_x( 'Expiration', 'as expiration date' ),
101
+ 'license' => _fs_x( 'License', 'as software license' ),
102
+ 'not-verified' => _fs_text( 'not verified' ),
103
+ 'verify-email' => _fs_text( 'Verify Email' ),
104
+ 'expires-in' => _fs_x( 'Expires in %s', 'e.g. expires in 2 months' ),
105
+ 'renews-in' => _fs_x( 'Auto renews in %s', 'e.g. auto renews in 2 months' ),
106
+ 'no-expiration' => _fs_text( 'No expiration' ),
107
+ 'expired' => _fs_text( 'Expired' ),
108
+ 'cancelled' => _fs_text( 'Cancelled' ),
109
+ 'in-x' => _fs_x( 'In %s', 'e.g. In 2 hours' ),
110
+ 'x-ago' => _fs_x( '%s ago', 'e.g. 2 min ago' ),
111
+ /* translators: %s: Version number (e.g. 4.6 or higher) */
112
+ 'x-or-higher' => _fs_text( '%s or higher' ),
113
+ 'version' => _fs_x( 'Version', 'as plugin version' ),
114
+ 'name' => _fs_text( 'Name' ),
115
+ 'email' => _fs_text( 'Email' ),
116
+ 'email-address' => _fs_text( 'Email address' ),
117
+ 'verified' => _fs_text( 'Verified' ),
118
+ 'module' => _fs_text( 'Module' ),
119
+ 'module-type' => _fs_text( 'Module Type' ),
120
+ 'plugin' => _fs_text( 'Plugin' ),
121
+ 'plugins' => _fs_text( 'Plugins' ),
122
+ 'theme' => _fs_text( 'Theme' ),
123
+ 'themes' => _fs_text( 'Themes' ),
124
+ 'path' => _fs_x( 'Path', 'as file/folder path' ),
125
+ 'title' => _fs_text( 'Title' ),
126
+ 'free-version' => _fs_text( 'Free version' ),
127
+ 'premium-version' => _fs_text( 'Premium version' ),
128
+ 'slug' => _fs_x( 'Slug', 'as WP plugin slug' ),
129
+ 'id' => _fs_text( 'ID' ),
130
+ 'users' => _fs_text( 'Users' ),
131
+ 'module-installs' => _fs_text( '%s Installs' ),
132
+ 'sites' => _fs_x( 'Sites', 'like websites' ),
133
+ 'user-id' => _fs_text( 'User ID' ),
134
+ 'site-id' => _fs_text( 'Site ID' ),
135
+ 'public-key' => _fs_text( 'Public Key' ),
136
+ 'secret-key' => _fs_text( 'Secret Key' ),
137
+ 'no-secret' => _fs_x( 'No Secret', 'as secret encryption key missing' ),
138
+ 'no-id' => _fs_text( 'No ID' ),
139
+ 'sync-license' => _fs_x( 'Sync License', 'as synchronize license' ),
140
+ 'sync' => _fs_x( 'Sync', 'as synchronize' ),
141
+ 'activate-license' => _fs_text( 'Activate License' ),
142
+ 'activate-free-version' => _fs_text( 'Activate Free Version' ),
143
+ 'activate-license-message' => _fs_text( 'Please enter the license key that you received in the email right after the purchase:' ),
144
+ 'activating-license' => _fs_text( 'Activating license...' ),
145
+ 'change-license' => _fs_text( 'Change License' ),
146
+ 'update-license' => _fs_text( 'Update License' ),
147
+ 'deactivate-license' => _fs_text( 'Deactivate License' ),
148
+ 'activate' => _fs_text( 'Activate' ),
149
+ 'deactivate' => _fs_text( 'Deactivate' ),
150
+ 'skip-deactivate' => _fs_text( 'Skip & Deactivate' ),
151
+ 'skip-and-x' => _fs_text( 'Skip & %s' ),
152
+ 'no-deactivate' => _fs_text( 'No - just deactivate' ),
153
+ 'yes-do-your-thing' => _fs_text( 'Yes - do your thing' ),
154
+ 'active' => _fs_x( 'Active', 'active mode' ),
155
+ 'is-active' => _fs_x( 'Is Active', 'is active mode?' ),
156
+ 'install-now' => _fs_text( 'Install Now' ),
157
+ 'install-update-now' => _fs_text( 'Install Update Now' ),
158
+ 'more-information-about-x' => _fs_text( 'More information about %s' ),
159
+ 'localhost' => _fs_text( 'Localhost' ),
160
+ 'activate-x-plan' => _fs_x( 'Activate %s Plan', 'as activate Professional plan' ),
161
+ 'x-left' => _fs_x( '%s left', 'as 5 licenses left' ),
162
+ 'last-license' => _fs_text( 'Last license' ),
163
+ 'what-is-your-x' => _fs_text( 'What is your %s?' ),
164
+ 'activate-this-addon' => _fs_text( 'Activate this add-on' ),
165
+ 'deactivate-license-confirm' => _fs_text( 'Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?' ),
166
+ 'delete-account-x-confirm' => _fs_text( 'Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the "Cancel" button, and first "Downgrade" your account. Are you sure you would like to continue with the deletion?' ),
167
+ 'delete-account-confirm' => _fs_text( 'Deletion is not temporary. Only delete if you no longer want to use this %s anymore. Are you sure you would like to continue with the deletion?' ),
168
+ 'downgrade-x-confirm' => _fs_text( 'Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s.' ),
169
+ 'cancel-trial-confirm' => _fs_text( 'Cancelling the trial will immediately block access to all premium features. Are you sure?' ),
170
+ 'after-downgrade-non-blocking' => _fs_text( 'You can still enjoy all %s features but you will not have access to %s updates and support.' ),
171
+ 'after-downgrade-blocking' => _fs_text( 'Once your license expires you can still use the Free version but you will NOT have access to the %s features.' ),
172
+ 'proceed-confirmation' => _fs_text( 'Are you sure you want to proceed?' ),
173
+ #endregion Account
174
+
175
+ 'add-ons-for-x' => _fs_text( 'Add Ons for %s' ),
176
+ 'add-ons-missing' => _fs_text( 'We could\'nt load the add-ons list. It\'s probably an issue on our side, please try to come back in few minutes.' ),
177
+ #region Plugin Deactivation
178
+ 'anonymous-feedback' => _fs_text( 'Anonymous feedback' ),
179
+ 'quick-feedback' => _fs_text( 'Quick feedback' ),
180
+ 'deactivation-share-reason' => _fs_text( 'If you have a moment, please let us know why you are %s' ),
181
+ 'deactivating' => _fs_text( 'deactivating' ),
182
+ 'deactivation' => _fs_text( 'Deactivation' ),
183
+ 'theme-switch' => _fs_text( 'Theme Switch' ),
184
+ 'switching' => _fs_text( 'switching' ),
185
+ 'switch' => _fs_text( 'Switch' ),
186
+ 'activate-x' => _fs_text( 'Activate %s' ),
187
+ 'deactivation-modal-button-confirm' => _fs_text( 'Yes - %s' ),
188
+ 'deactivation-modal-button-submit' => _fs_text( 'Submit & %s' ),
189
+ 'cancel' => _fs_text( 'Cancel' ),
190
+ 'reason-no-longer-needed' => _fs_text( 'I no longer need the %s' ),
191
+ 'reason-found-a-better-plugin' => _fs_text( 'I found a better %s' ),
192
+ 'reason-needed-for-a-short-period' => _fs_text( 'I only needed the %s for a short period' ),
193
+ 'reason-broke-my-site' => _fs_text( 'The %s broke my site' ),
194
+ 'reason-suddenly-stopped-working' => _fs_text( 'The %s suddenly stopped working' ),
195
+ 'reason-cant-pay-anymore' => _fs_text( "I can't pay for it anymore" ),
196
+ 'reason-temporary-deactivation' => _fs_text( "It's a temporary deactivation. I'm just debugging an issue." ),
197
+ 'reason-temporary-x' => _fs_text( "It's a temporary %s. I'm just debugging an issue." ),
198
+ 'reason-other' => _fs_x( 'Other',
199
+ 'the text of the "other" reason for deactivating the module that is shown in the modal box.' ),
200
+ 'ask-for-reason-message' => _fs_text( 'Kindly tell us the reason so we can improve.' ),
201
+ 'placeholder-plugin-name' => _fs_text( "What's the %s's name?" ),
202
+ 'placeholder-comfortable-price' => _fs_text( 'What price would you feel comfortable paying?' ),
203
+ 'reason-couldnt-make-it-work' => _fs_text( "I couldn't understand how to make it work" ),
204
+ 'reason-great-but-need-specific-feature' => _fs_text( "The %s is great, but I need specific feature that you don't support" ),
205
+ 'reason-not-working' => _fs_text( 'The %s is not working' ),
206
+ 'reason-not-what-i-was-looking-for' => _fs_text( "It's not what I was looking for" ),
207
+ 'reason-didnt-work-as-expected' => _fs_text( "The %s didn't work as expected" ),
208
+ 'placeholder-feature' => _fs_text( 'What feature?' ),
209
+ 'placeholder-share-what-didnt-work' => _fs_text( "Kindly share what didn't work so we can fix it for future users..." ),
210
+ 'placeholder-what-youve-been-looking-for' => _fs_text( "What you've been looking for?" ),
211
+ 'placeholder-what-did-you-expect' => _fs_text( "What did you expect?" ),
212
+ 'reason-didnt-work' => _fs_text( "The %s didn't work" ),
213
+ 'reason-dont-like-to-share-my-information' => _fs_text( "I don't like to share my information with you" ),
214
+ 'dont-have-to-share-any-data' => _fs_text( "You might have missed it, but you don't have to share any data and can just %s the opt-in." ),
215
+ #endregion Plugin Deactivation
216
+
217
+ #region Connect
218
+ 'hey-x' => _fs_x( 'Hey %s,', 'greeting' ),
219
+ 'thanks-x' => _fs_x( 'Thanks %s!', 'a greeting. E.g. Thanks John!' ),
220
+ 'connect-message' => _fs_text( 'Never miss an important update - opt in to our security and feature updates notifications, and non-sensitive diagnostic tracking with %4$s.' ),
221
+ 'connect-message_on-update' => _fs_text( 'Please help us improve %1$s! If you opt in, some data about your usage of %1$s will be sent to %4$s. If you skip this, that\'s okay! %1$s will still work just fine.' ),
222
+ 'pending-activation-message' => _fs_text( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s.' ),
223
+ 'complete-the-install' => _fs_text( 'complete the install' ),
224
+ 'start-the-trial' => _fs_text( 'start the trial' ),
225
+ 'thanks-for-purchasing' => _fs_text( 'Thanks for purchasing %s! To get started, please enter your license key:' ),
226
+ 'license-sync-disclaimer' => _fs_text( 'The %1$s will be periodically sending data to %2$s to check for security and feature updates, and verify the validity of your license.' ),
227
+ 'what-permissions' => _fs_text( 'What permissions are being granted?' ),
228
+ 'permissions-profile' => _fs_text( 'Your Profile Overview' ),
229
+ 'permissions-profile_desc' => _fs_text( 'Name and email address' ),
230
+ 'permissions-site' => _fs_text( 'Your Site Overview' ),
231
+ 'permissions-site_desc' => _fs_text( 'Site URL, WP version, PHP info, plugins & themes' ),
232
+ 'permissions-events' => _fs_text( 'Current %s Events' ),
233
+ 'permissions-events_desc' => _fs_text( 'Activation, deactivation and uninstall' ),
234
+ 'permissions-plugins_themes' => _fs_text( 'Plugins & Themes' ),
235
+ 'permissions-plugins_themes_desc' => _fs_text( 'Titles, versions and state.' ),
236
+ 'permissions-admin-notices' => _fs_text( 'Admin Notices' ),
237
+ 'permissions-newsletter' => _fs_text( 'Newsletter' ),
238
+ 'permissions-newsletter_desc' => _fs_text( 'Updates, announcements, marketing, no spam' ),
239
+ 'privacy-policy' => _fs_text( 'Privacy Policy' ),
240
+ 'tos' => _fs_text( 'Terms of Service' ),
241
+ 'activating' => _fs_x( 'Activating', 'as activating plugin' ),
242
+ 'sending-email' => _fs_x( 'Sending email', 'as in the process of sending an email' ),
243
+ 'opt-in-connect' => _fs_x( 'Allow & Continue', 'button label' ),
244
+ 'agree-activate-license' => _fs_x( 'Agree & Activate License', 'button label' ),
245
+ 'skip' => _fs_x( 'Skip', 'verb' ),
246
+ 'click-here-to-use-plugin-anonymously' => _fs_text( 'Click here to use the plugin anonymously' ),
247
+ 'resend-activation-email' => _fs_text( 'Re-send activation email' ),
248
+ 'license-key' => _fs_text( 'License key' ),
249
+ 'send-license-key' => _fs_text( 'Send License Key' ),
250
+ 'sending-license-key' => _fs_text( 'Sending license key' ),
251
+ 'have-license-key' => _fs_text( 'Have a license key?' ),
252
+ 'dont-have-license-key' => _fs_text( 'Don\'t have a license key?' ),
253
+ 'cant-find-license-key' => _fs_text( "Can't find your license key?" ),
254
+ 'email-not-found' => _fs_text( "We couldn't find your email address in the system, are you sure it's the right address?" ),
255
+ 'no-active-licenses' => _fs_text( "We can't see any active licenses associated with that email address, are you sure it's the right address?" ),
256
+ 'opt-in' => _fs_text( 'Opt In' ),
257
+ 'opt-out' => _fs_text( 'Opt Out' ),
258
+ 'opt-out-cancel' => _fs_text( 'On second thought - I want to continue helping' ),
259
+ 'opting-out' => _fs_text( 'Opting out...' ),
260
+ 'opting-in' => _fs_text( 'Opting in...' ),
261
+ 'opt-out-message-appreciation' => _fs_text( 'We appreciate your help in making the %s better by letting us track some usage data.' ),
262
+ 'opt-out-message-usage-tracking' => _fs_text( "Usage tracking is done in the name of making %s better. Making a better user experience, prioritizing new features, and more good things. We'd really appreciate if you'll reconsider letting us continue with the tracking." ),
263
+ 'opt-out-message-clicking-opt-out' => _fs_text( 'By clicking "Opt Out", we will no longer be sending any data from %s to %s.' ),
264
+ #endregion Connect
265
+
266
+ #region Screenshots
267
+ 'screenshots' => _fs_text( 'Screenshots' ),
268
+ 'view-full-size-x' => _fs_text( 'Click to view full-size screenshot %d' ),
269
+ #endregion Screenshots
270
+
271
+ #region Debug
272
+ 'freemius-debug' => _fs_text( 'Freemius Debug' ),
273
+ 'on' => _fs_x( 'On', 'as turned on' ),
274
+ 'off' => _fs_x( 'Off', 'as turned off' ),
275
+ 'debugging' => _fs_x( 'Debugging', 'as code debugging' ),
276
+ 'freemius-state' => _fs_text( 'Freemius State' ),
277
+ 'connected' => _fs_x( 'Connected', 'as connection was successful' ),
278
+ 'blocked' => _fs_x( 'Blocked', 'as connection blocked' ),
279
+ 'api' => _fs_x( 'API', 'as application program interface' ),
280
+ 'sdk' => _fs_x( 'SDK', 'as software development kit versions' ),
281
+ 'sdk-versions' => _fs_x( 'SDK Versions', 'as software development kit versions' ),
282
+ 'plugin-path' => _fs_x( 'Plugin Path', 'as plugin folder path' ),
283
+ 'sdk-path' => _fs_x( 'SDK Path', 'as sdk path' ),
284
+ 'addons-of-x' => _fs_text( 'Add Ons of Plugin %s' ),
285
+ 'delete-all-confirm' => _fs_text( 'Are you sure you want to delete all Freemius data?' ),
286
+ 'actions' => _fs_text( 'Actions' ),
287
+ 'delete-all-accounts' => _fs_text( 'Delete All Accounts' ),
288
+ 'start-fresh' => _fs_text( 'Start Fresh' ),
289
+ 'clear-api-cache' => _fs_text( 'Clear API Cache' ),
290
+ 'sync-data-from-server' => _fs_text( 'Sync Data From Server' ),
291
+ 'scheduled-crons' => _fs_text( 'Scheduled Crons' ),
292
+ 'cron-type' => _fs_text( 'Cron Type' ),
293
+ 'plugins-themes-sync' => _fs_text( 'Plugins & Themes Sync' ),
294
+ 'module-licenses' => _fs_text( '%s Licenses' ),
295
+ 'debug-log' => _fs_text( 'Debug Log' ),
296
+ 'all' => _fs_text( 'All' ),
297
+ 'file' => _fs_text( 'File' ),
298
+ 'function' => _fs_text( 'Function' ),
299
+ 'process-id' => _fs_text( 'Process ID' ),
300
+ 'logger' => _fs_text( 'Logger' ),
301
+ 'message' => _fs_text( 'Message' ),
302
+ 'download' => _fs_text( 'Download' ),
303
+ 'filter' => _fs_text( 'Filter' ),
304
+ 'type' => _fs_text( 'Type' ),
305
+ 'all-types' => _fs_text( 'All Types' ),
306
+ 'all-requests' => _fs_text( 'All Requests' ),
307
+ #endregion Debug
308
+
309
+ #region Expressions
310
+ 'congrats' => _fs_x( 'Congrats', 'as congratulations' ),
311
+ 'oops' => _fs_x( 'Oops', 'exclamation' ),
312
+ 'yee-haw' => _fs_x( 'Yee-haw', 'interjection expressing joy or exuberance' ),
313
+ 'woot' => _fs_x( 'W00t',
314
+ '(especially in electronic communication) used to express elation, enthusiasm, or triumph.' ),
315
+ 'right-on' => _fs_x( 'Right on', 'a positive response' ),
316
+ 'hmm' => _fs_x( 'Hmm',
317
+ 'something somebody says when they are thinking about what you have just said. ' ),
318
+ 'ok' => _fs_text( 'O.K' ),
319
+ 'hey' => _fs_x( 'Hey', 'exclamation' ),
320
+ 'heads-up' => _fs_x( 'Heads up',
321
+ 'advance notice of something that will need attention.' ),
322
+ #endregion Expressions
323
+
324
+ #region Admin Notices
325
+ 'you-have-latest' => _fs_text( 'Seems like you got the latest release.' ),
326
+ 'you-are-good' => _fs_text( 'You are all good!' ),
327
+ 'user-exist-message' => _fs_text( 'Sorry, we could not complete the email update. Another user with the same email is already registered.' ),
328
+ 'user-exist-message_ownership' => _fs_text( 'If you would like to give up the ownership of the %s\'s account to %s click the Change Ownership button.' ),
329
+ 'email-updated-message' => _fs_text( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.' ),
330
+ 'name-updated-message' => _fs_text( 'Your name was successfully updated.' ),
331
+ 'x-updated' => _fs_text( 'You have successfully updated your %s.' ),
332
+ 'name-update-failed-message' => _fs_text( 'Please provide your full name.' ),
333
+ 'verification-email-sent-message' => _fs_text( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.' ),
334
+ 'addons-info-external-message' => _fs_text( 'Just letting you know that the add-ons information of %s is being pulled from an external server.' ),
335
+ 'no-cc-required' => _fs_text( 'No credit card required' ),
336
+ 'premium-activated-message' => _fs_text( 'Premium %s version was successfully activated.' ),
337
+ 'successful-version-upgrade-message' => _fs_text( 'The upgrade of %s was successfully completed.' ),
338
+ 'activation-with-plan-x-message' => _fs_text( 'Your account was successfully activated with the %s plan.' ),
339
+ 'download-latest-x-version-now' => _fs_text( 'Download the latest %s version now' ),
340
+ 'follow-steps-to-complete-upgrade' => _fs_text( 'Please follow these steps to complete the upgrade' ),
341
+ 'download-latest-x-version' => _fs_text( 'Download the latest %s version' ),
342
+ 'download-latest-version' => _fs_text( 'Download the latest version' ),
343
+ 'deactivate-free-version' => _fs_text( 'Deactivate the free version' ),
344
+ 'upload-and-activate' => _fs_text( 'Upload and activate the downloaded version' ),
345
+ 'howto-upload-activate' => _fs_text( 'How to upload and activate?' ),
346
+ 'addon-successfully-purchased-message' => _fs_x( '%s Add-on was successfully purchased.',
347
+ '%s - product name, e.g. Facebook add-on was successfully...' ),
348
+ 'addon-successfully-upgraded-message' => _fs_text( 'Your %s Add-on plan was successfully upgraded.' ),
349
+ 'email-verified-message' => _fs_text( 'Your email has been successfully verified - you are AWESOME!' ),
350
+ 'plan-upgraded-message' => _fs_text( 'Your plan was successfully upgraded.' ),
351
+ 'plan-changed-to-x-message' => _fs_text( 'Your plan was successfully changed to %s.' ),
352
+ 'license-expired-blocking-message' => _fs_text( 'Your license has expired. You can still continue using the free %s forever.' ),
353
+ 'license-cancelled' => _fs_text( 'Your license has been cancelled. If you think it\'s a mistake, please contact support.' ),
354
+ 'trial-started-message' => _fs_text( 'Your trial has been successfully started.' ),
355
+ 'license-activated-message' => _fs_text( 'Your license was successfully activated.' ),
356
+ 'no-active-license-message' => _fs_text( 'It looks like your site currently doesn\'t have an active license.' ),
357
+ 'license-deactivation-message' => _fs_text( 'Your license was successfully deactivated, you are back to the %s plan.' ),
358
+ 'license-deactivation-failed-message' => _fs_text( 'It looks like the license deactivation failed.' ),
359
+ 'license-activation-failed-message' => _fs_text( 'It looks like the license could not be activated.' ),
360
+ 'server-error-message' => _fs_text( 'Error received from the server:' ),
361
+ 'trial-expired-message' => _fs_text( 'Your trial has expired. You can still continue using all our free features.' ),
362
+ 'plan-x-downgraded-message' => _fs_text( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.' ),
363
+ 'plan-downgraded-failure-message' => _fs_text( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.' ),
364
+ 'trial-cancel-no-trial-message' => _fs_text( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)' ),
365
+ 'trial-cancel-message' => _fs_text( 'Your %s free trial was successfully cancelled.' ),
366
+ 'version-x-released' => _fs_x( 'Version %s was released.', '%s - numeric version number' ),
367
+ 'please-download-x' => _fs_text( 'Please download %s.' ),
368
+ 'latest-x-version' => _fs_x( 'the latest %s version here',
369
+ '%s - plan name, as the latest professional version here' ),
370
+ 'trial-x-promotion-message' => _fs_text( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.' ),
371
+ 'start-free-trial' => _fs_x( 'Start free trial', 'call to action' ),
372
+ 'starting-trial' => _fs_text( 'Starting trial' ),
373
+ 'please-wait' => _fs_text( 'Please wait' ),
374
+ 'trial-cancel-failure-message' => _fs_text( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.' ),
375
+ 'trial-utilized' => _fs_text( 'You already utilized a trial before.' ),
376
+ 'in-trial-mode' => _fs_text( 'You are already running the %s in a trial mode.' ),
377
+ 'trial-plan-x-not-exist' => _fs_text( 'Plan %s do not exist, therefore, can\'t start a trial.' ),
378
+ 'plan-x-no-trial' => _fs_text( 'Plan %s does not support a trial period.' ),
379
+ 'no-trials' => _fs_text( 'None of the %s\'s plans supports a trial period.' ),
380
+ 'unexpected-api-error' => _fs_text( 'Unexpected API error. Please contact the %s\'s author with the following error.' ),
381
+ 'no-commitment-for-x-days' => _fs_text( 'No commitment for %s days - cancel anytime!' ),
382
+ 'license-expired-non-blocking-message' => _fs_text( 'Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.' ),
383
+ 'could-not-activate-x' => _fs_text( 'Couldn\'t activate %s.' ),
384
+ 'contact-us-with-error-message' => _fs_text( 'Please contact us with the following message:' ),
385
+ 'plan-did-not-change-message' => _fs_text( 'It looks like you are still on the %s plan. If you did upgrade or change your plan, it\'s probably an issue on our side - sorry.' ),
386
+ 'contact-us-here' => _fs_text( 'Please contact us here' ),
387
+ 'plan-did-not-change-email-message' => _fs_text( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.' ),
388
+ #endregion Admin Notices
389
+ #region Connectivity Issues
390
+ 'connectivity-test-fails-message' => _fs_text( 'From unknown reason, the API connectivity test failed.' ),
391
+ 'connectivity-test-maybe-temporary' => _fs_text( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?' ),
392
+ 'curl-missing-message' => _fs_text( 'We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server.' ),
393
+ 'curl-disabled-methods' => _fs_text( 'Disabled method(s):' ),
394
+ 'cloudflare-blocks-connection-message' => _fs_text( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.' ),
395
+ 'x-requires-access-to-api' => _fs_x( '%s requires an access to our API.',
396
+ 'as pluginX requires an access to our API' ),
397
+ 'squid-blocks-connection-message' => _fs_text( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.' ),
398
+ 'squid-no-clue-title' => _fs_text( 'I don\'t know what is Squid or ACL, help me!' ),
399
+ 'squid-no-clue-desc' => _fs_text( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.' ),
400
+ 'sysadmin-title' => _fs_text( 'I\'m a system administrator' ),
401
+ 'squid-sysadmin-desc' => _fs_text( 'Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again.' ),
402
+ 'curl-missing-no-clue-title' => _fs_text( 'I don\'t know what is cURL or how to install it, help me!' ),
403
+ 'curl-missing-no-clue-desc' => _fs_text( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.' ),
404
+ 'curl-missing-sysadmin-desc' => _fs_text( 'Great, please install cURL and enable it in your php.ini file. In addition, search for the \'disable_functions\' directive in your php.ini file and remove any disabled methods starting with \'curl_\'. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the %s and reactivate it back again.' ),
405
+ 'happy-to-resolve-issue-asap' => _fs_text( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.' ),
406
+ 'contact-support-before-deactivation' => _fs_text( 'Sorry for the inconvenience and we are here to help if you give us a chance.' ),
407
+ 'fix-issue-title' => _fs_text( 'Yes - I\'m giving you a chance to fix it' ),
408
+ 'fix-issue-desc' => _fs_text( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.' ),
409
+ 'install-previous-title' => _fs_text( 'Let\'s try your previous version' ),
410
+ 'install-previous-desc' => _fs_text( 'Uninstall this version and install the previous one.' ),
411
+ 'deactivate-plugin-title' => _fs_text( 'That\'s exhausting, please deactivate' ),
412
+ 'deactivate-plugin-desc' => _fs_text( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.' ),
413
+ 'fix-request-sent-message' => _fs_text( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.' ),
414
+ 'server-blocking-access' => _fs_x( 'Your server is blocking the access to Freemius\' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s',
415
+ '%1s - plugin title, %2s - API domain' ),
416
+ 'wrong-authentication-param-message' => _fs_text( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.' ),
417
+ #endregion Connectivity Issues
418
+ #region Change Owner
419
+ 'change-owner-request-sent-x' => _fs_text( 'Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder.' ),
420
+ 'change-owner-request_owner-confirmed' => _fs_text( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.' ),
421
+ 'change-owner-request_candidate-confirmed' => _fs_text( '%s is the new owner of the account.' ),
422
+ #endregion Change Owner
423
+ 'addon-x-cannot-run-without-y' => _fs_x( '%s cannot run without %s.',
424
+ 'addonX cannot run without pluginY' ),
425
+ 'addon-x-cannot-run-without-parent' => _fs_x( '%s cannot run without the plugin.', 'addonX cannot run...' ),
426
+ 'plugin-x-activation-message' => _fs_x( '%s activation was successfully completed.',
427
+ 'pluginX activation was successfully...' ),
428
+ 'features-and-pricing' => _fs_x( 'Features & Pricing', 'Plugin installer section title' ),
429
+ 'free-addon-not-deployed' => _fs_text( 'Add-on must be deployed to WordPress.org or Freemius.' ),
430
+ 'paid-addon-not-deployed' => _fs_text( 'Paid add-on must be deployed to Freemius.' ),
431
+ #--------------------------------------------------------------------------------
432
+ #region Add-On Licensing
433
+ #--------------------------------------------------------------------------------
434
+ 'addon-no-license-message' => _fs_text( '%s is a premium only add-on. You have to purchase a license first before activating the plugin.' ),
435
+ 'addon-trial-cancelled-message' => _fs_text( '%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you\'ll have to purchase a license.' ),
436
+ #endregion
437
+ #--------------------------------------------------------------------------------
438
+ #region Billing Cycles
439
+ #--------------------------------------------------------------------------------
440
+ 'monthly' => _fs_x( 'Monthly', 'as every month' ),
441
+ 'mo' => _fs_x( 'mo', 'as monthly period' ),
442
+ 'annual' => _fs_x( 'Annual', 'as once a year' ),
443
+ 'annually' => _fs_x( 'Annually', 'as once a year' ),
444
+ 'once' => _fs_x( 'Once', 'as once a year' ),
445
+ 'year' => _fs_x( 'year', 'as annual period' ),
446
+ 'lifetime' => _fs_text( 'Lifetime' ),
447
+ 'best' => _fs_x( 'Best', 'e.g. the best product' ),
448
+ 'billed-x' => _fs_x( 'Billed %s', 'e.g. billed monthly' ),
449
+ 'save-x' => _fs_x( 'Save %s', 'as a discount of $5 or 10%' ),
450
+ #endregion Billing Cycles
451
+ 'view-details' => _fs_text( 'View details' ),
452
+ #--------------------------------------------------------------------------------
453
+ #region Trial
454
+ #--------------------------------------------------------------------------------
455
+ 'approve-start-trial' => _fs_x( 'Approve & Start Trial', 'button label' ),
456
+ /* translators: %1$s: Number of trial days; %2$s: Plan name; */
457
+ 'start-trial-prompt-header' => _fs_text( 'You are 1-click away from starting your %1$s-day free trial of the %2$s plan.' ),
458
+ /* translators: %s: Link to freemius.com */
459
+ 'start-trial-prompt-message' => _fs_text( 'For compliance with the WordPress.org guidelines, before we start the trial we ask that you opt in with your user and non-sensitive site information, allowing the %s to periodically send data to %s to check for version updates and to validate your trial.' ),
460
+
461
+ #endregion
462
+ #--------------------------------------------------------------------------------
463
+ #region Billing Details
464
+ #--------------------------------------------------------------------------------
465
+ 'business-name' => _fs_text( 'Business name' ),
466
+ 'tax-vat-id' => _fs_text( 'Tax / VAT ID' ),
467
+ 'address-line-n' => _fs_text( 'Address Line %d' ),
468
+ 'country' => _fs_text( 'Country' ),
469
+ 'select-country' => _fs_text( 'Select Country' ),
470
+ 'city' => _fs_text( 'City' ),
471
+ 'town' => _fs_text( 'Town' ),
472
+ 'state' => _fs_text( 'State' ),
473
+ 'province' => _fs_text( 'Province' ),
474
+ 'zip-postal-code' => _fs_text( 'ZIP / Postal Code' ),
475
+ #endregion
476
+ #--------------------------------------------------------------------------------
477
+ #region Module Installation
478
+ #--------------------------------------------------------------------------------
479
+ 'installing-plugin-x' => _fs_text( 'Installing plugin: %s' ),
480
+ 'auto-installation' => _fs_text( 'Automatic Installation' ),
481
+ /* translators: %s: Number of seconds */
482
+ 'x-sec' => _fs_text( '%s sec' ),
483
+ 'installing-in-n' => _fs_text( 'An automated download and installation of %s (paid version) from %s will start in %s. If you would like to do it manually - click the cancellation button now.' ),
484
+ 'installing-module-x' => _fs_text( 'The installation process has started and may take a few minutes to complete. Please wait until it is done - do not refresh this page.' ),
485
+ 'cancel-installation' => _fs_text( 'Cancel Installation' ),
486
+ 'module-package-rename-failure' => _fs_text( 'The remote plugin package does not contain a folder with the desired slug and renaming did not work.' ),
487
+ 'auto-install-error-invalid-id' => _fs_text( 'Invalid module ID.' ),
488
+ 'auto-install-error-not-opted-in' => _fs_text( 'Auto installation only works for opted-in users.' ),
489
+ 'auto-install-error-premium-activated' => _fs_text( 'Premium version already active.' ),
490
+ 'auto-install-error-premium-addon-activated' => _fs_text( 'Premium add-on version already installed.' ),
491
+ 'auto-install-error-invalid-license' => _fs_text( 'You do not have a valid license to access the premium version.' ),
492
+ 'auto-install-error-serviceware' => _fs_text( 'Plugin is a "Serviceware" which means it does not have a premium code version.' ),
493
+ #endregion
494
+
495
+ /* translators: %s: Page name */
496
+ 'secure-x-page-header' => _fs_text( 'Secure HTTPS %s page, running from an external domain' ),
497
+ 'pci-compliant' => _fs_text( 'PCI compliant' ),
498
+ 'view-paid-features' => _fs_text( 'View paid features' ),
499
+ );
500
+
501
+ /**
502
+ * Localization of the strings in the plugin/theme info dialog box.
503
+ *
504
+ * $fs_module_info_text should ONLY include strings that are not located in $fs_text.
505
+ *
506
+ * @author Vova Feldman (@svovaf)
507
+ * @since 1.2.2
508
+ */
509
+ global $fs_module_info_text;
510
+
511
+ $fs_module_info_text = array(
512
+ 'description' => _fs_x( 'Description', 'Plugin installer section title' ),
513
+ 'installation' => _fs_x( 'Installation', 'Plugin installer section title' ),
514
+ 'faq' => _fs_x( 'FAQ', 'Plugin installer section title' ),
515
+ 'changelog' => _fs_x( 'Changelog', 'Plugin installer section title' ),
516
+ 'reviews' => _fs_x( 'Reviews', 'Plugin installer section title' ),
517
+ 'other_notes' => _fs_x( 'Other Notes', 'Plugin installer section title' ),
518
+ /* translators: %s: 1 or One */
519
+ 'x-star' => _fs_text( '%s star' ),
520
+ /* translators: %s: Number larger than 1 */
521
+ 'x-stars' => _fs_text( '%s stars' ),
522
+ /* translators: %s: 1 or One */
523
+ 'x-rating' => _fs_text( '%s rating' ),
524
+ /* translators: %s: Number larger than 1 */
525
+ 'x-ratings' => _fs_text( '%s ratings' ),
526
+ /* translators: %s: 1 or One (Number of times downloaded) */
527
+ 'x-time' => _fs_text( '%s time' ),
528
+ /* translators: %s: Number of times downloaded */
529
+ 'x-times' => _fs_text( '%s times' ),
530
+ /* translators: %s: # of stars (e.g. 5 stars) */
531
+ 'click-to-reviews' => _fs_text( 'Click to see reviews that provided a rating of %s' ),
532
+ 'last-updated:' => _fs_text( 'Last Updated' ),
533
+ 'requires-wordpress-version:' => _fs_text( 'Requires WordPress Version:' ),
534
+ 'author:' => _fs_x( 'Author:', 'as the plugin author' ),
535
+ 'compatible-up-to:' => _fs_text( 'Compatible up to:' ),
536
+ 'downloaded:' => _fs_text( 'Downloaded:' ),
537
+ 'wp-org-plugin-page' => _fs_text( 'WordPress.org Plugin Page' ),
538
+ 'plugin-homepage' => _fs_text( 'Plugin Homepage' ),
539
+ 'donate-to-plugin' => _fs_text( 'Donate to this plugin' ),
540
+ 'average-rating' => _fs_text( 'Average Rating' ),
541
+ 'based-on-x' => _fs_text( 'based on %s' ),
542
+ 'warning:' => _fs_text( 'Warning:' ),
543
+ 'contributors' => _fs_text( 'Contributors' ),
544
+ 'plugin-install' => _fs_text( 'Plugin Install' ),
545
+ 'not-tested-warning' => _fs_text( 'This plugin has not been tested with your current version of WordPress.' ),
546
+ 'not-compatible-warning' => _fs_text( 'This plugin has not been marked as compatible with your version of WordPress.' ),
547
+ 'newer-installed' => _fs_text( 'Newer Version (%s) Installed' ),
548
+ 'latest-installed' => _fs_text( 'Latest Version Installed' ),
549
+ );
freemius/includes/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/includes/l10n.php ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.2.1.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Retrieve the translation of $text.
15
+ *
16
+ * @since 1.2.1.6
17
+ *
18
+ * @param string $text
19
+ *
20
+ * @return string
21
+ */
22
+ function _fs_text( $text ) {
23
+ // Avoid misleading Theme Check warning.
24
+ $fn = 'translate';
25
+ return $fn( $text, 'freemius' );
26
+ }
27
+
28
+ /**
29
+ * Retrieve the translation of $text and escapes it for safe use in an attribute.
30
+ *
31
+ * @since 1.2.1.6
32
+ *
33
+ * @param string $text
34
+ *
35
+ * @return string
36
+ */
37
+ function _fs_esc_attr( $text ) {
38
+ // Avoid misleading Theme Check warning.
39
+ $fn = 'translate';
40
+ return esc_attr( $fn( $text, 'freemius' ) );
41
+ }
42
+
43
+ /**
44
+ * Retrieve the translation of $text and escapes it for safe use in HTML output.
45
+ *
46
+ * @since 1.2.1.6
47
+ *
48
+ * @param string $text
49
+ *
50
+ * @return string
51
+ */
52
+ function _fs_esc_html( $text ) {
53
+ // Avoid misleading Theme Check warning.
54
+ $fn = 'translate';
55
+ return esc_html( $fn( $text, 'freemius' ) );
56
+ }
57
+
58
+ /**
59
+ * Display translated text.
60
+ *
61
+ * @since 1.2.0
62
+ *
63
+ * @param string $text
64
+ */
65
+ function _fs_echo( $text ) {
66
+ // Avoid misleading Theme Check warning.
67
+ $fn = 'translate';
68
+ echo $fn( $text, 'freemius' );
69
+ }
70
+
71
+ /**
72
+ * Display translated text that has been escaped for safe use in an attribute.
73
+ *
74
+ * @since 1.2.1.6
75
+ *
76
+ * @param string $text
77
+ */
78
+ function _fs_esc_attr_echo( $text ) {
79
+ // Avoid misleading Theme Check warning.
80
+ $fn = 'translate';
81
+ echo esc_attr( $fn( $text, 'freemius' ) );
82
+ }
83
+
84
+ /**
85
+ * Display translated text that has been escaped for safe use in HTML output.
86
+ *
87
+ * @since 1.2.1.6
88
+ *
89
+ * @param string $text
90
+ */
91
+ function _fs_esc_html_echo( $text ) {
92
+ // Avoid misleading Theme Check warning.
93
+ $fn = 'translate';
94
+ echo esc_html( $fn( $text, 'freemius' ) );
95
+ }
96
+
97
+ /**
98
+ * Retrieve translated string with gettext context.
99
+ *
100
+ * Quite a few times, there will be collisions with similar translatable text
101
+ * found in more than two places, but with different translated context.
102
+ *
103
+ * By including the context in the pot file, translators can translate the two
104
+ * strings differently.
105
+ *
106
+ * @since 1.2.1.6
107
+ *
108
+ * @param string $text
109
+ * @param string $context
110
+ *
111
+ * @return string
112
+ */
113
+ function _fs_x( $text, $context ) {
114
+ // Avoid misleading Theme Check warning.
115
+ $fn = 'translate_with_gettext_context';
116
+ return $fn( $text, $context, 'freemius' );
117
+ }
118
+
119
+ /**
120
+ * Display translated string with gettext context.
121
+ *
122
+ * @since 1.2.1.6
123
+ *
124
+ * @param string $text
125
+ * @param string $context
126
+ */
127
+ function _fs_ex( $text, $context ) {
128
+ // Avoid misleading Theme Check warning.
129
+ $fn = '_x';
130
+ echo $fn( $text, $context, 'freemius' );
131
+ }
132
+
133
+ /**
134
+ * Translate string with gettext context, and escapes it for safe use in an attribute.
135
+ *
136
+ * @since 1.2.1.6
137
+ *
138
+ * @param string $text
139
+ * @param string $context
140
+ *
141
+ * @return string
142
+ */
143
+ function _fs_esc_attr_x( $text, $context ) {
144
+ // Avoid misleading Theme Check warning.
145
+ $fn = 'translate_with_gettext_context';
146
+ return esc_attr( $fn( $text, $context, 'freemius' ) );
147
+ }
148
+
149
+ /**
150
+ * Translate string with gettext context, and escapes it for safe use in HTML output.
151
+ *
152
+ * @since 2.9.0
153
+ *
154
+ * @param string $text
155
+ * @param string $context
156
+ *
157
+ * @return string
158
+ */
159
+ function _fs_esc_html_x( $text, $context ) {
160
+ // Avoid misleading Theme Check warning.
161
+ $fn = 'translate_with_gettext_context';
162
+ return esc_html( $fn( $text, $context, 'freemius' ) );
163
+ }
164
+
165
+ /**
166
+ * Translates and retrieves the singular or plural form based on the supplied number.
167
+ *
168
+ * @since 1.2.1.6
169
+ *
170
+ * @param string $single
171
+ * @param string $plural
172
+ * @param int $number
173
+ *
174
+ * @return string
175
+ */
176
+ function _fs_n( $single, $plural, $number ) {
177
+ $translations = get_translations_for_domain( 'freemius' );
178
+ $translation = $translations->translate_plural( $single, $plural, $number );
179
+
180
+ /**
181
+ * Filters the singular or plural form of a string.
182
+ *
183
+ * @since WP 2.2.0
184
+ *
185
+ * @param string $translation
186
+ * @param string $single
187
+ * @param string $plural
188
+ * @param string $number
189
+ * @param string $domain
190
+ */
191
+ return apply_filters( 'ngettext', $translation, $single, $plural, $number, 'freemius' );
192
+ }
193
+
194
+ /**
195
+ * Translates and retrieves the singular or plural form based on the supplied number, with gettext context.
196
+ *
197
+ * @since 1.2.1.6
198
+ *
199
+ * @param string $single
200
+ * @param string $plural
201
+ * @param int $number
202
+ * @param string $context
203
+ *
204
+ * @return string
205
+ */
206
+ function _fs_nx($single, $plural, $number, $context ) {
207
+ $translations = get_translations_for_domain( 'freemius' );
208
+ $translation = $translations->translate_plural( $single, $plural, $number, $context );
209
+
210
+ /**
211
+ * Filters the singular or plural form of a string with gettext context.
212
+ *
213
+ * @since WP 3.0
214
+ *
215
+ * @param string $translation
216
+ * @param string $single
217
+ * @param string $plural
218
+ * @param string $number
219
+ * @param string $context
220
+ * @param string $domain
221
+ */
222
+ return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, 'freemius' );
223
+ }
224
+
225
+ /**
226
+ * Registers plural strings in POT file, but does not translate them.
227
+ *
228
+ * Used when you want to keep structures with translatable plural
229
+ * strings and use them later when the number is known.
230
+ *
231
+ * @since 1.2.1.6
232
+ *
233
+ * @param string $singular
234
+ * @param string $plural
235
+ *
236
+ * @return array
237
+ */
238
+ function _fs_n_noop( $singular, $plural ) {
239
+ return array(
240
+ 'singular' => $singular,
241
+ 'plural' => $plural,
242
+ 'context' => null,
243
+ 'domain' => 'freemius'
244
+ );
245
+ }
246
+
247
+ /**
248
+ * Registers plural strings with gettext context in POT file, but does not translate them.
249
+ *
250
+ * Used when you want to keep structures with translatable plural
251
+ * strings and use them later when the number is known.
252
+ *
253
+ * @since 1.2.1.6
254
+ *
255
+ * @param string $singular
256
+ * @param string $plural
257
+ * @param string $context
258
+ *
259
+ * @return array
260
+ */
261
+ function _fs_nx_noop( $singular, $plural, $context ) {
262
+ return array(
263
+ 'singular' => $singular,
264
+ 'plural' => $plural,
265
+ 'context' => $context,
266
+ 'domain' => 'freemius'
267
+ );
268
+ }
freemius/includes/managers/class-fs-admin-menu-manager.php ADDED
@@ -0,0 +1,849 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.1.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Menu_Manager {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @since 1.2.2
19
+ *
20
+ * @var string
21
+ */
22
+ protected $_module_unique_affix;
23
+
24
+ /**
25
+ * @since 1.2.2
26
+ *
27
+ * @var number
28
+ */
29
+ protected $_module_id;
30
+
31
+ /**
32
+ * @since 1.2.2
33
+ *
34
+ * @var string
35
+ */
36
+ protected $_module_type;
37
+
38
+ /**
39
+ * @since 1.0.6
40
+ *
41
+ * @var string
42
+ */
43
+ private $_menu_slug;
44
+ /**
45
+ * @since 1.1.3
46
+ *
47
+ * @var string
48
+ */
49
+ private $_parent_slug;
50
+ /**
51
+ * @since 1.1.3
52
+ *
53
+ * @var string
54
+ */
55
+ private $_parent_type;
56
+ /**
57
+ * @since 1.1.3
58
+ *
59
+ * @var string
60
+ */
61
+ private $_type;
62
+ /**
63
+ * @since 1.1.3
64
+ *
65
+ * @var bool
66
+ */
67
+ private $_is_top_level;
68
+ /**
69
+ * @since 1.1.3
70
+ *
71
+ * @var bool
72
+ */
73
+ private $_is_override_exact;
74
+ /**
75
+ * @since 1.1.3
76
+ *
77
+ * @var array<string,bool>
78
+ */
79
+ private $_default_submenu_items;
80
+ /**
81
+ * @since 1.1.3
82
+ *
83
+ * @var string
84
+ */
85
+ private $_first_time_path;
86
+ /**
87
+ * @since 1.2.2
88
+ *
89
+ * @var bool
90
+ */
91
+ private $_menu_exists;
92
+
93
+ #endregion Properties
94
+
95
+ /**
96
+ * @var FS_Logger
97
+ */
98
+ protected $_logger;
99
+
100
+ #region Singleton
101
+
102
+ /**
103
+ * @var FS_Admin_Menu_Manager[]
104
+ */
105
+ private static $_instances = array();
106
+
107
+ /**
108
+ * @param number $module_id
109
+ * @param string $module_type
110
+ * @param string $module_unique_affix
111
+ *
112
+ * @return FS_Admin_Menu_Manager
113
+ */
114
+ static function instance( $module_id, $module_type, $module_unique_affix ) {
115
+ $key = 'm_' . $module_id;
116
+
117
+ if ( ! isset( self::$_instances[ $key ] ) ) {
118
+ self::$_instances[ $key ] = new FS_Admin_Menu_Manager( $module_id, $module_type, $module_unique_affix );
119
+ }
120
+
121
+ return self::$_instances[ $key ];
122
+ }
123
+
124
+ protected function __construct( $module_id, $module_type, $module_unique_affix ) {
125
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $module_id . '_admin_menu', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
126
+
127
+ $this->_module_id = $module_id;
128
+ $this->_module_type = $module_type;
129
+ $this->_module_unique_affix = $module_unique_affix;
130
+ }
131
+
132
+ #endregion Singleton
133
+
134
+ #region Helpers
135
+
136
+ private function get_option( &$options, $key, $default = false ) {
137
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
138
+ }
139
+
140
+ private function get_bool_option( &$options, $key, $default = false ) {
141
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
142
+ }
143
+
144
+ #endregion Helpers
145
+
146
+ /**
147
+ * @param array $menu
148
+ * @param bool $is_addon
149
+ */
150
+ function init( $menu, $is_addon = false ) {
151
+ $this->_menu_exists = ( isset( $menu['slug'] ) && ! empty( $menu['slug'] ) );
152
+
153
+ $this->_menu_slug = ( $this->_menu_exists ? $menu['slug'] : $this->_module_unique_affix );
154
+
155
+ $this->_default_submenu_items = array();
156
+ // @deprecated
157
+ $this->_type = 'page';
158
+ $this->_is_top_level = true;
159
+ $this->_is_override_exact = false;
160
+ $this->_parent_slug = false;
161
+ // @deprecated
162
+ $this->_parent_type = 'page';
163
+
164
+ if ( ! $is_addon && isset( $menu ) ) {
165
+ $this->_default_submenu_items = array(
166
+ 'contact' => $this->get_bool_option( $menu, 'contact', true ),
167
+ 'support' => $this->get_bool_option( $menu, 'support', true ),
168
+ 'account' => $this->get_bool_option( $menu, 'account', true ),
169
+ 'pricing' => $this->get_bool_option( $menu, 'pricing', true ),
170
+ 'addons' => $this->get_bool_option( $menu, 'addons', true ),
171
+ );
172
+
173
+ // @deprecated
174
+ $this->_type = $this->get_option( $menu, 'type', 'page' );
175
+ $this->_is_override_exact = $this->get_bool_option( $menu, 'override_exact' );
176
+
177
+ if ( isset( $menu['parent'] ) ) {
178
+ $this->_parent_slug = $this->get_option( $menu['parent'], 'slug' );
179
+ // @deprecated
180
+ $this->_parent_type = $this->get_option( $menu['parent'], 'type', 'page' );
181
+
182
+ // If parent's slug is different, then it's NOT a top level menu item.
183
+ $this->_is_top_level = ( $this->_parent_slug === $this->_menu_slug );
184
+ } else {
185
+ /**
186
+ * If no parent then top level if:
187
+ * - Has custom admin menu ('page')
188
+ * - CPT menu type ('cpt')
189
+ */
190
+ // $this->_is_top_level = in_array( $this->_type, array(
191
+ // 'cpt',
192
+ // 'page'
193
+ // ) );
194
+ }
195
+
196
+ $this->_first_time_path = $this->get_option( $menu, 'first-path', false );
197
+ if ( ! empty( $this->_first_time_path ) && is_string( $this->_first_time_path ) ) {
198
+ $this->_first_time_path = admin_url( $this->_first_time_path, 'admin' );
199
+ }
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Check if top level menu.
205
+ *
206
+ * @author Vova Feldman (@svovaf)
207
+ * @since 1.1.3
208
+ *
209
+ * @return bool False if submenu item.
210
+ */
211
+ function is_top_level() {
212
+ return $this->_is_top_level;
213
+ }
214
+
215
+ /**
216
+ * Check if the page should be override on exact URL match.
217
+ *
218
+ * @author Vova Feldman (@svovaf)
219
+ * @since 1.1.3
220
+ *
221
+ * @return bool False if submenu item.
222
+ */
223
+ function is_override_exact() {
224
+ return $this->_is_override_exact;
225
+ }
226
+
227
+
228
+ /**
229
+ * Get the path of the page the user should be forwarded to after first activation.
230
+ *
231
+ * @author Vova Feldman (@svovaf)
232
+ * @since 1.1.3
233
+ *
234
+ * @return string
235
+ */
236
+ function get_first_time_path() {
237
+ return $this->_first_time_path;
238
+ }
239
+
240
+ /**
241
+ * Check if plugin's menu item is part of a custom top level menu.
242
+ *
243
+ * @author Vova Feldman (@svovaf)
244
+ * @since 1.1.3
245
+ *
246
+ * @return bool
247
+ */
248
+ function has_custom_parent() {
249
+ return ! $this->_is_top_level && is_string( $this->_parent_slug );
250
+ }
251
+
252
+ /**
253
+ * @author Leo Fajardo (@leorw)
254
+ * @since 1.2.2
255
+ *
256
+ * @return bool
257
+ */
258
+ function has_menu() {
259
+ return $this->_menu_exists;
260
+ }
261
+
262
+ /**
263
+ * @author Vova Feldman (@svovaf)
264
+ * @since 1.1.3
265
+ *
266
+ * @param string $id
267
+ * @param bool $default
268
+ * @param bool $ignore_menu_existence Since 1.2.2.7 If true, check if the submenu item visible even if there's no parent menu.
269
+ *
270
+ * @return bool
271
+ */
272
+ function is_submenu_item_visible( $id, $default = true, $ignore_menu_existence = false ) {
273
+ if ( ! $ignore_menu_existence && ! $this->has_menu() ) {
274
+ return false;
275
+ }
276
+
277
+ return fs_apply_filter(
278
+ $this->_module_unique_affix,
279
+ 'is_submenu_visible',
280
+ $this->get_bool_option( $this->_default_submenu_items, $id, $default ),
281
+ $id
282
+ );
283
+ }
284
+
285
+ /**
286
+ * Calculates admin settings menu slug.
287
+ * If plugin's menu slug is a file (e.g. CPT), uses plugin's slug as the menu slug.
288
+ *
289
+ * @author Vova Feldman (@svovaf)
290
+ * @since 1.1.3
291
+ *
292
+ * @param string $page
293
+ *
294
+ * @return string
295
+ */
296
+ function get_slug( $page = '' ) {
297
+ return ( ( false === strpos( $this->_menu_slug, '.php?' ) ) ?
298
+ $this->_menu_slug :
299
+ $this->_module_unique_affix ) . ( empty( $page ) ? '' : ( '-' . $page ) );
300
+ }
301
+
302
+ /**
303
+ * @author Vova Feldman (@svovaf)
304
+ * @since 1.1.3
305
+ *
306
+ * @return string
307
+ */
308
+ function get_parent_slug() {
309
+ return $this->_parent_slug;
310
+ }
311
+
312
+ /**
313
+ * @author Vova Feldman (@svovaf)
314
+ * @since 1.1.3
315
+ *
316
+ * @return string
317
+ */
318
+ function get_type() {
319
+ return $this->_type;
320
+ }
321
+
322
+ /**
323
+ * @author Vova Feldman (@svovaf)
324
+ * @since 1.1.3
325
+ *
326
+ * @return bool
327
+ */
328
+ function is_cpt() {
329
+ return ( 0 === strpos( $this->_menu_slug, 'edit.php?post_type=' ) ||
330
+ // Back compatibility.
331
+ 'cpt' === $this->_type
332
+ );
333
+ }
334
+
335
+ /**
336
+ * @author Vova Feldman (@svovaf)
337
+ * @since 1.1.3
338
+ *
339
+ * @return string
340
+ */
341
+ function get_parent_type() {
342
+ return $this->_parent_type;
343
+ }
344
+
345
+ /**
346
+ * @author Vova Feldman (@svovaf)
347
+ * @since 1.1.3
348
+ *
349
+ * @return string
350
+ */
351
+ function get_raw_slug() {
352
+ return $this->_menu_slug;
353
+ }
354
+
355
+ /**
356
+ * Get plugin's original menu slug.
357
+ *
358
+ * @author Vova Feldman (@svovaf)
359
+ * @since 1.1.3
360
+ *
361
+ * @return string
362
+ */
363
+ function get_original_menu_slug() {
364
+ if ( 'cpt' === $this->_type ) {
365
+ return add_query_arg( array(
366
+ 'post_type' => $this->_menu_slug
367
+ ), 'edit.php' );
368
+ }
369
+
370
+ if ( false === strpos( $this->_menu_slug, '.php?' ) ) {
371
+ return $this->_menu_slug;
372
+ } else {
373
+ return $this->_module_unique_affix;
374
+ }
375
+ }
376
+
377
+ /**
378
+ * @author Vova Feldman (@svovaf)
379
+ * @since 1.1.3
380
+ *
381
+ * @return string
382
+ */
383
+ function get_top_level_menu_slug() {
384
+ return $this->has_custom_parent() ?
385
+ $this->get_parent_slug() :
386
+ $this->get_raw_slug();
387
+ }
388
+
389
+ /**
390
+ * Is user on plugin's admin activation page.
391
+ *
392
+ * @author Vova Feldman (@svovaf)
393
+ * @since 1.0.8
394
+ *
395
+ * @return bool
396
+ */
397
+ function is_main_settings_page() {
398
+ if ( $this->_menu_exists &&
399
+ ( fs_is_plugin_page( $this->_menu_slug ) || fs_is_plugin_page( $this->_module_unique_affix ) )
400
+ ) {
401
+ /**
402
+ * Module has a settings menu and the context page is the main settings page, so assume it's in
403
+ * activation (doesn't really check if already opted-in/skipped or not).
404
+ *
405
+ * @since 1.2.2
406
+ */
407
+ return true;
408
+ }
409
+
410
+ global $pagenow;
411
+ if ( ( WP_FS__MODULE_TYPE_THEME === $this->_module_type ) && Freemius::is_themes_page() ) {
412
+ /**
413
+ * In activation only when show_optin query string param is given.
414
+ *
415
+ * @since 1.2.2
416
+ */
417
+ return fs_request_get_bool( $this->_module_unique_affix . '_show_optin' );
418
+ }
419
+
420
+ return false;
421
+ }
422
+
423
+ #region Submenu Override
424
+
425
+ /**
426
+ * Override submenu's action.
427
+ *
428
+ * @author Vova Feldman (@svovaf)
429
+ * @since 1.1.0
430
+ *
431
+ * @param string $parent_slug
432
+ * @param string $menu_slug
433
+ * @param callable $function
434
+ *
435
+ * @return false|string If submenu exist, will return the hook name.
436
+ */
437
+ function override_submenu_action( $parent_slug, $menu_slug, $function ) {
438
+ global $submenu;
439
+
440
+ $menu_slug = plugin_basename( $menu_slug );
441
+ $parent_slug = plugin_basename( $parent_slug );
442
+
443
+ if ( ! isset( $submenu[ $parent_slug ] ) ) {
444
+ // Parent menu not exist.
445
+ return false;
446
+ }
447
+
448
+ $found_submenu_item = false;
449
+ foreach ( $submenu[ $parent_slug ] as $submenu_item ) {
450
+ if ( $menu_slug === $submenu_item[2] ) {
451
+ $found_submenu_item = $submenu_item;
452
+ break;
453
+ }
454
+ }
455
+
456
+ if ( false === $found_submenu_item ) {
457
+ // Submenu item not found.
458
+ return false;
459
+ }
460
+
461
+ // Remove current function.
462
+ $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
463
+ remove_all_actions( $hookname );
464
+
465
+ // Attach new action.
466
+ add_action( $hookname, $function );
467
+
468
+ return $hookname;
469
+ }
470
+
471
+ #endregion Submenu Override
472
+
473
+ #region Top level menu Override
474
+
475
+ /**
476
+ * Find plugin's admin dashboard main menu item.
477
+ *
478
+ * @author Vova Feldman (@svovaf)
479
+ * @since 1.0.2
480
+ *
481
+ * @return string[]|false
482
+ */
483
+ private function find_top_level_menu() {
484
+ global $menu;
485
+
486
+ $position = - 1;
487
+ $found_menu = false;
488
+
489
+ $menu_slug = $this->get_raw_slug();
490
+
491
+ $hook_name = get_plugin_page_hookname( $menu_slug, '' );
492
+ foreach ( $menu as $pos => $m ) {
493
+ if ( $menu_slug === $m[2] ) {
494
+ $position = $pos;
495
+ $found_menu = $m;
496
+ break;
497
+ }
498
+ }
499
+
500
+ if ( false === $found_menu ) {
501
+ return false;
502
+ }
503
+
504
+ return array(
505
+ 'menu' => $found_menu,
506
+ 'position' => $position,
507
+ 'hook_name' => $hook_name
508
+ );
509
+ }
510
+
511
+ /**
512
+ * Find plugin's admin dashboard main submenu item.
513
+ *
514
+ * @author Vova Feldman (@svovaf)
515
+ * @since 1.2.1.6
516
+ *
517
+ * @return array|false
518
+ */
519
+ private function find_main_submenu() {
520
+ global $submenu;
521
+
522
+ $top_level_menu_slug = $this->get_top_level_menu_slug();
523
+
524
+ if ( ! isset( $submenu[ $top_level_menu_slug ] ) ) {
525
+ return false;
526
+ }
527
+
528
+ $submenu_slug = $this->get_raw_slug();
529
+
530
+ $position = - 1;
531
+ $found_submenu = false;
532
+
533
+ $hook_name = get_plugin_page_hookname( $submenu_slug, '' );
534
+
535
+ foreach ( $submenu[ $top_level_menu_slug ] as $pos => $sub ) {
536
+ if ( $submenu_slug === $sub[2] ) {
537
+ $position = $pos;
538
+ $found_submenu = $sub;
539
+ }
540
+ }
541
+
542
+ if ( false === $found_submenu ) {
543
+ return false;
544
+ }
545
+
546
+ return array(
547
+ 'menu' => $found_submenu,
548
+ 'parent_slug' => $top_level_menu_slug,
549
+ 'position' => $position,
550
+ 'hook_name' => $hook_name
551
+ );
552
+ }
553
+
554
+ /**
555
+ * Remove all sub-menu items.
556
+ *
557
+ * @author Vova Feldman (@svovaf)
558
+ * @since 1.0.7
559
+ *
560
+ * @return bool If submenu with plugin's menu slug was found.
561
+ */
562
+ private function remove_all_submenu_items() {
563
+ global $submenu;
564
+
565
+ $menu_slug = $this->get_raw_slug();
566
+
567
+ if ( ! isset( $submenu[ $menu_slug ] ) ) {
568
+ return false;
569
+ }
570
+
571
+ /**
572
+ * This method is NOT executed for WordPress.org themes.
573
+ * Since we maintain only one version of the SDK we added this small
574
+ * hack to avoid the error from Theme Check since it's a false-positive.
575
+ *
576
+ * @author Vova Feldman (@svovaf)
577
+ * @since 1.2.2.7
578
+ */
579
+ $submenu_ref = &$submenu;
580
+ $submenu_ref[ $menu_slug ] = array();
581
+
582
+ return true;
583
+ }
584
+
585
+ /**
586
+ *
587
+ * @author Vova Feldman (@svovaf)
588
+ * @since 1.0.9
589
+ *
590
+ * @return false|array[string]mixed
591
+ */
592
+ function remove_menu_item() {
593
+ $this->_logger->entrance();
594
+
595
+ // Find main menu item.
596
+ $menu = $this->find_top_level_menu();
597
+
598
+ if ( false === $menu ) {
599
+ return false;
600
+ }
601
+
602
+ // Remove it with its actions.
603
+ remove_all_actions( $menu['hook_name'] );
604
+
605
+ // Remove all submenu items.
606
+ $this->remove_all_submenu_items();
607
+
608
+ return $menu;
609
+ }
610
+
611
+ /**
612
+ * Get module's main admin setting page URL.
613
+ *
614
+ * @todo This method was only tested for wp.org compliant themes with a submenu item. Need to test for plugins with top level, submenu, and CPT top level, menu items.
615
+ *
616
+ * @author Vova Feldman (@svovaf)
617
+ * @since 1.2.2.7
618
+ *
619
+ * @return string
620
+ */
621
+ function main_menu_url() {
622
+ $this->_logger->entrance();
623
+
624
+ if ( $this->_is_top_level ) {
625
+ $menu = $this->find_top_level_menu();
626
+ } else {
627
+ $menu = $this->find_main_submenu();
628
+ }
629
+
630
+ $parent_slug = isset( $menu['parent_slug'] ) ?
631
+ $menu['parent_slug'] :
632
+ 'admin.php';
633
+
634
+ return admin_url( $parent_slug . '?page=' . $menu['menu'][2] );
635
+ }
636
+
637
+ /**
638
+ * @author Vova Feldman (@svovaf)
639
+ * @since 1.1.4
640
+ *
641
+ * @param callable $function
642
+ *
643
+ * @return false|array[string]mixed
644
+ */
645
+ function override_menu_item( $function ) {
646
+ $found_menu = $this->remove_menu_item();
647
+
648
+ if ( false === $found_menu ) {
649
+ return false;
650
+ }
651
+
652
+ if ( ! $this->is_top_level() || ! $this->is_cpt() ) {
653
+ $menu_slug = plugin_basename( $this->get_slug() );
654
+
655
+ $hookname = get_plugin_page_hookname( $menu_slug, '' );
656
+
657
+ // Override menu action.
658
+ add_action( $hookname, $function );
659
+ } else {
660
+ global $menu;
661
+
662
+ // Remove original CPT menu.
663
+ unset( $menu[ $found_menu['position'] ] );
664
+
665
+ // Create new top-level menu action.
666
+ $hookname = self::add_page(
667
+ $found_menu['menu'][3],
668
+ $found_menu['menu'][0],
669
+ 'manage_options',
670
+ $this->get_slug(),
671
+ $function,
672
+ $found_menu['menu'][6],
673
+ $found_menu['position']
674
+ );
675
+ }
676
+
677
+ return $hookname;
678
+ }
679
+
680
+ /**
681
+ * Adds a counter to the module's top level menu item.
682
+ *
683
+ * @author Vova Feldman (@svovaf)
684
+ * @since 1.2.1.5
685
+ *
686
+ * @param int $counter
687
+ * @param string $class
688
+ */
689
+ function add_counter_to_menu_item( $counter = 1, $class = '' ) {
690
+ global $menu, $submenu;
691
+
692
+ $mask = '%s <span class="update-plugins %s count-%3$s" aria-hidden="true"><span>%3$s<span class="screen-reader-text">%3$s notifications</span></span></span>';
693
+
694
+ /**
695
+ * This method is NOT executed for WordPress.org themes.
696
+ * Since we maintain only one version of the SDK we added this small
697
+ * hack to avoid the error from Theme Check since it's a false-positive.
698
+ *
699
+ * @author Vova Feldman (@svovaf)
700
+ * @since 1.2.2.7
701
+ */
702
+ $menu_ref = &$menu;
703
+ $submenu_ref = &$submenu;
704
+
705
+ if ( $this->_is_top_level ) {
706
+ // Find main menu item.
707
+ $found_menu = $this->find_top_level_menu();
708
+
709
+ if ( false !== $found_menu ) {
710
+ // Override menu label.
711
+ $menu_ref[ $found_menu['position'] ][0] = sprintf(
712
+ $mask,
713
+ $found_menu['menu'][0],
714
+ $class,
715
+ $counter
716
+ );
717
+ }
718
+ } else {
719
+ $found_submenu = $this->find_main_submenu();
720
+
721
+ if ( false !== $found_submenu ) {
722
+ // Override menu label.
723
+ $submenu_ref[ $found_submenu['parent_slug'] ][ $found_submenu['position'] ][0] = sprintf(
724
+ $mask,
725
+ $found_submenu['menu'][0],
726
+ $class,
727
+ $counter
728
+ );
729
+ }
730
+ }
731
+ }
732
+
733
+ #endregion Top level menu Override
734
+
735
+ /**
736
+ * Add a top-level menu page.
737
+ *
738
+ * Note for WordPress.org Theme/Plugin reviewer:
739
+ *
740
+ * This is a replication of `add_menu_page()` to avoid Theme Check warning.
741
+ *
742
+ * Why?
743
+ * ====
744
+ * Freemius is an SDK for plugin and theme developers. Since the core
745
+ * of the SDK is relevant both for plugins and themes, for obvious reasons,
746
+ * we only develop and maintain one code base.
747
+ *
748
+ * This method will not run for wp.org themes (only plugins) since theme
749
+ * admin settings/options are now only allowed in the customizer.
750
+ *
751
+ * If you have any questions or need clarifications, please don't hesitate
752
+ * pinging me on slack, my username is @svovaf.
753
+ *
754
+ * @author Vova Feldman (@svovaf)
755
+ * @since 1.2.2
756
+ *
757
+ * @param string $page_title The text to be displayed in the title tags of the page when the menu is
758
+ * selected.
759
+ * @param string $menu_title The text to be used for the menu.
760
+ * @param string $capability The capability required for this menu to be displayed to the user.
761
+ * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu).
762
+ * @param callable|string $function The function to be called to output the content for this page.
763
+ * @param string $icon_url The URL to the icon to be used for this menu.
764
+ * * Pass a base64-encoded SVG using a data URI, which will be colored to
765
+ * match the color scheme. This should begin with
766
+ * 'data:image/svg+xml;base64,'.
767
+ * * Pass the name of a Dashicons helper class to use a font icon,
768
+ * e.g. 'dashicons-chart-pie'.
769
+ * * Pass 'none' to leave div.wp-menu-image empty so an icon can be added
770
+ * via CSS.
771
+ * @param int $position The position in the menu order this one should appear.
772
+ *
773
+ * @return string The resulting page's hook_suffix.
774
+ */
775
+ static function add_page(
776
+ $page_title,
777
+ $menu_title,
778
+ $capability,
779
+ $menu_slug,
780
+ $function = '',
781
+ $icon_url = '',
782
+ $position = null
783
+ ) {
784
+ $fn = 'add_menu' . '_page';
785
+
786
+ return $fn(
787
+ $page_title,
788
+ $menu_title,
789
+ $capability,
790
+ $menu_slug,
791
+ $function,
792
+ $icon_url,
793
+ $position
794
+ );
795
+ }
796
+
797
+ /**
798
+ * Add a submenu page.
799
+ *
800
+ * Note for WordPress.org Theme/Plugin reviewer:
801
+ *
802
+ * This is a replication of `add_submenu_page()` to avoid Theme Check warning.
803
+ *
804
+ * Why?
805
+ * ====
806
+ * Freemius is an SDK for plugin and theme developers. Since the core
807
+ * of the SDK is relevant both for plugins and themes, for obvious reasons,
808
+ * we only develop and maintain one code base.
809
+ *
810
+ * This method will not run for wp.org themes (only plugins) since theme
811
+ * admin settings/options are now only allowed in the customizer.
812
+ *
813
+ * If you have any questions or need clarifications, please don't hesitate
814
+ * pinging me on slack, my username is @svovaf.
815
+ *
816
+ * @author Vova Feldman (@svovaf)
817
+ * @since 1.2.2
818
+ *
819
+ * @param string $parent_slug The slug name for the parent menu (or the file name of a standard
820
+ * WordPress admin page).
821
+ * @param string $page_title The text to be displayed in the title tags of the page when the menu is
822
+ * selected.
823
+ * @param string $menu_title The text to be used for the menu.
824
+ * @param string $capability The capability required for this menu to be displayed to the user.
825
+ * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu).
826
+ * @param callable|string $function The function to be called to output the content for this page.
827
+ *
828
+ * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability
829
+ * required.
830
+ */
831
+ static function add_subpage(
832
+ $parent_slug,
833
+ $page_title,
834
+ $menu_title,
835
+ $capability,
836
+ $menu_slug,
837
+ $function = ''
838
+ ) {
839
+ $fn = 'add_submenu' . '_page';
840
+
841
+ return $fn( $parent_slug,
842
+ $page_title,
843
+ $menu_title,
844
+ $capability,
845
+ $menu_slug,
846
+ $function
847
+ );
848
+ }
849
+ }
freemius/includes/managers/class-fs-admin-notice-manager.php ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Notice_Manager {
14
+ /**
15
+ * @since 1.2.2
16
+ *
17
+ * @var string
18
+ */
19
+ protected $_module_unique_affix;
20
+ /**
21
+ * @var string
22
+ */
23
+ protected $_id;
24
+ /**
25
+ * @var string
26
+ */
27
+ protected $_title;
28
+ /**
29
+ * @var array[]
30
+ */
31
+ private $_admin_messages = array();
32
+ /**
33
+ * @var FS_Key_Value_Storage
34
+ */
35
+ private $_sticky_storage;
36
+ /**
37
+ * @var FS_Plugin_Manager[]
38
+ */
39
+ private static $_instances = array();
40
+ /**
41
+ * @var FS_Logger
42
+ */
43
+ protected $_logger;
44
+
45
+ /**
46
+ * @param string $id
47
+ * @param string $title
48
+ * @param string $module_unique_affix
49
+ *
50
+ * @return FS_Admin_Notice_Manager
51
+ */
52
+ static function instance( $id, $title = '', $module_unique_affix = '' ) {
53
+ if ( ! isset( self::$_instances[ $id ] ) ) {
54
+ self::$_instances[ $id ] = new FS_Admin_Notice_Manager( $id, $title, $module_unique_affix );
55
+ }
56
+
57
+ return self::$_instances[ $id ];
58
+ }
59
+
60
+ protected function __construct( $id, $title = '', $module_unique_affix = '' ) {
61
+ $this->_id = $id;
62
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->_id . '_data', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
63
+ $this->_title = ! empty( $title ) ? $title : '';
64
+ $this->_module_unique_affix = $module_unique_affix;
65
+ $this->_sticky_storage = FS_Key_Value_Storage::instance( 'admin_notices', $this->_id );
66
+
67
+ if ( is_admin() ) {
68
+ if ( 0 < count( $this->_sticky_storage ) ) {
69
+ $ajax_action_suffix = str_replace( ':', '-', $this->_id );
70
+
71
+ // If there are sticky notices for the current slug, add a callback
72
+ // to the AJAX action that handles message dismiss.
73
+ add_action( "wp_ajax_fs_dismiss_notice_action_{$ajax_action_suffix}", array(
74
+ &$this,
75
+ 'dismiss_notice_ajax_callback'
76
+ ) );
77
+
78
+ foreach ( $this->_sticky_storage as $msg ) {
79
+ // Add admin notice.
80
+ $this->add(
81
+ $msg['message'],
82
+ $msg['title'],
83
+ $msg['type'],
84
+ true,
85
+ $msg['all'],
86
+ $msg['id'],
87
+ false
88
+ );
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Remove sticky message by ID.
96
+ *
97
+ * @author Vova Feldman (@svovaf)
98
+ * @since 1.0.7
99
+ *
100
+ */
101
+ function dismiss_notice_ajax_callback() {
102
+ $this->_sticky_storage->remove( $_POST['message_id'] );
103
+ wp_die();
104
+ }
105
+
106
+ /**
107
+ * Rendered sticky message dismiss JavaScript.
108
+ *
109
+ * @author Vova Feldman (@svovaf)
110
+ * @since 1.0.7
111
+ */
112
+ static function _add_sticky_dismiss_javascript() {
113
+ $params = array();
114
+ fs_require_once_template( 'sticky-admin-notice-js.php', $params );
115
+ }
116
+
117
+ private static $_added_sticky_javascript = false;
118
+
119
+ /**
120
+ * Hook to the admin_footer to add sticky message dismiss JavaScript handler.
121
+ *
122
+ * @author Vova Feldman (@svovaf)
123
+ * @since 1.0.7
124
+ */
125
+ private static function has_sticky_messages() {
126
+ if ( ! self::$_added_sticky_javascript ) {
127
+ add_action( 'admin_footer', array( 'FS_Admin_Notice_Manager', '_add_sticky_dismiss_javascript' ) );
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Handle admin_notices by printing the admin messages stacked in the queue.
133
+ *
134
+ * @author Vova Feldman (@svovaf)
135
+ * @since 1.0.4
136
+ *
137
+ */
138
+ function _admin_notices_hook() {
139
+ $notice_type = 'admin_notices';
140
+
141
+ if ( function_exists( 'current_user_can' ) &&
142
+ ! current_user_can( 'manage_options' )
143
+ ) {
144
+ // Only show messages to admins.
145
+ return;
146
+ }
147
+
148
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
149
+ return;
150
+ }
151
+
152
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
153
+ fs_require_template( 'admin-notice.php', $msg );
154
+
155
+ if ( $msg['sticky'] ) {
156
+ self::has_sticky_messages();
157
+ }
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Handle all_admin_notices by printing the admin messages stacked in the queue.
163
+ *
164
+ * @author Vova Feldman (@svovaf)
165
+ * @since 1.0.4
166
+ *
167
+ */
168
+ function _all_admin_notices_hook() {
169
+ $notice_type = 'all_admin_notices';
170
+
171
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
172
+ return;
173
+ }
174
+
175
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
176
+ fs_require_template( 'all-admin-notice.php', $msg );
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Enqueue common stylesheet to style admin notice.
182
+ *
183
+ * @author Vova Feldman (@svovaf)
184
+ * @since 1.0.7
185
+ */
186
+ function _enqueue_styles() {
187
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
188
+ }
189
+
190
+ /**
191
+ * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked.
192
+ *
193
+ * @author Vova Feldman (@svovaf)
194
+ * @since 1.0.4
195
+ *
196
+ * @param string $message
197
+ * @param string $title
198
+ * @param string $type
199
+ * @param bool $is_sticky
200
+ * @param bool $all_admin
201
+ * @param string $id Message ID
202
+ * @param bool $store_if_sticky
203
+ *
204
+ * @uses add_action()
205
+ */
206
+ function add( $message, $title = '', $type = 'success', $is_sticky = false, $all_admin = false, $id = '', $store_if_sticky = true ) {
207
+ $key = ( $all_admin ? 'all_admin_notices' : 'admin_notices' );
208
+
209
+ if ( ! isset( $this->_admin_messages[ $key ] ) ) {
210
+ $this->_admin_messages[ $key ] = array();
211
+
212
+ add_action( $key, array( &$this, "_{$key}_hook" ) );
213
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_styles' ) );
214
+
215
+ }
216
+
217
+ if ( '' === $id ) {
218
+ $id = md5( $title . ' ' . $message . ' ' . $type );
219
+ }
220
+
221
+ $message_object = array(
222
+ 'message' => $message,
223
+ 'title' => $title,
224
+ 'type' => $type,
225
+ 'sticky' => $is_sticky,
226
+ 'id' => $id,
227
+ 'all' => $all_admin,
228
+ 'manager_id' => $this->_id,
229
+ 'plugin' => $this->_title,
230
+ );
231
+
232
+ if ( $is_sticky && $store_if_sticky ) {
233
+ $this->_sticky_storage->{$id} = $message_object;
234
+ }
235
+
236
+ $this->_admin_messages[ $key ][ $id ] = $message_object;
237
+ }
238
+
239
+ /**
240
+ * @author Vova Feldman (@svovaf)
241
+ * @since 1.0.7
242
+ *
243
+ * @param string|string[] $ids
244
+ */
245
+ function remove_sticky( $ids ) {
246
+ if ( ! is_array( $ids ) ) {
247
+ $ids = array( $ids );
248
+ }
249
+
250
+ foreach ( $ids as $id ) {
251
+ // Remove from sticky storage.
252
+ $this->_sticky_storage->remove( $id );
253
+
254
+ // Remove from current admin messages.
255
+ if ( isset( $this->_admin_messages['all_admin_notices'] ) && isset( $this->_admin_messages['all_admin_notices'][ $id ] ) ) {
256
+ unset( $this->_admin_messages['all_admin_notices'][ $id ] );
257
+ }
258
+ if ( isset( $this->_admin_messages['admin_notices'] ) && isset( $this->_admin_messages['admin_notices'][ $id ] ) ) {
259
+ unset( $this->_admin_messages['admin_notices'][ $id ] );
260
+ }
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Check if sticky message exists by id.
266
+ *
267
+ * @author Vova Feldman (@svovaf)
268
+ * @since 1.0.9
269
+ *
270
+ * @param $id
271
+ *
272
+ * @return bool
273
+ */
274
+ function has_sticky( $id ) {
275
+ return isset( $this->_sticky_storage[ $id ] );
276
+ }
277
+
278
+ /**
279
+ * Adds sticky admin notification.
280
+ *
281
+ * @author Vova Feldman (@svovaf)
282
+ * @since 1.0.7
283
+ *
284
+ * @param string $message
285
+ * @param string $id Message ID
286
+ * @param string $title
287
+ * @param string $type
288
+ * @param bool $all_admin
289
+ */
290
+ function add_sticky( $message, $id, $title = '', $type = 'success', $all_admin = false ) {
291
+ if ( ! empty( $this->_module_unique_affix ) ) {
292
+ $message = fs_apply_filter( $this->_module_unique_affix, "sticky_message_{$id}", $message );
293
+ $title = fs_apply_filter( $this->_module_unique_affix, "sticky_title_{$id}", $title );
294
+ }
295
+
296
+ $this->add( $message, $title, $type, true, $all_admin, $id );
297
+ }
298
+
299
+ /**
300
+ * Clear all sticky messages.
301
+ *
302
+ * @author Vova Feldman (@svovaf)
303
+ * @since 1.0.8
304
+ */
305
+ function clear_all_sticky() {
306
+ $this->_sticky_storage->clear_all();
307
+ }
308
+
309
+ /**
310
+ * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked.
311
+ *
312
+ * @author Vova Feldman (@svovaf)
313
+ * @since 1.0.4
314
+ *
315
+ * @param string $message
316
+ * @param string $title
317
+ * @param string $type
318
+ * @param bool $is_sticky
319
+ * @param string $id Message ID
320
+ */
321
+ function add_all( $message, $title = '', $type = 'success', $is_sticky = false, $id = '' ) {
322
+ $this->add( $message, $title, $type, $is_sticky, true, $id );
323
+ }
324
+ }
freemius/includes/managers/class-fs-cache-manager.php ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.1.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Cache_Manager {
14
+ /**
15
+ * @var FS_Option_Manager
16
+ */
17
+ private $_options;
18
+ /**
19
+ * @var FS_Logger
20
+ */
21
+ private $_logger;
22
+
23
+ /**
24
+ * @var FS_Cache_Manager[]
25
+ */
26
+ private static $_MANAGERS = array();
27
+
28
+ /**
29
+ * @author Vova Feldman (@svovaf)
30
+ * @since 1.1.3
31
+ *
32
+ * @param string $id
33
+ */
34
+ private function __construct( $id ) {
35
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_cach_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
36
+
37
+ $this->_logger->entrance();
38
+ $this->_logger->log( 'id = ' . $id );
39
+
40
+ $this->_options = FS_Option_Manager::get_manager( $id, true );
41
+ }
42
+
43
+ /**
44
+ * @author Vova Feldman (@svovaf)
45
+ * @since 1.1.6
46
+ *
47
+ * @param $id
48
+ *
49
+ * @return FS_Cache_Manager
50
+ */
51
+ static function get_manager( $id ) {
52
+ $id = strtolower( $id );
53
+
54
+ if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
55
+ self::$_MANAGERS[ $id ] = new FS_Cache_Manager( $id );
56
+ }
57
+
58
+ return self::$_MANAGERS[ $id ];
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.6
64
+ *
65
+ * @return bool
66
+ */
67
+ function is_empty() {
68
+ $this->_logger->entrance();
69
+
70
+ return $this->_options->is_empty();
71
+ }
72
+
73
+ /**
74
+ * @author Vova Feldman (@svovaf)
75
+ * @since 1.1.6
76
+ */
77
+ function clear() {
78
+ $this->_logger->entrance();
79
+
80
+ $this->_options->clear( true );
81
+ }
82
+
83
+ /**
84
+ * Delete cache manager from DB.
85
+ *
86
+ * @author Vova Feldman (@svovaf)
87
+ * @since 1.0.9
88
+ */
89
+ function delete() {
90
+ $this->_options->delete();
91
+ }
92
+
93
+ /**
94
+ * Check if there's a cached item.
95
+ *
96
+ * @author Vova Feldman (@svovaf)
97
+ * @since 1.1.6
98
+ *
99
+ * @param string $key
100
+ *
101
+ * @return bool
102
+ */
103
+ function has( $key ) {
104
+ $cache_entry = $this->_options->get_option( $key, false );
105
+
106
+ return ( is_object( $cache_entry ) &&
107
+ isset( $cache_entry->timestamp ) &&
108
+ is_numeric( $cache_entry->timestamp )
109
+ );
110
+ }
111
+
112
+ /**
113
+ * Check if there's a valid cached item.
114
+ *
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.1.6
117
+ *
118
+ * @param string $key
119
+ * @param null|int $expiration Since 1.2.2.7
120
+ *
121
+ * @return bool
122
+ */
123
+ function has_valid( $key, $expiration = null ) {
124
+ $cache_entry = $this->_options->get_option( $key, false );
125
+
126
+ $is_valid = ( is_object( $cache_entry ) &&
127
+ isset( $cache_entry->timestamp ) &&
128
+ is_numeric( $cache_entry->timestamp ) &&
129
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
130
+ );
131
+
132
+ if ( $is_valid &&
133
+ is_numeric( $expiration ) &&
134
+ isset( $cache_entry->created ) &&
135
+ is_numeric( $cache_entry->created ) &&
136
+ $cache_entry->created + $expiration < WP_FS__SCRIPT_START_TIME
137
+ ) {
138
+ /**
139
+ * Even if the cache is still valid, since we are checking for validity
140
+ * with an explicit expiration period, if the period has past, return
141
+ * `false` as if the cache is invalid.
142
+ *
143
+ * @since 1.2.2.7
144
+ */
145
+ $is_valid = false;
146
+ }
147
+
148
+ return $is_valid;
149
+ }
150
+
151
+ /**
152
+ * @author Vova Feldman (@svovaf)
153
+ * @since 1.1.6
154
+ *
155
+ * @param string $key
156
+ * @param mixed $default
157
+ *
158
+ * @return mixed
159
+ */
160
+ function get( $key, $default = null ) {
161
+ $this->_logger->entrance( 'key = ' . $key );
162
+
163
+ $cache_entry = $this->_options->get_option( $key, false );
164
+
165
+ if ( is_object( $cache_entry ) &&
166
+ isset( $cache_entry->timestamp ) &&
167
+ is_numeric( $cache_entry->timestamp )
168
+ ) {
169
+ return $cache_entry->result;
170
+ }
171
+
172
+ return $default;
173
+ }
174
+
175
+ /**
176
+ * @author Vova Feldman (@svovaf)
177
+ * @since 1.1.6
178
+ *
179
+ * @param string $key
180
+ * @param mixed $default
181
+ *
182
+ * @return mixed
183
+ */
184
+ function get_valid( $key, $default = null ) {
185
+ $this->_logger->entrance( 'key = ' . $key );
186
+
187
+ $cache_entry = $this->_options->get_option( $key, false );
188
+
189
+ if ( is_object( $cache_entry ) &&
190
+ isset( $cache_entry->timestamp ) &&
191
+ is_numeric( $cache_entry->timestamp ) &&
192
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
193
+ ) {
194
+ return $cache_entry->result;
195
+ }
196
+
197
+ return $default;
198
+ }
199
+
200
+ /**
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.6
203
+ *
204
+ * @param string $key
205
+ * @param mixed $value
206
+ * @param int $expiration
207
+ */
208
+ function set( $key, $value, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
209
+ $this->_logger->entrance( 'key = ' . $key );
210
+
211
+ $cache_entry = new stdClass();
212
+ $cache_entry->result = $value;
213
+ $cache_entry->created = WP_FS__SCRIPT_START_TIME;
214
+ $cache_entry->timestamp = WP_FS__SCRIPT_START_TIME + $expiration;
215
+ $this->_options->set_option( $key, $cache_entry, true );
216
+ }
217
+
218
+ /**
219
+ * Get cached record expiration, or false if not cached or expired.
220
+ *
221
+ * @author Vova Feldman (@svovaf)
222
+ * @since 1.1.7.3
223
+ *
224
+ * @param string $key
225
+ *
226
+ * @return bool|int
227
+ */
228
+ function get_record_expiration( $key ) {
229
+ $this->_logger->entrance( 'key = ' . $key );
230
+
231
+ $cache_entry = $this->_options->get_option( $key, false );
232
+
233
+ if ( is_object( $cache_entry ) &&
234
+ isset( $cache_entry->timestamp ) &&
235
+ is_numeric( $cache_entry->timestamp ) &&
236
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
237
+ ) {
238
+ return $cache_entry->timestamp;
239
+ }
240
+
241
+ return false;
242
+ }
243
+
244
+ /**
245
+ * Purge cached item.
246
+ *
247
+ * @author Vova Feldman (@svovaf)
248
+ * @since 1.1.6
249
+ *
250
+ * @param string $key
251
+ */
252
+ function purge( $key ) {
253
+ $this->_logger->entrance( 'key = ' . $key );
254
+
255
+ $this->_options->unset_option( $key, true );
256
+ }
257
+
258
+ /**
259
+ * Set cached item as expired.
260
+ *
261
+ * @author Vova Feldman (@svovaf)
262
+ * @since 1.2.2.7
263
+ *
264
+ * @param string $key
265
+ */
266
+ function expire( $key ) {
267
+ $this->_logger->entrance( 'key = ' . $key );
268
+
269
+ $cache_entry = $this->_options->get_option( $key, false );
270
+
271
+ if ( is_object( $cache_entry ) &&
272
+ isset( $cache_entry->timestamp ) &&
273
+ is_numeric( $cache_entry->timestamp ))
274
+ {
275
+ // Set to expired.
276
+ $cache_entry->timestamp = WP_FS__SCRIPT_START_TIME;
277
+ $this->_options->set_option( $key, $cache_entry, true );
278
+ }
279
+ }
280
+ }
freemius/includes/managers/class-fs-key-value-storage.php ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Key_Value_Storage
15
+ *
16
+ * @property int $install_timestamp
17
+ * @property int $activation_timestamp
18
+ * @property int $sync_timestamp
19
+ * @property object $sync_cron
20
+ * @property int $install_sync_timestamp
21
+ * @property array $connectivity_test
22
+ * @property array $is_on
23
+ * @property object $trial_plan
24
+ * @property bool $has_trial_plan
25
+ * @property bool $trial_promotion_shown
26
+ * @property string $sdk_version
27
+ * @property string $sdk_last_version
28
+ * @property bool $sdk_upgrade_mode
29
+ * @property bool $sdk_downgrade_mode
30
+ * @property bool $plugin_upgrade_mode
31
+ * @property bool $plugin_downgrade_mode
32
+ * @property string $plugin_version
33
+ * @property string $plugin_last_version
34
+ * @property bool $is_plugin_new_install
35
+ * @property bool $was_plugin_loaded
36
+ * @property object $plugin_main_file
37
+ * @property bool $prev_is_premium
38
+ * @property array $is_anonymous
39
+ * @property bool $is_pending_activation
40
+ * @property bool $sticky_optin_added
41
+ * @property object $uninstall_reason
42
+ * @property object $subscription
43
+ */
44
+ class FS_Key_Value_Storage implements ArrayAccess, Iterator, Countable {
45
+ /**
46
+ * @var string
47
+ */
48
+ protected $_id;
49
+ /**
50
+ * @since 1.2.2
51
+ *
52
+ * @var string
53
+ */
54
+ protected $_secondary_id;
55
+ /**
56
+ * @var array
57
+ */
58
+ protected $_data;
59
+
60
+ /**
61
+ * @var FS_Plugin_Manager[]
62
+ */
63
+ private static $_instances = array();
64
+ /**
65
+ * @var FS_Logger
66
+ */
67
+ protected $_logger;
68
+
69
+ /**
70
+ * @param string $id
71
+ * @param string $secondary_id
72
+ *
73
+ * @return FS_Key_Value_Storage
74
+ */
75
+ static function instance( $id, $secondary_id ) {
76
+ $key = $id . ':' . $secondary_id;
77
+ if ( ! isset( self::$_instances[ $key ] ) ) {
78
+ self::$_instances[ $key ] = new FS_Key_Value_Storage( $id, $secondary_id );
79
+ }
80
+
81
+ return self::$_instances[ $key ];
82
+ }
83
+
84
+ protected function __construct( $id, $secondary_id ) {
85
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $secondary_id . '_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
86
+
87
+ $this->_secondary_id = $secondary_id;
88
+ $this->_id = $id;
89
+ $this->load();
90
+ }
91
+
92
+ protected function get_option_manager() {
93
+ return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
94
+ }
95
+
96
+ protected function get_all_data() {
97
+ return $this->get_option_manager()->get_option( $this->_id, array() );
98
+ }
99
+
100
+ /**
101
+ * Load plugin data from local DB.
102
+ *
103
+ * @author Vova Feldman (@svovaf)
104
+ * @since 1.0.7
105
+ */
106
+ function load() {
107
+ $all_plugins_data = $this->get_all_data();
108
+ $this->_data = isset( $all_plugins_data[ $this->_secondary_id ] ) ?
109
+ $all_plugins_data[ $this->_secondary_id ] :
110
+ array();
111
+ }
112
+
113
+ /**
114
+ * @author Vova Feldman (@svovaf)
115
+ * @since 1.0.7
116
+ *
117
+ * @param string $key
118
+ * @param mixed $value
119
+ * @param bool $flush
120
+ */
121
+ function store( $key, $value, $flush = true ) {
122
+ if ( $this->_logger->is_on() ) {
123
+ $this->_logger->entrance( $key . ' = ' . var_export( $value, true ) );
124
+ }
125
+
126
+ if ( array_key_exists( $key, $this->_data ) && $value === $this->_data[ $key ] ) {
127
+ // No need to store data if the value wasn't changed.
128
+ return;
129
+ }
130
+
131
+ $all_data = $this->get_all_data();
132
+
133
+ $this->_data[ $key ] = $value;
134
+
135
+ $all_data[ $this->_secondary_id ] = $this->_data;
136
+
137
+ $options_manager = $this->get_option_manager();
138
+ $options_manager->set_option( $this->_id, $all_data, $flush );
139
+ }
140
+
141
+ /**
142
+ * @author Vova Feldman (@svovaf)
143
+ * @since 1.0.7
144
+ *
145
+ * @param bool $store
146
+ * @param string[] $exceptions Set of keys to keep and not clear.
147
+ */
148
+ function clear_all( $store = true, $exceptions = array() ) {
149
+ $new_data = array();
150
+ foreach ( $exceptions as $key ) {
151
+ if ( isset( $this->_data[ $key ] ) ) {
152
+ $new_data[ $key ] = $this->_data[ $key ];
153
+ }
154
+ }
155
+
156
+ $this->_data = $new_data;
157
+
158
+ if ( $store ) {
159
+ $all_data = $this->get_all_data();
160
+ $all_data[ $this->_secondary_id ] = $this->_data;
161
+ $options_manager = $this->get_option_manager();
162
+ $options_manager->set_option( $this->_id, $all_data, true );
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Delete key-value storage.
168
+ *
169
+ * @author Vova Feldman (@svovaf)
170
+ * @since 1.0.9
171
+ */
172
+ function delete() {
173
+ $this->_data = array();
174
+
175
+ $all_data = $this->get_all_data();
176
+ unset( $all_data[ $this->_secondary_id ] );
177
+ $options_manager = $this->get_option_manager();
178
+ $options_manager->set_option( $this->_id, $all_data, true );
179
+ }
180
+
181
+ /**
182
+ * @author Vova Feldman (@svovaf)
183
+ * @since 1.0.7
184
+ *
185
+ * @param string $key
186
+ * @param bool $store
187
+ */
188
+ function remove( $key, $store = true ) {
189
+ if ( ! array_key_exists( $key, $this->_data ) ) {
190
+ return;
191
+ }
192
+
193
+ unset( $this->_data[ $key ] );
194
+
195
+ if ( $store ) {
196
+ $all_data = $this->get_all_data();
197
+ $all_data[ $this->_secondary_id ] = $this->_data;
198
+ $options_manager = $this->get_option_manager();
199
+ $options_manager->set_option( $this->_id, $all_data, true );
200
+ }
201
+ }
202
+
203
+ /**
204
+ * @author Vova Feldman (@svovaf)
205
+ * @since 1.0.7
206
+ *
207
+ * @param string $key
208
+ * @param mixed $default
209
+ *
210
+ * @return bool|\FS_Plugin
211
+ */
212
+ function get( $key, $default = false ) {
213
+ return array_key_exists( $key, $this->_data ) ?
214
+ $this->_data[ $key ] :
215
+ $default;
216
+ }
217
+
218
+
219
+ /* ArrayAccess + Magic Access (better for refactoring)
220
+ -----------------------------------------------------------------------------------*/
221
+ function __set( $k, $v ) {
222
+ $this->store( $k, $v );
223
+ }
224
+
225
+ function __isset( $k ) {
226
+ return array_key_exists( $k, $this->_data );
227
+ }
228
+
229
+ function __unset( $k ) {
230
+ $this->remove( $k );
231
+ }
232
+
233
+ function __get( $k ) {
234
+ return $this->get( $k, null );
235
+ }
236
+
237
+ function offsetSet( $k, $v ) {
238
+ if ( is_null( $k ) ) {
239
+ throw new Exception( 'Can\'t append value to request params.' );
240
+ } else {
241
+ $this->{$k} = $v;
242
+ }
243
+ }
244
+
245
+ function offsetExists( $k ) {
246
+ return array_key_exists( $k, $this->_data );
247
+ }
248
+
249
+ function offsetUnset( $k ) {
250
+ unset( $this->$k );
251
+ }
252
+
253
+ function offsetGet( $k ) {
254
+ return $this->get( $k, null );
255
+ }
256
+
257
+ /**
258
+ * (PHP 5 &gt;= 5.0.0)<br/>
259
+ * Return the current element
260
+ *
261
+ * @link http://php.net/manual/en/iterator.current.php
262
+ * @return mixed Can return any type.
263
+ */
264
+ public function current() {
265
+ return current( $this->_data );
266
+ }
267
+
268
+ /**
269
+ * (PHP 5 &gt;= 5.0.0)<br/>
270
+ * Move forward to next element
271
+ *
272
+ * @link http://php.net/manual/en/iterator.next.php
273
+ * @return void Any returned value is ignored.
274
+ */
275
+ public function next() {
276
+ next( $this->_data );
277
+ }
278
+
279
+ /**
280
+ * (PHP 5 &gt;= 5.0.0)<br/>
281
+ * Return the key of the current element
282
+ *
283
+ * @link http://php.net/manual/en/iterator.key.php
284
+ * @return mixed scalar on success, or null on failure.
285
+ */
286
+ public function key() {
287
+ return key( $this->_data );
288
+ }
289
+
290
+ /**
291
+ * (PHP 5 &gt;= 5.0.0)<br/>
292
+ * Checks if current position is valid
293
+ *
294
+ * @link http://php.net/manual/en/iterator.valid.php
295
+ * @return boolean The return value will be casted to boolean and then evaluated.
296
+ * Returns true on success or false on failure.
297
+ */
298
+ public function valid() {
299
+ $key = key( $this->_data );
300
+
301
+ return ( $key !== null && $key !== false );
302
+ }
303
+
304
+ /**
305
+ * (PHP 5 &gt;= 5.0.0)<br/>
306
+ * Rewind the Iterator to the first element
307
+ *
308
+ * @link http://php.net/manual/en/iterator.rewind.php
309
+ * @return void Any returned value is ignored.
310
+ */
311
+ public function rewind() {
312
+ reset( $this->_data );
313
+ }
314
+
315
+ /**
316
+ * (PHP 5 &gt;= 5.1.0)<br/>
317
+ * Count elements of an object
318
+ *
319
+ * @link http://php.net/manual/en/countable.count.php
320
+ * @return int The custom count as an integer.
321
+ * </p>
322
+ * <p>
323
+ * The return value is cast to an integer.
324
+ */
325
+ public function count() {
326
+ return count( $this->_data );
327
+ }
328
+ }
freemius/includes/managers/class-fs-license-manager.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_License_Manager /*extends FS_Abstract_Manager*/
14
+ {
15
+ //
16
+ //
17
+ // /**
18
+ // * @var FS_License_Manager[]
19
+ // */
20
+ // private static $_instances = array();
21
+ //
22
+ // static function instance( Freemius $fs ) {
23
+ // $slug = strtolower( $fs->get_slug() );
24
+ //
25
+ // if ( ! isset( self::$_instances[ $slug ] ) ) {
26
+ // self::$_instances[ $slug ] = new FS_License_Manager( $slug, $fs );
27
+ // }
28
+ //
29
+ // return self::$_instances[ $slug ];
30
+ // }
31
+ //
32
+ //// private function __construct($slug) {
33
+ //// parent::__construct($slug);
34
+ //// }
35
+ //
36
+ // function entry_id() {
37
+ // return 'licenses';
38
+ // }
39
+ //
40
+ // function sync( $id ) {
41
+ //
42
+ // }
43
+ //
44
+ // /**
45
+ // * @author Vova Feldman (@svovaf)
46
+ // * @since 1.0.5
47
+ // * @uses FS_Api
48
+ // *
49
+ // * @param number|bool $plugin_id
50
+ // *
51
+ // * @return FS_Plugin_License[]|stdClass Licenses or API error.
52
+ // */
53
+ // function api_get_user_plugin_licenses( $plugin_id = false ) {
54
+ // $api = $this->_fs->get_api_user_scope();
55
+ //
56
+ // if ( ! is_numeric( $plugin_id ) ) {
57
+ // $plugin_id = $this->_fs->get_id();
58
+ // }
59
+ //
60
+ // $result = $api->call( "/plugins/{$plugin_id}/licenses.json" );
61
+ //
62
+ // if ( ! isset( $result->error ) ) {
63
+ // for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
64
+ // $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
65
+ // }
66
+ //
67
+ // $result = $result->licenses;
68
+ // }
69
+ //
70
+ // return $result;
71
+ // }
72
+ //
73
+ // function api_get_many() {
74
+ //
75
+ // }
76
+ //
77
+ // function api_activate( $id ) {
78
+ //
79
+ // }
80
+ //
81
+ // function api_deactivate( $id ) {
82
+ //
83
+ // }
84
+
85
+ /**
86
+ * @param FS_Plugin_License[] $licenses
87
+ *
88
+ * @return bool
89
+ */
90
+ static function has_premium_license( $licenses ) {
91
+ if ( is_array( $licenses ) ) {
92
+ foreach ( $licenses as $license ) {
93
+ /**
94
+ * @var FS_Plugin_License $license
95
+ */
96
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
97
+ return true;
98
+ }
99
+ }
100
+ }
101
+
102
+ return false;
103
+ }
104
+ }
freemius/includes/managers/class-fs-option-manager.php ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * 3-layer lazy options manager.
15
+ * layer 3: Memory
16
+ * layer 2: Cache (if there's any caching plugin and if WP_FS__DEBUG_SDK is FALSE)
17
+ * layer 1: Database (options table). All options stored as one option record in the DB to reduce number of DB
18
+ * queries.
19
+ *
20
+ * If load() is not explicitly called, starts as empty manager. Same thing about saving the data - you have to
21
+ * explicitly call store().
22
+ *
23
+ * Class Freemius_Option_Manager
24
+ */
25
+ class FS_Option_Manager {
26
+ /**
27
+ * @var string
28
+ */
29
+ private $_id;
30
+ /**
31
+ * @var array
32
+ */
33
+ private $_options;
34
+ /**
35
+ * @var FS_Logger
36
+ */
37
+ private $_logger;
38
+
39
+ /**
40
+ * @var FS_Option_Manager[]
41
+ */
42
+ private static $_MANAGERS = array();
43
+
44
+ /**
45
+ * @author Vova Feldman (@svovaf)
46
+ * @since 1.0.3
47
+ *
48
+ * @param string $id
49
+ * @param bool $load
50
+ */
51
+ private function __construct( $id, $load = false ) {
52
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_opt_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
53
+
54
+ $this->_logger->entrance();
55
+ $this->_logger->log( 'id = ' . $id );
56
+
57
+ $this->_id = $id;
58
+
59
+ if ( $load ) {
60
+ $this->load();
61
+ }
62
+ }
63
+
64
+ /**
65
+ * @author Vova Feldman (@svovaf)
66
+ * @since 1.0.3
67
+ *
68
+ * @param $id
69
+ * @param $load
70
+ *
71
+ * @return FS_Option_Manager
72
+ */
73
+ static function get_manager( $id, $load = false ) {
74
+ $id = strtolower( $id );
75
+
76
+ if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
77
+ self::$_MANAGERS[ $id ] = new FS_Option_Manager( $id, $load );
78
+ } // If load required but not yet loaded, load.
79
+ else if ( $load && ! self::$_MANAGERS[ $id ]->is_loaded() ) {
80
+ self::$_MANAGERS[ $id ]->load();
81
+ }
82
+
83
+ return self::$_MANAGERS[ $id ];
84
+ }
85
+
86
+ private function _get_option_manager_name() {
87
+ // return WP_FS__SLUG . '_' . $this->_id;
88
+ return $this->_id;
89
+ }
90
+
91
+ /**
92
+ * @author Vova Feldman (@svovaf)
93
+ * @since 1.0.3
94
+ *
95
+ * @param bool $flush
96
+ */
97
+ function load( $flush = false ) {
98
+ $this->_logger->entrance();
99
+
100
+ $option_name = $this->_get_option_manager_name();
101
+
102
+ if ( $flush || ! isset( $this->_options ) ) {
103
+ if ( isset( $this->_options ) ) {
104
+ // Clear prev options.
105
+ $this->clear();
106
+ }
107
+
108
+ if ( ! WP_FS__DEBUG_SDK ) {
109
+ $this->_options = wp_cache_get( $option_name, WP_FS__SLUG );
110
+ }
111
+
112
+ // $this->_logger->info('wp_cache_get = ' . var_export($this->_options, true));
113
+
114
+ // if ( is_array( $this->_options ) ) {
115
+ // $this->clear();
116
+ // }
117
+
118
+ $cached = true;
119
+
120
+ if ( empty( $this->_options ) ) {
121
+ $this->_options = get_option( $option_name );
122
+
123
+ if ( is_string( $this->_options ) ) {
124
+ $this->_options = json_decode( $this->_options );
125
+ }
126
+
127
+ // $this->_logger->info('get_option = ' . var_export($this->_options, true));
128
+
129
+ if ( false === $this->_options ) {
130
+ $this->clear();
131
+ }
132
+
133
+ $cached = false;
134
+ }
135
+
136
+ if ( ! WP_FS__DEBUG_SDK && ! $cached ) // Set non encoded cache.
137
+ {
138
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
139
+ }
140
+ }
141
+ }
142
+
143
+ /**
144
+ * @author Vova Feldman (@svovaf)
145
+ * @since 1.0.3
146
+ *
147
+ * @return bool
148
+ */
149
+ function is_loaded() {
150
+ return isset( $this->_options );
151
+ }
152
+
153
+ /**
154
+ * @author Vova Feldman (@svovaf)
155
+ * @since 1.0.3
156
+ *
157
+ * @return bool
158
+ */
159
+ function is_empty() {
160
+ return ( $this->is_loaded() && false === $this->_options );
161
+ }
162
+
163
+ /**
164
+ * @author Vova Feldman (@svovaf)
165
+ * @since 1.0.6
166
+ *
167
+ * @param bool $flush
168
+ */
169
+ function clear( $flush = false ) {
170
+ $this->_logger->entrance();
171
+
172
+ $this->_options = array();
173
+
174
+ if ( $flush ) {
175
+ $this->store();
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Delete options manager from DB.
181
+ *
182
+ * @author Vova Feldman (@svovaf)
183
+ * @since 1.0.9
184
+ */
185
+ function delete() {
186
+ delete_option( $this->_get_option_manager_name() );
187
+ }
188
+
189
+ /**
190
+ * @author Vova Feldman (@svovaf)
191
+ * @since 1.0.6
192
+ *
193
+ * @param string $option
194
+ *
195
+ * @return bool
196
+ */
197
+ function has_option( $option ) {
198
+ return array_key_exists( $option, $this->_options );
199
+ }
200
+
201
+ /**
202
+ * @author Vova Feldman (@svovaf)
203
+ * @since 1.0.3
204
+ *
205
+ * @param string $option
206
+ * @param mixed $default
207
+ *
208
+ * @return mixed
209
+ */
210
+ function get_option( $option, $default = null ) {
211
+ $this->_logger->entrance( 'option = ' . $option );
212
+
213
+ if ( is_array( $this->_options ) ) {
214
+ return isset( $this->_options[ $option ] ) ? $this->_options[ $option ] : $default;
215
+ } else if ( is_object( $this->_options ) ) {
216
+ return isset( $this->_options->{$option} ) ? $this->_options->{$option} : $default;
217
+ }
218
+
219
+ return $default;
220
+ }
221
+
222
+ /**
223
+ * @author Vova Feldman (@svovaf)
224
+ * @since 1.0.3
225
+ *
226
+ * @param string $option
227
+ * @param mixed $value
228
+ * @param bool $flush
229
+ */
230
+ function set_option( $option, $value, $flush = false ) {
231
+ $this->_logger->entrance( 'option = ' . $option );
232
+
233
+ if ( ! $this->is_loaded() ) {
234
+ $this->clear();
235
+ }
236
+
237
+ if ( is_array( $this->_options ) ) {
238
+ $this->_options[ $option ] = $value;
239
+ } else if ( is_object( $this->_options ) ) {
240
+ $this->_options->{$option} = $value;
241
+ }
242
+
243
+ if ( $flush ) {
244
+ $this->store();
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Unset option.
250
+ *
251
+ * @author Vova Feldman (@svovaf)
252
+ * @since 1.0.3
253
+ *
254
+ * @param string $option
255
+ * @param bool $flush
256
+ */
257
+ function unset_option( $option, $flush = false ) {
258
+ $this->_logger->entrance( 'option = ' . $option );
259
+
260
+ if ( is_array( $this->_options ) ) {
261
+ if ( ! isset( $this->_options[ $option ] ) ) {
262
+ return;
263
+ }
264
+
265
+ unset( $this->_options[ $option ] );
266
+
267
+ } else if ( is_object( $this->_options ) ) {
268
+ if ( ! isset( $this->_options->{$option} ) ) {
269
+ return;
270
+ }
271
+
272
+ unset( $this->_options->{$option} );
273
+ }
274
+
275
+ if ( $flush ) {
276
+ $this->store();
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Dump options to database.
282
+ *
283
+ * @author Vova Feldman (@svovaf)
284
+ * @since 1.0.3
285
+ */
286
+ function store() {
287
+ $this->_logger->entrance();
288
+
289
+ $option_name = $this->_get_option_manager_name();
290
+
291
+ if ( $this->_logger->is_on() ) {
292
+ $this->_logger->info( $option_name . ' = ' . var_export( $this->_options, true ) );
293
+ }
294
+
295
+ // Update DB.
296
+ update_option( $option_name, $this->_options );
297
+
298
+ if ( ! WP_FS__DEBUG_SDK ) {
299
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
300
+ }
301
+ }
302
+ }
freemius/includes/managers/class-fs-plan-manager.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plan_Manager {
14
+ /**
15
+ * @var FS_Plan_Manager
16
+ */
17
+ private static $_instance;
18
+
19
+ /**
20
+ * @return FS_Plan_Manager
21
+ */
22
+ static function instance() {
23
+ if ( ! isset( self::$_instance ) ) {
24
+ self::$_instance = new FS_Plan_Manager();
25
+ }
26
+
27
+ return self::$_instance;
28
+ }
29
+
30
+ private function __construct() {
31
+ }
32
+
33
+ /**
34
+ * @param FS_Plugin_License[] $licenses
35
+ *
36
+ * @return bool
37
+ */
38
+ function has_premium_license( $licenses ) {
39
+ if ( is_array( $licenses ) ) {
40
+ /**
41
+ * @var FS_Plugin_License[] $licenses
42
+ */
43
+ foreach ( $licenses as $license ) {
44
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
45
+ return true;
46
+ }
47
+ }
48
+ }
49
+
50
+ return false;
51
+ }
52
+
53
+ /**
54
+ * Check if plugin has any paid plans.
55
+ *
56
+ * @author Vova Feldman (@svovaf)
57
+ * @since 1.0.7
58
+ *
59
+ * @param FS_Plugin_Plan[] $plans
60
+ *
61
+ * @return bool
62
+ */
63
+ function has_paid_plan( $plans ) {
64
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
65
+ return false;
66
+ }
67
+
68
+ /**
69
+ * @var FS_Plugin_Plan[] $plans
70
+ */
71
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
72
+ if ( ! $plans[ $i ]->is_free() ) {
73
+ return true;
74
+ }
75
+ }
76
+
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * Check if plugin has any free plan, or is it premium only.
82
+ *
83
+ * Note: If no plans configured, assume plugin is free.
84
+ *
85
+ * @author Vova Feldman (@svovaf)
86
+ * @since 1.0.7
87
+ *
88
+ * @param FS_Plugin_Plan[] $plans
89
+ *
90
+ * @return bool
91
+ */
92
+ function has_free_plan( $plans ) {
93
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
94
+ return true;
95
+ }
96
+
97
+ /**
98
+ * @var FS_Plugin_Plan[] $plans
99
+ */
100
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
101
+ if ( $plans[ $i ]->is_free() ) {
102
+ return true;
103
+ }
104
+ }
105
+
106
+ return false;
107
+ }
108
+
109
+ /**
110
+ * Find all plans that have trial.
111
+ *
112
+ * @author Vova Feldman (@svovaf)
113
+ * @since 1.0.9
114
+ *
115
+ * @param FS_Plugin_Plan[] $plans
116
+ *
117
+ * @return FS_Plugin_Plan[]
118
+ */
119
+ function get_trial_plans( $plans ) {
120
+ $trial_plans = array();
121
+
122
+ if ( is_array( $plans ) && 0 < count( $plans ) ) {
123
+ /**
124
+ * @var FS_Plugin_Plan[] $plans
125
+ */
126
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
127
+ if ( $plans[ $i ]->has_trial() ) {
128
+ $trial_plans[] = $plans[ $i ];
129
+ }
130
+ }
131
+ }
132
+
133
+ return $trial_plans;
134
+ }
135
+
136
+ /**
137
+ * Check if plugin has any trial plan.
138
+ *
139
+ * @author Vova Feldman (@svovaf)
140
+ * @since 1.0.9
141
+ *
142
+ * @param FS_Plugin_Plan[] $plans
143
+ *
144
+ * @return bool
145
+ */
146
+ function has_trial_plan( $plans ) {
147
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
148
+ return true;
149
+ }
150
+
151
+ /**
152
+ * @var FS_Plugin_Plan[] $plans
153
+ */
154
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
155
+ if ( $plans[ $i ]->has_trial() ) {
156
+ return true;
157
+ }
158
+ }
159
+
160
+ return false;
161
+ }
162
+ }
freemius/includes/managers/class-fs-plugin-manager.php ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Manager {
14
+ /**
15
+ * @since 1.2.2
16
+ *
17
+ * @var string|number
18
+ */
19
+ protected $_module_id;
20
+ /**
21
+ * @since 1.2.2
22
+ *
23
+ * @var FS_Plugin
24
+ */
25
+ protected $_module;
26
+
27
+ /**
28
+ * @var FS_Plugin_Manager[]
29
+ */
30
+ private static $_instances = array();
31
+ /**
32
+ * @var FS_Logger
33
+ */
34
+ protected $_logger;
35
+
36
+ /**
37
+ * Option names
38
+ *
39
+ * @author Leo Fajardo (@leorw)
40
+ * @since 1.2.2
41
+ */
42
+ const OPTION_NAME_PLUGINS = 'plugins';
43
+ const OPTION_NAME_THEMES = 'themes';
44
+
45
+ /**
46
+ * @param string|number $module_id
47
+ *
48
+ * @return FS_Plugin_Manager
49
+ */
50
+ static function instance( $module_id ) {
51
+ $key = 'm_' . $module_id;
52
+
53
+ if ( ! isset( self::$_instances[ $key ] ) ) {
54
+ self::$_instances[ $key ] = new FS_Plugin_Manager( $module_id );
55
+ }
56
+
57
+ return self::$_instances[ $key ];
58
+ }
59
+
60
+ /**
61
+ * @param string|number $module_id
62
+ */
63
+ protected function __construct( $module_id ) {
64
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $module_id . '_' . 'plugins', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
65
+ $this->_module_id = $module_id;
66
+
67
+ $this->load();
68
+ }
69
+
70
+ protected function get_option_manager() {
71
+ return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
72
+ }
73
+
74
+ /**
75
+ * @author Leo Fajardo (@leorw)
76
+ * @since 1.2.2
77
+ *
78
+ * @param string|false $module_type "plugin", "theme", or "false" for all modules.
79
+ *
80
+ * @return array
81
+ */
82
+ protected function get_all_modules( $module_type = false ) {
83
+ $option_manager = $this->get_option_manager();
84
+
85
+ if ( false !== $module_type ) {
86
+ return $option_manager->get_option( $module_type . 's', array() );
87
+ }
88
+
89
+ return array(
90
+ self::OPTION_NAME_PLUGINS => $option_manager->get_option( self::OPTION_NAME_PLUGINS, array() ),
91
+ self::OPTION_NAME_THEMES => $option_manager->get_option( self::OPTION_NAME_THEMES, array() ),
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Load plugin data from local DB.
97
+ *
98
+ * @author Vova Feldman (@svovaf)
99
+ * @since 1.0.6
100
+ */
101
+ function load() {
102
+ $all_modules = $this->get_all_modules();
103
+
104
+ if ( ! is_numeric( $this->_module_id ) ) {
105
+ unset( $all_modules[ self::OPTION_NAME_THEMES ] );
106
+ }
107
+
108
+ foreach ( $all_modules as $modules ) {
109
+ /**
110
+ * @since 1.2.2
111
+ *
112
+ * @var $modules FS_Plugin[]
113
+ */
114
+ foreach ( $modules as $module ) {
115
+ $found_module = false;
116
+
117
+ /**
118
+ * If module ID is not numeric, it must be a plugin's slug.
119
+ *
120
+ * @author Leo Fajardo (@leorw)
121
+ * @since 1.2.2
122
+ */
123
+ if ( ! is_numeric( $this->_module_id ) ) {
124
+ if ( $this->_module_id === $module->slug ) {
125
+ $this->_module_id = $module->id;
126
+ $found_module = true;
127
+ }
128
+ } else if ( $this->_module_id == $module->id ) {
129
+ $found_module = true;
130
+ }
131
+
132
+ if ( $found_module ) {
133
+ $this->_module = $module;
134
+ break;
135
+ }
136
+ }
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Store plugin on local DB.
142
+ *
143
+ * @author Vova Feldman (@svovaf)
144
+ * @since 1.0.6
145
+ *
146
+ * @param bool|FS_Plugin $module
147
+ * @param bool $flush
148
+ *
149
+ * @return bool|\FS_Plugin
150
+ */
151
+ function store( $module = false, $flush = true ) {
152
+ if ( false !== $module ) {
153
+ $this->_module = $module;
154
+ }
155
+
156
+ $all_modules = $this->get_all_modules( $this->_module->type );
157
+ $all_modules[ $this->_module->slug ] = $this->_module;
158
+
159
+ $options_manager = $this->get_option_manager();
160
+ $options_manager->set_option( $this->_module->type . 's', $all_modules, $flush );
161
+
162
+ return $this->_module;
163
+ }
164
+
165
+ /**
166
+ * Update local plugin data if different.
167
+ *
168
+ * @author Vova Feldman (@svovaf)
169
+ * @since 1.0.6
170
+ *
171
+ * @param \FS_Plugin $plugin
172
+ * @param bool $store
173
+ *
174
+ * @return bool True if plugin was updated.
175
+ */
176
+ function update( FS_Plugin $plugin, $store = true ) {
177
+ if ( ! ($this->_module instanceof FS_Plugin ) ||
178
+ $this->_module->slug != $plugin->slug ||
179
+ $this->_module->public_key != $plugin->public_key ||
180
+ $this->_module->secret_key != $plugin->secret_key ||
181
+ $this->_module->parent_plugin_id != $plugin->parent_plugin_id ||
182
+ $this->_module->title != $plugin->title
183
+ ) {
184
+ $this->store( $plugin, $store );
185
+
186
+ return true;
187
+ }
188
+
189
+ return false;
190
+ }
191
+
192
+ /**
193
+ * @author Vova Feldman (@svovaf)
194
+ * @since 1.0.6
195
+ *
196
+ * @param FS_Plugin $plugin
197
+ * @param bool $store
198
+ */
199
+ function set( FS_Plugin $plugin, $store = false ) {
200
+ $this->_module = $plugin;
201
+
202
+ if ( $store ) {
203
+ $this->store();
204
+ }
205
+ }
206
+
207
+ /**
208
+ * @author Vova Feldman (@svovaf)
209
+ * @since 1.0.6
210
+ *
211
+ * @return bool|\FS_Plugin
212
+ */
213
+ function get() {
214
+ return isset( $this->_module ) ?
215
+ $this->_module :
216
+ false;
217
+ }
218
+
219
+
220
+ }
freemius/includes/managers/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/includes/sdk/Exceptions/ArgumentNotExistException.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
3
+ exit;
4
+ }
5
+
6
+ if ( ! class_exists( 'Freemius_ArgumentNotExistException' ) ) {
7
+ class Freemius_ArgumentNotExistException extends Freemius_InvalidArgumentException {
8
+ }
9
+ }
freemius/includes/sdk/Exceptions/EmptyArgumentException.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
3
+ exit;
4
+ }
5
+
6
+ if ( ! class_exists( 'Freemius_EmptyArgumentException' ) ) {
7
+ class Freemius_EmptyArgumentException extends Freemius_InvalidArgumentException {
8
+ }
9
+ }
freemius/includes/sdk/Exceptions/Exception.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_Exception' ) ) {
3
+ /**
4
+ * Thrown when an API call returns an exception.
5
+ *
6
+ */
7
+ class Freemius_Exception extends Exception {
8
+ protected $_result;
9
+ protected $_type;
10
+ protected $_code;
11
+
12
+ /**
13
+ * Make a new API Exception with the given result.
14
+ *
15
+ * @param array $result The result from the API server.
16
+ */
17
+ public function __construct( $result ) {
18
+ $this->_result = $result;
19
+
20
+ $code = 0;
21
+ $message = 'Unknown error, please check GetResult().';
22
+ $type = '';
23
+
24
+ if ( isset( $result['error'] ) && is_array( $result['error'] ) ) {
25
+ if ( isset( $result['error']['code'] ) ) {
26
+ $code = $result['error']['code'];
27
+ }
28
+ if ( isset( $result['error']['message'] ) ) {
29
+ $message = $result['error']['message'];
30
+ }
31
+ if ( isset( $result['error']['type'] ) ) {
32
+ $type = $result['error']['type'];
33
+ }
34
+ }
35
+
36
+ $this->_type = $type;
37
+ $this->_code = $code;
38
+
39
+ parent::__construct( $message, is_numeric( $code ) ? $code : 0 );
40
+ }
41
+
42
+ /**
43
+ * Return the associated result object returned by the API server.
44
+ *
45
+ * @return array The result from the API server
46
+ */
47
+ public function getResult() {
48
+ return $this->_result;
49
+ }
50
+
51
+ public function getStringCode() {
52
+ return $this->_code;
53
+ }
54
+
55
+ public function getType() {
56
+ return $this->_type;
57
+ }
58
+
59
+ /**
60
+ * To make debugging easier.
61
+ *
62
+ * @return string The string representation of the error
63
+ */
64
+ public function __toString() {
65
+ $str = $this->getType() . ': ';
66
+
67
+ if ( $this->code != 0 ) {
68
+ $str .= $this->getStringCode() . ': ';
69
+ }
70
+
71
+ return $str . $this->getMessage();
72
+ }
73
+ }
74
+ }
freemius/includes/sdk/Exceptions/InvalidArgumentException.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_Exception' ) ) {
3
+ exit;
4
+ }
5
+
6
+ if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
7
+ class Freemius_InvalidArgumentException extends Freemius_Exception { }
8
+ }
freemius/includes/sdk/Exceptions/OAuthException.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_Exception' ) ) {
3
+ exit;
4
+ }
5
+
6
+ if ( ! class_exists( 'Freemius_OAuthException' ) ) {
7
+ class Freemius_OAuthException extends Freemius_Exception {
8
+ public function __construct( $pResult ) {
9
+ parent::__construct( $pResult );
10
+ }
11
+ }
12
+ }
freemius/includes/sdk/Exceptions/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/includes/sdk/FreemiusBase.php ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2014 Freemius, Inc.
4
+ *
5
+ * Licensed under the GPL v2 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://choosealicense.com/licenses/gpl-v2/
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ if ( ! defined( 'FS_API__VERSION' ) ) {
19
+ define( 'FS_API__VERSION', '1' );
20
+ }
21
+ if ( ! defined( 'FS_SDK__PATH' ) ) {
22
+ define( 'FS_SDK__PATH', dirname( __FILE__ ) );
23
+ }
24
+ if ( ! defined( 'FS_SDK__EXCEPTIONS_PATH' ) ) {
25
+ define( 'FS_SDK__EXCEPTIONS_PATH', FS_SDK__PATH . '/Exceptions/' );
26
+ }
27
+
28
+ if ( ! function_exists( 'json_decode' ) ) {
29
+ throw new Exception( 'Freemius needs the JSON PHP extension.' );
30
+ }
31
+
32
+ // Include all exception files.
33
+ $exceptions = array(
34
+ 'Exception',
35
+ 'InvalidArgumentException',
36
+ 'ArgumentNotExistException',
37
+ 'EmptyArgumentException',
38
+ 'OAuthException'
39
+ );
40
+
41
+ foreach ( $exceptions as $e ) {
42
+ require_once FS_SDK__EXCEPTIONS_PATH . $e . '.php';
43
+ }
44
+
45
+ if ( class_exists( 'Freemius_Api_Base' ) ) {
46
+ return;
47
+ }
48
+
49
+ abstract class Freemius_Api_Base {
50
+ const VERSION = '1.0.4';
51
+ const FORMAT = 'json';
52
+
53
+ protected $_id;
54
+ protected $_public;
55
+ protected $_secret;
56
+ protected $_scope;
57
+ protected $_isSandbox;
58
+
59
+ /**
60
+ * @param string $pScope 'app', 'developer', 'plugin', 'user' or 'install'.
61
+ * @param number $pID Element's id.
62
+ * @param string $pPublic Public key.
63
+ * @param string $pSecret Element's secret key.
64
+ * @param bool $pIsSandbox Whether or not to run API in sandbox mode.
65
+ */
66
+ public function Init( $pScope, $pID, $pPublic, $pSecret, $pIsSandbox = false ) {
67
+ $this->_id = $pID;
68
+ $this->_public = $pPublic;
69
+ $this->_secret = $pSecret;
70
+ $this->_scope = $pScope;
71
+ $this->_isSandbox = $pIsSandbox;
72
+ }
73
+
74
+ public function IsSandbox() {
75
+ return $this->_isSandbox;
76
+ }
77
+
78
+ function CanonizePath( $pPath ) {
79
+ $pPath = trim( $pPath, '/' );
80
+ $query_pos = strpos( $pPath, '?' );
81
+ $query = '';
82
+
83
+ if ( false !== $query_pos ) {
84
+ $query = substr( $pPath, $query_pos );
85
+ $pPath = substr( $pPath, 0, $query_pos );
86
+ }
87
+
88
+ // Trim '.json' suffix.
89
+ $format_length = strlen( '.' . self::FORMAT );
90
+ $start = $format_length * ( - 1 ); //negative
91
+ if ( substr( strtolower( $pPath ), $start ) === ( '.' . self::FORMAT ) ) {
92
+ $pPath = substr( $pPath, 0, strlen( $pPath ) - $format_length );
93
+ }
94
+
95
+ switch ( $this->_scope ) {
96
+ case 'app':
97
+ $base = '/apps/' . $this->_id;
98
+ break;
99
+ case 'developer':
100
+ $base = '/developers/' . $this->_id;
101
+ break;
102
+ case 'user':
103
+ $base = '/users/' . $this->_id;
104
+ break;
105
+ case 'plugin':
106
+ $base = '/plugins/' . $this->_id;
107
+ break;
108
+ case 'install':
109
+ $base = '/installs/' . $this->_id;
110
+ break;
111
+ default:
112
+ throw new Freemius_Exception( 'Scope not implemented.' );
113
+ }
114
+
115
+ return '/v' . FS_API__VERSION . $base .
116
+ ( ! empty( $pPath ) ? '/' : '' ) . $pPath .
117
+ ( ( false === strpos( $pPath, '.' ) ) ? '.' . self::FORMAT : '' ) . $query;
118
+ }
119
+
120
+ abstract function MakeRequest( $pCanonizedPath, $pMethod = 'GET', $pParams = array() );
121
+
122
+ /**
123
+ * @param string $pPath
124
+ * @param string $pMethod
125
+ * @param array $pParams
126
+ *
127
+ * @return object[]|object|null
128
+ */
129
+ private function _Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
130
+ $pMethod = strtoupper( $pMethod );
131
+
132
+ try {
133
+ $result = $this->MakeRequest( $pPath, $pMethod, $pParams );
134
+ } catch ( Freemius_Exception $e ) {
135
+ // Map to error object.
136
+ $result = (object) $e->getResult();
137
+ } catch ( Exception $e ) {
138
+ // Map to error object.
139
+ $result = (object) array(
140
+ 'error' => array(
141
+ 'type' => 'Unknown',
142
+ 'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
143
+ 'code' => 'unknown',
144
+ 'http' => 402
145
+ )
146
+ );
147
+ }
148
+
149
+ return $result;
150
+ }
151
+
152
+ public function Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
153
+ return $this->_Api( $this->CanonizePath( $pPath ), $pMethod, $pParams );
154
+ }
155
+
156
+ /**
157
+ * Base64 decoding that does not need to be urldecode()-ed.
158
+ *
159
+ * Exactly the same as PHP base64 encode except it uses
160
+ * `-` instead of `+`
161
+ * `_` instead of `/`
162
+ * No padded =
163
+ *
164
+ * @param string $input Base64UrlEncoded() string
165
+ *
166
+ * @return string
167
+ */
168
+ protected static function Base64UrlDecode( $input ) {
169
+ /**
170
+ * IMPORTANT NOTE:
171
+ * This is a hack suggested by @otto42 and @greenshady from
172
+ * the theme's review team. The usage of base64 for API
173
+ * signature encoding was approved in a Slack meeting
174
+ * held on Tue (10/25 2016).
175
+ *
176
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
177
+ *
178
+ * @since 1.2.2
179
+ * @author Vova Feldman (@svovaf)
180
+ */
181
+ $fn = 'base64' . '_decode';
182
+ return $fn( strtr( $input, '-_', '+/' ) );
183
+ }
184
+
185
+ /**
186
+ * Base64 encoding that does not need to be urlencode()ed.
187
+ *
188
+ * Exactly the same as base64 encode except it uses
189
+ * `-` instead of `+
190
+ * `_` instead of `/`
191
+ *
192
+ * @param string $input string
193
+ *
194
+ * @return string Base64 encoded string
195
+ */
196
+ protected static function Base64UrlEncode( $input ) {
197
+ /**
198
+ * IMPORTANT NOTE:
199
+ * This is a hack suggested by @otto42 and @greenshady from
200
+ * the theme's review team. The usage of base64 for API
201
+ * signature encoding was approved in a Slack meeting
202
+ * held on Tue (10/25 2016).
203
+ *
204
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
205
+ *
206
+ * @since 1.2.2
207
+ * @author Vova Feldman (@svovaf)
208
+ */
209
+ $fn = 'base64' . '_encode';
210
+ $str = strtr( $fn( $input ), '+/', '-_' );
211
+ $str = str_replace( '=', '', $str );
212
+
213
+ return $str;
214
+ }
215
+ }
freemius/includes/sdk/FreemiusWordPress.php ADDED
@@ -0,0 +1,695 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2016 Freemius, Inc.
4
+ *
5
+ * Licensed under the GPL v2 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://choosealicense.com/licenses/gpl-v2/
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ require_once dirname( __FILE__ ) . '/FreemiusBase.php';
19
+
20
+ if ( ! defined( 'FS_SDK__USER_AGENT' ) ) {
21
+ define( 'FS_SDK__USER_AGENT', 'fs-php-' . Freemius_Api_Base::VERSION );
22
+ }
23
+
24
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_CURL' ) ) {
25
+ define( 'FS_SDK__SIMULATE_NO_CURL', false );
26
+ }
27
+
28
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
29
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
30
+ }
31
+
32
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
33
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
34
+ }
35
+
36
+ if ( ! defined( 'FS_SDK__HAS_CURL' ) ) {
37
+ if ( FS_SDK__SIMULATE_NO_CURL ) {
38
+ define( 'FS_SDK__HAS_CURL', false );
39
+ } else {
40
+ $curl_required_methods = array(
41
+ 'curl_version',
42
+ 'curl_exec',
43
+ 'curl_init',
44
+ 'curl_close',
45
+ 'curl_setopt',
46
+ 'curl_setopt_array',
47
+ 'curl_error',
48
+ );
49
+
50
+ $has_curl = true;
51
+ foreach ( $curl_required_methods as $m ) {
52
+ if ( ! function_exists( $m ) ) {
53
+ $has_curl = false;
54
+ break;
55
+ }
56
+ }
57
+
58
+ define( 'FS_SDK__HAS_CURL', $has_curl );
59
+ }
60
+ }
61
+
62
+ $curl_version = FS_SDK__HAS_CURL ?
63
+ curl_version() :
64
+ array( 'version' => '7.37' );
65
+
66
+ if ( ! defined( 'FS_API__PROTOCOL' ) ) {
67
+ define( 'FS_API__PROTOCOL', version_compare( $curl_version['version'], '7.37', '>=' ) ? 'https' : 'http' );
68
+ }
69
+
70
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
71
+ define( 'FS_API__LOGGER_ON', false );
72
+ }
73
+
74
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
75
+ define( 'FS_API__ADDRESS', '://api.freemius.com' );
76
+ }
77
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
78
+ define( 'FS_API__SANDBOX_ADDRESS', '://sandbox-api.freemius.com' );
79
+ }
80
+
81
+ if ( class_exists( 'Freemius_Api_WordPress' ) ) {
82
+ return;
83
+ }
84
+
85
+ class Freemius_Api_WordPress extends Freemius_Api_Base {
86
+ private static $_logger = array();
87
+
88
+ /**
89
+ * @param string $pScope 'app', 'developer', 'user' or 'install'.
90
+ * @param number $pID Element's id.
91
+ * @param string $pPublic Public key.
92
+ * @param string|bool $pSecret Element's secret key.
93
+ * @param bool $pSandbox Whether or not to run API in sandbox mode.
94
+ */
95
+ public function __construct( $pScope, $pID, $pPublic, $pSecret = false, $pSandbox = false ) {
96
+ // If secret key not provided, use public key encryption.
97
+ if ( is_bool( $pSecret ) ) {
98
+ $pSecret = $pPublic;
99
+ }
100
+
101
+ parent::Init( $pScope, $pID, $pPublic, $pSecret, $pSandbox );
102
+ }
103
+
104
+ public static function GetUrl( $pCanonizedPath = '', $pIsSandbox = false ) {
105
+ $address = ( $pIsSandbox ? FS_API__SANDBOX_ADDRESS : FS_API__ADDRESS );
106
+
107
+ if ( ':' === $address[0] ) {
108
+ $address = self::$_protocol . $address;
109
+ }
110
+
111
+ return $address . $pCanonizedPath;
112
+ }
113
+
114
+ #----------------------------------------------------------------------------------
115
+ #region Servers Clock Diff
116
+ #----------------------------------------------------------------------------------
117
+
118
+ /**
119
+ * @var int Clock diff in seconds between current server to API server.
120
+ */
121
+ private static $_clock_diff = 0;
122
+
123
+ /**
124
+ * Set clock diff for all API calls.
125
+ *
126
+ * @since 1.0.3
127
+ *
128
+ * @param $pSeconds
129
+ */
130
+ public static function SetClockDiff( $pSeconds ) {
131
+ self::$_clock_diff = $pSeconds;
132
+ }
133
+
134
+ /**
135
+ * Find clock diff between current server to API server.
136
+ *
137
+ * @since 1.0.2
138
+ * @return int Clock diff in seconds.
139
+ */
140
+ public static function FindClockDiff() {
141
+ $time = time();
142
+ $pong = self::Ping();
143
+
144
+ return ( $time - strtotime( $pong->timestamp ) );
145
+ }
146
+
147
+ #endregion
148
+
149
+ /**
150
+ * @var string http or https
151
+ */
152
+ private static $_protocol = FS_API__PROTOCOL;
153
+
154
+ /**
155
+ * Set API connection protocol.
156
+ *
157
+ * @since 1.0.4
158
+ */
159
+ public static function SetHttp() {
160
+ self::$_protocol = 'http';
161
+ }
162
+
163
+ /**
164
+ * @since 1.0.4
165
+ *
166
+ * @return bool
167
+ */
168
+ public static function IsHttps() {
169
+ return ( 'https' === self::$_protocol );
170
+ }
171
+
172
+ /**
173
+ * Sign request with the following HTTP headers:
174
+ * Content-MD5: MD5(HTTP Request body)
175
+ * Date: Current date (i.e Sat, 14 Feb 2016 20:24:46 +0000)
176
+ * Authorization: FS {scope_entity_id}:{scope_entity_public_key}:base64encode(sha256(string_to_sign,
177
+ * {scope_entity_secret_key}))
178
+ *
179
+ * @param string $pResourceUrl
180
+ * @param array $pWPRemoteArgs
181
+ *
182
+ * @return array
183
+ */
184
+ function SignRequest( $pResourceUrl, $pWPRemoteArgs ) {
185
+ $auth = $this->GenerateAuthorizationParams(
186
+ $pResourceUrl,
187
+ $pWPRemoteArgs['method'],
188
+ ! empty( $pWPRemoteArgs['body'] ) ? $pWPRemoteArgs['body'] : ''
189
+ );
190
+
191
+ $pWPRemoteArgs['headers']['Date'] = $auth['date'];
192
+ $pWPRemoteArgs['headers']['Authorization'] = $auth['authorization'];
193
+
194
+ if ( ! empty( $auth['content_md5'] ) ) {
195
+ $pWPRemoteArgs['headers']['Content-MD5'] = $auth['content_md5'];
196
+ }
197
+
198
+ return $pWPRemoteArgs;
199
+ }
200
+
201
+ /**
202
+ * Generate Authorization request headers:
203
+ *
204
+ * Content-MD5: MD5(HTTP Request body)
205
+ * Date: Current date (i.e Sat, 14 Feb 2016 20:24:46 +0000)
206
+ * Authorization: FS {scope_entity_id}:{scope_entity_public_key}:base64encode(sha256(string_to_sign,
207
+ * {scope_entity_secret_key}))
208
+ *
209
+ * @author Vova Feldman
210
+ *
211
+ * @param string $pResourceUrl
212
+ * @param string $pMethod
213
+ * @param string $pPostParams
214
+ *
215
+ * @return array
216
+ * @throws Freemius_Exception
217
+ */
218
+ function GenerateAuthorizationParams(
219
+ $pResourceUrl,
220
+ $pMethod = 'GET',
221
+ $pPostParams = ''
222
+ ) {
223
+ $pMethod = strtoupper( $pMethod );
224
+
225
+ $eol = "\n";
226
+ $content_md5 = '';
227
+ $content_type = '';
228
+ $now = ( time() - self::$_clock_diff );
229
+ $date = date( 'r', $now );
230
+
231
+ if ( in_array( $pMethod, array( 'POST', 'PUT' ) ) && ! empty( $pPostParams ) ) {
232
+ $content_md5 = md5( $pPostParams );
233
+ $content_type = 'application/json';
234
+ }
235
+
236
+ $string_to_sign = implode( $eol, array(
237
+ $pMethod,
238
+ $content_md5,
239
+ $content_type,
240
+ $date,
241
+ $pResourceUrl
242
+ ) );
243
+
244
+ // If secret and public keys are identical, it means that
245
+ // the signature uses public key hash encoding.
246
+ $auth_type = ( $this->_secret !== $this->_public ) ? 'FS' : 'FSP';
247
+
248
+ $auth = array(
249
+ 'date' => $date,
250
+ 'authorization' => $auth_type . ' ' . $this->_id . ':' .
251
+ $this->_public . ':' .
252
+ self::Base64UrlEncode( hash_hmac(
253
+ 'sha256', $string_to_sign, $this->_secret
254
+ ) )
255
+ );
256
+
257
+ if ( ! empty( $content_md5 ) ) {
258
+ $auth['content_md5'] = $content_md5;
259
+ }
260
+
261
+ return $auth;
262
+ }
263
+
264
+ /**
265
+ * Get API request URL signed via query string.
266
+ *
267
+ * @param string $pPath
268
+ *
269
+ * @throws Freemius_Exception
270
+ *
271
+ * @return string
272
+ */
273
+ function GetSignedUrl( $pPath ) {
274
+ $resource = explode( '?', $this->CanonizePath( $pPath ) );
275
+ $pResourceUrl = $resource[0];
276
+
277
+ $auth = $this->GenerateAuthorizationParams( $pResourceUrl );
278
+
279
+ return Freemius_Api_WordPress::GetUrl(
280
+ $pResourceUrl . '?' .
281
+ ( 1 < count( $resource ) && ! empty( $resource[1] ) ? $resource[1] . '&' : '' ) .
282
+ http_build_query( array(
283
+ 'auth_date' => $auth['date'],
284
+ 'authorization' => $auth['authorization']
285
+ ) ), $this->_isSandbox );
286
+ }
287
+
288
+ /**
289
+ * @author Vova Feldman
290
+ *
291
+ * @param string $pUrl
292
+ * @param array $pWPRemoteArgs
293
+ *
294
+ * @return mixed
295
+ */
296
+ private static function ExecuteRequest( $pUrl, &$pWPRemoteArgs ) {
297
+ $start = microtime( true );
298
+
299
+ $response = wp_remote_request( $pUrl, $pWPRemoteArgs );
300
+
301
+ if ( FS_API__LOGGER_ON ) {
302
+ $end = microtime( true );
303
+
304
+ $has_body = ( isset( $pWPRemoteArgs['body'] ) && ! empty( $pWPRemoteArgs['body'] ) );
305
+ $is_http_error = is_wp_error( $response );
306
+
307
+ self::$_logger[] = array(
308
+ 'id' => count( self::$_logger ),
309
+ 'start' => $start,
310
+ 'end' => $end,
311
+ 'total' => ( $end - $start ),
312
+ 'method' => $pWPRemoteArgs['method'],
313
+ 'path' => $pUrl,
314
+ 'body' => $has_body ? $pWPRemoteArgs['body'] : null,
315
+ 'result' => ! $is_http_error ?
316
+ $response['body'] :
317
+ json_encode( $response->get_error_messages() ),
318
+ 'code' => ! $is_http_error ? $response['response']['code'] : null,
319
+ 'backtrace' => debug_backtrace(),
320
+ );
321
+ }
322
+
323
+ return $response;
324
+ }
325
+
326
+ /**
327
+ * @return array
328
+ */
329
+ static function GetLogger() {
330
+ return self::$_logger;
331
+ }
332
+
333
+ /**
334
+ * @param string $pCanonizedPath
335
+ * @param string $pMethod
336
+ * @param array $pParams
337
+ * @param null|array $pWPRemoteArgs
338
+ * @param bool $pIsSandbox
339
+ * @param null|callable $pBeforeExecutionFunction
340
+ *
341
+ * @return object[]|object|null
342
+ *
343
+ * @throws \Freemius_Exception
344
+ */
345
+ private static function MakeStaticRequest(
346
+ $pCanonizedPath,
347
+ $pMethod = 'GET',
348
+ $pParams = array(),
349
+ $pWPRemoteArgs = null,
350
+ $pIsSandbox = false,
351
+ $pBeforeExecutionFunction = null
352
+ ) {
353
+ // Connectivity errors simulation.
354
+ if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
355
+ self::ThrowCloudFlareDDoSException();
356
+ } else if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
357
+ self::ThrowSquidAclException();
358
+ }
359
+
360
+ if ( empty( $pWPRemoteArgs ) ) {
361
+ $user_agent = 'Freemius/WordPress-SDK/' . Freemius_Api_Base::VERSION . '; ' .
362
+ home_url();
363
+
364
+ $pWPRemoteArgs = array(
365
+ 'method' => strtoupper( $pMethod ),
366
+ 'connect_timeout' => 10,
367
+ 'timeout' => 60,
368
+ 'follow_redirects' => true,
369
+ 'redirection' => 5,
370
+ 'user-agent' => $user_agent,
371
+ 'blocking' => true,
372
+ );
373
+ }
374
+
375
+ if ( ! isset( $pWPRemoteArgs['headers'] ) ||
376
+ ! is_array( $pWPRemoteArgs['headers'] )
377
+ ) {
378
+ $pWPRemoteArgs['headers'] = array();
379
+ }
380
+
381
+ if ( in_array( $pMethod, array( 'POST', 'PUT' ) ) ) {
382
+ if ( is_array( $pParams ) && 0 < count( $pParams ) ) {
383
+ $pWPRemoteArgs['headers']['Content-type'] = 'application/json';
384
+ $pWPRemoteArgs['body'] = json_encode( $pParams );
385
+ }
386
+ }
387
+
388
+ $request_url = self::GetUrl( $pCanonizedPath, $pIsSandbox );
389
+
390
+ $resource = explode( '?', $pCanonizedPath );
391
+
392
+ // Disable the 'Expect: 100-continue' behaviour. This causes cURL to wait
393
+ // for 2 seconds if the server does not support this header.
394
+ $pWPRemoteArgs['headers']['Expect'] = '';
395
+
396
+ if ( 'https' === substr( strtolower( $request_url ), 0, 5 ) ) {
397
+ $pWPRemoteArgs['sslverify'] = false;
398
+ }
399
+
400
+ if ( false !== $pBeforeExecutionFunction &&
401
+ is_callable( $pBeforeExecutionFunction )
402
+ ) {
403
+ $pWPRemoteArgs = call_user_func( $pBeforeExecutionFunction, $resource[0], $pWPRemoteArgs );
404
+ }
405
+
406
+ $result = self::ExecuteRequest( $request_url, $pWPRemoteArgs );
407
+
408
+ if ( is_wp_error( $result ) ) {
409
+ /**
410
+ * @var WP_Error $result
411
+ */
412
+ if ( self::IsCurlError( $result ) ) {
413
+ /**
414
+ * With dual stacked DNS responses, it's possible for a server to
415
+ * have IPv6 enabled but not have IPv6 connectivity. If this is
416
+ * the case, cURL will try IPv4 first and if that fails, then it will
417
+ * fall back to IPv6 and the error EHOSTUNREACH is returned by the
418
+ * operating system.
419
+ */
420
+ $matches = array();
421
+ $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
422
+ if ( preg_match( $regex, $result->get_error_message( 'http_request_failed' ), $matches ) ) {
423
+ if ( strlen( @inet_pton( $matches[1] ) ) === 16 ) {
424
+ // error_log('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.');
425
+ // Hook to an action triggered just before cURL is executed to resolve the IP version to v4.
426
+ add_action( 'http_api_curl', 'Freemius_Api_WordPress::CurlResolveToIPv4', 10, 1 );
427
+
428
+ // Re-run request.
429
+ $result = self::ExecuteRequest( $request_url, $pWPRemoteArgs );
430
+ }
431
+ }
432
+ }
433
+
434
+ if ( is_wp_error( $result ) ) {
435
+ self::ThrowWPRemoteException( $result );
436
+ }
437
+ }
438
+
439
+ $response_body = $result['body'];
440
+
441
+ if ( empty( $response_body ) ) {
442
+ return null;
443
+ }
444
+
445
+ $decoded = json_decode( $response_body );
446
+
447
+ if ( is_null( $decoded ) ) {
448
+ if ( preg_match( '/Please turn JavaScript on/i', $response_body ) &&
449
+ preg_match( '/text\/javascript/', $response_body )
450
+ ) {
451
+ self::ThrowCloudFlareDDoSException( $response_body );
452
+ } else if ( preg_match( '/Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect./', $response_body ) &&
453
+ preg_match( '/squid/', $response_body )
454
+ ) {
455
+ self::ThrowSquidAclException( $response_body );
456
+ } else {
457
+ $decoded = (object) array(
458
+ 'error' => (object) array(
459
+ 'type' => 'Unknown',
460
+ 'message' => $response_body,
461
+ 'code' => 'unknown',
462
+ 'http' => 402
463
+ )
464
+ );
465
+ }
466
+ }
467
+
468
+ return $decoded;
469
+ }
470
+
471
+
472
+ /**
473
+ * Makes an HTTP request. This method can be overridden by subclasses if
474
+ * developers want to do fancier things or use something other than wp_remote_request()
475
+ * to make the request.
476
+ *
477
+ * @param string $pCanonizedPath The URL to make the request to
478
+ * @param string $pMethod HTTP method
479
+ * @param array $pParams The parameters to use for the POST body
480
+ * @param null|array $pWPRemoteArgs wp_remote_request options.
481
+ *
482
+ * @return object[]|object|null
483
+ *
484
+ * @throws Freemius_Exception
485
+ */
486
+ public function MakeRequest(
487
+ $pCanonizedPath,
488
+ $pMethod = 'GET',
489
+ $pParams = array(),
490
+ $pWPRemoteArgs = null
491
+ ) {
492
+ $resource = explode( '?', $pCanonizedPath );
493
+
494
+ // Only sign request if not ping.json connectivity test.
495
+ $sign_request = ( '/v1/ping.json' !== strtolower( substr( $resource[0], - strlen( '/v1/ping.json' ) ) ) );
496
+
497
+ return self::MakeStaticRequest(
498
+ $pCanonizedPath,
499
+ $pMethod,
500
+ $pParams,
501
+ $pWPRemoteArgs,
502
+ $this->_isSandbox,
503
+ $sign_request ? array( &$this, 'SignRequest' ) : null
504
+ );
505
+ }
506
+
507
+ /**
508
+ * Sets CURLOPT_IPRESOLVE to CURL_IPRESOLVE_V4 for cURL-Handle provided as parameter
509
+ *
510
+ * @param resource $handle A cURL handle returned by curl_init()
511
+ *
512
+ * @return resource $handle A cURL handle returned by curl_init() with CURLOPT_IPRESOLVE set to
513
+ * CURL_IPRESOLVE_V4
514
+ *
515
+ * @link https://gist.github.com/golderweb/3a2aaec2d56125cc004e
516
+ */
517
+ static function CurlResolveToIPv4( $handle ) {
518
+ curl_setopt( $handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
519
+
520
+ return $handle;
521
+ }
522
+
523
+ #----------------------------------------------------------------------------------
524
+ #region Connectivity Test
525
+ #----------------------------------------------------------------------------------
526
+
527
+ /**
528
+ * If successful connectivity to the API endpoint using ping.json endpoint.
529
+ *
530
+ * - OR -
531
+ *
532
+ * Validate if ping result object is valid.
533
+ *
534
+ * @param mixed $pPong
535
+ *
536
+ * @return bool
537
+ */
538
+ public static function Test( $pPong = null ) {
539
+ $pong = is_null( $pPong ) ?
540
+ self::Ping() :
541
+ $pPong;
542
+
543
+ return (
544
+ is_object( $pong ) &&
545
+ isset( $pong->api ) &&
546
+ 'pong' === $pong->api
547
+ );
548
+ }
549
+
550
+ /**
551
+ * Ping API to test connectivity.
552
+ *
553
+ * @return object
554
+ */
555
+ public static function Ping() {
556
+ try {
557
+ $result = self::MakeStaticRequest( '/v' . FS_API__VERSION . '/ping.json' );
558
+ } catch ( Freemius_Exception $e ) {
559
+ // Map to error object.
560
+ $result = (object) $e->getResult();
561
+ } catch ( Exception $e ) {
562
+ // Map to error object.
563
+ $result = (object) array(
564
+ 'error' => array(
565
+ 'type' => 'Unknown',
566
+ 'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
567
+ 'code' => 'unknown',
568
+ 'http' => 402
569
+ )
570
+ );
571
+ }
572
+
573
+ return $result;
574
+ }
575
+
576
+ #endregion
577
+
578
+ #----------------------------------------------------------------------------------
579
+ #region Connectivity Exceptions
580
+ #----------------------------------------------------------------------------------
581
+
582
+ /**
583
+ * @param \WP_Error $pError
584
+ *
585
+ * @return bool
586
+ */
587
+ private static function IsCurlError( WP_Error $pError ) {
588
+ $message = $pError->get_error_message( 'http_request_failed' );
589
+
590
+ return ( 0 === strpos( $message, 'cURL' ) );
591
+ }
592
+
593
+ /**
594
+ * @param WP_Error $pError
595
+ *
596
+ * @throws Freemius_Exception
597
+ */
598
+ private static function ThrowWPRemoteException( WP_Error $pError ) {
599
+ if ( self::IsCurlError( $pError ) ) {
600
+ $message = $pError->get_error_message( 'http_request_failed' );
601
+
602
+ #region Check if there are any missing cURL methods.
603
+
604
+ $curl_required_methods = array(
605
+ 'curl_version',
606
+ 'curl_exec',
607
+ 'curl_init',
608
+ 'curl_close',
609
+ 'curl_setopt',
610
+ 'curl_setopt_array',
611
+ 'curl_error',
612
+ );
613
+
614
+ // Find all missing methods.
615
+ $missing_methods = array();
616
+ foreach ( $curl_required_methods as $m ) {
617
+ if ( ! function_exists( $m ) ) {
618
+ $missing_methods[] = $m;
619
+ }
620
+ }
621
+
622
+ if ( ! empty( $missing_methods ) ) {
623
+ throw new Freemius_Exception( array(
624
+ 'error' => (object) array(
625
+ 'type' => 'cUrlMissing',
626
+ 'message' => $message,
627
+ 'code' => 'curl_missing',
628
+ 'http' => 402
629
+ ),
630
+ 'missing_methods' => $missing_methods,
631
+ ) );
632
+ }
633
+
634
+ #endregion
635
+
636
+ // cURL error - "cURL error {{errno}}: {{error}}".
637
+ $parts = explode( ':', substr( $message, strlen( 'cURL error ' ) ), 2 );
638
+
639
+ $code = ( 0 < count( $parts ) ) ? $parts[0] : 'http_request_failed';
640
+ $message = ( 1 < count( $parts ) ) ? $parts[1] : $message;
641
+
642
+ $e = new Freemius_Exception( array(
643
+ 'error' => array(
644
+ 'code' => $code,
645
+ 'message' => $message,
646
+ 'type' => 'CurlException',
647
+ ),
648
+ ) );
649
+ } else {
650
+ $e = new Freemius_Exception( array(
651
+ 'error' => array(
652
+ 'code' => $pError->get_error_code(),
653
+ 'message' => $pError->get_error_message(),
654
+ 'type' => 'WPRemoteException',
655
+ ),
656
+ ) );
657
+ }
658
+
659
+ throw $e;
660
+ }
661
+
662
+ /**
663
+ * @param string $pResult
664
+ *
665
+ * @throws Freemius_Exception
666
+ */
667
+ private static function ThrowCloudFlareDDoSException( $pResult = '' ) {
668
+ throw new Freemius_Exception( array(
669
+ 'error' => (object) array(
670
+ 'type' => 'CloudFlareDDoSProtection',
671
+ 'message' => $pResult,
672
+ 'code' => 'cloudflare_ddos_protection',
673
+ 'http' => 402
674
+ )
675
+ ) );
676
+ }
677
+
678
+ /**
679
+ * @param string $pResult
680
+ *
681
+ * @throws Freemius_Exception
682
+ */
683
+ private static function ThrowSquidAclException( $pResult = '' ) {
684
+ throw new Freemius_Exception( array(
685
+ 'error' => (object) array(
686
+ 'type' => 'SquidCacheBlock',
687
+ 'message' => $pResult,
688
+ 'code' => 'squid_cache_block',
689
+ 'http' => 402
690
+ )
691
+ ) );
692
+ }
693
+
694
+ #endregion
695
+ }
freemius/includes/sdk/LICENSE.txt ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
340
+
freemius/includes/sdk/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/includes/supplements/fs-essential-functions-1.1.7.1.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.1.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Find the plugin main file path based on any give file inside the plugin's folder.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7.1
18
+ *
19
+ * @param string $file Absolute path to a file inside a plugin's folder.
20
+ *
21
+ * @return string
22
+ */
23
+ function fs_find_direct_caller_plugin_file( $file ) {
24
+ /**
25
+ * All the code below will be executed once on activation.
26
+ * If the user changes the main plugin's file name, the file_exists()
27
+ * will catch it.
28
+ */
29
+ if ( ! function_exists( 'get_plugins' ) ) {
30
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
31
+ }
32
+
33
+ $all_plugins = get_plugins();
34
+
35
+ $file_real_path = fs_normalize_path( realpath( $file ) );
36
+
37
+ // Get active plugin's main files real full names (might be symlinks).
38
+ foreach ( $all_plugins as $relative_path => &$data ) {
39
+ if ( 0 === strpos( $file_real_path, fs_normalize_path( dirname( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) ) ) ) ) {
40
+ if ( '.' !== dirname( trailingslashit( $relative_path ) ) ) {
41
+ return $relative_path;
42
+ }
43
+ }
44
+ }
45
+
46
+ return null;
47
+ }
freemius/includes/supplements/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
freemius/languages/freemius-da_DK.mo ADDED
Binary file
freemius/languages/freemius-da_DK.po ADDED
@@ -0,0 +1,1826 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2017 freemius
2
+ # This file is distributed under the same license as the freemius package.
3
+ # Translators:
4
+ # Joachim Jensen <jv@intox.dk>, 2016-2017
5
+ msgid ""
6
+ msgstr ""
7
+ "Project-Id-Version: WordPress SDK\n"
8
+ "Report-Msgid-Bugs-To: https://github.com/Freemius/wordpress-sdk/issues\n"
9
+ "POT-Creation-Date: \n"
10
+ "PO-Revision-Date: 2017-08-24 12:32+0000\n"
11
+ "Last-Translator: Vova Feldman <vova@freemius.com>\n"
12
+ "Language: da_DK\n"
13
+ "Language-Team: Danish (Denmark) (http://www.transifex.com/freemius/wordpress-sdk/language/da_DK/)\n"
14
+ "Content-Type: text/plain; charset=UTF-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
+ "MIME-Version: 1.0\n"
18
+ "X-Poedit-Basepath: ..\n"
19
+ "X-Poedit-KeywordsList: _fs_text;_fs_echo;_fs_esc_attr;_fs_esc_attr_echo;_fs_esc_html;_fs_esc_html_echo;_fs_x:1,2c;_fs_ex:1,2c;_fs_esc_attr_x:1,2c;_fs_esc_html_x:1,2c;_fs_n:1,2;_fs_n_noop:1,2;_fs_nx:1,2,4c;_fs_nx_noop:1,2,3c\n"
20
+ "X-Poedit-SearchPath-0: .\n"
21
+ "X-Poedit-SearchPathExcluded-0: *.js\n"
22
+ "X-Poedit-SourceCharset: UTF-8\n"
23
+
24
+ #: includes/i18n.php:37
25
+ msgid "Account"
26
+ msgstr "Konto"
27
+
28
+ #: includes/i18n.php:38
29
+ msgid "Add-On"
30
+ msgstr "Add-On"
31
+
32
+ #: includes/i18n.php:39
33
+ msgid "Contact Us"
34
+ msgstr "Kontakt os"
35
+
36
+ #: includes/i18n.php:40
37
+ msgid "Contact Support"
38
+ msgstr "Kontakt support"
39
+
40
+ #: includes/i18n.php:41
41
+ msgid "Change Ownership"
42
+ msgstr "Skift ejerskab"
43
+
44
+ #: includes/i18n.php:42
45
+ msgid "Support"
46
+ msgstr "Support"
47
+
48
+ #: includes/i18n.php:43
49
+ msgid "Support Forum"
50
+ msgstr "Supportforum"
51
+
52
+ #: includes/i18n.php:44
53
+ msgid "Add-Ons"
54
+ msgstr "Add-Ons"
55
+
56
+ #: includes/i18n.php:45
57
+ msgctxt "verb"
58
+ msgid "Upgrade"
59
+ msgstr "Opgrader"
60
+
61
+ #: includes/i18n.php:46
62
+ msgid "Awesome"
63
+ msgstr "Sejt"
64
+
65
+ #: includes/i18n.php:47
66
+ msgctxt "noun"
67
+ msgid "Pricing"
68
+ msgstr "Priser"
69
+
70
+ #: includes/i18n.php:48
71
+ msgctxt "noun"
72
+ msgid "Price"
73
+ msgstr "Pris"
74
+
75
+ #: includes/i18n.php:49
76
+ msgid "Unlimited Updates"
77
+ msgstr "Ubegrænsede opdateringer"
78
+
79
+ #: includes/i18n.php:50
80
+ msgctxt "verb"
81
+ msgid "Downgrade"
82
+ msgstr "Nedgrader"
83
+
84
+ #: includes/i18n.php:51
85
+ msgctxt "verb"
86
+ msgid "Cancel Subscription"
87
+ msgstr "Annuller abonnement"
88
+
89
+ #: includes/i18n.php:52
90
+ msgid "Cancel Trial"
91
+ msgstr "Annuller prøveperiode"
92
+
93
+ #: includes/i18n.php:53
94
+ msgid "Free Trial"
95
+ msgstr "Gratis prøveperiode"
96
+
97
+ #: includes/i18n.php:54
98
+ msgid "Start my free %s"
99
+ msgstr "Start min gratis %s"
100
+
101
+ #: includes/i18n.php:55
102
+ msgid "No commitment for %s - cancel anytime"
103
+ msgstr "Ingen bindinger ved %s - annuller når som helst"
104
+
105
+ #: includes/i18n.php:56
106
+ msgid "After your free %s, pay as little as %s"
107
+ msgstr "Efter din gratis %s er prisen kun %s"
108
+
109
+ #: includes/i18n.php:57
110
+ msgid "Details"
111
+ msgstr "Detaljer"
112
+
113
+ #: includes/i18n.php:58
114
+ msgid "Account Details"
115
+ msgstr "Kontodetaljer"
116
+
117
+ #: includes/i18n.php:59
118
+ msgctxt "verb"
119
+ msgid "Delete"
120
+ msgstr "Slet"
121
+
122
+ #: includes/i18n.php:60
123
+ msgctxt "verb"
124
+ msgid "Show"
125
+ msgstr "Vis"
126
+
127
+ #: includes/i18n.php:61
128
+ msgctxt "verb"
129
+ msgid "Hide"
130
+ msgstr "Skjul"
131
+
132
+ #: includes/i18n.php:62
133
+ msgctxt "verb"
134
+ msgid "Edit"
135
+ msgstr "Rediger"
136
+
137
+ #: includes/i18n.php:63
138
+ msgctxt "verb"
139
+ msgid "Update"
140
+ msgstr "Opdater"
141
+
142
+ #: includes/i18n.php:64
143
+ msgid "Date"
144
+ msgstr "Dato"
145
+
146
+ #: includes/i18n.php:65
147
+ msgid "Amount"
148
+ msgstr "Beløb"
149
+
150
+ #: includes/i18n.php:66
151
+ msgid "Invoice"
152
+ msgstr "Faktura"
153
+
154
+ #: includes/i18n.php:67
155
+ msgid "Billing"
156
+ msgstr "Betaling"
157
+
158
+ #: includes/i18n.php:68
159
+ msgid "Payments"
160
+ msgstr "Betalinger"
161
+
162
+ #: includes/i18n.php:69
163
+ msgid "Delete Account"
164
+ msgstr "Slet konto"
165
+
166
+ #: includes/i18n.php:70
167
+ msgctxt "as close a window"
168
+ msgid "Dismiss"
169
+ msgstr "Fjern"
170
+
171
+ #: includes/i18n.php:71
172
+ msgctxt "as product pricing plan"
173
+ msgid "Plan"
174
+ msgstr "Plan"
175
+
176
+ #: includes/i18n.php:72
177
+ msgid "Change Plan"
178
+ msgstr "Skift plan"
179
+
180
+ #: includes/i18n.php:73
181
+ msgctxt "as download professional version"
182
+ msgid "Download %s Version"
183
+ msgstr "Download %s Version"
184
+
185
+ #: includes/i18n.php:74
186
+ msgctxt "as download professional version now"
187
+ msgid "Download %s version now"
188
+ msgstr "Download %s version now"
189
+
190
+ #: includes/i18n.php:75
191
+ msgctxt "as download latest version"
192
+ msgid "Download Latest"
193
+ msgstr "Download seneste"
194
+
195
+ #: includes/i18n.php:76
196
+ msgctxt "E.g. you have a professional license."
197
+ msgid "You have a %s license."
198
+ msgstr "Du har en %s licens."
199
+
200
+ #: includes/i18n.php:77
201
+ msgid "New"
202
+ msgstr "Ny"
203
+
204
+ #: includes/i18n.php:78
205
+ msgid "Free"
206
+ msgstr "Gratis"
207
+
208
+ #: includes/i18n.php:79
209
+ msgctxt "as trial plan"
210
+ msgid "Trial"
211
+ msgstr "Prøveperiode"
212
+
213
+ #: includes/i18n.php:80
214
+ msgctxt "as starting a trial plan"
215
+ msgid "Start Trial"
216
+ msgstr "Start prøveperiode"
217
+
218
+ #: includes/i18n.php:81
219
+ msgctxt "verb"
220
+ msgid "Purchase"
221
+ msgstr "Køb"
222
+
223
+ #: includes/i18n.php:82
224
+ msgid "Purchase License"
225
+ msgstr "Køb licens"
226
+
227
+ #: includes/i18n.php:83
228
+ msgctxt "verb"
229
+ msgid "Buy"
230
+ msgstr "Køb"
231
+
232
+ #: includes/i18n.php:84
233
+ msgid "Buy License"
234
+ msgstr "Køb licens"
235
+
236
+ #: includes/i18n.php:85
237
+ msgid "Single Site License"
238
+ msgstr "Single Site License"
239
+
240
+ #: includes/i18n.php:86
241
+ msgid "Unlimited Licenses"
242
+ msgstr "Ubegrænsede licenser"
243
+
244
+ #: includes/i18n.php:87
245
+ msgid "Up to %s Sites"
246
+ msgstr "Op til %s websteder"
247
+
248
+ #: includes/i18n.php:88
249
+ msgid "%sRenew your license now%s to access version %s features and support."
250
+ msgstr "%sRenew your license now%s to access version %s features and support."
251
+
252
+ #: includes/i18n.php:89
253
+ msgid "Enter the email address you've used for the upgrade below and we will resend you the license key."
254
+ msgstr "Enter the email address you've used for the upgrade below and we will resend you the license key."
255
+
256
+ #: includes/i18n.php:90
257
+ msgctxt "e.g. Professional Plan"
258
+ msgid "%s Plan"
259
+ msgstr "%s Plan"
260
+
261
+ #: includes/i18n.php:91
262
+ msgid "You are just one step away - %s"
263
+ msgstr "Du mangler kun ét skridt - %s"
264
+
265
+ #: includes/i18n.php:92
266
+ msgctxt "%s - plugin name. As complete \"Jetpack\" activation now"
267
+ msgid "Complete \"%s\" Activation Now"
268
+ msgstr "Færdiggør aktivering af \"%s\" nu"
269
+
270
+ #: includes/i18n.php:94
271
+ msgid "We made a few tweaks to the %s, %s"
272
+ msgstr "We made a few tweaks to the %s, %s"
273
+
274
+ #: includes/i18n.php:95
275
+ msgid "Opt-in to make \"%s\" Better!"
276
+ msgstr "Tilmeld for at gøre \"%s\" bedre!"
277
+
278
+ #: includes/i18n.php:96
279
+ msgid "Error"
280
+ msgstr "Fejl"
281
+
282
+ #: includes/i18n.php:97
283
+ msgid "Freemius SDK couldn't find the plugin's main file. Please contact sdk@freemius.com with the current error."
284
+ msgstr "Freemius SDK couldn't find the plugin's main file. Please contact sdk@freemius.com with the current error."
285
+
286
+ #: includes/i18n.php:100
287
+ msgctxt "as expiration date"
288
+ msgid "Expiration"
289
+ msgstr "Expiration"
290
+
291
+ #: includes/i18n.php:101
292
+ msgctxt "as software license"
293
+ msgid "License"
294
+ msgstr "Licens"
295
+
296
+ #: includes/i18n.php:102
297
+ msgid "not verified"
298
+ msgstr "ikke verificeret"
299
+
300
+ #: includes/i18n.php:103
301
+ msgid "Verify Email"
302
+ msgstr "Verificer e-mail"
303
+
304
+ #: includes/i18n.php:104
305
+ msgctxt "e.g. expires in 2 months"
306
+ msgid "Expires in %s"
307
+ msgstr "Udløber om %s"
308
+
309
+ #: includes/i18n.php:105
310
+ msgctxt "e.g. auto renews in 2 months"
311
+ msgid "Auto renews in %s"
312
+ msgstr "Auto-fornyer om %s"
313
+
314
+ #: includes/i18n.php:106
315
+ msgid "No expiration"
316
+ msgstr "Udløber ikke"
317
+
318
+ #: includes/i18n.php:107
319
+ msgid "Expired"
320
+ msgstr "Udløbet"
321
+
322
+ #: includes/i18n.php:108
323
+ msgid "Cancelled"
324
+ msgstr "Annulleret"
325
+
326
+ #: includes/i18n.php:109
327
+ msgctxt "e.g. In 2 hours"
328
+ msgid "In %s"
329
+ msgstr "Om %s"
330
+
331
+ #: includes/i18n.php:110
332
+ msgctxt "e.g. 2 min ago"
333
+ msgid "%s ago"
334
+ msgstr "%s siden"
335
+
336
+ #: includes/i18n.php:112
337
+ msgid "%s or higher"
338
+ msgstr "%s eller højere"
339
+
340
+ #: includes/i18n.php:113
341
+ msgctxt "as plugin version"
342
+ msgid "Version"
343
+ msgstr "Version"
344
+
345
+ #: includes/i18n.php:114
346
+ msgid "Name"
347
+ msgstr "Navn"
348
+
349
+ #: includes/i18n.php:115
350
+ msgid "Email"
351
+ msgstr "E-mail"
352
+
353
+ #: includes/i18n.php:116
354
+ msgid "Email address"
355
+ msgstr "E-mailadresse"
356
+
357
+ #: includes/i18n.php:117
358
+ msgid "Verified"
359
+ msgstr "Verificeret"
360
+
361
+ #: includes/i18n.php:118
362
+ msgid "Module"
363
+ msgstr "Modul"
364
+
365
+ #: includes/i18n.php:119
366
+ msgid "Module Type"
367
+ msgstr "Modultype"
368
+
369
+ #: includes/i18n.php:120
370
+ msgid "Plugin"
371
+ msgstr "Plugin"
372
+
373
+ #: includes/i18n.php:121
374
+ msgid "Plugins"
375
+ msgstr "Plugins"
376
+
377
+ #: includes/i18n.php:122
378
+ msgid "Theme"
379
+ msgstr "Tema"
380
+
381
+ #: includes/i18n.php:123
382
+ msgid "Themes"
383
+ msgstr "Temaer"
384
+
385
+ #: includes/i18n.php:124
386
+ msgctxt "as file/folder path"
387
+ msgid "Path"
388
+ msgstr "Sti"
389
+
390
+ #: includes/i18n.php:125
391
+ msgid "Title"
392
+ msgstr "Titel"
393
+
394
+ #: includes/i18n.php:126
395
+ msgid "Free version"
396
+ msgstr "Gratis version"
397
+
398
+ #: includes/i18n.php:127
399
+ msgid "Premium version"
400
+ msgstr "Premium version"
401
+
402
+ #: includes/i18n.php:128
403
+ msgctxt "as WP plugin slug"
404
+ msgid "Slug"
405
+ msgstr "Kortnavn"
406
+
407
+ #: includes/i18n.php:129
408
+ msgid "ID"
409
+ msgstr "ID"
410
+
411
+ #: includes/i18n.php:130
412
+ msgid "Users"
413
+ msgstr "Brugere"
414
+
415
+ #: includes/i18n.php:131
416
+ msgid "%s Installs"
417
+ msgstr "%s installeringer"
418
+
419
+ #: includes/i18n.php:132
420
+ msgctxt "like websites"
421
+ msgid "Sites"
422
+ msgstr "Websteder"
423
+
424
+ #: includes/i18n.php:133
425
+ msgid "User ID"
426
+ msgstr "Bruger-ID"
427
+
428
+ #: includes/i18n.php:134
429
+ msgid "Site ID"
430
+ msgstr "Websteds-ID"
431
+
432
+ #: includes/i18n.php:135
433
+ msgid "Public Key"
434
+ msgstr "Offentlig nøgle"
435
+
436
+ #: includes/i18n.php:136
437
+ msgid "Secret Key"
438
+ msgstr "Privat nøgle"
439
+
440
+ #: includes/i18n.php:137
441
+ msgctxt "as secret encryption key missing"
442
+ msgid "No Secret"
443
+ msgstr "Ingen privat nøgle"
444
+
445
+ #: includes/i18n.php:138
446
+ msgid "No ID"
447
+ msgstr "Intet ID"
448
+
449
+ #: includes/i18n.php:139
450
+ msgctxt "as synchronize license"
451
+ msgid "Sync License"
452
+ msgstr "Synkroniser licens"
453
+
454
+ #: includes/i18n.php:140
455
+ msgctxt "as synchronize"
456
+ msgid "Sync"
457
+ msgstr "Synkroniser"
458
+
459
+ #: includes/i18n.php:141
460
+ msgid "Activate License"
461
+ msgstr "Aktiver licens"
462
+
463
+ #: includes/i18n.php:142
464
+ msgid "Activate Free Version"
465
+ msgstr "Aktiver gratis version"
466
+
467
+ #: includes/i18n.php:143
468
+ msgid "Please enter the license key that you received in the email right after the purchase:"
469
+ msgstr "Please enter the license key that you received in the email right after the purchase:"
470
+
471
+ #: includes/i18n.php:144
472
+ msgid "Activating license..."
473
+ msgstr "Aktiverer licens..."
474
+
475
+ #: includes/i18n.php:145
476
+ msgid "Change License"
477
+ msgstr "Skift licens"
478
+
479
+ #: includes/i18n.php:146
480
+ msgid "Update License"
481
+ msgstr "Opdater licens"
482
+
483
+ #: includes/i18n.php:147
484
+ msgid "Deactivate License"
485
+ msgstr "Deaktiver licens"
486
+
487
+ #: includes/i18n.php:148
488
+ msgid "Activate"
489
+ msgstr "Aktiver"
490
+
491
+ #: includes/i18n.php:149
492
+ msgid "Deactivate"
493
+ msgstr "Deaktiver"
494
+
495
+ #: includes/i18n.php:150
496
+ msgid "Skip & Deactivate"
497
+ msgstr "Spring over & deaktiver"
498
+
499
+ #: includes/i18n.php:151
500
+ msgid "Skip & %s"
501
+ msgstr "Spring over & %s"
502
+
503
+ #: includes/i18n.php:152
504
+ msgid "No - just deactivate"
505
+ msgstr "Nej - bare deaktiver"
506
+
507
+ #: includes/i18n.php:153
508
+ msgid "Yes - do your thing"
509
+ msgstr "Yes - do your thing"
510
+
511
+ #: includes/i18n.php:154
512
+ msgctxt "active mode"
513
+ msgid "Active"
514
+ msgstr "Aktiv"
515
+
516
+ #: includes/i18n.php:155
517
+ msgctxt "is active mode?"
518
+ msgid "Is Active"
519
+ msgstr "Er aktiv"
520
+
521
+ #: includes/i18n.php:156
522
+ msgid "Install Now"
523
+ msgstr "Installer nu"
524
+
525
+ #: includes/i18n.php:157
526
+ msgid "Install Update Now"
527
+ msgstr "Installer opdatering nu"
528
+
529
+ #: includes/i18n.php:158
530
+ msgid "More information about %s"
531
+ msgstr "Mere information om %s"
532
+
533
+ #: includes/i18n.php:159
534
+ msgid "Localhost"
535
+ msgstr "Localhost"
536
+
537
+ #: includes/i18n.php:160
538
+ msgctxt "as activate Professional plan"
539
+ msgid "Activate %s Plan"
540
+ msgstr "Aktiver %s plan"
541
+
542
+ #: includes/i18n.php:161
543
+ msgctxt "as 5 licenses left"
544
+ msgid "%s left"
545
+ msgstr "%s tilbage"
546
+
547
+ #: includes/i18n.php:162
548
+ msgid "Last license"
549
+ msgstr "Seneste license"
550
+
551
+ #: includes/i18n.php:163
552
+ msgid "What is your %s?"
553
+ msgstr "What is your %s?"
554
+
555
+ #: includes/i18n.php:164
556
+ msgid "Activate this add-on"
557
+ msgstr "Aktiver denne tilføjelse"
558
+
559
+ #: includes/i18n.php:165
560
+ msgid "Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?"
561
+ msgstr "Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?"
562
+
563
+ #: includes/i18n.php:166
564
+ msgid "Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the \"Cancel\" button, and first \"Downgrade\" your account. Are you sure you would like to continue with the deletion?"
565
+ msgstr "Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the \"Cancel\" button, and first \"Downgrade\" your account. Are you sure you would like to continue with the deletion?"
566
+
567
+ #: includes/i18n.php:167
568
+ msgid "Deletion is not temporary. Only delete if you no longer want to use this %s anymore. Are you sure you would like to continue with the deletion?"
569
+ msgstr "Deletion is not temporary. Only delete if you no longer want to use this %s anymore. Are you sure you would like to continue with the deletion?"
570
+
571
+ #: includes/i18n.php:168
572
+ msgid "Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s."
573
+ msgstr "Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s."
574
+
575
+ #: includes/i18n.php:169
576
+ msgid "Cancelling the trial will immediately block access to all premium features. Are you sure?"
577
+ msgstr "Cancelling the trial will immediately block access to all premium features. Are you sure?"
578
+
579
+ #: includes/i18n.php:170
580
+ msgid "You can still enjoy all %s features but you will not have access to %s updates and support."
581
+ msgstr "You can still enjoy all %s features but you will not have access to %s updates and support."
582
+
583
+ #: includes/i18n.php:171
584
+ msgid "Once your license expires you can still use the Free version but you will NOT have access to the %s features."
585
+ msgstr "Once your license expires you can still use the Free version but you will NOT have access to the %s features."
586
+
587
+ #: includes/i18n.php:172
588
+ msgid "Are you sure you want to proceed?"
589
+ msgstr "Er du sikker på, du vil fortsætte?"
590
+
591
+ #: includes/i18n.php:175
592
+ msgid "Add Ons for %s"
593
+ msgstr "Tilføjelser til %s"
594
+
595
+ #: includes/i18n.php:176
596
+ msgid "We could'nt load the add-ons list. It's probably an issue on our side, please try to come back in few minutes."
597
+ msgstr "We could'nt load the add-ons list. It's probably an issue on our side, please try to come back in few minutes."
598
+
599
+ #: includes/i18n.php:178
600
+ msgid "Anonymous feedback"
601
+ msgstr "Anonym feedback"
602
+
603
+ #: includes/i18n.php:179
604
+ msgid "Quick feedback"
605
+ msgstr "Hurtig feedback"
606
+
607
+ #: includes/i18n.php:180
608
+ msgid "If you have a moment, please let us know why you are %s"
609
+ msgstr "If you have a moment, please let us know why you are %s"
610
+
611
+ #: includes/i18n.php:181
612
+ msgid "deactivating"
613
+ msgstr "deactivating"
614
+
615
+ #: includes/i18n.php:182
616
+ msgid "Deactivation"
617
+ msgstr "Deactivation"
618
+
619
+ #: includes/i18n.php:183
620
+ msgid "Theme Switch"
621
+ msgstr "Theme Switch"
622
+
623
+ #: includes/i18n.php:184
624
+ msgid "switching"
625
+ msgstr "switching"
626
+
627
+ #: includes/i18n.php:185
628
+ msgid "Switch"
629
+ msgstr "Switch"
630
+
631
+ #: includes/i18n.php:186
632
+ msgid "Activate %s"
633
+ msgstr "Activate %s"
634
+
635
+ #: includes/i18n.php:187
636
+ msgid "Yes - %s"
637
+ msgstr "Yes - %s"
638
+
639
+ #: includes/i18n.php:188
640
+ msgid "Submit & %s"
641
+ msgstr "Submit & %s"
642
+
643
+ #: includes/i18n.php:189
644
+ msgid "Cancel"
645
+ msgstr "Annuller"
646
+
647
+ #: includes/i18n.php:190
648
+ msgid "I no longer need the %s"
649
+ msgstr "I no longer need the %s"
650
+
651
+ #: includes/i18n.php:191
652
+ msgid "I found a better %s"
653
+ msgstr "I found a better %s"
654
+
655
+ #: includes/i18n.php:192
656
+ msgid "I only needed the %s for a short period"
657
+ msgstr "I only needed the %s for a short period"
658
+
659
+ #: includes/i18n.php:193
660
+ msgid "The %s broke my site"
661
+ msgstr "The %s broke my site"
662
+
663
+ #: includes/i18n.php:194
664
+ msgid "The %s suddenly stopped working"
665
+ msgstr "The %s suddenly stopped working"
666
+
667
+ #: includes/i18n.php:195
668
+ msgid "I can't pay for it anymore"
669
+ msgstr "Jeg kan ikke længere betale for det"
670
+
671
+ #: includes/i18n.php:196
672
+ msgid "It's a temporary deactivation. I'm just debugging an issue."
673
+ msgstr "Det er en midlertidig deaktivering. Jeg prøver at fejlfinde et problem."
674
+
675
+ #: includes/i18n.php:197
676
+ msgid "It's a temporary %s. I'm just debugging an issue."
677
+ msgstr "It's a temporary %s. I'm just debugging an issue."
678
+
679
+ #: includes/i18n.php:198
680
+ msgctxt ""
681
+ msgid "Other"
682
+ msgstr "Other"
683
+
684
+ #: includes/i18n.php:200
685
+ msgid "Kindly tell us the reason so we can improve."
686
+ msgstr "Fortæl os venligst årsagen, så vi kan forbedre det."
687
+
688
+ #: includes/i18n.php:201
689
+ msgid "What's the %s's name?"
690
+ msgstr "What's the %s's name?"
691
+
692
+ #: includes/i18n.php:202
693
+ msgid "What price would you feel comfortable paying?"
694
+ msgstr "What price would you feel comfortable paying?"
695
+
696
+ #: includes/i18n.php:203
697
+ msgid "I couldn't understand how to make it work"
698
+ msgstr "Jeg forstod ikke, hvordan jeg skulle få det til at fungere."
699
+
700
+ #: includes/i18n.php:204
701
+ msgid "The %s is great, but I need specific feature that you don't support"
702
+ msgstr "The %s is great, but I need specific feature that you don't support"
703
+
704
+ #: includes/i18n.php:205
705
+ msgid "The %s is not working"
706
+ msgstr "The %s is not working"
707
+
708
+ #: includes/i18n.php:206
709
+ msgid "It's not what I was looking for"
710
+ msgstr "Det er ikke, hvad jeg søgte"
711
+
712
+ #: includes/i18n.php:207
713
+ msgid "The %s didn't work as expected"
714
+ msgstr "The %s didn't work as expected"
715
+
716
+ #: includes/i18n.php:208
717
+ msgid "What feature?"
718
+ msgstr "Hvilken feature?"
719
+
720
+ #: includes/i18n.php:209
721
+ msgid "Kindly share what didn't work so we can fix it for future users..."
722
+ msgstr "Kindly share what didn't work so we can fix it for future users..."
723
+
724
+ #: includes/i18n.php:210
725
+ msgid "What you've been looking for?"
726
+ msgstr "What you've been looking for?"
727
+
728
+ #: includes/i18n.php:211
729
+ msgid "What did you expect?"
730
+ msgstr "Hvad forventede du?"
731
+
732
+ #: includes/i18n.php:212
733
+ msgid "The %s didn't work"
734
+ msgstr "The %s didn't work"
735
+
736
+ #: includes/i18n.php:213
737
+ msgid "I don't like to share my information with you"
738
+ msgstr "I don't like to share my information with you"
739
+
740
+ #: includes/i18n.php:214
741
+ msgid "You might have missed it, but you don't have to share any data and can just %s the opt-in."
742
+ msgstr "You might have missed it, but you don't have to share any data and can just %s the opt-in."
743
+
744
+ #: includes/i18n.php:218
745
+ msgctxt "greeting"
746
+ msgid "Hey %s,"
747
+ msgstr "Hey %s,"
748
+
749
+ #: includes/i18n.php:219
750
+ msgctxt "a greeting. E.g. Thanks John!"
751
+ msgid "Thanks %s!"
752
+ msgstr "Tak %s!"
753
+
754
+ #: includes/i18n.php:220
755
+ msgid "Never miss an important update - opt-in to our security and feature updates notifications, and non-sensitive diagnostic tracking with %4$s."
756
+ msgstr "Never miss an important update - opt-in to our security and feature updates notifications, and non-sensitive diagnostic tracking with %4$s."
757
+
758
+ #: includes/i18n.php:221
759
+ msgid "Please help us improve %1$s! If you opt-in, some data about your usage of %1$s will be sent to %4$s. If you skip this, that's okay! %1$s will still work just fine."
760
+ msgstr "Please help us improve %1$s! If you opt-in, some data about your usage of %1$s will be sent to %4$s. If you skip this, that's okay! %1$s will still work just fine."
761
+
762
+ #: includes/i18n.php:222
763
+ msgid "You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s."
764
+ msgstr "You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s."
765
+
766
+ #: includes/i18n.php:223
767
+ msgid "complete the install"
768
+ msgstr "færdiggør installeringen"
769
+
770
+ #: includes/i18n.php:224
771
+ msgid "start the trial"
772
+ msgstr "start prøveperioden"
773
+
774
+ #: includes/i18n.php:225
775
+ msgid "Thanks for purchasing %s! To get started, please enter your license key:"
776
+ msgstr "Thanks for purchasing %s! To get started, please enter your license key:"
777
+
778
+ #: includes/i18n.php:226
779
+ msgid "The %1$s will be periodically sending data to %2$s to check for security and feature updates, and verify the validity of your license."
780
+ msgstr "The %1$s will be periodically sending data to %2$s to check for security and feature updates, and verify the validity of your license."
781
+
782
+ #: includes/i18n.php:227
783
+ msgid "What permissions are being granted?"
784
+ msgstr "Hvilke tilladelser bliver givet?"
785
+
786
+ #: includes/i18n.php:228
787
+ msgid "Your Profile Overview"
788
+ msgstr "Overblik af din profil"
789
+
790
+ #: includes/i18n.php:229
791
+ msgid "Name and email address"
792
+ msgstr "Navn og e-mailadresse"
793
+
794
+ #: includes/i18n.php:230
795
+ msgid "Your Site Overview"
796
+ msgstr "Overblik af dit websted"
797
+
798
+ #: includes/i18n.php:231
799
+ msgid "Site URL, WP version, PHP info, plugins & themes"
800
+ msgstr "Websteds-URL, WP version, PHP info, plugins og temaer"
801
+
802
+ #: includes/i18n.php:232
803
+ msgid "Current %s Events"
804
+ msgstr "Current %s Events"
805
+
806
+ #: includes/i18n.php:233
807
+ msgid "Activation, deactivation and uninstall"
808
+ msgstr "Aktivering, deaktivering og afinstallering"
809
+
810
+ #: includes/i18n.php:234
811
+ msgid "Plugins & Themes"
812
+ msgstr "Plugins & Temaer"
813
+
814
+ #: includes/i18n.php:235
815
+ msgid "Titles, versions and state."
816
+ msgstr "Titler, versioner og tilstand."
817
+
818
+ #: includes/i18n.php:236
819
+ msgid "Admin Notices"
820
+ msgstr "Admin Notices"
821
+
822
+ #: includes/i18n.php:237
823
+ msgid "Newsletter"
824
+ msgstr "Nyhedsbrev"
825
+
826
+ #: includes/i18n.php:238
827
+ msgid "Updates, announcements, marketing, no spam"
828
+ msgstr "Updates, announcements, marketing, no spam"
829
+
830
+ #: includes/i18n.php:239
831
+ msgid "Privacy Policy"
832
+ msgstr "Privatlivspolitik"
833
+
834
+ #: includes/i18n.php:240
835
+ msgid "Terms of Service"
836
+ msgstr "Servicevilkår"
837
+
838
+ #: includes/i18n.php:241
839
+ msgctxt "as activating plugin"
840
+ msgid "Activating"
841
+ msgstr "Aktiverer"
842
+
843
+ #: includes/i18n.php:242
844
+ msgctxt "as in the process of sending an email"
845
+ msgid "Sending email"
846
+ msgstr "Sender e-mail"
847
+
848
+ #: includes/i18n.php:243
849
+ msgctxt "button label"
850
+ msgid "Allow & Continue"
851
+ msgstr "Tillad & Fortsæt"
852
+
853
+ #: includes/i18n.php:244
854
+ msgctxt "button label"
855
+ msgid "Agree & Activate License"
856
+ msgstr "Accepter & aktiver licens"
857
+
858
+ #: includes/i18n.php:245
859
+ msgctxt "verb"
860
+ msgid "Skip"
861
+ msgstr "Spring over"
862
+
863
+ #: includes/i18n.php:246
864
+ msgid "Click here to use the plugin anonymously"
865
+ msgstr "Klik her for at benytte pluginnet anonymt"
866
+
867
+ #: includes/i18n.php:247
868
+ msgid "Re-send activation email"
869
+ msgstr "Gensend e-mail om aktivering"
870
+
871
+ #: includes/i18n.php:248
872
+ msgid "License key"
873
+ msgstr "Licensnøgle"
874
+
875
+ #: includes/i18n.php:249
876
+ msgid "Send License Key"
877
+ msgstr "Send licensnøgle"
878
+
879
+ #: includes/i18n.php:250
880
+ msgid "Sending license key"
881
+ msgstr "Sender licensnøgle"
882
+
883
+ #: includes/i18n.php:251
884
+ msgid "Have a license key?"
885
+ msgstr "Har du en licensnøgle?"
886
+
887
+ #: includes/i18n.php:252
888
+ msgid "Don't have a license key?"
889
+ msgstr "Har du ikke en licensnøgle?"
890
+
891
+ #: includes/i18n.php:253
892
+ msgid "Can't find your license key?"
893
+ msgstr "Kan du ikke finde din licensnøgle?"
894
+
895
+ #: includes/i18n.php:254
896
+ msgid "We couldn't find your email address in the system, are you sure it's the right address?"
897
+ msgstr "We couldn't find your email address in the system, are you sure it's the right address?"
898
+
899
+ #: includes/i18n.php:255
900
+ msgid "We can't see any active licenses associated with that email address, are you sure it's the right address?"
901
+ msgstr "We can't see any active licenses associated with that email address, are you sure it's the right address?"
902
+
903
+ #: includes/i18n.php:256
904
+ msgid "Opt In"
905
+ msgstr "Tilmeld"
906
+
907
+ #: includes/i18n.php:257
908
+ msgid "Opt Out"
909
+ msgstr "Frameld"
910
+
911
+ #: includes/i18n.php:258
912
+ msgid "On second thought - I want to continue helping"
913
+ msgstr "Ved nærmere eftertanke - Jeg vil fortsætte med at hjælpe"
914
+
915
+ #: includes/i18n.php:259
916
+ msgid "Opting out..."
917
+ msgstr "Framelder..."
918
+
919
+ #: includes/i18n.php:260
920
+ msgid "Opting in..."
921
+ msgstr "Tilmelder..."
922
+
923
+ #: includes/i18n.php:261
924
+ msgid "We appreciate your help in making the %s better by letting us track some usage data."
925
+ msgstr "We appreciate your help in making the %s better by letting us track some usage data."
926
+
927
+ #: includes/i18n.php:262
928
+ msgid "Usage tracking is done in the name of making %s better. Making a better user experience, prioritizing new features, and more good things. We'd really appreciate if you'll reconsider letting us continue with the tracking."
929
+ msgstr "Usage tracking is done in the name of making %s better. Making a better user experience, prioritizing new features, and more good things. We'd really appreciate if you'll reconsider letting us continue with the tracking."
930
+
931
+ #: includes/i18n.php:263
932
+ msgid "By clicking \"Opt Out\", we will no longer be sending any data from %s to %s."
933
+ msgstr "Ved at klikke \"Frameld\" vil vi ikke længere sende data fra %s til %s."
934
+
935
+ #: includes/i18n.php:267
936
+ msgid "Screenshots"
937
+ msgstr "Skærmbilleder"
938
+
939
+ #: includes/i18n.php:268
940
+ msgid "Click to view full-size screenshot %d"
941
+ msgstr "Click to view full-size screenshot %d"
942
+
943
+ #: includes/i18n.php:272
944
+ msgid "Freemius Debug"
945
+ msgstr "Freemius Debug"
946
+
947
+ #: includes/i18n.php:273
948
+ msgctxt "as turned on"
949
+ msgid "On"
950
+ msgstr "Til"
951
+
952
+ #: includes/i18n.php:274
953
+ msgctxt "as turned off"
954
+ msgid "Off"
955
+ msgstr "Fra"
956
+
957
+ #: includes/i18n.php:275
958
+ msgctxt "as code debugging"
959
+ msgid "Debugging"
960
+ msgstr "Fejlfinding"
961
+
962
+ #: includes/i18n.php:276
963
+ msgid "Freemius State"
964
+ msgstr "Freemius tilstand"
965
+
966
+ #: includes/i18n.php:277
967
+ msgctxt "as connection was successful"
968
+ msgid "Connected"
969
+ msgstr "Forbundet"
970
+
971
+ #: includes/i18n.php:278
972
+ msgctxt "as connection blocked"
973
+ msgid "Blocked"
974
+ msgstr "Blokeret"
975
+
976
+ #: includes/i18n.php:279
977
+ msgctxt "as application program interface"
978
+ msgid "API"
979
+ msgstr "API"
980
+
981
+ #: includes/i18n.php:280
982
+ msgctxt "as software development kit versions"
983
+ msgid "SDK"
984
+ msgstr "SDK"
985
+
986
+ #: includes/i18n.php:281
987
+ msgctxt "as software development kit versions"
988
+ msgid "SDK Versions"
989
+ msgstr "SDK-versioner"
990
+
991
+ #: includes/i18n.php:282
992
+ msgctxt "as plugin folder path"
993
+ msgid "Plugin Path"
994
+ msgstr "Plugin-sti"
995
+
996
+ #: includes/i18n.php:283
997
+ msgctxt "as sdk path"
998
+ msgid "SDK Path"
999
+ msgstr "SDK-sti"
1000
+
1001
+ #: includes/i18n.php:284
1002
+ msgid "Add Ons of Plugin %s"
1003
+ msgstr "Tilføjelser til plugin %s"
1004
+
1005
+ #: includes/i18n.php:285
1006
+ msgid "Are you sure you want to delete all Freemius data?"
1007
+ msgstr "Er du sikker på, du vil slette al Freemius data?"
1008
+
1009
+ #: includes/i18n.php:286
1010
+ msgid "Actions"
1011
+ msgstr "Handlinger"
1012
+
1013
+ #: includes/i18n.php:287
1014
+ msgid "Delete All Accounts"
1015
+ msgstr "Slet alle konti"
1016
+
1017
+ #: includes/i18n.php:288
1018
+ msgid "Start Fresh"
1019
+ msgstr "Start forfra"
1020
+
1021
+ #: includes/i18n.php:289
1022
+ msgid "Clear API Cache"
1023
+ msgstr "Ryd API-cache"
1024
+
1025
+ #: includes/i18n.php:290
1026
+ msgid "Sync Data From Server"
1027
+ msgstr "Synkroniser data fra server"
1028
+
1029
+ #: includes/i18n.php:291
1030
+ msgid "Scheduled Crons"
1031
+ msgstr "Planlagte cron jobs"
1032
+
1033
+ #: includes/i18n.php:292
1034
+ msgid "Cron Type"
1035
+ msgstr "Cron Type"
1036
+
1037
+ #: includes/i18n.php:293
1038
+ msgid "Plugins & Themes Sync"
1039
+ msgstr "Synkronisering af plugins og temaer"
1040
+
1041
+ #: includes/i18n.php:294
1042
+ msgid "%s Licenses"
1043
+ msgstr "%s Licenses"
1044
+
1045
+ #: includes/i18n.php:295
1046
+ msgid "Debug Log"
1047
+ msgstr "Fejlfindingslog"
1048
+
1049
+ #: includes/i18n.php:296
1050
+ msgid "All"
1051
+ msgstr "Alle"
1052
+
1053
+ #: includes/i18n.php:297
1054
+ msgid "File"
1055
+ msgstr "Fil"
1056
+
1057
+ #: includes/i18n.php:298
1058
+ msgid "Function"
1059
+ msgstr "Funktion"
1060
+
1061
+ #: includes/i18n.php:299
1062
+ msgid "Process ID"
1063
+ msgstr "Proces-ID"
1064
+
1065
+ #: includes/i18n.php:300
1066
+ msgid "Logger"
1067
+ msgstr "Logger"
1068
+
1069
+ #: includes/i18n.php:301
1070
+ msgid "Message"
1071
+ msgstr "Besked"
1072
+
1073
+ #: includes/i18n.php:302
1074
+ msgid "Download"
1075
+ msgstr "Download"
1076
+
1077
+ #: includes/i18n.php:303
1078
+ msgid "Filter"
1079
+ msgstr "Filter"
1080
+
1081
+ #: includes/i18n.php:304
1082
+ msgid "Type"
1083
+ msgstr "Type"
1084
+
1085
+ #: includes/i18n.php:305
1086
+ msgid "All Types"
1087
+ msgstr "Alle typer"
1088
+
1089
+ #: includes/i18n.php:306
1090
+ msgid "All Requests"
1091
+ msgstr "Alle forespørgsler"
1092
+
1093
+ #: includes/i18n.php:310
1094
+ msgctxt "as congratulations"
1095
+ msgid "Congrats"
1096
+ msgstr "Tillykke"
1097
+
1098
+ #: includes/i18n.php:311
1099
+ msgctxt "exclamation"
1100
+ msgid "Oops"
1101
+ msgstr "Ups"
1102
+
1103
+ #: includes/i18n.php:312
1104
+ msgctxt "interjection expressing joy or exuberance"
1105
+ msgid "Yee-haw"
1106
+ msgstr "Yee-haw"
1107
+
1108
+ #: includes/i18n.php:313
1109
+ msgctxt ""
1110
+ msgid "W00t"
1111
+ msgstr "W00t"
1112
+
1113
+ #: includes/i18n.php:315
1114
+ msgctxt "a positive response"
1115
+ msgid "Right on"
1116
+ msgstr "Sådan"
1117
+
1118
+ #: includes/i18n.php:316
1119
+ msgctxt ""
1120
+ msgid "Hmm"
1121
+ msgstr "Hmm"
1122
+
1123
+ #: includes/i18n.php:318
1124
+ msgid "O.K"
1125
+ msgstr "O.K"
1126
+
1127
+ #: includes/i18n.php:319
1128
+ msgctxt "exclamation"
1129
+ msgid "Hey"
1130
+ msgstr "Hey"
1131
+
1132
+ #: includes/i18n.php:320
1133
+ msgctxt "advance notice of something that will need attention."
1134
+ msgid "Heads up"
1135
+ msgstr "Se her"
1136
+
1137
+ #: includes/i18n.php:325
1138
+ msgid "Seems like you got the latest release."
1139
+ msgstr "Det ser ud til, at du har den seneste udgivelse."
1140
+
1141
+ #: includes/i18n.php:326
1142
+ msgid "You are all good!"
1143
+ msgstr "Det var det!"
1144
+
1145
+ #: includes/i18n.php:327
1146
+ msgid "Sorry, we could not complete the email update. Another user with the same email is already registered."
1147
+ msgstr "Sorry, we could not complete the email update. Another user with the same email is already registered."
1148
+
1149
+ #: includes/i18n.php:328
1150
+ msgid "If you would like to give up the ownership of the %s's account to %s click the Change Ownership button."
1151
+ msgstr "If you would like to give up the ownership of the %s's account to %s click the Change Ownership button."
1152
+
1153
+ #: includes/i18n.php:329
1154
+ msgid "Your email was successfully updated. You should receive an email with confirmation instructions in few moments."
1155
+ msgstr "Your email was successfully updated. You should receive an email with confirmation instructions in few moments."
1156
+
1157
+ #: includes/i18n.php:330
1158
+ msgid "Your name was successfully updated."
1159
+ msgstr "Dit navn er blevet opdateret."
1160
+
1161
+ #: includes/i18n.php:331
1162
+ msgid "You have successfully updated your %s."
1163
+ msgstr "Opdatering af %s blev gennemført."
1164
+
1165
+ #: includes/i18n.php:332
1166
+ msgid "Please provide your full name."
1167
+ msgstr "Indtast venligst dit fulde navn."
1168
+
1169
+ #: includes/i18n.php:333
1170
+ msgid "Verification mail was just sent to %s. If you can't find it after 5 min, please check your spam box."
1171
+ msgstr "Verification mail was just sent to %s. If you can't find it after 5 min, please check your spam box."
1172
+
1173
+ #: includes/i18n.php:334
1174
+ msgid "Just letting you know that the add-ons information of %s is being pulled from an external server."
1175
+ msgstr "Just letting you know that the add-ons information of %s is being pulled from an external server."
1176
+
1177
+ #: includes/i18n.php:335
1178
+ msgid "No credit card required"
1179
+ msgstr "Betalingskort ikke påkrævet"
1180
+
1181
+ #: includes/i18n.php:336
1182
+ msgid "Premium %s version was successfully activated."
1183
+ msgstr "Premium %s version was successfully activated."
1184
+
1185
+ #: includes/i18n.php:337
1186
+ msgid "The upgrade of %s was successfully completed."
1187
+ msgstr "Opgraderingen af %s blev fuldendt."
1188
+
1189
+ #: includes/i18n.php:338
1190
+ msgid "Your account was successfully activated with the %s plan."
1191
+ msgstr "Din konto blev aktiveret med planen %s."
1192
+
1193
+ #: includes/i18n.php:339
1194
+ msgid "Download the latest %s version now"
1195
+ msgstr "Download den seneste version af %s nu"
1196
+
1197
+ #: includes/i18n.php:340
1198
+ msgid "Please follow these steps to complete the upgrade"
1199
+ msgstr "Følg venligst disse trin for at færdiggøre opgraderingen"
1200
+
1201
+ #: includes/i18n.php:341
1202
+ msgid "Download the latest %s version"
1203
+ msgstr "Download den seneste version af %s"
1204
+
1205
+ #: includes/i18n.php:342
1206
+ msgid "Download the latest version"
1207
+ msgstr "Download den seneste version"
1208
+
1209
+ #: includes/i18n.php:343
1210
+ msgid "Deactivate the free version"
1211
+ msgstr "Deaktiver den gratis version"
1212
+
1213
+ #: includes/i18n.php:344
1214
+ msgid "Upload and activate the downloaded version"
1215
+ msgstr "Upload og aktiver den downloadede version"
1216
+
1217
+ #: includes/i18n.php:345
1218
+ msgid "How to upload and activate?"
1219
+ msgstr "Upload og aktivering, hvordan?"
1220
+
1221
+ #: includes/i18n.php:346
1222
+ msgctxt "%s - product name, e.g. Facebook add-on was successfully..."
1223
+ msgid "%s Add-on was successfully purchased."
1224
+ msgstr "Betalingen for tilføjelsen %s blev gennemført."
1225
+
1226
+ #: includes/i18n.php:348
1227
+ msgid "Your %s Add-on plan was successfully upgraded."
1228
+ msgstr "Your %s Add-on plan was successfully upgraded."
1229
+
1230
+ #: includes/i18n.php:349
1231
+ msgid "Your email has been successfully verified - you are AWESOME!"
1232
+ msgstr "Your email has been successfully verified - you are AWESOME!"
1233
+
1234
+ #: includes/i18n.php:350
1235
+ msgid "Your plan was successfully upgraded."
1236
+ msgstr "Din plan er blevet opgraderet."
1237
+
1238
+ #: includes/i18n.php:351
1239
+ msgid "Your plan was successfully changed to %s."
1240
+ msgstr "Din plan er blevet ændret til %s."
1241
+
1242
+ #: includes/i18n.php:352
1243
+ msgid "Your license has expired. You can still continue using the free %s forever."
1244
+ msgstr "Your license has expired. You can still continue using the free %s forever."
1245
+
1246
+ #: includes/i18n.php:353
1247
+ msgid "Your license has been cancelled. If you think it's a mistake, please contact support."
1248
+ msgstr "Din licens er blevet annulleret. Hvis du mener, dette er en fejl, så kontakt venligst support."
1249
+
1250
+ #: includes/i18n.php:354
1251
+ msgid "Your trial has been successfully started."
1252
+ msgstr "Din prøveperiode er begyndt."
1253
+
1254
+ #: includes/i18n.php:355
1255
+ msgid "Your license was successfully activated."
1256
+ msgstr "Din licens er blevet aktiveret."
1257
+
1258
+ #: includes/i18n.php:356
1259
+ msgid "It looks like your site currently doesn't have an active license."
1260
+ msgstr "Det ser ud til, at dit websted endnu ikke har en aktiv licens."
1261
+
1262
+ #: includes/i18n.php:357
1263
+ msgid "Your license was successfully deactivated, you are back to the %s plan."
1264
+ msgstr "Din licens blev deaktiveret, du er tilbage på planen %s."
1265
+
1266
+ #: includes/i18n.php:358
1267
+ msgid "It looks like the license deactivation failed."
1268
+ msgstr "Det ser ud til, at licens-deaktiveringen mislykkedes."
1269
+
1270
+ #: includes/i18n.php:359
1271
+ msgid "It looks like the license could not be activated."
1272
+ msgstr "Det ser ud til, at licensen ikke kunne aktiveres."
1273
+
1274
+ #: includes/i18n.php:360
1275
+ msgid "Error received from the server:"
1276
+ msgstr "Fejl modtager fra serveren:"
1277
+
1278
+ #: includes/i18n.php:361
1279
+ msgid "Your trial has expired. You can still continue using all our free features."
1280
+ msgstr "Din prøveperiode er udløbet. Du kan fortsat bruge alle vores gratis funktioner."
1281
+
1282
+ #: includes/i18n.php:362
1283
+ msgid "Your plan was successfully downgraded. Your %s plan license will expire in %s."
1284
+ msgstr "Din plan blev nedgraderet. Licensen til din %s plan vil udløbe om %s."
1285
+
1286
+ #: includes/i18n.php:363
1287
+ msgid "Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes."
1288
+ msgstr "Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes."
1289
+
1290
+ #: includes/i18n.php:364
1291
+ msgid "It looks like you are not in trial mode anymore so there's nothing to cancel :)"
1292
+ msgstr "It looks like you are not in trial mode anymore so there's nothing to cancel :)"
1293
+
1294
+ #: includes/i18n.php:365
1295
+ msgid "Your %s free trial was successfully cancelled."
1296
+ msgstr "Din gratis prøveperiode for %s er blevet annulleret."
1297
+
1298
+ #: includes/i18n.php:366
1299
+ msgctxt "%s - numeric version number"
1300
+ msgid "Version %s was released."
1301
+ msgstr "Version %s er blevet udgivet."
1302
+
1303
+ #: includes/i18n.php:367
1304
+ msgid "Please download %s."
1305
+ msgstr "Download venligst %s."
1306
+
1307
+ #: includes/i18n.php:368
1308
+ msgctxt "%s - plan name, as the latest professional version here"
1309
+ msgid "the latest %s version here"
1310
+ msgstr "den seneste version af %s her"
1311
+
1312
+ #: includes/i18n.php:370
1313
+ msgid "How do you like %s so far? Test all our %s premium features with a %d-day free trial."
1314
+ msgstr "How do you like %s so far? Test all our %s premium features with a %d-day free trial."
1315
+
1316
+ #: includes/i18n.php:371
1317
+ msgctxt "call to action"
1318
+ msgid "Start free trial"
1319
+ msgstr "Start gratis prøveperiode"
1320
+
1321
+ #: includes/i18n.php:372
1322
+ msgid "Starting trial"
1323
+ msgstr "Starter prøveperiode"
1324
+
1325
+ #: includes/i18n.php:373
1326
+ msgid "Please wait"
1327
+ msgstr "Vent venligst"
1328
+
1329
+ #: includes/i18n.php:374
1330
+ msgid "Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes."
1331
+ msgstr "Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes."
1332
+
1333
+ #: includes/i18n.php:375
1334
+ msgid "You already utilized a trial before."
1335
+ msgstr "Du har allerede brugt din prøveperiode."
1336
+
1337
+ #: includes/i18n.php:376
1338
+ msgid "You are already running the %s in a trial mode."
1339
+ msgstr "You are already running the %s in a trial mode."
1340
+
1341
+ #: includes/i18n.php:377
1342
+ msgid "Plan %s do not exist, therefore, can't start a trial."
1343
+ msgstr "Plan %s eksisterer ikke og kan derfor ikke starte prøveperiode."
1344
+
1345
+ #: includes/i18n.php:378
1346
+ msgid "Plan %s does not support a trial period."
1347
+ msgstr "Plan %s understøtter ikke en prøveperiode."
1348
+
1349
+ #: includes/i18n.php:379
1350
+ msgid "None of the %s's plans supports a trial period."
1351
+ msgstr "None of the %s's plans supports a trial period."
1352
+
1353
+ #: includes/i18n.php:380
1354
+ msgid "Unexpected API error. Please contact the %s's author with the following error."
1355
+ msgstr "Unexpected API error. Please contact the %s's author with the following error."
1356
+
1357
+ #: includes/i18n.php:381
1358
+ msgid "No commitment for %s days - cancel anytime!"
1359
+ msgstr "Ingen bindinger i %s dage - annuller når som helst!"
1360
+
1361
+ #: includes/i18n.php:382
1362
+ msgid "Your license has expired. You can still continue using all the %s features, but you'll need to renew your license to continue getting updates and support."
1363
+ msgstr "Din licens er udløbet. Du kan stadig benytte alle funktionerne i %s, men du bliver nødt til at fornye din licens for at få opdateringer og support."
1364
+
1365
+ #: includes/i18n.php:383
1366
+ msgid "Couldn't activate %s."
1367
+ msgstr "Kunne ikke aktivere %s."
1368
+
1369
+ #: includes/i18n.php:384
1370
+ msgid "Please contact us with the following message:"
1371
+ msgstr "Kontakt os venligst med følgende besked:"
1372
+
1373
+ #: includes/i18n.php:385
1374
+ msgid "It looks like you are still on the %s plan. If you did upgrade or change your plan, it's probably an issue on our side - sorry."
1375
+ msgstr "It looks like you are still on the %s plan. If you did upgrade or change your plan, it's probably an issue on our side - sorry."
1376
+
1377
+ #: includes/i18n.php:386
1378
+ msgid "Please contact us here"
1379
+ msgstr "Kontakt os her"
1380
+
1381
+ #: includes/i18n.php:387
1382
+ msgid "I have upgraded my account but when I try to Sync the License, the plan remains %s."
1383
+ msgstr "I have upgraded my account but when I try to Sync the License, the plan remains %s."
1384
+
1385
+ #: includes/i18n.php:390
1386
+ msgid "From unknown reason, the API connectivity test failed."
1387
+ msgstr "From unknown reason, the API connectivity test failed."
1388
+
1389
+ #: includes/i18n.php:391
1390
+ msgid "It's probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?"
1391
+ msgstr "It's probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?"
1392
+
1393
+ #: includes/i18n.php:392
1394
+ msgid "We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server."
1395
+ msgstr "We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server."
1396
+
1397
+ #: includes/i18n.php:393
1398
+ msgid "Disabled method(s):"
1399
+ msgstr "Disabled method(s):"
1400
+
1401
+ #: includes/i18n.php:394
1402
+ msgid "From unknown reason, CloudFlare, the firewall we use, blocks the connection."
1403
+ msgstr "Af en ukendt årsag blokerer CloudFlare, vores firewall, forbindelsen."
1404
+
1405
+ #: includes/i18n.php:395
1406
+ msgctxt "as pluginX requires an access to our API"
1407
+ msgid "%s requires an access to our API."
1408
+ msgstr "%s påkræver adgang til vores API."
1409
+
1410
+ #: includes/i18n.php:397
1411
+ msgid "It looks like your server is using Squid ACL (access control lists), which blocks the connection."
1412
+ msgstr "Det ser ud til, at din server benytter Squid ACL (access control lists), som blokerer forbindelsen."
1413
+
1414
+ #: includes/i18n.php:398
1415
+ msgid "I don't know what is Squid or ACL, help me!"
1416
+ msgstr "Jeg ved ikke hvad Squid eller ACL er. Hjælp mig!"
1417
+
1418
+ #: includes/i18n.php399, includes/i18n.php:403
1419
+ msgid "We'll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update."
1420
+ msgstr "Vi vil kontakte din udbyder og løse problemet. Når vi har opdatinger i sagen, vil vi følge op med en email til dig på %s."
1421
+
1422
+ #: includes/i18n.php:400
1423
+ msgid "I'm a system administrator"
1424
+ msgstr "Jeg er en system-administrator"
1425
+
1426
+ #: includes/i18n.php:401
1427
+ msgid "Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again."
1428
+ msgstr "Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again."
1429
+
1430
+ #: includes/i18n.php:402
1431
+ msgid "I don't know what is cURL or how to install it, help me!"
1432
+ msgstr "Jeg ved ikke hvad cURL er, eller hvordan jeg installerer det. Hjælp mig!"
1433
+
1434
+ #: includes/i18n.php:404
1435
+ msgid "Great, please install cURL and enable it in your php.ini file. In addition, search for the 'disable_functions' directive in your php.ini file and remove any disabled methods starting with 'curl_'. To make sure it was successfully activated, use 'phpinfo()'. Once activated, deactivate the %s and reactivate it back again."
1436
+ msgstr "Great, please install cURL and enable it in your php.ini file. In addition, search for the 'disable_functions' directive in your php.ini file and remove any disabled methods starting with 'curl_'. To make sure it was successfully activated, use 'phpinfo()'. Once activated, deactivate the %s and reactivate it back again."
1437
+
1438
+ #: includes/i18n.php:405
1439
+ msgid "We are sure it's an issue on our side and more than happy to resolve it for you ASAP if you give us a chance."
1440
+ msgstr "We are sure it's an issue on our side and more than happy to resolve it for you ASAP if you give us a chance."
1441
+
1442
+ #: includes/i18n.php:406
1443
+ msgid "Sorry for the inconvenience and we are here to help if you give us a chance."
1444
+ msgstr "Vi beklager ulejligheden, og vi er her for at hjælpe, hvis du giver os chancen."
1445
+
1446
+ #: includes/i18n.php:407
1447
+ msgid "Yes - I'm giving you a chance to fix it"
1448
+ msgstr "Ja - jeg giver jer en chance for at rette det"
1449
+
1450
+ #: includes/i18n.php:408
1451
+ msgid "We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update."
1452
+ msgstr "We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update."
1453
+
1454
+ #: includes/i18n.php:409
1455
+ msgid "Let's try your previous version"
1456
+ msgstr "Lad os prøve din forrige version"
1457
+
1458
+ #: includes/i18n.php:410
1459
+ msgid "Uninstall this version and install the previous one."
1460
+ msgstr "Afinstaller denne version og installer den forrige."
1461
+
1462
+ #: includes/i18n.php:411
1463
+ msgid "That's exhausting, please deactivate"
1464
+ msgstr "Det er udmattende, deaktiver venligst"
1465
+
1466
+ #: includes/i18n.php:412
1467
+ msgid "We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future."
1468
+ msgstr "We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future."
1469
+
1470
+ #: includes/i18n.php:413
1471
+ msgid "Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience."
1472
+ msgstr "Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience."
1473
+
1474
+ #: includes/i18n.php:414
1475
+ msgctxt "%1s - plugin title, %2s - API domain"
1476
+ msgid "Your server is blocking the access to Freemius' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s"
1477
+ msgstr "Your server is blocking the access to Freemius' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s"
1478
+
1479
+ #: includes/i18n.php:416
1480
+ msgid "It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again."
1481
+ msgstr "It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again."
1482
+
1483
+ #: includes/i18n.php:419
1484
+ msgid "Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder."
1485
+ msgstr "Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder."
1486
+
1487
+ #: includes/i18n.php:420
1488
+ msgid "Thanks for confirming the ownership change. An email was just sent to %s for final approval."
1489
+ msgstr "Thanks for confirming the ownership change. An email was just sent to %s for final approval."
1490
+
1491
+ #: includes/i18n.php:421
1492
+ msgid "%s is the new owner of the account."
1493
+ msgstr "%s er den nye ejer af kontoen."
1494
+
1495
+ #: includes/i18n.php:423
1496
+ msgctxt "addonX cannot run without pluginY"
1497
+ msgid "%s cannot run without %s."
1498
+ msgstr "%s virker ikke uden %s."
1499
+
1500
+ #: includes/i18n.php:425
1501
+ msgctxt "addonX cannot run..."
1502
+ msgid "%s cannot run without the plugin."
1503
+ msgstr "%s virker ikke uden pluginnet."
1504
+
1505
+ #: includes/i18n.php:426
1506
+ msgctxt "pluginX activation was successfully..."
1507
+ msgid "%s activation was successfully completed."
1508
+ msgstr "Aktivering af %s blev gennemført."
1509
+
1510
+ #: includes/i18n.php:428
1511
+ msgctxt "Plugin installer section title"
1512
+ msgid "Features & Pricing"
1513
+ msgstr "Funktioner og priser"
1514
+
1515
+ #: includes/i18n.php:429
1516
+ msgid "Add-on must be deployed to WordPress.org or Freemius."
1517
+ msgstr "Add-on must be deployed to WordPress.org or Freemius."
1518
+
1519
+ #: includes/i18n.php:430
1520
+ msgid "Paid add-on must be deployed to Freemius."
1521
+ msgstr "Paid add-on must be deployed to Freemius."
1522
+
1523
+ #: includes/i18n.php:434
1524
+ msgid "%s is a premium only add-on. You have to purchase a license first before activating the plugin."
1525
+ msgstr "%s is a premium only add-on. You have to purchase a license first before activating the plugin."
1526
+
1527
+ #: includes/i18n.php:435
1528
+ msgid "%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you'll have to purchase a license."
1529
+ msgstr "%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you'll have to purchase a license."
1530
+
1531
+ #: includes/i18n.php:440
1532
+ msgctxt "as every month"
1533
+ msgid "Monthly"
1534
+ msgstr "Månedligt"
1535
+
1536
+ #: includes/i18n.php:441
1537
+ msgctxt "as monthly period"
1538
+ msgid "mo"
1539
+ msgstr "md"
1540
+
1541
+ #: includes/i18n.php:442
1542
+ msgctxt "as once a year"
1543
+ msgid "Annual"
1544
+ msgstr "Årligt"
1545
+
1546
+ #: includes/i18n.php:443
1547
+ msgctxt "as once a year"
1548
+ msgid "Annually"
1549
+ msgstr "Årligt"
1550
+
1551
+ #: includes/i18n.php:444
1552
+ msgctxt "as once a year"
1553
+ msgid "Once"
1554
+ msgstr "Engangsbeløb"
1555
+
1556
+ #: includes/i18n.php:445
1557
+ msgctxt "as annual period"
1558
+ msgid "year"
1559
+ msgstr "år"
1560
+
1561
+ #: includes/i18n.php:446
1562
+ msgid "Lifetime"
1563
+ msgstr "Livstid"
1564
+
1565
+ #: includes/i18n.php:447
1566
+ msgctxt "e.g. the best product"
1567
+ msgid "Best"
1568
+ msgstr "Bedste"
1569
+
1570
+ #: includes/i18n.php:448
1571
+ msgctxt "e.g. billed monthly"
1572
+ msgid "Billed %s"
1573
+ msgstr "Faktureret %s"
1574
+
1575
+ #: includes/i18n.php:449
1576
+ msgctxt "as a discount of $5 or 10%"
1577
+ msgid "Save %s"
1578
+ msgstr "Spar %s"
1579
+
1580
+ #: includes/i18n.php:451
1581
+ msgid "View details"
1582
+ msgstr "Vis detaljer"
1583
+
1584
+ #: includes/i18n.php:455
1585
+ msgctxt "button label"
1586
+ msgid "Approve & Start Trial"
1587
+ msgstr "Godkend & start prøveperiode"
1588
+
1589
+ #: includes/i18n.php:457
1590
+ msgid "You are 1-click away from starting your %1$s-day free trial of the %2$s plan."
1591
+ msgstr "Du er 1 klik fra at begynde din %1$s dages gratis prøveperiode af planen %2$s."
1592
+
1593
+ #: includes/i18n.php:459
1594
+ msgid "For compliance with the WordPress.org guidelines, before we start the trial we ask that you opt-in with your user and non-sensitive site information, allowing the %s to periodically send data to %s to check for version updates and to validate your trial."
1595
+ msgstr "For compliance with the WordPress.org guidelines, before we start the trial we ask that you opt-in with your user and non-sensitive site information, allowing the %s to periodically send data to %s to check for version updates and to validate your trial."
1596
+
1597
+ #: includes/i18n.php:465
1598
+ msgid "Business name"
1599
+ msgstr "Firmanavn"
1600
+
1601
+ #: includes/i18n.php:466
1602
+ msgid "Tax / VAT ID"
1603
+ msgstr "Moms / VAT ID"
1604
+
1605
+ #: includes/i18n.php:467
1606
+ msgid "Address Line %d"
1607
+ msgstr "Adresselinje %d"
1608
+
1609
+ #: includes/i18n.php:468
1610
+ msgid "Country"
1611
+ msgstr "Land"
1612
+
1613
+ #: includes/i18n.php:469
1614
+ msgid "Select Country"
1615
+ msgstr "Vælg land"
1616
+
1617
+ #: includes/i18n.php:470
1618
+ msgid "City"
1619
+ msgstr "By"
1620
+
1621
+ #: includes/i18n.php:471
1622
+ msgid "Town"
1623
+ msgstr "By"
1624
+
1625
+ #: includes/i18n.php:472
1626
+ msgid "State"
1627
+ msgstr "Stat"
1628
+
1629
+ #: includes/i18n.php:473
1630
+ msgid "Province"
1631
+ msgstr "Provins"
1632
+
1633
+ #: includes/i18n.php:474
1634
+ msgid "ZIP / Postal Code"
1635
+ msgstr "ZIP / Postnummer"
1636
+
1637
+ #: includes/i18n.php:479
1638
+ msgid "Installing plugin: %s"
1639
+ msgstr "Installing plugin: %s"
1640
+
1641
+ #: includes/i18n.php:480
1642
+ msgid "Automatic Installation"
1643
+ msgstr "Automatic Installation"
1644
+
1645
+ #: includes/i18n.php:482
1646
+ msgid "%s sec"
1647
+ msgstr "%s sec"
1648
+
1649
+ #: includes/i18n.php:483
1650
+ msgid "An automated download and installation of %s (paid version) from %s will start in %s. If you would like to do it manually - click the cancellation button now."
1651
+ msgstr "An automated download and installation of %s (paid version) from %s will start in %s. If you would like to do it manually - click the cancellation button now."
1652
+
1653
+ #: includes/i18n.php:484
1654
+ msgid "The installation process has started and may take a few minutes to complete. Please wait until it is done - do not refresh this page."
1655
+ msgstr "The installation process has started and may take a few minutes to complete. Please wait until it is done - do not refresh this page."
1656
+
1657
+ #: includes/i18n.php:485
1658
+ msgid "Cancel Installation"
1659
+ msgstr "Cancel Installation"
1660
+
1661
+ #: includes/i18n.php:486
1662
+ msgid "The remote plugin package does not contain a folder with the desired slug and renaming did not work."
1663
+ msgstr "The remote plugin package does not contain a folder with the desired slug and renaming did not work."
1664
+
1665
+ #: includes/i18n.php:487
1666
+ msgid "Invalid module ID."
1667
+ msgstr "Invalid module ID."
1668
+
1669
+ #: includes/i18n.php:488
1670
+ msgid "Auto installation only works for opted-in users."
1671
+ msgstr "Auto installation only works for opted-in users."
1672
+
1673
+ #: includes/i18n.php:489
1674
+ msgid "Premium version already active."
1675
+ msgstr "Premium version already active."
1676
+
1677
+ #: includes/i18n.php:490
1678
+ msgid "Premium add-on version already installed."
1679
+ msgstr "Premium add-on version already installed."
1680
+
1681
+ #: includes/i18n.php:491
1682
+ msgid "You do not have a valid license to access the premium version."
1683
+ msgstr "You do not have a valid license to access the premium version."
1684
+
1685
+ #: includes/i18n.php:492
1686
+ msgid "Plugin is a \"Serviceware\" which means it does not have a premium code version."
1687
+ msgstr "Plugin is a \"Serviceware\" which means it does not have a premium code version."
1688
+
1689
+ #: includes/i18n.php:496
1690
+ msgid "Secure HTTPS %s page, running from an external domain"
1691
+ msgstr "Secure HTTPS %s page, running from an external domain"
1692
+
1693
+ #: includes/i18n.php:497
1694
+ msgid "PCI compliant"
1695
+ msgstr "PCI compliant"
1696
+
1697
+ #: includes/i18n.php:498
1698
+ msgid "View paid features"
1699
+ msgstr "View paid features"
1700
+
1701
+ #: includes/i18n.php:512
1702
+ msgctxt "Plugin installer section title"
1703
+ msgid "Description"
1704
+ msgstr "Beskrivelse"
1705
+
1706
+ #: includes/i18n.php:513
1707
+ msgctxt "Plugin installer section title"
1708
+ msgid "Installation"
1709
+ msgstr "Installering"
1710
+
1711
+ #: includes/i18n.php:514
1712
+ msgctxt "Plugin installer section title"
1713
+ msgid "FAQ"
1714
+ msgstr "FAQ"
1715
+
1716
+ #: includes/i18n.php:515
1717
+ msgctxt "Plugin installer section title"
1718
+ msgid "Changelog"
1719
+ msgstr "Ændringslog"
1720
+
1721
+ #: includes/i18n.php:516
1722
+ msgctxt "Plugin installer section title"
1723
+ msgid "Reviews"
1724
+ msgstr "Anmeldelser"
1725
+
1726
+ #: includes/i18n.php:517
1727
+ msgctxt "Plugin installer section title"
1728
+ msgid "Other Notes"
1729
+ msgstr "Andre noter"
1730
+
1731
+ #: includes/i18n.php:519
1732
+ msgid "%s star"
1733
+ msgstr "%s stjerne"
1734
+
1735
+ #: includes/i18n.php:521
1736
+ msgid "%s stars"
1737
+ msgstr "%s stjerner"
1738
+
1739
+ #: includes/i18n.php:523
1740
+ msgid "%s rating"
1741
+ msgstr "%s vurdering"
1742
+
1743
+ #: includes/i18n.php:525
1744
+ msgid "%s ratings"
1745
+ msgstr "%s vurderinger"
1746
+
1747
+ #: includes/i18n.php:527
1748
+ msgid "%s time"
1749
+ msgstr "%s gang"
1750
+
1751
+ #: includes/i18n.php:529
1752
+ msgid "%s times"
1753
+ msgstr "%s gange"
1754
+
1755
+ #: includes/i18n.php:531
1756
+ msgid "Click to see reviews that provided a rating of %s"
1757
+ msgstr "Click to see reviews that provided a rating of %s"
1758
+
1759
+ #: includes/i18n.php:532
1760
+ msgid "Last Updated"
1761
+ msgstr "Senest opdateret"
1762
+
1763
+ #: includes/i18n.php:533
1764
+ msgid "Requires WordPress Version:"
1765
+ msgstr "Kræver WordPress-version:"
1766
+
1767
+ #: includes/i18n.php:534
1768
+ msgctxt "as the plugin author"
1769
+ msgid "Author:"
1770
+ msgstr "Forfatter:"
1771
+
1772
+ #: includes/i18n.php:535
1773
+ msgid "Compatible up to:"
1774
+ msgstr "Kompatibel op til:"
1775
+
1776
+ #: includes/i18n.php:536
1777
+ msgid "Downloaded:"
1778
+ msgstr "Hentet:"
1779
+
1780
+ #: includes/i18n.php:537
1781
+ msgid "WordPress.org Plugin Page"
1782
+ msgstr "WordPress.org Plugin-side"
1783
+
1784
+ #: includes/i18n.php:538
1785
+ msgid "Plugin Homepage"
1786
+ msgstr "Plugin-websted"
1787
+
1788
+ #: includes/i18n.php:539
1789
+ msgid "Donate to this plugin"
1790
+ msgstr "Donér til dette plugin"
1791
+
1792
+ #: includes/i18n.php:540
1793
+ msgid "Average Rating"
1794
+ msgstr "Gennemsnitlig vurdering"
1795
+
1796
+ #: includes/i18n.php:541
1797
+ msgid "based on %s"
1798
+ msgstr "baseret på %s"
1799
+
1800
+ #: includes/i18n.php:542
1801
+ msgid "Warning:"
1802
+ msgstr "Advarsel:"
1803
+
1804
+ #: includes/i18n.php:543
1805
+ msgid "Contributors"
1806
+ msgstr "Bidragsydere"
1807
+
1808
+ #: includes/i18n.php:544
1809
+ msgid "Plugin Install"
1810
+ msgstr "Plugin Install"
1811
+
1812
+ #: includes/i18n.php:545
1813
+ msgid "This plugin has not been tested with your current version of WordPress."
1814
+ msgstr "This plugin has not been tested with your current version of WordPress."
1815
+
1816
+ #: includes/i18n.php:546
1817
+ msgid "This plugin has not been marked as compatible with your version of WordPress."
1818
+ msgstr "This plugin has not been marked as compatible with your version of WordPress."
1819
+
1820
+ #: includes/i18n.php:547
1821
+ msgid "Newer Version (%s) Installed"
1822
+ msgstr "Nyere version (%s) installeret"
1823
+
1824
+ #: includes/i18n.php:548
1825
+ msgid "Latest Version Installed"
1826
+ msgstr "Seneste version installeret"
freemius/languages/freemius-en.mo ADDED
Binary file
freemius/languages/freemius-en.po ADDED
@@ -0,0 +1,1824 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2017 freemius
2
+ # This file is distributed under the same license as the freemius package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: freemius\n"
6
+ "Report-Msgid-Bugs-To: https://github.com/Freemius/wordpress-sdk/issues\n"
7
+ "POT-Creation-Date: \n"
8
+ "PO-Revision-Date: \n"
9
+ "Last-Translator: Vova Feldman <vova@freemius.com>\n"
10
+ "Language: \n"
11
+ "Language-Team: Freemius Team <admin@freemius.com>\n"
12
+ "Content-Type: text/plain; charset=UTF-8\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "MIME-Version: 1.0\n"
16
+ "X-Poedit-Basepath: ..\n"
17
+ "X-Poedit-KeywordsList: _fs_text;_fs_echo;_fs_esc_attr;_fs_esc_attr_echo;_fs_esc_html;_fs_esc_html_echo;_fs_x:1,2c;_fs_ex:1,2c;_fs_esc_attr_x:1,2c;_fs_esc_html_x:1,2c;_fs_n:1,2;_fs_n_noop:1,2;_fs_nx:1,2,4c;_fs_nx_noop:1,2,3c\n"
18
+ "X-Poedit-SearchPath-0: .\n"
19
+ "X-Poedit-SearchPathExcluded-0: *.js\n"
20
+ "X-Poedit-SourceCharset: UTF-8\n"
21
+
22
+ #: includes/i18n.php:37
23
+ msgid "Account"
24
+ msgstr "Account"
25
+
26
+ #: includes/i18n.php:38
27
+ msgid "Add-On"
28
+ msgstr "Add-On"
29
+
30
+ #: includes/i18n.php:39
31
+ msgid "Contact Us"
32
+ msgstr "Contact Us"
33
+
34
+ #: includes/i18n.php:40
35
+ msgid "Contact Support"
36
+ msgstr "Contact Support"
37
+
38
+ #: includes/i18n.php:41
39
+ msgid "Change Ownership"
40
+ msgstr "Change Ownership"
41
+
42
+ #: includes/i18n.php:42
43
+ msgid "Support"
44
+ msgstr "Support"
45
+
46
+ #: includes/i18n.php:43
47
+ msgid "Support Forum"
48
+ msgstr "Support Forum"
49
+
50
+ #: includes/i18n.php:44
51
+ msgid "Add-Ons"
52
+ msgstr "Add-Ons"
53
+
54
+ #: includes/i18n.php:45
55
+ msgctxt "verb"
56
+ msgid "Upgrade"
57
+ msgstr "Upgrade"
58
+
59
+ #: includes/i18n.php:46
60
+ msgid "Awesome"
61
+ msgstr "Awesome"
62
+
63
+ #: includes/i18n.php:47
64
+ msgctxt "noun"
65
+ msgid "Pricing"
66
+ msgstr "Pricing"
67
+
68
+ #: includes/i18n.php:48
69
+ msgctxt "noun"
70
+ msgid "Price"
71
+ msgstr "Price"
72
+
73
+ #: includes/i18n.php:49
74
+ msgid "Unlimited Updates"
75
+ msgstr "Unlimited Updates"
76
+
77
+ #: includes/i18n.php:50
78
+ msgctxt "verb"
79
+ msgid "Downgrade"
80
+ msgstr "Downgrade"
81
+
82
+ #: includes/i18n.php:51
83
+ msgctxt "verb"
84
+ msgid "Cancel Subscription"
85
+ msgstr "Cancel Subscription"
86
+
87
+ #: includes/i18n.php:52
88
+ msgid "Cancel Trial"
89
+ msgstr "Cancel Trial"
90
+
91
+ #: includes/i18n.php:53
92
+ msgid "Free Trial"
93
+ msgstr "Free Trial"
94
+
95
+ #: includes/i18n.php:54
96
+ msgid "Start my free %s"
97
+ msgstr "Start my free %s"
98
+
99
+ #: includes/i18n.php:55
100
+ msgid "No commitment for %s - cancel anytime"
101
+ msgstr "No commitment for %s - cancel anytime"
102
+
103
+ #: includes/i18n.php:56
104
+ msgid "After your free %s, pay as little as %s"
105
+ msgstr "After your free %s, pay as little as %s"
106
+
107
+ #: includes/i18n.php:57
108
+ msgid "Details"
109
+ msgstr "Details"
110
+
111
+ #: includes/i18n.php:58
112
+ msgid "Account Details"
113
+ msgstr "Account Details"
114
+
115
+ #: includes/i18n.php:59
116
+ msgctxt "verb"
117
+ msgid "Delete"
118
+ msgstr "Delete"
119
+
120
+ #: includes/i18n.php:60
121
+ msgctxt "verb"
122
+ msgid "Show"
123
+ msgstr "Show"
124
+
125
+ #: includes/i18n.php:61
126
+ msgctxt "verb"
127
+ msgid "Hide"
128
+ msgstr "Hide"
129
+
130
+ #: includes/i18n.php:62
131
+ msgctxt "verb"
132
+ msgid "Edit"
133
+ msgstr "Edit"
134
+
135
+ #: includes/i18n.php:63
136
+ msgctxt "verb"
137
+ msgid "Update"
138
+ msgstr "Update"
139
+
140
+ #: includes/i18n.php:64
141
+ msgid "Date"
142
+ msgstr "Date"
143
+
144
+ #: includes/i18n.php:65
145
+ msgid "Amount"
146
+ msgstr "Amount"
147
+
148
+ #: includes/i18n.php:66
149
+ msgid "Invoice"
150
+ msgstr "Invoice"
151
+
152
+ #: includes/i18n.php:67
153
+ msgid "Billing"
154
+ msgstr "Billing"
155
+
156
+ #: includes/i18n.php:68
157
+ msgid "Payments"
158
+ msgstr "Payments"
159
+
160
+ #: includes/i18n.php:69
161
+ msgid "Delete Account"
162
+ msgstr "Delete Account"
163
+
164
+ #: includes/i18n.php:70
165
+ msgctxt "as close a window"
166
+ msgid "Dismiss"
167
+ msgstr "Dismiss"
168
+
169
+ #: includes/i18n.php:71
170
+ msgctxt "as product pricing plan"
171
+ msgid "Plan"
172
+ msgstr "Plan"
173
+
174
+ #: includes/i18n.php:72
175
+ msgid "Change Plan"
176
+ msgstr "Change Plan"
177
+
178
+ #: includes/i18n.php:73
179
+ msgctxt "as download professional version"
180
+ msgid "Download %s Version"
181
+ msgstr "Download %s Version"
182
+
183
+ #: includes/i18n.php:74
184
+ msgctxt "as download professional version now"
185
+ msgid "Download %s version now"
186
+ msgstr "Download %s version now"
187
+
188
+ #: includes/i18n.php:75
189
+ msgctxt "as download latest version"
190
+ msgid "Download Latest"
191
+ msgstr "Download Latest"
192
+
193
+ #: includes/i18n.php:76
194
+ msgctxt "E.g. you have a professional license."
195
+ msgid "You have a %s license."
196
+ msgstr "You have a %s license."
197
+
198
+ #: includes/i18n.php:77
199
+ msgid "New"
200
+ msgstr "New"
201
+
202
+ #: includes/i18n.php:78
203
+ msgid "Free"
204
+ msgstr "Free"
205
+
206
+ #: includes/i18n.php:79
207
+ msgctxt "as trial plan"
208
+ msgid "Trial"
209
+ msgstr "Trial"
210
+
211
+ #: includes/i18n.php:80
212
+ msgctxt "as starting a trial plan"
213
+ msgid "Start Trial"
214
+ msgstr "Start Trial"
215
+
216
+ #: includes/i18n.php:81
217
+ msgctxt "verb"
218
+ msgid "Purchase"
219
+ msgstr "Purchase"
220
+
221
+ #: includes/i18n.php:82
222
+ msgid "Purchase License"
223
+ msgstr "Purchase License"
224
+
225
+ #: includes/i18n.php:83
226
+ msgctxt "verb"
227
+ msgid "Buy"
228
+ msgstr "Buy"
229
+
230
+ #: includes/i18n.php:84
231
+ msgid "Buy License"
232
+ msgstr "Buy License"
233
+
234
+ #: includes/i18n.php:85
235
+ msgid "Single Site License"
236
+ msgstr "Single Site License"
237
+
238
+ #: includes/i18n.php:86
239
+ msgid "Unlimited Licenses"
240
+ msgstr "Unlimited Licenses"
241
+
242
+ #: includes/i18n.php:87
243
+ msgid "Up to %s Sites"
244
+ msgstr "Up to %s Sites"
245
+
246
+ #: includes/i18n.php:88
247
+ msgid "%sRenew your license now%s to access version %s features and support."
248
+ msgstr "%sRenew your license now%s to access version %s features and support."
249
+
250
+ #: includes/i18n.php:89
251
+ msgid "Enter the email address you've used for the upgrade below and we will resend you the license key."
252
+ msgstr "Enter the email address you've used for the upgrade below and we will resend you the license key."
253
+
254
+ #: includes/i18n.php:90
255
+ msgctxt "e.g. Professional Plan"
256
+ msgid "%s Plan"
257
+ msgstr "%s Plan"
258
+
259
+ #: includes/i18n.php:91
260
+ msgid "You are just one step away - %s"
261
+ msgstr "You are just one step away - %s"
262
+
263
+ #: includes/i18n.php:92
264
+ msgctxt "%s - plugin name. As complete \"Jetpack\" activation now"
265
+ msgid "Complete \"%s\" Activation Now"
266
+ msgstr "Complete \"%s\" Activation Now"
267
+
268
+ #: includes/i18n.php:94
269
+ msgid "We made a few tweaks to the %s, %s"
270
+ msgstr "We made a few tweaks to the %s, %s"
271
+
272
+ #: includes/i18n.php:95
273
+ msgid "Opt-in to make \"%s\" Better!"
274
+ msgstr "Opt-in to make \"%s\" Better!"
275
+
276
+ #: includes/i18n.php:96
277
+ msgid "Error"
278
+ msgstr "Error"
279
+
280
+ #: includes/i18n.php:97
281
+ msgid "Freemius SDK couldn't find the plugin's main file. Please contact sdk@freemius.com with the current error."
282
+ msgstr "Freemius SDK couldn't find the plugin's main file. Please contact sdk@freemius.com with the current error."
283
+
284
+ #: includes/i18n.php:100
285
+ msgctxt "as expiration date"
286
+ msgid "Expiration"
287
+ msgstr "Expiration"
288
+
289
+ #: includes/i18n.php:101
290
+ msgctxt "as software license"
291
+ msgid "License"
292
+ msgstr "License"
293
+
294
+ #: includes/i18n.php:102
295
+ msgid "not verified"
296
+ msgstr "not verified"
297
+
298
+ #: includes/i18n.php:103
299
+ msgid "Verify Email"
300
+ msgstr "Verify Email"
301
+
302
+ #: includes/i18n.php:104
303
+ msgctxt "e.g. expires in 2 months"
304
+ msgid "Expires in %s"
305
+ msgstr "Expires in %s"
306
+
307
+ #: includes/i18n.php:105
308
+ msgctxt "e.g. auto renews in 2 months"
309
+ msgid "Auto renews in %s"
310
+ msgstr "Auto renews in %s"
311
+
312
+ #: includes/i18n.php:106
313
+ msgid "No expiration"
314
+ msgstr "No expiration"
315
+
316
+ #: includes/i18n.php:107
317
+ msgid "Expired"
318
+ msgstr "Expired"
319
+
320
+ #: includes/i18n.php:108
321
+ msgid "Cancelled"
322
+ msgstr "Cancelled"
323
+
324
+ #: includes/i18n.php:109
325
+ msgctxt "e.g. In 2 hours"
326
+ msgid "In %s"
327
+ msgstr "In %s"
328
+
329
+ #: includes/i18n.php:110
330
+ msgctxt "e.g. 2 min ago"
331
+ msgid "%s ago"
332
+ msgstr "%s ago"
333
+
334
+ #: includes/i18n.php:112
335
+ msgid "%s or higher"
336
+ msgstr "%s or higher"
337
+
338
+ #: includes/i18n.php:113
339
+ msgctxt "as plugin version"
340
+ msgid "Version"
341
+ msgstr "Version"
342
+
343
+ #: includes/i18n.php:114
344
+ msgid "Name"
345
+ msgstr "Name"
346
+
347
+ #: includes/i18n.php:115
348
+ msgid "Email"
349
+ msgstr "Email"
350
+
351
+ #: includes/i18n.php:116
352
+ msgid "Email address"
353
+ msgstr "Email address"
354
+
355
+ #: includes/i18n.php:117
356
+ msgid "Verified"
357
+ msgstr "Verified"
358
+
359
+ #: includes/i18n.php:118
360
+ msgid "Module"
361
+ msgstr "Module"
362
+
363
+ #: includes/i18n.php:119
364
+ msgid "Module Type"
365
+ msgstr "Module Type"
366
+
367
+ #: includes/i18n.php:120
368
+ msgid "Plugin"
369
+ msgstr "Plugin"
370
+
371
+ #: includes/i18n.php:121
372
+ msgid "Plugins"
373
+ msgstr "Plugins"
374
+
375
+ #: includes/i18n.php:122
376
+ msgid "Theme"
377
+ msgstr "Theme"
378
+
379
+ #: includes/i18n.php:123
380
+ msgid "Themes"
381
+ msgstr "Themes"
382
+
383
+ #: includes/i18n.php:124
384
+ msgctxt "as file/folder path"
385
+ msgid "Path"
386
+ msgstr "Path"
387
+
388
+ #: includes/i18n.php:125
389
+ msgid "Title"
390
+ msgstr "Title"
391
+
392
+ #: includes/i18n.php:126
393
+ msgid "Free version"
394
+ msgstr "Free version"
395
+
396
+ #: includes/i18n.php:127
397
+ msgid "Premium version"
398
+ msgstr "Premium version"
399
+
400
+ #: includes/i18n.php:128
401
+ msgctxt "as WP plugin slug"
402
+ msgid "Slug"
403
+ msgstr "Slug"
404
+
405
+ #: includes/i18n.php:129
406
+ msgid "ID"
407
+ msgstr "ID"
408
+
409
+ #: includes/i18n.php:130
410
+ msgid "Users"
411
+ msgstr "Users"
412
+
413
+ #: includes/i18n.php:131
414
+ msgid "%s Installs"
415
+ msgstr "%s Installs"
416
+
417
+ #: includes/i18n.php:132
418
+ msgctxt "like websites"
419
+ msgid "Sites"
420
+ msgstr "Sites"
421
+
422
+ #: includes/i18n.php:133
423
+ msgid "User ID"
424
+ msgstr "User ID"
425
+
426
+ #: includes/i18n.php:134
427
+ msgid "Site ID"
428
+ msgstr "Site ID"
429
+
430
+ #: includes/i18n.php:135
431
+ msgid "Public Key"
432
+ msgstr "Public Key"
433
+
434
+ #: includes/i18n.php:136
435
+ msgid "Secret Key"
436
+ msgstr "Secret Key"
437
+
438
+ #: includes/i18n.php:137
439
+ msgctxt "as secret encryption key missing"
440
+ msgid "No Secret"
441
+ msgstr "No Secret"
442
+
443
+ #: includes/i18n.php:138
444
+ msgid "No ID"
445
+ msgstr "No ID"
446
+
447
+ #: includes/i18n.php:139
448
+ msgctxt "as synchronize license"
449
+ msgid "Sync License"
450
+ msgstr "Sync License"
451
+
452
+ #: includes/i18n.php:140
453
+ msgctxt "as synchronize"
454
+ msgid "Sync"
455
+ msgstr "Sync"
456
+
457
+ #: includes/i18n.php:141
458
+ msgid "Activate License"
459
+ msgstr "Activate License"
460
+
461
+ #: includes/i18n.php:142
462
+ msgid "Activate Free Version"
463
+ msgstr "Activate Free Version"
464
+
465
+ #: includes/i18n.php:143
466
+ msgid "Please enter the license key that you received in the email right after the purchase:"
467
+ msgstr "Please enter the license key that you received in the email right after the purchase:"
468
+
469
+ #: includes/i18n.php:144
470
+ msgid "Activating license..."
471
+ msgstr "Activating license..."
472
+
473
+ #: includes/i18n.php:145
474
+ msgid "Change License"
475
+ msgstr "Change License"
476
+
477
+ #: includes/i18n.php:146
478
+ msgid "Update License"
479
+ msgstr "Update License"
480
+
481
+ #: includes/i18n.php:147
482
+ msgid "Deactivate License"
483
+ msgstr "Deactivate License"
484
+
485
+ #: includes/i18n.php:148
486
+ msgid "Activate"
487
+ msgstr "Activate"
488
+
489
+ #: includes/i18n.php:149
490
+ msgid "Deactivate"
491
+ msgstr "Deactivate"
492
+
493
+ #: includes/i18n.php:150
494
+ msgid "Skip & Deactivate"
495
+ msgstr "Skip & Deactivate"
496
+
497
+ #: includes/i18n.php:151
498
+ msgid "Skip & %s"
499
+ msgstr "Skip & %s"
500
+
501
+ #: includes/i18n.php:152
502
+ msgid "No - just deactivate"
503
+ msgstr "No - just deactivate"
504
+
505
+ #: includes/i18n.php:153
506
+ msgid "Yes - do your thing"
507
+ msgstr "Yes - do your thing"
508
+
509
+ #: includes/i18n.php:154
510
+ msgctxt "active mode"
511
+ msgid "Active"
512
+ msgstr "Active"
513
+
514
+ #: includes/i18n.php:155
515
+ msgctxt "is active mode?"
516
+ msgid "Is Active"
517
+ msgstr "Is Active"
518
+
519
+ #: includes/i18n.php:156
520
+ msgid "Install Now"
521
+ msgstr "Install Now"
522
+
523
+ #: includes/i18n.php:157
524
+ msgid "Install Update Now"
525
+ msgstr "Install Update Now"
526
+
527
+ #: includes/i18n.php:158
528
+ msgid "More information about %s"
529
+ msgstr "More information about %s"
530
+
531
+ #: includes/i18n.php:159
532
+ msgid "Localhost"
533
+ msgstr "Localhost"
534
+
535
+ #: includes/i18n.php:160
536
+ msgctxt "as activate Professional plan"
537
+ msgid "Activate %s Plan"
538
+ msgstr "Activate %s Plan"
539
+
540
+ #: includes/i18n.php:161
541
+ msgctxt "as 5 licenses left"
542
+ msgid "%s left"
543
+ msgstr "%s left"
544
+
545
+ #: includes/i18n.php:162
546
+ msgid "Last license"
547
+ msgstr "Last license"
548
+
549
+ #: includes/i18n.php:163
550
+ msgid "What is your %s?"
551
+ msgstr "What is your %s?"
552
+
553
+ #: includes/i18n.php:164
554
+ msgid "Activate this add-on"
555
+ msgstr "Activate this add-on"
556
+
557
+ #: includes/i18n.php:165
558
+ msgid "Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?"
559
+ msgstr "Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?"
560
+
561
+ #: includes/i18n.php:166
562
+ msgid "Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the \"Cancel\" button, and first \"Downgrade\" your account. Are you sure you would like to continue with the deletion?"
563
+ msgstr "Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the \"Cancel\" button, and first \"Downgrade\" your account. Are you sure you would like to continue with the deletion?"
564
+
565
+ #: includes/i18n.php:167
566
+ msgid "Deletion is not temporary. Only delete if you no longer want to use this %s anymore. Are you sure you would like to continue with the deletion?"
567
+ msgstr "Deletion is not temporary. Only delete if you no longer want to use this %s anymore. Are you sure you would like to continue with the deletion?"
568
+
569
+ #: includes/i18n.php:168
570
+ msgid "Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s."
571
+ msgstr "Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s."
572
+
573
+ #: includes/i18n.php:169
574
+ msgid "Cancelling the trial will immediately block access to all premium features. Are you sure?"
575
+ msgstr "Cancelling the trial will immediately block access to all premium features. Are you sure?"
576
+
577
+ #: includes/i18n.php:170
578
+ msgid "You can still enjoy all %s features but you will not have access to %s updates and support."
579
+ msgstr "You can still enjoy all %s features but you will not have access to %s updates and support."
580
+
581
+ #: includes/i18n.php:171
582
+ msgid "Once your license expires you can still use the Free version but you will NOT have access to the %s features."
583
+ msgstr "Once your license expires you can still use the Free version but you will NOT have access to the %s features."
584
+
585
+ #: includes/i18n.php:172
586
+ msgid "Are you sure you want to proceed?"
587
+ msgstr "Are you sure you want to proceed?"
588
+
589
+ #: includes/i18n.php:175
590
+ msgid "Add Ons for %s"
591
+ msgstr "Add Ons for %s"
592
+
593
+ #: includes/i18n.php:176
594
+ msgid "We could'nt load the add-ons list. It's probably an issue on our side, please try to come back in few minutes."
595
+ msgstr "We could'nt load the add-ons list. It's probably an issue on our side, please try to come back in few minutes."
596
+
597
+ #: includes/i18n.php:178
598
+ msgid "Anonymous feedback"
599
+ msgstr "Anonymous feedback"
600
+
601
+ #: includes/i18n.php:179
602
+ msgid "Quick feedback"
603
+ msgstr "Quick feedback"
604
+
605
+ #: includes/i18n.php:180
606
+ msgid "If you have a moment, please let us know why you are %s"
607
+ msgstr "If you have a moment, please let us know why you are %s"
608
+
609
+ #: includes/i18n.php:181
610
+ msgid "deactivating"
611
+ msgstr "deactivating"
612
+
613
+ #: includes/i18n.php:182
614
+ msgid "Deactivation"
615
+ msgstr "Deactivation"
616
+
617
+ #: includes/i18n.php:183
618
+ msgid "Theme Switch"
619
+ msgstr "Theme Switch"
620
+
621
+ #: includes/i18n.php:184
622
+ msgid "switching"
623
+ msgstr "switching"
624
+
625
+ #: includes/i18n.php:185
626
+ msgid "Switch"
627
+ msgstr "Switch"
628
+
629
+ #: includes/i18n.php:186
630
+ msgid "Activate %s"
631
+ msgstr "Activate %s"
632
+
633
+ #: includes/i18n.php:187
634
+ msgid "Yes - %s"
635
+ msgstr "Yes - %s"
636
+
637
+ #: includes/i18n.php:188
638
+ msgid "Submit & %s"
639
+ msgstr "Submit & %s"
640
+
641
+ #: includes/i18n.php:189
642
+ msgid "Cancel"
643
+ msgstr "Cancel"
644
+
645
+ #: includes/i18n.php:190
646
+ msgid "I no longer need the %s"
647
+ msgstr "I no longer need the %s"
648
+
649
+ #: includes/i18n.php:191
650
+ msgid "I found a better %s"
651
+ msgstr "I found a better %s"
652
+
653
+ #: includes/i18n.php:192
654
+ msgid "I only needed the %s for a short period"
655
+ msgstr "I only needed the %s for a short period"
656
+
657
+ #: includes/i18n.php:193
658
+ msgid "The %s broke my site"
659
+ msgstr "The %s broke my site"
660
+
661
+ #: includes/i18n.php:194
662
+ msgid "The %s suddenly stopped working"
663
+ msgstr "The %s suddenly stopped working"
664
+
665
+ #: includes/i18n.php:195
666
+ msgid "I can't pay for it anymore"
667
+ msgstr "I can't pay for it anymore"
668
+
669
+ #: includes/i18n.php:196
670
+ msgid "It's a temporary deactivation. I'm just debugging an issue."
671
+ msgstr "It's a temporary deactivation. I'm just debugging an issue."
672
+
673
+ #: includes/i18n.php:197
674
+ msgid "It's a temporary %s. I'm just debugging an issue."
675
+ msgstr "It's a temporary %s. I'm just debugging an issue."
676
+
677
+ #: includes/i18n.php:198
678
+ msgctxt "the text of the \"other\" reason for deactivating the module that is shown in the modal box."
679
+ msgid "Other"
680
+ msgstr "Other"
681
+
682
+ #: includes/i18n.php:200
683
+ msgid "Kindly tell us the reason so we can improve."
684
+ msgstr "Kindly tell us the reason so we can improve."
685
+
686
+ #: includes/i18n.php:201
687
+ msgid "What's the %s's name?"
688
+ msgstr "What's the %s's name?"
689
+
690
+ #: includes/i18n.php:202
691
+ msgid "What price would you feel comfortable paying?"
692
+ msgstr "What price would you feel comfortable paying?"
693
+
694
+ #: includes/i18n.php:203
695
+ msgid "I couldn't understand how to make it work"
696
+ msgstr "I couldn't understand how to make it work"
697
+
698
+ #: includes/i18n.php:204
699
+ msgid "The %s is great, but I need specific feature that you don't support"
700
+ msgstr "The %s is great, but I need specific feature that you don't support"
701
+
702
+ #: includes/i18n.php:205
703
+ msgid "The %s is not working"
704
+ msgstr "The %s is not working"
705
+
706
+ #: includes/i18n.php:206
707
+ msgid "It's not what I was looking for"
708
+ msgstr "It's not what I was looking for"
709
+
710
+ #: includes/i18n.php:207
711
+ msgid "The %s didn't work as expected"
712
+ msgstr "The %s didn't work as expected"
713
+
714
+ #: includes/i18n.php:208
715
+ msgid "What feature?"
716
+ msgstr "What feature?"
717
+
718
+ #: includes/i18n.php:209
719
+ msgid "Kindly share what didn't work so we can fix it for future users..."
720
+ msgstr "Kindly share what didn't work so we can fix it for future users..."
721
+
722
+ #: includes/i18n.php:210
723
+ msgid "What you've been looking for?"
724
+ msgstr "What you've been looking for?"
725
+
726
+ #: includes/i18n.php:211
727
+ msgid "What did you expect?"
728
+ msgstr "What did you expect?"
729
+
730
+ #: includes/i18n.php:212
731
+ msgid "The %s didn't work"
732
+ msgstr "The %s didn't work"
733
+
734
+ #: includes/i18n.php:213
735
+ msgid "I don't like to share my information with you"
736
+ msgstr "I don't like to share my information with you"
737
+
738
+ #: includes/i18n.php:214
739
+ msgid "You might have missed it, but you don't have to share any data and can just %s the opt-in."
740
+ msgstr "You might have missed it, but you don't have to share any data and can just %s the opt-in."
741
+
742
+ #: includes/i18n.php:218
743
+ msgctxt "greeting"
744
+ msgid "Hey %s,"
745
+ msgstr "Hey %s,"
746
+
747
+ #: includes/i18n.php:219
748
+ msgctxt "a greeting. E.g. Thanks John!"
749
+ msgid "Thanks %s!"
750
+ msgstr "Thanks %s!"
751
+
752
+ #: includes/i18n.php:220
753
+ msgid "Never miss an important update - opt-in to our security and feature updates notifications, and non-sensitive diagnostic tracking with %4$s."
754
+ msgstr "Never miss an important update - opt-in to our security and feature updates notifications, and non-sensitive diagnostic tracking with %4$s."
755
+
756
+ #: includes/i18n.php:221
757
+ msgid "Please help us improve %1$s! If you opt-in, some data about your usage of %1$s will be sent to %4$s. If you skip this, that's okay! %1$s will still work just fine."
758
+ msgstr "Please help us improve %1$s! If you opt-in, some data about your usage of %1$s will be sent to %4$s. If you skip this, that's okay! %1$s will still work just fine."
759
+
760
+ #: includes/i18n.php:222
761
+ msgid "You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s."
762
+ msgstr "You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s."
763
+
764
+ #: includes/i18n.php:223
765
+ msgid "complete the install"
766
+ msgstr "complete the install"
767
+
768
+ #: includes/i18n.php:224
769
+ msgid "start the trial"
770
+ msgstr "start the trial"
771
+
772
+ #: includes/i18n.php:225
773
+ msgid "Thanks for purchasing %s! To get started, please enter your license key:"
774
+ msgstr "Thanks for purchasing %s! To get started, please enter your license key:"
775
+
776
+ #: includes/i18n.php:226
777
+ msgid "The %1$s will be periodically sending data to %2$s to check for security and feature updates, and verify the validity of your license."
778
+ msgstr "The %1$s will be periodically sending data to %2$s to check for security and feature updates, and verify the validity of your license."
779
+
780
+ #: includes/i18n.php:227
781
+ msgid "What permissions are being granted?"
782
+ msgstr "What permissions are being granted?"
783
+
784
+ #: includes/i18n.php:228
785
+ msgid "Your Profile Overview"
786
+ msgstr "Your Profile Overview"
787
+
788
+ #: includes/i18n.php:229
789
+ msgid "Name and email address"
790
+ msgstr "Name and email address"
791
+
792
+ #: includes/i18n.php:230
793
+ msgid "Your Site Overview"
794
+ msgstr "Your Site Overview"
795
+
796
+ #: includes/i18n.php:231
797
+ msgid "Site URL, WP version, PHP info, plugins & themes"
798
+ msgstr "Site URL, WP version, PHP info, plugins & themes"
799
+
800
+ #: includes/i18n.php:232
801
+ msgid "Current %s Events"
802
+ msgstr "Current %s Events"
803
+
804
+ #: includes/i18n.php:233
805
+ msgid "Activation, deactivation and uninstall"
806
+ msgstr "Activation, deactivation and uninstall"
807
+
808
+ #: includes/i18n.php:234
809
+ msgid "Plugins & Themes"
810
+ msgstr "Plugins & Themes"
811
+
812
+ #: includes/i18n.php:235
813
+ msgid "Titles, versions and state."
814
+ msgstr "Titles, versions and state."
815
+
816
+ #: includes/i18n.php:236
817
+ msgid "Admin Notices"
818
+ msgstr "Admin Notices"
819
+
820
+ #: includes/i18n.php:237
821
+ msgid "Newsletter"
822
+ msgstr "Newsletter"
823
+
824
+ #: includes/i18n.php:238
825
+ msgid "Updates, announcements, marketing, no spam"
826
+ msgstr "Updates, announcements, marketing, no spam"
827
+
828
+ #: includes/i18n.php:239
829
+ msgid "Privacy Policy"
830
+ msgstr "Privacy Policy"
831
+
832
+ #: includes/i18n.php:240
833
+ msgid "Terms of Service"
834
+ msgstr "Terms of Service"
835
+
836
+ #: includes/i18n.php:241
837
+ msgctxt "as activating plugin"
838
+ msgid "Activating"
839
+ msgstr "Activating"
840
+
841
+ #: includes/i18n.php:242
842
+ msgctxt "as in the process of sending an email"
843
+ msgid "Sending email"
844
+ msgstr "Sending email"
845
+
846
+ #: includes/i18n.php:243
847
+ msgctxt "button label"
848
+ msgid "Allow & Continue"
849
+ msgstr "Allow & Continue"
850
+
851
+ #: includes/i18n.php:244
852
+ msgctxt "button label"
853
+ msgid "Agree & Activate License"
854
+ msgstr "Agree & Activate License"
855
+
856
+ #: includes/i18n.php:245
857
+ msgctxt "verb"
858
+ msgid "Skip"
859
+ msgstr "Skip"
860
+
861
+ #: includes/i18n.php:246
862
+ msgid "Click here to use the plugin anonymously"
863
+ msgstr "Click here to use the plugin anonymously"
864
+
865
+ #: includes/i18n.php:247
866
+ msgid "Re-send activation email"
867
+ msgstr "Re-send activation email"
868
+
869
+ #: includes/i18n.php:248
870
+ msgid "License key"
871
+ msgstr "License key"
872
+
873
+ #: includes/i18n.php:249
874
+ msgid "Send License Key"
875
+ msgstr "Send License Key"
876
+
877
+ #: includes/i18n.php:250
878
+ msgid "Sending license key"
879
+ msgstr "Sending license key"
880
+
881
+ #: includes/i18n.php:251
882
+ msgid "Have a license key?"
883
+ msgstr "Have a license key?"
884
+
885
+ #: includes/i18n.php:252
886
+ msgid "Don't have a license key?"
887
+ msgstr "Don't have a license key?"
888
+
889
+ #: includes/i18n.php:253
890
+ msgid "Can't find your license key?"
891
+ msgstr "Can't find your license key?"
892
+
893
+ #: includes/i18n.php:254
894
+ msgid "We couldn't find your email address in the system, are you sure it's the right address?"
895
+ msgstr "We couldn't find your email address in the system, are you sure it's the right address?"
896
+
897
+ #: includes/i18n.php:255
898
+ msgid "We can't see any active licenses associated with that email address, are you sure it's the right address?"
899
+ msgstr "We can't see any active licenses associated with that email address, are you sure it's the right address?"
900
+
901
+ #: includes/i18n.php:256
902
+ msgid "Opt In"
903
+ msgstr "Opt In"
904
+
905
+ #: includes/i18n.php:257
906
+ msgid "Opt Out"
907
+ msgstr "Opt Out"
908
+
909
+ #: includes/i18n.php:258
910
+ msgid "On second thought - I want to continue helping"
911
+ msgstr "On second thought - I want to continue helping"
912
+
913
+ #: includes/i18n.php:259
914
+ msgid "Opting out..."
915
+ msgstr "Opting out..."
916
+
917
+ #: includes/i18n.php:260
918
+ msgid "Opting in..."
919
+ msgstr "Opting in..."
920
+
921
+ #: includes/i18n.php:261
922
+ msgid "We appreciate your help in making the %s better by letting us track some usage data."
923
+ msgstr "We appreciate your help in making the %s better by letting us track some usage data."
924
+
925
+ #: includes/i18n.php:262
926
+ msgid "Usage tracking is done in the name of making %s better. Making a better user experience, prioritizing new features, and more good things. We'd really appreciate if you'll reconsider letting us continue with the tracking."
927
+ msgstr "Usage tracking is done in the name of making %s better. Making a better user experience, prioritizing new features, and more good things. We'd really appreciate if you'll reconsider letting us continue with the tracking."
928
+
929
+ #: includes/i18n.php:263
930
+ msgid "By clicking \"Opt Out\", we will no longer be sending any data from %s to %s."
931
+ msgstr "By clicking \"Opt Out\", we will no longer be sending any data from %s to %s."
932
+
933
+ #: includes/i18n.php:267
934
+ msgid "Screenshots"
935
+ msgstr "Screenshots"
936
+
937
+ #: includes/i18n.php:268
938
+ msgid "Click to view full-size screenshot %d"
939
+ msgstr "Click to view full-size screenshot %d"
940
+
941
+ #: includes/i18n.php:272
942
+ msgid "Freemius Debug"
943
+ msgstr "Freemius Debug"
944
+
945
+ #: includes/i18n.php:273
946
+ msgctxt "as turned on"
947
+ msgid "On"
948
+ msgstr "On"
949
+
950
+ #: includes/i18n.php:274
951
+ msgctxt "as turned off"
952
+ msgid "Off"
953
+ msgstr "Off"
954
+
955
+ #: includes/i18n.php:275
956
+ msgctxt "as code debugging"
957
+ msgid "Debugging"
958
+ msgstr "Debugging"
959
+
960
+ #: includes/i18n.php:276
961
+ msgid "Freemius State"
962
+ msgstr "Freemius State"
963
+
964
+ #: includes/i18n.php:277
965
+ msgctxt "as connection was successful"
966
+ msgid "Connected"
967
+ msgstr "Connected"
968
+
969
+ #: includes/i18n.php:278
970
+ msgctxt "as connection blocked"
971
+ msgid "Blocked"
972
+ msgstr "Blocked"
973
+
974
+ #: includes/i18n.php:279
975
+ msgctxt "as application program interface"
976
+ msgid "API"
977
+ msgstr "API"
978
+
979
+ #: includes/i18n.php:280
980
+ msgctxt "as software development kit versions"
981
+ msgid "SDK"
982
+ msgstr "SDK"
983
+
984
+ #: includes/i18n.php:281
985
+ msgctxt "as software development kit versions"
986
+ msgid "SDK Versions"
987
+ msgstr "SDK Versions"
988
+
989
+ #: includes/i18n.php:282
990
+ msgctxt "as plugin folder path"
991
+ msgid "Plugin Path"
992
+ msgstr "Plugin Path"
993
+
994
+ #: includes/i18n.php:283
995
+ msgctxt "as sdk path"
996
+ msgid "SDK Path"
997
+ msgstr "SDK Path"
998
+
999
+ #: includes/i18n.php:284
1000
+ msgid "Add Ons of Plugin %s"
1001
+ msgstr "Add Ons of Plugin %s"
1002
+
1003
+ #: includes/i18n.php:285
1004
+ msgid "Are you sure you want to delete all Freemius data?"
1005
+ msgstr "Are you sure you want to delete all Freemius data?"
1006
+
1007
+ #: includes/i18n.php:286
1008
+ msgid "Actions"
1009
+ msgstr "Actions"
1010
+
1011
+ #: includes/i18n.php:287
1012
+ msgid "Delete All Accounts"
1013
+ msgstr "Delete All Accounts"
1014
+
1015
+ #: includes/i18n.php:288
1016
+ msgid "Start Fresh"
1017
+ msgstr "Start Fresh"
1018
+
1019
+ #: includes/i18n.php:289
1020
+ msgid "Clear API Cache"
1021
+ msgstr "Clear API Cache"
1022
+
1023
+ #: includes/i18n.php:290
1024
+ msgid "Sync Data From Server"
1025
+ msgstr "Sync Data From Server"
1026
+
1027
+ #: includes/i18n.php:291
1028
+ msgid "Scheduled Crons"
1029
+ msgstr "Scheduled Crons"
1030
+
1031
+ #: includes/i18n.php:292
1032
+ msgid "Cron Type"
1033
+ msgstr "Cron Type"
1034
+
1035
+ #: includes/i18n.php:293
1036
+ msgid "Plugins & Themes Sync"
1037
+ msgstr "Plugins & Themes Sync"
1038
+
1039
+ #: includes/i18n.php:294
1040
+ msgid "%s Licenses"
1041
+ msgstr "%s Licenses"
1042
+
1043
+ #: includes/i18n.php:295
1044
+ msgid "Debug Log"
1045
+ msgstr "Debug Log"
1046
+
1047
+ #: includes/i18n.php:296
1048
+ msgid "All"
1049
+ msgstr "All"
1050
+
1051
+ #: includes/i18n.php:297
1052
+ msgid "File"
1053
+ msgstr "File"
1054
+
1055
+ #: includes/i18n.php:298
1056
+ msgid "Function"
1057
+ msgstr "Function"
1058
+
1059
+ #: includes/i18n.php:299
1060
+ msgid "Process ID"
1061
+ msgstr "Process ID"
1062
+
1063
+ #: includes/i18n.php:300
1064
+ msgid "Logger"
1065
+ msgstr "Logger"
1066
+
1067
+ #: includes/i18n.php:301
1068
+ msgid "Message"
1069
+ msgstr "Message"
1070
+
1071
+ #: includes/i18n.php:302
1072
+ msgid "Download"
1073
+ msgstr "Download"
1074
+
1075
+ #: includes/i18n.php:303
1076
+ msgid "Filter"
1077
+ msgstr "Filter"
1078
+
1079
+ #: includes/i18n.php:304
1080
+ msgid "Type"
1081
+ msgstr "Type"
1082
+
1083
+ #: includes/i18n.php:305
1084
+ msgid "All Types"
1085
+ msgstr "All Types"
1086
+
1087
+ #: includes/i18n.php:306
1088
+ msgid "All Requests"
1089
+ msgstr "All Requests"
1090
+
1091
+ #: includes/i18n.php:310
1092
+ msgctxt "as congratulations"
1093
+ msgid "Congrats"
1094
+ msgstr "Congrats"
1095
+
1096
+ #: includes/i18n.php:311
1097
+ msgctxt "exclamation"
1098
+ msgid "Oops"
1099
+ msgstr "Oops"
1100
+
1101
+ #: includes/i18n.php:312
1102
+ msgctxt "interjection expressing joy or exuberance"
1103
+ msgid "Yee-haw"
1104
+ msgstr "Yee-haw"
1105
+
1106
+ #: includes/i18n.php:313
1107
+ msgctxt "(especially in electronic communication) used to express elation, enthusiasm, or triumph."
1108
+ msgid "W00t"
1109
+ msgstr "W00t"
1110
+
1111
+ #: includes/i18n.php:315
1112
+ msgctxt "a positive response"
1113
+ msgid "Right on"
1114
+ msgstr "Right on"
1115
+
1116
+ #: includes/i18n.php:316
1117
+ msgctxt "something somebody says when they are thinking about what you have just said. "
1118
+ msgid "Hmm"
1119
+ msgstr "Hmm"
1120
+
1121
+ #: includes/i18n.php:318
1122
+ msgid "O.K"
1123
+ msgstr "O.K"
1124
+
1125
+ #: includes/i18n.php:319
1126
+ msgctxt "exclamation"
1127
+ msgid "Hey"
1128
+ msgstr "Hey"
1129
+
1130
+ #: includes/i18n.php:320
1131
+ msgctxt "advance notice of something that will need attention."
1132
+ msgid "Heads up"
1133
+ msgstr "Heads up"
1134
+
1135
+ #: includes/i18n.php:325
1136
+ msgid "Seems like you got the latest release."
1137
+ msgstr "Seems like you got the latest release."
1138
+
1139
+ #: includes/i18n.php:326
1140
+ msgid "You are all good!"
1141
+ msgstr "You are all good!"
1142
+
1143
+ #: includes/i18n.php:327
1144
+ msgid "Sorry, we could not complete the email update. Another user with the same email is already registered."
1145
+ msgstr "Sorry, we could not complete the email update. Another user with the same email is already registered."
1146
+
1147
+ #: includes/i18n.php:328
1148
+ msgid "If you would like to give up the ownership of the %s's account to %s click the Change Ownership button."
1149
+ msgstr "If you would like to give up the ownership of the %s's account to %s click the Change Ownership button."
1150
+
1151
+ #: includes/i18n.php:329
1152
+ msgid "Your email was successfully updated. You should receive an email with confirmation instructions in few moments."
1153
+ msgstr "Your email was successfully updated. You should receive an email with confirmation instructions in few moments."
1154
+
1155
+ #: includes/i18n.php:330
1156
+ msgid "Your name was successfully updated."
1157
+ msgstr "Your name was successfully updated."
1158
+
1159
+ #: includes/i18n.php:331
1160
+ msgid "You have successfully updated your %s."
1161
+ msgstr "You have successfully updated your %s."
1162
+
1163
+ #: includes/i18n.php:332
1164
+ msgid "Please provide your full name."
1165
+ msgstr "Please provide your full name."
1166
+
1167
+ #: includes/i18n.php:333
1168
+ msgid "Verification mail was just sent to %s. If you can't find it after 5 min, please check your spam box."
1169
+ msgstr "Verification mail was just sent to %s. If you can't find it after 5 min, please check your spam box."
1170
+
1171
+ #: includes/i18n.php:334
1172
+ msgid "Just letting you know that the add-ons information of %s is being pulled from an external server."
1173
+ msgstr "Just letting you know that the add-ons information of %s is being pulled from an external server."
1174
+
1175
+ #: includes/i18n.php:335
1176
+ msgid "No credit card required"
1177
+ msgstr "No credit card required"
1178
+
1179
+ #: includes/i18n.php:336
1180
+ msgid "Premium %s version was successfully activated."
1181
+ msgstr "Premium %s version was successfully activated."
1182
+
1183
+ #: includes/i18n.php:337
1184
+ msgid "The upgrade of %s was successfully completed."
1185
+ msgstr "The upgrade of %s was successfully completed."
1186
+
1187
+ #: includes/i18n.php:338
1188
+ msgid "Your account was successfully activated with the %s plan."
1189
+ msgstr "Your account was successfully activated with the %s plan."
1190
+
1191
+ #: includes/i18n.php:339
1192
+ msgid "Download the latest %s version now"
1193
+ msgstr "Download the latest %s version now"
1194
+
1195
+ #: includes/i18n.php:340
1196
+ msgid "Please follow these steps to complete the upgrade"
1197
+ msgstr "Please follow these steps to complete the upgrade"
1198
+
1199
+ #: includes/i18n.php:341
1200
+ msgid "Download the latest %s version"
1201
+ msgstr "Download the latest %s version"
1202
+
1203
+ #: includes/i18n.php:342
1204
+ msgid "Download the latest version"
1205
+ msgstr "Download the latest version"
1206
+
1207
+ #: includes/i18n.php:343
1208
+ msgid "Deactivate the free version"
1209
+ msgstr "Deactivate the free version"
1210
+
1211
+ #: includes/i18n.php:344
1212
+ msgid "Upload and activate the downloaded version"
1213
+ msgstr "Upload and activate the downloaded version"
1214
+
1215
+ #: includes/i18n.php:345
1216
+ msgid "How to upload and activate?"
1217
+ msgstr "How to upload and activate?"
1218
+
1219
+ #: includes/i18n.php:346
1220
+ msgctxt "%s - product name, e.g. Facebook add-on was successfully..."
1221
+ msgid "%s Add-on was successfully purchased."
1222
+ msgstr "%s Add-on was successfully purchased."
1223
+
1224
+ #: includes/i18n.php:348
1225
+ msgid "Your %s Add-on plan was successfully upgraded."
1226
+ msgstr "Your %s Add-on plan was successfully upgraded."
1227
+
1228
+ #: includes/i18n.php:349
1229
+ msgid "Your email has been successfully verified - you are AWESOME!"
1230
+ msgstr "Your email has been successfully verified - you are AWESOME!"
1231
+
1232
+ #: includes/i18n.php:350
1233
+ msgid "Your plan was successfully upgraded."
1234
+ msgstr "Your plan was successfully upgraded."
1235
+
1236
+ #: includes/i18n.php:351
1237
+ msgid "Your plan was successfully changed to %s."
1238
+ msgstr "Your plan was successfully changed to %s."
1239
+
1240
+ #: includes/i18n.php:352
1241
+ msgid "Your license has expired. You can still continue using the free %s forever."
1242
+ msgstr "Your license has expired. You can still continue using the free %s forever."
1243
+
1244
+ #: includes/i18n.php:353
1245
+ msgid "Your license has been cancelled. If you think it's a mistake, please contact support."
1246
+ msgstr "Your license has been cancelled. If you think it's a mistake, please contact support."
1247
+
1248
+ #: includes/i18n.php:354
1249
+ msgid "Your trial has been successfully started."
1250
+ msgstr "Your trial has been successfully started."
1251
+
1252
+ #: includes/i18n.php:355
1253
+ msgid "Your license was successfully activated."
1254
+ msgstr "Your license was successfully activated."
1255
+
1256
+ #: includes/i18n.php:356
1257
+ msgid "It looks like your site currently doesn't have an active license."
1258
+ msgstr "It looks like your site currently doesn't have an active license."
1259
+
1260
+ #: includes/i18n.php:357
1261
+ msgid "Your license was successfully deactivated, you are back to the %s plan."
1262
+ msgstr "Your license was successfully deactivated, you are back to the %s plan."
1263
+
1264
+ #: includes/i18n.php:358
1265
+ msgid "It looks like the license deactivation failed."
1266
+ msgstr "It looks like the license deactivation failed."
1267
+
1268
+ #: includes/i18n.php:359
1269
+ msgid "It looks like the license could not be activated."
1270
+ msgstr "It looks like the license could not be activated."
1271
+
1272
+ #: includes/i18n.php:360
1273
+ msgid "Error received from the server:"
1274
+ msgstr "Error received from the server:"
1275
+
1276
+ #: includes/i18n.php:361
1277
+ msgid "Your trial has expired. You can still continue using all our free features."
1278
+ msgstr "Your trial has expired. You can still continue using all our free features."
1279
+
1280
+ #: includes/i18n.php:362
1281
+ msgid "Your plan was successfully downgraded. Your %s plan license will expire in %s."
1282
+ msgstr "Your plan was successfully downgraded. Your %s plan license will expire in %s."
1283
+
1284
+ #: includes/i18n.php:363
1285
+ msgid "Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes."
1286
+ msgstr "Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes."
1287
+
1288
+ #: includes/i18n.php:364
1289
+ msgid "It looks like you are not in trial mode anymore so there's nothing to cancel :)"
1290
+ msgstr "It looks like you are not in trial mode anymore so there's nothing to cancel :)"
1291
+
1292
+ #: includes/i18n.php:365
1293
+ msgid "Your %s free trial was successfully cancelled."
1294
+ msgstr "Your %s free trial was successfully cancelled."
1295
+
1296
+ #: includes/i18n.php:366
1297
+ msgctxt "%s - numeric version number"
1298
+ msgid "Version %s was released."
1299
+ msgstr "Version %s was released."
1300
+
1301
+ #: