Easy Facebook Like Box (Facebook Page Plugin) – Custom Facebook Feed – Auto PopUp - Version 4.3.1

Version Description

Next and previous story in popup. Added some fancy effects to popup. Load asynchronously to avoid render blocking.

Download this release

Release Info

Developer jwebsol
Plugin Icon 128x128 Easy Facebook Like Box (Facebook Page Plugin) – Custom Facebook Feed – Auto PopUp
Version 4.3.1
Comparing to
See all releases

Code changes from version 4.3.0 to 4.3.1

Files changed (134) hide show
  1. README.txt +16 -6
  2. admin/assets/css/index.php +0 -1
  3. admin/assets/js/index.php +0 -1
  4. admin/easy-facebook-likebox-admin.php +2 -2
  5. assets/banner-772x250.jpg +0 -0
  6. assets/banner-772x250.png +0 -0
  7. assets/index.php +0 -1
  8. assets/screenshot-1.png +0 -0
  9. assets/screenshot-2.png +0 -0
  10. assets/screenshot-3.png +0 -0
  11. assets/screenshot-4.png +0 -0
  12. assets/screenshot-5.png +0 -0
  13. assets/screenshot-6.png +0 -0
  14. assets/screenshot-7.png +0 -0
  15. easy-facebook-likebox.php +31 -22
  16. freemius/.codeclimate.yml +13 -0
  17. freemius/.travis.yml +11 -0
  18. freemius/LICENSE.txt +340 -0
  19. freemius/README.md +250 -0
  20. freemius/assets/css/admin/account.css +1 -0
  21. freemius/assets/css/admin/add-ons.css +2 -0
  22. freemius/assets/css/admin/common.css +1 -0
  23. freemius/assets/css/admin/connect.css +1 -0
  24. freemius/assets/css/admin/deactivation-feedback.css +1 -0
  25. freemius/assets/css/admin/debug.css +1 -0
  26. freemius/assets/css/admin/dialog-boxes.css +3 -0
  27. freemius/assets/css/admin/license-activation.css +1 -0
  28. freemius/assets/css/common.css +1 -0
  29. assets/PluginIcon - Copy.png → freemius/assets/img/easy-facebook-likebox.png +0 -0
  30. freemius/assets/img/plugin-icon.png +0 -0
  31. freemius/assets/js/jquery.ba-postmessage.js +222 -0
  32. freemius/assets/js/jquery.ba-postmessage.min.js +9 -0
  33. freemius/assets/js/nojquery.ba-postmessage.js +140 -0
  34. freemius/assets/js/nojquery.ba-postmessage.min.js +12 -0
  35. freemius/assets/js/postmessage.js +110 -0
  36. freemius/assets/scss/_colors.scss +58 -0
  37. freemius/assets/scss/_functions.scss +0 -0
  38. freemius/assets/scss/_load.scss +4 -0
  39. freemius/assets/scss/_mixins.scss +224 -0
  40. freemius/assets/scss/_start.scss +4 -0
  41. freemius/assets/scss/_vars.scss +5 -0
  42. freemius/assets/scss/admin/_deactivation-feedback.scss +42 -0
  43. freemius/assets/scss/admin/_license-activation.scss +7 -0
  44. freemius/assets/scss/admin/_license-key-resend.scss +35 -0
  45. freemius/assets/scss/admin/_modal-common.scss +104 -0
  46. freemius/assets/scss/admin/account.scss +184 -0
  47. freemius/assets/scss/admin/add-ons.scss +449 -0
  48. freemius/assets/scss/admin/common.scss +134 -0
  49. freemius/assets/scss/admin/connect.scss +471 -0
  50. freemius/assets/scss/admin/debug.scss +91 -0
  51. freemius/assets/scss/admin/dialog-boxes.scss +4 -0
  52. freemius/composer.json +10 -0
  53. freemius/config.php +229 -0
  54. freemius/includes/class-freemius-abstract.php +454 -0
  55. freemius/includes/class-freemius.php +10148 -0
  56. freemius/includes/class-fs-api.php +455 -0
  57. freemius/includes/class-fs-logger.php +179 -0
  58. freemius/includes/class-fs-plugin-updater.php +334 -0
  59. freemius/includes/class-fs-security.php +61 -0
  60. freemius/includes/debug/class-fs-debug-bar-panel.php +64 -0
  61. freemius/includes/debug/debug-bar-start.php +52 -0
  62. freemius/includes/entities/class-fs-entity.php +149 -0
  63. freemius/includes/entities/class-fs-payment.php +94 -0
  64. freemius/includes/entities/class-fs-plugin-info.php +34 -0
  65. freemius/includes/entities/class-fs-plugin-license.php +194 -0
  66. freemius/includes/entities/class-fs-plugin-plan.php +140 -0
  67. freemius/includes/entities/class-fs-plugin-tag.php +24 -0
  68. freemius/includes/entities/class-fs-plugin.php +90 -0
  69. freemius/includes/entities/class-fs-pricing.php +141 -0
  70. freemius/includes/entities/class-fs-scope-entity.php +29 -0
  71. freemius/includes/entities/class-fs-site.php +127 -0
  72. freemius/includes/entities/class-fs-subscription.php +125 -0
  73. freemius/includes/entities/class-fs-user.php +62 -0
  74. freemius/includes/fs-core-functions.php +453 -0
  75. freemius/includes/fs-essential-functions.php +412 -0
  76. freemius/includes/fs-plugin-info-dialog.php +936 -0
  77. freemius/includes/i18n.php +384 -0
  78. freemius/includes/managers/class-fs-admin-menu-manager.php +549 -0
  79. freemius/includes/managers/class-fs-admin-notice-manager.php +310 -0
  80. freemius/includes/managers/class-fs-cache-manager.php +237 -0
  81. freemius/includes/managers/class-fs-key-value-storage.php +326 -0
  82. freemius/includes/managers/class-fs-license-manager.php +101 -0
  83. freemius/includes/managers/class-fs-option-manager.php +302 -0
  84. freemius/includes/managers/class-fs-plan-manager.php +162 -0
  85. freemius/includes/managers/class-fs-plugin-manager.php +154 -0
  86. freemius/includes/sdk/Exceptions/ArgumentNotExistException.php +6 -0
  87. freemius/includes/sdk/Exceptions/EmptyArgumentException.php +6 -0
  88. freemius/includes/sdk/Exceptions/Exception.php +75 -0
  89. freemius/includes/sdk/Exceptions/InvalidArgumentException.php +6 -0
  90. freemius/includes/sdk/Exceptions/OAuthException.php +12 -0
  91. freemius/includes/sdk/Freemius.php +576 -0
  92. freemius/includes/sdk/FreemiusBase.php +178 -0
  93. freemius/includes/sdk/LICENSE.txt +340 -0
  94. freemius/includes/supplements/fs-essential-functions-1.1.7.1.php +45 -0
  95. freemius/require.php +43 -0
  96. freemius/start.php +310 -0
  97. freemius/templates/account.php +688 -0
  98. freemius/templates/add-ons.php +152 -0
  99. freemius/templates/admin-notice.php +46 -0
  100. freemius/templates/all-admin-notice.php +35 -0
  101. freemius/templates/billing.php +106 -0
  102. freemius/templates/checkout.php +262 -0
  103. freemius/templates/connect.php +346 -0
  104. freemius/templates/contact.php +85 -0
  105. freemius/templates/debug.php +295 -0
  106. freemius/templates/debug/api-calls.php +138 -0
  107. freemius/templates/debug/logger.php +60 -0
  108. freemius/templates/debug/plugins-themes-sync.php +68 -0
  109. freemius/templates/debug/scheduled-crons.php +100 -0
  110. freemius/templates/email.php +46 -0
  111. freemius/templates/firewall-issues-js.php +60 -0
  112. freemius/templates/forms/deactivation/contact.php +20 -0
  113. freemius/templates/forms/deactivation/form.php +311 -0
  114. freemius/templates/forms/deactivation/retry-skip.php +21 -0
  115. freemius/templates/forms/license-activation.php +211 -0
  116. freemius/templates/forms/resend-key.php +203 -0
  117. freemius/templates/plugin-icon.php +93 -0
  118. freemius/templates/plugin-info/description.php +75 -0
  119. freemius/templates/plugin-info/features.php +97 -0
  120. freemius/templates/plugin-info/screenshots.php +33 -0
  121. freemius/templates/powered-by.php +39 -0
  122. freemius/templates/pricing.php +108 -0
  123. freemius/templates/sticky-admin-notice-js.php +40 -0
  124. includes/easy-custom-facebook-feed-widget.php +3 -4
  125. includes/easy-facebook-page-plugin-widget.php +48 -94
  126. languages/easy-facebook-likebox.pot +2 -0
  127. public/assets/css/animate.css +3340 -0
  128. public/assets/css/public.css +100 -11
  129. public/assets/images/loader.gif +0 -0
  130. public/assets/images/loader_icon.gif +0 -0
  131. public/assets/js/public.js +123 -30
  132. public/easy-facebook-likebox.php +32 -5
  133. public/includes/core-functions.php +175 -0
  134. public/views/feed.php +8 -8
README.txt CHANGED
@@ -1,10 +1,10 @@
1
- === Easy Facebook Like Box (Page Plugin) - Custom Facebook Feed - Auto PopUp ===
2
  Contributors: sjaved, DaNish Ali, jwebsol
3
- Tags: custom facebook feed, facebook feed, facebook page plugin, page plugin, adoptive, facebook, facebook like box,, like box, facebook like box, facebook like box widget, facebook like box shortcodes, shortcodes, facebook like box plugin, facebook like box wordpress plugin, plugin, responsive facebook like box, responsive, facebook like box in 75 locales, facebook like box in 75 languages, facebook like box in PopUp, PopUp, Auto PopUp, like box in PopUp, social media, Facebook fan page, facebook share, advanced responsive facebook likebox, facebook wall, facebook sidebar, facebook recommend, open graph, facebook page, facebook group
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=sjaved786%40gmail%2ecom&lc=US&item_name=Easy%20Facebook%20Like%20Box%20WordPress%20Plugin&item_number=efbl&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
5
  Requires at least: 3.3
6
  Tested up to: 4.7.2
7
- Stable tag: 4.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -12,7 +12,7 @@ Easy facebook like box WordPress plugin allows to display custom facebook feed,
12
 
13
  == Description ==
14
 
15
- There are **three** main features of this plugin, **Custom Facebook Feed**, **Faceook Page Plugin** (previously Like Box) and **Auto PopUp**.
16
 
17
  [Custom facebook feed demo](https://jwebsol.com/custom-facebook-feed/ "See this plugin in action (Custom facebook feed demo)") | [Fixed width demo](https://jwebsol.com/easy-facebook-like-box-plugin-demo/ "See this plugin in action (Fixed width)") | [Responsive demo](https://jwebsol.com/easy-facebook-like-box-responsive-demo/ "See this plugin in action (Responsive)") |
18
  [Auto PopUp demo](https://jwebsol.com/easy-facebook-like-box-auto-popup-demo/ "See this plugin in action (Auto PopUp)")
@@ -33,10 +33,11 @@ Displays a Facebook Page Plugin (previously Facebook Like Box). The Facebook Pag
33
  1. Chose your desired language or input your own language (if not in list).
34
  1. Support 75 different locales.
35
  1. Like box in responsive PopUp/Modal window.
 
36
  1. Enable/Disable PopUp.
37
  1. All above options are available with PopUp.
38
  1. Generate shortcode using widget form.
39
- 1. Ssupport all WordPress shortcodes and even html in PopUp
40
  1. Set PopUp delay from Back-end.
41
  1. Show PopUp on home page only.
42
  1. Show PopUp if visitors are logged in
@@ -91,6 +92,11 @@ Thanks to *Marek Sierociński* for translating this plugin into polish language
91
  3. Navigate to "Appearance > Widgets" and drag and drop "Easy Facebook Likebox" in desired widget area or use the shortcode in page/post generated by widget.
92
 
93
  == Upgrade Notice ==
 
 
 
 
 
94
  = 4.3.0 =
95
  MUST update to make it work with latest facebook API.
96
 
@@ -155,8 +161,12 @@ http://wordpress.org/support/topic/need-feed-back-on-plugin-feature/
155
  8. Easy Facebook Like Box settings dashboard.
156
  9. Auto PopUp settings panel.
157
 
158
-
159
  == Changelog ==
 
 
 
 
 
160
  = 4.3.0 =
161
  * Fixed: Migrating from Facebook API 2.1 to 2.8
162
  * Some other minor improvements and fixes
1
+ === Easy Facebook Like Box (Facebook Page Plugin) - Custom Facebook Feed - Auto PopUp ===
2
  Contributors: sjaved, DaNish Ali, jwebsol
3
+ Tags: easy custom facebook feed, facebook feed, facebook page plugin, page plugin, adoptive, facebook, facebook like box,, like box, facebook like box, facebook like box widget, facebook like box shortcodes, shortcodes, facebook like box plugin, facebook like box wordpress plugin, plugin, responsive facebook like box, responsive, facebook like box in 75 locales, facebook like box in 75 languages, custom facebook feed, facebook like box in PopUp, PopUp, Auto PopUp, like box in PopUp, fancybox, lightbox, seo, social media, facebook badge, facebook button, facebook connect, facebook facepile, Facebook fan page, wordpress facebook like box, facebook share, facebook integration, shortcode generator, advanced responsive facebook likebox, facebook wall, facebook sidebar, facebook recommend, like box facebook, open graph, facebook page, facebook group, rt facebook like box, sharebar
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=sjaved786%40gmail%2ecom&lc=US&item_name=Easy%20Facebook%20Like%20Box%20WordPress%20Plugin&item_number=efbl&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
5
  Requires at least: 3.3
6
  Tested up to: 4.7.2
7
+ Stable tag: 4.3.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
12
 
13
  == Description ==
14
 
15
+ There are **three** main features of this plugin, **Custom Facebook Feed**, **Faceook Page Plugin** (previously Facebook Like Box) and **Auto PopUp**.
16
 
17
  [Custom facebook feed demo](https://jwebsol.com/custom-facebook-feed/ "See this plugin in action (Custom facebook feed demo)") | [Fixed width demo](https://jwebsol.com/easy-facebook-like-box-plugin-demo/ "See this plugin in action (Fixed width)") | [Responsive demo](https://jwebsol.com/easy-facebook-like-box-responsive-demo/ "See this plugin in action (Responsive)") |
18
  [Auto PopUp demo](https://jwebsol.com/easy-facebook-like-box-auto-popup-demo/ "See this plugin in action (Auto PopUp)")
33
  1. Chose your desired language or input your own language (if not in list).
34
  1. Support 75 different locales.
35
  1. Like box in responsive PopUp/Modal window.
36
+ 1. Next and previous story in popup. **NEW**.
37
  1. Enable/Disable PopUp.
38
  1. All above options are available with PopUp.
39
  1. Generate shortcode using widget form.
40
+ 1. Support all WordPress shortcodes and even html in PopUp
41
  1. Set PopUp delay from Back-end.
42
  1. Show PopUp on home page only.
43
  1. Show PopUp if visitors are logged in
92
  3. Navigate to "Appearance > Widgets" and drag and drop "Easy Facebook Likebox" in desired widget area or use the shortcode in page/post generated by widget.
93
 
94
  == Upgrade Notice ==
95
+ = 4.3.1 =
96
+ Next and previous story in popup.
97
+ Added some fancy effects to popup.
98
+ Load asynchronously to avoid render blocking.
99
+
100
  = 4.3.0 =
101
  MUST update to make it work with latest facebook API.
102
 
161
  8. Easy Facebook Like Box settings dashboard.
162
  9. Auto PopUp settings panel.
163
 
 
164
  == Changelog ==
165
+ = 4.3.1 =
166
+ * Added: Next and previous story in popup
167
+ * Added: Some fancy effects to popup
168
+ * Added: Load asynchronously to avoid render blocking
169
+
170
  = 4.3.0 =
171
  * Fixed: Migrating from Facebook API 2.1 to 2.8
172
  * Some other minor improvements and fixes
admin/assets/css/index.php DELETED
@@ -1 +0,0 @@
1
- <?php // Silence is golden
 
admin/assets/js/index.php DELETED
@@ -1 +0,0 @@
1
- <?php // Silence is golden
 
admin/easy-facebook-likebox-admin.php CHANGED
@@ -310,11 +310,11 @@ class Easy_Facebook_Likebox_Admin {
310
  function efbl_default_options() {
311
 
312
  $defaults = array(
313
- 'efbl_enable_popup' => '',
314
  'efbl_popup_interval' => 5000,
315
  'efbl_popup_width' => 400,
316
  'efbl_popup_height' => 300,
317
- 'efbl_popup_shortcode' => '',
318
  );
319
 
320
  return apply_filters( 'efbl_default_options', $defaults );
310
  function efbl_default_options() {
311
 
312
  $defaults = array(
313
+ 'efbl_enable_popup' => null,
314
  'efbl_popup_interval' => 5000,
315
  'efbl_popup_width' => 400,
316
  'efbl_popup_height' => 300,
317
+ 'efbl_popup_shortcode' => null,
318
  );
319
 
320
  return apply_filters( 'efbl_default_options', $defaults );
assets/banner-772x250.jpg DELETED
Binary file
assets/banner-772x250.png DELETED
Binary file
assets/index.php DELETED
@@ -1 +0,0 @@
1
- <?php // Silence is golden
 
assets/screenshot-1.png DELETED
Binary file
assets/screenshot-2.png DELETED
Binary file
assets/screenshot-3.png DELETED
Binary file
assets/screenshot-4.png DELETED
Binary file
assets/screenshot-5.png DELETED
Binary file
assets/screenshot-6.png DELETED
Binary file
assets/screenshot-7.png DELETED
Binary file
easy-facebook-likebox.php CHANGED
@@ -3,13 +3,41 @@
3
  * Plugin Name: Easy Facebook Likebox
4
  * Plugin URI: httt://wordpress.org/plugins/easy-facebook-likebox
5
  * Description: Easy Facebook like box WordPress plugin allows you to easly display facebook like box fan page on your website using either widget or shortcode to increase facbook fan page likes. You can use the shortcode generated after saving the facebook like box widget. Additionally it also now allows you to dipslay the cusetomized facebook feed on your website using the same color scheme of your website. Its completely customizable with lots of optional settings. Its also responsive facebook like box at the same time.
6
- * Version: 4.3.0
7
  * Author: Sajid Javed
8
  * Author URI: http://jwebsol.com
9
  * Text Domain: easy-facebook-likebox
10
  * Domain Path: /languages
11
  */
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  // If this file is called directly, abort.
14
  if ( ! defined( 'WPINC' ) ) {
15
  die;
@@ -34,19 +62,12 @@ require_once( plugin_dir_path( __FILE__ ) . 'public/easy-facebook-likebox.php' )
34
  * Register hooks that are fired when the plugin is activated or deactivated.
35
  * When the plugin is deleted, the uninstall.php file is loaded.
36
  *
37
- * @TODO:
38
- *
39
- * - replace Plugin_Name with the name of the class defined in
40
- * `class-plugin-name.php`
41
  */
42
  register_activation_hook( __FILE__, array( 'Easy_Facebook_Likebox', 'activate' ) );
43
  register_deactivation_hook( __FILE__, array( 'Easy_Facebook_Likebox', 'deactivate' ) );
44
 
45
  /*
46
- * @TODO:
47
- *
48
- * - replace Plugin_Name with the name of the class defined in
49
- * `class-plugin-name.php`
50
  */
51
  add_action( 'plugins_loaded', array( 'Easy_Facebook_Likebox', 'get_instance' ) );
52
 
@@ -55,18 +76,7 @@ add_action( 'plugins_loaded', array( 'Easy_Facebook_Likebox', 'get_instance' ) )
55
  *----------------------------------------------------------------------------*/
56
 
57
  /*
58
- * @TODO:
59
- *
60
- * - replace `class-plugin-name-admin.php` with the name of the plugin's admin file
61
- * - replace Plugin_Name_Admin with the name of the class defined in
62
- * `class-plugin-name-admin.php`
63
- *
64
- * If you want to include Ajax within the dashboard, change the following
65
- * conditional to:
66
- *
67
- * if ( is_admin() ) {
68
- * ...
69
- * }
70
  *
71
  * The code below is intended to give the lightest footprint possible.
72
  */
@@ -86,7 +96,6 @@ if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
86
  * Including widget class.
87
  */
88
 
89
- //require_once( plugin_dir_path( __FILE__ ) . 'includes/easy-facebook-likebox-widget.php' );
90
  require_once( plugin_dir_path( __FILE__ ) . 'includes/easy-custom-facebook-feed-widget.php' );
91
  require_once( plugin_dir_path( __FILE__ ) . 'includes/easy-facebook-page-plugin-widget.php' );
92
 
3
  * Plugin Name: Easy Facebook Likebox
4
  * Plugin URI: httt://wordpress.org/plugins/easy-facebook-likebox
5
  * Description: Easy Facebook like box WordPress plugin allows you to easly display facebook like box fan page on your website using either widget or shortcode to increase facbook fan page likes. You can use the shortcode generated after saving the facebook like box widget. Additionally it also now allows you to dipslay the cusetomized facebook feed on your website using the same color scheme of your website. Its completely customizable with lots of optional settings. Its also responsive facebook like box at the same time.
6
+ * Version: 4.3.1
7
  * Author: Sajid Javed
8
  * Author URI: http://jwebsol.com
9
  * Text Domain: easy-facebook-likebox
10
  * Domain Path: /languages
11
  */
12
 
13
+ // // Create a helper function for easy SDK access.
14
+ // function efl_fs() {
15
+ // global $efl_fs;
16
+
17
+ // if ( ! isset( $efl_fs ) ) {
18
+ // // Include Freemius SDK.
19
+ // require_once dirname(__FILE__) . '/freemius/start.php';
20
+
21
+ // $efl_fs = fs_dynamic_init( array(
22
+ // 'id' => '422',
23
+ // 'slug' => 'easy-facebook-likebox',
24
+ // 'type' => 'plugin',
25
+ // 'public_key' => 'pk_d094d1d699779a0b87f02a7a9830c',
26
+ // 'is_premium' => false,
27
+ // 'has_addons' => false,
28
+ // 'has_paid_plans' => false,
29
+ // 'menu' => array(
30
+ // 'slug' => 'easy-facebook-likebox',
31
+ // ),
32
+ // ) );
33
+ // }
34
+
35
+ // return $efl_fs;
36
+ // }
37
+
38
+ // // Init Freemius.
39
+ // efl_fs();
40
+
41
  // If this file is called directly, abort.
42
  if ( ! defined( 'WPINC' ) ) {
43
  die;
62
  * Register hooks that are fired when the plugin is activated or deactivated.
63
  * When the plugin is deleted, the uninstall.php file is loaded.
64
  *
 
 
 
 
65
  */
66
  register_activation_hook( __FILE__, array( 'Easy_Facebook_Likebox', 'activate' ) );
67
  register_deactivation_hook( __FILE__, array( 'Easy_Facebook_Likebox', 'deactivate' ) );
68
 
69
  /*
70
+ * Get instance on plugins loaded
 
 
 
71
  */
72
  add_action( 'plugins_loaded', array( 'Easy_Facebook_Likebox', 'get_instance' ) );
73
 
76
  *----------------------------------------------------------------------------*/
77
 
78
  /*
79
+ * Get instance of admin area class.
 
 
 
 
 
 
 
 
 
 
 
80
  *
81
  * The code below is intended to give the lightest footprint possible.
82
  */
96
  * Including widget class.
97
  */
98
 
 
99
  require_once( plugin_dir_path( __FILE__ ) . 'includes/easy-custom-facebook-feed-widget.php' );
100
  require_once( plugin_dir_path( __FILE__ ) . 'includes/easy-facebook-page-plugin-widget.php' );
101
 
freemius/.codeclimate.yml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ engines:
2
+ phpcodesniffer:
3
+ enabled: true
4
+ config:
5
+ standard: "WordPress"
6
+ checks:
7
+ Squiz Commenting InlineComment InvalidEndChar:
8
+ enabled: false
9
+ Squiz Commenting InlineComment SpacingBefore:
10
+ enabled: false
11
+ ratings:
12
+ paths:
13
+ - "**.php"
freemius/.travis.yml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ sudo: false
2
+
3
+ language: php
4
+
5
+ php:
6
+ - 5.3
7
+ - 5.4
8
+ - 5.5
9
+ - 5.6
10
+ - 7.0
11
+ - hhvm
freemius/LICENSE.txt ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
340
+
freemius/README.md ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Freemius WordPress SDK
2
+ ======================
3
+
4
+ Freemius is an [analytics](https://freemius.com/wordpress/insights/) & [monetization](https://freemius.com/wordpress/) platform for plugin developers. Freemius empower developers with advanced real-time analytics and helps turning any plugin into a commercial product in less than 10 min.
5
+
6
+ The platform is fully functional and running in production. Having said that, the monetization platform is still in closed beta.
7
+ If you are a WordPress plugin developer and you are interested to monetize with Freemius [apply to our closed beta here](http://bit.ly/freemius-beta):
8
+
9
+ http://bit.ly/freemius-beta
10
+
11
+ **Below you'll find the integration instructions for our WordPress SDK.**
12
+
13
+ ## Code Documentation
14
+
15
+ You can find the SDK's PHP-Doc documentation here:
16
+ https://codedoc.pub/freemius/wordpress-sdk/master/
17
+
18
+ ## Initializing the SDK
19
+
20
+ Copy the code below and paste it into the top of your main plugin's PHP file, right after the plugin's header comment:
21
+
22
+ ```php
23
+ <?php
24
+ // Create a helper function for easy SDK access.
25
+ function my_prefix_fs() {
26
+ global $my_prefix_fs;
27
+ if ( ! isset( $my_prefix_fs ) ) {
28
+ // Include Freemius SDK.
29
+ require_once dirname(__FILE__) . '/freemius/start.php';
30
+
31
+ $my_prefix_fs = fs_dynamic_init( array(
32
+ 'id' => '1234',
33
+ 'slug' => 'my-plugin-slug',
34
+ 'menu_slug' => 'my_menu_slug', // You can also use __FILE__
35
+ 'public_key' => 'pk_MY_PUBLIC_KEY',
36
+ 'is_live' => true,
37
+ 'is_premium' => true,
38
+ 'has_addons' => false,
39
+ 'has_paid_plans' => false,
40
+ // Set the SDK to work in a sandbox mode (for development & testing).
41
+ // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
42
+ 'secret_key' => 'sk_MY_SECRET_KEY',
43
+ ) );
44
+ }
45
+
46
+ return $my_prefix_fs;
47
+ }
48
+
49
+ // Init Freemius.
50
+ my_prefix_fs();
51
+ ?>
52
+ ```
53
+
54
+ - **1234** - Replace with your plugin's ID.
55
+ - **pk_MY_PUBLIC_KEY** - Replace with your plugin's public key.
56
+ - **sk_MY_SECRET_KEY** - Replace with your plugin's secret key.
57
+ - **my-plugin-slug** - Replace with your plugin's WordPress.org slug.
58
+ - **my_menu_slug** - Replace with your admin dashboard settings menu slug.
59
+
60
+
61
+ ## Usage example
62
+
63
+ You can call the SDK by using the shortcode function:
64
+
65
+ ```php
66
+ <?php my_prefix_fs()->get_upgrade_url(); ?>
67
+ ```
68
+
69
+ Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:
70
+
71
+ ```php
72
+ <?php
73
+ global $my_prefix_fs;
74
+ $my_prefix_fs->get_account_url();
75
+ ?>
76
+ ```
77
+
78
+ ## Adding license based logic examples
79
+
80
+ Add marketing content to encourage your users to upgrade for your paid version:
81
+
82
+ ```php
83
+ <?php
84
+ if ( my_prefix_fs()->is_not_paying() ) {
85
+ echo '<section><h1>' . esc_html__('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
86
+ echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
87
+ esc_html__('Upgrade Now!', 'my-plugin-slug') .
88
+ '</a>';
89
+ echo '</section>';
90
+ }
91
+ ?>
92
+ ```
93
+
94
+ Add logic which will only be available in your premium plugin version:
95
+
96
+ ```php
97
+ <?php
98
+ // This "if" block will be auto removed from the Free version.
99
+ if ( my_prefix_fs()->is__premium_only() ) {
100
+
101
+ // ... premium only logic ...
102
+
103
+ }
104
+ ?>
105
+ ```
106
+
107
+ To add a function which will only be available in your premium plugin version, simply add __premium_only as the suffix of the function name. Just make sure that all lines that call that method directly or by hooks, are also wrapped in premium only logic:
108
+
109
+ ```php
110
+ <?php
111
+ class My_Plugin {
112
+ function init() {
113
+ ...
114
+
115
+ // This "if" block will be auto removed from the free version.
116
+ if ( my_prefix_fs()->is__premium_only() ) {
117
+ // Init premium version.
118
+ $this->admin_init__premium_only();
119
+
120
+ add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
121
+ }
122
+
123
+ ...
124
+ }
125
+
126
+ // This method will be only included in the premium version.
127
+ function admin_init__premium_only() {
128
+ ...
129
+ }
130
+
131
+ // This method will be only included in the premium version.
132
+ function admin_init_hook__premium_only() {
133
+ ...
134
+ }
135
+ }
136
+ ?>
137
+ ```
138
+
139
+ Add logic which will only be executed for customers in your 'professional' plan:
140
+
141
+ ```php
142
+ <?php
143
+ if ( my_prefix_fs()->is_plan('professional', true) ) {
144
+ // .. logic related to Professional plan only ...
145
+ }
146
+ ?>
147
+ ```
148
+
149
+ Add logic which will only be executed for customers in your 'professional' plan or higher plans:
150
+
151
+ ```php
152
+ <?php
153
+ if ( my_prefix_fs()->is_plan('professional') ) {
154
+ // ... logic related to Professional plan and higher plans ...
155
+ }
156
+ ?>
157
+ ```
158
+
159
+ Add logic which will only be available in your premium plugin version AND will only be executed for customers in your 'professional' plan (and higher plans):
160
+
161
+ ```php
162
+ <?php
163
+ // This "if" block will be auto removed from the Free version.
164
+ if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
165
+ // ... logic related to Professional plan and higher plans ...
166
+ }
167
+ ?>
168
+ ```
169
+
170
+ Add logic only for users in trial:
171
+
172
+ ```php
173
+ <?php
174
+ if ( my_prefix_fs()->is_trial() ) {
175
+ // ... logic for users in trial ...
176
+ }
177
+ ?>
178
+ ```
179
+
180
+ Add logic for specified paid plan:
181
+
182
+ ```php
183
+ <?php
184
+ // This "if" block will be auto removed from the Free version.
185
+ if ( my_prefix_fs()->is__premium_only() ) {
186
+ if ( my_prefix_fs()->is_plan( 'professional', true ) ) {
187
+
188
+ // ... logic related to Professional plan only ...
189
+
190
+ } else if ( my_prefix_fs()->is_plan( 'business' ) ) {
191
+
192
+ // ... logic related to Business plan and higher plans ...
193
+
194
+ }
195
+ }
196
+ ?>
197
+ ```
198
+
199
+ ## Excluding files and folders from the free plugin version
200
+ There are two ways to exclude files from your free version.
201
+
202
+ 1. Add `__premium_only` just before the file extension. For example, functions__premium_only.php will be only included in the premium plugin version. This works for all type of files, not only PHP.
203
+ 2. Add `@fs_premium_only` a sepcial meta tag to the plugin's main PHP file header. Example:
204
+ ```php
205
+ <?php
206
+ /**
207
+ * Plugin Name: My Very Awesome Plugin
208
+ * Plugin URI: http://my-awesome-plugin.com
209
+ * Description: Create and manage Awesomeness right in WordPress.
210
+ * Version: 1.0.0
211
+ * Author: Awesomattic
212
+ * Author URI: http://my-awesome-plugin.com/me/
213
+ * License: GPLv2
214
+ * Text Domain: myplugin
215
+ * Domain Path: /langs
216
+ *
217
+ * @fs_premium_only /lib/functions.php, /premium-files/
218
+ */
219
+
220
+ if ( ! defined( 'ABSPATH' ) ) {
221
+ exit;
222
+ }
223
+
224
+ // ... my code ...
225
+ ?>
226
+ ```
227
+ The file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
228
+
229
+ # WordPress.org Compliance
230
+ Based on [WordPress.org Guidelines](https://wordpress.org/plugins/about/guidelines/) you are not allowed to submit a plugin that has premium code in it:
231
+ > All code hosted by WordPress.org servers must be free and fully-functional. If you want to sell advanced features for a plugin (such as a "pro" version), then you must sell and serve that code from your own site, we will not host it on our servers.
232
+
233
+ Therefore, if you want to deploy your free plugin's version to WordPress.org, make sure you wrap all your premium code with `if ( my_prefix_fs()->{{ method }}__premium_only() )` or the other methods provided to exclude premium features & files from the free version.
234
+
235
+ ## Deployment
236
+ Zip your plugin's root folder and upload it in the Deployment section in the *Freemius Developer's Dashboard*.
237
+ The plugin will be scanned and processed by a custom developed *PHP Processor* which will auto-generate two versions of your plugin:
238
+
239
+ 1. **Premium version**: Identical to your uploaded version, including all code (except your `secret_key`). Will be enabled for download ONLY for your paying or in trial customers.
240
+ 2. **Free version**: The code stripped from all your paid features (based on the logic added wrapped in `{ method }__premium_only()`).
241
+
242
+ The free version is the one that you should give your users to download. Therefore, download the free generated version and upload to your site. Or, if your plugin was WordPress.org complaint and you made sure to exclude all your premium code with the different provided techniques, you can deploy the downloaded free version to the .org repo.
243
+
244
+ ## Reporting Bugs
245
+ Email dev [at] freemius [dot] com
246
+
247
+ ## FAQ
248
+
249
+ ## Copyright
250
+ Freemius, Inc.
freemius/assets/css/admin/account.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_account .postbox,#fs_account .widefat{max-width:700px}#fs_account h3{font-size:1.3em;padding:12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #F1F1F1}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .button i.dashicons{vertical-align:middle}#fs_account .fs-header-actions{position:absolute;top:17px;right:15px;font-size:0.9em}#fs_account .fs-header-actions ul{margin:0}#fs_account .fs-header-actions li{float:left}#fs_account .fs-header-actions li form{display:inline-block}#fs_account .fs-header-actions li a{text-decoration:none}#fs_account_details .button-group{float:right}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type="text"]{color:#0073AA;font-size:16px;background:none}.fs-key-value-table input[type="text"]{width:100%;font-weight:bold}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}
freemius/assets/css/admin/add-ons.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ #fs_addons .fs-cards-list{list-style:none}#fs_addons .fs-cards-list .fs-card{float:left;height:152px;width:310px;padding:0;margin:0 0 30px 30px;font-size:14px;list-style:none;border:1px solid #ddd;cursor:pointer;position:relative}#fs_addons .fs-cards-list .fs-card .fs-overlay{position:absolute;left:0;right:0;bottom:0;top:0;z-index:9}#fs_addons .fs-cards-list .fs-card .fs-inner{background-color:#fff;overflow:hidden;height:100%;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner ul{-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner li{list-style:none;line-height:18px;padding:0 15px;width:100%;display:block;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner{padding:0;margin:0;line-height:0;display:block;height:100px;background-repeat:repeat-x;background-size:100% 100%;-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-title{margin:10px 0 0 0;height:18px;overflow:hidden;color:#000;white-space:nowrap;text-overflow:ellipsis;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-offer{font-size:0.9em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-description{background-color:#f9f9f9;padding:10px 15px 100px 15px;border-top:1px solid #eee;margin:0 0 10px 0;color:#777}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-tag{position:absolute;top:10px;right:0px;background:greenyellow;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.3);box-shadow:1px 1px 1px rgba(0,0,0,0.3);text-transform:uppercase;font-size:0.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button{position:absolute;top:112px;right:10px}@media screen and (min-width: 960px){#fs_addons .fs-cards-list .fs-card:hover .fs-overlay{border:2px solid #29abe1;margin-left:-1px;margin-top:-1px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner ul{top:-100px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-title,#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-offer{color:#29abe1}}
2
+ #TB_window,#TB_window iframe{width:772px !important}#plugin-information #section-description h2,#plugin-information #section-description h3,#plugin-information #section-description p,#plugin-information #section-description b,#plugin-information #section-description i,#plugin-information #section-description blockquote,#plugin-information #section-description li,#plugin-information #section-description ul,#plugin-information #section-description ol{clear:none}#plugin-information #section-description .fs-selling-points{padding-bottom:10px;border-bottom:1px solid #ddd}#plugin-information #section-description .fs-selling-points ul{margin:0}#plugin-information #section-description .fs-selling-points ul li{padding:0;list-style:none outside none}#plugin-information #section-description .fs-selling-points ul li i.dashicons{color:#71ae00;font-size:3em;vertical-align:middle;line-height:30px;float:left;margin:0 0 0 -15px}#plugin-information #section-description .fs-selling-points ul li h3{margin:1em 30px !important}#plugin-information #section-description .fs-screenshots:after{content:"";display:table;clear:both}#plugin-information #section-description .fs-screenshots ul{list-style:none;margin:0}#plugin-information #section-description .fs-screenshots ul li{width:225px;height:225px;float:left;margin-bottom:20px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}#plugin-information #section-description .fs-screenshots ul li a{display:block;width:100%;height:100%;border:1px solid;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);background-size:cover}#plugin-information #section-description .fs-screenshots ul li.odd{margin-right:20px}#plugin-information .plugin-information-pricing{margin:-16px;border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan h3{margin-top:0;padding:20px;font-size:16px}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper{border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab{cursor:pointer;position:relative;padding:0 10px;font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:greenyellow;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid darkgreen;padding:2px;text-align:center;font-size:0.9em;line-height:1em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab.nav-tab-active{cursor:default;background:#fffeec;border-bottom-color:#fffeec}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle h3{background:#fffeec;margin:0;padding-bottom:0;color:#0073aa}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .nav-tab-wrapper,#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .fs-billing-frequency{display:none}#plugin-information .plugin-information-pricing .fs-plan .fs-pricing-body{background:#fffeec;padding:20px}#plugin-information .plugin-information-pricing .fs-plan .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing .fs-plan label{white-space:nowrap}#plugin-information .plugin-information-pricing .fs-plan var{font-style:normal}#plugin-information .plugin-information-pricing .fs-plan .fs-billing-frequency,#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-align:center;display:block;font-weight:bold;margin-bottom:10px;text-transform:uppercase;background:#F3F3F3;padding:2px;border:1px solid #ccc}#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-transform:none;color:green;background:greenyellow}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms i{float:left;margin:0 0 0 -15px}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms li{margin:10px 0 0 0}#plugin-information #section-features .fs-features{margin:-20px -26px}#plugin-information #section-features table{width:100%;border-spacing:0;border-collapse:separate}#plugin-information #section-features table thead th{padding:10px 0}#plugin-information #section-features table thead .fs-price{color:#71ae00;font-weight:normal;display:block;text-align:center}#plugin-information #section-features table tbody td{border-top:1px solid #ccc;padding:10px 0;text-align:center;width:100px;color:#71ae00}#plugin-information #section-features table tbody td:first-child{text-align:left;width:auto;color:inherit;padding-left:26px}#plugin-information #section-features table tbody tr.fs-odd td{background:#fefefe}#plugin-information #section-features .dashicons-yes{width:30px;height:30px;font-size:30px}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}
freemius/assets/css/admin/common.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,0.3);color:#fff;padding:2px 10px;position:absolute;top:100%;bottom:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;box-shadow:0px 2px 2px rgba(6,113,6,0.3);opacity:0.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}
freemius/assets/css/admin/connect.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,0.3);box-shadow:0px 1px 2px rgba(0,0,0,0.3);margin:20px 0}@media screen and (max-width: 479px){#fs_connect{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;width:auto;margin:0 0 0 -10px}}#fs_connect .fs-content{background:#fff;padding:15px 20px}#fs_connect .fs-content .fs-error{background:snow;color:#d3135a;border:1px solid #d3135a;-moz-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);text-align:center;padding:5px;margin-bottom:10px}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-license-key-container{position:relative;width:280px;margin:10px auto 0 auto}#fs_connect .fs-license-key-container input{width:100%}#fs_connect .fs-license-key-container .dashicons{position:absolute;top:5px;right:5px}#fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}#fs_connect .fs-actions .button{padding:0 10px 1px;line-height:35px;height:37px;font-size:16px;margin-bottom:0}#fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}#fs_connect .fs-actions .button.button-primary{padding-right:15px;padding-left:15px}#fs_connect .fs-actions .button.button-primary:after{content:' \279C'}#fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}#fs_connect .fs-actions .button.button-secondary{float:right}#fs_connect.fs-anonymous-disabled .fs-actions .button.button-primary{width:100%}#fs_connect .fs-permissions{padding:10px 20px;background:#FEFEFE;-moz-transition:background 0.5s ease;-o-transition:background 0.5s ease;-ms-transition:background 0.5s ease;-webkit-transition:background 0.5s ease;transition:background 0.5s ease}#fs_connect .fs-permissions .fs-license-sync-disclaimer{text-align:center;margin-top:0}#fs_connect .fs-permissions .fs-trigger{font-size:0.9em;text-decoration:none;text-align:center;display:block}#fs_connect .fs-permissions ul{height:0;overflow:hidden;margin:0}#fs_connect .fs-permissions ul li{margin-bottom:12px}#fs_connect .fs-permissions ul li:last-child{margin-bottom:0}#fs_connect .fs-permissions ul li i.dashicons{float:left;font-size:40px;width:40px;height:40px}#fs_connect .fs-permissions ul li div{margin-left:55px}#fs_connect .fs-permissions ul li div span{font-weight:bold;text-transform:uppercase;color:#23282d}#fs_connect .fs-permissions ul li div p{margin:2px 0 0 0}#fs_connect .fs-permissions.fs-open{background:#fff}#fs_connect .fs-permissions.fs-open ul{height:auto;margin:20px 20px 10px 20px}@media screen and (max-width: 479px){#fs_connect .fs-permissions{background:#fff}#fs_connect .fs-permissions .fs-trigger{display:none}#fs_connect .fs-permissions ul{height:auto;margin:20px}}#fs_connect .fs-freemium-licensing{padding:8px;background:#777;color:#fff}#fs_connect .fs-freemium-licensing p{text-align:center;display:block;margin:0;padding:0}#fs_connect .fs-freemium-licensing a{color:#C2EEFF;text-decoration:underline}#fs_connect .fs-visual{padding:12px;line-height:0;background:#fafafa;height:80px;position:relative}#fs_connect .fs-visual .fs-site-icon{position:absolute;left:20px;top:10px}#fs_connect .fs-visual .fs-connect-logo{position:absolute;right:20px;top:10px}#fs_connect .fs-visual .fs-plugin-icon{position:absolute;top:10px;left:50%;margin-left:-40px}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-site-icon,#fs_connect .fs-visual img,#fs_connect .fs-visual object{width:80px;height:80px}#fs_connect .fs-visual .dashicons-wordpress{font-size:64px;background:#01749a;color:#fff;width:64px;height:64px;padding:8px}#fs_connect .fs-visual .dashicons-plus{position:absolute;top:50%;font-size:30px;margin-top:-10px;color:#bbb}#fs_connect .fs-visual .dashicons-plus.fs-first{left:28%}#fs_connect .fs-visual .dashicons-plus.fs-second{left:65%}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-connect-logo,#fs_connect .fs-visual .fs-site-icon{border:1px solid #ccc;padding:1px;background:#fff}#fs_connect .fs-terms{text-align:center;font-size:0.85em;padding:5px;background:rgba(0,0,0,0.05)}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:' \000bb'}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-permissions ul li div{margin-right:55px;margin-left:0}.rtl #fs_connect .fs-permissions ul li i.dashicons{float:right}.rtl #fs_connect .fs-visual .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-visual .fs-connect-logo{right:auto;left:20px}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}
freemius/assets/css/admin/deactivation-feedback.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}.fs-modal .fs-modal-dialog li.reason{margin-bottom:10px}.fs-modal .fs-modal-dialog li.reason .reason-input,.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}
freemius/assets/css/admin/dialog-boxes.css ADDED
@@ -0,0 +1,3 @@
 
 
 
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 p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}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}}
2
+ #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 .button-close{float:right;margin:5px}.fs-modal.fs-modal-license-key-resend .button-close:hover{cursor:pointer}.fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend .fs-modal-body input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:right;margin-left:7px}@media (max-width: 650px){.fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{margin-top:2px}}
3
+ a.show-license-resend-modal{margin-top:4px;display:inline-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/common.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice.success{color:green;font-weight:700}
assets/PluginIcon - Copy.png → freemius/assets/img/easy-facebook-likebox.png RENAMED
File without changes
freemius/assets/img/plugin-icon.png ADDED
Binary file
freemius/assets/js/jquery.ba-postmessage.js ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ */
9
+
10
+ // Script: jQuery postMessage: Cross-domain scripting goodness
11
+ //
12
+ // *Version: 0.5, Last updated: 9/11/2009*
13
+ //
14
+ // Project Home - http://benalman.com/projects/jquery-postmessage-plugin/
15
+ // GitHub - http://github.com/cowboy/jquery-postmessage/
16
+ // Source - http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.js
17
+ // (Minified) - http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.min.js (0.9kb)
18
+ //
19
+ // About: License
20
+ //
21
+ // Copyright (c) 2009 "Cowboy" Ben Alman,
22
+ // Dual licensed under the MIT and GPL licenses.
23
+ // http://benalman.com/about/license/
24
+ //
25
+ // About: Examples
26
+ //
27
+ // This working example, complete with fully commented code, illustrates one
28
+ // way in which this plugin can be used.
29
+ //
30
+ // Iframe resizing - http://benalman.com/code/projects/jquery-postmessage/examples/iframe/
31
+ //
32
+ // About: Support and Testing
33
+ //
34
+ // Information about what version or versions of jQuery this plugin has been
35
+ // tested with and what browsers it has been tested in.
36
+ //
37
+ // jQuery Versions - 1.3.2
38
+ // Browsers Tested - Internet Explorer 6-8, Firefox 3, Safari 3-4, Chrome, Opera 9.
39
+ //
40
+ // About: Release History
41
+ //
42
+ // 0.5 - (9/11/2009) Improved cache-busting
43
+ // 0.4 - (8/25/2009) Initial release
44
+
45
+ (function($){
46
+ '$:nomunge'; // Used by YUI compressor.
47
+
48
+ // A few vars used in non-awesome browsers.
49
+ var interval_id,
50
+ last_hash,
51
+ cache_bust = 1,
52
+
53
+ // A var used in awesome browsers.
54
+ rm_callback,
55
+
56
+ // A few convenient shortcuts.
57
+ window = this,
58
+ FALSE = !1,
59
+
60
+ // Reused internal strings.
61
+ postMessage = 'postMessage',
62
+ addEventListener = 'addEventListener',
63
+
64
+ p_receiveMessage,
65
+
66
+ // I couldn't get window.postMessage to actually work in Opera 9.64!
67
+ has_postMessage = window[postMessage] && !$.browser.opera;
68
+
69
+ // Method: jQuery.postMessage
70
+ //
71
+ // This method will call window.postMessage if available, setting the
72
+ // targetOrigin parameter to the base of the target_url parameter for maximum
73
+ // security in browsers that support it. If window.postMessage is not available,
74
+ // the target window's location.hash will be used to pass the message. If an
75
+ // object is passed as the message param, it will be serialized into a string
76
+ // using the jQuery.param method.
77
+ //
78
+ // Usage:
79
+ //
80
+ // > jQuery.postMessage( message, target_url [, target ] );
81
+ //
82
+ // Arguments:
83
+ //
84
+ // message - (String) A message to be passed to the other frame.
85
+ // message - (Object) An object to be serialized into a params string, using
86
+ // the jQuery.param method.
87
+ // target_url - (String) The URL of the other frame this window is
88
+ // attempting to communicate with. This must be the exact URL (including
89
+ // any query string) of the other window for this script to work in
90
+ // browsers that don't support window.postMessage.
91
+ // target - (Object) A reference to the other frame this window is
92
+ // attempting to communicate with. If omitted, defaults to `parent`.
93
+ //
94
+ // Returns:
95
+ //
96
+ // Nothing.
97
+
98
+ $[postMessage] = function( message, target_url, target ) {
99
+ if ( !target_url ) { return; }
100
+
101
+ // Serialize the message if not a string. Note that this is the only real
102
+ // jQuery dependency for this script. If removed, this script could be
103
+ // written as very basic JavaScript.
104
+ message = typeof message === 'string' ? message : $.param( message );
105
+
106
+ // Default to parent if unspecified.
107
+ target = target || parent;
108
+
109
+ if ( has_postMessage ) {
110
+ // The browser supports window.postMessage, so call it with a targetOrigin
111
+ // set appropriately, based on the target_url parameter.
112
+ target[postMessage]( message, target_url.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
113
+
114
+ } else if ( target_url ) {
115
+ // The browser does not support window.postMessage, so set the location
116
+ // of the target to target_url#message. A bit ugly, but it works! A cache
117
+ // bust parameter is added to ensure that repeat messages trigger the
118
+ // callback.
119
+ target.location = target_url.replace( /#.*$/, '' ) + '#' + (+new Date) + (cache_bust++) + '&' + message;
120
+ }
121
+ };
122
+
123
+ // Method: jQuery.receiveMessage
124
+ //
125
+ // Register a single callback for either a window.postMessage call, if
126
+ // supported, or if unsupported, for any change in the current window
127
+ // location.hash. If window.postMessage is supported and source_origin is
128
+ // specified, the source window will be checked against this for maximum
129
+ // security. If window.postMessage is unsupported, a polling loop will be
130
+ // started to watch for changes to the location.hash.
131
+ //
132
+ // Note that for simplicity's sake, only a single callback can be registered
133
+ // at one time. Passing no params will unbind this event (or stop the polling
134
+ // loop), and calling this method a second time with another callback will
135
+ // unbind the event (or stop the polling loop) first, before binding the new
136
+ // callback.
137
+ //
138
+ // Also note that if window.postMessage is available, the optional
139
+ // source_origin param will be used to test the event.origin property. From
140
+ // the MDC window.postMessage docs: This string is the concatenation of the
141
+ // protocol and "://", the host name if one exists, and ":" followed by a port
142
+ // number if a port is present and differs from the default port for the given
143
+ // protocol. Examples of typical origins are https://example.org (implying
144
+ // port 443), http://example.net (implying port 80), and http://example.com:8080.
145
+ //
146
+ // Usage:
147
+ //
148
+ // > jQuery.receiveMessage( callback [, source_origin ] [, delay ] );
149
+ //
150
+ // Arguments:
151
+ //
152
+ // callback - (Function) This callback will execute whenever a <jQuery.postMessage>
153
+ // message is received, provided the source_origin matches. If callback is
154
+ // omitted, any existing receiveMessage event bind or polling loop will be
155
+ // canceled.
156
+ // source_origin - (String) If window.postMessage is available and this value
157
+ // is not equal to the event.origin property, the callback will not be
158
+ // called.
159
+ // source_origin - (Function) If window.postMessage is available and this
160
+ // function returns false when passed the event.origin property, the
161
+ // callback will not be called.
162
+ // delay - (Number) An optional zero-or-greater delay in milliseconds at
163
+ // which the polling loop will execute (for browser that don't support
164
+ // window.postMessage). If omitted, defaults to 100.
165
+ //
166
+ // Returns:
167
+ //
168
+ // Nothing!
169
+
170
+ $.receiveMessage = p_receiveMessage = function( callback, source_origin, delay ) {
171
+ if ( has_postMessage ) {
172
+ // Since the browser supports window.postMessage, the callback will be
173
+ // bound to the actual event associated with window.postMessage.
174
+
175
+ if ( callback ) {
176
+ // Unbind an existing callback if it exists.
177
+ rm_callback && p_receiveMessage();
178
+
179
+ // Bind the callback. A reference to the callback is stored for ease of
180
+ // unbinding.
181
+ rm_callback = function(e) {
182
+ if ( ( typeof source_origin === 'string' && e.origin !== source_origin )
183
+ || ( $.isFunction( source_origin ) && source_origin( e.origin ) === FALSE ) ) {
184
+ return FALSE;
185
+ }
186
+ callback( e );
187
+ };
188
+ }
189
+
190
+ if ( window[addEventListener] ) {
191
+ window[ callback ? addEventListener : 'removeEventListener' ]( 'message', rm_callback, FALSE );
192
+ } else {
193
+ window[ callback ? 'attachEvent' : 'detachEvent' ]( 'onmessage', rm_callback );
194
+ }
195
+
196
+ } else {
197
+ // Since the browser sucks, a polling loop will be started, and the
198
+ // callback will be called whenever the location.hash changes.
199
+
200
+ interval_id && clearInterval( interval_id );
201
+ interval_id = null;
202
+
203
+ if ( callback ) {
204
+ delay = typeof source_origin === 'number'
205
+ ? source_origin
206
+ : typeof delay === 'number'
207
+ ? delay
208
+ : 100;
209
+
210
+ interval_id = setInterval(function(){
211
+ var hash = document.location.hash,
212
+ re = /^#?\d+&/;
213
+ if ( hash !== last_hash && re.test( hash ) ) {
214
+ last_hash = hash;
215
+ callback({ data: hash.replace( re, '' ) });
216
+ }
217
+ }, delay );
218
+ }
219
+ }
220
+ };
221
+
222
+ })(jQuery);
freemius/assets/js/jquery.ba-postmessage.min.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ */
9
+ (function($){var g,d,j=1,a,b=this,f=!1,h="postMessage",e="addEventListener",c,i=b[h]&&!$.browser.opera;$[h]=function(k,l,m){if(!l){return}k=typeof k==="string"?k:$.param(k);m=m||parent;if(i){m[h](k,l.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))}else{if(l){m.location=l.replace(/#.*$/,"")+"#"+(+new Date)+(j++)+"&"+k}}};$.receiveMessage=c=function(l,m,k){if(i){if(l){a&&c();a=function(n){if((typeof m==="string"&&n.origin!==m)||($.isFunction(m)&&m(n.origin)===f)){return f}l(n)}}if(b[e]){b[l?e:"removeEventListener"]("message",a,f)}else{b[l?"attachEvent":"detachEvent"]("onmessage",a)}}else{g&&clearInterval(g);g=null;if(l){k=typeof m==="number"?m:typeof k==="number"?k:100;g=setInterval(function(){var o=document.location.hash,n=/^#?\d+&/;if(o!==d&&n.test(o)){d=o;l({data:o.replace(n,"")})}},k)}}}})(jQuery);
freemius/assets/js/nojquery.ba-postmessage.js ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ *
9
+ * Non-jQuery fork by Jeff Lee
10
+ *
11
+ * This fork consists of the following changes:
12
+ * 1. Basic code cleanup and restructuring, for legibility.
13
+ * 2. The `postMessage` and `receiveMessage` functions can be bound arbitrarily,
14
+ * in terms of both function names and object scope. Scope is specified by
15
+ * the the "this" context of NoJQueryPostMessageMixin();
16
+ * 3. I've removed the check for Opera 9.64, which used `$.browser`. There were
17
+ * at least three different GitHub users requesting the removal of this
18
+ * "Opera sniff" on the original project's Issues page, so I figured this
19
+ * would be a relatively safe change.
20
+ * 4. `postMessage` no longer uses `$.param` to serialize messages that are not
21
+ * strings. I actually prefer this structure anyway. `receiveMessage` does
22
+ * not implement a corresponding deserialization step, and as such it seems
23
+ * cleaner and more symmetric to leave both data serialization and
24
+ * deserialization to the client.
25
+ * 5. The use of `$.isFunction` is replaced by a functionally-identical check.
26
+ * 6. The `$:nomunge` YUI option is no longer necessary.
27
+ */
28
+
29
+ function NoJQueryPostMessageMixin(postBinding, receiveBinding) {
30
+
31
+ var setMessageCallback, unsetMessageCallback, currentMsgCallback,
32
+ intervalId, lastHash, cacheBust = 1;
33
+
34
+ if (window.postMessage) {
35
+
36
+ if (window.addEventListener) {
37
+ setMessageCallback = function(callback) {
38
+ window.addEventListener('message', callback, false);
39
+ }
40
+
41
+ unsetMessageCallback = function(callback) {
42
+ window.removeEventListener('message', callback, false);
43
+ }
44
+ } else {
45
+ setMessageCallback = function(callback) {
46
+ window.attachEvent('onmessage', callback);
47
+ }
48
+
49
+ unsetMessageCallback = function(callback) {
50
+ window.detachEvent('onmessage', callback);
51
+ }
52
+ }
53
+
54
+ this[postBinding] = function(message, targetUrl, target) {
55
+ if (!targetUrl) {
56
+ return;
57
+ }
58
+
59
+ // The browser supports window.postMessage, so call it with a targetOrigin
60
+ // set appropriately, based on the targetUrl parameter.
61
+ target.postMessage( message, targetUrl.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
62
+ }
63
+
64
+ // Since the browser supports window.postMessage, the callback will be
65
+ // bound to the actual event associated with window.postMessage.
66
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
67
+ // Unbind an existing callback if it exists.
68
+ if (currentMsgCallback) {
69
+ unsetMessageCallback(currentMsgCallback);
70
+ currentMsgCallback = null;
71
+ }
72
+
73
+ if (!callback) {
74
+ return false;
75
+ }
76
+
77
+ // Bind the callback. A reference to the callback is stored for ease of
78
+ // unbinding.
79
+ currentMsgCallback = setMessageCallback(function(e) {
80
+ switch(Object.prototype.toString.call(sourceOrigin)) {
81
+ case '[object String]':
82
+ if (sourceOrigin !== e.origin) {
83
+ return false;
84
+ }
85
+ break;
86
+ case '[object Function]':
87
+ if (sourceOrigin(e.origin)) {
88
+ return false;
89
+ }
90
+ break;
91
+ }
92
+
93
+ callback(e);
94
+ });
95
+ };
96
+
97
+ } else {
98
+
99
+ this[postBinding] = function(message, targetUrl, target) {
100
+ if (!targetUrl) {
101
+ return;
102
+ }
103
+
104
+ // The browser does not support window.postMessage, so set the location
105
+ // of the target to targetUrl#message. A bit ugly, but it works! A cache
106
+ // bust parameter is added to ensure that repeat messages trigger the
107
+ // callback.
108
+ target.location = targetUrl.replace( /#.*$/, '' ) + '#' + (+new Date) + (cacheBust++) + '&' + message;
109
+ }
110
+
111
+ // Since the browser sucks, a polling loop will be started, and the
112
+ // callback will be called whenever the location.hash changes.
113
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
114
+ if (intervalId) {
115
+ clearInterval(intervalId);
116
+ intervalId = null;
117
+ }
118
+
119
+ if (callback) {
120
+ delay = typeof sourceOrigin === 'number'
121
+ ? sourceOrigin
122
+ : typeof delay === 'number'
123
+ ? delay
124
+ : 100;
125
+
126
+ intervalId = setInterval(function(){
127
+ var hash = document.location.hash,
128
+ re = /^#?\d+&/;
129
+ if ( hash !== lastHash && re.test( hash ) ) {
130
+ lastHash = hash;
131
+ callback({ data: hash.replace( re, '' ) });
132
+ }
133
+ }, delay );
134
+ }
135
+ };
136
+
137
+ }
138
+
139
+ return this;
140
+ }
freemius/assets/js/nojquery.ba-postmessage.min.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * nojquery-postmessage by Jeff Lee
3
+ * a non-jQuery fork of:
4
+ *
5
+ * jQuery postMessage - v0.5 - 9/11/2009
6
+ * http://benalman.com/projects/jquery-postmessage-plugin/
7
+ *
8
+ * Copyright (c) 2009 "Cowboy" Ben Alman
9
+ * Dual licensed under the MIT and GPL licenses.
10
+ * http://benalman.com/about/license/
11
+ */
12
+ function NoJQueryPostMessageMixin(g,a){var b,h,e,d,f,c=1;if(window.postMessage){if(window.addEventListener){b=function(i){window.addEventListener("message",i,false)};h=function(i){window.removeEventListener("message",i,false)}}else{b=function(i){window.attachEvent("onmessage",i)};h=function(i){window.detachEvent("onmessage",i)}}this[g]=function(i,k,j){if(!k){return}j.postMessage(i,k.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))};this[a]=function(k,j,i){if(e){h(e);e=null}if(!k){return false}e=b(function(l){switch(Object.prototype.toString.call(j)){case"[object String]":if(j!==l.origin){return false}break;case"[object Function]":if(j(l.origin)){return false}break}k(l)})}}else{this[g]=function(i,k,j){if(!k){return}j.location=k.replace(/#.*$/,"")+"#"+(+new Date)+(c++)+"&"+i};this[a]=function(k,j,i){if(d){clearInterval(d);d=null}if(k){i=typeof j==="number"?j:typeof i==="number"?i:100;d=setInterval(function(){var m=document.location.hash,l=/^#?\d+&/;if(m!==f&&l.test(m)){f=m;k({data:m.replace(l,"")})}},i)}}}return this};
freemius/assets/js/postmessage.js ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($, undef) {
2
+ var global = this;
3
+
4
+ // Namespace.
5
+ global.FS = global.FS || {};
6
+
7
+ global.FS.PostMessage = function ()
8
+ {
9
+ var
10
+ _is_child = false,
11
+ _postman = new NoJQueryPostMessageMixin('postMessage', 'receiveMessage'),
12
+ _callbacks = {},
13
+ _base_url,
14
+ _parent_url = decodeURIComponent(document.location.hash.replace(/^#/, '')),
15
+ _parent_subdomain = _parent_url.substring(0, _parent_url.indexOf('/', ('https://' === _parent_url.substring(0, ('https://').length)) ? 8 : 7)),
16
+ _init = function () {
17
+ _postman.receiveMessage(function (e) {
18
+ var data = JSON.parse(e.data);
19
+
20
+ if (_callbacks[data.type]) {
21
+ for (var i = 0; i < _callbacks[data.type].length; i++) {
22
+ // Execute type callbacks.
23
+ _callbacks[data.type][i](data.data);
24
+ }
25
+ }
26
+ }, _base_url);
27
+ };
28
+
29
+ return {
30
+ init : function (url)
31
+ {
32
+ _base_url = url;
33
+ _init();
34
+
35
+ // Automatically receive forward messages.
36
+ FS.PostMessage.receiveOnce('forward', function (data){
37
+ window.location = data.url;
38
+ });
39
+ },
40
+ init_child : function ()
41
+ {
42
+ this.init(_parent_subdomain);
43
+
44
+ _is_child = true;
45
+
46
+ // Post height of a child right after window is loaded.
47
+ $(window).bind('load', function () {
48
+ FS.PostMessage.postHeight();
49
+ });
50
+
51
+ },
52
+ postHeight : function (diff, wrapper) {
53
+ diff = diff || 0;
54
+ wrapper = wrapper || '#wrap_section';
55
+ this.post('height', {
56
+ height: diff + $(wrapper).outerHeight(true)
57
+ });
58
+ },
59
+ post : function (type, data, iframe)
60
+ {
61
+ console.debug('PostMessage.post', type);
62
+
63
+ if (iframe)
64
+ {
65
+ // Post to iframe.
66
+ _postman.postMessage(JSON.stringify({
67
+ type: type,
68
+ data: data
69
+ }), iframe.src, iframe.contentWindow);
70
+ }
71
+ else {
72
+ // Post to parent.
73
+ _postman.postMessage(JSON.stringify({
74
+ type: type,
75
+ data: data
76
+ }), _parent_url, window.parent);
77
+ }
78
+ },
79
+ receive: function (type, callback)
80
+ {
81
+ console.debug('PostMessage.receive', type);
82
+
83
+ if (undef === _callbacks[type])
84
+ _callbacks[type] = [];
85
+
86
+ _callbacks[type].push(callback);
87
+ },
88
+ receiveOnce: function (type, callback)
89
+ {
90
+ if (this.is_set(type))
91
+ return;
92
+
93
+ this.receive(type, callback);
94
+ },
95
+ // Check if any callbacks assigned to a specified message type.
96
+ is_set: function (type)
97
+ {
98
+ return (undef != _callbacks[type]);
99
+ },
100
+ parent_url: function ()
101
+ {
102
+ return _parent_url;
103
+ },
104
+ parent_subdomain: function ()
105
+ {
106
+ return _parent_subdomain;
107
+ }
108
+ };
109
+ }();
110
+ })(jQuery);
freemius/assets/scss/_colors.scss ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $menu-hover-color: #333;
2
+ $darkest-color: #000;
3
+ $fms-live-color: #71ae00;
4
+ $fms-test-color: #f7941d;
5
+ $fms-link-color: #29abe1;
6
+ $fms-link-hover-color: darken(#29abe1, 10%);
7
+ $body-bkg: #111;
8
+ $special-color: #d3135a;
9
+ $body-color: #f1f1f1;
10
+ $fms-white: #f1f1f1;
11
+ $container-bkg: #222;
12
+ $container-bkg-odd: #262626;
13
+ $container-border-color: #333;
14
+ $table-head-bkg: #333;
15
+ $table-head-color: #999;
16
+ $info-color: #999;
17
+ $error-color: #ff0000;
18
+
19
+ $fs-logo-blue-color: #29abe1;
20
+ $fs-logo-green-color: #71ae00;
21
+ $fs-logo-magenta-color: #d3135a;
22
+
23
+ $fs-notice-promotion-border-color: #00a0d2;
24
+ $fs-notice-promotion-bkg: #f2fcff;
25
+
26
+ // WordPress colors.
27
+ $page-header-bkg: #333;
28
+ $page-header-color: $fms-white;
29
+ $text-dark-color: #333;
30
+ $text-light-color: #666;
31
+ $text-lightest-color: #999;
32
+
33
+ // WP Buttons.
34
+ $button-primary-bkg: #6bc406;
35
+ $button-primary-color: $fms-white;
36
+ $button-secondary-bkg: #333;
37
+ $button-secondary-color: $fms-white;
38
+ $featured-color: #6bc406;
39
+ $wp-selected-color: #0074a3;
40
+
41
+ $wordpress_color: #01749A;
42
+ $blogger_color: #ff8100;
43
+ $wix_color: #fac102;
44
+ $shopify_color: #80d100;
45
+ $addthis_color: #fe6d4e;
46
+ $tumblr_color: #34506b;
47
+ $zepo_color: #00baf2;
48
+ $jquery_color: #000919;
49
+ $javascript_color: #00baf2;
50
+ $squarespace_color: #000;
51
+
52
+ $blog_color: #ff6600;
53
+ $facebook_color: #3b5998;
54
+ $twitter_color: #4099ff;
55
+ $linkedin_color: #4875b4;
56
+ $youtube_color: #ff3333;
57
+ $gplus_color: #c63d2d;
58
+
freemius/assets/scss/_functions.scss ADDED
File without changes
freemius/assets/scss/_load.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import 'mixins';
2
+ @import "vars";
3
+ @import "functions";
4
+ @import "colors";
freemius/assets/scss/_mixins.scss ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ---- CSS3 SASS MIXINS ----
2
+ // https://github.com/madr/css3-sass-mixins
3
+ //
4
+ // Copyright (C) 2011 by Anders Ytterström
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in
14
+ // all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ // THE SOFTWARE.
23
+ //
24
+
25
+ // ---- LEGACY IE SUPPORT USING FILTERS ----
26
+ // Should IE filters be used or not?
27
+ // PROS: gradients, drop shadows etc will be handled by css.
28
+ // CONS: will harm the site performance badly,
29
+ // especially on sites with heavy rendering and scripting.
30
+ $useIEFilters: 0;
31
+ // might be 0 or 1. disabled by default.
32
+ // ---- /LEGACY IE SUPPORT USING FILTERS ----
33
+
34
+
35
+ @mixin background-size ($value) {
36
+ -webkit-background-size: $value;
37
+ background-size: $value;
38
+ }
39
+
40
+ @mixin border-image ($path, $offsets, $repeats) {
41
+ -moz-border-image: $path $offsets $repeats;
42
+ -o-border-image: $path $offsets $repeats;
43
+ -webkit-border-image: $path $offsets $repeats;
44
+ border-image: $path $offsets $repeats;
45
+ }
46
+
47
+ @mixin border-radius ($values...) {
48
+ -moz-border-radius: $values;
49
+ -webkit-border-radius: $values;
50
+ border-radius: $values;
51
+ /*-moz-background-clip: padding;
52
+ -webkit-background-clip: padding-box;
53
+ background-clip: padding-box;*/
54
+ }
55
+
56
+ @mixin box-shadow ($values...) {
57
+ -moz-box-shadow: $values;
58
+ -webkit-box-shadow: $values;
59
+ box-shadow: $values;
60
+ }
61
+
62
+ //@mixin box-shadow ($x, $y, $offset, $hex, $ie: $useIEFilters, $inset: null, $spread:null) {
63
+ // -moz-box-shadow: $x $y $offset $spread $hex $inset;
64
+ // -webkit-box-shadow: $x $y $offset $spread $hex $inset;
65
+ // box-shadow: $x $y $offset $spread $hex $inset;
66
+ //
67
+ // @if $ie == 1 {
68
+ // $iecolor: '#' + red($hex) + green($hex) + blue($hex);
69
+ // filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}');
70
+ // -ms-filter: quote(progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}'));
71
+ // }
72
+ //}
73
+
74
+ @mixin box-sizing($value) {
75
+ -moz-box-sizing: $value;
76
+ -webkit-box-sizing: $value;
77
+ box-sizing: $value;
78
+ }
79
+
80
+ // requires sass 3.2
81
+ //@mixin keyframes {
82
+ // @-moz-keyframes { @content; }
83
+ // @-ms-keyframes { @content; }
84
+ // @-o-keyframes { @content; }
85
+ // @-webkit-keyframes { @content; }
86
+ // @keyframes { @content; }
87
+ //}
88
+
89
+ @mixin linear-gradient($from, $to, $ie: $useIEFilters) {
90
+ @if $ie != 1 { background-color: $to; }
91
+
92
+ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, $from),color-stop(1, $to));
93
+ background-image: -webkit-linear-gradient(top, $from, $to);
94
+ background-image: -moz-linear-gradient(top, $from, $to);
95
+ background-image: -ms-linear-gradient(top, $from, $to);
96
+ background-image: -o-linear-gradient(top, $from, $to);
97
+ background-image: linear-gradient(top, bottom, $from, $to);
98
+
99
+ @if $ie == 1 {
100
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
101
+ }
102
+ }
103
+
104
+ @mixin horizontal-gradient($startColor: #555, $endColor: #333, $ie: $useIEFilters) {
105
+ @if $ie != 1 { background-color: $endColor; }
106
+
107
+ background-color: $endColor;
108
+ background-image: -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
109
+ background-image: -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
110
+ background-image: -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
111
+ background-image: -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
112
+ background-image: linear-gradient(to right, $startColor, $endColor); // Standard, IE10
113
+ background-repeat: repeat-x;
114
+ @if $ie == 1 {
115
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$startColor}', endColorstr='#{$endColor}', GradientType=1);
116
+ }
117
+ }
118
+
119
+ @mixin radial-gradient($from, $to, $ie: $useIEFilters) {
120
+ @if $ie != 1 { background-color: $to; }
121
+
122
+ background: -moz-radial-gradient(center, circle cover, $from 0%, $to 100%);
123
+ background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, $from), color-stop(100%, $to));
124
+ background: -webkit-radial-gradient(center, circle cover, $from 0%, $to 100%);
125
+ background: -o-radial-gradient(center, circle cover, $from 0%, $to 100%);
126
+ background: -ms-radial-gradient(center, circle cover, $from 0%, $to 100%);
127
+ background: radial-gradient(center, circle cover, $from 0%, $to 100%);
128
+ background-color: $from;
129
+
130
+ @if $ie == 1 {
131
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}', GradientType=1); /* IE6-9 fallback on horizontal gradient */
132
+ }
133
+ }
134
+
135
+ /*@mixin rgba-bg ($hex, $alpha, $ie: $useIEFilters) {
136
+ @if $ie == 1 {
137
+ background-color: none;
138
+ $hexopac: ie-hex-str(rgba($hex, $alpha));
139
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#{$hexopac}',EndColorStr='#{$hexopac}}');
140
+ -ms-filter: quote(progid:DXImageTransform.Microsoft.gradient(startColorStr='#{$hexopac}',EndColorStr='#{$hexopac}'));
141
+ }
142
+ @else {
143
+ background-color: $hex;
144
+ background-color: rgba($hex, $alpha);
145
+ }
146
+ }*/
147
+
148
+ @mixin perspective($perspective) {
149
+ -moz-perspective: $perspective;
150
+ -ms-perspective: $perspective;
151
+ -webkit-perspective: $perspective;
152
+ perspective: $perspective;
153
+ -moz-transform-style: preserve-3d;
154
+ -ms-transform-style: preserve-3d;
155
+ -webkit-transform-style: preserve-3d;
156
+ transform-style: preserve-3d;
157
+ }
158
+
159
+ @mixin transform ($transforms) {
160
+ -moz-transform: $transforms;
161
+ -o-transform: $transforms;
162
+ -ms-transform: $transforms;
163
+ -webkit-transform: $transforms;
164
+ transform: $transforms;
165
+ }
166
+
167
+ @mixin matrix ($a, $b, $c, $d, $e, $f) {
168
+ -moz-transform: matrix($a, $b, $c, $d, #{$e}px, #{$f}px);
169
+ -o-transform: matrix($a, $b, $c, $d, $e, $f);
170
+ -ms-transform: matrix($a, $b, $c, $d, $e, $f);
171
+ -webkit-transform: matrix($a, $b, $c, $d, $e, $f);
172
+ transform: matrix($a, $b, $c, $d, $e, $f);
173
+ }
174
+
175
+ @mixin rotate ($deg) {
176
+ @include transform(rotate(#{$deg}deg));
177
+ }
178
+
179
+ @mixin scale ($size) {
180
+ @include transform(scale(#{$size}));
181
+ }
182
+
183
+ @mixin translate ($x, $y) {
184
+ @include transform(translate($x, $y));
185
+ }
186
+
187
+ @mixin transition ($value...) {
188
+ -moz-transition: $value;
189
+ -o-transition: $value;
190
+ -ms-transition: $value;
191
+ -webkit-transition: $value;
192
+ transition: $value;
193
+ }
194
+
195
+ // ==== /CSS3 SASS MIXINS ====
196
+
197
+ @mixin opacity($opacity) {
198
+ opacity: $opacity;
199
+ $opacity-ie: $opacity * 100;
200
+ filter: alpha(opacity=$opacity-ie); //IE8
201
+ }
202
+
203
+ @mixin sprite($img, $width, $height: $width, $display: block)
204
+ {
205
+ display: $display;
206
+ background-image: url('#{$img}');
207
+
208
+ @include size($width, $height);
209
+ }
210
+
211
+ @mixin size($width, $height: $width)
212
+ {
213
+ width: $width;
214
+ height: $height;
215
+ }
216
+
217
+ @mixin clearfix
218
+ {
219
+ &:after {
220
+ content: "";
221
+ display: table;
222
+ clear: both;
223
+ }
224
+ }
freemius/assets/scss/_start.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import "vars";
2
+ @import "colors";
3
+ @import "mixins";
4
+ @import "functions";
freemius/assets/scss/_vars.scss ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ $is_production: true;
2
+
3
+ $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
+
5
+ $layout_width: 960px;
freemius/assets/scss/admin/_deactivation-feedback.scss ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
40
+ #the-list .deactivate > .fs-slug {
41
+ display: none;
42
+ }
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,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-key-resend {
2
+ .button-close {
3
+ float: right;
4
+ margin: 5px;
5
+
6
+ &:hover {
7
+ cursor: pointer;
8
+ }
9
+ }
10
+
11
+ .fs-modal-body {
12
+ .input-container > .email-address-container {
13
+ overflow: hidden;
14
+ padding-right: 2px;
15
+ }
16
+
17
+ input.email-address {
18
+ width: 100%;
19
+ }
20
+
21
+ .button-container {
22
+ float: right;
23
+ margin-left: 7px;
24
+
25
+ @media (max-width: 650px) {
26
+ margin-top: 2px;
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
+ a.show-license-resend-modal {
33
+ margin-top: 4px;
34
+ display: inline-block;
35
+ }
freemius/assets/scss/admin/_modal-common.scss ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+
3
+ .fs-modal {
4
+ position: fixed;
5
+ overflow: auto;
6
+ height: 100%;
7
+ width: 100%;
8
+ top: 0;
9
+ z-index: 100000;
10
+ display: none;
11
+ background: rgba(0, 0, 0, 0.6);
12
+
13
+ .fs-modal-dialog {
14
+ background: transparent;
15
+ position: absolute;
16
+ left: 50%;
17
+ margin-left: -298px;
18
+ padding-bottom: 30px;
19
+ top: -100%;
20
+ z-index: 100001;
21
+ width: 596px;
22
+
23
+ @media (max-width: 650px) {
24
+ margin-left: -50%;
25
+ box-sizing: border-box;
26
+ padding-left: 10px;
27
+ padding-right: 10px;
28
+ width: 100%;
29
+
30
+ .fs-modal-panel > h3 > strong {
31
+ font-size: 1.3em;
32
+ }
33
+ }
34
+ }
35
+
36
+ &.active {
37
+ display: block;
38
+
39
+ &:before {
40
+ display: block;
41
+ }
42
+
43
+ .fs-modal-dialog {
44
+ top: 10%;
45
+ }
46
+ }
47
+
48
+ .fs-modal-body,
49
+ .fs-modal-footer {
50
+ border: 0;
51
+ background: #fefefe;
52
+ padding: 20px;
53
+ }
54
+
55
+ .fs-modal-body {
56
+ border-bottom: 0;
57
+
58
+ p {
59
+ font-size: 14px;
60
+ }
61
+
62
+ h2 {
63
+ font-size: 20px;
64
+ }
65
+
66
+ > div {
67
+ margin-top: 10px;
68
+
69
+ h2 {
70
+ font-weight: bold;
71
+ font-size: 20px;
72
+ margin-top: 0;
73
+ }
74
+ }
75
+ }
76
+
77
+ .fs-modal-footer {
78
+ border-top: #eeeeee solid 1px;
79
+ text-align: right;
80
+
81
+ > .button {
82
+ margin: 0 7px;
83
+
84
+ &:first-child {
85
+ margin: 0;
86
+ }
87
+ }
88
+ }
89
+
90
+ .fs-modal-panel {
91
+ > .notice.inline {
92
+ margin: 0;
93
+ display: none;
94
+ }
95
+
96
+ &:not(.active) {
97
+ display: none;
98
+ }
99
+ }
100
+ }
101
+
102
+ body.has-fs-modal {
103
+ overflow: hidden;
104
+ }
freemius/assets/scss/admin/account.scss ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #fs_account
2
+ {
3
+ .postbox,
4
+ .widefat
5
+ {
6
+ max-width: 700px;
7
+ }
8
+
9
+ h3
10
+ {
11
+ font-size: 1.3em;
12
+ padding: 12px 15px;
13
+ margin: 0 0 12px 0;
14
+ line-height: 1.4;
15
+ border-bottom: 1px solid #F1F1F1;
16
+ }
17
+
18
+ i.dashicons
19
+ {
20
+ font-size: 1.2em;
21
+ height: 1.2em;
22
+ width: 1.2em;
23
+ }
24
+
25
+ .button
26
+ {
27
+ i.dashicons
28
+ {
29
+ vertical-align: middle;
30
+ }
31
+ }
32
+
33
+ .fs-header-actions
34
+ {
35
+ position: absolute;
36
+ top: 17px;
37
+ right: 15px;
38
+ font-size: 0.9em;
39
+
40
+ ul
41
+ {
42
+ margin: 0;
43
+ }
44
+
45
+ li
46
+ {
47
+ form
48
+ {
49
+ display: inline-block;
50
+ }
51
+
52
+ float: left;
53
+ a
54
+ {
55
+ text-decoration: none;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ #fs_account_details .button-group {
62
+ float: right;
63
+ }
64
+
65
+ .rtl #fs_account .fs-header-actions
66
+ {
67
+ left: 15px;
68
+ right: auto;
69
+ }
70
+
71
+ .fs-key-value-table
72
+ {
73
+ width: 100%;
74
+
75
+ form
76
+ {
77
+ display: inline-block;
78
+ }
79
+
80
+ tr
81
+ {
82
+ td:first-child
83
+ {
84
+ nobr
85
+ {
86
+ font-weight: bold;
87
+ }
88
+
89
+ text-align: right;
90
+
91
+ form
92
+ {
93
+ display: block;
94
+ }
95
+ }
96
+
97
+ td.fs-right
98
+ {
99
+ text-align: right;
100
+ }
101
+
102
+ &.fs-odd
103
+ {
104
+ background: #ebebeb;
105
+ }
106
+ }
107
+
108
+ td, th
109
+ {
110
+ padding: 10px;
111
+ }
112
+
113
+ code {
114
+ line-height: 28px;
115
+ }
116
+
117
+ var, code, input[type="text"]
118
+ {
119
+ color: #0073AA;
120
+ font-size: 16px;
121
+ background: none;
122
+ }
123
+
124
+ input[type="text"] {
125
+ width: 100%;
126
+ font-weight: bold;
127
+ }
128
+ }
129
+
130
+ label.fs-tag
131
+ {
132
+ background: #ffba00;
133
+ color: #fff;
134
+ display: inline-block;
135
+ border-radius: 3px;
136
+ padding: 5px;
137
+ font-size: 11px;
138
+ line-height: 11px;
139
+ vertical-align: baseline;
140
+
141
+ &.fs-warn
142
+ {
143
+ background: #ffba00;
144
+ }
145
+ &.fs-success
146
+ {
147
+ background: #46b450;
148
+ }
149
+ &.fs-error
150
+ {
151
+ background: #dc3232;
152
+ }
153
+ }
154
+
155
+ #fs_addons
156
+ {
157
+ h3
158
+ {
159
+ border: none;
160
+ margin-bottom: 0;
161
+ padding: 4px 5px;
162
+ }
163
+
164
+ td
165
+ {
166
+ vertical-align: middle;
167
+ }
168
+
169
+ td:first-child,
170
+ th:first-child
171
+ {
172
+ text-align: left;
173
+ font-weight: bold;
174
+ }
175
+ td:last-child,
176
+ th:last-child
177
+ {
178
+ text-align: right;
179
+ }
180
+ th
181
+ {
182
+ font-weight: bold;
183
+ }
184
+ }
freemius/assets/scss/admin/add-ons.scss ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_addons
4
+ {
5
+ .fs-cards-list
6
+ {
7
+ list-style: none;
8
+
9
+ .fs-card
10
+ {
11
+ float: left;
12
+ // height: 185px; // With reviews/ratings
13
+ height: 152px;
14
+ width: 310px;
15
+ padding: 0;
16
+ margin: 0 0 30px 30px;
17
+ font-size: 14px;
18
+ list-style: none;
19
+ border: 1px solid #ddd;
20
+ cursor: pointer;
21
+ position: relative;
22
+
23
+ .fs-overlay
24
+ {
25
+ position: absolute;
26
+ left: 0;
27
+ right: 0;
28
+ bottom: 0;
29
+ top: 0;
30
+ z-index: 9;
31
+ }
32
+
33
+ .fs-inner
34
+ {
35
+ background-color: #fff;
36
+ overflow: hidden;
37
+ height: 100%;
38
+ position: relative;
39
+
40
+ ul
41
+ {
42
+ @include transition(all, 0.15s);
43
+ left: 0;
44
+ right: 0;
45
+ top: 0;
46
+ position: absolute;
47
+ }
48
+
49
+ li
50
+ {
51
+ list-style: none;
52
+ line-height: 18px;
53
+ padding: 0 15px;
54
+ width: 100%;
55
+ display: block;
56
+ @include box-sizing(border-box);
57
+ }
58
+
59
+ .fs-card-banner
60
+ {
61
+ padding: 0;
62
+ margin: 0;
63
+ line-height: 0;
64
+ display: block;
65
+ height: 100px;
66
+ background-repeat: repeat-x;
67
+ background-size: 100% 100%;
68
+ @include transition(all, 0.15s);
69
+ }
70
+
71
+ .fs-title
72
+ {
73
+ margin: 10px 0 0 0;
74
+ height: 18px;
75
+ overflow: hidden;
76
+ color: #000;
77
+ white-space: nowrap;
78
+ text-overflow: ellipsis;
79
+ font-weight: bold;
80
+ }
81
+
82
+ .fs-offer
83
+ {
84
+ font-size: 0.9em;
85
+ }
86
+
87
+ .fs-description
88
+ {
89
+ background-color: #f9f9f9;
90
+ padding: 10px 15px 100px 15px;
91
+ border-top: 1px solid #eee;
92
+ margin: 0 0 10px 0;
93
+ color: #777;
94
+ }
95
+
96
+ .fs-tag
97
+ {
98
+ position: absolute;
99
+ top: 10px;
100
+ right: 0px;
101
+ background: greenyellow;
102
+ display: block;
103
+ padding: 2px 10px;
104
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.3));
105
+ text-transform: uppercase;
106
+ font-size: 0.9em;
107
+ font-weight: bold;
108
+ }
109
+
110
+ .fs-cta
111
+ {
112
+ .button
113
+ {
114
+ position: absolute;
115
+ top: 112px;
116
+ right: 10px;
117
+ }
118
+ }
119
+ }
120
+
121
+ @media screen and (min-width: 960px) {
122
+ &:hover
123
+ {
124
+ .fs-overlay
125
+ {
126
+ border: 2px solid $fms-link-color;
127
+ margin-left: -1px;
128
+ margin-top: -1px;
129
+ }
130
+
131
+ .fs-inner
132
+ {
133
+ ul
134
+ {
135
+ top: -100px;
136
+ }
137
+
138
+ .fs-card-banner
139
+ {
140
+ // background-position: 50% -100px;
141
+ }
142
+
143
+ .fs-title,
144
+ .fs-offer
145
+ {
146
+ color: $fms-link-color;
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ #TB_window
156
+ {
157
+ &, iframe
158
+ {
159
+ width: 772px !important;
160
+ }
161
+ }
162
+
163
+ #plugin-information
164
+ {
165
+ #section-description
166
+ {
167
+ h2, h3, p, b, i, blockquote, li, ul, ol
168
+ {
169
+ clear: none;
170
+ }
171
+
172
+ .fs-selling-points
173
+ {
174
+ padding-bottom: 10px;
175
+ border-bottom: 1px solid #ddd;
176
+
177
+ ul
178
+ {
179
+ margin: 0;
180
+
181
+ li
182
+ {
183
+ padding: 0;
184
+ list-style: none outside none;
185
+
186
+ i.dashicons
187
+ {
188
+ color: $fs-logo-green-color;
189
+ font-size: 3em;
190
+ vertical-align: middle;
191
+ line-height: 30px;
192
+ float: left;
193
+ margin: 0 0 0 -15px;
194
+ }
195
+
196
+ h3
197
+ {
198
+ margin: 1em 30px !important;
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ .fs-screenshots
205
+ {
206
+ @include clearfix();
207
+ ul
208
+ {
209
+ list-style: none;
210
+ margin: 0;
211
+
212
+ li
213
+ {
214
+ width: 225px;
215
+ height: 225px;
216
+ float: left;
217
+ margin-bottom: 20px;
218
+ @include box-sizing(content-box);
219
+
220
+ a
221
+ {
222
+ display: block;
223
+ width: 100%;
224
+ height: 100%;
225
+ border: 1px solid;
226
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
227
+ background-size: cover;
228
+ }
229
+
230
+ &.odd
231
+ {
232
+ margin-right: 20px;
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ .plugin-information-pricing
240
+ {
241
+ $pricing_color: #FFFEEC;
242
+ $borders_color: #DDD;
243
+ margin: -16px;
244
+ // padding: 20px;
245
+ border-bottom: 1px solid $borders_color;
246
+
247
+ .fs-plan
248
+ {
249
+
250
+ h3
251
+ {
252
+ margin-top: 0;
253
+ padding: 20px;
254
+ font-size: 16px;
255
+ }
256
+
257
+ .nav-tab-wrapper
258
+ {
259
+ border-bottom: 1px solid $borders_color;
260
+
261
+ .nav-tab
262
+ {
263
+ cursor: pointer;
264
+ position: relative;
265
+ padding: 0 10px;
266
+ font-size: 0.9em;
267
+
268
+ label
269
+ {
270
+ text-transform: uppercase;
271
+ color: green;
272
+ background: greenyellow;
273
+ position: absolute;
274
+ left: -1px;
275
+ right: -1px;
276
+ bottom: 100%;
277
+ border: 1px solid darkgreen;
278
+ padding: 2px;
279
+ text-align: center;
280
+ font-size: 0.9em;
281
+ line-height: 1em;
282
+ }
283
+
284
+ &.nav-tab-active
285
+ {
286
+ cursor: default;
287
+ background: $pricing_color;
288
+ border-bottom-color: $pricing_color;
289
+ }
290
+ }
291
+ }
292
+
293
+ &.fs-single-cycle
294
+ {
295
+ h3
296
+ {
297
+ background: $pricing_color;
298
+ margin: 0;
299
+ padding-bottom: 0;
300
+ color: #0073aa;
301
+ }
302
+
303
+ .nav-tab-wrapper,
304
+ .fs-billing-frequency
305
+ {
306
+ display: none;
307
+ }
308
+ }
309
+
310
+ .fs-pricing-body
311
+ {
312
+ background: $pricing_color;
313
+ padding: 20px;
314
+ }
315
+
316
+ .button
317
+ {
318
+ width: 100%;
319
+ text-align: center;
320
+ font-weight: bold;
321
+ text-transform: uppercase;
322
+ font-size: 1.1em;
323
+ }
324
+
325
+ label
326
+ {
327
+ white-space: nowrap;
328
+ }
329
+
330
+ var {
331
+ font-style: normal;
332
+ }
333
+
334
+ .fs-billing-frequency,
335
+ .fs-annual-discount
336
+ {
337
+ text-align: center;
338
+ display: block;
339
+ font-weight: bold;
340
+ margin-bottom: 10px;
341
+ text-transform: uppercase;
342
+ background: #F3F3F3;
343
+ padding: 2px;
344
+ border: 1px solid #ccc;
345
+ }
346
+
347
+ .fs-annual-discount
348
+ {
349
+ text-transform: none;
350
+ color: green;
351
+ background: greenyellow;
352
+ }
353
+
354
+ ul.fs-trial-terms
355
+ {
356
+ font-size: 0.9em;
357
+
358
+ i
359
+ {
360
+ float: left;
361
+ margin: 0 0 0 -15px;
362
+ }
363
+
364
+ li
365
+ {
366
+ margin: 10px 0 0 0;
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ #section-features
373
+ {
374
+ .fs-features
375
+ {
376
+ margin: -20px -26px;
377
+ }
378
+
379
+ table
380
+ {
381
+ width: 100%;
382
+ border-spacing: 0;
383
+ border-collapse: separate;
384
+
385
+ thead
386
+ {
387
+ th
388
+ {
389
+ padding: 10px 0;
390
+ }
391
+
392
+ .fs-price
393
+ {
394
+ color: $fs-logo-green-color;
395
+ font-weight: normal;
396
+ display: block;
397
+ text-align: center;
398
+ }
399
+ }
400
+
401
+ tbody
402
+ {
403
+ td
404
+ {
405
+ border-top: 1px solid #ccc;
406
+ padding: 10px 0;
407
+ text-align: center;
408
+ width: 100px;
409
+ color: $fs-logo-green-color;
410
+
411
+ &:first-child
412
+ {
413
+ text-align: left;
414
+ width: auto;
415
+ color: inherit;
416
+ padding-left: 26px;
417
+ }
418
+ }
419
+ tr.fs-odd
420
+ {
421
+ td
422
+ {
423
+ background: #fefefe;
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ .dashicons-yes
430
+ {
431
+ width: 30px;
432
+ height: 30px;
433
+ font-size: 30px;
434
+ }
435
+ }
436
+ }
437
+
438
+ @media screen and (max-width: 961px) {
439
+ #fs_addons
440
+ {
441
+ .fs-cards-list
442
+ {
443
+ .fs-card
444
+ {
445
+ height: 265px;
446
+ }
447
+ }
448
+ }
449
+ }
freemius/assets/scss/admin/common.scss ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .fs-notice
4
+ {
5
+ position: relative;
6
+
7
+ &.fs-has-title
8
+ {
9
+ margin-bottom: 30px !important;
10
+ }
11
+
12
+ &.success
13
+ {
14
+ color: green;
15
+ // font-weight: normal;
16
+ }
17
+
18
+ &.promotion
19
+ {
20
+ border-color: $fs-notice-promotion-border-color !important;
21
+ background-color: $fs-notice-promotion-bkg !important;
22
+ }
23
+
24
+ .fs-notice-body
25
+ {
26
+ margin: .5em 0;
27
+ padding: 2px;
28
+ }
29
+
30
+ .fs-close
31
+ {
32
+ // position: absolute;
33
+ // top: 2px;
34
+ // bottom: 2px;
35
+ // right: 2px;
36
+ // min-width: 100px;
37
+ // text-align: center;
38
+ // padding-right: 2px;
39
+ cursor: pointer;
40
+ color: #aaa;
41
+ float: right;
42
+
43
+ &:hover
44
+ {
45
+ color: #666;
46
+ // background: #A9A9A9;
47
+ }
48
+
49
+ > *
50
+ {
51
+ margin-top: 7px;
52
+ display: inline-block;
53
+ }
54
+ }
55
+
56
+ label.fs-plugin-title
57
+ {
58
+ background: rgba(0, 0, 0, 0.3);
59
+ color: #fff;
60
+ padding: 2px 10px;
61
+ position: absolute;
62
+ top: 100%;
63
+ bottom: auto;
64
+ right: auto;
65
+ @include border-radius(0 0 3px 3px);
66
+ left: 10px;
67
+ font-size: 12px;
68
+ font-weight: bold;
69
+ cursor: auto;
70
+ }
71
+ }
72
+
73
+ .rtl .fs-notice
74
+ {
75
+ .fs-close
76
+ {
77
+ // left: 2px;
78
+ // right: auto;
79
+ // padding-right: 0;
80
+ // padding-left: 2px;
81
+ float: left;
82
+ }
83
+ }
84
+
85
+ .fs-secure-notice
86
+ {
87
+ position: fixed;
88
+ top: 32px;
89
+ left: 160px;
90
+ right: 0;
91
+ background: rgb(235, 253, 235);
92
+ padding: 10px 20px;
93
+ color: green;
94
+ z-index: 9999;
95
+ box-shadow: 0px 2px 2px rgba(6, 113, 6, 0.3);
96
+ @include opacity(0.95);
97
+
98
+ &:hover
99
+ {
100
+ @include opacity(1);
101
+ }
102
+ }
103
+
104
+ @media screen and (max-width: 960px) {
105
+ .fs-secure-notice
106
+ {
107
+ left: 36px;
108
+ }
109
+ }
110
+
111
+ @media screen and (max-width: 782px) {
112
+ .fs-secure-notice
113
+ {
114
+ left: 0;
115
+ top: 46px;
116
+ text-align: center;
117
+ }
118
+ }
119
+
120
+ span.fs-submenu-item.fs-sub:before
121
+ {
122
+ // Add small arrow.
123
+ content: '\21B3';
124
+ padding: 0 5px;
125
+ }
126
+
127
+ .rtl
128
+ {
129
+ span.fs-submenu-item.fs-sub:before
130
+ {
131
+ // Add small RTL arrow.
132
+ content: '\21B2';
133
+ }
134
+ }
freemius/assets/scss/admin/connect.scss ADDED
@@ -0,0 +1,471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ $form_width: 480px;
4
+
5
+ #fs_connect
6
+ {
7
+ width: $form_width;
8
+ @include box-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
9
+ margin: 20px 0;
10
+
11
+ @media screen and (max-width: ($form_width - 1)) {
12
+ @include box-shadow(none);
13
+ width: auto;
14
+ margin: 0 0 0 -10px;
15
+ }
16
+
17
+ .fs-content
18
+ {
19
+ background: #fff;
20
+ padding: 15px 20px;
21
+
22
+ .fs-error {
23
+ background: snow;
24
+ color: $fs-logo-magenta-color;
25
+ border: 1px solid $fs-logo-magenta-color;
26
+ @include box-shadow(0 1px 1px 0 rgba(0,0,0,.1));
27
+ text-align: center;
28
+ padding: 5px;
29
+ margin-bottom: 10px;
30
+ }
31
+
32
+ p
33
+ {
34
+ margin: 0;
35
+ padding: 0;
36
+ font-size: 1.2em;
37
+ }
38
+ }
39
+
40
+ .fs-license-key-container {
41
+ position: relative;
42
+ width: 280px;
43
+ margin: 10px auto 0 auto;
44
+
45
+ input {
46
+ width: 100%;
47
+ }
48
+
49
+ .dashicons {
50
+ position: absolute;
51
+ top: 5px;
52
+ right: 5px;
53
+ }
54
+ }
55
+
56
+ .fs-actions
57
+ {
58
+ padding: 10px 20px;
59
+ background: #C0C7CA;
60
+
61
+ .button
62
+ {
63
+ padding: 0 10px 1px;
64
+ line-height: 35px;
65
+ height: 37px;
66
+ font-size: 16px;
67
+ margin-bottom: 0;
68
+
69
+ .dashicons
70
+ {
71
+ font-size: 37px;
72
+ margin-left: -8px;
73
+ margin-right: 12px;
74
+ }
75
+
76
+ &.button-primary
77
+ {
78
+ padding-right: 15px;
79
+ padding-left: 15px;
80
+
81
+ &:after
82
+ {
83
+ content: ' \279C';
84
+ }
85
+
86
+ &.fs-loading
87
+ {
88
+ &:after
89
+ {
90
+ content: '';
91
+ }
92
+ }
93
+ }
94
+
95
+ &.button-secondary
96
+ {
97
+ float: right;
98
+ }
99
+ }
100
+
101
+ // .fs-skip
102
+ // {
103
+ // line-height: 38px;
104
+ // vertical-align: middle;
105
+ // text-decoration: none;
106
+ // margin-left: 10px;
107
+ // }
108
+ }
109
+
110
+ &.fs-anonymous-disabled
111
+ {
112
+ .fs-actions
113
+ {
114
+ .button.button-primary
115
+ {
116
+ width: 100%;
117
+ }
118
+ }
119
+ }
120
+
121
+ .fs-permissions
122
+ {
123
+ padding: 10px 20px;
124
+ background: #FEFEFE;
125
+ // background: #F1F1F1;
126
+ @include transition(background 0.5s ease);
127
+
128
+ .fs-license-sync-disclaimer {
129
+ text-align: center;
130
+ margin-top: 0;
131
+ }
132
+
133
+ .fs-trigger
134
+ {
135
+ font-size: 0.9em;
136
+ text-decoration: none;
137
+ text-align: center;
138
+ display: block;
139
+ }
140
+
141
+ ul
142
+ {
143
+ height: 0;
144
+ overflow: hidden;
145
+ margin: 0;
146
+
147
+ li
148
+ {
149
+ margin-bottom: 12px;
150
+
151
+ &:last-child
152
+ {
153
+ margin-bottom: 0;
154
+ }
155
+
156
+ i.dashicons
157
+ {
158
+ float: left;
159
+ font-size: 40px;
160
+ width: 40px;
161
+ height: 40px;
162
+ }
163
+
164
+ div
165
+ {
166
+ margin-left: 55px;
167
+
168
+ span
169
+ {
170
+ font-weight: bold;
171
+ text-transform: uppercase;
172
+ color: #23282d;
173
+ }
174
+
175
+ p
176
+ {
177
+ margin: 2px 0 0 0;
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ &.fs-open
184
+ {
185
+ background: #fff;
186
+
187
+ ul
188
+ {
189
+ height: auto;
190
+ margin: 20px 20px 10px 20px;
191
+ }
192
+ }
193
+
194
+ @media screen and (max-width: ($form_width - 1)) {
195
+ background: #fff;
196
+
197
+ .fs-trigger
198
+ {
199
+ display: none;
200
+ }
201
+
202
+ ul
203
+ {
204
+ height: auto;
205
+ margin: 20px;
206
+ }
207
+ }
208
+ }
209
+
210
+ .fs-freemium-licensing {
211
+ padding: 8px;
212
+ // background: #0085BA;
213
+ background: #777;
214
+ color: #fff;
215
+
216
+ p {
217
+ text-align: center;
218
+ display: block;
219
+ margin: 0;
220
+ padding: 0;
221
+ }
222
+
223
+ a {
224
+ color: #C2EEFF;
225
+ text-decoration: underline;
226
+ }
227
+ }
228
+
229
+ $icon_size: 80px;
230
+ $wp_logo_padding: $icon_size / 10;
231
+ $icons_top: 10px;
232
+
233
+ .fs-visual
234
+ {
235
+ padding: 12px;
236
+ line-height: 0;
237
+ background: #fafafa;
238
+ height: $icon_size;
239
+ position: relative;
240
+
241
+ .fs-site-icon
242
+ {
243
+ position: absolute;
244
+ left: 20px;
245
+ top: $icons_top;
246
+ }
247
+
248
+ .fs-connect-logo
249
+ {
250
+ position: absolute;
251
+ right: 20px;
252
+ top: $icons_top;
253
+ }
254
+
255
+ .fs-plugin-icon
256
+ {
257
+ position: absolute;
258
+ top: $icons_top;
259
+ left: 50%;
260
+ margin-left: - ($icon_size / 2);
261
+ }
262
+
263
+ .fs-plugin-icon,
264
+ .fs-site-icon,
265
+ img,
266
+ object
267
+ {
268
+ width: $icon_size;
269
+ height: $icon_size;
270
+ }
271
+
272
+ .dashicons-wordpress
273
+ {
274
+ font-size: $icon_size - ($wp_logo_padding * 2);
275
+ background: $wordpress_color;
276
+ color: #fff;
277
+ width: $icon_size - ($wp_logo_padding * 2);
278
+ height: $icon_size - ($wp_logo_padding * 2);
279
+ padding: $wp_logo_padding;
280
+ }
281
+
282
+ .dashicons-plus
283
+ {
284
+ position: absolute;
285
+ top: 50%;
286
+ font-size: 30px;
287
+ margin-top: -10px;
288
+ color: #bbb;
289
+
290
+ &.fs-first
291
+ {
292
+ left: 28%;
293
+ }
294
+ &.fs-second
295
+ {
296
+ left: 65%;
297
+ }
298
+ }
299
+
300
+ .fs-plugin-icon,
301
+ .fs-connect-logo,
302
+ .fs-site-icon
303
+ {
304
+ border: 1px solid #ccc;
305
+ padding: 1px;
306
+ background: #fff;
307
+ }
308
+ }
309
+
310
+ .fs-terms
311
+ {
312
+ text-align: center;
313
+ font-size: 0.85em;
314
+ padding: 5px;
315
+ background: rgba(0, 0, 0, 0.05);
316
+
317
+ &, a
318
+ {
319
+ color: #999;
320
+ }
321
+
322
+ a
323
+ {
324
+ text-decoration: none;
325
+ }
326
+ }
327
+ }
328
+
329
+ .rtl
330
+ {
331
+ #fs_connect
332
+ {
333
+ .fs-actions
334
+ {
335
+ padding: 10px 20px;
336
+ background: #C0C7CA;
337
+
338
+ .button
339
+ {
340
+ .dashicons
341
+ {
342
+ font-size: 37px;
343
+ margin-left: -8px;
344
+ margin-right: 12px;
345
+ }
346
+
347
+ &.button-primary
348
+ {
349
+ &:after
350
+ {
351
+ content: ' \000bb';
352
+ }
353
+
354
+ &.fs-loading
355
+ {
356
+ &:after
357
+ {
358
+ content: '';
359
+ }
360
+ }
361
+ }
362
+
363
+ &.button-secondary
364
+ {
365
+ float: left;
366
+ }
367
+ }
368
+ }
369
+
370
+ .fs-permissions
371
+ {
372
+ ul
373
+ {
374
+ li
375
+ {
376
+ div
377
+ {
378
+ margin-right: 55px;
379
+ margin-left: 0;
380
+ }
381
+
382
+ i.dashicons
383
+ {
384
+ float: right;
385
+ }
386
+
387
+ }
388
+ }
389
+ }
390
+
391
+ .fs-visual
392
+ {
393
+ .fs-site-icon
394
+ {
395
+ right: 20px;
396
+ left: auto;
397
+ }
398
+
399
+ .fs-connect-logo
400
+ {
401
+ right: auto;
402
+ left: 20px;
403
+ }
404
+ }
405
+ }
406
+ }
407
+
408
+ .wp-pointer-content
409
+ {
410
+ #fs_connect
411
+ {
412
+ margin: 0;
413
+ @include box-shadow(none);
414
+ }
415
+ }
416
+
417
+ .fs-opt-in-pointer
418
+ {
419
+ .wp-pointer-content
420
+ {
421
+ padding: 0;
422
+ }
423
+
424
+ &.wp-pointer-top
425
+ {
426
+ .wp-pointer-arrow
427
+ {
428
+ border-bottom-color: #dfdfdf;
429
+ }
430
+ .wp-pointer-arrow-inner
431
+ {
432
+ border-bottom-color: #fafafa;
433
+ }
434
+ }
435
+
436
+ &.wp-pointer-bottom
437
+ {
438
+ .wp-pointer-arrow
439
+ {
440
+ border-top-color: #dfdfdf;
441
+ }
442
+ .wp-pointer-arrow-inner
443
+ {
444
+ border-top-color: #fafafa;
445
+ }
446
+ }
447
+
448
+ &.wp-pointer-left
449
+ {
450
+ .wp-pointer-arrow
451
+ {
452
+ border-right-color: #dfdfdf;
453
+ }
454
+ .wp-pointer-arrow-inner
455
+ {
456
+ border-right-color: #fafafa;
457
+ }
458
+ }
459
+
460
+ &.wp-pointer-right
461
+ {
462
+ .wp-pointer-arrow
463
+ {
464
+ border-left-color: #dfdfdf;
465
+ }
466
+ .wp-pointer-arrow-inner
467
+ {
468
+ border-left-color: #fafafa;
469
+ }
470
+ }
471
+ }
freemius/assets/scss/admin/debug.scss ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .switch
4
+ {
5
+ position: relative;
6
+ display: inline-block;
7
+ font-size: 1.6em;
8
+ font-weight: bold;
9
+ color: #ccc;
10
+ text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.8);
11
+ height: 18px;
12
+ padding: 6px 6px 5px 6px;
13
+ border: 1px solid #ccc;
14
+ border: 1px solid rgba(0, 0, 0, 0.2);
15
+ border-radius: 4px;
16
+ background: #ececec;
17
+ box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), inset 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
18
+ cursor: pointer;
19
+
20
+ span
21
+ {
22
+ display: inline-block; width: 35px;
23
+ text-transform: uppercase;
24
+
25
+ &.on
26
+ {
27
+ color: $button-primary-bkg;
28
+ }
29
+ }
30
+
31
+ .toggle
32
+ {
33
+ position: absolute;
34
+ top: 1px;
35
+ width: 37px;
36
+ height: 25px;
37
+ border: 1px solid #ccc;
38
+ border: 1px solid rgba(0, 0, 0, 0.3);
39
+ border-radius: 4px;
40
+ background: #fff;
41
+ background: -moz-linear-gradient(top, #ececec 0%, #fff 100%);
42
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));
43
+ background: -webkit-linear-gradient(top, #ececec 0%, #fff 100%);
44
+ background: -o-linear-gradient(top, #ececec 0%, #fff 100%);
45
+ background: -ms-linear-gradient(top, #ececec 0%, #fff 100%);
46
+ background: linear-gradient(top, #ececec 0%, #fff 100%);
47
+ box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, 0.5);
48
+ z-index: 999;
49
+ @include transition(all 0.15s ease-in-out);
50
+ }
51
+
52
+ &.on .toggle
53
+ {
54
+ left: 2%;
55
+ }
56
+ &.off .toggle
57
+ {
58
+ left: 54%;
59
+ }
60
+
61
+ /* Round switch */
62
+ &.round
63
+ {
64
+ padding: 0px 20px;
65
+ border-radius: 40px;
66
+
67
+ .toggle
68
+ {
69
+ border-radius: 40px;
70
+ width: 14px;
71
+ height: 14px;
72
+ }
73
+
74
+ &.on .toggle
75
+ {
76
+ left: 3%;
77
+ background: $button-primary-bkg;
78
+ }
79
+ &.off .toggle
80
+ {
81
+ left: 58%;
82
+ }
83
+ }
84
+ }
85
+
86
+ .switch-label
87
+ {
88
+ font-size: 20px;
89
+ line-height: 31px;
90
+ margin: 0 5px;
91
+ }
freemius/assets/scss/admin/dialog-boxes.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import "modal-common";
2
+ @import "deactivation-feedback";
3
+ @import "license-activation";
4
+ @import "license-key-resend";
freemius/composer.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "freemius/wordpress-sdk",
3
+ "description": "Freemius WordPress SDK",
4
+ "keywords": ["freemius", "wordpress", "plugin", "sdk"],
5
+ "homepage": "https://freemius.com",
6
+ "license": "GPL-2.0+",
7
+ "require": {
8
+ "php": ">=5.2"
9
+ }
10
+ }
freemius/config.php ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ define( 'WP_FS__SLUG', 'freemius' );
14
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
15
+ define( 'WP_FS__DEV_MODE', false );
16
+ }
17
+
18
+ /**
19
+ * API Connectivity Simulation
20
+ */
21
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
22
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
23
+ }
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
32
+ }
33
+ if ( WP_FS__SIMULATE_NO_CURL ) {
34
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
37
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
41
+ }
42
+
43
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
44
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
45
+ }
46
+
47
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
48
+ /**
49
+ * @since 1.1.7.3
50
+ * @author Vova Feldman (@svovaf)
51
+ *
52
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
53
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
54
+ * between domains on a daily basis. Therefore, to eliminate the risk of
55
+ * multiple unwanted connectivity test pings, temporary ignore domain or
56
+ * server IP changes.
57
+ */
58
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
59
+ }
60
+
61
+ /**
62
+ * If your dev environment supports custom public network IP setup
63
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
64
+ * and uncomment it during dev.
65
+ */
66
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
67
+ // VVV default public network IP.
68
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
69
+
70
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
71
+ }
72
+
73
+ /**
74
+ * If true and running with secret key, the opt-in process
75
+ * will skip the email activation process which is invoked
76
+ * when the email of the context user already exist in Freemius
77
+ * database (as a security precaution, to prevent sharing user
78
+ * secret with unauthorized entity).
79
+ *
80
+ * IMPORTANT:
81
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
82
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
83
+ * CLOCK IS SYNCED.
84
+ */
85
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
86
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
87
+ }
88
+
89
+
90
+ /**
91
+ * Directories
92
+ */
93
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
94
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
95
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
96
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
97
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
98
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
99
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
100
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
101
+
102
+
103
+ /**
104
+ * Domain / URL / Address
105
+ */
106
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
107
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
108
+
109
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
110
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
111
+ }
112
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
113
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
114
+ }
115
+
116
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
117
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
118
+ }
119
+
120
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
121
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
122
+ }
123
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
124
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
125
+ }
126
+
127
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
128
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
129
+
130
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
131
+ // By default, run with Freemius production servers.
132
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
133
+ }
134
+
135
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
136
+
137
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
138
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
139
+ } else {
140
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
141
+ is_string( WP_FS__REMOTE_ADDR ) &&
142
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) == '127.' ||
143
+ WP_FS__REMOTE_ADDR == '::1' )
144
+ );
145
+ }
146
+
147
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
148
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
149
+
150
+ // Set API address for local testing.
151
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
152
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
153
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
154
+ }
155
+
156
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
157
+
158
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
159
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
160
+ }
161
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
162
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
163
+ }
164
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
165
+
166
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
167
+ // Checks if CloudFlare's HTTPS (Flexible SSL support)
168
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) ||
169
+ // Check if HTTPS request.
170
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
171
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
172
+ );
173
+
174
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
175
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
176
+
177
+ /**
178
+ * Billing Frequencies
179
+ */
180
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
181
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
182
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
183
+
184
+ /**
185
+ * Plans
186
+ */
187
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
188
+ define( 'WP_FS__PLAN_FREE', 'free' );
189
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
190
+
191
+ /**
192
+ * Times in seconds
193
+ */
194
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
195
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
196
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
197
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', 86400 );
198
+
199
+ /**
200
+ * Debugging
201
+ */
202
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
203
+ $debug_mode = get_option( 'fs_debug_mode', null );
204
+
205
+ if ( $debug_mode === null ) {
206
+ $debug_mode = false;
207
+ add_option( 'fs_debug_mode', $debug_mode );
208
+ }
209
+
210
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
211
+ }
212
+
213
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
214
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-n-d H:i:s' );
215
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
216
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
217
+ }
218
+
219
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
220
+ error_reporting( E_ALL );
221
+ ini_set( 'error_reporting', E_ALL );
222
+ ini_set( 'display_errors', true );
223
+ ini_set( 'html_errors', true );
224
+ }
225
+
226
+
227
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
228
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
229
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
freemius/includes/class-freemius-abstract.php ADDED
@@ -0,0 +1,454 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+
13
+ /**
14
+ * - Each instance of Freemius class represents a single plugin
15
+ * install by a single user (the installer of the plugin).
16
+ *
17
+ * - Each website can only have one install of the same plugin.
18
+ *
19
+ * - Install entity is only created after a user connects his account with Freemius.
20
+ *
21
+ * Class Freemius_Abstract
22
+ */
23
+ abstract class Freemius_Abstract {
24
+
25
+ #region Identity ------------------------------------------------------------------
26
+
27
+ /**
28
+ * Check if user registered with Freemius by connecting his account.
29
+ *
30
+ * @since 1.0.1
31
+ * @return bool
32
+ */
33
+ abstract function is_registered();
34
+
35
+ /**
36
+ * Check if the user skipped connecting the account with Freemius.
37
+ *
38
+ * @since 1.0.7
39
+ *
40
+ * @return bool
41
+ */
42
+ abstract function is_anonymous();
43
+
44
+ /**
45
+ * Check if the user currently in activation mode.
46
+ *
47
+ * @since 1.0.7
48
+ *
49
+ * @return bool
50
+ */
51
+ abstract function is_activation_mode();
52
+
53
+ #endregion Identity ------------------------------------------------------------------
54
+
55
+ #region Permissions ------------------------------------------------------------------
56
+
57
+ /**
58
+ * Check if plugin must be WordPress.org compliant.
59
+ *
60
+ * @since 1.0.7
61
+ *
62
+ * @return bool
63
+ */
64
+ abstract function is_org_repo_compliant();
65
+
66
+ /**
67
+ * Check if plugin is allowed to install executable files.
68
+ *
69
+ * @author Vova Feldman (@svovaf)
70
+ * @since 1.0.5
71
+ *
72
+ * @return bool
73
+ */
74
+ function is_allowed_to_install() {
75
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
76
+ }
77
+
78
+ #endregion Permissions ------------------------------------------------------------------
79
+
80
+ /**
81
+ * Check if user in trial or in free plan (not paying).
82
+ *
83
+ * @author Vova Feldman (@svovaf)
84
+ * @since 1.0.4
85
+ *
86
+ * @return bool
87
+ */
88
+ function is_not_paying() {
89
+ return ( $this->is_trial() || $this->is_free_plan() );
90
+ }
91
+
92
+ /**
93
+ * Check if the user has an activated and valid paid license on current plugin's install.
94
+ *
95
+ * @since 1.0.9
96
+ *
97
+ * @return bool
98
+ */
99
+ abstract function is_paying();
100
+
101
+ /**
102
+ * Check if the user is paying or in trial.
103
+ *
104
+ * @since 1.0.9
105
+ *
106
+ * @return bool
107
+ */
108
+ function is_paying_or_trial() {
109
+ return ( $this->is_paying() || $this->is_trial() );
110
+ }
111
+
112
+ /**
113
+ * Check if user in a trial or have feature enabled license.
114
+ *
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.1.7
117
+ *
118
+ * @return bool
119
+ */
120
+ abstract function can_use_premium_code();
121
+
122
+ #region Premium Only ------------------------------------------------------------------
123
+
124
+ /**
125
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
126
+ * included in the premium code.
127
+ *
128
+ * Example:
129
+ * if ( freemius()->is__premium_only() ) {
130
+ * ...
131
+ * }
132
+ */
133
+
134
+ /**
135
+ * Returns true when running premium plugin code.
136
+ *
137
+ * @since 1.0.9
138
+ *
139
+ * @return bool
140
+ */
141
+ function is__premium_only() {
142
+ return $this->is_premium();
143
+ }
144
+
145
+ /**
146
+ * Check if the user has an activated and valid paid license on current plugin's install.
147
+ *
148
+ * @since 1.0.9
149
+ *
150
+ * @return bool
151
+ *
152
+ */
153
+ function is_paying__premium_only() {
154
+ return ( $this->is__premium_only() && $this->is_paying() );
155
+ }
156
+
157
+ /**
158
+ * All code wrapped in this statement will be only included in the premium code.
159
+ *
160
+ * @since 1.0.9
161
+ *
162
+ * @param string $plan Plan name
163
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
164
+ *
165
+ * @return bool
166
+ */
167
+ function is_plan__premium_only( $plan, $exact = false ) {
168
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
169
+ }
170
+
171
+ /**
172
+ * Check if plan matches active license' plan or active trial license' plan.
173
+ *
174
+ * All code wrapped in this statement will be only included in the premium code.
175
+ *
176
+ * @since 1.0.9
177
+ *
178
+ * @param string $plan Plan name
179
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
180
+ *
181
+ * @return bool
182
+ */
183
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
184
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
185
+ }
186
+
187
+ /**
188
+ * Check if the user is paying or in trial.
189
+ *
190
+ * All code wrapped in this statement will be only included in the premium code.
191
+ *
192
+ * @since 1.0.9
193
+ *
194
+ * @return bool
195
+ */
196
+ function is_paying_or_trial__premium_only() {
197
+ return $this->is_premium() && $this->is_paying_or_trial();
198
+ }
199
+
200
+ /**
201
+ * Check if the user has an activated and valid paid license on current plugin's install.
202
+ *
203
+ * @since 1.0.4
204
+ *
205
+ * @return bool
206
+ *
207
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
208
+ * @using Alias to is_paying__premium_only()
209
+ */
210
+ function is_paying__fs__() {
211
+ return $this->is_paying__premium_only();
212
+ }
213
+
214
+ /**
215
+ * Check if user in a trial or have feature enabled license.
216
+ *
217
+ * All code wrapped in this statement will be only included in the premium code.
218
+ *
219
+ * @author Vova Feldman (@svovaf)
220
+ * @since 1.1.9
221
+ *
222
+ * @return bool
223
+ */
224
+ function can_use_premium_code__premium_only() {
225
+ return $this->is_premium() && $this->can_use_premium_code();
226
+ }
227
+
228
+ #endregion Premium Only ------------------------------------------------------------------
229
+
230
+ #region Trial ------------------------------------------------------------------
231
+
232
+ /**
233
+ * Check if the user in a trial.
234
+ *
235
+ * @since 1.0.3
236
+ *
237
+ * @return bool
238
+ */
239
+ abstract function is_trial();
240
+
241
+ /**
242
+ * Check if trial already utilized.
243
+ *
244
+ * @since 1.0.9
245
+ *
246
+ * @return bool
247
+ */
248
+ abstract function is_trial_utilized();
249
+
250
+ #endregion Trial ------------------------------------------------------------------
251
+
252
+ #region Plans ------------------------------------------------------------------
253
+
254
+ /**
255
+ * Check if plugin using the free plan.
256
+ *
257
+ * @since 1.0.4
258
+ *
259
+ * @return bool
260
+ */
261
+ abstract function is_free_plan();
262
+
263
+ /**
264
+ * @since 1.0.2
265
+ *
266
+ * @param string $plan Plan name
267
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
268
+ *
269
+ * @return bool
270
+ */
271
+ abstract function is_plan( $plan, $exact = false );
272
+
273
+ /**
274
+ * Check if plan based on trial. If not in trial mode, should return false.
275
+ *
276
+ * @since 1.0.9
277
+ *
278
+ * @param string $plan Plan name
279
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
280
+ *
281
+ * @return bool
282
+ */
283
+ abstract function is_trial_plan( $plan, $exact = false );
284
+
285
+ /**
286
+ * Check if plan matches active license' plan or active trial license' plan.
287
+ *
288
+ * @since 1.0.9
289
+ *
290
+ * @param string $plan Plan name
291
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
292
+ *
293
+ * @return bool
294
+ */
295
+ function is_plan_or_trial( $plan, $exact = false ) {
296
+ return $this->is_plan( $plan, $exact ) ||
297
+ $this->is_trial_plan( $plan, $exact );
298
+ }
299
+
300
+ /**
301
+ * Check if plugin has any paid plans.
302
+ *
303
+ * @author Vova Feldman (@svovaf)
304
+ * @since 1.0.7
305
+ *
306
+ * @return bool
307
+ */
308
+ abstract function has_paid_plan();
309
+
310
+ /**
311
+ * Check if plugin has any free plan, or is it premium only.
312
+ *
313
+ * Note: If no plans configured, assume plugin is free.
314
+ *
315
+ * @author Vova Feldman (@svovaf)
316
+ * @since 1.0.7
317
+ *
318
+ * @return bool
319
+ */
320
+ abstract function has_free_plan();
321
+
322
+ /**
323
+ * Check if plugin is premium only (no free plans).
324
+ *
325
+ * NOTE: is__premium_only() is very different method, don't get confused.
326
+ *
327
+ * @author Vova Feldman (@svovaf)
328
+ * @since 1.1.9
329
+ *
330
+ * @return bool
331
+ */
332
+ abstract function is_only_premium();
333
+
334
+ /**
335
+ * Checks if it's a freemium plugin.
336
+ *
337
+ * @author Vova Feldman (@svovaf)
338
+ * @since 1.1.9
339
+ *
340
+ * @return bool
341
+ */
342
+ function is_freemium() {
343
+ return ! $this->is_only_premium() &&
344
+ $this->has_paid_plan() &&
345
+ $this->has_free_plan();
346
+ }
347
+
348
+ #endregion Plans ------------------------------------------------------------------
349
+
350
+ /**
351
+ * Check if running payments in sandbox mode.
352
+ *
353
+ * @since 1.0.4
354
+ *
355
+ * @return bool
356
+ */
357
+ abstract function is_payments_sandbox();
358
+
359
+ /**
360
+ * Check if running test vs. live plugin.
361
+ *
362
+ * @since 1.0.5
363
+ *
364
+ * @return bool
365
+ */
366
+ abstract function is_live();
367
+
368
+ /**
369
+ * Check if running premium plugin code.
370
+ *
371
+ * @since 1.0.5
372
+ *
373
+ * @return bool
374
+ */
375
+ abstract function is_premium();
376
+
377
+ /**
378
+ * Get upgrade URL.
379
+ *
380
+ * @author Vova Feldman (@svovaf)
381
+ * @since 1.0.2
382
+ *
383
+ * @param string $period Billing cycle
384
+ *
385
+ * @return string
386
+ */
387
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
388
+
389
+ /**
390
+ * Check if Freemius was first added in a plugin update.
391
+ *
392
+ * @author Vova Feldman (@svovaf)
393
+ * @since 1.1.5
394
+ *
395
+ * @return bool
396
+ */
397
+ function is_plugin_update() {
398
+ return ! $this->is_plugin_new_install();
399
+ }
400
+
401
+ /**
402
+ * Check if Freemius was part of the plugin when the user installed it first.
403
+ *
404
+ * @author Vova Feldman (@svovaf)
405
+ * @since 1.1.5
406
+ *
407
+ * @return bool
408
+ */
409
+ abstract function is_plugin_new_install();
410
+
411
+ #region Marketing ------------------------------------------------------------------
412
+
413
+ /**
414
+ * Check if current user purchased any other plugins before.
415
+ *
416
+ * @author Vova Feldman (@svovaf)
417
+ * @since 1.0.9
418
+ *
419
+ * @return bool
420
+ */
421
+ abstract function has_purchased_before();
422
+
423
+ /**
424
+ * Check if current user classified as an agency.
425
+ *
426
+ * @author Vova Feldman (@svovaf)
427
+ * @since 1.0.9
428
+ *
429
+ * @return bool
430
+ */
431
+ abstract function is_agency();
432
+
433
+ /**
434
+ * Check if current user classified as a developer.
435
+ *
436
+ * @author Vova Feldman (@svovaf)
437
+ * @since 1.0.9
438
+ *
439
+ * @return bool
440
+ */
441
+ abstract function is_developer();
442
+
443
+ /**
444
+ * Check if current user classified as a business.
445
+ *
446
+ * @author Vova Feldman (@svovaf)
447
+ * @since 1.0.9
448
+ *
449
+ * @return bool
450
+ */
451
+ abstract function is_business();
452
+
453
+ #endregion ------------------------------------------------------------------
454
+ }
freemius/includes/class-freemius.php ADDED
@@ -0,0 +1,10148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ // "final class"
13
+ class Freemius extends Freemius_Abstract {
14
+ /**
15
+ * SDK Version
16
+ *
17
+ * @var string
18
+ */
19
+ public $version = WP_FS__SDK_VERSION;
20
+
21
+ #region Plugin Info
22
+
23
+ /**
24
+ * @since 1.0.1
25
+ *
26
+ * @var string
27
+ */
28
+ private $_slug;
29
+
30
+ /**
31
+ * @since 1.0.0
32
+ *
33
+ * @var string
34
+ */
35
+ private $_plugin_basename;
36
+ /**
37
+ * @since 1.0.0
38
+ *
39
+ * @var string
40
+ */
41
+ private $_free_plugin_basename;
42
+ /**
43
+ * @since 1.0.0
44
+ *
45
+ * @var string
46
+ */
47
+ private $_plugin_dir_path;
48
+ /**
49
+ * @since 1.0.0
50
+ *
51
+ * @var string
52
+ */
53
+ private $_plugin_dir_name;
54
+ /**
55
+ * @since 1.0.0
56
+ *
57
+ * @var string
58
+ */
59
+ private $_plugin_main_file_path;
60
+ /**
61
+ * @var string[]
62
+ */
63
+ private $_plugin_data;
64
+ /**
65
+ * @since 1.0.9
66
+ *
67
+ * @var string
68
+ */
69
+ private $_plugin_name;
70
+
71
+ #endregion Plugin Info
72
+
73
+ /**
74
+ * @since 1.0.9
75
+ *
76
+ * @var bool If false, don't turn Freemius on.
77
+ */
78
+ private $_is_on;
79
+
80
+ /**
81
+ * @since 1.1.3
82
+ *
83
+ * @var bool If false, don't turn Freemius on.
84
+ */
85
+ private $_is_anonymous;
86
+
87
+ /**
88
+ * @since 1.0.9
89
+ * @var bool If false, issues with connectivity to Freemius API.
90
+ */
91
+ private $_has_api_connection;
92
+
93
+ /**
94
+ * @since 1.0.9
95
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
96
+ */
97
+ private $_enable_anonymous;
98
+
99
+ /**
100
+ * @since 1.1.7.5
101
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
102
+ */
103
+ private $_anonymous_mode;
104
+
105
+ /**
106
+ * @since 1.1.9
107
+ * @var bool Hints the SDK if plugin have any free plans.
108
+ */
109
+ private $_is_premium_only;
110
+
111
+ /**
112
+ * @since 1.0.8
113
+ * @var bool Hints the SDK if the plugin has any paid plans.
114
+ */
115
+ private $_has_paid_plans;
116
+
117
+ /**
118
+ * @since 1.0.7
119
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
120
+ */
121
+ private $_is_org_compliant;
122
+
123
+ /**
124
+ * @since 1.0.7
125
+ * @var bool Hints the SDK if the plugin is has add-ons.
126
+ */
127
+ private $_has_addons;
128
+
129
+ /**
130
+ * @since 1.1.6
131
+ * @var string[]bool.
132
+ */
133
+ private $_permissions;
134
+
135
+ /**
136
+ * @var FS_Key_Value_Storage
137
+ */
138
+ private $_storage;
139
+
140
+ /**
141
+ * @since 1.0.0
142
+ *
143
+ * @var FS_Logger
144
+ */
145
+ private $_logger;
146
+ /**
147
+ * @since 1.0.4
148
+ *
149
+ * @var FS_Plugin
150
+ */
151
+ private $_plugin = false;
152
+ /**
153
+ * @since 1.0.4
154
+ *
155
+ * @var FS_Plugin|false
156
+ */
157
+ private $_parent_plugin = false;
158
+ /**
159
+ * @since 1.1.1
160
+ *
161
+ * @var Freemius
162
+ */
163
+ private $_parent = false;
164
+ /**
165
+ * @since 1.0.1
166
+ *
167
+ * @var FS_User
168
+ */
169
+ private $_user = false;
170
+ /**
171
+ * @since 1.0.1
172
+ *
173
+ * @var FS_Site
174
+ */
175
+ private $_site = false;
176
+ /**
177
+ * @since 1.0.1
178
+ *
179
+ * @var FS_Plugin_License
180
+ */
181
+ private $_license;
182
+ /**
183
+ * @since 1.0.2
184
+ *
185
+ * @var FS_Plugin_Plan[]
186
+ */
187
+ private $_plans = false;
188
+ /**
189
+ * @var FS_Plugin_License[]
190
+ * @since 1.0.5
191
+ */
192
+ private $_licenses = false;
193
+
194
+ /**
195
+ * @since 1.0.1
196
+ *
197
+ * @var FS_Admin_Menu_Manager
198
+ */
199
+ private $_menu;
200
+
201
+ /**
202
+ * @var FS_Admin_Notice_Manager
203
+ */
204
+ private $_admin_notices;
205
+
206
+ /**
207
+ * @since 1.1.6
208
+ *
209
+ * @var FS_Admin_Notice_Manager
210
+ */
211
+ private static $_global_admin_notices;
212
+
213
+ /**
214
+ * @var FS_Logger
215
+ * @since 1.0.0
216
+ */
217
+ private static $_static_logger;
218
+
219
+ /**
220
+ * @var FS_Option_Manager
221
+ * @since 1.0.2
222
+ */
223
+ private static $_accounts;
224
+
225
+ /**
226
+ * @var Freemius[]
227
+ */
228
+ private static $_instances = array();
229
+
230
+
231
+ /* Ctor
232
+ ------------------------------------------------------------------------------------------------------------------*/
233
+
234
+ private function __construct( $slug ) {
235
+ $this->_slug = $slug;
236
+
237
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
238
+
239
+ $this->_storage = FS_Key_Value_Storage::instance( 'plugin_data', $this->_slug );
240
+
241
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file();
242
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
243
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
244
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
245
+
246
+ $base_name_split = explode( '/', $this->_plugin_basename );
247
+ $this->_plugin_dir_name = $base_name_split[0];
248
+
249
+ if ( $this->_logger->is_on() ) {
250
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
251
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
252
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
253
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
254
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
255
+ }
256
+
257
+ // Remember link between file to slug.
258
+ $this->store_file_slug_map();
259
+
260
+ // Store plugin's initial install timestamp.
261
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
262
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
263
+ }
264
+
265
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->get();
266
+
267
+ $this->_admin_notices = FS_Admin_Notice_Manager::instance(
268
+ $slug,
269
+ is_object( $this->_plugin ) ? $this->_plugin->title : ''
270
+ );
271
+
272
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
273
+ 'true' === fs_request_is_action( 'restart_freemius' )
274
+ ) {
275
+ FS_Api::clear_cache();
276
+ }
277
+
278
+ $this->_register_hooks();
279
+
280
+ $this->_load_account();
281
+
282
+ $this->_version_updates_handler();
283
+ }
284
+
285
+ /**
286
+ * @author Vova Feldman (@svovaf)
287
+ * @since 1.0.9
288
+ */
289
+ private function _version_updates_handler() {
290
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
291
+ // Freemius version upgrade mode.
292
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
293
+ $this->_storage->sdk_version = $this->version;
294
+
295
+ if ( empty( $this->_storage->sdk_last_version ) ||
296
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
297
+ ) {
298
+ $this->_storage->sdk_upgrade_mode = true;
299
+ $this->_storage->sdk_downgrade_mode = false;
300
+ } else {
301
+ $this->_storage->sdk_downgrade_mode = true;
302
+ $this->_storage->sdk_upgrade_mode = false;
303
+
304
+ }
305
+
306
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
307
+ }
308
+
309
+ $plugin_version = $this->get_plugin_version();
310
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
311
+ // Plugin version upgrade mode.
312
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
313
+ $this->_storage->plugin_version = $plugin_version;
314
+
315
+ if ( empty( $this->_storage->plugin_last_version ) ||
316
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
317
+ ) {
318
+ $this->_storage->plugin_upgrade_mode = true;
319
+ $this->_storage->plugin_downgrade_mode = false;
320
+ } else {
321
+ $this->_storage->plugin_downgrade_mode = true;
322
+ $this->_storage->plugin_upgrade_mode = false;
323
+ }
324
+
325
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
326
+ // Different version of the plugin was installed before, therefore it's an update.
327
+ $this->_storage->is_plugin_new_install = false;
328
+ }
329
+
330
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
331
+ }
332
+ }
333
+
334
+ /**
335
+ * @author Vova Feldman (@svovaf)
336
+ * @since 1.1.5
337
+ *
338
+ * @param string $sdk_prev_version
339
+ * @param string $sdk_version
340
+ */
341
+ function _data_migration( $sdk_prev_version, $sdk_version ) {
342
+ /**
343
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
344
+ */
345
+ if ( empty( $sdk_prev_version ) ) {
346
+ return;
347
+ }
348
+
349
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
350
+ version_compare( $sdk_version, '1.1.5', '>=' )
351
+ ) {
352
+ // On version 1.1.5 merged connectivity and is_on data.
353
+ if ( isset( $this->_storage->connectivity_test ) ) {
354
+ if ( ! isset( $this->_storage->is_on ) ) {
355
+ unset( $this->_storage->connectivity_test );
356
+ } else {
357
+ $connectivity_data = $this->_storage->connectivity_test;
358
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
359
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
360
+
361
+ // Override.
362
+ $this->_storage->connectivity_test = $connectivity_data;
363
+
364
+ // Remove previous structure.
365
+ unset( $this->_storage->is_on );
366
+ }
367
+
368
+ }
369
+ }
370
+ }
371
+
372
+ /**
373
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
374
+ * if this is a new plugin installation or a plugin update.
375
+ *
376
+ * There are 3 different use-cases:
377
+ * 1) New plugin installation right with Freemius:
378
+ * 1.1 _activate_plugin_event_hook() will be executed first
379
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
380
+ * and $this->_storage->plugin_last_version is not set,
381
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
382
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
383
+ * be already set to TRUE.
384
+ *
385
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
386
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
387
+ * the activation hook do NOT fires on updates since WP 3.1.
388
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
389
+ * be empty, therefore, it will be set to FALSE.
390
+ *
391
+ * 3) Plugin update, had Freemius in prev version as well:
392
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
393
+ * before, $this->_storage->plugin_last_version will NOT be empty,
394
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
395
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
396
+ * already set, therefore, it will not be modified.
397
+ *
398
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
399
+ *
400
+ * NOTE:
401
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
402
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
403
+ * show the opt-in right away. The reason it will happen is because Freemius execution
404
+ * will be turned off till the plugin is fully loaded at least once
405
+ * (till $this->_storage->was_plugin_loaded is TRUE).
406
+ *
407
+ * @author Vova Feldman (@svovaf)
408
+ * @since 1.1.9
409
+ *
410
+ */
411
+ function _plugins_loaded() {
412
+ // Update flag that plugin was loaded with Freemius at least once.
413
+ $this->_storage->was_plugin_loaded = true;
414
+
415
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
416
+ $this->_storage->is_plugin_new_install = false;
417
+ }
418
+ }
419
+
420
+ /**
421
+ * @author Vova Feldman (@svovaf)
422
+ * @since 1.0.9
423
+ */
424
+ private function _register_hooks() {
425
+ if ( is_admin() ) {
426
+ // Hook to plugin activation
427
+ register_activation_hook( $this->_plugin_main_file_path, array(
428
+ &$this,
429
+ '_activate_plugin_event_hook'
430
+ ) );
431
+
432
+ /**
433
+ * Part of the mechanism to identify new plugin install vs. plugin update.
434
+ *
435
+ * @author Vova Feldman (@svovaf)
436
+ * @since 1.1.9
437
+ */
438
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
439
+ if ( $this->is_activation_mode( false ) ) {
440
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
441
+ } else {
442
+ // If was activated before, then it was already loaded before.
443
+ $this->_plugins_loaded();
444
+ }
445
+ }
446
+
447
+ if ( ! $this->is_ajax() ) {
448
+ if ( ! $this->is_addon() ) {
449
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
450
+ add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
451
+ }
452
+ }
453
+ }
454
+
455
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
456
+
457
+ add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
458
+
459
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
460
+
461
+ $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
462
+ }
463
+
464
+ /**
465
+ * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
466
+ * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
467
+ * plugin will trigger inclusion of the free or premium version and if one of them is active during the
468
+ * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
469
+ *
470
+ * @author Leo Fajardo (leorw)
471
+ *
472
+ * @since 1.2.0
473
+ */
474
+ private function unregister_uninstall_hook() {
475
+ $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
476
+ unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
477
+ unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
478
+
479
+ update_option( 'uninstall_plugins', $uninstallable_plugins );
480
+ }
481
+
482
+ /**
483
+ * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
484
+ */
485
+ private function clear_module_main_file_cache() {
486
+ unset( $this->_storage->plugin_main_file );
487
+ }
488
+
489
+ /**
490
+ * @author Vova Feldman (@svovaf)
491
+ * @since 1.0.9
492
+ */
493
+ private function _register_account_hooks() {
494
+ if ( is_admin() ) {
495
+ if ( ! $this->is_ajax() ) {
496
+ if ( $this->apply_filters( 'show_trial', true ) && $this->has_trial_plan() ) {
497
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
498
+ if ( ! $this->_site->is_trial_utilized() &&
499
+ (
500
+ // Show promotion if never shown it yet and 24 hours after initial activation.
501
+ ( false === $last_time_trial_promotion_shown && $this->_storage->activation_timestamp < ( time() - WP_FS__TIME_24_HOURS_IN_SEC ) ) ||
502
+ // Show promotion in every 30 days.
503
+ ( is_numeric( $last_time_trial_promotion_shown ) && 30 * WP_FS__TIME_24_HOURS_IN_SEC < time() - $last_time_trial_promotion_shown ) )
504
+ ) {
505
+ $this->add_action( 'after_init_plugin_registered', array( &$this, '_add_trial_notice' ) );
506
+ }
507
+ }
508
+ }
509
+
510
+ // If user is paying or in trial and have the free version installed,
511
+ // assume that the deactivation is for the upgrade process.
512
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
513
+ add_action( 'wp_ajax_submit-uninstall-reason', array( &$this, '_submit_uninstall_reason_action' ) );
514
+
515
+ global $pagenow;
516
+ if ( 'plugins.php' === $pagenow ) {
517
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
518
+ }
519
+ }
520
+
521
+ if ( ! $this->is_addon() ) {
522
+ if ( $this->is_registered() ) {
523
+ $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
524
+ }
525
+ }
526
+ }
527
+ }
528
+
529
+ /**
530
+ * Leverage backtrace to find caller plugin file path.
531
+ *
532
+ * @author Vova Feldman (@svovaf)
533
+ * @since 1.0.6
534
+ *
535
+ * @return string
536
+ *
537
+ * @uses fs_find_caller_plugin_file
538
+ */
539
+ private function _find_caller_plugin_file() {
540
+ // Try to load the cached value of the file path.
541
+ if ( isset( $this->_storage->plugin_main_file ) ) {
542
+ if ( file_exists( $this->_storage->plugin_main_file->path ) ) {
543
+ return $this->_storage->plugin_main_file->path;
544
+ }
545
+ }
546
+
547
+ $plugin_file = fs_find_caller_plugin_file();
548
+
549
+ $this->_storage->plugin_main_file = (object) array(
550
+ 'path' => fs_normalize_path( $plugin_file ),
551
+ );
552
+
553
+ return $plugin_file;
554
+ }
555
+
556
+
557
+ #region Deactivation Feedback Form ------------------------------------------------------------------
558
+
559
+ /**
560
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
561
+ * page.
562
+ *
563
+ * @author Vova Feldman (@svovaf)
564
+ * @author Leo Fajardo (@leorw)
565
+ * @since 1.1.2
566
+ */
567
+ function _add_deactivation_feedback_dialog_box() {
568
+ /* Check the type of user:
569
+ * 1. Long-term (long-term)
570
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
571
+ * 3. Short-term (short-term)
572
+ */
573
+ $is_long_term_user = true;
574
+
575
+ // Check if the site is at least 2 days old.
576
+ $time_installed = $this->_storage->install_timestamp;
577
+
578
+ // Difference in seconds.
579
+ $date_diff = time() - $time_installed;
580
+
581
+ // Convert seconds to days.
582
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
583
+
584
+ if ( $date_diff_days < 2 ) {
585
+ $is_long_term_user = false;
586
+ }
587
+
588
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
589
+
590
+ if ( $is_long_term_user ) {
591
+ $user_type = 'long-term';
592
+ } else {
593
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
594
+ $user_type = 'non-registered-and-non-anonymous-short-term';
595
+ } else {
596
+ $user_type = 'short-term';
597
+ }
598
+ }
599
+
600
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
601
+
602
+ // Load the HTML template for the deactivation feedback dialog box.
603
+ $vars = array(
604
+ 'reasons' => $uninstall_reasons,
605
+ 'slug' => $this->_slug
606
+ );
607
+
608
+ /**
609
+ * @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.
610
+ */
611
+ fs_require_template( 'forms/deactivation/form.php', $vars );
612
+ }
613
+
614
+ /**
615
+ * @author Leo Fajardo (leorw)
616
+ * @since 1.1.2
617
+ *
618
+ * @param string $user_type
619
+ *
620
+ * @return array The uninstall reasons for the specified user type.
621
+ */
622
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
623
+ $internal_message_template_var = array(
624
+ 'slug' => $this->_slug
625
+ );
626
+
627
+ if ( $this->is_registered() && false !== $this->get_plan() && $this->get_plan()->has_technical_support() ) {
628
+ $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
629
+ } else {
630
+ $contact_support_template = '';
631
+ }
632
+
633
+ $reason_found_better_plugin = array(
634
+ 'id' => 2,
635
+ 'text' => __fs( 'reason-found-a-better-plugin', $this->_slug ),
636
+ 'input_type' => 'textfield',
637
+ 'input_placeholder' => __fs( 'placeholder-plugin-name', $this->_slug )
638
+ );
639
+
640
+ $reason_temporary_deactivation = array(
641
+ 'id' => 15,
642
+ 'text' => __fs( 'reason-temporary-deactivation', $this->_slug ),
643
+ 'input_type' => '',
644
+ 'input_placeholder' => ''
645
+ );
646
+
647
+ $reason_other = array(
648
+ 'id' => 7,
649
+ 'text' => __fs( 'reason-other', $this->_slug ),
650
+ 'input_type' => 'textfield',
651
+ 'input_placeholder' => ''
652
+ );
653
+
654
+ $long_term_user_reasons = array(
655
+ array(
656
+ 'id' => 1,
657
+ 'text' => __fs( 'reason-no-longer-needed', $this->_slug ),
658
+ 'input_type' => '',
659
+ 'input_placeholder' => ''
660
+ ),
661
+ $reason_found_better_plugin,
662
+ array(
663
+ 'id' => 3,
664
+ 'text' => __fs( 'reason-needed-for-a-short-period', $this->_slug ),
665
+ 'input_type' => '',
666
+ 'input_placeholder' => ''
667
+ ),
668
+ array(
669
+ 'id' => 4,
670
+ 'text' => __fs( 'reason-broke-my-site', $this->_slug ),
671
+ 'input_type' => '',
672
+ 'input_placeholder' => '',
673
+ 'internal_message' => $contact_support_template
674
+ ),
675
+ array(
676
+ 'id' => 5,
677
+ 'text' => __fs( 'reason-suddenly-stopped-working', $this->_slug ),
678
+ 'input_type' => '',
679
+ 'input_placeholder' => '',
680
+ 'internal_message' => $contact_support_template
681
+ )
682
+ );
683
+
684
+ if ( $this->is_paying() ) {
685
+ $long_term_user_reasons[] = array(
686
+ 'id' => 6,
687
+ 'text' => __fs( 'reason-cant-pay-anymore', $this->_slug ),
688
+ 'input_type' => 'textfield',
689
+ 'input_placeholder' => __fs( 'placeholder-comfortable-price', $this->_slug )
690
+ );
691
+ }
692
+
693
+ $reason_dont_share_info = array(
694
+ 'id' => 9,
695
+ 'text' => __fs( 'reason-dont-like-to-share-my-information', $this->_slug ),
696
+ 'input_type' => '',
697
+ 'input_placeholder' => ''
698
+ );
699
+
700
+ /**
701
+ * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
702
+ * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
703
+ * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
704
+ * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
705
+ * button in the opt-in form is shown/hidden).
706
+ */
707
+ if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
708
+ $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
709
+ }
710
+
711
+ $long_term_user_reasons[] = $reason_temporary_deactivation;
712
+ $long_term_user_reasons[] = $reason_other;
713
+
714
+ $uninstall_reasons = array(
715
+ 'long-term' => $long_term_user_reasons,
716
+ 'non-registered-and-non-anonymous-short-term' => array(
717
+ array(
718
+ 'id' => 8,
719
+ 'text' => __fs( 'reason-didnt-work', $this->_slug ),
720
+ 'input_type' => '',
721
+ 'input_placeholder' => ''
722
+ ),
723
+ $reason_dont_share_info,
724
+ $reason_found_better_plugin,
725
+ $reason_temporary_deactivation,
726
+ $reason_other
727
+ ),
728
+ 'short-term' => array(
729
+ array(
730
+ 'id' => 10,
731
+ 'text' => __fs( 'reason-couldnt-make-it-work', $this->_slug ),
732
+ 'input_type' => '',
733
+ 'input_placeholder' => '',
734
+ 'internal_message' => $contact_support_template
735
+ ),
736
+ $reason_found_better_plugin,
737
+ array(
738
+ 'id' => 11,
739
+ 'text' => __fs( 'reason-great-but-need-specific-feature', $this->_slug ),
740
+ 'input_type' => 'textarea',
741
+ 'input_placeholder' => __fs( 'placeholder-feature', $this->_slug )
742
+ ),
743
+ array(
744
+ 'id' => 12,
745
+ 'text' => __fs( 'reason-not-working', $this->_slug ),
746
+ 'input_type' => 'textarea',
747
+ 'input_placeholder' => __fs( 'placeholder-share-what-didnt-work', $this->_slug )
748
+ ),
749
+ array(
750
+ 'id' => 13,
751
+ 'text' => __fs( 'reason-not-what-i-was-looking-for', $this->_slug ),
752
+ 'input_type' => 'textarea',
753
+ 'input_placeholder' => __fs( 'placeholder-what-youve-been-looking-for', $this->_slug )
754
+ ),
755
+ array(
756
+ 'id' => 14,
757
+ 'text' => __fs( 'reason-didnt-work-as-expected', $this->_slug ),
758
+ 'input_type' => 'textarea',
759
+ 'input_placeholder' => __fs( 'placeholder-what-did-you-expect', $this->_slug )
760
+ ),
761
+ $reason_temporary_deactivation,
762
+ $reason_other
763
+ )
764
+ );
765
+
766
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
767
+
768
+ return $uninstall_reasons[ $user_type ];
769
+ }
770
+
771
+ /**
772
+ * Called after the user has submitted his reason for deactivating the plugin.
773
+ *
774
+ * @author Leo Fajardo (@leorw)
775
+ * @since 1.1.2
776
+ */
777
+ function _submit_uninstall_reason_action() {
778
+ if ( ! isset( $_POST['reason_id'] ) ) {
779
+ exit;
780
+ }
781
+
782
+ $reason_info = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '';
783
+
784
+ $reason = (object) array(
785
+ 'id' => $_POST['reason_id'],
786
+ 'info' => substr( $reason_info, 0, 128 )
787
+ );
788
+
789
+ $this->_storage->store( 'uninstall_reason', $reason );
790
+
791
+ // Print '1' for successful operation.
792
+ echo 1;
793
+ exit;
794
+ }
795
+
796
+ #endregion Deactivation Feedback Form ------------------------------------------------------------------
797
+
798
+ #region Instance ------------------------------------------------------------------
799
+
800
+ /**
801
+ * Main singleton instance.
802
+ *
803
+ * @author Vova Feldman (@svovaf)
804
+ * @since 1.0.0
805
+ *
806
+ * @param $slug
807
+ *
808
+ * @return Freemius
809
+ */
810
+ static function instance( $slug ) {
811
+ $slug = strtolower( $slug );
812
+
813
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
814
+ if ( 0 === count( self::$_instances ) ) {
815
+ self::_load_required_static();
816
+ }
817
+
818
+ self::$_instances[ $slug ] = new Freemius( $slug );
819
+ }
820
+
821
+ return self::$_instances[ $slug ];
822
+ }
823
+
824
+ /**
825
+ * @author Vova Feldman (@svovaf)
826
+ * @since 1.0.6
827
+ *
828
+ * @param string|number $slug_or_id
829
+ *
830
+ * @return bool
831
+ */
832
+ private static function has_instance( $slug_or_id ) {
833
+ return ! is_numeric( $slug_or_id ) ?
834
+ isset( self::$_instances[ strtolower( $slug_or_id ) ] ) :
835
+ ( false !== self::get_instance_by_id( $slug_or_id ) );
836
+ }
837
+
838
+ /**
839
+ * @author Vova Feldman (@svovaf)
840
+ * @since 1.0.6
841
+ *
842
+ * @param $id
843
+ *
844
+ * @return false|Freemius
845
+ */
846
+ static function get_instance_by_id( $id ) {
847
+ foreach ( self::$_instances as $slug => $instance ) {
848
+ if ( $id == $instance->get_id() ) {
849
+ return $instance;
850
+ }
851
+ }
852
+
853
+ return false;
854
+ }
855
+
856
+ /**
857
+ *
858
+ * @author Vova Feldman (@svovaf)
859
+ * @since 1.0.1
860
+ *
861
+ * @param $plugin_file
862
+ *
863
+ * @return false|Freemius
864
+ */
865
+ static function get_instance_by_file( $plugin_file ) {
866
+ $slug = self::find_slug_by_basename( $plugin_file );
867
+
868
+ return ( false !== $slug ) ?
869
+ self::instance( $slug ) :
870
+ false;
871
+ }
872
+
873
+ /**
874
+ * @author Vova Feldman (@svovaf)
875
+ * @since 1.0.6
876
+ *
877
+ * @return false|Freemius
878
+ */
879
+ function get_parent_instance() {
880
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
881
+ }
882
+
883
+ /**
884
+ * @author Vova Feldman (@svovaf)
885
+ * @since 1.0.6
886
+ *
887
+ * @param $slug_or_id
888
+ *
889
+ * @return bool|Freemius
890
+ */
891
+ function get_addon_instance( $slug_or_id ) {
892
+ return ! is_numeric( $slug_or_id ) ?
893
+ self::instance( strtolower( $slug_or_id ) ) :
894
+ self::get_instance_by_id( $slug_or_id );
895
+ }
896
+
897
+ #endregion ------------------------------------------------------------------
898
+
899
+ /**
900
+ * @author Vova Feldman (@svovaf)
901
+ * @since 1.0.6
902
+ *
903
+ * @return bool
904
+ */
905
+ function is_parent_plugin_installed() {
906
+ return self::has_instance( $this->_plugin->parent_plugin_id );
907
+ }
908
+
909
+ /**
910
+ * Check if add-on parent plugin in activation mode.
911
+ *
912
+ * @author Vova Feldman (@svovaf)
913
+ * @since 1.0.7
914
+ *
915
+ * @return bool
916
+ */
917
+ function is_parent_in_activation() {
918
+ $parent_fs = $this->get_parent_instance();
919
+ if ( ! is_object( $parent_fs ) ) {
920
+ return false;
921
+ }
922
+
923
+ return ( $parent_fs->is_activation_mode() );
924
+ }
925
+
926
+ /**
927
+ * Is plugin in activation mode.
928
+ *
929
+ * @author Vova Feldman (@svovaf)
930
+ * @since 1.0.7
931
+ *
932
+ * @param bool $and_on
933
+ *
934
+ * @return bool
935
+ */
936
+ function is_activation_mode( $and_on = true ) {
937
+ return (
938
+ ( $this->is_on() || ! $and_on ) &&
939
+ ! $this->is_registered() &&
940
+ ( ! $this->is_enable_anonymous() ||
941
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
942
+ );
943
+ }
944
+
945
+ /**
946
+ * Get collection of all active plugins.
947
+ *
948
+ * @author Vova Feldman (@svovaf)
949
+ * @since 1.0.9
950
+ *
951
+ * @return array[string]array
952
+ */
953
+ private static function get_active_plugins() {
954
+ self::require_plugin_essentials();
955
+
956
+ $active_plugin = array();
957
+ $all_plugins = get_plugins();
958
+ $active_plugins_basenames = get_option( 'active_plugins' );
959
+
960
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
961
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
962
+ }
963
+
964
+ return $active_plugin;
965
+ }
966
+
967
+ /**
968
+ * Get collection of all plugins.
969
+ *
970
+ * @author Vova Feldman (@svovaf)
971
+ * @since 1.1.8
972
+ *
973
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
974
+ */
975
+ private static function get_all_plugins() {
976
+ self::require_plugin_essentials();
977
+
978
+ $all_plugins = get_plugins();
979
+ $active_plugins_basenames = get_option( 'active_plugins' );
980
+
981
+ foreach ( $all_plugins as $basename => &$data ) {
982
+ // By default set to inactive (next foreach update the active plugins).
983
+ $data['is_active'] = false;
984
+ // Enrich with plugin slug.
985
+ $data['slug'] = self::get_plugin_slug( $basename );
986
+ }
987
+
988
+ // Flag active plugins.
989
+ foreach ( $active_plugins_basenames as $basename ) {
990
+ if ( isset( $all_plugins[ $basename ] ) ) {
991
+ $all_plugins[ $basename ]['is_active'] = true;
992
+ }
993
+ }
994
+
995
+ return $all_plugins;
996
+ }
997
+
998
+
999
+ /**
1000
+ * Cached result of get_site_transient( 'update_plugins' )
1001
+ *
1002
+ * @author Vova Feldman (@svovaf)
1003
+ * @since 1.1.8
1004
+ *
1005
+ * @var object
1006
+ */
1007
+ private static $_plugins_info;
1008
+
1009
+ /**
1010
+ * Helper function to get specified plugin's slug.
1011
+ *
1012
+ * @author Vova Feldman (@svovaf)
1013
+ * @since 1.1.8
1014
+ *
1015
+ * @param $basename
1016
+ *
1017
+ * @return string
1018
+ */
1019
+ private static function get_plugin_slug( $basename ) {
1020
+ if ( ! isset( self::$_plugins_info ) ) {
1021
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
1022
+ }
1023
+
1024
+ $slug = '';
1025
+
1026
+ if ( is_object( self::$_plugins_info ) ) {
1027
+ if ( isset( self::$_plugins_info->no_update ) &&
1028
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
1029
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
1030
+ ) {
1031
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
1032
+ } else if ( isset( self::$_plugins_info->response ) &&
1033
+ isset( self::$_plugins_info->response[ $basename ] ) &&
1034
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
1035
+ ) {
1036
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
1037
+ }
1038
+ }
1039
+
1040
+ if ( empty( $slug ) ) {
1041
+ // Try to find slug from FS data.
1042
+ $slug = self::find_slug_by_basename( $basename );
1043
+ }
1044
+
1045
+ if ( empty( $slug ) ) {
1046
+ // Fallback to plugin's folder name.
1047
+ $slug = dirname( $basename );
1048
+ }
1049
+
1050
+ return $slug;
1051
+ }
1052
+
1053
+ private static $_statics_loaded = false;
1054
+
1055
+ /**
1056
+ * Load static resources.
1057
+ *
1058
+ * @author Vova Feldman (@svovaf)
1059
+ * @since 1.0.1
1060
+ */
1061
+ private static function _load_required_static() {
1062
+ if ( self::$_statics_loaded ) {
1063
+ return;
1064
+ }
1065
+
1066
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
1067
+
1068
+ self::$_static_logger->entrance();
1069
+
1070
+ self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
1071
+
1072
+ self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
1073
+
1074
+ // Configure which Freemius powered plugins should be auto updated.
1075
+ // add_filter( 'auto_update_plugin', '_include_plugins_in_auto_update', 10, 2 );
1076
+
1077
+ add_action( 'admin_menu', array( 'Freemius', 'add_debug_page' ) );
1078
+
1079
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
1080
+
1081
+ self::$_statics_loaded = true;
1082
+ }
1083
+
1084
+ #region Debugging ------------------------------------------------------------------
1085
+
1086
+ /**
1087
+ * @author Vova Feldman (@svovaf)
1088
+ * @since 1.0.8
1089
+ */
1090
+ static function add_debug_page() {
1091
+ if ( ! current_user_can( 'activate_plugins' ) ) {
1092
+ return;
1093
+ }
1094
+
1095
+ self::$_static_logger->entrance();
1096
+
1097
+ $title = sprintf( '%s [v.%s]', __fs( 'freemius-debug' ), WP_FS__SDK_VERSION );
1098
+
1099
+ if ( WP_FS__DEV_MODE ) {
1100
+ // Add top-level debug menu item.
1101
+ $hook = add_menu_page(
1102
+ $title,
1103
+ $title,
1104
+ 'manage_options',
1105
+ 'freemius',
1106
+ array( 'Freemius', '_debug_page_render' )
1107
+ );
1108
+ } else {
1109
+ // Add hidden debug page.
1110
+ $hook = add_submenu_page(
1111
+ null,
1112
+ $title,
1113
+ $title,
1114
+ 'manage_options',
1115
+ 'freemius',
1116
+ array( 'Freemius', '_debug_page_render' )
1117
+ );
1118
+ }
1119
+
1120
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
1121
+ }
1122
+
1123
+ /**
1124
+ * @author Vova Feldman (@svovaf)
1125
+ * @since 1.1.7.3
1126
+ */
1127
+ static function _toggle_debug_mode() {
1128
+ if ( in_array( $_POST['is_on'], array( 0, 1 ) ) ) {
1129
+ update_option( 'fs_debug_mode', $_POST['is_on'] );
1130
+ }
1131
+
1132
+ exit;
1133
+ }
1134
+
1135
+ /**
1136
+ * @author Vova Feldman (@svovaf)
1137
+ * @since 1.0.8
1138
+ */
1139
+ static function _debug_page_actions() {
1140
+ self::_clean_admin_content_section();
1141
+
1142
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
1143
+ check_admin_referer( 'restart_freemius' );
1144
+
1145
+ self::$_accounts->clear( true );
1146
+
1147
+
1148
+ return;
1149
+ }
1150
+ }
1151
+
1152
+ /**
1153
+ * @author Vova Feldman (@svovaf)
1154
+ * @since 1.0.8
1155
+ */
1156
+ static function _debug_page_render() {
1157
+ self::$_static_logger->entrance();
1158
+
1159
+ $sites = self::get_all_sites();
1160
+ $users = self::get_all_users();
1161
+ $addons = self::get_all_addons();
1162
+ $account_addons = self::get_all_account_addons();
1163
+ $licenses = self::get_all_licenses();
1164
+
1165
+ // $plans = self::get_all_plans();
1166
+ // $licenses = self::get_all_licenses();
1167
+
1168
+ $vars = array(
1169
+ 'sites' => $sites,
1170
+ 'users' => $users,
1171
+ 'addons' => $addons,
1172
+ 'account_addons' => $account_addons,
1173
+ 'licenses' => $licenses,
1174
+ );
1175
+
1176
+ fs_enqueue_local_style( 'fs_account', '/admin/debug.css' );
1177
+ fs_require_once_template( 'debug.php', $vars );
1178
+ }
1179
+
1180
+ #endregion ------------------------------------------------------------------
1181
+
1182
+ #region Connectivity Issues ------------------------------------------------------------------
1183
+
1184
+ /**
1185
+ * Check if Freemius should be turned on for the current plugin install.
1186
+ *
1187
+ * Note:
1188
+ * $this->_is_on is updated in has_api_connectivity()
1189
+ *
1190
+ * @author Vova Feldman (@svovaf)
1191
+ * @since 1.0.9
1192
+ *
1193
+ * @return bool
1194
+ */
1195
+ function is_on() {
1196
+ self::$_static_logger->entrance();
1197
+
1198
+ if ( isset( $this->_is_on ) ) {
1199
+ return $this->_is_on;
1200
+ }
1201
+
1202
+ // If already installed or pending then sure it's on :)
1203
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
1204
+ $this->_is_on = true;
1205
+
1206
+ return true;
1207
+ }
1208
+
1209
+ return false;
1210
+ }
1211
+
1212
+ /**
1213
+ * @author Vova Feldman (@svovaf)
1214
+ * @since 1.1.7.3
1215
+ *
1216
+ * @param bool $flush_if_no_connectivity
1217
+ *
1218
+ * @return bool
1219
+ */
1220
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
1221
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
1222
+ // Connectivity test was never executed, or cache was cleared.
1223
+ return true;
1224
+ }
1225
+
1226
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
1227
+ if ( WP_FS__IS_HTTP_REQUEST ) {
1228
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
1229
+ // Domain changed.
1230
+ return true;
1231
+ }
1232
+
1233
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
1234
+ // Server IP changed.
1235
+ return true;
1236
+ }
1237
+ }
1238
+ }
1239
+
1240
+ if ( $this->_storage->connectivity_test['is_connected'] &&
1241
+ $this->_storage->connectivity_test['is_active']
1242
+ ) {
1243
+ // API connected and Freemius is active - no need to run connectivity check.
1244
+ return false;
1245
+ }
1246
+
1247
+ if ( $flush_if_no_connectivity ) {
1248
+ /**
1249
+ * If explicitly asked to flush when no connectivity - do it only
1250
+ * if at least 10 sec passed from the last API connectivity test.
1251
+ */
1252
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
1253
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
1254
+ }
1255
+
1256
+ /**
1257
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
1258
+ */
1259
+ $version = $this->get_plugin_version();
1260
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
1261
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
1262
+ return true;
1263
+ }
1264
+
1265
+ return false;
1266
+ }
1267
+
1268
+ /**
1269
+ * @author Vova Feldman (@svovaf)
1270
+ * @since 1.1.7.4
1271
+ *
1272
+ * @return object|false
1273
+ */
1274
+ private function ping() {
1275
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
1276
+ return false;
1277
+ }
1278
+
1279
+ $version = $this->get_plugin_version();
1280
+
1281
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
1282
+
1283
+ return $this->get_api_plugin_scope()->ping(
1284
+ $this->get_anonymous_id(),
1285
+ array(
1286
+ 'is_update' => json_encode( $is_update ),
1287
+ 'version' => $version,
1288
+ 'sdk' => $this->version,
1289
+ 'is_admin' => json_encode( is_admin() ),
1290
+ 'is_ajax' => json_encode( $this->is_ajax() ),
1291
+ 'is_cron' => json_encode( $this->is_cron() ),
1292
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
1293
+ )
1294
+ );
1295
+ }
1296
+
1297
+ /**
1298
+ * Check if there's any connectivity issue to Freemius API.
1299
+ *
1300
+ * @author Vova Feldman (@svovaf)
1301
+ * @since 1.0.9
1302
+ *
1303
+ * @param bool $flush_if_no_connectivity
1304
+ *
1305
+ * @return bool
1306
+ */
1307
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
1308
+ $this->_logger->entrance();
1309
+
1310
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
1311
+ return $this->_has_api_connection;
1312
+ }
1313
+
1314
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
1315
+ isset( $this->_storage->connectivity_test ) &&
1316
+ true === $this->_storage->connectivity_test['is_connected']
1317
+ ) {
1318
+ unset( $this->_storage->connectivity_test );
1319
+ }
1320
+
1321
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
1322
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
1323
+ /**
1324
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
1325
+ */
1326
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
1327
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1328
+
1329
+ return $this->_has_api_connection;
1330
+ }
1331
+
1332
+ $pong = $this->ping();
1333
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1334
+
1335
+ if ( ! $is_connected ) {
1336
+ // API failure.
1337
+ $this->_add_connectivity_issue_message( $pong );
1338
+ }
1339
+
1340
+ $this->store_connectivity_info( $pong, $is_connected );
1341
+
1342
+ return $this->_has_api_connection;
1343
+ }
1344
+
1345
+ /**
1346
+ * @author Vova Feldman (@svovaf)
1347
+ * @since 1.1.7.4
1348
+ *
1349
+ * @param object $pong
1350
+ * @param bool $is_connected
1351
+ */
1352
+ private function store_connectivity_info( $pong, $is_connected ) {
1353
+ $this->_logger->entrance();
1354
+
1355
+ $version = $this->get_plugin_version();
1356
+
1357
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
1358
+ $is_active = false;
1359
+ } else {
1360
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
1361
+ }
1362
+
1363
+ $is_active = $this->apply_filters(
1364
+ 'is_on',
1365
+ $is_active,
1366
+ $this->is_plugin_update(),
1367
+ $version
1368
+ );
1369
+
1370
+ $this->_storage->connectivity_test = array(
1371
+ 'is_connected' => $is_connected,
1372
+ 'host' => $_SERVER['HTTP_HOST'],
1373
+ 'server_ip' => WP_FS__REMOTE_ADDR,
1374
+ 'is_active' => $is_active,
1375
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
1376
+ // Last version with connectivity attempt.
1377
+ 'version' => $version,
1378
+ );
1379
+
1380
+ $this->_has_api_connection = $is_connected;
1381
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1382
+ }
1383
+
1384
+ /**
1385
+ * Force turning Freemius on.
1386
+ *
1387
+ * @author Vova Feldman (@svovaf)
1388
+ * @since 1.1.8.1
1389
+ *
1390
+ * @return bool TRUE if successfully turned on.
1391
+ */
1392
+ private function turn_on() {
1393
+ $this->_logger->entrance();
1394
+
1395
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
1396
+ return false;
1397
+ }
1398
+
1399
+ $updated_connectivity = $this->_storage->connectivity_test;
1400
+ $updated_connectivity['is_active'] = true;
1401
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
1402
+ $this->_storage->connectivity_test = $updated_connectivity;
1403
+
1404
+ $this->_is_on = true;
1405
+
1406
+ return true;
1407
+ }
1408
+
1409
+ /**
1410
+ * Anonymous and unique site identifier (Hash).
1411
+ *
1412
+ * @author Vova Feldman (@svovaf)
1413
+ * @since 1.1.0
1414
+ *
1415
+ * @return string
1416
+ */
1417
+ function get_anonymous_id() {
1418
+ $unique_id = self::$_accounts->get_option( 'unique_id' );
1419
+
1420
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
1421
+ $key = get_site_url();
1422
+
1423
+ // If localhost, assign microtime instead of domain.
1424
+ if ( WP_FS__IS_LOCALHOST ||
1425
+ false !== strpos( $key, 'localhost' ) ||
1426
+ false === strpos( $key, '.' )
1427
+ ) {
1428
+ $key = microtime();
1429
+ }
1430
+
1431
+ $unique_id = md5( $key );
1432
+
1433
+ self::$_accounts->set_option( 'unique_id', $unique_id, true );
1434
+ }
1435
+
1436
+ $this->_logger->departure( $unique_id );
1437
+
1438
+ return $unique_id;
1439
+ }
1440
+
1441
+ /**
1442
+ * @author Vova Feldman (@svovaf)
1443
+ * @since 1.1.7.4
1444
+ *
1445
+ * @return \WP_User
1446
+ */
1447
+ static function _get_current_wp_user() {
1448
+ self::require_pluggable_essentials();
1449
+
1450
+ return wp_get_current_user();
1451
+ }
1452
+
1453
+ /**
1454
+ * Generate API connectivity issue message.
1455
+ *
1456
+ * @author Vova Feldman (@svovaf)
1457
+ * @since 1.0.9
1458
+ *
1459
+ * @param mixed $api_result
1460
+ * @param bool $is_first_failure
1461
+ */
1462
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
1463
+ if ( $this->_enable_anonymous ) {
1464
+ // Don't add message if can run anonymously.
1465
+ return;
1466
+ }
1467
+
1468
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
1469
+ require_once( ABSPATH . 'wp-includes/functions.php' );
1470
+ }
1471
+
1472
+ $current_user = self::_get_current_wp_user();
1473
+ // $admin_email = get_option( 'admin_email' );
1474
+ $admin_email = $current_user->user_email;
1475
+
1476
+ $message = false;
1477
+ if ( is_object( $api_result ) &&
1478
+ isset( $api_result->error ) &&
1479
+ isset( $api_result->error->code )
1480
+ ) {
1481
+ switch ( $api_result->error->code ) {
1482
+ case 'curl_missing':
1483
+ $message = sprintf(
1484
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1485
+ __fs( 'curl-missing-message', $this->_slug ) . ' ' .
1486
+ ' %s',
1487
+ '<b>' . $this->get_plugin_name() . '</b>',
1488
+ sprintf(
1489
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1490
+ sprintf(
1491
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
1492
+ __fs( 'curl-missing-no-clue-title', $this->_slug ),
1493
+ ' - ' . sprintf(
1494
+ __fs( 'curl-missing-no-clue-desc', $this->_slug ),
1495
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1496
+ )
1497
+ ),
1498
+ sprintf(
1499
+ '<b>%s</b> - %s',
1500
+ __fs( 'sysadmin-title', $this->_slug ),
1501
+ __fs( 'curl-missing-sysadmin-desc', $this->_slug )
1502
+ ),
1503
+ sprintf(
1504
+ '<a href="%s"><b>%s</b></a>%s',
1505
+ 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 ),
1506
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1507
+ ' - ' . __fs( 'deactivate-plugin-desc', 'freemius', $this->_slug )
1508
+ )
1509
+ )
1510
+ );
1511
+ break;
1512
+ case 'cloudflare_ddos_protection':
1513
+ $message = sprintf(
1514
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1515
+ __fs( 'cloudflare-blocks-connection-message', $this->_slug ) . ' ' .
1516
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1517
+ ' %s',
1518
+ '<b>' . $this->get_plugin_name() . '</b>',
1519
+ sprintf(
1520
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1521
+ sprintf(
1522
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
1523
+ __fs( 'fix-issue-title', $this->_slug ),
1524
+ ' - ' . sprintf(
1525
+ __fs( 'fix-issue-desc', $this->_slug ),
1526
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1527
+ )
1528
+ ),
1529
+ sprintf(
1530
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1531
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1532
+ __fs( 'install-previous-title', $this->_slug ),
1533
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1534
+ ),
1535
+ sprintf(
1536
+ '<a href="%s"><b>%s</b></a>%s',
1537
+ 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 ),
1538
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1539
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1540
+ )
1541
+ )
1542
+ );
1543
+ break;
1544
+ case 'squid_cache_block':
1545
+ $message = sprintf(
1546
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1547
+ __fs( 'squid-blocks-connection-message', $this->_slug ) .
1548
+ ' %s',
1549
+ '<b>' . $this->get_plugin_name() . '</b>',
1550
+ sprintf(
1551
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1552
+ sprintf(
1553
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
1554
+ __fs( 'squid-no-clue-title', $this->_slug ),
1555
+ ' - ' . sprintf(
1556
+ __fs( 'squid-no-clue-desc', $this->_slug ),
1557
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1558
+ )
1559
+ ),
1560
+ sprintf(
1561
+ '<b>%s</b> - %s',
1562
+ __fs( 'sysadmin-title', $this->_slug ),
1563
+ sprintf(
1564
+ __fs( 'squid-sysadmin-desc', $this->_slug ),
1565
+ // We use a filter since the plugin might require additional API connectivity.
1566
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com' ) ) ) . '</b>' )
1567
+ ),
1568
+ sprintf(
1569
+ '<a href="%s"><b>%s</b></a>%s',
1570
+ 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 ),
1571
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1572
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1573
+ )
1574
+ )
1575
+ );
1576
+ break;
1577
+ // default:
1578
+ // $message = __fs( 'connectivity-test-fails-message', $this->_slug );
1579
+ // break;
1580
+ }
1581
+ }
1582
+
1583
+ $message_id = 'failed_connect_api';
1584
+ $type = 'error';
1585
+
1586
+ if ( false === $message ) {
1587
+ if ( $is_first_failure ) {
1588
+ // First attempt failed.
1589
+ $message = sprintf(
1590
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1591
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1592
+ __fs( 'connectivity-test-maybe-temporary', $this->_slug ) . '<br><br>' .
1593
+ '%s',
1594
+ '<b>' . $this->get_plugin_name() . '</b>',
1595
+ sprintf(
1596
+ '<div id="fs_firewall_issue_options">%s %s</div>',
1597
+ sprintf(
1598
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
1599
+ __fs( 'yes-do-your-thing', $this->_slug )
1600
+ ),
1601
+ sprintf(
1602
+ '<a href="%s" class="button">%s</a>',
1603
+ 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 ),
1604
+ __fs( 'no-deactivate', $this->_slug )
1605
+ )
1606
+ )
1607
+ );
1608
+
1609
+ $message_id = 'failed_connect_api_first';
1610
+ $type = 'promotion';
1611
+ } else {
1612
+ // Second connectivity attempt failed.
1613
+ $message = sprintf(
1614
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1615
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1616
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1617
+ ' %s',
1618
+ '<b>' . $this->get_plugin_name() . '</b>',
1619
+ sprintf(
1620
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1621
+ sprintf(
1622
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
1623
+ __fs( 'fix-issue-title', $this->_slug ),
1624
+ ' - ' . sprintf(
1625
+ __fs( 'fix-issue-desc', $this->_slug ),
1626
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1627
+ )
1628
+ ),
1629
+ sprintf(
1630
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1631
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1632
+ __fs( 'install-previous-title', $this->_slug ),
1633
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1634
+ ),
1635
+ sprintf(
1636
+ '<a href="%s"><b>%s</b></a>%s',
1637
+ 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 ),
1638
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1639
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1640
+ )
1641
+ )
1642
+ );
1643
+ }
1644
+ }
1645
+
1646
+ $this->_admin_notices->add_sticky(
1647
+ $message,
1648
+ $message_id,
1649
+ __fs( 'oops', $this->_slug ) . '...',
1650
+ $type
1651
+ );
1652
+ }
1653
+
1654
+ /**
1655
+ * Handle user request to resolve connectivity issue.
1656
+ * This method will send an email to Freemius API technical staff for resolution.
1657
+ * The email will contain server's info and installed plugins (might be caching issue).
1658
+ *
1659
+ * @author Vova Feldman (@svovaf)
1660
+ * @since 1.0.9
1661
+ */
1662
+ function _email_about_firewall_issue() {
1663
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
1664
+
1665
+ $pong = $this->ping();
1666
+
1667
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1668
+
1669
+ if ( $is_connected ) {
1670
+ $this->store_connectivity_info( $pong, $is_connected );
1671
+
1672
+ echo $this->get_after_plugin_activation_redirect_url();
1673
+ exit;
1674
+ }
1675
+
1676
+ $current_user = self::_get_current_wp_user();
1677
+ $admin_email = $current_user->user_email;
1678
+
1679
+ $error_type = fs_request_get( 'error_type', 'general' );
1680
+
1681
+ switch ( $error_type ) {
1682
+ case 'squid':
1683
+ $title = 'Squid ACL Blocking Issue';
1684
+ break;
1685
+ case 'cloudflare':
1686
+ $title = 'CloudFlare Blocking Issue';
1687
+ break;
1688
+ default:
1689
+ $title = 'API Connectivity Issue';
1690
+ break;
1691
+ }
1692
+
1693
+ $custom_email_sections = array();
1694
+
1695
+ if ( 'squid' === $error_type ) {
1696
+ // Override the 'Site' email section.
1697
+ $custom_email_sections['site'] = array(
1698
+ 'rows' => array(
1699
+ 'hosting_company' => array( 'Hosting Company', fs_request_get( 'hosting_company' ) )
1700
+ )
1701
+ );
1702
+ }
1703
+
1704
+ // Add 'API Error' custom email section.
1705
+ $custom_email_sections['api_error'] = array(
1706
+ 'title' => 'API Error',
1707
+ 'rows' => array(
1708
+ 'ping' => array( is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong ) )
1709
+ )
1710
+ );
1711
+
1712
+ // Add PHP info for deeper investigation.
1713
+ ob_start();
1714
+ phpinfo();
1715
+ $php_info = ob_get_clean();
1716
+ $custom_email_sections['php_info'] = array(
1717
+ 'title' => 'PHP Info',
1718
+ 'rows' => array(
1719
+ 'info' => array( $php_info )
1720
+ )
1721
+ );
1722
+
1723
+ // Send email with technical details to resolve CloudFlare's firewall unnecessary protection.
1724
+ $this->send_email(
1725
+ 'api@freemius.com', // recipient
1726
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
1727
+ $custom_email_sections,
1728
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
1729
+ );
1730
+
1731
+ $this->_admin_notices->add_sticky(
1732
+ sprintf(
1733
+ __fs( 'fix-request-sent-message', $this->_slug ),
1734
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1735
+ ),
1736
+ 'server_details_sent'
1737
+ );
1738
+
1739
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
1740
+
1741
+ echo "1";
1742
+ exit;
1743
+ }
1744
+
1745
+ /**
1746
+ * Handle connectivity test retry approved by the user.
1747
+ *
1748
+ * @author Vova Feldman (@svovaf)
1749
+ * @since 1.1.7.4
1750
+ */
1751
+ function _retry_connectivity_test() {
1752
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
1753
+
1754
+ $pong = $this->ping();
1755
+
1756
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1757
+
1758
+ if ( $is_connected ) {
1759
+ $this->store_connectivity_info( $pong, $is_connected );
1760
+
1761
+ echo $this->get_after_plugin_activation_redirect_url();
1762
+ } else {
1763
+ // Add connectivity issue message after 2nd failed attempt.
1764
+ $this->_add_connectivity_issue_message( $pong, false );
1765
+
1766
+ echo "1";
1767
+ }
1768
+
1769
+ exit;
1770
+ }
1771
+
1772
+ static function _add_firewall_issues_javascript() {
1773
+ $params = array();
1774
+ fs_require_once_template( 'firewall-issues-js.php', $params );
1775
+ }
1776
+
1777
+ #endregion Connectivity Issues ------------------------------------------------------------------
1778
+
1779
+ #region Email ------------------------------------------------------------------
1780
+
1781
+ /**
1782
+ * Generates and sends an HTML email with customizable sections.
1783
+ *
1784
+ * @author Leo Fajardo (@leorw)
1785
+ * @since 1.1.2
1786
+ *
1787
+ * @param string $to_address
1788
+ * @param string $subject
1789
+ * @param array $sections
1790
+ * @param array $headers
1791
+ *
1792
+ * @return bool Whether the email contents were sent successfully.
1793
+ */
1794
+ private function send_email(
1795
+ $to_address,
1796
+ $subject,
1797
+ $sections = array(),
1798
+ $headers = array()
1799
+ ) {
1800
+ $default_sections = $this->get_email_sections();
1801
+
1802
+ // Insert new sections or replace the default email sections.
1803
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
1804
+ foreach ( $sections as $section_id => $custom_section ) {
1805
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
1806
+ // If the section does not exist, add it.
1807
+ $default_sections[ $section_id ] = $custom_section;
1808
+ } else {
1809
+ // If the section already exists, override it.
1810
+ $current_section = $default_sections[ $section_id ];
1811
+
1812
+ // Replace the current section's title if a custom section title exists.
1813
+ if ( isset( $custom_section['title'] ) ) {
1814
+ $current_section['title'] = $custom_section['title'];
1815
+ }
1816
+
1817
+ // Insert new rows under the current section or replace the default rows.
1818
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
1819
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
1820
+ $current_section['rows'][ $row_id ] = $row;
1821
+ }
1822
+ }
1823
+
1824
+ $default_sections[ $section_id ] = $current_section;
1825
+ }
1826
+ }
1827
+ }
1828
+
1829
+ $vars = array( 'sections' => $default_sections );
1830
+ $message = fs_get_template( 'email.php', $vars );
1831
+
1832
+ // Set the type of email to HTML.
1833
+ $headers[] = 'Content-type: text/html';
1834
+
1835
+ $header_string = implode( "\r\n", $headers );
1836
+
1837
+ return wp_mail(
1838
+ $to_address,
1839
+ $subject,
1840
+ $message,
1841
+ $header_string
1842
+ );
1843
+ }
1844
+
1845
+ /**
1846
+ * Generates the data for the sections of the email content.
1847
+ *
1848
+ * @author Leo Fajardo (@leorw)
1849
+ * @since 1.1.2
1850
+ *
1851
+ * @return array
1852
+ */
1853
+ private function get_email_sections() {
1854
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
1855
+ $current_user = self::_get_current_wp_user();
1856
+
1857
+ // Retrieve the cURL version information so that we can get the version number below.
1858
+ $curl_version_information = curl_version();
1859
+
1860
+ $active_plugin = self::get_active_plugins();
1861
+
1862
+ // Generate the list of active plugins separated by new line.
1863
+ $active_plugin_string = '';
1864
+ foreach ( $active_plugin as $plugin ) {
1865
+ $active_plugin_string .= sprintf(
1866
+ '<a href="%s">%s</a> [v%s]<br>',
1867
+ $plugin['PluginURI'],
1868
+ $plugin['Name'],
1869
+ $plugin['Version']
1870
+ );
1871
+ }
1872
+
1873
+ $server_ip = WP_FS__REMOTE_ADDR;
1874
+
1875
+ // Generate the default email sections.
1876
+ $sections = array(
1877
+ 'sdk' => array(
1878
+ 'title' => 'SDK',
1879
+ 'rows' => array(
1880
+ 'fs_version' => array( 'FS Version', $this->version ),
1881
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
1882
+ )
1883
+ ),
1884
+ 'plugin' => array(
1885
+ 'title' => 'Plugin',
1886
+ 'rows' => array(
1887
+ 'name' => array( 'Name', $this->get_plugin_name() ),
1888
+ 'version' => array( 'Version', $this->get_plugin_version() )
1889
+ )
1890
+ ),
1891
+ 'site' => array(
1892
+ 'title' => 'Site',
1893
+ 'rows' => array(
1894
+ 'unique_id' => array( 'Address', $this->get_anonymous_id() ),
1895
+ 'address' => array( 'Address', site_url() ),
1896
+ 'host' => array(
1897
+ 'HTTP_HOST',
1898
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
1899
+ ),
1900
+ 'server_addr' => array(
1901
+ 'SERVER_ADDR',
1902
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
1903
+ )
1904
+ )
1905
+ ),
1906
+ 'user' => array(
1907
+ 'title' => 'User',
1908
+ 'rows' => array(
1909
+ 'email' => array( 'Email', $current_user->user_email ),
1910
+ 'first' => array( 'First', $current_user->user_firstname ),
1911
+ 'last' => array( 'Last', $current_user->user_lastname )
1912
+ )
1913
+ ),
1914
+ 'plugins' => array(
1915
+ 'title' => 'Plugins',
1916
+ 'rows' => array(
1917
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
1918
+ )
1919
+ ),
1920
+ );
1921
+
1922
+ // Allow the sections to be modified by other code.
1923
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
1924
+
1925
+ return $sections;
1926
+ }
1927
+
1928
+ #endregion Email ------------------------------------------------------------------
1929
+
1930
+ #region Initialization ------------------------------------------------------------------
1931
+
1932
+ /**
1933
+ * Init plugin's Freemius instance.
1934
+ *
1935
+ * @author Vova Feldman (@svovaf)
1936
+ * @since 1.0.1
1937
+ *
1938
+ * @param number $id
1939
+ * @param string $public_key
1940
+ * @param bool $is_live
1941
+ * @param bool $is_premium
1942
+ */
1943
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
1944
+ $this->_logger->entrance();
1945
+
1946
+ $this->dynamic_init( array(
1947
+ 'id' => $id,
1948
+ 'public_key' => $public_key,
1949
+ 'is_live' => $is_live,
1950
+ 'is_premium' => $is_premium,
1951
+ ) );
1952
+ }
1953
+
1954
+ /**
1955
+ * Dynamic initiator, originally created to support initiation
1956
+ * with parent_id for add-ons.
1957
+ *
1958
+ * @author Vova Feldman (@svovaf)
1959
+ * @since 1.0.6
1960
+ *
1961
+ * @param array $plugin_info
1962
+ *
1963
+ * @throws Freemius_Exception
1964
+ */
1965
+ function dynamic_init( array $plugin_info ) {
1966
+ $this->_logger->entrance();
1967
+
1968
+ $this->parse_settings( $plugin_info );
1969
+
1970
+ if ( $this->should_stop_execution() ) {
1971
+ return;
1972
+ }
1973
+
1974
+ if ( ! $this->is_registered() ) {
1975
+ if ( $this->is_anonymous() ) {
1976
+ // If user skipped, no need to test connectivity.
1977
+ $this->_has_api_connection = true;
1978
+ $this->_is_on = true;
1979
+ } else {
1980
+ if ( ! $this->has_api_connectivity() ) {
1981
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
1982
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
1983
+ ) {
1984
+ if ( ! $this->_enable_anonymous ) {
1985
+ // If anonymous mode is disabled, add firewall admin-notice message.
1986
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
1987
+
1988
+ add_action( "wp_ajax_{$this->_slug}_resolve_firewall_issues", array(
1989
+ &$this,
1990
+ '_email_about_firewall_issue'
1991
+ ) );
1992
+
1993
+ add_action( "wp_ajax_{$this->_slug}_retry_connectivity_test", array(
1994
+ &$this,
1995
+ '_retry_connectivity_test'
1996
+ ) );
1997
+ }
1998
+ }
1999
+
2000
+ return;
2001
+ } else {
2002
+ $this->_admin_notices->remove_sticky( array(
2003
+ 'failed_connect_api_first',
2004
+ 'failed_connect_api',
2005
+ ) );
2006
+
2007
+ if ( $this->_anonymous_mode ) {
2008
+ // Simulate anonymous mode.
2009
+ $this->_is_anonymous = true;
2010
+ }
2011
+ }
2012
+ }
2013
+
2014
+ // Check if Freemius is on for the current plugin.
2015
+ // This MUST be executed after all the plugin variables has been loaded.
2016
+ if ( ! $this->is_on() ) {
2017
+ return;
2018
+ }
2019
+ }
2020
+
2021
+ if ( $this->has_api_connectivity() && $this->is_user_in_admin() ) {
2022
+ /**
2023
+ * Schedule daily data sync cron if:
2024
+ *
2025
+ * 1. User opted-in (for tracking).
2026
+ * 2. If plugin has add-ons (update add-ons data).
2027
+ * 3. If skipped, but later upgraded (opted-in via upgrade).
2028
+ *
2029
+ * @author Vova Feldman (@svovaf)
2030
+ * @since 1.1.7.3
2031
+ *
2032
+ */
2033
+ if ( $this->is_registered() ||
2034
+ ( ! $this->is_activation_mode() && $this->_has_addons )
2035
+ ) {
2036
+
2037
+ $this->hook_callback_to_sync_cron();
2038
+
2039
+ if ( ! $this->is_sync_cron_on() ) {
2040
+ $this->schedule_sync_cron();
2041
+ }
2042
+ }
2043
+
2044
+ /**
2045
+ * Check if requested for manual blocking background sync.
2046
+ */
2047
+ if ( fs_request_has( 'background_sync' ) ) {
2048
+ $this->run_manual_sync();
2049
+ }
2050
+ }
2051
+
2052
+ if ( $this->is_registered() ) {
2053
+ $this->hook_callback_to_install_sync();
2054
+ }
2055
+
2056
+ if ( $this->is_addon() ) {
2057
+ if ( $this->is_parent_plugin_installed() ) {
2058
+ // Link to parent FS.
2059
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2060
+
2061
+ // Get parent plugin reference.
2062
+ $this->_parent_plugin = $this->_parent->get_plugin();
2063
+ }
2064
+ }
2065
+
2066
+ if ( $this->is_user_in_admin() ) {
2067
+ global $pagenow;
2068
+ if ( 'plugins.php' === $pagenow ) {
2069
+ $this->hook_plugin_action_links();
2070
+ }
2071
+
2072
+ if ( $this->is_addon() ) {
2073
+ if ( ! $this->is_parent_plugin_installed() ) {
2074
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2075
+
2076
+ if ( isset( $plugin_info['parent'] ) ) {
2077
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2078
+ }
2079
+
2080
+ $this->_admin_notices->add(
2081
+ ( ! empty( $parent_name ) ?
2082
+ sprintf( __fs( 'addon-x-cannot-run-without-y', $this->_slug ), $this->get_plugin_name(), $parent_name ) :
2083
+ sprintf( __fs( 'addon-x-cannot-run-without-parent', $this->_slug ), $this->get_plugin_name() )
2084
+ ),
2085
+ __fs( 'oops', $this->_slug ) . '...',
2086
+ 'error'
2087
+ );
2088
+
2089
+ return;
2090
+ } else {
2091
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
2092
+ // If parent plugin activated, automatically install add-on for the user.
2093
+ $this->_activate_addon_account( $this->_parent );
2094
+ }
2095
+
2096
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
2097
+ if ( $this->is_premium() ) {
2098
+ // Remove add-on download admin-notice.
2099
+ $this->_parent->_admin_notices->remove_sticky( array(
2100
+ 'addon_plan_upgraded_' . $this->_slug,
2101
+ 'no_addon_license_' . $this->_slug,
2102
+ ) );
2103
+ }
2104
+
2105
+ $this->deactivate_premium_only_addon_without_license();
2106
+ }
2107
+ } else {
2108
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
2109
+
2110
+ if ( $this->has_addons() &&
2111
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
2112
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
2113
+ ) {
2114
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
2115
+
2116
+ new FS_Plugin_Info_Dialog( $this );
2117
+ }
2118
+ }
2119
+
2120
+ if ( $this->is_premium() ) {
2121
+ new FS_Plugin_Updater( $this );
2122
+ }
2123
+
2124
+ // if ( $this->is_registered() ||
2125
+ // $this->is_anonymous() ||
2126
+ // $this->is_pending_activation()
2127
+ // ) {
2128
+ // $this->_init_admin();
2129
+ // }
2130
+ }
2131
+
2132
+ $this->do_action( 'initiated' );
2133
+
2134
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
2135
+ if ( isset( $this->_storage->prev_is_premium ) ) {
2136
+ $this->apply_filters(
2137
+ 'after_code_type_change',
2138
+ // New code type.
2139
+ $this->_plugin->is_premium
2140
+ );
2141
+ } else {
2142
+ // Set for code type for the first time.
2143
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2144
+ }
2145
+ }
2146
+
2147
+ if ( ! $this->is_addon() ) {
2148
+ if ( $this->is_registered() ) {
2149
+ // Fix for upgrade from versions < 1.0.9.
2150
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
2151
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
2152
+ }
2153
+
2154
+ $this->do_action( 'after_init_plugin_registered' );
2155
+ } else if ( $this->is_anonymous() ) {
2156
+ $this->do_action( 'after_init_plugin_anonymous' );
2157
+ } else if ( $this->is_pending_activation() ) {
2158
+ $this->do_action( 'after_init_plugin_pending_activations' );
2159
+ }
2160
+ } else {
2161
+ if ( $this->is_registered() ) {
2162
+ $this->do_action( 'after_init_addon_registered' );
2163
+ } else if ( $this->is_anonymous() ) {
2164
+ $this->do_action( 'after_init_addon_anonymous' );
2165
+ } else if ( $this->is_pending_activation() ) {
2166
+ $this->do_action( 'after_init_addon_pending_activations' );
2167
+ }
2168
+ }
2169
+
2170
+ // Add license activation link and AJAX request handler.
2171
+ if ( $this->has_paid_plan() ) {
2172
+ global $pagenow;
2173
+ if ( 'plugins.php' === $pagenow ) {
2174
+ /**
2175
+ * @since 1.2.0 Add license action link only on plugins page.
2176
+ */
2177
+ $this->_add_license_action_link();
2178
+ $this->_require_license_activation_dialog();
2179
+ }
2180
+
2181
+ if ( $this->is_ajax_action( array(
2182
+ 'activate_license',
2183
+ 'resend_license_key'
2184
+ ) )
2185
+ ) {
2186
+ // Hook license activation and resend AJAX callbacks.
2187
+ $this->_require_license_activation_dialog();
2188
+ }
2189
+ }
2190
+ }
2191
+
2192
+ /**
2193
+ * Parse plugin's settings (as defined by the plugin dev).
2194
+ *
2195
+ * @author Vova Feldman (@svovaf)
2196
+ * @since 1.1.7.3
2197
+ *
2198
+ * @param array $plugin_info
2199
+ *
2200
+ * @throws \Freemius_Exception
2201
+ */
2202
+ private function parse_settings( &$plugin_info ) {
2203
+ $this->_logger->entrance();
2204
+
2205
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
2206
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
2207
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
2208
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
2209
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2210
+
2211
+ /**
2212
+ * @author Vova Feldman (@svovaf)
2213
+ * @since 1.1.9 Try to pull secret key from external config.
2214
+ */
2215
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
2216
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
2217
+ }
2218
+
2219
+ if ( isset( $plugin_info['parent'] ) ) {
2220
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
2221
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
2222
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
2223
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2224
+ }
2225
+
2226
+ if ( false === $id ) {
2227
+ throw new Freemius_Exception( 'Plugin id parameter is not set.' );
2228
+ }
2229
+ if ( false === $public_key ) {
2230
+ throw new Freemius_Exception( 'Plugin public_key parameter is not set.' );
2231
+ }
2232
+
2233
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
2234
+ $this->_plugin :
2235
+ new FS_Plugin();
2236
+
2237
+ $plugin->update( array(
2238
+ 'id' => $id,
2239
+ 'public_key' => $public_key,
2240
+ 'slug' => $this->_slug,
2241
+ 'parent_plugin_id' => $parent_id,
2242
+ 'version' => $this->get_plugin_version(),
2243
+ 'title' => $this->get_plugin_name(),
2244
+ 'file' => $this->_plugin_basename,
2245
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
2246
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
2247
+ // 'secret_key' => $secret_key,
2248
+ ) );
2249
+
2250
+ if ( $plugin->is_updated() ) {
2251
+ // Update plugin details.
2252
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->store( $plugin );
2253
+ }
2254
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
2255
+ $this->_plugin->secret_key = $secret_key;
2256
+
2257
+ if ( ! isset( $plugin_info['menu'] ) ) {
2258
+ // Back compatibility to 1.1.2
2259
+ $plugin_info['menu'] = array(
2260
+ 'slug' => isset( $plugin_info['menu_slug'] ) ?
2261
+ $plugin_info['menu_slug'] :
2262
+ $this->_slug
2263
+ );
2264
+ }
2265
+
2266
+ $this->_menu = FS_Admin_Menu_Manager::instance( $this->_slug );
2267
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
2268
+
2269
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
2270
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
2271
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
2272
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
2273
+ if ( $this->_is_premium_only ) {
2274
+ // If premium only plugin, disable anonymous mode.
2275
+ $this->_enable_anonymous = false;
2276
+ $this->_anonymous_mode = false;
2277
+ } else {
2278
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
2279
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
2280
+ }
2281
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
2282
+ }
2283
+
2284
+ /**
2285
+ * @param string[] $options
2286
+ * @param string $key
2287
+ * @param mixed $default
2288
+ *
2289
+ * @return bool
2290
+ */
2291
+ private function get_option( &$options, $key, $default = false ) {
2292
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
2293
+ }
2294
+
2295
+ private function get_bool_option( &$options, $key, $default = false ) {
2296
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
2297
+ }
2298
+
2299
+ private function get_numeric_option( &$options, $key, $default = false ) {
2300
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
2301
+ }
2302
+
2303
+ /**
2304
+ * Gate keeper.
2305
+ *
2306
+ * @author Vova Feldman (@svovaf)
2307
+ * @since 1.1.7.3
2308
+ *
2309
+ * @return bool
2310
+ */
2311
+ private function should_stop_execution() {
2312
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
2313
+ /**
2314
+ * Don't execute Freemius until plugin was fully loaded at least once,
2315
+ * to give the opportunity for the activation hook to run before pinging
2316
+ * the API for connectivity test. This logic is relevant for the
2317
+ * identification of new plugin install vs. plugin update.
2318
+ *
2319
+ * @author Vova Feldman (@svovaf)
2320
+ * @since 1.1.9
2321
+ */
2322
+ return true;
2323
+ }
2324
+
2325
+ if ( $this->is_activation_mode() ) {
2326
+ if ( ! is_admin() ) {
2327
+ /**
2328
+ * If in activation mode, don't execute Freemius outside of the
2329
+ * admin dashboard.
2330
+ *
2331
+ * @author Vova Feldman (@svovaf)
2332
+ * @since 1.1.7.3
2333
+ */
2334
+ return true;
2335
+ }
2336
+
2337
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
2338
+ /**
2339
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
2340
+ * then don't start Freemius.
2341
+ *
2342
+ * @author Vova Feldman (@svovaf)
2343
+ * @since 1.1.6.3
2344
+ *
2345
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
2346
+ */
2347
+ return true;
2348
+ }
2349
+
2350
+ if ( $this->is_cron() ) {
2351
+ /**
2352
+ * If in activation mode, don't execute Freemius during wp crons
2353
+ * (wp crons have HTTP context - called as HTTP request).
2354
+ *
2355
+ * @author Vova Feldman (@svovaf)
2356
+ * @since 1.1.7.3
2357
+ */
2358
+ return true;
2359
+ }
2360
+
2361
+ if ( $this->is_ajax() &&
2362
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
2363
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
2364
+ ) {
2365
+ /**
2366
+ * During activation, if running in AJAX mode, unless there's a sticky
2367
+ * connectivity issue notice, don't run Freemius.
2368
+ *
2369
+ * @author Vova Feldman (@svovaf)
2370
+ * @since 1.1.7.3
2371
+ */
2372
+ return true;
2373
+ }
2374
+ }
2375
+
2376
+ return false;
2377
+ }
2378
+
2379
+ /**
2380
+ * Triggered after code type has changed.
2381
+ *
2382
+ * @author Vova Feldman (@svovaf)
2383
+ * @since 1.1.9.1
2384
+ */
2385
+ function _after_code_type_change() {
2386
+ $this->_logger->entrance();
2387
+
2388
+ add_action( is_admin() ? 'admin_init' : 'init', array(
2389
+ &$this,
2390
+ '_plugin_code_type_changed'
2391
+ ) );
2392
+ }
2393
+
2394
+ /**
2395
+ * Handles plugin's code type change (free <--> premium).
2396
+ *
2397
+ * @author Vova Feldman (@svovaf)
2398
+ * @since 1.0.9
2399
+ */
2400
+ function _plugin_code_type_changed() {
2401
+ $this->_logger->entrance();
2402
+
2403
+ // Schedule code type changes event.
2404
+ // $this->sync_install();
2405
+ $this->schedule_install_sync();
2406
+
2407
+ if ( $this->is_premium() ) {
2408
+ // Activated premium code.
2409
+ $this->do_action( 'after_premium_version_activation' );
2410
+
2411
+ // Remove all sticky messages related to download of the premium version.
2412
+ $this->_admin_notices->remove_sticky( array(
2413
+ 'trial_started',
2414
+ 'plan_upgraded',
2415
+ 'plan_changed',
2416
+ ) );
2417
+
2418
+ $this->_admin_notices->add_sticky(
2419
+ __fs( 'premium-activated-message', $this->_slug ),
2420
+ 'premium_activated',
2421
+ __fs( 'woot', $this->_slug ) . '!'
2422
+ );
2423
+ } else {
2424
+ // Activated free code (after had the premium before).
2425
+ $this->do_action( 'after_free_version_reactivation' );
2426
+
2427
+ if ( $this->is_paying() && ! $this->is_premium() ) {
2428
+ $this->_admin_notices->add_sticky(
2429
+ sprintf(
2430
+ __fs( 'you-have-x-license', $this->_slug ),
2431
+ $this->_site->plan->title
2432
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
2433
+ __fs( 'download-x-version-now', $this->_slug ),
2434
+ $this->_site->plan->title
2435
+ ) ),
2436
+ 'plan_upgraded',
2437
+ __fs( 'yee-haw', $this->_slug ) . '!'
2438
+ );
2439
+ }
2440
+ }
2441
+
2442
+ /**
2443
+ * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
2444
+ * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
2445
+ * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
2446
+ * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
2447
+ * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
2448
+ * free and premium versions are almost identical (same class or have same functions), a fatal error like
2449
+ * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
2450
+ */
2451
+ $this->unregister_uninstall_hook();
2452
+
2453
+ $this->clear_module_main_file_cache();
2454
+
2455
+ // Update is_premium of latest version.
2456
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2457
+ }
2458
+
2459
+ #endregion Initialization ------------------------------------------------------------------
2460
+
2461
+ #region Add-ons -------------------------------------------------------------------------
2462
+
2463
+ /**
2464
+ * Check if add-on installed and activated on site.
2465
+ *
2466
+ * @author Vova Feldman (@svovaf)
2467
+ * @since 1.0.6
2468
+ *
2469
+ * @param string|number $slug_or_id
2470
+ *
2471
+ * @return bool
2472
+ */
2473
+ function is_addon_activated( $slug_or_id ) {
2474
+ return self::has_instance( $slug_or_id );
2475
+ }
2476
+
2477
+ /**
2478
+ * Check if add-on was connected to install
2479
+ *
2480
+ * @author Vova Feldman (@svovaf)
2481
+ * @since 1.1.7
2482
+ *
2483
+ * @param string $slug
2484
+ *
2485
+ * @return bool
2486
+ */
2487
+ function is_addon_connected( $slug ) {
2488
+ $sites = self::get_all_sites();
2489
+
2490
+ if ( ! isset( $sites[ $slug ] ) ) {
2491
+ return false;
2492
+ }
2493
+
2494
+ $site = $sites[ $slug ];
2495
+
2496
+ $plugin = FS_Plugin_Manager::instance( $slug )->get();
2497
+
2498
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
2499
+ // The given slug do NOT belong to any of the plugin's add-ons.
2500
+ return false;
2501
+ }
2502
+
2503
+ return ( is_object( $site ) &&
2504
+ is_numeric( $site->id ) &&
2505
+ is_numeric( $site->user_id ) &&
2506
+ is_object( $site->plan )
2507
+ );
2508
+ }
2509
+
2510
+ /**
2511
+ * Determines if add-on installed.
2512
+ *
2513
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
2514
+ *
2515
+ * @author Vova Feldman (@svovaf)
2516
+ * @since 1.0.6
2517
+ *
2518
+ * @param string $slug
2519
+ *
2520
+ * @return bool
2521
+ */
2522
+ function is_addon_installed( $slug ) {
2523
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $slug ) ) );
2524
+ }
2525
+
2526
+ /**
2527
+ * Get add-on basename.
2528
+ *
2529
+ * @author Vova Feldman (@svovaf)
2530
+ * @since 1.0.6
2531
+ *
2532
+ * @param string $slug
2533
+ *
2534
+ * @return string
2535
+ */
2536
+ function get_addon_basename( $slug ) {
2537
+ if ( $this->is_addon_activated( $slug ) ) {
2538
+ self::instance( $slug )->get_plugin_basename();
2539
+ }
2540
+
2541
+ $premium_basename = $slug . '-premium/' . $slug . '.php';
2542
+
2543
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
2544
+ return $premium_basename;
2545
+ }
2546
+
2547
+ $free_basename = $slug . '/' . $slug . '.php';
2548
+
2549
+ return $free_basename;
2550
+ }
2551
+
2552
+ /**
2553
+ * Get installed add-ons instances.
2554
+ *
2555
+ * @author Vova Feldman (@svovaf)
2556
+ * @since 1.0.6
2557
+ *
2558
+ * @return Freemius[]
2559
+ */
2560
+ function get_installed_addons() {
2561
+ $installed_addons = array();
2562
+ foreach ( self::$_instances as $slug => $instance ) {
2563
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2564
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2565
+ $installed_addons[] = $instance;
2566
+ }
2567
+ }
2568
+ }
2569
+
2570
+ return $installed_addons;
2571
+ }
2572
+
2573
+ /**
2574
+ * Check if any add-ons of the plugin are installed.
2575
+ *
2576
+ * @author Leo Fajardo (@leorw)
2577
+ * @since 1.1.1
2578
+ *
2579
+ * @return bool
2580
+ */
2581
+ function has_installed_addons() {
2582
+ if ( ! $this->has_addons() ) {
2583
+ return false;
2584
+ }
2585
+
2586
+ foreach ( self::$_instances as $slug => $instance ) {
2587
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2588
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2589
+ return true;
2590
+ }
2591
+ }
2592
+ }
2593
+
2594
+ return false;
2595
+ }
2596
+
2597
+ /**
2598
+ * Tell Freemius that the current plugin is an add-on.
2599
+ *
2600
+ * @author Vova Feldman (@svovaf)
2601
+ * @since 1.0.6
2602
+ *
2603
+ * @param number $parent_plugin_id The parent plugin ID
2604
+ */
2605
+ function init_addon( $parent_plugin_id ) {
2606
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
2607
+ }
2608
+
2609
+ /**
2610
+ * @author Vova Feldman (@svovaf)
2611
+ * @since 1.0.6
2612
+ *
2613
+ * @return bool
2614
+ */
2615
+ function is_addon() {
2616
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
2617
+ }
2618
+
2619
+ /**
2620
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
2621
+ *
2622
+ * @param bool $is_after_trial_cancel
2623
+ *
2624
+ * @return bool If add-on was deactivated.
2625
+ */
2626
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
2627
+ if ( ! $this->has_free_plan() &&
2628
+ ! $this->has_features_enabled_license() &&
2629
+ ! $this->_has_premium_license()
2630
+ ) {
2631
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
2632
+ // if (empty($this->_storage->activation_timestamp) ||
2633
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
2634
+ // ) {
2635
+ /**
2636
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
2637
+ *
2638
+ * Retry syncing the user add-on licenses.
2639
+ */
2640
+ // Sync licenses.
2641
+ $this->_sync_licenses();
2642
+ // }
2643
+
2644
+ // Try to activate premium license.
2645
+ $this->_activate_license( true );
2646
+
2647
+ if ( ! $this->has_free_plan() &&
2648
+ ! $this->has_features_enabled_license() &&
2649
+ ! $this->_has_premium_license()
2650
+ ) {
2651
+ // @todo Check if deactivate plugins also call the deactivation hook.
2652
+
2653
+ deactivate_plugins( array( $this->_plugin_basename ), true );
2654
+
2655
+ $this->_parent->_admin_notices->add_sticky(
2656
+ sprintf(
2657
+ __fs( ( $is_after_trial_cancel ?
2658
+ 'addon-trial-cancelled-message' :
2659
+ 'addon-no-license-message' ),
2660
+ $this->_parent->_slug
2661
+ ),
2662
+ '<b>' . $this->_plugin->title . '</b>'
2663
+ ) . ' ' . sprintf(
2664
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
2665
+ $this->_parent->addon_url( $this->_slug ),
2666
+ esc_attr( sprintf( __fs( 'more-information-about-x', $this->_parent->_slug ), $this->_plugin->title ) ),
2667
+ __fs( 'purchase-license', $this->_parent->_slug )
2668
+ ),
2669
+ 'no_addon_license_' . $this->_slug,
2670
+ ( $is_after_trial_cancel ? '' : __fs( 'oops', $this->_parent->_slug ) . '...' ),
2671
+ ( $is_after_trial_cancel ? 'success' : 'error' )
2672
+ );
2673
+
2674
+ return true;
2675
+ }
2676
+ }
2677
+
2678
+ return false;
2679
+ }
2680
+
2681
+ #endregion ------------------------------------------------------------------
2682
+
2683
+ #region Sandbox ------------------------------------------------------------------
2684
+
2685
+ /**
2686
+ * Set Freemius into sandbox mode for debugging.
2687
+ *
2688
+ * @author Vova Feldman (@svovaf)
2689
+ * @since 1.0.4
2690
+ *
2691
+ * @param string $secret_key
2692
+ */
2693
+ function init_sandbox( $secret_key ) {
2694
+ $this->_plugin->secret_key = $secret_key;
2695
+
2696
+ // Update plugin details.
2697
+ FS_Plugin_Manager::instance( $this->_slug )->update( $this->_plugin, true );
2698
+ }
2699
+
2700
+ /**
2701
+ * Check if running payments in sandbox mode.
2702
+ *
2703
+ * @author Vova Feldman (@svovaf)
2704
+ * @since 1.0.4
2705
+ *
2706
+ * @return bool
2707
+ */
2708
+ function is_payments_sandbox() {
2709
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
2710
+ }
2711
+
2712
+ #endregion Sandbox ------------------------------------------------------------------
2713
+
2714
+ /**
2715
+ * Check if running test vs. live plugin.
2716
+ *
2717
+ * @author Vova Feldman (@svovaf)
2718
+ * @since 1.0.5
2719
+ *
2720
+ * @return bool
2721
+ */
2722
+ function is_live() {
2723
+ return $this->_plugin->is_live;
2724
+ }
2725
+
2726
+ /**
2727
+ * Check if the user skipped connecting the account with Freemius.
2728
+ *
2729
+ * @author Vova Feldman (@svovaf)
2730
+ * @since 1.0.7
2731
+ *
2732
+ * @return bool
2733
+ */
2734
+ function is_anonymous() {
2735
+ if ( ! isset( $this->_is_anonymous ) ) {
2736
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
2737
+ // Not skipped.
2738
+ $this->_is_anonymous = false;
2739
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
2740
+ // For back compatibility, since the variable was boolean before.
2741
+ $this->_is_anonymous = $this->_storage->is_anonymous;
2742
+
2743
+ // Upgrade stored data format to 1.1.3 format.
2744
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
2745
+ } else {
2746
+ // Version 1.1.3 and later.
2747
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
2748
+ }
2749
+ }
2750
+
2751
+ return $this->_is_anonymous;
2752
+ }
2753
+
2754
+ /**
2755
+ * Check if user connected his account and install pending email activation.
2756
+ *
2757
+ * @author Vova Feldman (@svovaf)
2758
+ * @since 1.0.7
2759
+ *
2760
+ * @return bool
2761
+ */
2762
+ function is_pending_activation() {
2763
+ return $this->_storage->get( 'is_pending_activation', false );
2764
+ }
2765
+
2766
+ /**
2767
+ * Check if plugin must be WordPress.org compliant.
2768
+ *
2769
+ * @since 1.0.7
2770
+ *
2771
+ * @return bool
2772
+ */
2773
+ function is_org_repo_compliant() {
2774
+ return $this->_is_org_compliant;
2775
+ }
2776
+
2777
+ #region Daily Sync Cron ------------------------------------------------------------------
2778
+
2779
+ /**
2780
+ * @author Vova Feldman (@svovaf)
2781
+ * @since 1.1.7.3
2782
+ */
2783
+ private function run_manual_sync() {
2784
+ $this->require_pluggable_essentials();
2785
+
2786
+ if ( ! current_user_can( 'activate_plugins' ) ) {
2787
+ return;
2788
+ }
2789
+
2790
+ // Run manual sync.
2791
+ $this->_sync_cron();
2792
+
2793
+ // Reschedule next cron to run 24 hours from now (performance optimization).
2794
+ $this->clear_sync_cron();
2795
+
2796
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
2797
+ }
2798
+
2799
+ /**
2800
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
2801
+ * that doesn't halt page loading.
2802
+ *
2803
+ * @author Vova Feldman (@svovaf)
2804
+ * @since 1.1.7.3
2805
+ */
2806
+ function _sync_cron() {
2807
+ $this->_logger->entrance();
2808
+
2809
+ // Store the last time data sync was executed.
2810
+ $this->_storage->sync_timestamp = time();
2811
+
2812
+ // Check if API is temporary down.
2813
+ if ( FS_Api::is_temporary_down() ) {
2814
+ return;
2815
+ }
2816
+
2817
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
2818
+
2819
+ if ( $this->is_registered() ) {
2820
+ if ( $this->has_paid_plan() ) {
2821
+ // Initiate background plan sync.
2822
+ $this->_sync_license( true );
2823
+
2824
+ if ( $this->is_paying() ) {
2825
+ // Check for premium plugin updates.
2826
+ $this->_check_updates( true );
2827
+ }
2828
+ } else {
2829
+ // Sync install (only if something changed locally).
2830
+ $this->sync_install();
2831
+ }
2832
+ }
2833
+
2834
+ if ( ! $this->is_addon() && $this->_has_addons ) {
2835
+ // Sync add-ons collection.
2836
+ $this->_sync_addons( true );
2837
+ }
2838
+
2839
+ $this->do_action( 'after_sync_cron' );
2840
+ }
2841
+
2842
+ /**
2843
+ * Check if sync was executed in the last $period of seconds.
2844
+ *
2845
+ * @author Vova Feldman (@svovaf)
2846
+ * @since 1.1.7.3
2847
+ *
2848
+ * @param int $period In seconds
2849
+ *
2850
+ * @return bool
2851
+ */
2852
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
2853
+ if ( ! isset( $this->_storage->sync_timestamp ) ) {
2854
+ return false;
2855
+ }
2856
+
2857
+ return ( $this->_storage->sync_timestamp > ( WP_FS__SCRIPT_START_TIME - $period ) );
2858
+ }
2859
+
2860
+ /**
2861
+ * @author Vova Feldman (@svovaf)
2862
+ * @since 1.1.7.3
2863
+ *
2864
+ * @return bool
2865
+ */
2866
+ private function is_sync_cron_on() {
2867
+ /**
2868
+ * @var object $sync_cron_data
2869
+ */
2870
+ $sync_cron_data = $this->_storage->get( 'sync_cron', null );
2871
+
2872
+ return ( ! is_null( $sync_cron_data ) && true === $sync_cron_data->on );
2873
+ }
2874
+
2875
+ /**
2876
+ * @author Vova Feldman (@svovaf)
2877
+ * @since 1.1.7.3
2878
+ *
2879
+ * @param int $start_at Defaults to now.
2880
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise,
2881
+ * schedule job to start right away.
2882
+ */
2883
+ private function schedule_sync_cron( $start_at = WP_FS__SCRIPT_START_TIME, $randomize_start = true ) {
2884
+ $this->_logger->entrance();
2885
+
2886
+ if ( $randomize_start ) {
2887
+ // Schedule first sync with a random 12 hour time range from now.
2888
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
2889
+ }
2890
+
2891
+ // Schedule daily WP cron.
2892
+ wp_schedule_event(
2893
+ $start_at,
2894
+ 'daily',
2895
+ $this->get_action_tag( 'data_sync' )
2896
+ );
2897
+
2898
+ $this->_storage->store( 'sync_cron', (object) array(
2899
+ 'version' => $this->get_plugin_version(),
2900
+ 'sdk_version' => $this->version,
2901
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
2902
+ 'on' => true,
2903
+ ) );
2904
+ }
2905
+
2906
+ /**
2907
+ * Add the actual sync function to the cron job hook.
2908
+ *
2909
+ * @author Vova Feldman (@svovaf)
2910
+ * @since 1.1.7.3
2911
+ */
2912
+ private function hook_callback_to_sync_cron() {
2913
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
2914
+ }
2915
+
2916
+ /**
2917
+ * @author Vova Feldman (@svovaf)
2918
+ * @since 1.1.7.3
2919
+ */
2920
+ private function clear_sync_cron() {
2921
+ $this->_logger->entrance();
2922
+
2923
+ if ( ! $this->is_sync_cron_on() ) {
2924
+ return;
2925
+ }
2926
+
2927
+ $this->_storage->remove( 'sync_cron' );
2928
+
2929
+ wp_clear_scheduled_hook( $this->get_action_tag( 'data_sync' ) );
2930
+ }
2931
+
2932
+ /**
2933
+ * Unix timestamp for next sync cron execution or false if not scheduled.
2934
+ *
2935
+ * @author Vova Feldman (@svovaf)
2936
+ * @since 1.1.7.3
2937
+ *
2938
+ * @return int|false
2939
+ */
2940
+ function next_sync_cron() {
2941
+ $this->_logger->entrance();
2942
+
2943
+ if ( ! $this->is_sync_cron_on() ) {
2944
+ return false;
2945
+ }
2946
+
2947
+ return wp_next_scheduled( $this->get_action_tag( 'data_sync' ) );
2948
+ }
2949
+
2950
+ /**
2951
+ * Unix timestamp for previous sync cron execution or false if never executed.
2952
+ *
2953
+ * @author Vova Feldman (@svovaf)
2954
+ * @since 1.1.7.3
2955
+ *
2956
+ * @return int|false
2957
+ */
2958
+ function last_sync_cron() {
2959
+ $this->_logger->entrance();
2960
+
2961
+ return $this->_storage->get( 'sync_timestamp' );
2962
+ }
2963
+
2964
+ #endregion Daily Sync Cron ------------------------------------------------------------------
2965
+
2966
+ #region Async Install Sync ------------------------------------------------------------------
2967
+
2968
+ /**
2969
+ * @author Vova Feldman (@svovaf)
2970
+ * @since 1.1.7.3
2971
+ *
2972
+ * @return bool
2973
+ */
2974
+ private function is_install_sync_scheduled() {
2975
+ /**
2976
+ * @var object $cron_data
2977
+ */
2978
+ $cron_data = $this->_storage->get( 'install_sync_cron', null );
2979
+
2980
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
2981
+ }
2982
+
2983
+ /**
2984
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
2985
+ *
2986
+ * @author Vova Feldman (@svovaf)
2987
+ * @since 1.1.7.3
2988
+ */
2989
+ private function schedule_install_sync() {
2990
+ $this->_logger->entrance();
2991
+
2992
+ $this->clear_install_sync_cron();
2993
+
2994
+ // Schedule immediate install sync.
2995
+ wp_schedule_single_event(
2996
+ WP_FS__SCRIPT_START_TIME,
2997
+ $this->get_action_tag( 'install_sync' )
2998
+ );
2999
+
3000
+ $this->_storage->store( 'install_sync_cron', (object) array(
3001
+ 'version' => $this->get_plugin_version(),
3002
+ 'sdk_version' => $this->version,
3003
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3004
+ 'on' => true,
3005
+ ) );
3006
+ }
3007
+
3008
+ /**
3009
+ * Unix timestamp for previous install sync cron execution or false if never executed.
3010
+ *
3011
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being
3012
+ * updated. But for sure the sync event is working.
3013
+ *
3014
+ * @author Vova Feldman (@svovaf)
3015
+ * @since 1.1.7.3
3016
+ *
3017
+ * @return int|false
3018
+ */
3019
+ function last_install_sync() {
3020
+ $this->_logger->entrance();
3021
+
3022
+ return $this->_storage->get( 'install_sync_timestamp' );
3023
+ }
3024
+
3025
+ /**
3026
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
3027
+ *
3028
+ * @author Vova Feldman (@svovaf)
3029
+ * @since 1.1.7.3
3030
+ *
3031
+ * @return int|false
3032
+ */
3033
+ function next_install_sync() {
3034
+ $this->_logger->entrance();
3035
+
3036
+ if ( ! $this->is_install_sync_scheduled() ) {
3037
+ return false;
3038
+ }
3039
+
3040
+ return wp_next_scheduled( $this->get_action_tag( 'install_sync' ) );
3041
+ }
3042
+
3043
+ /**
3044
+ * Add the actual install sync function to the cron job hook.
3045
+ *
3046
+ * @author Vova Feldman (@svovaf)
3047
+ * @since 1.1.7.3
3048
+ */
3049
+ private function hook_callback_to_install_sync() {
3050
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
3051
+ }
3052
+
3053
+ /**
3054
+ * @author Vova Feldman (@svovaf)
3055
+ * @since 1.1.7.3
3056
+ */
3057
+ private function clear_install_sync_cron() {
3058
+ $this->_logger->entrance();
3059
+
3060
+ if ( ! $this->is_install_sync_scheduled() ) {
3061
+ return;
3062
+ }
3063
+
3064
+ $this->_storage->remove( 'install_sync_cron' );
3065
+
3066
+ wp_clear_scheduled_hook( $this->get_action_tag( 'install_sync' ) );
3067
+ }
3068
+
3069
+ /**
3070
+ * @author Vova Feldman (@svovaf)
3071
+ * @since 1.1.7.3
3072
+ */
3073
+ public function _run_sync_install() {
3074
+ $this->_logger->entrance();
3075
+
3076
+ // Update last install sync timestamp.
3077
+ $this->_storage->install_sync_timestamp = time();
3078
+
3079
+ $this->sync_install( array(), true );
3080
+ }
3081
+
3082
+ #endregion Async Install Sync ------------------------------------------------------------------
3083
+
3084
+ /**
3085
+ * Show a notice that activation is currently pending.
3086
+ *
3087
+ * @author Vova Feldman (@svovaf)
3088
+ * @since 1.0.7
3089
+ *
3090
+ * @param bool|string $email
3091
+ */
3092
+ function _add_pending_activation_notice( $email = false ) {
3093
+ if ( ! is_string( $email ) ) {
3094
+ $current_user = self::_get_current_wp_user();
3095
+ $email = $current_user->user_email;
3096
+ }
3097
+
3098
+ $this->_admin_notices->add_sticky(
3099
+ sprintf(
3100
+ __fs( 'pending-activation-message', $this->_slug ),
3101
+ '<b>' . $this->get_plugin_name() . '</b>',
3102
+ '<b>' . $email . '</b>'
3103
+ ),
3104
+ 'activation_pending',
3105
+ 'Thanks!'
3106
+ );
3107
+ }
3108
+
3109
+ /**
3110
+ * Check if currently in plugin activation.
3111
+ *
3112
+ * @author Vova Feldman (@svovaf)
3113
+ * @since 1.1.4
3114
+ *
3115
+ * @return bool
3116
+ */
3117
+ function is_plugin_activation() {
3118
+ return get_option( "fs_{$this->_slug}_activated", false );
3119
+ }
3120
+
3121
+ /**
3122
+ *
3123
+ * NOTE: admin_menu action executed before admin_init.
3124
+ *
3125
+ * @author Vova Feldman (@svovaf)
3126
+ * @since 1.0.7
3127
+ */
3128
+ function _admin_init_action() {
3129
+ /**
3130
+ * Automatically redirect to connect/activation page after plugin activation.
3131
+ *
3132
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
3133
+ */
3134
+ if ( $this->is_plugin_activation() ) {
3135
+ delete_option( "fs_{$this->_slug}_activated" );
3136
+
3137
+ if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
3138
+ $this->_redirect_on_activation_hook();
3139
+
3140
+ return;
3141
+ }
3142
+ }
3143
+
3144
+ if ( fs_request_is_action( $this->_slug . '_skip_activation' ) ) {
3145
+ check_admin_referer( $this->_slug . '_skip_activation' );
3146
+
3147
+ $this->skip_connection();
3148
+
3149
+ if ( fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) ) ) {
3150
+ exit();
3151
+ }
3152
+ }
3153
+
3154
+ if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
3155
+ if ( ! $this->is_pending_activation() ) {
3156
+ if ( ! $this->_menu->is_activation_page() ) {
3157
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
3158
+ // Show notice for new plugin installations.
3159
+ $this->_admin_notices->add(
3160
+ sprintf(
3161
+ __fs( 'you-are-step-away', $this->_slug ),
3162
+ sprintf( '<b><a href="%s">%s</a></b>',
3163
+ $this->get_activation_url(),
3164
+ sprintf( __fs( 'activate-x-now', $this->_slug ), $this->get_plugin_name() )
3165
+ )
3166
+ ),
3167
+ '',
3168
+ 'update-nag'
3169
+ );
3170
+ } else {
3171
+ if ( ! isset( $this->_storage->sticky_optin_added ) ) {
3172
+ $this->_storage->sticky_optin_added = true;
3173
+
3174
+ // Show notice for new plugin installations.
3175
+ $this->_admin_notices->add_sticky(
3176
+ sprintf(
3177
+ __fs( 'few-plugin-tweaks', $this->_slug ),
3178
+ sprintf( '<b><a href="%s">%s</a></b>',
3179
+ $this->get_activation_url(),
3180
+ sprintf( __fs( 'optin-x-now', $this->_slug ), $this->get_plugin_name() )
3181
+ )
3182
+ ),
3183
+ 'connect_account',
3184
+ '',
3185
+ 'update-nag'
3186
+ );
3187
+ }
3188
+
3189
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
3190
+ // Don't show admin nag if plugin update.
3191
+ wp_enqueue_script( 'wp-pointer' );
3192
+ wp_enqueue_style( 'wp-pointer' );
3193
+
3194
+ $this->_enqueue_connect_essentials();
3195
+
3196
+ add_action( 'admin_print_footer_scripts', array(
3197
+ $this,
3198
+ '_add_connect_pointer_script'
3199
+ ) );
3200
+ }
3201
+
3202
+ }
3203
+ }
3204
+ }
3205
+ }
3206
+
3207
+ $this->_add_upgrade_action_link();
3208
+ }
3209
+
3210
+ /**
3211
+ * Enqueue connect requires scripts and styles.
3212
+ *
3213
+ * @author Vova Feldman (@svovaf)
3214
+ * @since 1.1.4
3215
+ */
3216
+ function _enqueue_connect_essentials() {
3217
+ wp_enqueue_script( 'jquery' );
3218
+ wp_enqueue_script( 'json2' );
3219
+
3220
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
3221
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
3222
+
3223
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
3224
+ }
3225
+
3226
+ /**
3227
+ * Add connect / opt-in pointer.
3228
+ *
3229
+ * @author Vova Feldman (@svovaf)
3230
+ * @since 1.1.4
3231
+ */
3232
+ function _add_connect_pointer_script() {
3233
+ $vars = array( 'slug' => $this->_slug );
3234
+ $pointer_content = fs_get_template( 'connect.php', $vars );
3235
+ ?>
3236
+ <script type="text/javascript">// <![CDATA[
3237
+ jQuery(document).ready(function ($) {
3238
+ if ('undefined' !== typeof(jQuery().pointer)) {
3239
+
3240
+ var element = <?php echo $this->apply_filters('optin_pointer_element', '$("#non_existing_element");') ?>;
3241
+
3242
+ if (element.length > 0) {
3243
+ var optin = $(element).pointer($.extend(true, {}, {
3244
+ content : <?php echo json_encode($pointer_content) ?>,
3245
+ position : {
3246
+ edge : 'left',
3247
+ align: 'center'
3248
+ },
3249
+ buttons : function () {
3250
+ // Don't show pointer buttons.
3251
+ return '';
3252
+ },
3253
+ pointerWidth: 482
3254
+ }, <?php echo $this->apply_filters('optin_pointer_options_json', '{}') ?>));
3255
+
3256
+ <?php
3257
+ echo $this->apply_filters('optin_pointer_execute', "
3258
+
3259
+ optin.pointer('open');
3260
+
3261
+ // Tag the opt-in pointer with custom class.
3262
+ $('.wp-pointer #fs_connect')
3263
+ .parents('.wp-pointer.wp-pointer-top')
3264
+ .addClass('fs-opt-in-pointer');
3265
+
3266
+ ", 'element', 'optin') ?>
3267
+ }
3268
+ }
3269
+ });
3270
+ // ]]></script>
3271
+ <?php
3272
+ }
3273
+
3274
+ /**
3275
+ * Return current page's URL.
3276
+ *
3277
+ * @author Vova Feldman (@svovaf)
3278
+ * @since 1.0.7
3279
+ *
3280
+ * @return string
3281
+ */
3282
+ function current_page_url() {
3283
+ $url = 'http';
3284
+
3285
+ if ( isset( $_SERVER["HTTPS"] ) ) {
3286
+ if ( $_SERVER["HTTPS"] == "on" ) {
3287
+ $url .= "s";
3288
+ }
3289
+ }
3290
+ $url .= "://";
3291
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
3292
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
3293
+ } else {
3294
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
3295
+ }
3296
+
3297
+ return esc_url( $url );
3298
+ }
3299
+
3300
+ /**
3301
+ * Check if the current page is the plugin's main admin settings page.
3302
+ *
3303
+ * @author Vova Feldman (@svovaf)
3304
+ * @since 1.0.7
3305
+ *
3306
+ * @return bool
3307
+ */
3308
+ function _is_plugin_page() {
3309
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
3310
+ fs_is_plugin_page( $this->_slug );
3311
+ }
3312
+
3313
+ /* Events
3314
+ ------------------------------------------------------------------------------------------------------------------*/
3315
+ /**
3316
+ * Delete site install from Database.
3317
+ *
3318
+ * @author Vova Feldman (@svovaf)
3319
+ * @since 1.0.1
3320
+ *
3321
+ * @param bool $store
3322
+ */
3323
+ function _delete_site( $store = true ) {
3324
+ $sites = self::get_all_sites();
3325
+
3326
+ if ( isset( $sites[ $this->_slug ] ) ) {
3327
+ unset( $sites[ $this->_slug ] );
3328
+ }
3329
+
3330
+ self::$_accounts->set_option( 'sites', $sites, $store );
3331
+ }
3332
+
3333
+ /**
3334
+ * Delete plugin's plans information.
3335
+ *
3336
+ * @param bool $store Flush to Database if true.
3337
+ *
3338
+ * @author Vova Feldman (@svovaf)
3339
+ * @since 1.0.9
3340
+ */
3341
+ private function _delete_plans( $store = true ) {
3342
+ $this->_logger->entrance();
3343
+
3344
+ $plans = self::get_all_plans();
3345
+
3346
+ unset( $plans[ $this->_slug ] );
3347
+
3348
+ self::$_accounts->set_option( 'plans', $plans, $store );
3349
+ }
3350
+
3351
+ /**
3352
+ * Delete all plugin licenses.
3353
+ *
3354
+ * @author Vova Feldman (@svovaf)
3355
+ * @since 1.0.9
3356
+ *
3357
+ * @param bool $store
3358
+ * @param string|bool $plugin_slug
3359
+ */
3360
+ private function _delete_licenses( $store = true, $plugin_slug = false ) {
3361
+ $this->_logger->entrance();
3362
+
3363
+ $all_licenses = self::get_all_licenses();
3364
+
3365
+ if ( ! is_string( $plugin_slug ) ) {
3366
+ $plugin_slug = $this->_slug;
3367
+ }
3368
+
3369
+ unset( $all_licenses[ $plugin_slug ] );
3370
+
3371
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
3372
+ }
3373
+
3374
+ /**
3375
+ * Check if Freemius was added on new plugin installation.
3376
+ *
3377
+ * @author Vova Feldman (@svovaf)
3378
+ * @since 1.1.5
3379
+ *
3380
+ * @return bool
3381
+ */
3382
+ function is_plugin_new_install() {
3383
+ return isset( $this->_storage->is_plugin_new_install ) &&
3384
+ $this->_storage->is_plugin_new_install;
3385
+ }
3386
+
3387
+ /**
3388
+ * Plugin activated hook.
3389
+ *
3390
+ * @author Vova Feldman (@svovaf)
3391
+ * @since 1.0.1
3392
+ *
3393
+ * @uses FS_Api
3394
+ */
3395
+ function _activate_plugin_event_hook() {
3396
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3397
+
3398
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3399
+ return;
3400
+ }
3401
+
3402
+ $this->unregister_uninstall_hook();
3403
+
3404
+ // Clear API cache on activation.
3405
+ FS_Api::clear_cache();
3406
+
3407
+ if ( $this->is_registered() ) {
3408
+ // Schedule re-activation event and sync.
3409
+ // $this->sync_install( array(), true );
3410
+ $this->schedule_install_sync();
3411
+
3412
+ /**
3413
+ * @todo Work on automatic deactivation of the Free plugin version. It doesn't work since the slug of the free & premium versions is identical. Therefore, only one instance of Freemius is created and the activation hook of the premium version is not being added.
3414
+ */
3415
+ if ( $this->_plugin_basename !== $this->_free_plugin_basename ) {
3416
+ // Deactivate Free plugin version on premium plugin activation.
3417
+ deactivate_plugins( $this->_free_plugin_basename );
3418
+
3419
+ $this->_admin_notices->add(
3420
+ sprintf( __fs( 'successful-version-upgrade-message', $this->_slug ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
3421
+ __fs( 'woot', $this->_slug ) . '!'
3422
+ );
3423
+ }
3424
+ } else if ( $this->is_anonymous() ) {
3425
+ /**
3426
+ * Reset "skipped" click cache on the following:
3427
+ * 1. Development mode.
3428
+ * 2. If the user skipped the exact same version before.
3429
+ *
3430
+ * @todo 3. If explicitly asked to retry after every activation.
3431
+ */
3432
+ if ( WP_FS__DEV_MODE ||
3433
+ $this->get_plugin_version() == $this->_storage->is_anonymous['version']
3434
+ ) {
3435
+ $this->reset_anonymous_mode();
3436
+ }
3437
+ }
3438
+
3439
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3440
+ /**
3441
+ * If no previous version of plugin's version exist, it means that it's either
3442
+ * the first time that the plugin installed on the site, or the plugin was installed
3443
+ * before but didn't have Freemius integrated.
3444
+ *
3445
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
3446
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
3447
+ * only after immediate activation.
3448
+ *
3449
+ * @since 1.1.4
3450
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
3451
+ */
3452
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
3453
+ }
3454
+
3455
+ if ( ! $this->_anonymous_mode && $this->has_api_connectivity( WP_FS__DEV_MODE ) ) {
3456
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
3457
+ add_option( "fs_{$this->_slug}_activated", true );
3458
+ }
3459
+
3460
+ /**
3461
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
3462
+ * after the plugin was loaded. The logic is located at activate_plugin()
3463
+ * ./wp-admin/includes/plugin.php.
3464
+ *
3465
+ * @author Vova Feldman (@svovaf)
3466
+ * @since 1.1.9
3467
+ */
3468
+ $this->_storage->was_plugin_loaded = true;
3469
+ }
3470
+
3471
+ /**
3472
+ * Delete account.
3473
+ *
3474
+ * @author Vova Feldman (@svovaf)
3475
+ * @since 1.0.3
3476
+ *
3477
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
3478
+ */
3479
+ function delete_account_event( $check_user = true ) {
3480
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3481
+
3482
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3483
+ return;
3484
+ }
3485
+
3486
+ $this->do_action( 'before_account_delete' );
3487
+
3488
+ // Clear all admin notices.
3489
+ $this->_admin_notices->clear_all_sticky();
3490
+
3491
+ $this->_delete_site( false );
3492
+
3493
+ $this->_delete_plans( false );
3494
+
3495
+ $this->_delete_licenses( false );
3496
+
3497
+ // Delete add-ons related to plugin's account.
3498
+ $this->_delete_account_addons( false );
3499
+
3500
+ // @todo Delete plans and licenses of add-ons.
3501
+
3502
+ self::$_accounts->store();
3503
+
3504
+ /**
3505
+ * IMPORTANT:
3506
+ * Clear crons must be executed before clearing all storage.
3507
+ * Otherwise, the cron will not be cleared.
3508
+ */
3509
+ $this->clear_sync_cron();
3510
+ $this->clear_install_sync_cron();
3511
+
3512
+ // Clear all storage data.
3513
+ $this->_storage->clear_all( true, array(
3514
+ 'connectivity_test',
3515
+ 'is_on',
3516
+ ) );
3517
+
3518
+ // Send delete event.
3519
+ $this->get_api_site_scope()->call( '/', 'delete' );
3520
+
3521
+ $this->do_action( 'after_account_delete' );
3522
+ }
3523
+
3524
+ /**
3525
+ * Plugin deactivation hook.
3526
+ *
3527
+ * @author Vova Feldman (@svovaf)
3528
+ * @since 1.0.1
3529
+ */
3530
+ function _deactivate_plugin_hook() {
3531
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3532
+
3533
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3534
+ return;
3535
+ }
3536
+
3537
+ $this->_admin_notices->clear_all_sticky();
3538
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
3539
+ unset( $this->_storage->sticky_optin_added );
3540
+ }
3541
+
3542
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3543
+ // Remember that plugin was already installed.
3544
+ $this->_storage->is_plugin_new_install = false;
3545
+ }
3546
+
3547
+ // Hook to plugin uninstall.
3548
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
3549
+
3550
+ $this->clear_module_main_file_cache();
3551
+ $this->clear_sync_cron();
3552
+ $this->clear_install_sync_cron();
3553
+
3554
+ if ( $this->is_registered() ) {
3555
+ // Send deactivation event.
3556
+ $this->sync_install( array(
3557
+ 'is_active' => false,
3558
+ ) );
3559
+ } else {
3560
+ if ( ! $this->has_api_connectivity() ) {
3561
+ // Reset connectivity test cache.
3562
+ unset( $this->_storage->connectivity_test );
3563
+ }
3564
+ }
3565
+
3566
+ // Clear API cache on deactivation.
3567
+ FS_Api::clear_cache();
3568
+
3569
+ $this->remove_sdk_reference();
3570
+ }
3571
+
3572
+ /**
3573
+ * @author Vova Feldman (@svovaf)
3574
+ * @since 1.1.6
3575
+ */
3576
+ private function remove_sdk_reference() {
3577
+ global $fs_active_plugins;
3578
+
3579
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
3580
+ if ( $this->_plugin_basename == $data->plugin_path ) {
3581
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
3582
+ break;
3583
+ }
3584
+ }
3585
+
3586
+ fs_fallback_to_newest_active_sdk();
3587
+ }
3588
+
3589
+ /**
3590
+ * @author Vova Feldman (@svovaf)
3591
+ * @since 1.1.3
3592
+ *
3593
+ * @param bool $is_anonymous
3594
+ */
3595
+ private function set_anonymous_mode( $is_anonymous = true ) {
3596
+ // Store information regarding skip to try and opt-in the user
3597
+ // again in the future.
3598
+ $this->_storage->is_anonymous = array(
3599
+ 'is' => $is_anonymous,
3600
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3601
+ 'version' => $this->get_plugin_version(),
3602
+ );
3603
+
3604
+ // Update anonymous mode cache.
3605
+ $this->_is_anonymous = $is_anonymous;
3606
+ }
3607
+
3608
+ /**
3609
+ * @author Vova Feldman (@svovaf)
3610
+ * @since 1.1.3
3611
+ */
3612
+ private function reset_anonymous_mode() {
3613
+ unset( $this->_storage->is_anonymous );
3614
+ }
3615
+
3616
+ /**
3617
+ * Clears the anonymous mode and redirects to the opt-in screen.
3618
+ *
3619
+ * @author Vova Feldman (@svovaf)
3620
+ * @since 1.1.7
3621
+ */
3622
+ function connect_again() {
3623
+ if ( ! $this->is_anonymous() ) {
3624
+ return;
3625
+ }
3626
+
3627
+ $this->reset_anonymous_mode();
3628
+
3629
+ if ( fs_redirect( $this->get_activation_url() ) ) {
3630
+ exit();
3631
+ }
3632
+ }
3633
+
3634
+ /**
3635
+ * Skip account connect, and set anonymous mode.
3636
+ *
3637
+ * @author Vova Feldman (@svovaf)
3638
+ * @since 1.1.1
3639
+ */
3640
+ private function skip_connection() {
3641
+ $this->_logger->entrance();
3642
+
3643
+ $this->_admin_notices->remove_sticky( 'connect_account' );
3644
+
3645
+ $this->set_anonymous_mode();
3646
+
3647
+ // Send anonymous skip event.
3648
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
3649
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
3650
+ 'uid' => $this->get_anonymous_id(),
3651
+ ) );
3652
+ }
3653
+
3654
+ /**
3655
+ * Plugin version update hook.
3656
+ *
3657
+ * @author Vova Feldman (@svovaf)
3658
+ * @since 1.0.4
3659
+ */
3660
+ private function update_plugin_version_event() {
3661
+ $this->_logger->entrance();
3662
+
3663
+ if ( ! $this->is_registered() ) {
3664
+ return;
3665
+ }
3666
+
3667
+ $this->schedule_install_sync();
3668
+ // $this->sync_install( array(), true );
3669
+ }
3670
+
3671
+ /**
3672
+ * Return a list of modified plugins since the last sync.
3673
+ *
3674
+ * Note:
3675
+ * There's no point to store a plugins counter since even if the number of
3676
+ * plugins didn't change, we still need to check if the versions are all the
3677
+ * same and the activity state is similar.
3678
+ *
3679
+ * @author Vova Feldman (@svovaf)
3680
+ * @since 1.1.8
3681
+ *
3682
+ * @return array|false
3683
+ */
3684
+ private function get_plugins_data_for_api() {
3685
+ // Alias.
3686
+ $option_name = 'all_plugins';
3687
+
3688
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
3689
+
3690
+ if ( ! is_object( $all_cached_plugins ) ) {
3691
+ $all_cached_plugins = (object) array(
3692
+ 'timestamp' => '',
3693
+ 'md5' => '',
3694
+ 'plugins' => array(),
3695
+ );
3696
+ }
3697
+
3698
+ $time = time();
3699
+
3700
+ if ( ! empty( $all_cached_plugins->timestamp ) &&
3701
+ ( $time - $all_cached_plugins->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3702
+ ) {
3703
+ // Don't send plugin updates if last update was in the past 5 min.
3704
+ return false;
3705
+ }
3706
+
3707
+ // Write timestamp to lock the logic.
3708
+ $all_cached_plugins->timestamp = $time;
3709
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3710
+
3711
+ // Reload options from DB.
3712
+ self::$_accounts->load( true );
3713
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
3714
+
3715
+ if ( $time != $all_cached_plugins->timestamp ) {
3716
+ // If timestamp is different, then another thread captured the lock.
3717
+ return false;
3718
+ }
3719
+
3720
+ // Check if there's a change in plugins.
3721
+ $all_plugins = self::get_all_plugins();
3722
+
3723
+ // Check if plugins changed.
3724
+ ksort( $all_plugins );
3725
+
3726
+ $plugins_signature = '';
3727
+ foreach ( $all_plugins as $basename => $data ) {
3728
+ $plugins_signature .= $data['slug'] . ',' .
3729
+ $data['Version'] . ',' .
3730
+ ( $data['is_active'] ? '1' : '0' ) . ';';
3731
+ }
3732
+
3733
+ // Check if plugins status changed (version or active/inactive).
3734
+ $plugins_changed = ( $all_cached_plugins->md5 !== md5( $plugins_signature ) );
3735
+
3736
+ $plugins_update_data = array();
3737
+
3738
+ if ( $plugins_changed ) {
3739
+ // Change in plugins, report changes.
3740
+
3741
+ // Update existing plugins info.
3742
+ foreach ( $all_cached_plugins->plugins as $basename => $data ) {
3743
+ if ( ! isset( $all_plugins[ $basename ] ) ) {
3744
+ // Plugin uninstalled.
3745
+ $uninstalled_plugin_data = $data;
3746
+ $uninstalled_plugin_data['is_active'] = false;
3747
+ $uninstalled_plugin_data['is_uninstalled'] = true;
3748
+ $plugins_update_data[] = $uninstalled_plugin_data;
3749
+
3750
+ unset( $all_plugins[ $basename ] );
3751
+ unset( $all_cached_plugins->plugins[ $basename ] );
3752
+ } else if ( $data['is_active'] !== $all_plugins[ $basename ]['is_active'] ||
3753
+ $data['version'] !== $all_plugins[ $basename ]['Version']
3754
+ ) {
3755
+ // Plugin activated or deactivated, or version changed.
3756
+ $all_cached_plugins->plugins[ $basename ]['is_active'] = $all_plugins[ $basename ]['is_active'];
3757
+ $all_cached_plugins->plugins[ $basename ]['version'] = $all_plugins[ $basename ]['Version'];
3758
+
3759
+ $plugins_update_data[] = $all_cached_plugins->plugins[ $basename ];
3760
+ }
3761
+ }
3762
+
3763
+ // Find new plugins that weren't yet seen before.
3764
+ foreach ( $all_plugins as $basename => $data ) {
3765
+ if ( ! isset( $all_cached_plugins->plugins[ $basename ] ) ) {
3766
+ // New plugin.
3767
+ $new_plugin = array(
3768
+ 'slug' => $data['slug'],
3769
+ 'version' => $data['Version'],
3770
+ 'title' => $data['Name'],
3771
+ 'is_active' => $data['is_active'],
3772
+ 'is_uninstalled' => false,
3773
+ );
3774
+
3775
+ $plugins_update_data[] = $new_plugin;
3776
+ $all_cached_plugins->plugins[ $basename ] = $new_plugin;
3777
+ }
3778
+ }
3779
+
3780
+ $all_cached_plugins->md5 = md5( $plugins_signature );
3781
+ $all_cached_plugins->timestamp = $time;
3782
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3783
+ }
3784
+
3785
+ return $plugins_update_data;
3786
+ }
3787
+
3788
+ /**
3789
+ * Return a list of modified themes since the last sync.
3790
+ *
3791
+ * Note:
3792
+ * There's no point to store a themes counter since even if the number of
3793
+ * themes didn't change, we still need to check if the versions are all the
3794
+ * same and the activity state is similar.
3795
+ *
3796
+ * @author Vova Feldman (@svovaf)
3797
+ * @since 1.1.8
3798
+ *
3799
+ * @return array|false
3800
+ */
3801
+ private function get_themes_data_for_api() {
3802
+ // Alias.
3803
+ $option_name = 'all_themes';
3804
+
3805
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
3806
+
3807
+ if ( ! is_object( $all_cached_themes ) ) {
3808
+ $all_cached_themes = (object) array(
3809
+ 'timestamp' => '',
3810
+ 'md5' => '',
3811
+ 'themes' => array(),
3812
+ );
3813
+ }
3814
+
3815
+ $time = time();
3816
+
3817
+ if ( ! empty( $all_cached_themes->timestamp ) &&
3818
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3819
+ ) {
3820
+ // Don't send theme updates if last update was in the past 5 min.
3821
+ return false;
3822
+ }
3823
+
3824
+ // Write timestamp to lock the logic.
3825
+ $all_cached_themes->timestamp = $time;
3826
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3827
+
3828
+ // Reload options from DB.
3829
+ self::$_accounts->load( true );
3830
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
3831
+
3832
+ if ( $time != $all_cached_themes->timestamp ) {
3833
+ // If timestamp is different, then another thread captured the lock.
3834
+ return false;
3835
+ }
3836
+
3837
+ // Get active theme.
3838
+ $active_theme = wp_get_theme();
3839
+
3840
+ // Check if there's a change in themes.
3841
+ $all_themes = wp_get_themes();
3842
+
3843
+ // Check if themes changed.
3844
+ ksort( $all_themes );
3845
+
3846
+ $themes_signature = '';
3847
+ foreach ( $all_themes as $slug => $data ) {
3848
+ $is_active = ( $slug === $active_theme->stylesheet );
3849
+ $themes_signature .= $slug . ',' .
3850
+ $data->version . ',' .
3851
+ ( $is_active ? '1' : '0' ) . ';';
3852
+ }
3853
+
3854
+ // Check if themes status changed (version or active/inactive).
3855
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
3856
+
3857
+ $themes_update_data = array();
3858
+
3859
+ if ( $themes_changed ) {
3860
+ // Change in themes, report changes.
3861
+
3862
+ // Update existing themes info.
3863
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
3864
+ $is_active = ( $slug === $active_theme->stylesheet );
3865
+
3866
+ if ( ! isset( $all_themes[ $slug ] ) ) {
3867
+ // Plugin uninstalled.
3868
+ $uninstalled_theme_data = $data;
3869
+ $uninstalled_theme_data['is_active'] = false;
3870
+ $uninstalled_theme_data['is_uninstalled'] = true;
3871
+ $themes_update_data[] = $uninstalled_theme_data;
3872
+
3873
+ unset( $all_themes[ $slug ] );
3874
+ unset( $all_cached_themes->themes[ $slug ] );
3875
+ } else if ( $data['is_active'] !== $is_active ||
3876
+ $data['version'] !== $all_themes[ $slug ]->version
3877
+ ) {
3878
+ // Plugin activated or deactivated, or version changed.
3879
+
3880
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
3881
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
3882
+
3883
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
3884
+ }
3885
+ }
3886
+
3887
+ // Find new themes that weren't yet seen before.
3888
+ foreach ( $all_themes as $slug => $data ) {
3889
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
3890
+ $is_active = ( $slug === $active_theme->stylesheet );
3891
+
3892
+ // New plugin.
3893
+ $new_plugin = array(
3894
+ 'slug' => $slug,
3895
+ 'version' => $data->version,
3896
+ 'title' => $data->name,
3897
+ 'is_active' => $is_active,
3898
+ 'is_uninstalled' => false,
3899
+ );
3900
+
3901
+ $themes_update_data[] = $new_plugin;
3902
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
3903
+ }
3904
+ }
3905
+
3906
+ $all_cached_themes->md5 = md5( $themes_signature );
3907
+ $all_cached_themes->timestamp = time();
3908
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3909
+ }
3910
+
3911
+ return $themes_update_data;
3912
+ }
3913
+
3914
+ /**
3915
+ * Update install details.
3916
+ *
3917
+ * @author Vova Feldman (@svovaf)
3918
+ * @since 1.1.2
3919
+ *
3920
+ * @param string[] string $override
3921
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
3922
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
3923
+ *
3924
+ * @return array
3925
+ */
3926
+ private function get_install_data_for_api(
3927
+ array $override,
3928
+ $include_plugins = true,
3929
+ $include_themes = true
3930
+ ) {
3931
+ /**
3932
+ * @since 1.1.8 Also send plugin updates.
3933
+ */
3934
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
3935
+ $plugins = $this->get_plugins_data_for_api();
3936
+ if ( ! empty( $plugins ) ) {
3937
+ $override['plugins'] = $plugins;
3938
+ }
3939
+ }
3940
+ /**
3941
+ * @since 1.1.8 Also send themes updates.
3942
+ */
3943
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
3944
+ $themes = $this->get_themes_data_for_api();
3945
+ if ( ! empty( $themes ) ) {
3946
+ $override['themes'] = $themes;
3947
+ }
3948
+ }
3949
+
3950
+ return array_merge( array(
3951
+ 'version' => $this->get_plugin_version(),
3952
+ 'is_premium' => $this->is_premium(),
3953
+ 'language' => get_bloginfo( 'language' ),
3954
+ 'charset' => get_bloginfo( 'charset' ),
3955
+ 'platform_version' => get_bloginfo( 'version' ),
3956
+ 'programming_language_version' => phpversion(),
3957
+ 'title' => get_bloginfo( 'name' ),
3958
+ 'url' => get_site_url(),
3959
+ // Special params.
3960
+ 'is_active' => true,
3961
+ 'is_uninstalled' => false,
3962
+ ), $override );
3963
+ }
3964
+
3965
+ /**
3966
+ * Update install only if changed.
3967
+ *
3968
+ * @author Vova Feldman (@svovaf)
3969
+ * @since 1.0.9
3970
+ *
3971
+ * @param string[] string $override
3972
+ * @param bool $flush
3973
+ *
3974
+ * @return false|object|string
3975
+ */
3976
+ private function send_install_update( $override = array(), $flush = false ) {
3977
+ $this->_logger->entrance();
3978
+
3979
+ $check_properties = $this->get_install_data_for_api( $override );
3980
+
3981
+ if ( $flush ) {
3982
+ $params = $check_properties;
3983
+ } else {
3984
+ $params = array();
3985
+ $special = array();
3986
+ $special_override = false;
3987
+
3988
+ foreach ( $check_properties as $p => $v ) {
3989
+ if ( property_exists( $this->_site, $p ) ) {
3990
+ if ( ! empty( $this->_site->{$p} ) &&
3991
+ $this->_site->{$p} != $v
3992
+ ) {
3993
+ $this->_site->{$p} = $v;
3994
+ $params[ $p ] = $v;
3995
+ }
3996
+ } else {
3997
+ $special[ $p ] = $v;
3998
+
3999
+ if ( isset( $override[ $p ] ) ||
4000
+ 'plugins' === $p ||
4001
+ 'themes' === $p
4002
+ ) {
4003
+ $special_override = true;
4004
+ }
4005
+ }
4006
+ }
4007
+
4008
+ if ( $special_override || 0 < count( $params ) ) {
4009
+ // Add special params only if has at least one
4010
+ // standard param, or if explicitly requested to
4011
+ // override a special param or a param which is not exist
4012
+ // in the install object.
4013
+ $params = array_merge( $params, $special );
4014
+ }
4015
+ }
4016
+
4017
+ if ( 0 < count( $params ) ) {
4018
+ // Update last install sync timestamp.
4019
+ $this->_storage->install_sync_timestamp = time();
4020
+
4021
+ $params['uid'] = $this->get_anonymous_id();
4022
+
4023
+ // Send updated values to FS.
4024
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
4025
+
4026
+ if ( ! $this->is_api_error( $site ) ) {
4027
+ // I successfully sent install update, clear scheduled sync if exist.
4028
+ $this->clear_install_sync_cron();
4029
+ }
4030
+
4031
+ return $site;
4032
+ }
4033
+
4034
+ return false;
4035
+ }
4036
+
4037
+ /**
4038
+ * Update install only if changed.
4039
+ *
4040
+ * @author Vova Feldman (@svovaf)
4041
+ * @since 1.0.9
4042
+ *
4043
+ * @param string[] string $override
4044
+ * @param bool $flush
4045
+ *
4046
+ * @return false|object|string
4047
+ */
4048
+ private function sync_install( $override = array(), $flush = false ) {
4049
+ $this->_logger->entrance();
4050
+
4051
+ $site = $this->send_install_update( $override, $flush );
4052
+
4053
+ if ( false === $site ) {
4054
+ // No sync required.
4055
+ return;
4056
+ }
4057
+
4058
+ if ( $this->is_api_error( $site ) ) {
4059
+ // Failed to sync, don't update locally.
4060
+ return;
4061
+ }
4062
+
4063
+ $plan = $this->get_plan();
4064
+ $this->_site = new FS_Site( $site );
4065
+ $this->_site->plan = $plan;
4066
+
4067
+ $this->_store_site( true );
4068
+ }
4069
+
4070
+ /**
4071
+ * Plugin uninstall hook.
4072
+ *
4073
+ * @author Vova Feldman (@svovaf)
4074
+ * @since 1.0.1
4075
+ *
4076
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
4077
+ */
4078
+ function _uninstall_plugin_event( $check_user = true ) {
4079
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
4080
+
4081
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
4082
+ return;
4083
+ }
4084
+
4085
+ $params = array();
4086
+ if ( isset( $this->_storage->uninstall_reason ) ) {
4087
+ $params['reason_id'] = $this->_storage->uninstall_reason->id;
4088
+ $params['reason_info'] = $this->_storage->uninstall_reason->info;
4089
+ }
4090
+
4091
+ if ( ! $this->is_registered() && isset( $this->_storage->uninstall_reason ) ) {
4092
+ // Send anonymous uninstall event only if user submitted a feedback.
4093
+ $params['uid'] = $this->get_anonymous_id();
4094
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
4095
+ } else {
4096
+ // Send uninstall event.
4097
+ $this->send_install_update( array_merge( $params, array(
4098
+ 'is_active' => false,
4099
+ 'is_uninstalled' => true,
4100
+ ) ) );
4101
+ }
4102
+
4103
+ // @todo Decide if we want to delete plugin information from db.
4104
+ }
4105
+
4106
+ /**
4107
+ * @author Vova Feldman (@svovaf)
4108
+ * @since 1.1.1
4109
+ *
4110
+ * @return string
4111
+ */
4112
+ private function premium_plugin_basename() {
4113
+ return preg_replace( '/\//', '-premium/', $this->_free_plugin_basename, 1 );
4114
+ }
4115
+
4116
+ /**
4117
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
4118
+ *
4119
+ * @author Vova Feldman (@svovaf)
4120
+ * @since 1.0.2
4121
+ */
4122
+ public static function _uninstall_plugin_hook() {
4123
+ self::_load_required_static();
4124
+
4125
+ self::$_static_logger->entrance();
4126
+
4127
+ if ( ! current_user_can( 'activate_plugins' ) ) {
4128
+ return;
4129
+ }
4130
+
4131
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
4132
+
4133
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
4134
+
4135
+ define( 'WP_FS__UNINSTALL_MODE', true );
4136
+
4137
+ $fs = self::get_instance_by_file( $plugin_file );
4138
+
4139
+ if ( is_object( $fs ) ) {
4140
+ self::require_plugin_essentials();
4141
+
4142
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
4143
+ is_plugin_active( $fs->premium_plugin_basename() )
4144
+ ) {
4145
+ // Deleting Free or Premium plugin version while the other version still installed.
4146
+ return;
4147
+ }
4148
+
4149
+ $fs->_uninstall_plugin_event();
4150
+
4151
+ $fs->do_action( 'after_uninstall' );
4152
+ }
4153
+ }
4154
+
4155
+ #region Plugin Information ------------------------------------------------------------------
4156
+
4157
+ /**
4158
+ * Load WordPress core plugin.php essential module.
4159
+ *
4160
+ * @author Vova Feldman (@svovaf)
4161
+ * @since 1.1.1
4162
+ */
4163
+ private static function require_plugin_essentials() {
4164
+ if ( ! function_exists( 'get_plugins' ) ) {
4165
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
4166
+ }
4167
+ }
4168
+
4169
+ /**
4170
+ * Load WordPress core pluggable.php module.
4171
+ *
4172
+ * @author Vova Feldman (@svovaf)
4173
+ * @since 1.1.2
4174
+ */
4175
+ private static function require_pluggable_essentials() {
4176
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
4177
+ require_once( ABSPATH . 'wp-includes/pluggable.php' );
4178
+ }
4179
+ }
4180
+
4181
+ /**
4182
+ * Return plugin data.
4183
+ *
4184
+ * @author Vova Feldman (@svovaf)
4185
+ * @since 1.0.1
4186
+ *
4187
+ * @return array
4188
+ */
4189
+ function get_plugin_data() {
4190
+ if ( ! isset( $this->_plugin_data ) ) {
4191
+ self::require_plugin_essentials();
4192
+
4193
+ /**
4194
+ * @author Vova Feldman (@svovaf)
4195
+ * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
4196
+ *
4197
+ * @link https://github.com/Freemius/wordpress-sdk/issues/77
4198
+ */
4199
+ $this->_plugin_data = get_plugin_data(
4200
+ $this->_plugin_main_file_path,
4201
+ false,
4202
+ false
4203
+ );
4204
+ }
4205
+
4206
+ return $this->_plugin_data;
4207
+ }
4208
+
4209
+ /**
4210
+ * @author Vova Feldman (@svovaf)
4211
+ * @since 1.0.1
4212
+ *
4213
+ * @return string Plugin slug.
4214
+ */
4215
+ function get_slug() {
4216
+ return $this->_slug;
4217
+ }
4218
+
4219
+ /**
4220
+ * @author Vova Feldman (@svovaf)
4221
+ * @since 1.0.1
4222
+ *
4223
+ * @return number Plugin ID.
4224
+ */
4225
+ function get_id() {
4226
+ return $this->_plugin->id;
4227
+ }
4228
+
4229
+ /**
4230
+ * @author Vova Feldman (@svovaf)
4231
+ * @since 1.0.1
4232
+ *
4233
+ * @return string Plugin public key.
4234
+ */
4235
+ function get_public_key() {
4236
+ return $this->_plugin->public_key;
4237
+ }
4238
+
4239
+ /**
4240
+ * Will be available only on sandbox mode.
4241
+ *
4242
+ * @author Vova Feldman (@svovaf)
4243
+ * @since 1.0.4
4244
+ *
4245
+ * @return mixed Plugin secret key.
4246
+ */
4247
+ function get_secret_key() {
4248
+ return $this->_plugin->secret_key;
4249
+ }
4250
+
4251
+ /**
4252
+ * @author Vova Feldman (@svovaf)
4253
+ * @since 1.1.1
4254
+ *
4255
+ * @return bool
4256
+ */
4257
+ function has_secret_key() {
4258
+ return ! empty( $this->_plugin->secret_key );
4259
+ }
4260
+
4261
+ /**
4262
+ * @author Vova Feldman (@svovaf)
4263
+ * @since 1.0.9
4264
+ *
4265
+ * @return string
4266
+ */
4267
+ function get_plugin_name() {
4268
+ $this->_logger->entrance();
4269
+
4270
+ if ( ! isset( $this->_plugin_name ) ) {
4271
+ $plugin_data = $this->get_plugin_data();
4272
+
4273
+ // Get name.
4274
+ $this->_plugin_name = $plugin_data['Name'];
4275
+
4276
+ // Check if plugin name contains [Premium] suffix and remove it.
4277
+ $suffix = '[premium]';
4278
+ $suffix_len = strlen( $suffix );
4279
+
4280
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
4281
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
4282
+ ) {
4283
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
4284
+ }
4285
+
4286
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
4287
+ }
4288
+
4289
+ return $this->_plugin_name;
4290
+ }
4291
+
4292
+ /**
4293
+ * @author Vova Feldman (@svovaf)
4294
+ * @since 1.0.0
4295
+ *
4296
+ * @return string
4297
+ */
4298
+ function get_plugin_version() {
4299
+ $this->_logger->entrance();
4300
+
4301
+ $plugin_data = $this->get_plugin_data();
4302
+
4303
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
4304
+
4305
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
4306
+ }
4307
+
4308
+ /**
4309
+ * @author Vova Feldman (@svovaf)
4310
+ * @since 1.0.4
4311
+ *
4312
+ * @return string
4313
+ */
4314
+ function get_plugin_basename() {
4315
+ return $this->_plugin_basename;
4316
+ }
4317
+
4318
+ function get_plugin_folder_name() {
4319
+ $this->_logger->entrance();
4320
+
4321
+ $plugin_folder = $this->_plugin_basename;
4322
+
4323
+ while ( '.' !== dirname( $plugin_folder ) ) {
4324
+ $plugin_folder = dirname( $plugin_folder );
4325
+ }
4326
+
4327
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
4328
+
4329
+ return $plugin_folder;
4330
+ }
4331
+
4332
+ #endregion ------------------------------------------------------------------
4333
+
4334
+ /* Account
4335
+ ------------------------------------------------------------------------------------------------------------------*/
4336
+
4337
+ /**
4338
+ * Find plugin's slug by plugin's basename.
4339
+ *
4340
+ * @author Vova Feldman (@svovaf)
4341
+ * @since 1.0.9
4342
+ *
4343
+ * @param string $plugin_base_name
4344
+ *
4345
+ * @return false|string
4346
+ */
4347
+ private static function find_slug_by_basename( $plugin_base_name ) {
4348
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4349
+
4350
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
4351
+ return false;
4352
+ }
4353
+
4354
+ return $file_slug_map[ $plugin_base_name ];
4355
+ }
4356
+
4357
+ /**
4358
+ * Store the map between the plugin's basename to the slug.
4359
+ *
4360
+ * @author Vova Feldman (@svovaf)
4361
+ * @since 1.0.9
4362
+ */
4363
+ private function store_file_slug_map() {
4364
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4365
+
4366
+ if ( ! array( $file_slug_map ) ) {
4367
+ $file_slug_map = array();
4368
+ }
4369
+
4370
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
4371
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
4372
+ ) {
4373
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
4374
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
4375
+ }
4376
+ }
4377
+
4378
+ /**
4379
+ * @return FS_User[]
4380
+ */
4381
+ static function get_all_users() {
4382
+ $users = self::$_accounts->get_option( 'users', array() );
4383
+
4384
+ if ( ! is_array( $users ) ) {
4385
+ $users = array();
4386
+ }
4387
+
4388
+ return $users;
4389
+ }
4390
+
4391
+ /**
4392
+ * @return FS_Site[]
4393
+ */
4394
+ private static function get_all_sites() {
4395
+ $sites = self::$_accounts->get_option( 'sites', array() );
4396
+
4397
+ if ( ! is_array( $sites ) ) {
4398
+ $sites = array();
4399
+ }
4400
+
4401
+ return $sites;
4402
+ }
4403
+
4404
+ /**
4405
+ * @author Vova Feldman (@svovaf)
4406
+ * @since 1.0.6
4407
+ *
4408
+ * @return FS_Plugin_License[]
4409
+ */
4410
+ private static function get_all_licenses() {
4411
+ $licenses = self::$_accounts->get_option( 'licenses', array() );
4412
+
4413
+ if ( ! is_array( $licenses ) ) {
4414
+ $licenses = array();
4415
+ }
4416
+
4417
+ return $licenses;
4418
+ }
4419
+
4420
+ /**
4421
+ * @return FS_Plugin_Plan[]
4422
+ */
4423
+ private static function get_all_plans() {
4424
+ $plans = self::$_accounts->get_option( 'plans', array() );
4425
+
4426
+ if ( ! is_array( $plans ) ) {
4427
+ $plans = array();
4428
+ }
4429
+
4430
+ return $plans;
4431
+ }
4432
+
4433
+ /**
4434
+ * @author Vova Feldman (@svovaf)
4435
+ * @since 1.0.4
4436
+ *
4437
+ * @return FS_Plugin_Tag[]
4438
+ */
4439
+ private static function get_all_updates() {
4440
+ $updates = self::$_accounts->get_option( 'updates', array() );
4441
+
4442
+ if ( ! is_array( $updates ) ) {
4443
+ $updates = array();
4444
+ }
4445
+
4446
+ return $updates;
4447
+ }
4448
+
4449
+ /**
4450
+ * @author Vova Feldman (@svovaf)
4451
+ * @since 1.0.6
4452
+ *
4453
+ * @return FS_Plugin[]|false
4454
+ */
4455
+ private static function get_all_addons() {
4456
+ $addons = self::$_accounts->get_option( 'addons', array() );
4457
+
4458
+ if ( ! is_array( $addons ) ) {
4459
+ $addons = array();
4460
+ }
4461
+
4462
+ return $addons;
4463
+ }
4464
+
4465
+ /**
4466
+ * @author Vova Feldman (@svovaf)
4467
+ * @since 1.0.6
4468
+ *
4469
+ * @return FS_Plugin[]|false
4470
+ */
4471
+ private static function get_all_account_addons() {
4472
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
4473
+
4474
+ if ( ! is_array( $addons ) ) {
4475
+ $addons = array();
4476
+ }
4477
+
4478
+ return $addons;
4479
+ }
4480
+
4481
+ /**
4482
+ * Check if user is registered.
4483
+ *
4484
+ * @author Vova Feldman (@svovaf)
4485
+ * @since 1.0.1
4486
+ * @return bool
4487
+ */
4488
+ function is_registered() {
4489
+ return is_object( $this->_user );
4490
+ }
4491
+
4492
+ /**
4493
+ * @author Vova Feldman (@svovaf)
4494
+ * @since 1.0.4
4495
+ *
4496
+ * @return FS_Plugin
4497
+ */
4498
+ function get_plugin() {
4499
+ return $this->_plugin;
4500
+ }
4501
+
4502
+ /**
4503
+ * @author Vova Feldman (@svovaf)
4504
+ * @since 1.0.3
4505
+ *
4506
+ * @return FS_User
4507
+ */
4508
+ function get_user() {
4509
+ return $this->_user;
4510
+ }
4511
+
4512
+ /**
4513
+ * @author Vova Feldman (@svovaf)
4514
+ * @since 1.0.3
4515
+ *
4516
+ * @return FS_Site
4517
+ */
4518
+ function get_site() {
4519
+ return $this->_site;
4520
+ }
4521
+
4522
+ /**
4523
+ * Get plugin add-ons.
4524
+ *
4525
+ * @author Vova Feldman (@svovaf)
4526
+ * @since 1.0.6
4527
+ *
4528
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4529
+ *
4530
+ * @return FS_Plugin[]|false
4531
+ */
4532
+ function get_addons() {
4533
+ $this->_logger->entrance();
4534
+
4535
+ $all_addons = self::get_all_addons();
4536
+
4537
+ /**
4538
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4539
+ */
4540
+ if ( ! is_array( $all_addons ) ||
4541
+ ! isset( $all_addons[ $this->_plugin->id ] ) ||
4542
+ ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4543
+ empty( $all_addons[ $this->_plugin->id ] )
4544
+ ) {
4545
+ if ( $this->_has_addons ) {
4546
+ $addons = $this->_sync_addons();
4547
+
4548
+ if ( ! empty( $addons ) ) {
4549
+ $all_addons = self::get_all_addons();
4550
+ }
4551
+ }
4552
+ }
4553
+
4554
+ if ( ! is_array( $all_addons ) ||
4555
+ ! isset( $all_addons[ $this->_plugin->id ] ) ||
4556
+ ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4557
+ empty( $all_addons[ $this->_plugin->id ] )
4558
+ ) {
4559
+ return false;
4560
+ }
4561
+
4562
+ return $all_addons[ $this->_plugin->id ];
4563
+ }
4564
+
4565
+ /**
4566
+ * @author Vova Feldman (@svovaf)
4567
+ * @since 1.0.6
4568
+ *
4569
+ * @return FS_Plugin[]|false
4570
+ */
4571
+ function get_account_addons() {
4572
+ $this->_logger->entrance();
4573
+
4574
+ $addons = self::get_all_account_addons();
4575
+
4576
+ if ( ! is_array( $addons ) ||
4577
+ ! isset( $addons[ $this->_plugin->id ] ) ||
4578
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
4579
+ 0 === count( $addons[ $this->_plugin->id ] )
4580
+ ) {
4581
+ return false;
4582
+ }
4583
+
4584
+ return $addons[ $this->_plugin->id ];
4585
+ }
4586
+
4587
+ /**
4588
+ * Check if user has any
4589
+ *
4590
+ * @author Vova Feldman (@svovaf)
4591
+ * @since 1.1.6
4592
+ *
4593
+ * @return bool
4594
+ */
4595
+ function has_account_addons() {
4596
+ $addons = $this->get_account_addons();
4597
+
4598
+ return is_array( $addons ) && ( 0 < count( $addons ) );
4599
+ }
4600
+
4601
+
4602
+ /**
4603
+ * Get add-on by ID (from local data).
4604
+ *
4605
+ * @author Vova Feldman (@svovaf)
4606
+ * @since 1.0.6
4607
+ *
4608
+ * @param number $id
4609
+ *
4610
+ * @return FS_Plugin|false
4611
+ */
4612
+ function get_addon( $id ) {
4613
+ $this->_logger->entrance();
4614
+
4615
+ $addons = $this->get_addons();
4616
+
4617
+ if ( is_array( $addons ) ) {
4618
+ foreach ( $addons as $addon ) {
4619
+ if ( $id == $addon->id ) {
4620
+ return $addon;
4621
+ }
4622
+ }
4623
+ }
4624
+
4625
+ return false;
4626
+ }
4627
+
4628
+ /**
4629
+ * Get add-on by slug (from local data).
4630
+ *
4631
+ * @author Vova Feldman (@svovaf)
4632
+ * @since 1.0.6
4633
+ *
4634
+ * @param string $slug
4635
+ *
4636
+ * @return FS_Plugin|false
4637
+ */
4638
+ function get_addon_by_slug( $slug ) {
4639
+ $this->_logger->entrance();
4640
+
4641
+ $addons = $this->get_addons();
4642
+
4643
+ if ( is_array( $addons ) ) {
4644
+ foreach ( $addons as $addon ) {
4645
+ if ( $slug == $addon->slug ) {
4646
+ return $addon;
4647
+ }
4648
+ }
4649
+ }
4650
+
4651
+ return false;
4652
+ }
4653
+
4654
+ #region Plans & Licensing ------------------------------------------------------------------
4655
+
4656
+ /**
4657
+ * Check if running premium plugin code.
4658
+ *
4659
+ * @author Vova Feldman (@svovaf)
4660
+ * @since 1.0.5
4661
+ *
4662
+ * @return bool
4663
+ */
4664
+ function is_premium() {
4665
+ return $this->_plugin->is_premium;
4666
+ }
4667
+
4668
+ /**
4669
+ * Get site's plan ID.
4670
+ *
4671
+ * @author Vova Feldman (@svovaf)
4672
+ * @since 1.0.2
4673
+ *
4674
+ * @return number
4675
+ */
4676
+ function get_plan_id() {
4677
+ return $this->_site->plan->id;
4678
+ }
4679
+
4680
+ /**
4681
+ * Get site's plan title.
4682
+ *
4683
+ * @author Vova Feldman (@svovaf)
4684
+ * @since 1.0.2
4685
+ *
4686
+ * @return string
4687
+ */
4688
+ function get_plan_title() {
4689
+ return $this->_site->plan->title;
4690
+ }
4691
+
4692
+ /**
4693
+ * @author Vova Feldman (@svovaf)
4694
+ * @since 1.0.9
4695
+ *
4696
+ * @return FS_Plugin_Plan
4697
+ */
4698
+ function get_plan() {
4699
+ return is_object( $this->_site->plan ) ? $this->_site->plan : false;
4700
+ }
4701
+
4702
+ /**
4703
+ * @author Vova Feldman (@svovaf)
4704
+ * @since 1.0.3
4705
+ *
4706
+ * @return bool
4707
+ */
4708
+ function is_trial() {
4709
+ $this->_logger->entrance();
4710
+
4711
+ if ( ! $this->is_registered() ) {
4712
+ return false;
4713
+ }
4714
+
4715
+ return $this->_site->is_trial();
4716
+ }
4717
+
4718
+ /**
4719
+ * Check if currently in a trial with payment method (credit card or paypal).
4720
+ *
4721
+ * @author Vova Feldman (@svovaf)
4722
+ * @since 1.1.7
4723
+ *
4724
+ * @return bool
4725
+ */
4726
+ function is_paid_trial() {
4727
+ $this->_logger->entrance();
4728
+
4729
+ if ( ! $this->is_trial() ) {
4730
+ return false;
4731
+ }
4732
+
4733
+ return $this->has_active_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
4734
+ }
4735
+
4736
+ /**
4737
+ * Check if trial already utilized.
4738
+ *
4739
+ * @since 1.0.9
4740
+ *
4741
+ * @return bool
4742
+ */
4743
+ function is_trial_utilized() {
4744
+ $this->_logger->entrance();
4745
+
4746
+ if ( ! $this->is_registered() ) {
4747
+ return false;
4748
+ }
4749
+
4750
+ return $this->_site->is_trial_utilized();
4751
+ }
4752
+
4753
+ /**
4754
+ * Get trial plan information (if in trial).
4755
+ *
4756
+ * @author Vova Feldman (@svovaf)
4757
+ * @since 1.0.9
4758
+ *
4759
+ * @return bool|FS_Plugin_Plan
4760
+ */
4761
+ function get_trial_plan() {
4762
+ $this->_logger->entrance();
4763
+
4764
+ if ( ! $this->is_trial() ) {
4765
+ return false;
4766
+ }
4767
+
4768
+ return $this->_storage->trial_plan;
4769
+ }
4770
+
4771
+ /**
4772
+ * Check if the user has an activated and valid paid license on current plugin's install.
4773
+ *
4774
+ * @since 1.0.9
4775
+ *
4776
+ * @return bool
4777
+ */
4778
+ function is_paying() {
4779
+ $this->_logger->entrance();
4780
+
4781
+ if ( ! $this->is_registered() ) {
4782
+ return false;
4783
+ }
4784
+
4785
+ if ( ! $this->has_paid_plan() ) {
4786
+ return false;
4787
+ }
4788
+
4789
+ return (
4790
+ ! $this->is_trial() &&
4791
+ 'free' !== $this->_site->plan->name &&
4792
+ $this->has_features_enabled_license()
4793
+ );
4794
+ }
4795
+
4796
+ /**
4797
+ * @author Vova Feldman (@svovaf)
4798
+ * @since 1.0.4
4799
+ *
4800
+ * @return bool
4801
+ */
4802
+ function is_free_plan() {
4803
+ if ( ! $this->is_registered() ) {
4804
+ return true;
4805
+ }
4806
+
4807
+ if ( ! $this->has_paid_plan() ) {
4808
+ return true;
4809
+ }
4810
+
4811
+ return (
4812
+ 'free' === $this->_site->plan->name ||
4813
+ ! $this->has_features_enabled_license()
4814
+ );
4815
+ }
4816
+
4817
+ /**
4818
+ * @author Vova Feldman (@svovaf)
4819
+ * @since 1.0.5
4820
+ *
4821
+ * @return bool
4822
+ */
4823
+ function _has_premium_license() {
4824
+ $this->_logger->entrance();
4825
+
4826
+ $premium_license = $this->_get_available_premium_license();
4827
+
4828
+ return ( false !== $premium_license );
4829
+ }
4830
+
4831
+ /**
4832
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
4833
+ *
4834
+ * @author Vova Feldman (@svovaf)
4835
+ * @since 1.1.7.3
4836
+ *
4837
+ * @return bool
4838
+ */
4839
+ private function has_any_license() {
4840
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
4841
+ }
4842
+
4843
+ /**
4844
+ * @author Vova Feldman (@svovaf)
4845
+ * @since 1.0.5
4846
+ *
4847
+ * @return FS_Plugin_License
4848
+ */
4849
+ function _get_available_premium_license() {
4850
+ $this->_logger->entrance();
4851
+
4852
+ if ( ! $this->has_paid_plan() ) {
4853
+ return false;
4854
+ }
4855
+
4856
+ if ( is_array( $this->_licenses ) ) {
4857
+ foreach ( $this->_licenses as $license ) {
4858
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
4859
+ return $license;
4860
+ }
4861
+ }
4862
+ }
4863
+
4864
+ return false;
4865
+ }
4866
+
4867
+ /**
4868
+ * Sync local plugin plans with remote server.
4869
+ *
4870
+ * @author Vova Feldman (@svovaf)
4871
+ * @since 1.0.5
4872
+ *
4873
+ * @return FS_Plugin_Plan[]|object
4874
+ */
4875
+ function _sync_plans() {
4876
+ $plans = $this->_fetch_plugin_plans();
4877
+ if ( ! $this->is_api_error( $plans ) ) {
4878
+ $this->_plans = $plans;
4879
+ $this->_store_plans();
4880
+ }
4881
+
4882
+ $this->do_action( 'after_plans_sync', $plans );
4883
+
4884
+ return $this->_plans;
4885
+ }
4886
+
4887
+ /**
4888
+ * @author Vova Feldman (@svovaf)
4889
+ * @since 1.0.5
4890
+ *
4891
+ * @param number $id
4892
+ *
4893
+ * @return FS_Plugin_Plan
4894
+ */
4895
+ function _get_plan_by_id( $id ) {
4896
+ $this->_logger->entrance();
4897
+
4898
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4899
+ $this->_sync_plans();
4900
+ }
4901
+
4902
+ foreach ( $this->_plans as $plan ) {
4903
+ if ( $id == $plan->id ) {
4904
+ return $plan;
4905
+ }
4906
+ }
4907
+
4908
+ return false;
4909
+ }
4910
+
4911
+ /**
4912
+ * @author Vova Feldman (@svovaf)
4913
+ * @since 1.1.8.1
4914
+ *
4915
+ * @param string $name
4916
+ *
4917
+ * @return FS_Plugin_Plan|false
4918
+ */
4919
+ private function get_plan_by_name( $name ) {
4920
+ $this->_logger->entrance();
4921
+
4922
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4923
+ $this->_sync_plans();
4924
+ }
4925
+
4926
+ foreach ( $this->_plans as $plan ) {
4927
+ if ( $name == $plan->name ) {
4928
+ return $plan;
4929
+ }
4930
+ }
4931
+
4932
+ return false;
4933
+ }
4934
+
4935
+ /**
4936
+ * Sync local plugin plans with remote server.
4937
+ *
4938
+ * @author Vova Feldman (@svovaf)
4939
+ * @since 1.0.6
4940
+ *
4941
+ * @param number|bool $site_license_id
4942
+ *
4943
+ * @return FS_Plugin_License[]|object
4944
+ */
4945
+ function _sync_licenses( $site_license_id = false ) {
4946
+ $licenses = $this->_fetch_licenses( false, $site_license_id );
4947
+ if ( ! $this->is_api_error( $licenses ) ) {
4948
+ $this->_licenses = $licenses;
4949
+ $this->_store_licenses();
4950
+ }
4951
+
4952
+ // Update current license.
4953
+ if ( is_object( $this->_license ) ) {
4954
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
4955
+ }
4956
+
4957
+ return $this->_licenses;
4958
+ }
4959
+
4960
+ /**
4961
+ * @author Vova Feldman (@svovaf)
4962
+ * @since 1.0.5
4963
+ *
4964
+ * @param number $id
4965
+ *
4966
+ * @return FS_Plugin_License
4967
+ */
4968
+ function _get_license_by_id( $id ) {
4969
+ $this->_logger->entrance();
4970
+
4971
+ if ( ! is_numeric( $id ) ) {
4972
+ return false;
4973
+ }
4974
+
4975
+ if ( ! $this->has_any_license() ) {
4976
+ $this->_sync_licenses();
4977
+ }
4978
+
4979
+ foreach ( $this->_licenses as $license ) {
4980
+ if ( $id == $license->id ) {
4981
+ return $license;
4982
+ }
4983
+ }
4984
+
4985
+ return false;
4986
+ }
4987
+
4988
+ /**
4989
+ * Sync site's license with user licenses.
4990
+ *
4991
+ * @author Vova Feldman (@svovaf)
4992
+ * @since 1.0.6
4993
+ *
4994
+ * @param FS_Plugin_License|null $new_license
4995
+ */
4996
+ function _update_site_license( $new_license ) {
4997
+ $this->_logger->entrance();
4998
+
4999
+ $this->_license = $new_license;
5000
+
5001
+ if ( ! is_object( $new_license ) ) {
5002
+ $this->_site->license_id = null;
5003
+ $this->_sync_site_subscription( null );
5004
+
5005
+ return;
5006
+ }
5007
+
5008
+ $this->_site->license_id = $this->_license->id;
5009
+
5010
+ if ( ! is_array( $this->_licenses ) ) {
5011
+ $this->_licenses = array();
5012
+ }
5013
+
5014
+ $is_license_found = false;
5015
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
5016
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
5017
+ $this->_licenses[ $i ] = $new_license;
5018
+
5019
+ $is_license_found = true;
5020
+ break;
5021
+ }
5022
+ }
5023
+
5024
+ // If new license just append.
5025
+ if ( ! $is_license_found ) {
5026
+ $this->_licenses[] = $new_license;
5027
+ }
5028
+
5029
+ $this->_sync_site_subscription( $new_license );
5030
+ }
5031
+
5032
+ /**
5033
+ * Sync site's subscription.
5034
+ *
5035
+ * @author Vova Feldman (@svovaf)
5036
+ * @since 1.0.9
5037
+ *
5038
+ * @param FS_Plugin_License|null $license
5039
+ *
5040
+ * @return bool|\FS_Subscription
5041
+ */
5042
+ private function _sync_site_subscription( $license ) {
5043
+ if ( ! is_object( $license ) ) {
5044
+ unset( $this->_storage->subscription );
5045
+
5046
+ return false;
5047
+ }
5048
+
5049
+ // Load subscription details if not lifetime.
5050
+ $subscription = $license->is_lifetime() ?
5051
+ false :
5052
+ $this->_fetch_site_license_subscription();
5053
+
5054
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
5055
+ $this->_storage->subscription = $subscription;
5056
+ } else {
5057
+ unset( $this->_storage->subscription );
5058
+ }
5059
+
5060
+ return $subscription;
5061
+ }
5062
+
5063
+ /**
5064
+ * @author Vova Feldman (@svovaf)
5065
+ * @since 1.0.6
5066
+ *
5067
+ * @return bool|\FS_Plugin_License
5068
+ */
5069
+ function _get_license() {
5070
+ return $this->_license;
5071
+ }
5072
+
5073
+ /**
5074
+ * @return bool|\FS_Subscription
5075
+ */
5076
+ function _get_subscription() {
5077
+ return isset( $this->_storage->subscription ) ?
5078
+ $this->_storage->subscription :
5079
+ false;
5080
+ }
5081
+
5082
+ /**
5083
+ * @author Vova Feldman (@svovaf)
5084
+ * @since 1.0.2
5085
+ *
5086
+ * @param string $plan Plan name
5087
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
5088
+ *
5089
+ * @return bool
5090
+ */
5091
+ function is_plan( $plan, $exact = false ) {
5092
+ $this->_logger->entrance();
5093
+
5094
+ if ( ! $this->is_registered() ) {
5095
+ return false;
5096
+ }
5097
+
5098
+ $plan = strtolower( $plan );
5099
+
5100
+ if ( $this->_site->plan->name === $plan ) // Exact plan.
5101
+ {
5102
+ return true;
5103
+ } else if ( $exact ) // Required exact, but plans are different.
5104
+ {
5105
+ return false;
5106
+ }
5107
+
5108
+ $current_plan_order = - 1;
5109
+ $required_plan_order = - 1;
5110
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5111
+ if ( $plan === $this->_plans[ $i ]->name ) {
5112
+ $required_plan_order = $i;
5113
+ } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
5114
+ $current_plan_order = $i;
5115
+ }
5116
+ }
5117
+
5118
+ return ( $current_plan_order > $required_plan_order );
5119
+ }
5120
+
5121
+ /**
5122
+ * Check if plan based on trial. If not in trial mode, should return false.
5123
+ *
5124
+ * @since 1.0.9
5125
+ *
5126
+ * @param string $plan Plan name
5127
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
5128
+ *
5129
+ * @return bool
5130
+ */
5131
+ function is_trial_plan( $plan, $exact = false ) {
5132
+ $this->_logger->entrance();
5133
+
5134
+ if ( ! $this->is_registered() ) {
5135
+ return false;
5136
+ }
5137
+
5138
+ if ( ! $this->is_trial() ) {
5139
+ return false;
5140
+ }
5141
+
5142
+ if ( ! isset( $this->_storage->trial_plan ) ) {
5143
+ // Store trial plan information.
5144
+ $this->_enrich_site_trial_plan( true );
5145
+ }
5146
+
5147
+ if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
5148
+ {
5149
+ return true;
5150
+ } else if ( $exact ) // Required exact, but plans are different.
5151
+ {
5152
+ return false;
5153
+ }
5154
+
5155
+ $current_plan_order = - 1;
5156
+ $required_plan_order = - 1;
5157
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5158
+ if ( $plan === $this->_plans[ $i ]->name ) {
5159
+ $required_plan_order = $i;
5160
+ } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
5161
+ $current_plan_order = $i;
5162
+ }
5163
+ }
5164
+
5165
+ return ( $current_plan_order > $required_plan_order );
5166
+ }
5167
+
5168
+ /**
5169
+ * Check if plugin has any paid plans.
5170
+ *
5171
+ * @author Vova Feldman (@svovaf)
5172
+ * @since 1.0.7
5173
+ *
5174
+ * @return bool
5175
+ */
5176
+ function has_paid_plan() {
5177
+ return $this->_has_paid_plans || FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
5178
+ }
5179
+
5180
+ /**
5181
+ * Check if plugin has any plan with a trail.
5182
+ *
5183
+ * @author Vova Feldman (@svovaf)
5184
+ * @since 1.0.9
5185
+ *
5186
+ * @return bool
5187
+ */
5188
+ function has_trial_plan() {
5189
+ if ( ! $this->is_registered() ) {
5190
+ return false;
5191
+ }
5192
+
5193
+ return $this->_storage->get( 'has_trial_plan', false );
5194
+ }
5195
+
5196
+ /**
5197
+ * Check if plugin has any free plan, or is it premium only.
5198
+ *
5199
+ * Note: If no plans configured, assume plugin is free.
5200
+ *
5201
+ * @author Vova Feldman (@svovaf)
5202
+ * @since 1.0.7
5203
+ *
5204
+ * @return bool
5205
+ */
5206
+ function has_free_plan() {
5207
+ return ! $this->is_only_premium() && FS_Plan_Manager::instance()->has_free_plan( $this->_plans );
5208
+ }
5209
+
5210
+ /**
5211
+ * Displays a license activation dialog box when the user clicks on the "Activate License"
5212
+ * or "Change License" link on the plugins
5213
+ * page.
5214
+ *
5215
+ * @author Leo Fajardo (@leorw)
5216
+ * @since 1.1.9
5217
+ */
5218
+ function _add_license_activation_dialog_box() {
5219
+ if ( $this->is_addon() ) {
5220
+ $sync_license_url = $this->get_parent_instance()->_get_sync_license_url( $this->_plugin->id, true );
5221
+ } else {
5222
+ $sync_license_url = $this->_get_sync_license_url( $this->_plugin->id, true );
5223
+ }
5224
+
5225
+ $vars = array(
5226
+ 'slug' => $this->_slug,
5227
+ // Avoid having HTML entity like "&amp;" in the URL which breaks the redirection to the "Account" page.
5228
+ 'sync-license-url' => html_entity_decode( $sync_license_url )
5229
+ );
5230
+
5231
+ fs_require_template( 'forms/license-activation.php', $vars );
5232
+ fs_require_template( 'forms/resend-key.php', $vars );
5233
+ }
5234
+
5235
+ /**
5236
+ * Prepare page to include all required UI and logic for the license activation dialog.
5237
+ *
5238
+ * @author Vova Feldman (@svovaf)
5239
+ * @since 1.2.0
5240
+ */
5241
+ function _require_license_activation_dialog() {
5242
+ if ( $this->is_ajax() ) {
5243
+ if ( fs_request_is_action( 'activate_license' ) ) {
5244
+ // Add license activation AJAX callback.
5245
+ add_action( 'wp_ajax_activate_license', array( &$this, '_activate_license_ajax_action' ) );
5246
+ }
5247
+
5248
+ if ( fs_request_is_action( 'resend_license_key' ) ) {
5249
+ // Add resend license AJAX callback.
5250
+ add_action( 'wp_ajax_resend_license_key', array(
5251
+ &$this,
5252
+ '_resend_license_key_ajax_action'
5253
+ ) );
5254
+ }
5255
+ } else {
5256
+ // Inject license activation dialog UI and client side code.
5257
+ add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
5258
+ }
5259
+ }
5260
+
5261
+ /**
5262
+ * @author Leo Fajardo (@leorw)
5263
+ * @since 1.1.9
5264
+ */
5265
+ function _activate_license_ajax_action() {
5266
+ $license_key = trim( fs_request_get('license_key') );
5267
+
5268
+ if ( empty( $license_key ) ) {
5269
+ exit;
5270
+ }
5271
+
5272
+ $slug = $_POST['slug'];
5273
+ $fs = ( ( $slug === $this->_slug ) ? $this : self::instance( $slug ) );
5274
+ $error = false;
5275
+
5276
+ if ( $this->is_registered() ) {
5277
+ $api = $fs->get_api_site_scope();
5278
+ $install = $api->call( '/', 'put',
5279
+ array(
5280
+ 'license_key' => $license_key
5281
+ )
5282
+ );
5283
+
5284
+ if ( isset( $install->error ) ) {
5285
+ $error = $install->error->message;
5286
+ }
5287
+ } else {
5288
+ $this->opt_in( false, false, false, $license_key );
5289
+ }
5290
+
5291
+ $result = array(
5292
+ 'success' => ( false === $error )
5293
+ );
5294
+
5295
+ if ( false !== $error ) {
5296
+ $result['error'] = $error;
5297
+ }
5298
+
5299
+ echo json_encode( $result );
5300
+
5301
+ exit;
5302
+ }
5303
+
5304
+ /**
5305
+ * @author Leo Fajardo (@leorw)
5306
+ * @since 1.2.0
5307
+ */
5308
+ function _resend_license_key_ajax_action() {
5309
+ if ( ! isset( $_POST['email'] ) ) {
5310
+ exit;
5311
+ }
5312
+
5313
+ $email_address = trim( $_POST['email'] );
5314
+ if ( empty( $email_address ) ) {
5315
+ exit;
5316
+ }
5317
+
5318
+ $error = false;
5319
+
5320
+ $api = $this->get_api_plugin_scope();
5321
+ $result = $api->call( '/licenses/resend.json', 'post',
5322
+ array(
5323
+ 'email' => $email_address,
5324
+ 'is_localhost' => WP_FS__IS_LOCALHOST
5325
+ )
5326
+ );
5327
+
5328
+ if ( is_object( $result ) && isset( $result->error ) ) {
5329
+ $error = $result->error;
5330
+
5331
+ if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
5332
+ $error = __fs( 'email-not-found' );
5333
+ } else if ( 'no_license' === $error->code ) {
5334
+ $error = __fs( 'no-active-licenses' );
5335
+ } else {
5336
+ $error = $error->message;
5337
+ }
5338
+ }
5339
+
5340
+ $licenses = array(
5341
+ 'success' => ( false === $error )
5342
+ );
5343
+
5344
+ if ( false !== $error ) {
5345
+ $licenses['error'] = sprintf( '%s... %s', __fs( 'oops', $this->_slug ), strtolower( $error ) );
5346
+ }
5347
+
5348
+ echo json_encode( $licenses );
5349
+
5350
+ exit;
5351
+ }
5352
+
5353
+ #region URL Generators
5354
+
5355
+ /**
5356
+ * Alias to pricing_url().
5357
+ *
5358
+ * @author Vova Feldman (@svovaf)
5359
+ * @since 1.0.2
5360
+ *
5361
+ * @uses pricing_url()
5362
+ *
5363
+ * @param string $period Billing cycle
5364
+ * @param bool $is_trial
5365
+ *
5366
+ * @return string
5367
+ */
5368
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
5369
+ return $this->pricing_url( $period, $is_trial );
5370
+ }
5371
+
5372
+ /**
5373
+ * @author Vova Feldman (@svovaf)
5374
+ * @since 1.0.9
5375
+ *
5376
+ * @uses get_upgrade_url()
5377
+ *
5378
+ * @return string
5379
+ */
5380
+ function get_trial_url() {
5381
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
5382
+ }
5383
+
5384
+ /**
5385
+ * Plugin's pricing URL.
5386
+ *
5387
+ * @author Vova Feldman (@svovaf)
5388
+ * @since 1.0.4
5389
+ *
5390
+ * @param string $billing_cycle Billing cycle
5391
+ *
5392
+ * @param bool $is_trial
5393
+ *
5394
+ * @return string
5395
+ */
5396
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
5397
+ $this->_logger->entrance();
5398
+
5399
+ $params = array(
5400
+ 'billing_cycle' => $billing_cycle
5401
+ );
5402
+
5403
+ if ( $is_trial ) {
5404
+ $params['trial'] = 'true';
5405
+ }
5406
+
5407
+ return $this->_get_admin_page_url( 'pricing', $params );
5408
+ }
5409
+
5410
+ /**
5411
+ * Checkout page URL.
5412
+ *
5413
+ * @author Vova Feldman (@svovaf)
5414
+ * @since 1.0.6
5415
+ *
5416
+ * @param string $billing_cycle Billing cycle
5417
+ * @param bool $is_trial
5418
+ * @param array $extra (optional) Extra parameters, override other query params.
5419
+ *
5420
+ * @return string
5421
+ */
5422
+ function checkout_url(
5423
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5424
+ $is_trial = false,
5425
+ $extra = array()
5426
+ ) {
5427
+ $this->_logger->entrance();
5428
+
5429
+ $params = array(
5430
+ 'checkout' => 'true',
5431
+ 'billing_cycle' => $billing_cycle,
5432
+ );
5433
+
5434
+ if ( $is_trial ) {
5435
+ $params['trial'] = 'true';
5436
+ }
5437
+
5438
+ /**
5439
+ * Params in extra override other params.
5440
+ */
5441
+ $params = array_merge( $params, $extra );
5442
+
5443
+ return $this->_get_admin_page_url( 'pricing', $params );
5444
+ }
5445
+
5446
+ /**
5447
+ * Add-on checkout URL.
5448
+ *
5449
+ * @author Vova Feldman (@svovaf)
5450
+ * @since 1.1.7
5451
+ *
5452
+ * @param number $addon_id
5453
+ * @param number $pricing_id
5454
+ * @param string $billing_cycle
5455
+ * @param bool $is_trial
5456
+ *
5457
+ * @return string
5458
+ */
5459
+ function addon_checkout_url(
5460
+ $addon_id,
5461
+ $pricing_id,
5462
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5463
+ $is_trial = false
5464
+ ) {
5465
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
5466
+ 'plugin_id' => $addon_id,
5467
+ 'pricing_id' => $pricing_id,
5468
+ ) );
5469
+ }
5470
+
5471
+ #endregion
5472
+
5473
+ #endregion ------------------------------------------------------------------
5474
+
5475
+ /**
5476
+ * Check if plugin has any add-ons.
5477
+ *
5478
+ * @author Vova Feldman (@svovaf)
5479
+ * @since 1.0.5
5480
+ *
5481
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
5482
+ *
5483
+ * @return bool
5484
+ */
5485
+ function has_addons() {
5486
+ $this->_logger->entrance();
5487
+
5488
+ return $this->_has_addons;
5489
+ }
5490
+
5491
+ /**
5492
+ * Check if plugin can work in anonymous mode.
5493
+ *
5494
+ * @author Vova Feldman (@svovaf)
5495
+ * @since 1.0.9
5496
+ *
5497
+ * @return bool
5498
+ *
5499
+ * @deprecated Please use is_enable_anonymous() instead
5500
+ */
5501
+ function enable_anonymous() {
5502
+ return $this->_enable_anonymous;
5503
+ }
5504
+
5505
+ /**
5506
+ * Check if plugin can work in anonymous mode.
5507
+ *
5508
+ * @author Vova Feldman (@svovaf)
5509
+ * @since 1.1.9
5510
+ *
5511
+ * @return bool
5512
+ */
5513
+ function is_enable_anonymous() {
5514
+ return $this->_enable_anonymous;
5515
+ }
5516
+
5517
+ /**
5518
+ * Check if plugin is premium only (no free plans).
5519
+ *
5520
+ * @author Vova Feldman (@svovaf)
5521
+ * @since 1.1.9
5522
+ *
5523
+ * @return bool
5524
+ */
5525
+ function is_only_premium() {
5526
+ return $this->_is_premium_only;
5527
+ }
5528
+
5529
+ /**
5530
+ * Check if feature supported with current site's plan.
5531
+ *
5532
+ * @author Vova Feldman (@svovaf)
5533
+ * @since 1.0.1
5534
+ *
5535
+ * @todo IMPLEMENT
5536
+ *
5537
+ * @param number $feature_id
5538
+ *
5539
+ * @throws Exception
5540
+ */
5541
+ function is_feature_supported( $feature_id ) {
5542
+ throw new Exception( 'not implemented' );
5543
+ }
5544
+
5545
+ /**
5546
+ * @author Vova Feldman (@svovaf)
5547
+ * @since 1.0.1
5548
+ *
5549
+ * @return bool Is running in SSL/HTTPS
5550
+ */
5551
+ function is_ssl() {
5552
+ return WP_FS__IS_HTTPS;
5553
+ }
5554
+
5555
+ /**
5556
+ * @author Vova Feldman (@svovaf)
5557
+ * @since 1.0.9
5558
+ *
5559
+ * @return bool Is running in AJAX call.
5560
+ *
5561
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
5562
+ */
5563
+ function is_ajax() {
5564
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
5565
+ }
5566
+
5567
+ /**
5568
+ * Check if it's an AJAX call targeted for the current module.
5569
+ *
5570
+ * @author Vova Feldman (@svovaf)
5571
+ * @since 1.2.0
5572
+ *
5573
+ * @param array|string $actions Collection of AJAX actions.
5574
+ *
5575
+ * @return bool
5576
+ */
5577
+ function is_ajax_action( $actions ) {
5578
+ // Verify it's an ajax call.
5579
+ if ( ! $this->is_ajax() ) {
5580
+ return false;
5581
+ }
5582
+
5583
+ // Verify the call is relevant for the plugin.
5584
+ if ( $this->_slug !== fs_request_get( 'slug' ) ) {
5585
+ return false;
5586
+ }
5587
+
5588
+ // Verify it's one of the specified actions.
5589
+ if ( is_string( $actions ) ) {
5590
+ $actions = explode( ',', $actions );
5591
+ }
5592
+
5593
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
5594
+ $ajax_action = fs_request_get( 'action' );
5595
+
5596
+ foreach ( $actions as $action ) {
5597
+ if ( $ajax_action === $action ) {
5598
+ return true;
5599
+ }
5600
+ }
5601
+ }
5602
+
5603
+ return false;
5604
+ }
5605
+
5606
+ /**
5607
+ * @author Vova Feldman (@svovaf)
5608
+ * @since 1.1.7
5609
+ *
5610
+ * @return bool
5611
+ */
5612
+ function is_cron() {
5613
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
5614
+ }
5615
+
5616
+ /**
5617
+ * Check if a real user is visiting the admin dashboard.
5618
+ *
5619
+ * @author Vova Feldman (@svovaf)
5620
+ * @since 1.1.7
5621
+ *
5622
+ * @return bool
5623
+ */
5624
+ function is_user_in_admin() {
5625
+ return is_admin() && ! $this->is_ajax() && ! $this->is_cron();
5626
+ }
5627
+
5628
+ /**
5629
+ * Check if running in HTTPS and if site's plan matching the specified plan.
5630
+ *
5631
+ * @param string $plan
5632
+ * @param bool $exact
5633
+ *
5634
+ * @return bool
5635
+ */
5636
+ function is_ssl_and_plan( $plan, $exact = false ) {
5637
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
5638
+ }
5639
+
5640
+ /**
5641
+ * Construct plugin's settings page URL.
5642
+ *
5643
+ * @author Vova Feldman (@svovaf)
5644
+ * @since 1.0.4
5645
+ *
5646
+ * @param string $page
5647
+ * @param array $params
5648
+ *
5649
+ * @return string
5650
+ */
5651
+ function _get_admin_page_url( $page = '', $params = array() ) {
5652
+ if ( ! $this->_menu->is_top_level() ) {
5653
+ $parent_slug = $this->_menu->get_parent_slug();
5654
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
5655
+ $parent_slug :
5656
+ 'admin.php';
5657
+
5658
+ return add_query_arg( array_merge( $params, array(
5659
+ 'page' => $this->_menu->get_slug( $page ),
5660
+ ) ), admin_url( $menu_file, 'admin' ) );
5661
+ }
5662
+
5663
+ if ( $this->_menu->is_cpt() ) {
5664
+ if ( empty( $page ) && $this->is_activation_mode() ) {
5665
+ return add_query_arg( array_merge( $params, array(
5666
+ 'page' => $this->_menu->get_slug()
5667
+ ) ), admin_url( 'admin.php', 'admin' ) );
5668
+ } else {
5669
+ if ( ! empty( $page ) ) {
5670
+ $params['page'] = $this->_menu->get_slug( $page );
5671
+ }
5672
+
5673
+ return add_query_arg( $params, admin_url( $this->_menu->get_raw_slug(), 'admin' ) );
5674
+ }
5675
+ } else {
5676
+ return add_query_arg( array_merge( $params, array(
5677
+ 'page' => $this->_menu->get_slug( $page ),
5678
+ ) ), admin_url( 'admin.php', 'admin' ) );
5679
+ }
5680
+ }
5681
+
5682
+ /**
5683
+ * Plugin's account page + sync license URL.
5684
+ *
5685
+ * @author Vova Feldman (@svovaf)
5686
+ * @since 1.1.9.1
5687
+ *
5688
+ * @param bool|number $plugin_id
5689
+ * @param bool $add_action_nonce
5690
+ *
5691
+ * @return string
5692
+ */
5693
+ function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true ) {
5694
+ $params = array();
5695
+
5696
+ if ( is_numeric( $plugin_id ) ) {
5697
+ $params['plugin_id'] = $plugin_id;
5698
+ }
5699
+
5700
+ return $this->get_account_url(
5701
+ $this->_slug . '_sync_license',
5702
+ $params,
5703
+ $add_action_nonce
5704
+ );
5705
+ }
5706
+
5707
+ /**
5708
+ * Plugin's account URL.
5709
+ *
5710
+ * @author Vova Feldman (@svovaf)
5711
+ * @since 1.0.4
5712
+ *
5713
+ * @param bool|string $action
5714
+ * @param array $params
5715
+ *
5716
+ * @param bool $add_action_nonce
5717
+ *
5718
+ * @return string
5719
+ */
5720
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
5721
+ if ( is_string( $action ) ) {
5722
+ $params['fs_action'] = $action;
5723
+ }
5724
+
5725
+ self::require_pluggable_essentials();
5726
+
5727
+ return ( $add_action_nonce && is_string( $action ) ) ?
5728
+ wp_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
5729
+ $this->_get_admin_page_url( 'account', $params );
5730
+ }
5731
+
5732
+ /**
5733
+ * @author Vova Feldman (@svovaf)
5734
+ * @since 1.2.0
5735
+ *
5736
+ * @param string $tab
5737
+ * @param bool $action
5738
+ * @param array $params
5739
+ * @param bool $add_action_nonce
5740
+ *
5741
+ * @return string
5742
+ *
5743
+ * @uses get_account_url()
5744
+ */
5745
+ function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
5746
+ $params['tab'] = $tab;
5747
+
5748
+ return $this->get_account_url( $action, $params, $add_action_nonce );
5749
+ }
5750
+
5751
+ /**
5752
+ * Plugin's account URL.
5753
+ *
5754
+ * @author Vova Feldman (@svovaf)
5755
+ * @since 1.0.4
5756
+ *
5757
+ * @param bool|string $topic
5758
+ * @param bool|string $message
5759
+ *
5760
+ * @return string
5761
+ */
5762
+ function contact_url( $topic = false, $message = false ) {
5763
+ $params = array();
5764
+ if ( is_string( $topic ) ) {
5765
+ $params['topic'] = $topic;
5766
+ }
5767
+ if ( is_string( $message ) ) {
5768
+ $params['message'] = $message;
5769
+ }
5770
+
5771
+ if ( $this->is_addon() ) {
5772
+ $params['addon_id'] = $this->get_id();
5773
+
5774
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
5775
+ } else {
5776
+ return $this->_get_admin_page_url( 'contact', $params );
5777
+ }
5778
+ }
5779
+
5780
+ /**
5781
+ * Add-on direct info URL.
5782
+ *
5783
+ * @author Vova Feldman (@svovaf)
5784
+ * @since 1.1.0
5785
+ *
5786
+ * @param string $slug
5787
+ *
5788
+ * @return string
5789
+ */
5790
+ function addon_url( $slug ) {
5791
+ return $this->_get_admin_page_url( 'addons', array(
5792
+ 'slug' => $slug
5793
+ ) );
5794
+ }
5795
+
5796
+ /* Logger
5797
+ ------------------------------------------------------------------------------------------------------------------*/
5798
+ /**
5799
+ * @param string $id
5800
+ * @param bool $prefix_slug
5801
+ *
5802
+ * @return FS_Logger
5803
+ */
5804
+ function get_logger( $id = '', $prefix_slug = true ) {
5805
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
5806
+ }
5807
+
5808
+ /**
5809
+ * @param $id
5810
+ * @param bool $load_options
5811
+ * @param bool $prefix_slug
5812
+ *
5813
+ * @return FS_Option_Manager
5814
+ */
5815
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
5816
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
5817
+ }
5818
+
5819
+ /* Security
5820
+ ------------------------------------------------------------------------------------------------------------------*/
5821
+ private function _encrypt( $str ) {
5822
+ if ( is_null( $str ) ) {
5823
+ return null;
5824
+ }
5825
+
5826
+ return base64_encode( $str );
5827
+ }
5828
+
5829
+ private function _decrypt( $str ) {
5830
+ if ( is_null( $str ) ) {
5831
+ return null;
5832
+ }
5833
+
5834
+ return base64_decode( $str );
5835
+ }
5836
+
5837
+ /**
5838
+ * @author Vova Feldman (@svovaf)
5839
+ * @since 1.0.5
5840
+ *
5841
+ * @param FS_Entity $entity
5842
+ *
5843
+ * @return FS_Entity Return an encrypted clone entity.
5844
+ */
5845
+ private function _encrypt_entity( FS_Entity $entity ) {
5846
+ $clone = clone $entity;
5847
+ $props = get_object_vars( $entity );
5848
+
5849
+ foreach ( $props as $key => $val ) {
5850
+ $clone->{$key} = $this->_encrypt( $val );
5851
+ }
5852
+
5853
+ return $clone;
5854
+ }
5855
+
5856
+ /**
5857
+ * @author Vova Feldman (@svovaf)
5858
+ * @since 1.0.5
5859
+ *
5860
+ * @param FS_Entity $entity
5861
+ *
5862
+ * @return FS_Entity Return an decrypted clone entity.
5863
+ */
5864
+ private function _decrypt_entity( FS_Entity $entity ) {
5865
+ $clone = clone $entity;
5866
+ $props = get_object_vars( $entity );
5867
+
5868
+ foreach ( $props as $key => $val ) {
5869
+ $clone->{$key} = $this->_decrypt( $val );
5870
+ }
5871
+
5872
+ return $clone;
5873
+ }
5874
+
5875
+ /**
5876
+ * Tries to activate account based on POST params.
5877
+ *
5878
+ * @author Vova Feldman (@svovaf)
5879
+ * @since 1.0.2
5880
+ */
5881
+ function _activate_account() {
5882
+ if ( $this->is_registered() ) {
5883
+ // Already activated.
5884
+ return;
5885
+ }
5886
+
5887
+ self::_clean_admin_content_section();
5888
+
5889
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
5890
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
5891
+
5892
+ // Verify matching plugin details.
5893
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
5894
+ return;
5895
+ }
5896
+
5897
+ $user = new FS_User();
5898
+ $user->id = fs_request_get( 'user_id' );
5899
+ $user->public_key = fs_request_get( 'user_public_key' );
5900
+ $user->secret_key = fs_request_get( 'user_secret_key' );
5901
+ $user->email = fs_request_get( 'user_email' );
5902
+ $user->first = fs_request_get( 'user_first' );
5903
+ $user->last = fs_request_get( 'user_last' );
5904
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
5905
+
5906
+ $site = new FS_Site();
5907
+ $site->id = fs_request_get( 'install_id' );
5908
+ $site->public_key = fs_request_get( 'install_public_key' );
5909
+ $site->secret_key = fs_request_get( 'install_secret_key' );
5910
+ $site->plan->id = fs_request_get( 'plan_id' );
5911
+ $site->plan->title = fs_request_get( 'plan_title' );
5912
+ $site->plan->name = fs_request_get( 'plan_name' );
5913
+
5914
+ $plans = array();
5915
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
5916
+ foreach ( $plans_data as $p ) {
5917
+ $plans[] = new FS_Plugin_Plan( $p );
5918
+ }
5919
+
5920
+ $this->_set_account( $user, $site, $plans );
5921
+
5922
+ // Reload the page with the keys.
5923
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
5924
+ exit();
5925
+ }
5926
+ }
5927
+ }
5928
+
5929
+ /**
5930
+ * @author Vova Feldman (@svovaf)
5931
+ * @since 1.0.7
5932
+ *
5933
+ * @param string $email
5934
+ *
5935
+ * @return FS_User|bool
5936
+ */
5937
+ static function _get_user_by_email( $email ) {
5938
+ self::$_static_logger->entrance();
5939
+
5940
+ $email = trim( strtolower( $email ) );
5941
+ $users = self::get_all_users();
5942
+ if ( is_array( $users ) ) {
5943
+ foreach ( $users as $u ) {
5944
+ if ( $email === trim( strtolower( $u->email ) ) ) {
5945
+ return $u;
5946
+ }
5947
+ }
5948
+ }
5949
+
5950
+ return false;
5951
+ }
5952
+
5953
+ #region Account (Loading, Updates & Activation) ------------------------------------------------------------------
5954
+
5955
+ /***
5956
+ * Load account information (user + site).
5957
+ *
5958
+ * @author Vova Feldman (@svovaf)
5959
+ * @since 1.0.1
5960
+ */
5961
+ private function _load_account() {
5962
+ $this->_logger->entrance();
5963
+
5964
+ $this->do_action( 'before_account_load' );
5965
+
5966
+ $sites = self::get_all_sites();
5967
+ $users = self::get_all_users();
5968
+ $plans = self::get_all_plans();
5969
+ $licenses = self::get_all_licenses();
5970
+
5971
+ if ( $this->_logger->is_on() && is_admin() ) {
5972
+ $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
5973
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
5974
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
5975
+ $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
5976
+ }
5977
+
5978
+ $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
5979
+
5980
+ if ( is_object( $site ) &&
5981
+ is_numeric( $site->id ) &&
5982
+ is_numeric( $site->user_id ) &&
5983
+ is_object( $site->plan )
5984
+ ) {
5985
+ // Load site.
5986
+ $this->_site = clone $site;
5987
+ $this->_site->plan = $this->_decrypt_entity( $this->_site->plan );
5988
+
5989
+ // Load relevant user.
5990
+ $this->_user = clone $users[ $this->_site->user_id ];
5991
+
5992
+ // Load plans.
5993
+ $this->_plans = $plans[ $this->_slug ];
5994
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
5995
+ $this->_sync_plans( true );
5996
+ } else {
5997
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5998
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
5999
+ $this->_plans[ $i ] = $this->_decrypt_entity( $this->_plans[ $i ] );
6000
+ } else {
6001
+ unset( $this->_plans[ $i ] );
6002
+ }
6003
+ }
6004
+ }
6005
+
6006
+ // Load licenses.
6007
+ $this->_licenses = array();
6008
+ if ( is_array( $licenses ) &&
6009
+ isset( $licenses[ $this->_slug ] ) &&
6010
+ isset( $licenses[ $this->_slug ][ $this->_user->id ] )
6011
+ ) {
6012
+ $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
6013
+ }
6014
+
6015
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
6016
+
6017
+ if ( $this->_site->version != $this->get_plugin_version() ) {
6018
+ // If stored install version is different than current installed plugin version,
6019
+ // then update plugin version event.
6020
+ $this->update_plugin_version_event();
6021
+ }
6022
+ }
6023
+
6024
+ $this->_register_account_hooks();
6025
+ }
6026
+
6027
+ /**
6028
+ * @author Vova Feldman (@svovaf)
6029
+ * @since 1.0.1
6030
+ *
6031
+ * @param FS_User $user
6032
+ * @param FS_Site $site
6033
+ * @param bool|array $plans
6034
+ */
6035
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
6036
+ $site->slug = $this->_slug;
6037
+ $site->user_id = $user->id;
6038
+
6039
+ $this->_site = $site;
6040
+ $this->_user = $user;
6041
+ if ( false !== $plans ) {
6042
+ $this->_plans = $plans;
6043
+ }
6044
+
6045
+ $this->send_install_update();
6046
+
6047
+ $this->_store_account();
6048
+
6049
+ }
6050
+
6051
+ /**
6052
+ * @author Vova Feldman (@svovaf)
6053
+ * @since 1.1.7.4
6054
+ *
6055
+ * @param array $override_with
6056
+ *
6057
+ * @return array
6058
+ */
6059
+ function get_opt_in_params( $override_with = array() ) {
6060
+ $this->_logger->entrance();
6061
+
6062
+ $current_user = self::_get_current_wp_user();
6063
+
6064
+ $params = array(
6065
+ 'user_firstname' => $current_user->user_firstname,
6066
+ 'user_lastname' => $current_user->user_lastname,
6067
+ 'user_nickname' => $current_user->user_nicename,
6068
+ 'user_email' => $current_user->user_email,
6069
+ 'user_ip' => WP_FS__REMOTE_ADDR,
6070
+ 'plugin_slug' => $this->_slug,
6071
+ 'plugin_id' => $this->get_id(),
6072
+ 'plugin_public_key' => $this->get_public_key(),
6073
+ 'plugin_version' => $this->get_plugin_version(),
6074
+ 'return_url' => wp_nonce_url( $this->_get_admin_page_url(
6075
+ '',
6076
+ array( 'fs_action' => $this->_slug . '_activate_new' )
6077
+ ), $this->_slug . '_activate_new' ),
6078
+ 'account_url' => wp_nonce_url( $this->_get_admin_page_url(
6079
+ 'account',
6080
+ array( 'fs_action' => 'sync_user' )
6081
+ ), 'sync_user' ),
6082
+ 'site_uid' => $this->get_anonymous_id(),
6083
+ 'site_url' => get_site_url(),
6084
+ 'site_name' => get_bloginfo( 'name' ),
6085
+ 'platform_version' => get_bloginfo( 'version' ),
6086
+ 'php_version' => phpversion(),
6087
+ 'language' => get_bloginfo( 'language' ),
6088
+ 'charset' => get_bloginfo( 'charset' ),
6089
+ );
6090
+
6091
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
6092
+ // Even though rand() is known for its security issues,
6093
+ // the timestamp adds another layer of protection.
6094
+ // It would be very hard for an attacker to get the secret key form here.
6095
+ // Plus, this should never run in production since the secret should never
6096
+ // be included in the production version.
6097
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
6098
+ $params['salt'] = md5( uniqid( rand() ) );
6099
+ $params['secure'] = md5(
6100
+ $params['ts'] .
6101
+ $params['salt'] .
6102
+ $this->get_secret_key()
6103
+ );
6104
+ }
6105
+
6106
+ return array_merge( $params, $override_with );
6107
+ }
6108
+
6109
+ /**
6110
+ * @author Vova Feldman (@svovaf)
6111
+ * @since 1.1.7.4
6112
+ *
6113
+ * @param string|bool $email
6114
+ * @param string|bool $first
6115
+ * @param string|bool $last
6116
+ * @param string|bool $license_secret_key
6117
+ *
6118
+ * @return bool Is successful opt-in (or set to pending).
6119
+ */
6120
+ function opt_in( $email = false, $first = false, $last = false, $license_secret_key = false ) {
6121
+ $this->_logger->entrance();
6122
+
6123
+ if ( false === $email ) {
6124
+ $current_user = self::_get_current_wp_user();
6125
+ $email = $current_user->user_email;
6126
+ }
6127
+
6128
+ $fs_user = Freemius::_get_user_by_email( $email );
6129
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
6130
+ $this->install_with_current_user( false );
6131
+
6132
+ return true;
6133
+ }
6134
+
6135
+ $user_info = array();
6136
+ if ( ! empty( $email ) ) {
6137
+ $user_info['user_email'] = $email;
6138
+ }
6139
+ if ( ! empty( $first ) ) {
6140
+ $user_info['user_firstname'] = $first;
6141
+ }
6142
+ if ( ! empty( $last ) ) {
6143
+ $user_info['user_lastname'] = $last;
6144
+ }
6145
+
6146
+ $params = $this->get_opt_in_params( $user_info );
6147
+
6148
+ if ( is_string( $license_secret_key ) ) {
6149
+ $params['license_secret_key'] = $license_secret_key;
6150
+ }
6151
+
6152
+ $params['format'] = 'json';
6153
+
6154
+ $url = WP_FS__ADDRESS . '/action/service/user/install/';
6155
+ if ( isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
6156
+ $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
6157
+ }
6158
+
6159
+ $response = wp_remote_post( $url, array(
6160
+ 'method' => 'POST',
6161
+ 'body' => $params,
6162
+ 'timeout' => 15,
6163
+ ) );
6164
+
6165
+ if ( $response instanceof WP_Error ) {
6166
+ if ( 'https://' === substr( $url, 0, 8 ) &&
6167
+ isset( $response->errors ) &&
6168
+ isset( $response->errors['http_request_failed'] ) &&
6169
+ false !== strpos( $response->errors['http_request_failed'][0], 'sslv3 alert handshake' )
6170
+ ) {
6171
+ // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
6172
+ $url = 'http://' . substr( $url, 8 );
6173
+
6174
+ $response = wp_remote_post( $url, array(
6175
+ 'method' => 'POST',
6176
+ 'body' => $params,
6177
+ 'timeout' => 15,
6178
+ ) );
6179
+ }
6180
+
6181
+ if ( $response instanceof WP_Error ) {
6182
+ return false;
6183
+ }
6184
+ }
6185
+
6186
+ if ( is_wp_error( $response ) ) {
6187
+ return false;
6188
+ }
6189
+
6190
+ $decoded = @json_decode( $response['body'] );
6191
+
6192
+ if ( empty( $decoded ) ) {
6193
+ return false;
6194
+ }
6195
+
6196
+ if ( isset( $decoded->error ) ) {
6197
+ return false;
6198
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
6199
+ // Pending activation, add message.
6200
+ $this->set_pending_confirmation( false, false );
6201
+
6202
+ return true;
6203
+ } else if ( isset( $decoded->install_secret_key ) ) {
6204
+ $this->install_with_new_user(
6205
+ $decoded->user_id,
6206
+ $decoded->user_public_key,
6207
+ $decoded->user_secret_key,
6208
+ $decoded->install_id,
6209
+ $decoded->install_public_key,
6210
+ $decoded->install_secret_key,
6211
+ false
6212
+ );
6213
+
6214
+ return true;
6215
+ }
6216
+
6217
+ return false;
6218
+ }
6219
+
6220
+ /**
6221
+ * Set user and site identities.
6222
+ *
6223
+ * @author Vova Feldman (@svovaf)
6224
+ * @since 1.0.9
6225
+ *
6226
+ * @param FS_User $user
6227
+ * @param FS_Site $site
6228
+ * @param bool $redirect
6229
+ *
6230
+ * @return bool False if account already set.
6231
+ */
6232
+ function setup_account( FS_User $user, FS_Site $site, $redirect = true ) {
6233
+ $this->_user = $user;
6234
+ $this->_site = $site;
6235
+
6236
+ $this->_sync_plans();
6237
+
6238
+ $this->_enrich_site_plan( false );
6239
+
6240
+ $this->_set_account( $user, $site );
6241
+
6242
+ if ( $this->is_trial() ) {
6243
+ // Store trial plan information.
6244
+ $this->_enrich_site_trial_plan( true );
6245
+ }
6246
+
6247
+ // If Freemius was OFF before, turn it on.
6248
+ $this->turn_on();
6249
+
6250
+ $this->do_action( 'after_account_connection', $user, $site );
6251
+
6252
+ if ( is_numeric( $site->license_id ) ) {
6253
+ $this->_license = $this->_get_license_by_id( $site->license_id );
6254
+ }
6255
+
6256
+ if ( $this->is_pending_activation() ) {
6257
+ // Remove pending activation sticky notice (if still exist).
6258
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
6259
+
6260
+ // Remove plugin from pending activation mode.
6261
+ unset( $this->_storage->is_pending_activation );
6262
+
6263
+ if ( ! $this->is_paying() ) {
6264
+ $this->_admin_notices->add_sticky(
6265
+ sprintf( __fs( 'plugin-x-activation-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
6266
+ 'activation_complete'
6267
+ );
6268
+ }
6269
+ }
6270
+
6271
+ if ( $this->is_paying() && ! $this->is_premium() ) {
6272
+ $this->_admin_notices->add_sticky(
6273
+ sprintf(
6274
+ __fs( 'activation-with-plan-x-message', $this->_slug ),
6275
+ $this->_site->plan->title
6276
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
6277
+ __fs( 'download-latest-x-version', $this->_slug ),
6278
+ $this->_site->plan->title
6279
+ ) ),
6280
+ 'plan_upgraded',
6281
+ __fs( 'yee-haw', $this->_slug ) . '!'
6282
+ );
6283
+ }
6284
+
6285
+ $plugin_id = fs_request_get( 'plugin_id', false );
6286
+
6287
+ // Store activation time ONLY for plugins (not add-ons).
6288
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
6289
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
6290
+ }
6291
+
6292
+ if ( is_numeric( $plugin_id ) ) {
6293
+ if ( $plugin_id != $this->_plugin->id ) {
6294
+ // Add-on was installed - sync license right after install.
6295
+ if ( $redirect && fs_redirect( $this->_get_sync_license_url( $plugin_id ) )
6296
+ ) {
6297
+ exit();
6298
+ }
6299
+
6300
+ }
6301
+ } else {
6302
+ /**
6303
+ * @author Vova Feldman (@svovaf)
6304
+ * @since 1.1.9 If site installed with a valid license, sync license.
6305
+ */
6306
+ if ( $this->is_paying() ) {
6307
+ $this->_sync_plugin_license( true );
6308
+ }
6309
+
6310
+ // Reload the page with the keys.
6311
+ if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_connect_url' ) ) ) {
6312
+ exit();
6313
+ }
6314
+ }
6315
+ }
6316
+
6317
+ /**
6318
+ * Install plugin with new user information after approval.
6319
+ *
6320
+ * @author Vova Feldman (@svovaf)
6321
+ * @since 1.0.7
6322
+ */
6323
+ function _install_with_new_user() {
6324
+ $this->_logger->entrance();
6325
+
6326
+ if ( $this->is_registered() ) {
6327
+ return;
6328
+ }
6329
+
6330
+ if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
6331
+ // check_admin_referer( $this->_slug . '_activate_new' );
6332
+
6333
+ $this->_admin_notices->remove_sticky( 'connect_account' );
6334
+
6335
+ if ( fs_request_has( 'user_secret_key' ) ) {
6336
+ $this->install_with_new_user(
6337
+ fs_request_get( 'user_id' ),
6338
+ fs_request_get( 'user_public_key' ),
6339
+ fs_request_get( 'user_secret_key' ),
6340
+ fs_request_get( 'install_id' ),
6341
+ fs_request_get( 'install_public_key' ),
6342
+ fs_request_get( 'install_secret_key' )
6343
+ );
6344
+ } else if ( fs_request_has( 'pending_activation' ) ) {
6345
+ $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
6346
+ }
6347
+ }
6348
+ }
6349
+
6350
+ /**
6351
+ * Install plugin with new user.
6352
+ *
6353
+ * @author Vova Feldman (@svovaf)
6354
+ * @since 1.1.7.4
6355
+ *
6356
+ * @param number $user_id
6357
+ * @param string $user_public_key
6358
+ * @param string $user_secret_key
6359
+ * @param number $install_id
6360
+ * @param string $install_public_key
6361
+ * @param string $install_secret_key
6362
+ * @param bool $redirect
6363
+ */
6364
+ private function install_with_new_user(
6365
+ $user_id,
6366
+ $user_public_key,
6367
+ $user_secret_key,
6368
+ $install_id,
6369
+ $install_public_key,
6370
+ $install_secret_key,
6371
+ $redirect = true
6372
+ ) {
6373
+ $user = new FS_User();
6374
+ $user->id = $user_id;
6375
+ $user->public_key = $user_public_key;
6376
+ $user->secret_key = $user_secret_key;
6377
+
6378
+ $this->_user = $user;
6379
+ $user_result = $this->get_api_user_scope()->get();
6380
+ $user = new FS_User( $user_result );
6381
+ $this->_user = $user;
6382
+
6383
+ $site = new FS_Site();
6384
+ $site->id = $install_id;
6385
+ $site->public_key = $install_public_key;
6386
+ $site->secret_key = $install_secret_key;
6387
+
6388
+ $this->_site = $site;
6389
+ $site_result = $this->get_api_site_scope()->get();
6390
+ $site = new FS_Site( $site_result );
6391
+ $this->_site = $site;
6392
+
6393
+ $this->setup_account( $this->_user, $this->_site, $redirect );
6394
+ }
6395
+
6396
+ /**
6397
+ * @author Vova Feldman (@svovaf)
6398
+ * @since 1.1.7.4
6399
+ *
6400
+ * @param bool $email
6401
+ * @param bool $redirect
6402
+ */
6403
+ private function set_pending_confirmation( $email = false, $redirect = true ) {
6404
+ // Install must be activated via email since
6405
+ // user with the same email already exist.
6406
+ $this->_storage->is_pending_activation = true;
6407
+ $this->_add_pending_activation_notice( $email );
6408
+
6409
+ // Reload the page with with pending activation message.
6410
+ if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_pending_connect_url' ) ) ) {
6411
+ exit();
6412
+ }
6413
+ }
6414
+
6415
+ /**
6416
+ * Install plugin with current logged WP user info.
6417
+ *
6418
+ * @author Vova Feldman (@svovaf)
6419
+ * @since 1.0.7
6420
+ */
6421
+ function _install_with_current_user() {
6422
+ $this->_logger->entrance();
6423
+
6424
+ if ( $this->is_registered() ) {
6425
+ return;
6426
+ }
6427
+
6428
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) && fs_request_is_post() ) {
6429
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
6430
+
6431
+ $this->install_with_current_user();
6432
+ }
6433
+ }
6434
+
6435
+
6436
+ /**
6437
+ * @author Vova Feldman (@svovaf)
6438
+ * @since 1.1.7.4
6439
+ *
6440
+ * @param bool $redirect
6441
+ */
6442
+ private function install_with_current_user( $redirect = true ) {
6443
+ $this->_admin_notices->remove_sticky( 'connect_account' );
6444
+
6445
+ // Get current logged WP user.
6446
+ $current_user = self::_get_current_wp_user();
6447
+
6448
+ // Find the relevant FS user by the email.
6449
+ $user = self::_get_user_by_email( $current_user->user_email );
6450
+
6451
+ // We have to set the user before getting user scope API handler.
6452
+ $this->_user = $user;
6453
+
6454
+ $extra_install_params = array(
6455
+ 'uid' => $this->get_anonymous_id(),
6456
+ );
6457
+
6458
+ /**
6459
+ * @author Vova Feldman (@svovaf)
6460
+ * @since 1.1.9 Add license key if given.
6461
+ */
6462
+ $license_key = fs_request_get( 'license_secret_key' );
6463
+
6464
+ if ( ! empty( $license_key ) ) {
6465
+ $extra_install_params['license_secret_key'] = $license_key;
6466
+ }
6467
+
6468
+ // Install the plugin.
6469
+ $install = $this->get_api_user_scope()->call(
6470
+ "/plugins/{$this->get_id()}/installs.json",
6471
+ 'post',
6472
+ $this->get_install_data_for_api( $extra_install_params, false, false )
6473
+ );
6474
+
6475
+ if ( isset( $install->error ) ) {
6476
+ $this->_admin_notices->add(
6477
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
6478
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $install->error->message . '</b>',
6479
+ __fs( 'oops', $this->_slug ) . '...',
6480
+ 'error'
6481
+ );
6482
+
6483
+ return;
6484
+ }
6485
+
6486
+ $site = new FS_Site( $install );
6487
+ $this->_site = $site;
6488
+ // $this->_enrich_site_plan( false );
6489
+
6490
+ // $this->_set_account( $user, $site );
6491
+ // $this->_sync_plans();
6492
+
6493
+ $this->setup_account( $this->_user, $this->_site, $redirect );
6494
+ }
6495
+
6496
+ /**
6497
+ * Tries to activate add-on account based on parent plugin info.
6498
+ *
6499
+ * @author Vova Feldman (@svovaf)
6500
+ * @since 1.0.6
6501
+ *
6502
+ * @param Freemius $parent_fs
6503
+ */
6504
+ private function _activate_addon_account( Freemius $parent_fs ) {
6505
+ if ( $this->is_registered() ) {
6506
+ // Already activated.
6507
+ return;
6508
+ }
6509
+
6510
+ // Activate add-on with parent plugin credentials.
6511
+ $addon_install = $parent_fs->get_api_site_scope()->call(
6512
+ "/addons/{$this->_plugin->id}/installs.json",
6513
+ 'post',
6514
+ $this->get_install_data_for_api( array(
6515
+ 'uid' => $this->get_anonymous_id(),
6516
+ ), false, false )
6517
+ );
6518
+
6519
+ if ( isset( $addon_install->error ) ) {
6520
+ $this->_admin_notices->add(
6521
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
6522
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
6523
+ __fs( 'oops', $this->_slug ) . '...',
6524
+ 'error'
6525
+ );
6526
+
6527
+ return;
6528
+ }
6529
+
6530
+ // First of all, set site info - otherwise we won't
6531
+ // be able to invoke API calls.
6532
+ $this->_site = new FS_Site( $addon_install );
6533
+
6534
+ // Sync add-on plans.
6535
+ $this->_sync_plans();
6536
+
6537
+ // Get site's current plan.
6538
+ $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
6539
+
6540
+ // Get user information based on parent's plugin.
6541
+ $user = $parent_fs->get_user();
6542
+
6543
+ $this->_set_account( $user, $this->_site );
6544
+
6545
+ // Sync licenses.
6546
+ $this->_sync_licenses();
6547
+
6548
+ // Try to activate premium license.
6549
+ $this->_activate_license( true );
6550
+ }
6551
+
6552
+ #endregion ------------------------------------------------------------------
6553
+
6554
+ #region Admin Menu Items ------------------------------------------------------------------
6555
+
6556
+ private $_menu_items = array();
6557
+
6558
+ /**
6559
+ * @author Vova Feldman (@svovaf)
6560
+ * @since 1.0.7
6561
+ *
6562
+ * @return string
6563
+ */
6564
+ function get_menu_slug() {
6565
+ return $this->_menu->get_slug();
6566
+ }
6567
+
6568
+ /**
6569
+ * @author Vova Feldman (@svovaf)
6570
+ * @since 1.0.9
6571
+ */
6572
+ function _prepare_admin_menu() {
6573
+ // if ( ! $this->is_on() ) {
6574
+ // return;
6575
+ // }
6576
+
6577
+ if ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) {
6578
+ $this->_menu->remove_menu_item();
6579
+ } else {
6580
+ $this->do_action( 'before_admin_menu_init' );
6581
+
6582
+ $this->add_menu_action();
6583
+ $this->add_submenu_items();
6584
+ }
6585
+ }
6586
+
6587
+ /**
6588
+ * Admin dashboard menu items modifications.
6589
+ *
6590
+ * NOTE: admin_menu action executed before admin_init.
6591
+ *
6592
+ * @author Vova Feldman (@svovaf)
6593
+ * @since 1.0.7
6594
+ *
6595
+ */
6596
+ private function add_menu_action() {
6597
+ if ( $this->is_activation_mode() ) {
6598
+ $this->override_plugin_menu_with_activation();
6599
+ } else {
6600
+ // If not registered try to install user.
6601
+ if ( ! $this->is_registered() &&
6602
+ fs_request_is_action( $this->_slug . '_activate_new' )
6603
+ ) {
6604
+ $this->_install_with_new_user();
6605
+ }
6606
+ }
6607
+ }
6608
+
6609
+ /**
6610
+ * @author Vova Feldman (@svovaf)
6611
+ * @since 1.0.1
6612
+ *
6613
+ * @return string
6614
+ */
6615
+ function _redirect_on_clicked_menu_link() {
6616
+ $this->_logger->entrance();
6617
+
6618
+ $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
6619
+
6620
+ $this->_logger->log( 'page = ' . $page );
6621
+
6622
+ foreach ( $this->_menu_items as $priority => $items ) {
6623
+ foreach ( $items as $item ) {
6624
+ if ( isset( $item['url'] ) ) {
6625
+ if ( $page === strtolower( $item['menu_slug'] ) ) {
6626
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
6627
+
6628
+ fs_redirect( $item['url'] );
6629
+ }
6630
+ }
6631
+ }
6632
+ }
6633
+ }
6634
+
6635
+ /**
6636
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
6637
+ *
6638
+ * @author Vova Feldman (@svovaf)
6639
+ * @since 1.0.1
6640
+ */
6641
+ private function override_plugin_menu_with_activation() {
6642
+ $this->_logger->entrance();
6643
+
6644
+ $hook = false;
6645
+
6646
+ if ( $this->_menu->is_top_level() ) {
6647
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
6648
+
6649
+ if ( false === $hook ) {
6650
+ // Create new menu item just for the opt-in.
6651
+ $hook = add_menu_page(
6652
+ $this->get_plugin_name(),
6653
+ $this->get_plugin_name(),
6654
+ 'manage_options',
6655
+ $this->_menu->get_slug(),
6656
+ array( &$this, '_connect_page_render' )
6657
+ );
6658
+ }
6659
+ } else {
6660
+ $menus = array( $this->_menu->get_parent_slug() );
6661
+
6662
+ if ( $this->_menu->is_override_exact() ) {
6663
+ // Make sure the current page is matching the activation page.
6664
+ $activation_url = strtolower( $this->get_activation_url() );
6665
+ $request_url = strtolower( $_SERVER['REQUEST_URI'] );
6666
+
6667
+ if ( parse_url( $activation_url, PHP_URL_PATH ) !== parse_url( $request_url, PHP_URL_PATH ) ) {
6668
+ // Different path - DO NOT OVERRIDE PAGE.
6669
+ return;
6670
+ }
6671
+
6672
+ $activation_url_params = array();
6673
+ parse_str( parse_url( $activation_url, PHP_URL_QUERY ), $activation_url_params );
6674
+
6675
+ $request_url_params = array();
6676
+ parse_str( parse_url( $request_url, PHP_URL_QUERY ), $request_url_params );
6677
+
6678
+
6679
+ foreach ( $activation_url_params as $key => $val ) {
6680
+ if ( ! isset( $request_url_params[ $key ] ) || $val != $request_url_params[ $key ] ) {
6681
+ // Not matching query string - DO NOT OVERRIDE PAGE.
6682
+ return;
6683
+ }
6684
+ }
6685
+ }
6686
+
6687
+ foreach ( $menus as $parent_slug ) {
6688
+ $hook = $this->_menu->override_submenu_action(
6689
+ $parent_slug,
6690
+ $this->_menu->get_raw_slug(),
6691
+ array( &$this, '_connect_page_render' )
6692
+ );
6693
+
6694
+ if ( false !== $hook ) {
6695
+ // Found plugin's submenu item.
6696
+ break;
6697
+ }
6698
+ }
6699
+ }
6700
+
6701
+ if ( $this->_menu->is_activation_page() ) {
6702
+ // Clean admin page from distracting content.
6703
+ self::_clean_admin_content_section();
6704
+ }
6705
+
6706
+ if ( false !== $hook ) {
6707
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) ) {
6708
+ add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
6709
+ } else if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
6710
+ add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
6711
+ }
6712
+ }
6713
+ }
6714
+
6715
+ /**
6716
+ * @author Vova Feldman (@svovaf)
6717
+ * @since 1.0.0
6718
+ *
6719
+ * @return string
6720
+ */
6721
+ private function get_top_level_menu_slug() {
6722
+ return ( $this->is_addon() ?
6723
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
6724
+ $this->_menu->get_top_level_menu_slug() );
6725
+ }
6726
+
6727
+ /**
6728
+ * Add default Freemius menu items.
6729
+ *
6730
+ * @author Vova Feldman (@svovaf)
6731
+ * @since 1.0.0
6732
+ */
6733
+ private function add_submenu_items() {
6734
+ $this->_logger->entrance();
6735
+
6736
+ if ( ! $this->is_addon() ) {
6737
+ if ( ! $this->is_activation_mode() ) {
6738
+ if ( $this->is_registered() ) {
6739
+ // Add user account page.
6740
+ $this->add_submenu_item(
6741
+ __fs( 'account', $this->_slug ),
6742
+ array( &$this, '_account_page_render' ),
6743
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'account', $this->_slug ),
6744
+ 'manage_options',
6745
+ 'account',
6746
+ array( &$this, '_account_page_load' ),
6747
+ WP_FS__DEFAULT_PRIORITY,
6748
+ $this->_menu->is_submenu_item_visible( 'account' )
6749
+ );
6750
+ }
6751
+
6752
+ // Add contact page.
6753
+ $this->add_submenu_item(
6754
+ __fs( 'contact-us', $this->_slug ),
6755
+ array( &$this, '_contact_page_render' ),
6756
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'contact-us', $this->_slug ),
6757
+ 'manage_options',
6758
+ 'contact',
6759
+ 'Freemius::_clean_admin_content_section',
6760
+ WP_FS__DEFAULT_PRIORITY,
6761
+ $this->_menu->is_submenu_item_visible( 'contact' )
6762
+ );
6763
+
6764
+ if ( $this->has_addons() ) {
6765
+ $this->add_submenu_item(
6766
+ __fs( 'add-ons', $this->_slug ),
6767
+ array( &$this, '_addons_page_render' ),
6768
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'add-ons', $this->_slug ),
6769
+ 'manage_options',
6770
+ 'addons',
6771
+ array( &$this, '_addons_page_load' ),
6772
+ WP_FS__LOWEST_PRIORITY - 1,
6773
+ $this->_menu->is_submenu_item_visible( 'addons' )
6774
+ );
6775
+ }
6776
+
6777
+ $show_pricing = ( $this->has_paid_plan() && $this->_menu->is_submenu_item_visible( 'pricing' ) );
6778
+ // If user don't have paid plans, add pricing page
6779
+ // to support add-ons checkout but don't add the submenu item.
6780
+ // || (isset( $_GET['page'] ) && $this->_menu->get_slug( 'pricing' ) == $_GET['page']);
6781
+
6782
+ // Add upgrade/pricing page.
6783
+ $this->add_submenu_item(
6784
+ ( $this->is_paying() ? __fs( 'pricing', $this->_slug ) : __fs( 'upgrade', $this->_slug ) . '&nbsp;&nbsp;&#x27a4;' ),
6785
+ array( &$this, '_pricing_page_render' ),
6786
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'pricing', $this->_slug ),
6787
+ 'manage_options',
6788
+ 'pricing',
6789
+ 'Freemius::_clean_admin_content_section',
6790
+ WP_FS__LOWEST_PRIORITY,
6791
+ $show_pricing
6792
+ );
6793
+ }
6794
+ }
6795
+
6796
+
6797
+ if ( 0 < count( $this->_menu_items ) ) {
6798
+ if ( ! $this->_menu->is_top_level() ) {
6799
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
6800
+
6801
+ // Append submenu items right after the plugin's submenu item.
6802
+ $this->order_sub_submenu_items();
6803
+ } else {
6804
+ // Append submenu items.
6805
+ $this->embed_submenu_items();
6806
+ }
6807
+ }
6808
+ }
6809
+
6810
+ /**
6811
+ * Moved the actual submenu item additions to a separated function,
6812
+ * in order to support sub-submenu items when the plugin's settings
6813
+ * only have a submenu and not top-level menu item.
6814
+ *
6815
+ * @author Vova Feldman (@svovaf)
6816
+ * @since 1.1.4
6817
+ */
6818
+ private function embed_submenu_items() {
6819
+ $item_template = $this->_menu->is_top_level() ?
6820
+ '<span class="fs-submenu-item">%s</span>' :
6821
+ '<span class="fs-submenu-item fs-sub">%s</span>';
6822
+
6823
+ ksort( $this->_menu_items );
6824
+
6825
+ foreach ( $this->_menu_items as $priority => $items ) {
6826
+ foreach ( $items as $item ) {
6827
+ if ( ! isset( $item['url'] ) ) {
6828
+ $hook = add_submenu_page(
6829
+ $item['show_submenu'] ?
6830
+ $this->get_top_level_menu_slug() :
6831
+ null,
6832
+ $item['page_title'],
6833
+ sprintf( $item_template, $item['menu_title'] ),
6834
+ $item['capability'],
6835
+ $item['menu_slug'],
6836
+ $item['render_function']
6837
+ );
6838
+
6839
+ if ( false !== $item['before_render_function'] ) {
6840
+ add_action( "load-$hook", $item['before_render_function'] );
6841
+ }
6842
+ } else {
6843
+ add_submenu_page(
6844
+ $this->get_top_level_menu_slug(),
6845
+ $item['page_title'],
6846
+ sprintf( $item_template, $item['menu_title'] ),
6847
+ $item['capability'],
6848
+ $item['menu_slug'],
6849
+ array( $this, '' )
6850
+ );
6851
+ }
6852
+ }
6853
+ }
6854
+ }
6855
+
6856
+ /**
6857
+ * Re-order the submenu items so all Freemius added new submenu items
6858
+ * are added right after the plugin's settings submenu item.
6859
+ *
6860
+ * @author Vova Feldman (@svovaf)
6861
+ * @since 1.1.4
6862
+ */
6863
+ private function order_sub_submenu_items() {
6864
+ global $submenu;
6865
+
6866
+ $menu_slug = $this->_menu->get_top_level_menu_slug();
6867
+
6868
+ if ( empty( $submenu[ $menu_slug ] ) ) {
6869
+ return;
6870
+ }
6871
+
6872
+ $top_level_menu = &$submenu[ $menu_slug ];
6873
+
6874
+ $all_submenu_items_after = array();
6875
+
6876
+ $found_submenu_item = false;
6877
+
6878
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
6879
+ if ( $found_submenu_item ) {
6880
+ // Remove all submenu items after the plugin's submenu item.
6881
+ $all_submenu_items_after[] = $meta;
6882
+ unset( $top_level_menu[ $submenu_id ] );
6883
+ }
6884
+
6885
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
6886
+ // Found the submenu item, put all below.
6887
+ $found_submenu_item = true;
6888
+ continue;
6889
+ }
6890
+ }
6891
+
6892
+ // Embed all plugin's new submenu items.
6893
+ $this->embed_submenu_items();
6894
+
6895
+ // Start with specially high number to make sure it's appended.
6896
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
6897
+ foreach ( $all_submenu_items_after as $meta ) {
6898
+ $top_level_menu[ $i ] = $meta;
6899
+ $i ++;
6900
+ }
6901
+
6902
+ // Sort submenu items.
6903
+ ksort( $top_level_menu );
6904
+ }
6905
+
6906
+ /**
6907
+ * Displays the Support Forum link when enabled.
6908
+ *
6909
+ * Can be filtered like so:
6910
+ *
6911
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
6912
+ * if ( 'support' === $menu_id ) {
6913
+ * return _fs->is_registered();
6914
+ * }
6915
+ * return $is_visible;
6916
+ * }
6917
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
6918
+ *
6919
+ */
6920
+ function _add_default_submenu_items() {
6921
+ if ( ! $this->is_on() ) {
6922
+ return;
6923
+ }
6924
+
6925
+ if ( ! $this->is_activation_mode() ) {
6926
+ if ( $this->_menu->is_submenu_item_visible( 'support' ) ) {
6927
+ $this->add_submenu_link_item(
6928
+ $this->apply_filters( 'support_forum_submenu', __fs( 'support-forum', $this->_slug ) ),
6929
+ $this->apply_filters( 'support_forum_url', 'https://wordpress.org/support/plugin/' . $this->_slug ),
6930
+ 'wp-support-forum',
6931
+ 'read',
6932
+ 50
6933
+ );
6934
+ }
6935
+ }
6936
+ }
6937
+
6938
+ /**
6939
+ * @author Vova Feldman (@svovaf)
6940
+ * @since 1.0.1
6941
+ *
6942
+ * @param string $menu_title
6943
+ * @param callable $render_function
6944
+ * @param bool|string $page_title
6945
+ * @param string $capability
6946
+ * @param bool|string $menu_slug
6947
+ * @param bool|callable $before_render_function
6948
+ * @param int $priority
6949
+ * @param bool $show_submenu
6950
+ */
6951
+ function add_submenu_item(
6952
+ $menu_title,
6953
+ $render_function,
6954
+ $page_title = false,
6955
+ $capability = 'manage_options',
6956
+ $menu_slug = false,
6957
+ $before_render_function = false,
6958
+ $priority = WP_FS__DEFAULT_PRIORITY,
6959
+ $show_submenu = true
6960
+ ) {
6961
+ $this->_logger->entrance( 'Title = ' . $menu_title );
6962
+
6963
+ if ( $this->is_addon() ) {
6964
+ $parent_fs = $this->get_parent_instance();
6965
+
6966
+ if ( is_object( $parent_fs ) ) {
6967
+ $parent_fs->add_submenu_item(
6968
+ $menu_title,
6969
+ $render_function,
6970
+ $page_title,
6971
+ $capability,
6972
+ $menu_slug,
6973
+ $before_render_function,
6974
+ $priority,
6975
+ $show_submenu
6976
+ );
6977
+
6978
+ return;
6979
+ }
6980
+ }
6981
+
6982
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
6983
+ $this->_menu_items[ $priority ] = array();
6984
+ }
6985
+
6986
+ $this->_menu_items[ $priority ][] = array(
6987
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
6988
+ 'menu_title' => $menu_title,
6989
+ 'capability' => $capability,
6990
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
6991
+ 'render_function' => $render_function,
6992
+ 'before_render_function' => $before_render_function,
6993
+ 'show_submenu' => $show_submenu,
6994
+ );
6995
+ }
6996
+
6997
+ /**
6998
+ * @author Vova Feldman (@svovaf)
6999
+ * @since 1.0.1
7000
+ *
7001
+ * @param string $menu_title
7002
+ * @param string $url
7003
+ * @param bool $menu_slug
7004
+ * @param string $capability
7005
+ * @param int $priority
7006
+ *
7007
+ */
7008
+ function add_submenu_link_item(
7009
+ $menu_title,
7010
+ $url,
7011
+ $menu_slug = false,
7012
+ $capability = 'read',
7013
+ $priority = WP_FS__DEFAULT_PRIORITY
7014
+ ) {
7015
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
7016
+
7017
+ if ( $this->is_addon() ) {
7018
+ $parent_fs = $this->get_parent_instance();
7019
+
7020
+ if ( is_object( $parent_fs ) ) {
7021
+ $parent_fs->add_submenu_link_item(
7022
+ $menu_title,
7023
+ $url,
7024
+ $menu_slug,
7025
+ $capability,
7026
+ $priority
7027
+ );
7028
+
7029
+ return;
7030
+ }
7031
+ }
7032
+
7033
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
7034
+ $this->_menu_items[ $priority ] = array();
7035
+ }
7036
+
7037
+ $this->_menu_items[ $priority ][] = array(
7038
+ 'menu_title' => $menu_title,
7039
+ 'capability' => $capability,
7040
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
7041
+ 'url' => $url,
7042
+ 'page_title' => $menu_title,
7043
+ 'render_function' => 'fs_dummy',
7044
+ 'before_render_function' => '',
7045
+ );
7046
+ }
7047
+
7048
+ #endregion ------------------------------------------------------------------
7049
+
7050
+ /* Actions / Hooks / Filters
7051
+ ------------------------------------------------------------------------------------------------------------------*/
7052
+ /**
7053
+ * @author Vova Feldman (@svovaf)
7054
+ * @since 1.1.7
7055
+ *
7056
+ * @param string $tag
7057
+ *
7058
+ * @return string
7059
+ */
7060
+ private function get_action_tag( $tag ) {
7061
+ return 'fs_' . $tag . '_' . $this->_slug;
7062
+ }
7063
+
7064
+ /**
7065
+ * Do action, specific for the current context plugin.
7066
+ *
7067
+ * @author Vova Feldman (@svovaf)
7068
+ * @since 1.0.1
7069
+ *
7070
+ * @param string $tag The name of the action to be executed.
7071
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
7072
+ * functions hooked to the action. Default empty.
7073
+ *
7074
+ * @uses do_action()
7075
+ */
7076
+ function do_action( $tag, $arg = '' ) {
7077
+ $this->_logger->entrance( $tag );
7078
+
7079
+ $args = func_get_args();
7080
+
7081
+ call_user_func_array( 'do_action', array_merge(
7082
+ array( $this->get_action_tag( $tag ) ),
7083
+ array_slice( $args, 1 ) )
7084
+ );
7085
+ }
7086
+
7087
+ /**
7088
+ * Add action, specific for the current context plugin.
7089
+ *
7090
+ * @author Vova Feldman (@svovaf)
7091
+ * @since 1.0.1
7092
+ *
7093
+ * @param string $tag
7094
+ * @param callable $function_to_add
7095
+ * @param int $priority
7096
+ * @param int $accepted_args
7097
+ *
7098
+ * @uses add_action()
7099
+ */
7100
+ function add_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
7101
+ $this->_logger->entrance( $tag );
7102
+
7103
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
7104
+ }
7105
+
7106
+ /**
7107
+ * Apply filter, specific for the current context plugin.
7108
+ *
7109
+ * @author Vova Feldman (@svovaf)
7110
+ * @since 1.0.9
7111
+ *
7112
+ * @param string $tag The name of the filter hook.
7113
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
7114
+ *
7115
+ * @return mixed The filtered value after all hooked functions are applied to it.
7116
+ *
7117
+ * @uses apply_filters()
7118
+ */
7119
+ function apply_filters( $tag, $value ) {
7120
+ $this->_logger->entrance( $tag );
7121
+
7122
+ $args = func_get_args();
7123
+ array_unshift( $args, $this->_slug );
7124
+
7125
+ return call_user_func_array( 'fs_apply_filter', $args );
7126
+ }
7127
+
7128
+ /**
7129
+ * Add filter, specific for the current context plugin.
7130
+ *
7131
+ * @author Vova Feldman (@svovaf)
7132
+ * @since 1.0.9
7133
+ *
7134
+ * @param string $tag
7135
+ * @param callable $function_to_add
7136
+ * @param int $priority
7137
+ * @param int $accepted_args
7138
+ *
7139
+ * @uses add_filter()
7140
+ */
7141
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
7142
+ $this->_logger->entrance( $tag );
7143
+
7144
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
7145
+ }
7146
+
7147
+ /**
7148
+ * Check if has filter.
7149
+ *
7150
+ * @author Vova Feldman (@svovaf)
7151
+ * @since 1.1.4
7152
+ *
7153
+ * @param string $tag
7154
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
7155
+ *
7156
+ * @return false|int
7157
+ *
7158
+ * @uses has_filter()
7159
+ */
7160
+ function has_filter( $tag, $function_to_check = false ) {
7161
+ $this->_logger->entrance( $tag );
7162
+
7163
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
7164
+ }
7165
+
7166
+ /**
7167
+ * Override default i18n text phrases.
7168
+ *
7169
+ * @author Vova Feldman (@svovaf)
7170
+ * @since 1.1.6
7171
+ *
7172
+ * @param string[] string $key_value
7173
+ *
7174
+ * @uses fs_override_i18n()
7175
+ */
7176
+ function override_i18n( $key_value ) {
7177
+ fs_override_i18n( $key_value, $this->_slug );
7178
+ }
7179
+
7180
+ /* Account Page
7181
+ ------------------------------------------------------------------------------------------------------------------*/
7182
+ /**
7183
+ * Update site information.
7184
+ *
7185
+ * @author Vova Feldman (@svovaf)
7186
+ * @since 1.0.1
7187
+ *
7188
+ * @param bool $store Flush to Database if true.
7189
+ */
7190
+ private function _store_site( $store = true ) {
7191
+ $this->_logger->entrance();
7192
+
7193
+ $encrypted_site = clone $this->_site;
7194
+ $encrypted_site->plan = $this->_encrypt_entity( $this->_site->plan );
7195
+
7196
+ $sites = self::get_all_sites();
7197
+ $sites[ $this->_slug ] = $encrypted_site;
7198
+ self::$_accounts->set_option( 'sites', $sites, $store );
7199
+ }
7200
+
7201
+ /**
7202
+ * Update plugin's plans information.
7203
+ *
7204
+ * @author Vova Feldman (@svovaf)
7205
+ * @since 1.0.2
7206
+ *
7207
+ * @param bool $store Flush to Database if true.
7208
+ */
7209
+ private function _store_plans( $store = true ) {
7210
+ $this->_logger->entrance();
7211
+
7212
+ $plans = self::get_all_plans();
7213
+
7214
+ // Copy plans.
7215
+ $encrypted_plans = array();
7216
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
7217
+ $encrypted_plans[] = $this->_encrypt_entity( $this->_plans[ $i ] );
7218
+ }
7219
+
7220
+ $plans[ $this->_slug ] = $encrypted_plans;
7221
+ self::$_accounts->set_option( 'plans', $plans, $store );
7222
+ }
7223
+
7224
+ /**
7225
+ * Update user's plugin licenses.
7226
+ *
7227
+ * @author Vova Feldman (@svovaf)
7228
+ * @since 1.0.5
7229
+ *
7230
+ * @param bool $store
7231
+ * @param string|bool $plugin_slug
7232
+ * @param FS_Plugin_License[] $licenses
7233
+ */
7234
+ private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
7235
+ $this->_logger->entrance();
7236
+
7237
+ $all_licenses = self::get_all_licenses();
7238
+
7239
+ if ( ! is_string( $plugin_slug ) ) {
7240
+ $plugin_slug = $this->_slug;
7241
+ $licenses = $this->_licenses;
7242
+ }
7243
+
7244
+ if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
7245
+ $all_licenses[ $plugin_slug ] = array();
7246
+ }
7247
+
7248
+ $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
7249
+
7250
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
7251
+ }
7252
+
7253
+ /**
7254
+ * Update user information.
7255
+ *
7256
+ * @author Vova Feldman (@svovaf)
7257
+ * @since 1.0.1
7258
+ *
7259
+ * @param bool $store Flush to Database if true.
7260
+ */
7261
+ private function _store_user( $store = true ) {
7262
+ $this->_logger->entrance();
7263
+
7264
+ $users = self::get_all_users();
7265
+ $users[ $this->_user->id ] = $this->_user;
7266
+ self::$_accounts->set_option( 'users', $users, $store );
7267
+ }
7268
+
7269
+ /**
7270
+ * Update new updates information.
7271
+ *
7272
+ * @author Vova Feldman (@svovaf)
7273
+ * @since 1.0.4
7274
+ *
7275
+ * @param FS_Plugin_Tag|null $update
7276
+ * @param bool $store Flush to Database if true.
7277
+ * @param bool|number $plugin_id
7278
+ */
7279
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
7280
+ $this->_logger->entrance();
7281
+
7282
+ if ( $update instanceof FS_Plugin_Tag ) {
7283
+ $update->updated = time();
7284
+ }
7285
+
7286
+ if ( ! is_numeric( $plugin_id ) ) {
7287
+ $plugin_id = $this->_plugin->id;
7288
+ }
7289
+
7290
+ $updates = self::get_all_updates();
7291
+ $updates[ $plugin_id ] = $update;
7292
+ self::$_accounts->set_option( 'updates', $updates, $store );
7293
+ }
7294
+
7295
+ /**
7296
+ * Update new updates information.
7297
+ *
7298
+ * @author Vova Feldman (@svovaf)
7299
+ * @since 1.0.6
7300
+ *
7301
+ * @param FS_Plugin[] $plugin_addons
7302
+ * @param bool $store Flush to Database if true.
7303
+ */
7304
+ private function _store_addons( $plugin_addons, $store = true ) {
7305
+ $this->_logger->entrance();
7306
+
7307
+ $addons = self::get_all_addons();
7308
+ $addons[ $this->_plugin->id ] = $plugin_addons;
7309
+ self::$_accounts->set_option( 'addons', $addons, $store );
7310
+ }
7311
+
7312
+ /**
7313
+ * Delete plugin's associated add-ons.
7314
+ *
7315
+ * @author Vova Feldman (@svovaf)
7316
+ * @since 1.0.8
7317
+ *
7318
+ * @param bool $store
7319
+ *
7320
+ * @return bool
7321
+ */
7322
+ private function _delete_account_addons( $store = true ) {
7323
+ $all_addons = self::get_all_account_addons();
7324
+
7325
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
7326
+ return false;
7327
+ }
7328
+
7329
+ unset( $all_addons[ $this->_plugin->id ] );
7330
+
7331
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
7332
+
7333
+ return true;
7334
+ }
7335
+
7336
+ /**
7337
+ * Update account add-ons list.
7338
+ *
7339
+ * @author Vova Feldman (@svovaf)
7340
+ * @since 1.0.6
7341
+ *
7342
+ * @param FS_Plugin[] $addons
7343
+ * @param bool $store Flush to Database if true.
7344
+ */
7345
+ private function _store_account_addons( $addons, $store = true ) {
7346
+ $this->_logger->entrance();
7347
+
7348
+ $all_addons = self::get_all_account_addons();
7349
+ $all_addons[ $this->_plugin->id ] = $addons;
7350
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
7351
+ }
7352
+
7353
+ /**
7354
+ * Store account params in the Database.
7355
+ *
7356
+ * @author Vova Feldman (@svovaf)
7357
+ * @since 1.0.1
7358
+ */
7359
+ private function _store_account() {
7360
+ $this->_logger->entrance();
7361
+
7362
+ $this->_store_site( false );
7363
+ $this->_store_user( false );
7364
+ $this->_store_plans( false );
7365
+ $this->_store_licenses( false );
7366
+
7367
+ self::$_accounts->store();
7368
+ }
7369
+
7370
+ /**
7371
+ * Sync user's information.
7372
+ *
7373
+ * @author Vova Feldman (@svovaf)
7374
+ * @since 1.0.3
7375
+ * @uses FS_Api
7376
+ */
7377
+ private function _handle_account_user_sync() {
7378
+ $this->_logger->entrance();
7379
+
7380
+ $api = $this->get_api_user_scope();
7381
+
7382
+ // Get user's information.
7383
+ $user = $api->get( '/', true );
7384
+
7385
+ if ( isset( $user->id ) ) {
7386
+ $this->_user->first = $user->first;
7387
+ $this->_user->last = $user->last;
7388
+ $this->_user->email = $user->email;
7389
+
7390
+ $is_menu_item_account_visible = $this->_menu->is_submenu_item_visible( 'account' );
7391
+
7392
+ if ( $user->is_verified &&
7393
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
7394
+ ) {
7395
+ $this->_user->is_verified = true;
7396
+
7397
+ $this->do_action( 'account_email_verified', $user->email );
7398
+
7399
+ $this->_admin_notices->add(
7400
+ __fs( 'email-verified-message', $this->_slug ),
7401
+ __fs( 'right-on', $this->_slug ) . '!',
7402
+ 'success',
7403
+ // Make admin sticky if account menu item is invisible,
7404
+ // since the page will be auto redirected to the plugin's
7405
+ // main settings page, and the non-sticky message
7406
+ // will disappear.
7407
+ ! $is_menu_item_account_visible,
7408
+ false,
7409
+ 'email_verified'
7410
+ );
7411
+ }
7412
+
7413
+ // Flush user details to DB.
7414
+ $this->_store_user();
7415
+
7416
+ $this->do_action( 'after_account_user_sync', $user );
7417
+
7418
+ /**
7419
+ * If account menu item is hidden, redirect to plugin's main settings page.
7420
+ *
7421
+ * @author Vova Feldman (@svovaf)
7422
+ * @since 1.1.6
7423
+ *
7424
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
7425
+ */
7426
+ if ( ! $is_menu_item_account_visible ) {
7427
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
7428
+ exit();
7429
+ }
7430
+ }
7431
+ }
7432
+ }
7433
+
7434
+ /**
7435
+ * @author Vova Feldman (@svovaf)
7436
+ * @since 1.0.5
7437
+ * @uses FS_Api
7438
+ *
7439
+ * @param bool $flush
7440
+ *
7441
+ * @return object|\FS_Site
7442
+ */
7443
+ private function _fetch_site( $flush = false ) {
7444
+ $this->_logger->entrance();
7445
+ $api = $this->get_api_site_scope();
7446
+
7447
+ $site = $api->get( '/', $flush );
7448
+
7449
+ if ( ! isset( $site->error ) ) {
7450
+ $site = new FS_Site( $site );
7451
+ $site->slug = $this->_slug;
7452
+ $site->version = $this->get_plugin_version();
7453
+ }
7454
+
7455
+ return $site;
7456
+ }
7457
+
7458
+ /**
7459
+ * @param bool $store
7460
+ *
7461
+ * @return FS_Plugin_Plan|object|false
7462
+ */
7463
+ private function _enrich_site_plan( $store = true ) {
7464
+ // Try to load plan from local cache.
7465
+ $plan = $this->_get_plan_by_id( $this->_site->plan->id );
7466
+
7467
+ if ( false === $plan ) {
7468
+ $plan = $this->_fetch_site_plan();
7469
+ }
7470
+
7471
+ if ( $plan instanceof FS_Plugin_Plan ) {
7472
+ $this->_update_plan( $plan, $store );
7473
+ }
7474
+
7475
+ return $plan;
7476
+ }
7477
+
7478
+ /**
7479
+ * @author Vova Feldman (@svovaf)
7480
+ * @since 1.0.9
7481
+ * @uses FS_Api
7482
+ *
7483
+ * @param bool $store
7484
+ *
7485
+ * @return FS_Plugin_Plan|object|false
7486
+ */
7487
+ private function _enrich_site_trial_plan( $store = true ) {
7488
+ // Try to load plan from local cache.
7489
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
7490
+
7491
+ if ( false === $trial_plan ) {
7492
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
7493
+ }
7494
+
7495
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
7496
+ $this->_storage->store( 'trial_plan', $trial_plan, $store );
7497
+ }
7498
+
7499
+ return $trial_plan;
7500
+ }
7501
+
7502
+ /**
7503
+ * @author Vova Feldman (@svovaf)
7504
+ * @since 1.0.9
7505
+ * @uses FS_Api
7506
+ *
7507
+ * @param number|bool $license_id
7508
+ *
7509
+ * @return FS_Subscription|object|bool
7510
+ */
7511
+ private function _fetch_site_license_subscription( $license_id = false ) {
7512
+ $this->_logger->entrance();
7513
+ $api = $this->get_api_site_scope();
7514
+
7515
+ if ( ! is_numeric( $license_id ) ) {
7516
+ $license_id = $this->_license->id;
7517
+ }
7518
+
7519
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
7520
+
7521
+ return ! isset( $result->error ) ?
7522
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
7523
+ new FS_Subscription( $result->subscriptions[0] ) :
7524
+ false
7525
+ ) :
7526
+ $result;
7527
+ }
7528
+
7529
+ /**
7530
+ * @author Vova Feldman (@svovaf)
7531
+ * @since 1.0.4
7532
+ * @uses FS_Api
7533
+ *
7534
+ * @param number|bool $plan_id
7535
+ *
7536
+ * @return FS_Plugin_Plan|object
7537
+ */
7538
+ private function _fetch_site_plan( $plan_id = false ) {
7539
+ $this->_logger->entrance();
7540
+ $api = $this->get_api_site_scope();
7541
+
7542
+ if ( ! is_numeric( $plan_id ) ) {
7543
+ $plan_id = $this->_site->plan->id;
7544
+ }
7545
+
7546
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
7547
+
7548
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
7549
+ }
7550
+
7551
+ /**
7552
+ * @author Vova Feldman (@svovaf)
7553
+ * @since 1.0.5
7554
+ * @uses FS_Api
7555
+ *
7556
+ * @return FS_Plugin_Plan[]|object
7557
+ */
7558
+ private function _fetch_plugin_plans() {
7559
+ $this->_logger->entrance();
7560
+ $api = $this->get_api_site_scope();
7561
+
7562
+ $result = $api->get( '/plans.json', true );
7563
+
7564
+ if ( ! $this->is_api_error( $result ) ) {
7565
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
7566
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
7567
+ }
7568
+
7569
+ $result = $result->plans;
7570
+ }
7571
+
7572
+ return $result;
7573
+ }
7574
+
7575
+ /**
7576
+ * @author Vova Feldman (@svovaf)
7577
+ * @since 1.0.5
7578
+ * @uses FS_Api
7579
+ *
7580
+ * @param number|bool $plugin_id
7581
+ * @param number|bool $site_license_id
7582
+ *
7583
+ * @return FS_Plugin_License[]|object
7584
+ */
7585
+ private function _fetch_licenses( $plugin_id = false, $site_license_id = false ) {
7586
+ $this->_logger->entrance();
7587
+
7588
+ $api = $this->get_api_user_scope();
7589
+
7590
+ if ( ! is_numeric( $plugin_id ) ) {
7591
+ $plugin_id = $this->_plugin->id;
7592
+ }
7593
+
7594
+ $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
7595
+
7596
+ $is_site_license_synced = false;
7597
+
7598
+ if ( ! isset( $result->error ) ) {
7599
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
7600
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
7601
+
7602
+ if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
7603
+ $is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
7604
+ }
7605
+ }
7606
+
7607
+ $result = $result->licenses;
7608
+ }
7609
+
7610
+ if ( ! $is_site_license_synced ) {
7611
+ $api = $this->get_api_site_scope();
7612
+
7613
+ if ( is_numeric( $site_license_id ) ) {
7614
+ // Try to retrieve a foreign license that is linked to the install.
7615
+ $api_result = $api->call( '/licenses.json' );
7616
+
7617
+ if ( ! isset( $api_result->error ) ) {
7618
+ $licenses = $api_result->licenses;
7619
+
7620
+ if ( ! empty( $licenses ) ) {
7621
+ $result[] = new FS_Plugin_License( $licenses[0] );
7622
+ }
7623
+ }
7624
+ } else if ( is_object( $this->_license ) ) {
7625
+ // Fetch foreign license by ID and license key.
7626
+ $license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
7627
+ urlencode( $this->_license->secret_key ) );
7628
+
7629
+ if ( ! isset( $license->error ) ) {
7630
+ $result[] = new FS_Plugin_License( $license );
7631
+ }
7632
+ }
7633
+ }
7634
+
7635
+ return $result;
7636
+ }
7637
+
7638
+ /**
7639
+ * @author Vova Feldman (@svovaf)
7640
+ * @since 1.2.0
7641
+ * @uses FS_Api
7642
+ *
7643
+ * @param number|bool $plugin_id
7644
+ *
7645
+ * @return FS_Payment[]|object
7646
+ */
7647
+ function _fetch_payments( $plugin_id = false ) {
7648
+ $this->_logger->entrance();
7649
+
7650
+ $api = $this->get_api_user_scope();
7651
+
7652
+ if ( ! is_numeric( $plugin_id ) ) {
7653
+ $plugin_id = $this->_plugin->id;
7654
+ }
7655
+
7656
+ $result = $api->get( "/plugins/{$plugin_id}/payments.json", true );
7657
+
7658
+ if ( ! isset( $result->error ) ) {
7659
+ for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
7660
+ $result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
7661
+ }
7662
+ $result = $result->payments;
7663
+ }
7664
+
7665
+ return $result;
7666
+ }
7667
+
7668
+ /**
7669
+ * @author Vova Feldman (@svovaf)
7670
+ * @since 1.0.4
7671
+ *
7672
+ * @param FS_Plugin_Plan $plan
7673
+ * @param bool $store
7674
+ */
7675
+ private function _update_plan( $plan, $store = false ) {
7676
+ $this->_logger->entrance();
7677
+
7678
+ $this->_site->plan = $plan;
7679
+ $this->_store_site( $store );
7680
+ }
7681
+
7682
+ /**
7683
+ * @author Vova Feldman (@svovaf)
7684
+ * @since 1.0.5
7685
+ *
7686
+ * @param FS_Plugin_License[] $licenses
7687
+ * @param string|bool $plugin_slug
7688
+ */
7689
+ private function _update_licenses( $licenses, $plugin_slug = false ) {
7690
+ $this->_logger->entrance();
7691
+
7692
+ if ( is_array( $licenses ) ) {
7693
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
7694
+ $licenses[ $i ]->updated = time();
7695
+ }
7696
+ }
7697
+
7698
+ if ( ! is_string( $plugin_slug ) ) {
7699
+ $this->_licenses = $licenses;
7700
+ }
7701
+
7702
+ $this->_store_licenses( true, $plugin_slug, $licenses );
7703
+ }
7704
+
7705
+ /**
7706
+ * @author Vova Feldman (@svovaf)
7707
+ * @since 1.0.4
7708
+ *
7709
+ * @param bool|number $plugin_id
7710
+ * @param bool $flush Since 1.1.7.3
7711
+ *
7712
+ * @return object|false New plugin tag info if exist.
7713
+ */
7714
+ private function _fetch_newer_version( $plugin_id = false, $flush = true ) {
7715
+ $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush );
7716
+
7717
+ if ( ! is_object( $latest_tag ) ) {
7718
+ return false;
7719
+ }
7720
+
7721
+ // Check if version is actually newer.
7722
+ $has_new_version =
7723
+ // If it's an non-installed add-on then always return latest.
7724
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
7725
+ // Compare versions.
7726
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
7727
+
7728
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
7729
+
7730
+ return $has_new_version ? $latest_tag : false;
7731
+ }
7732
+
7733
+ /**
7734
+ * @author Vova Feldman (@svovaf)
7735
+ * @since 1.0.5
7736
+ *
7737
+ * @param bool|number $plugin_id
7738
+ * @param bool $flush Since 1.1.7.3
7739
+ *
7740
+ * @return bool|FS_Plugin_Tag
7741
+ */
7742
+ function get_update( $plugin_id = false, $flush = true ) {
7743
+ $this->_logger->entrance();
7744
+
7745
+ if ( ! is_numeric( $plugin_id ) ) {
7746
+ $plugin_id = $this->_plugin->id;
7747
+ }
7748
+
7749
+ $this->_check_updates( true, $plugin_id, $flush );
7750
+ $updates = $this->get_all_updates();
7751
+
7752
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
7753
+ }
7754
+
7755
+ /**
7756
+ * Check if site assigned with active license.
7757
+ *
7758
+ * @author Vova Feldman (@svovaf)
7759
+ * @since 1.0.6
7760
+ */
7761
+ function has_active_license() {
7762
+ return (
7763
+ is_object( $this->_license ) &&
7764
+ is_numeric( $this->_license->id ) &&
7765
+ ! $this->_license->is_expired()
7766
+ );
7767
+ }
7768
+
7769
+ /**
7770
+ * Check if site assigned with license with enabled features.
7771
+ *
7772
+ * @author Vova Feldman (@svovaf)
7773
+ * @since 1.0.6
7774
+ *
7775
+ * @return bool
7776
+ */
7777
+ function has_features_enabled_license() {
7778
+ return (
7779
+ is_object( $this->_license ) &&
7780
+ is_numeric( $this->_license->id ) &&
7781
+ $this->_license->is_features_enabled()
7782
+ );
7783
+ }
7784
+
7785
+ /**
7786
+ * Check if user is a trial or have feature enabled license.
7787
+ *
7788
+ * @author Vova Feldman (@svovaf)
7789
+ * @since 1.1.7
7790
+ *
7791
+ * @return bool
7792
+ */
7793
+ function can_use_premium_code() {
7794
+ return $this->is_trial() || $this->has_features_enabled_license();
7795
+ }
7796
+
7797
+ /**
7798
+ * Sync site's plan.
7799
+ *
7800
+ * @author Vova Feldman (@svovaf)
7801
+ * @since 1.0.3
7802
+ *
7803
+ * @uses FS_Api
7804
+ *
7805
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7806
+ * the admin.
7807
+ */
7808
+ private function _sync_license( $background = false ) {
7809
+ $this->_logger->entrance();
7810
+
7811
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
7812
+
7813
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
7814
+
7815
+ if ( $is_addon_sync ) {
7816
+ $this->_sync_addon_license( $plugin_id, $background );
7817
+ } else {
7818
+ $this->_sync_plugin_license( $background );
7819
+ }
7820
+
7821
+ $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
7822
+ }
7823
+
7824
+ /**
7825
+ * Sync plugin's add-on license.
7826
+ *
7827
+ * @author Vova Feldman (@svovaf)
7828
+ * @since 1.0.6
7829
+ * @uses FS_Api
7830
+ *
7831
+ * @param number $addon_id
7832
+ * @param bool $background
7833
+ */
7834
+ private function _sync_addon_license( $addon_id, $background ) {
7835
+ $this->_logger->entrance();
7836
+
7837
+ if ( $this->is_addon_activated( $addon_id ) ) {
7838
+ // If already installed, use add-on sync.
7839
+ $fs_addon = self::get_instance_by_id( $addon_id );
7840
+ $fs_addon->_sync_license( $background );
7841
+
7842
+ return;
7843
+ }
7844
+
7845
+ // Validate add-on exists.
7846
+ $addon = $this->get_addon( $addon_id );
7847
+
7848
+ if ( ! is_object( $addon ) ) {
7849
+ return;
7850
+ }
7851
+
7852
+ // Add add-on into account add-ons.
7853
+ $account_addons = $this->get_account_addons();
7854
+ if ( ! is_array( $account_addons ) ) {
7855
+ $account_addons = array();
7856
+ }
7857
+ $account_addons[] = $addon->id;
7858
+ $account_addons = array_unique( $account_addons );
7859
+ $this->_store_account_addons( $account_addons );
7860
+
7861
+ // Load add-on licenses.
7862
+ $licenses = $this->_fetch_licenses( $addon->id );
7863
+
7864
+ // Sync add-on licenses.
7865
+ if ( ! isset( $licenses->error ) ) {
7866
+ $this->_update_licenses( $licenses, $addon->slug );
7867
+
7868
+ if ( ! $this->is_addon_installed( $addon->slug ) && FS_License_Manager::has_premium_license( $licenses ) ) {
7869
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
7870
+
7871
+ if ( ! isset( $plans_result->error ) ) {
7872
+ $plans = array();
7873
+ foreach ( $plans_result->plans as $plan ) {
7874
+ $plans[] = new FS_Plugin_Plan( $plan );
7875
+ }
7876
+
7877
+ $this->_admin_notices->add_sticky(
7878
+ FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
7879
+ sprintf(
7880
+ __fs( 'addon-successfully-upgraded-message', $this->_slug ),
7881
+ $addon->title
7882
+ ) . ' ' . $this->_get_latest_download_link(
7883
+ __fs( 'download-latest-version', $this->_slug ),
7884
+ $addon_id
7885
+ )
7886
+ :
7887
+ sprintf(
7888
+ __fs( 'addon-successfully-purchased-message', $this->_slug ),
7889
+ $addon->title
7890
+ ) . ' ' . $this->_get_latest_download_link(
7891
+ __fs( 'download-latest-version', $this->_slug ),
7892
+ $addon_id
7893
+ ),
7894
+ 'addon_plan_upgraded_' . $addon->slug,
7895
+ __fs( 'yee-haw', $this->_slug ) . '!'
7896
+ );
7897
+ }
7898
+ }
7899
+ }
7900
+ }
7901
+
7902
+ /**
7903
+ * Sync site's plugin plan.
7904
+ *
7905
+ * @author Vova Feldman (@svovaf)
7906
+ * @since 1.0.6
7907
+ * @uses FS_Api
7908
+ *
7909
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7910
+ * the admin.
7911
+ */
7912
+ private function _sync_plugin_license( $background = false ) {
7913
+ $this->_logger->entrance();
7914
+
7915
+ // Sync site info.
7916
+ $site = $this->send_install_update( array(), true );
7917
+
7918
+ $plan_change = 'none';
7919
+
7920
+ if ( $this->is_api_error( $site ) ) {
7921
+ // Show API messages only if not background sync or if paying customer.
7922
+ if ( ! $background || $this->is_paying() ) {
7923
+ // Try to ping API to see if not blocked.
7924
+ if ( ! FS_Api::test() ) {
7925
+ /**
7926
+ * Failed to ping API - blocked!
7927
+ *
7928
+ * @author Vova Feldman (@svovaf)
7929
+ * @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.
7930
+ */
7931
+ $api = $this->get_api_site_scope();
7932
+
7933
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
7934
+ self::$_global_admin_notices->add(
7935
+ sprintf(
7936
+ __fs( 'server-blocking-access', $this->_slug ),
7937
+ $this->get_plugin_name(),
7938
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
7939
+ ) . '<br> ' . __fs( 'server-error-message', $this->_slug ) . var_export( $site->error, true ),
7940
+ __fs( 'oops', $this->_slug ) . '...',
7941
+ 'error',
7942
+ $background,
7943
+ false,
7944
+ 'api_blocked'
7945
+ );
7946
+ }
7947
+ } else {
7948
+ // Authentication params are broken.
7949
+ $this->_admin_notices->add(
7950
+ __fs( 'wrong-authentication-param-message', $this->_slug ),
7951
+ __fs( 'oops', $this->_slug ) . '...',
7952
+ 'error'
7953
+ );
7954
+ }
7955
+ }
7956
+
7957
+ // No reason to continue with license sync while there are API issues.
7958
+ return;
7959
+ }
7960
+
7961
+ // Remove sticky API connectivity message.
7962
+ self::$_global_admin_notices->remove_sticky( 'api_blocked' );
7963
+
7964
+ $site = new FS_Site( $site );
7965
+
7966
+ // Sync plans.
7967
+ $this->_sync_plans();
7968
+
7969
+ if ( ! $this->has_paid_plan() ) {
7970
+ $this->_site = $site;
7971
+ $this->_enrich_site_plan( true );
7972
+ $this->_store_site();
7973
+ } else {
7974
+ /**
7975
+ * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
7976
+ * associated with that ID is not included in the user's licenses collection.
7977
+ */
7978
+ $this->_sync_licenses( $site->license_id );
7979
+
7980
+ // Check if plan / license changed.
7981
+ if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
7982
+ // Check if trial started.
7983
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
7984
+ $site->trial_ends != $this->_site->trial_ends ||
7985
+ // Check if license changed.
7986
+ $site->license_id != $this->_site->license_id
7987
+ ) {
7988
+ if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
7989
+ // New trial started.
7990
+ $this->_site = $site;
7991
+ $plan_change = 'trial_started';
7992
+
7993
+ // Store trial plan information.
7994
+ $this->_enrich_site_trial_plan( true );
7995
+
7996
+ // For trial with subscription use-case.
7997
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
7998
+
7999
+ if ( is_object( $new_license ) && ! $new_license->is_expired() ) {
8000
+ $this->_site = $site;
8001
+ $this->_update_site_license( $new_license );
8002
+ $this->_store_licenses();
8003
+ $this->_enrich_site_plan( true );
8004
+
8005
+ $this->_sync_site_subscription( $this->_license );
8006
+ }
8007
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
8008
+ // Was in trial, but now trial expired and no license ID.
8009
+ // New trial started.
8010
+ $this->_site = $site;
8011
+ $plan_change = 'trial_expired';
8012
+
8013
+ // Clear trial plan information.
8014
+ $this->_storage->trial_plan = null;
8015
+
8016
+ } else {
8017
+ $is_free = $this->is_free_plan();
8018
+
8019
+ // Make sure license exist and not expired.
8020
+ $new_license = is_null( $site->license_id ) ?
8021
+ null :
8022
+ $this->_get_license_by_id( $site->license_id );
8023
+
8024
+ if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
8025
+ // License cancelled.
8026
+ $this->_site = $site;
8027
+ $this->_update_site_license( $new_license );
8028
+ $this->_store_licenses();
8029
+ $this->_enrich_site_plan( true );
8030
+
8031
+ $plan_change = 'cancelled';
8032
+ } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
8033
+ // The license is expired, so ignore upgrade method.
8034
+ } else {
8035
+ // License changed.
8036
+ $this->_site = $site;
8037
+ $this->_update_site_license( $new_license );
8038
+ $this->_store_licenses();
8039
+ $this->_enrich_site_plan( true );
8040
+
8041
+ $plan_change = $is_free ?
8042
+ 'upgraded' :
8043
+ ( is_object( $new_license ) ?
8044
+ 'changed' :
8045
+ 'downgraded' );
8046
+ }
8047
+ }
8048
+
8049
+ // Store updated site info.
8050
+ $this->_store_site();
8051
+ } else {
8052
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
8053
+ if ( ! $this->has_features_enabled_license() ) {
8054
+ $this->_deactivate_license();
8055
+ $plan_change = 'downgraded';
8056
+ } else {
8057
+ $plan_change = 'expired';
8058
+ }
8059
+ }
8060
+
8061
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
8062
+ $this->_sync_site_subscription( $this->_license );
8063
+ }
8064
+ }
8065
+ }
8066
+
8067
+ if ( $this->has_paid_plan() ) {
8068
+ switch ( $plan_change ) {
8069
+ case 'none':
8070
+ if ( ! $background && is_admin() ) {
8071
+ $plan = $this->is_trial() ?
8072
+ $this->_storage->trial_plan :
8073
+ $this->_site->plan;
8074
+
8075
+ $this->_admin_notices->add(
8076
+ sprintf(
8077
+ __fs( 'plan-did-not-change-message', $this->_slug ) . ' ' .
8078
+ sprintf(
8079
+ '<a href="%s">%s</a>',
8080
+ $this->contact_url(
8081
+ 'bug',
8082
+ sprintf( __fs( 'plan-did-not-change-email-message', $this->_slug ),
8083
+ strtoupper( $plan->name )
8084
+ )
8085
+ ),
8086
+ __fs( 'contact-us-here', $this->_slug )
8087
+ ),
8088
+ '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . __fs( 'trial', $this->_slug ) : '' ) . '</b></i>'
8089
+ ),
8090
+ __fs( 'hmm', $this->_slug ) . '...'
8091
+ );
8092
+ }
8093
+ break;
8094
+ case 'upgraded':
8095
+ $this->_admin_notices->add_sticky(
8096
+ sprintf(
8097
+ __fs( 'plan-upgraded-message', $this->_slug ),
8098
+ '<i>' . $this->get_plugin_name() . '</i>'
8099
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
8100
+ __fs( 'download-latest-x-version', $this->_slug ),
8101
+ $this->_site->plan->title
8102
+ ) )
8103
+ ),
8104
+ 'plan_upgraded',
8105
+ __fs( 'yee-haw', $this->_slug ) . '!'
8106
+ );
8107
+
8108
+ $this->_admin_notices->remove_sticky( array(
8109
+ 'trial_started',
8110
+ 'trial_promotion',
8111
+ 'trial_expired',
8112
+ 'activation_complete',
8113
+ ) );
8114
+ break;
8115
+ case 'changed':
8116
+ $this->_admin_notices->add_sticky(
8117
+ sprintf(
8118
+ __fs( 'plan-changed-to-x-message', $this->_slug ),
8119
+ $this->_site->plan->title
8120
+ ),
8121
+ 'plan_changed'
8122
+ );
8123
+
8124
+ $this->_admin_notices->remove_sticky( array(
8125
+ 'trial_started',
8126
+ 'trial_promotion',
8127
+ 'trial_expired',
8128
+ 'activation_complete',
8129
+ ) );
8130
+ break;
8131
+ case 'downgraded':
8132
+ $this->_admin_notices->add_sticky(
8133
+ sprintf( __fs( 'license-expired-blocking-message', $this->_slug ) ),
8134
+ 'license_expired',
8135
+ __fs( 'hmm', $this->_slug ) . '...'
8136
+ );
8137
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
8138
+ break;
8139
+ case 'cancelled':
8140
+ $this->_admin_notices->add(
8141
+ __fs( 'license-cancelled', $this->_slug ) . ' ' .
8142
+ sprintf(
8143
+ '<a href="%s">%s</a>',
8144
+ $this->contact_url( 'bug' ),
8145
+ __fs( 'contact-us-here', $this->_slug )
8146
+ ),
8147
+ __fs( 'hmm', $this->_slug ) . '...',
8148
+ 'error'
8149
+ );
8150
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
8151
+ break;
8152
+ case 'expired':
8153
+ $this->_admin_notices->add_sticky(
8154
+ sprintf( __fs( 'license-expired-non-blocking-message', $this->_slug ), $this->_site->plan->title ),
8155
+ 'license_expired',
8156
+ __fs( 'hmm', $this->_slug ) . '...'
8157
+ );
8158
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
8159
+ break;
8160
+ case 'trial_started':
8161
+ $this->_admin_notices->add_sticky(
8162
+ sprintf(
8163
+ __fs( 'trial-started-message', $this->_slug ),
8164
+ '<i>' . $this->get_plugin_name() . '</i>'
8165
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
8166
+ __fs( 'download-latest-x-version', $this->_slug ),
8167
+ $this->_storage->trial_plan->title
8168
+ ) ) ),
8169
+ 'trial_started',
8170
+ __fs( 'yee-haw', $this->_slug ) . '!'
8171
+ );
8172
+
8173
+ $this->_admin_notices->remove_sticky( array(
8174
+ 'trial_promotion',
8175
+ ) );
8176
+ break;
8177
+ case 'trial_expired':
8178
+ $this->_admin_notices->add_sticky(
8179
+ __fs( 'trial-expired-message', $this->_slug ),
8180
+ 'trial_expired',
8181
+ __fs( 'hmm', $this->_slug ) . '...'
8182
+ );
8183
+ $this->_admin_notices->remove_sticky( array(
8184
+ 'trial_started',
8185
+ 'trial_promotion',
8186
+ 'plan_upgraded',
8187
+ ) );
8188
+ break;
8189
+ }
8190
+ }
8191
+
8192
+ if ( 'none' !== $plan_change ) {
8193
+ $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
8194
+ }
8195
+ }
8196
+
8197
+ /**
8198
+ * @author Vova Feldman (@svovaf)
8199
+ * @since 1.0.5
8200
+ *
8201
+ * @param bool $background
8202
+ */
8203
+ protected function _activate_license( $background = false ) {
8204
+ $this->_logger->entrance();
8205
+
8206
+ $license_id = fs_request_get( 'license_id' );
8207
+
8208
+ if ( FS_Plugin_License::is_valid_id( $license_id ) && $license_id == $this->_site->license_id ) {
8209
+ // License is already activated.
8210
+ return;
8211
+ }
8212
+
8213
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
8214
+ $this->_get_license_by_id( $license_id ) :
8215
+ $this->_get_available_premium_license();
8216
+
8217
+ if ( ! is_object( $premium_license ) ) {
8218
+ return;
8219
+ }
8220
+
8221
+ /**
8222
+ * If the premium license is already associated with the install, just
8223
+ * update the license reference (activation is not required).
8224
+ *
8225
+ * @since 1.1.9
8226
+ */
8227
+ if ( $premium_license->id == $this->_site->license_id ) {
8228
+ // License is already activated.
8229
+ $this->_update_site_license( $premium_license );
8230
+ $this->_enrich_site_plan( false );
8231
+ $this->_store_account();
8232
+
8233
+ return;
8234
+ }
8235
+
8236
+ if ( $this->_site->user_id != $premium_license->user_id ) {
8237
+ $api_request_params = array( 'license_key' => $premium_license->secret_key );
8238
+ } else {
8239
+ $api_request_params = array();
8240
+ }
8241
+
8242
+ $api = $this->get_api_site_scope();
8243
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );
8244
+
8245
+ if ( $this->is_api_error( $license ) ) {
8246
+ if ( ! $background ) {
8247
+ $this->_admin_notices->add(
8248
+ __fs( 'license-activation-failed-message', $this->_slug ) . '<br> ' .
8249
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license, true ),
8250
+ __fs( 'hmm', $this->_slug ) . '...',
8251
+ 'error'
8252
+ );
8253
+ }
8254
+
8255
+ return;
8256
+ }
8257
+
8258
+ $premium_license = new FS_Plugin_License( $license );
8259
+
8260
+ // Updated site plan.
8261
+ $site = $this->get_api_site_scope()->get( '/', true );
8262
+ if ( ! $this->is_api_error( $site ) ) {
8263
+ $this->_site = new FS_Site( $site );
8264
+ }
8265
+ $this->_update_site_license( $premium_license );
8266
+ $this->_enrich_site_plan( false );
8267
+
8268
+ $this->_store_account();
8269
+
8270
+ if ( ! $background ) {
8271
+ $this->_admin_notices->add_sticky(
8272
+ __fs( 'license-activated-message', $this->_slug ) .
8273
+ ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
8274
+ __fs( 'download-latest-x-version', $this->_slug ),
8275
+ $this->_site->plan->title
8276
+ ) ) ),
8277
+ 'license_activated',
8278
+ __fs( 'yee-haw', $this->_slug ) . '!'
8279
+ );
8280
+ }
8281
+
8282
+ $this->_admin_notices->remove_sticky( array(
8283
+ 'trial_promotion',
8284
+ 'license_expired',
8285
+ ) );
8286
+ }
8287
+
8288
+ /**
8289
+ * @author Vova Feldman (@svovaf)
8290
+ * @since 1.0.5
8291
+ *
8292
+ * @param bool $show_notice
8293
+ */
8294
+ protected function _deactivate_license( $show_notice = true ) {
8295
+ $this->_logger->entrance();
8296
+
8297
+ if ( ! is_object( $this->_license ) ) {
8298
+ $this->_admin_notices->add(
8299
+ sprintf( __fs( 'no-active-license-message', $this->_slug ), $this->_site->plan->title ),
8300
+ __fs( 'hmm', $this->_slug ) . '...'
8301
+ );
8302
+
8303
+ return;
8304
+ }
8305
+
8306
+ $api = $this->get_api_site_scope();
8307
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
8308
+
8309
+ if ( isset( $license->error ) ) {
8310
+ $this->_admin_notices->add(
8311
+ __fs( 'license-deactivation-failed-message', $this->_slug ) . '<br> ' .
8312
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license->error, true ),
8313
+ __fs( 'hmm', $this->_slug ) . '...',
8314
+ 'error'
8315
+ );
8316
+
8317
+ return;
8318
+ }
8319
+
8320
+ // Update license cache.
8321
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
8322
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
8323
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
8324
+ }
8325
+ }
8326
+
8327
+ // Updated site plan to default.
8328
+ $this->_sync_plans();
8329
+ $this->_site->plan->id = $this->_plans[0]->id;
8330
+ // Unlink license from site.
8331
+ $this->_update_site_license( null );
8332
+ $this->_enrich_site_plan( false );
8333
+
8334
+ $this->_store_account();
8335
+
8336
+ if ( $show_notice ) {
8337
+ $this->_admin_notices->add(
8338
+ sprintf( __fs( 'license-deactivation-message', $this->_slug ), $this->_site->plan->title ),
8339
+ __fs( 'ok', $this->_slug )
8340
+ );
8341
+ }
8342
+
8343
+ $this->_admin_notices->remove_sticky( array(
8344
+ 'plan_upgraded',
8345
+ 'license_activated',
8346
+ ) );
8347
+ }
8348
+
8349
+ /**
8350
+ * Site plan downgrade.
8351
+ *
8352
+ * @author Vova Feldman (@svovaf)
8353
+ * @since 1.0.4
8354
+ *
8355
+ * @uses FS_Api
8356
+ */
8357
+ private function _downgrade_site() {
8358
+ $this->_logger->entrance();
8359
+
8360
+ $api = $this->get_api_site_scope();
8361
+ $site = $api->call( 'downgrade.json', 'put' );
8362
+
8363
+ $plan_downgraded = false;
8364
+ $plan = false;
8365
+ if ( ! isset( $site->error ) ) {
8366
+ $prev_plan_id = $this->_site->plan->id;
8367
+
8368
+ // Update new site plan id.
8369
+ $this->_site->plan->id = $site->plan_id;
8370
+
8371
+ $plan = $this->_enrich_site_plan();
8372
+ $subscription = $this->_sync_site_subscription( $this->_license );
8373
+
8374
+ // Plan downgraded if plan was changed or subscription was cancelled.
8375
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
8376
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
8377
+ } else {
8378
+ // handle different error cases.
8379
+
8380
+ }
8381
+
8382
+ if ( $plan_downgraded ) {
8383
+ // Remove previous sticky message about upgrade (if exist).
8384
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
8385
+
8386
+ $this->_admin_notices->add(
8387
+ sprintf( __fs( 'plan-x-downgraded-message', $this->_slug ),
8388
+ $plan->title,
8389
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
8390
+ )
8391
+ );
8392
+
8393
+ // Store site updates.
8394
+ $this->_store_site();
8395
+ } else {
8396
+ $this->_admin_notices->add(
8397
+ __fs( 'plan-downgraded-failure-message', $this->_slug ),
8398
+ __fs( 'oops', $this->_slug ) . '...',
8399
+ 'error'
8400
+ );
8401
+ }
8402
+ }
8403
+
8404
+ /**
8405
+ * @author Vova Feldman (@svovaf)
8406
+ * @since 1.1.8.1
8407
+ *
8408
+ * @param bool|string $plan_name
8409
+ *
8410
+ * @return bool If trial was successfully started.
8411
+ */
8412
+ function start_trial( $plan_name = false ) {
8413
+ $this->_logger->entrance();
8414
+
8415
+ if ( $this->is_trial() ) {
8416
+ // Already in trial mode.
8417
+ $this->_admin_notices->add(
8418
+ __fs( 'in-trial-mode', $this->_slug ),
8419
+ __fs( 'oops', $this->_slug ) . '...',
8420
+ 'error'
8421
+ );
8422
+
8423
+ return false;
8424
+ }
8425
+
8426
+ if ( $this->_site->is_trial_utilized() ) {
8427
+ // Trial was already utilized.
8428
+ $this->_admin_notices->add(
8429
+ __fs( 'trial-utilized', $this->_slug ),
8430
+ __fs( 'oops', $this->_slug ) . '...',
8431
+ 'error'
8432
+ );
8433
+
8434
+ return false;
8435
+ }
8436
+
8437
+ if ( false !== $plan_name ) {
8438
+ $plan = $this->get_plan_by_name( $plan_name );
8439
+
8440
+ if ( false === $plan ) {
8441
+ // Plan doesn't exist.
8442
+ $this->_admin_notices->add(
8443
+ sprintf( __fs( 'trial-plan-x-not-exist', $this->_slug ), $plan_name ),
8444
+ __fs( 'oops', $this->_slug ) . '...',
8445
+ 'error'
8446
+ );
8447
+
8448
+ return false;
8449
+ }
8450
+
8451
+ if ( ! $plan->has_trial() ) {
8452
+ // Plan doesn't exist.
8453
+ $this->_admin_notices->add(
8454
+ sprintf( __fs( 'plan-x-no-trial', $this->_slug ), $plan_name ),
8455
+ __fs( 'oops', $this->_slug ) . '...',
8456
+ 'error'
8457
+ );
8458
+
8459
+ return false;
8460
+ }
8461
+ } else {
8462
+ if ( ! $this->has_trial_plan() ) {
8463
+ // None of the plans have a trial.
8464
+ $this->_admin_notices->add(
8465
+ __fs( 'no-trials', $this->_slug ),
8466
+ __fs( 'oops', $this->_slug ) . '...',
8467
+ 'error'
8468
+ );
8469
+
8470
+ return false;
8471
+ }
8472
+
8473
+ $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
8474
+
8475
+ $plan = $plans_with_trial[0];
8476
+ }
8477
+
8478
+ $api = $this->get_api_site_scope();
8479
+ $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
8480
+
8481
+ if ( $this->is_api_error( $plan ) ) {
8482
+ // Some API error while trying to start the trial.
8483
+ $this->_admin_notices->add(
8484
+ __fs( 'unexpected-api-error', $this->_slug ) . ' ' . var_export( $plan, true ),
8485
+ __fs( 'oops', $this->_slug ) . '...',
8486
+ 'error'
8487
+ );
8488
+
8489
+ return false;
8490
+ }
8491
+
8492
+ // Sync license.
8493
+ $this->_sync_license();
8494
+
8495
+ return $this->is_trial();
8496
+ }
8497
+
8498
+ /**
8499
+ * Cancel site trial.
8500
+ *
8501
+ * @author Vova Feldman (@svovaf)
8502
+ * @since 1.0.9
8503
+ *
8504
+ * @uses FS_Api
8505
+ */
8506
+ private function _cancel_trial() {
8507
+ $this->_logger->entrance();
8508
+
8509
+ if ( ! $this->is_trial() ) {
8510
+ $this->_admin_notices->add(
8511
+ __fs( 'trial-cancel-no-trial-message', $this->_slug ),
8512
+ __fs( 'oops', $this->_slug ) . '...',
8513
+ 'error'
8514
+ );
8515
+
8516
+ return;
8517
+ }
8518
+
8519
+ $api = $this->get_api_site_scope();
8520
+ $site = $api->call( 'trials.json', 'delete' );
8521
+
8522
+ $trial_cancelled = false;
8523
+
8524
+ if ( ! $this->is_api_error( $site ) ) {
8525
+ $prev_trial_ends = $this->_site->trial_ends;
8526
+
8527
+ if ( $this->is_paid_trial() ) {
8528
+ $this->_license->expiration = $site->trial_ends;
8529
+ $this->_license->is_cancelled = true;
8530
+ $this->_update_site_license( $this->_license );
8531
+ $this->_store_licenses();
8532
+
8533
+ // Clear subscription reference.
8534
+ $this->_sync_site_subscription( null );
8535
+ }
8536
+
8537
+ // Update site info.
8538
+ $this->_site = new FS_Site( $site );
8539
+ $this->_enrich_site_plan();
8540
+
8541
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
8542
+ } else {
8543
+ // handle different error cases.
8544
+
8545
+ }
8546
+
8547
+ if ( $trial_cancelled ) {
8548
+ // Remove previous sticky messages about upgrade or trial (if exist).
8549
+ $this->_admin_notices->remove_sticky( array(
8550
+ 'trial_started',
8551
+ 'trial_promotion',
8552
+ 'plan_upgraded',
8553
+ ) );
8554
+
8555
+ // Store site updates.
8556
+ $this->_store_site();
8557
+
8558
+ // Clear trial plan information.
8559
+ unset( $this->_storage->trial_plan );
8560
+
8561
+ if ( ! $this->is_addon() ||
8562
+ ! $this->deactivate_premium_only_addon_without_license( true )
8563
+ ) {
8564
+ $this->_admin_notices->add(
8565
+ sprintf( __fs( 'trial-cancel-message', $this->_slug ), $this->_storage->trial_plan->title )
8566
+ );
8567
+ }
8568
+ } else {
8569
+ $this->_admin_notices->add(
8570
+ __fs( 'trial-cancel-failure-message', $this->_slug ),
8571
+ __fs( 'oops', $this->_slug ) . '...',
8572
+ 'error'
8573
+ );
8574
+ }
8575
+ }
8576
+
8577
+ /**
8578
+ * @author Vova Feldman (@svovaf)
8579
+ * @since 1.0.6
8580
+ *
8581
+ * @param bool|number $plugin_id
8582
+ *
8583
+ * @return bool
8584
+ */
8585
+ private function _is_addon_id( $plugin_id ) {
8586
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
8587
+ }
8588
+
8589
+ /**
8590
+ * Check if user eligible to download premium version updates.
8591
+ *
8592
+ * @author Vova Feldman (@svovaf)
8593
+ * @since 1.0.6
8594
+ *
8595
+ * @return bool
8596
+ */
8597
+ private function _can_download_premium() {
8598
+ return $this->has_active_license() ||
8599
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
8600
+ }
8601
+
8602
+ /**
8603
+ *
8604
+ * @author Vova Feldman (@svovaf)
8605
+ * @since 1.0.6
8606
+ *
8607
+ * @param bool|number $addon_id
8608
+ * @param string $type "json" or "zip"
8609
+ *
8610
+ * @return string
8611
+ */
8612
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
8613
+
8614
+ $is_addon = $this->_is_addon_id( $addon_id );
8615
+
8616
+ $is_premium = null;
8617
+ if ( ! $is_addon ) {
8618
+ $is_premium = $this->_can_download_premium();
8619
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
8620
+ $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
8621
+ }
8622
+
8623
+ return // If add-on, then append add-on ID.
8624
+ ( $is_addon ? "/addons/$addon_id" : '' ) .
8625
+ '/updates/latest.' . $type .
8626
+ // If add-on and not yet activated, try to fetch based on server licensing.
8627
+ ( is_bool( $is_premium ) ? '?is_premium=' . json_encode( $is_premium ) : '' );
8628
+ }
8629
+
8630
+ /**
8631
+ * @author Vova Feldman (@svovaf)
8632
+ * @since 1.0.4
8633
+ *
8634
+ * @param bool|number $addon_id
8635
+ * @param bool $flush Since 1.1.7.3
8636
+ *
8637
+ * @return object|false Plugin latest tag info.
8638
+ */
8639
+ function _fetch_latest_version( $addon_id = false, $flush = true ) {
8640
+ $this->_logger->entrance();
8641
+
8642
+ /**
8643
+ * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
8644
+ * @since 1.1.7.4 Also check updates for add-ons.
8645
+ */
8646
+ if ( ! $this->is_registered() &&
8647
+ ! $this->_is_addon_id( $addon_id )
8648
+ ) {
8649
+ return false;
8650
+ }
8651
+
8652
+ $tag = $this->get_api_site_or_plugin_scope()->get(
8653
+ $this->_get_latest_version_endpoint( $addon_id, 'json' ),
8654
+ $flush
8655
+ );
8656
+
8657
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
8658
+
8659
+ $this->_logger->departure( 'Latest version ' . $latest_version );
8660
+
8661
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
8662
+ }
8663
+
8664
+ #region Download Plugin ------------------------------------------------------------------
8665
+
8666
+ /**
8667
+ * Download latest plugin version, based on plan.
8668
+ * The download will be fetched via the API first.
8669
+ *
8670
+ * @author Vova Feldman (@svovaf)
8671
+ * @since 1.0.4
8672
+ *
8673
+ * @param bool|number $plugin_id
8674
+ *
8675
+ * @uses FS_Api
8676
+ *
8677
+ * @deprecated
8678
+ */
8679
+ private function _download_latest( $plugin_id = false ) {
8680
+ $this->_logger->entrance();
8681
+
8682
+ $is_addon = $this->_is_addon_id( $plugin_id );
8683
+
8684
+ $is_premium = $this->_can_download_premium();
8685
+
8686
+ $latest = $this->get_api_site_scope()->call(
8687
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8688
+ );
8689
+
8690
+ $slug = $this->_slug;
8691
+ if ( $is_addon ) {
8692
+ $addon = $this->get_addon( $plugin_id );
8693
+ $slug = is_object( $addon ) ? $addon->slug : 'addon';
8694
+ }
8695
+
8696
+ if ( ! is_object( $latest ) ) {
8697
+ header( "Content-Type: application/zip" );
8698
+ header( "Content-Disposition: attachment; filename={$slug}" . ( ! $is_addon && $is_premium ? '-premium' : '' ) . ".zip" );
8699
+ header( "Content-Length: " . strlen( $latest ) );
8700
+ echo $latest;
8701
+
8702
+ exit();
8703
+ }
8704
+ }
8705
+
8706
+ /**
8707
+ * Download latest plugin version, based on plan.
8708
+ *
8709
+ * Not like _download_latest(), this will redirect the page
8710
+ * to secure download url to prevent dual download (from FS to WP server,
8711
+ * and then from WP server to the client / browser).
8712
+ *
8713
+ * @author Vova Feldman (@svovaf)
8714
+ * @since 1.0.9
8715
+ *
8716
+ * @param bool|number $plugin_id
8717
+ *
8718
+ * @uses FS_Api
8719
+ * @uses wp_redirect()
8720
+ */
8721
+ private function _download_latest_directly( $plugin_id = false ) {
8722
+ $this->_logger->entrance();
8723
+
8724
+ wp_redirect( $this->_get_latest_download_api_url( $plugin_id ) );
8725
+ }
8726
+
8727
+ /**
8728
+ * Get latest plugin FS API download URL.
8729
+ *
8730
+ * @author Vova Feldman (@svovaf)
8731
+ * @since 1.0.9
8732
+ *
8733
+ * @param bool|number $plugin_id
8734
+ *
8735
+ * @return string
8736
+ */
8737
+ private function _get_latest_download_api_url( $plugin_id = false ) {
8738
+ $this->_logger->entrance();
8739
+
8740
+ return $this->get_api_site_scope()->get_signed_url(
8741
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8742
+ );
8743
+ }
8744
+
8745
+ /**
8746
+ * Get payment invoice URL.
8747
+ *
8748
+ * @author Vova Feldman (@svovaf)
8749
+ * @since 1.2.0
8750
+ *
8751
+ * @param bool|number $payment_id
8752
+ *
8753
+ * @return string
8754
+ */
8755
+ function _get_invoice_api_url( $payment_id = false ) {
8756
+ $this->_logger->entrance();
8757
+
8758
+ return $this->get_api_user_scope()->get_signed_url(
8759
+ "/payments/{$payment_id}/invoice.pdf"
8760
+ );
8761
+ }
8762
+
8763
+ /**
8764
+ * Get latest plugin download link.
8765
+ *
8766
+ * @author Vova Feldman (@svovaf)
8767
+ * @since 1.0.9
8768
+ *
8769
+ * @param string $label
8770
+ * @param bool|number $plugin_id
8771
+ *
8772
+ * @return string
8773
+ */
8774
+ private function _get_latest_download_link( $label, $plugin_id = false ) {
8775
+ return sprintf(
8776
+ '<a target="_blank" href="%s">%s</a>',
8777
+ $this->_get_latest_download_local_url( $plugin_id ),
8778
+ $label
8779
+ );
8780
+ }
8781
+
8782
+ /**
8783
+ * Get latest plugin download local URL.
8784
+ *
8785
+ * @author Vova Feldman (@svovaf)
8786
+ * @since 1.0.9
8787
+ *
8788
+ * @param bool|number $plugin_id
8789
+ *
8790
+ * @return string
8791
+ */
8792
+ function _get_latest_download_local_url( $plugin_id = false ) {
8793
+ // Add timestamp to protect from caching.
8794
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
8795
+
8796
+ if ( ! empty( $plugin_id ) ) {
8797
+ $params['plugin_id'] = $plugin_id;
8798
+ }
8799
+
8800
+ return $this->get_account_url( 'download_latest', $params );
8801
+ }
8802
+
8803
+ #endregion Download Plugin ------------------------------------------------------------------
8804
+
8805
+ /**
8806
+ * @author Vova Feldman (@svovaf)
8807
+ * @since 1.0.4
8808
+ *
8809
+ * @uses FS_Api
8810
+ *
8811
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
8812
+ * was initiated by the admin.
8813
+ * @param bool|number $plugin_id
8814
+ * @param bool $flush Since 1.1.7.3
8815
+ */
8816
+ private function _check_updates( $background = false, $plugin_id = false, $flush = true ) {
8817
+ $this->_logger->entrance();
8818
+
8819
+ // Check if there's a newer version for download.
8820
+ $new_version = $this->_fetch_newer_version( $plugin_id, $flush );
8821
+
8822
+ $update = null;
8823
+ if ( is_object( $new_version ) ) {
8824
+ $update = new FS_Plugin_Tag( $new_version );
8825
+
8826
+ if ( ! $background ) {
8827
+ $this->_admin_notices->add(
8828
+ sprintf(
8829
+ __fs( 'version-x-released', $this->_slug ) . ' ' . __fs( 'please-download-x', $this->_slug ),
8830
+ $update->version,
8831
+ sprintf(
8832
+ '<a href="%s" target="_blank">%s</a>',
8833
+ $this->get_account_url( 'download_latest' ),
8834
+ sprintf( __fs( 'latest-x-version', $this->_slug ), $this->_site->plan->title )
8835
+ )
8836
+ ),
8837
+ __fs( 'new', $this->_slug ) . '!'
8838
+ );
8839
+ }
8840
+ } else if ( false === $new_version && ! $background ) {
8841
+ $this->_admin_notices->add(
8842
+ __fs( 'you-have-latest', $this->_slug ),
8843
+ __fs( 'you-are-good', $this->_slug )
8844
+ );
8845
+ }
8846
+
8847
+ $this->_store_update( $update, true, $plugin_id );
8848
+ }
8849
+
8850
+ /**
8851
+ * @author Vova Feldman (@svovaf)
8852
+ * @since 1.0.4
8853
+ *
8854
+ * @param bool $flush Since 1.1.7.3 by default add 24 hour cache.
8855
+ *
8856
+ * @return FS_Plugin[]
8857
+ *
8858
+ * @uses FS_Api
8859
+ */
8860
+ private function _sync_addons( $flush = false ) {
8861
+ $this->_logger->entrance();
8862
+
8863
+ $result = $this->get_api_site_or_plugin_scope()->get( '/addons.json?enriched=true', $flush );
8864
+
8865
+ $addons = array();
8866
+ if ( ! $this->is_api_error( $result ) ) {
8867
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
8868
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
8869
+ }
8870
+
8871
+ $this->_store_addons( $addons, true );
8872
+ }
8873
+
8874
+ return $addons;
8875
+ }
8876
+
8877
+ /**
8878
+ * Handle user email update.
8879
+ *
8880
+ * @author Vova Feldman (@svovaf)
8881
+ * @since 1.0.3
8882
+ * @uses FS_Api
8883
+ *
8884
+ * @param string $new_email
8885
+ *
8886
+ * @return object
8887
+ */
8888
+ private function _update_email( $new_email ) {
8889
+ $this->_logger->entrance();
8890
+
8891
+
8892
+ $api = $this->get_api_user_scope();
8893
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
8894
+ 'email' => $new_email,
8895
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
8896
+ 'account',
8897
+ array( 'fs_action' => 'sync_user' )
8898
+ ),
8899
+ ) );
8900
+
8901
+ if ( ! isset( $user->error ) ) {
8902
+ $this->_user->email = $user->email;
8903
+ $this->_user->is_verified = $user->is_verified;
8904
+ $this->_store_user();
8905
+ } else {
8906
+ // handle different error cases.
8907
+
8908
+ }
8909
+
8910
+ return $user;
8911
+ }
8912
+
8913
+ /**
8914
+ * @author Vova Feldman (@svovaf)
8915
+ * @since 1.1.1
8916
+ *
8917
+ * @param mixed $result
8918
+ *
8919
+ * @return bool Is API result contains an error.
8920
+ */
8921
+ private function is_api_error( $result ) {
8922
+ return ( is_object( $result ) && isset( $result->error ) ) ||
8923
+ is_string( $result );
8924
+ }
8925
+
8926
+ /**
8927
+ * Start install ownership change.
8928
+ *
8929
+ * @author Vova Feldman (@svovaf)
8930
+ * @since 1.1.1
8931
+ * @uses FS_Api
8932
+ *
8933
+ * @param string $candidate_email
8934
+ *
8935
+ * @return bool Is ownership change successfully initiated.
8936
+ */
8937
+ private function init_change_owner( $candidate_email ) {
8938
+ $this->_logger->entrance();
8939
+
8940
+ $api = $this->get_api_site_scope();
8941
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
8942
+ 'email' => $candidate_email,
8943
+ 'after_confirm_url' => $this->_get_admin_page_url(
8944
+ 'account',
8945
+ array( 'fs_action' => 'change_owner' )
8946
+ ),
8947
+ ) );
8948
+
8949
+ return ! $this->is_api_error( $result );
8950
+ }
8951
+
8952
+ /**
8953
+ * Handle install ownership change.
8954
+ *
8955
+ * @author Vova Feldman (@svovaf)
8956
+ * @since 1.1.1
8957
+ * @uses FS_Api
8958
+ *
8959
+ * @return bool Was ownership change successfully complete.
8960
+ */
8961
+ private function complete_change_owner() {
8962
+ $this->_logger->entrance();
8963
+
8964
+ $site_result = $this->get_api_site_scope( true )->get();
8965
+ $site = new FS_Site( $site_result );
8966
+ $this->_site = $site;
8967
+
8968
+ $user = new FS_User();
8969
+ $user->id = fs_request_get( 'user_id' );
8970
+
8971
+ // Validate install's user and given user.
8972
+ if ( $user->id != $this->_site->user_id ) {
8973
+ return false;
8974
+ }
8975
+
8976
+ $user->public_key = fs_request_get( 'user_public_key' );
8977
+ $user->secret_key = fs_request_get( 'user_secret_key' );
8978
+
8979
+ // Fetch new user information.
8980
+ $this->_user = $user;
8981
+ $user_result = $this->get_api_user_scope( true )->get();
8982
+ $user = new FS_User( $user_result );
8983
+ $this->_user = $user;
8984
+
8985
+ $this->_set_account( $user, $site );
8986
+
8987
+ return true;
8988
+ }
8989
+
8990
+ /**
8991
+ * Handle user name update.
8992
+ *
8993
+ * @author Vova Feldman (@svovaf)
8994
+ * @since 1.0.9
8995
+ * @uses FS_Api
8996
+ *
8997
+ * @return object
8998
+ */
8999
+ private function update_user_name() {
9000
+ $this->_logger->entrance();
9001
+ $name = fs_request_get( 'fs_user_name_' . $this->_slug, '' );
9002
+
9003
+ $api = $this->get_api_user_scope();
9004
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
9005
+ 'name' => $name,
9006
+ ) );
9007
+
9008
+ if ( ! isset( $user->error ) ) {
9009
+ $this->_user->first = $user->first;
9010
+ $this->_user->last = $user->last;
9011
+ $this->_store_user();
9012
+ } else {
9013
+ // handle different error cases.
9014
+
9015
+ }
9016
+
9017
+ return $user;
9018
+ }
9019
+
9020
+ /**
9021
+ * Verify user email.
9022
+ *
9023
+ * @author Vova Feldman (@svovaf)
9024
+ * @since 1.0.3
9025
+ * @uses FS_Api
9026
+ */
9027
+ private function verify_email() {
9028
+ $this->_handle_account_user_sync();
9029
+
9030
+ if ( $this->_user->is_verified() ) {
9031
+ return;
9032
+ }
9033
+
9034
+ $api = $this->get_api_site_scope();
9035
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
9036
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
9037
+ 'account',
9038
+ array( 'fs_action' => 'sync_user' )
9039
+ )
9040
+ ) );
9041
+
9042
+ if ( ! isset( $result->error ) ) {
9043
+ $this->_admin_notices->add( sprintf(
9044
+ __fs( 'verification-email-sent-message', $this->_slug ),
9045
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
9046
+ ) );
9047
+ } else {
9048
+ // handle different error cases.
9049
+
9050
+ }
9051
+ }
9052
+
9053
+ /**
9054
+ * @author Vova Feldman (@svovaf)
9055
+ * @since 1.1.2
9056
+ *
9057
+ * @return string
9058
+ */
9059
+ private function get_activation_url() {
9060
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url() );
9061
+ }
9062
+
9063
+ /**
9064
+ * Get the URL of the page that should be loaded after the user connect or skip in the opt-in screen.
9065
+ *
9066
+ * @author Vova Feldman (@svovaf)
9067
+ * @since 1.1.3
9068
+ *
9069
+ * @param string $filter Filter name.
9070
+ *
9071
+ * @return string
9072
+ */
9073
+ private function get_after_activation_url( $filter ) {
9074
+ $first_time_path = $this->_menu->get_first_time_path();
9075
+
9076
+ return $this->apply_filters(
9077
+ $filter,
9078
+ empty( $first_time_path ) ?
9079
+ $this->_get_admin_page_url() :
9080
+ $first_time_path
9081
+ );
9082
+ }
9083
+
9084
+ /**
9085
+ * Handle account page updates / edits / actions.
9086
+ *
9087
+ * @author Vova Feldman (@svovaf)
9088
+ * @since 1.0.2
9089
+ *
9090
+ */
9091
+ private function _handle_account_edits() {
9092
+ if ( ! current_user_can( 'activate_plugins' ) ) {
9093
+ return;
9094
+ }
9095
+
9096
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
9097
+ $action = fs_get_action();
9098
+
9099
+ switch ( $action ) {
9100
+ case 'delete_account':
9101
+ check_admin_referer( $action );
9102
+
9103
+ if ( $plugin_id == $this->get_id() ) {
9104
+ $this->delete_account_event();
9105
+
9106
+ // Clear user and site.
9107
+ $this->_site = null;
9108
+ $this->_user = null;
9109
+
9110
+ if ( fs_redirect( $this->get_activation_url() ) ) {
9111
+ exit();
9112
+ }
9113
+ } else {
9114
+ if ( $this->is_addon_activated( $plugin_id ) ) {
9115
+ $fs_addon = self::get_instance_by_id( $plugin_id );
9116
+ $fs_addon->delete_account_event();
9117
+
9118
+ if ( fs_redirect( $this->_get_admin_page_url( 'account' ) ) ) {
9119
+ exit();
9120
+ }
9121
+ }
9122
+ }
9123
+
9124
+ return;
9125
+
9126
+ case 'downgrade_account':
9127
+ check_admin_referer( $action );
9128
+ $this->_downgrade_site();
9129
+
9130
+ return;
9131
+
9132
+ case 'activate_license':
9133
+ check_admin_referer( $action );
9134
+
9135
+ if ( $plugin_id == $this->get_id() ) {
9136
+ $this->_activate_license();
9137
+ } else {
9138
+ if ( $this->is_addon_activated( $plugin_id ) ) {
9139
+ $fs_addon = self::get_instance_by_id( $plugin_id );
9140
+ $fs_addon->_activate_license();
9141
+ }
9142
+ }
9143
+
9144
+ return;
9145
+
9146
+ case 'deactivate_license':
9147
+ check_admin_referer( $action );
9148
+
9149
+ if ( $plugin_id == $this->get_id() ) {
9150
+ $this->_deactivate_license();
9151
+ } else {
9152
+ if ( $this->is_addon_activated( $plugin_id ) ) {
9153
+ $fs_addon = self::get_instance_by_id( $plugin_id );
9154
+ $fs_addon->_deactivate_license();
9155
+ }
9156
+ }
9157
+
9158
+ return;
9159
+
9160
+ case 'check_updates':
9161
+ check_admin_referer( $action );
9162
+ $this->_check_updates();
9163
+
9164
+ return;
9165
+
9166
+ case 'change_owner':
9167
+ $state = fs_request_get( 'state', 'init' );
9168
+ switch ( $state ) {
9169
+ case 'init':
9170
+ $candidate_email = fs_request_get( 'candidate_email', '' );
9171
+
9172
+ if ( $this->init_change_owner( $candidate_email ) ) {
9173
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request-sent-x', $this->_slug ), '<b>' . $this->_user->email . '</b>' ) );
9174
+ }
9175
+ break;
9176
+ case 'owner_confirmed':
9177
+ $candidate_email = fs_request_get( 'candidate_email', '' );
9178
+
9179
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request_owner-confirmed', $this->_slug ), '<b>' . $candidate_email . '</b>' ) );
9180
+ break;
9181
+ case 'candidate_confirmed':
9182
+ if ( $this->complete_change_owner() ) {
9183
+ $this->_admin_notices->add_sticky(
9184
+ sprintf( __fs( 'change-owner-request_candidate-confirmed', $this->_slug ), '<b>' . $this->_user->email . '</b>' ),
9185
+ 'ownership_changed',
9186
+ __fs( 'congrats', $this->_slug ) . '!'
9187
+ );
9188
+ } else {
9189
+ // @todo Handle failed ownership change message.
9190
+ }
9191
+ break;
9192
+ }
9193
+
9194
+ return;
9195
+
9196
+ case 'update_email':
9197
+ check_admin_referer( 'update_email' );
9198
+
9199
+ $new_email = fs_request_get( 'fs_email_' . $this->_slug, '' );
9200
+ $result = $this->_update_email( $new_email );
9201
+
9202
+ if ( isset( $result->error ) ) {
9203
+ switch ( $result->error->code ) {
9204
+ case 'user_exist':
9205
+ $this->_admin_notices->add(
9206
+ __fs( 'user-exist-message', $this->_slug ) . ' ' .
9207
+ sprintf( __fs( 'user-exist-message_ownership', $this->_slug ), '<b>' . $new_email . '</b>' ) .
9208
+ sprintf(
9209
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
9210
+ $this->get_account_url( 'change_owner', array(
9211
+ 'state' => 'init',
9212
+ 'candidate_email' => $new_email
9213
+ ) ),
9214
+ __fs( 'change-ownership', $this->_slug )
9215
+ ),
9216
+ __fs( 'oops', $this->_slug ) . '...',
9217
+ 'error'
9218
+ );
9219
+ break;
9220
+ }
9221
+ } else {
9222
+ $this->_admin_notices->add( __fs( 'email-updated-message', $this->_slug ) );
9223
+ }
9224
+
9225
+ return;
9226
+
9227
+ case 'update_user_name':
9228
+ check_admin_referer( 'update_user_name' );
9229
+
9230
+ $result = $this->update_user_name();
9231
+
9232
+ if ( isset( $result->error ) ) {
9233
+ $this->_admin_notices->add(
9234
+ __fs( 'name-update-failed-message', $this->_slug ),
9235
+ __fs( 'oops', $this->_slug ) . '...',
9236
+ 'error'
9237
+ );
9238
+ } else {
9239
+ $this->_admin_notices->add( __fs( 'name-updated-message', $this->_slug ) );
9240
+ }
9241
+
9242
+ return;
9243
+
9244
+ #region Actions that might be called from external links (e.g. email)
9245
+
9246
+ case 'cancel_trial':
9247
+ if ( $plugin_id == $this->get_id() ) {
9248
+ $this->_cancel_trial();
9249
+ } else {
9250
+ if ( $this->is_addon_activated( $plugin_id ) ) {
9251
+ $fs_addon = self::get_instance_by_id( $plugin_id );
9252
+ $fs_addon->_cancel_trial();
9253
+ }
9254
+ }
9255
+
9256
+ return;
9257
+
9258
+ case 'verify_email':
9259
+ $this->verify_email();
9260
+
9261
+ return;
9262
+
9263
+ case 'sync_user':
9264
+ $this->_handle_account_user_sync();
9265
+
9266
+ return;
9267
+
9268
+ case $this->_slug . '_sync_license':
9269
+ $this->_sync_license();
9270
+
9271
+ return;
9272
+
9273
+ case 'download_latest':
9274
+ $this->_download_latest_directly( $plugin_id );
9275
+
9276
+ return;
9277
+
9278
+ #endregion
9279
+ }
9280
+
9281
+ if ( WP_FS__IS_POST_REQUEST ) {
9282
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
9283
+ foreach ( $properties as $p ) {
9284
+ if ( 'update_' . $p === $action ) {
9285
+ check_admin_referer( $action );
9286
+
9287
+ $this->_logger->log( $action );
9288
+
9289
+ $site_property = substr( $p, strlen( 'site_' ) );
9290
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->_slug, '' );
9291
+ $this->get_site()->{$site_property} = $site_property_value;
9292
+
9293
+ // Store account after modification.
9294
+ $this->_store_site();
9295
+
9296
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
9297
+
9298
+ $this->_admin_notices->add( sprintf(
9299
+ __fs( 'x-updated', $this->_slug ),
9300
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
9301
+
9302
+ return;
9303
+ }
9304
+ }
9305
+ }
9306
+ }
9307
+
9308
+ /**
9309
+ * Account page resources load.
9310
+ *
9311
+ * @author Vova Feldman (@svovaf)
9312
+ * @since 1.0.6
9313
+ */
9314
+ function _account_page_load() {
9315
+ $this->_logger->entrance();
9316
+
9317
+ $this->_logger->info( var_export( $_REQUEST, true ) );
9318
+
9319
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
9320
+
9321
+ if ( $this->has_addons() ) {
9322
+ wp_enqueue_script( 'plugin-install' );
9323
+ add_thickbox();
9324
+
9325
+ function fs_addons_body_class( $classes ) {
9326
+ $classes .= ' plugins-php';
9327
+
9328
+ return $classes;
9329
+ }
9330
+
9331
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
9332
+ }
9333
+
9334
+ if ( $this->has_paid_plan() &&
9335
+ ! $this->has_any_license() &&
9336
+ ! $this->is_sync_executed()
9337
+ ) {
9338
+ /**
9339
+ * If no licenses found and no sync job was executed during the last 24 hours,
9340
+ * just execute the sync job right away (blocking execution).
9341
+ *
9342
+ * @since 1.1.7.3
9343
+ */
9344
+ $this->run_manual_sync();
9345
+ }
9346
+
9347
+ $this->_handle_account_edits();
9348
+
9349
+ $this->do_action( 'account_page_load_before_departure' );
9350
+ }
9351
+
9352
+ /**
9353
+ * Render account page.
9354
+ *
9355
+ * @author Vova Feldman (@svovaf)
9356
+ * @since 1.0.0
9357
+ */
9358
+ function _account_page_render() {
9359
+ $this->_logger->entrance();
9360
+
9361
+ $vars = array( 'slug' => $this->_slug );
9362
+ if ( 'billing' === fs_request_get( 'tab' ) ) {
9363
+ fs_require_once_template( 'billing.php', $vars );
9364
+ } else {
9365
+ fs_require_once_template( 'account.php', $vars );
9366
+ }
9367
+ }
9368
+
9369
+ /**
9370
+ * Render account connect page.
9371
+ *
9372
+ * @author Vova Feldman (@svovaf)
9373
+ * @since 1.0.7
9374
+ */
9375
+ function _connect_page_render() {
9376
+ $this->_logger->entrance();
9377
+
9378
+ $vars = array( 'slug' => $this->_slug );
9379
+ fs_require_once_template( 'connect.php', $vars );
9380
+ }
9381
+
9382
+ /**
9383
+ * Load required resources before add-ons page render.
9384
+ *
9385
+ * @author Vova Feldman (@svovaf)
9386
+ * @since 1.0.6
9387
+ */
9388
+ function _addons_page_load() {
9389
+ $this->_logger->entrance();
9390
+
9391
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
9392
+
9393
+ wp_enqueue_script( 'plugin-install' );
9394
+ add_thickbox();
9395
+
9396
+ function fs_addons_body_class( $classes ) {
9397
+ $classes .= ' plugins-php';
9398
+
9399
+ return $classes;
9400
+ }
9401
+
9402
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
9403
+
9404
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
9405
+ $this->_admin_notices->add(
9406
+ sprintf( __fs( 'addons-info-external-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
9407
+ __fs( 'heads-up', $this->_slug ),
9408
+ 'update-nag'
9409
+ );
9410
+ }
9411
+ }
9412
+
9413
+ /**
9414
+ * Render add-ons page.
9415
+ *
9416
+ * @author Vova Feldman (@svovaf)
9417
+ * @since 1.0.6
9418
+ */
9419
+ function _addons_page_render() {
9420
+ $this->_logger->entrance();
9421
+
9422
+ $vars = array( 'slug' => $this->_slug );
9423
+ fs_require_once_template( 'add-ons.php', $vars );
9424
+ }
9425
+
9426
+ /* Pricing & Upgrade
9427
+ ------------------------------------------------------------------------------------------------------------------*/
9428
+ /**
9429
+ * Render pricing page.
9430
+ *
9431
+ * @author Vova Feldman (@svovaf)
9432
+ * @since 1.0.0
9433
+ */
9434
+ function _pricing_page_render() {
9435
+ $this->_logger->entrance();
9436
+
9437
+ $vars = array( 'slug' => $this->_slug );
9438
+
9439
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
9440
+ fs_require_once_template( 'checkout.php', $vars );
9441
+ } else {
9442
+ fs_require_once_template( 'pricing.php', $vars );
9443
+ }
9444
+ }
9445
+
9446
+ #region Contact Us ------------------------------------------------------------------
9447
+
9448
+ /**
9449
+ * Render contact-us page.
9450
+ *
9451
+ * @author Vova Feldman (@svovaf)
9452
+ * @since 1.0.3
9453
+ */
9454
+ function _contact_page_render() {
9455
+ $this->_logger->entrance();
9456
+
9457
+ $vars = array( 'slug' => $this->_slug );
9458
+ fs_require_once_template( 'contact.php', $vars );
9459
+ }
9460
+
9461
+ #endregion ------------------------------------------------------------------
9462
+
9463
+ /**
9464
+ * Hide all admin notices to prevent distractions.
9465
+ *
9466
+ * @author Vova Feldman (@svovaf)
9467
+ * @since 1.0.3
9468
+ *
9469
+ * @uses remove_all_actions()
9470
+ */
9471
+ private static function _hide_admin_notices() {
9472
+ remove_all_actions( 'admin_notices' );
9473
+ remove_all_actions( 'network_admin_notices' );
9474
+ remove_all_actions( 'all_admin_notices' );
9475
+ remove_all_actions( 'user_admin_notices' );
9476
+ }
9477
+
9478
+ static function _clean_admin_content_section_hook() {
9479
+ self::_hide_admin_notices();
9480
+
9481
+ // Hide footer.
9482
+ echo '<style>#wpfooter { display: none !important; }</style>';
9483
+ }
9484
+
9485
+ /**
9486
+ * Attach to admin_head hook to hide all admin notices.
9487
+ *
9488
+ * @author Vova Feldman (@svovaf)
9489
+ * @since 1.0.3
9490
+ */
9491
+ static function _clean_admin_content_section() {
9492
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
9493
+ }
9494
+
9495
+ /* CSS & JavaScript
9496
+ ------------------------------------------------------------------------------------------------------------------*/
9497
+ /* function _enqueue_script($handle, $src) {
9498
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
9499
+
9500
+ $this->_logger->entrance( 'script = ' . $url );
9501
+
9502
+ wp_enqueue_script( $handle, $url );
9503
+ }*/
9504
+
9505
+ /* SDK
9506
+ ------------------------------------------------------------------------------------------------------------------*/
9507
+ private $_user_api;
9508
+
9509
+ /**
9510
+ *
9511
+ * @author Vova Feldman (@svovaf)
9512
+ * @since 1.0.2
9513
+ *
9514
+ * @param bool $flush
9515
+ *
9516
+ * @return FS_Api
9517
+ */
9518
+ function get_api_user_scope( $flush = false ) {
9519
+ if ( ! isset( $this->_user_api ) || $flush ) {
9520
+ $this->_user_api = FS_Api::instance(
9521
+ $this->_slug,
9522
+ 'user',
9523
+ $this->_user->id,
9524
+ $this->_user->public_key,
9525
+ ! $this->is_live(),
9526
+ $this->_user->secret_key
9527
+ );
9528
+ }
9529
+
9530
+ return $this->_user_api;
9531
+ }
9532
+
9533
+ private $_site_api;
9534
+
9535
+ /**
9536
+ *
9537
+ * @author Vova Feldman (@svovaf)
9538
+ * @since 1.0.2
9539
+ *
9540
+ * @param bool $flush
9541
+ *
9542
+ * @return FS_Api
9543
+ */
9544
+ function get_api_site_scope( $flush = false ) {
9545
+ if ( ! isset( $this->_site_api ) || $flush ) {
9546
+ $this->_site_api = FS_Api::instance(
9547
+ $this->_slug,
9548
+ 'install',
9549
+ $this->_site->id,
9550
+ $this->_site->public_key,
9551
+ ! $this->is_live(),
9552
+ $this->_site->secret_key
9553
+ );
9554
+ }
9555
+
9556
+ return $this->_site_api;
9557
+ }
9558
+
9559
+ private $_plugin_api;
9560
+
9561
+ /**
9562
+ * Get plugin public API scope.
9563
+ *
9564
+ * @author Vova Feldman (@svovaf)
9565
+ * @since 1.0.7
9566
+ *
9567
+ * @return FS_Api
9568
+ */
9569
+ function get_api_plugin_scope() {
9570
+ if ( ! isset( $this->_plugin_api ) ) {
9571
+ $this->_plugin_api = FS_Api::instance(
9572
+ $this->_slug,
9573
+ 'plugin',
9574
+ $this->_plugin->id,
9575
+ $this->_plugin->public_key,
9576
+ ! $this->is_live()
9577
+ );
9578
+ }
9579
+
9580
+ return $this->_plugin_api;
9581
+ }
9582
+
9583
+ /**
9584
+ * Get site API scope object (fallback to public plugin scope when not registered).
9585
+ *
9586
+ * @author Vova Feldman (@svovaf)
9587
+ * @since 1.0.7
9588
+ *
9589
+ * @return FS_Api
9590
+ */
9591
+ function get_api_site_or_plugin_scope() {
9592
+ return $this->is_registered() ?
9593
+ $this->get_api_site_scope() :
9594
+ $this->get_api_plugin_scope();
9595
+ }
9596
+
9597
+ /**
9598
+ * Show trial promotional notice (if any trial exist).
9599
+ *
9600
+ * @author Vova Feldman (@svovaf)
9601
+ * @since 1.0.9
9602
+ *
9603
+ * @param $plans
9604
+ */
9605
+ function _check_for_trial_plans( $plans ) {
9606
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
9607
+ }
9608
+
9609
+ /**
9610
+ * Show trial promotional notice (if any trial exist).
9611
+ *
9612
+ * @author Vova Feldman (@svovaf)
9613
+ * @since 1.0.9
9614
+ */
9615
+ function _add_trial_notice() {
9616
+ // Check if trial already utilized.
9617
+ if ( $this->_site->is_trial_utilized() ) {
9618
+ return;
9619
+ }
9620
+
9621
+ // Check if already paying.
9622
+ if ( $this->is_paying() ) {
9623
+ return;
9624
+ }
9625
+
9626
+ // Check if trial message is already shown.
9627
+ if ( $this->_admin_notices->has_sticky( 'trial_promotion' ) ) {
9628
+ return;
9629
+ }
9630
+
9631
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
9632
+ $trial_plans_count = count( $trial_plans );
9633
+
9634
+ // Check if any of the plans contains trial.
9635
+ if ( 0 === $trial_plans_count ) {
9636
+ return;
9637
+ }
9638
+
9639
+ /**
9640
+ * @var FS_Plugin_Plan $paid_plan
9641
+ */
9642
+ $paid_plan = $trial_plans[0];
9643
+ $require_subscription = $paid_plan->is_require_subscription;
9644
+ $upgrade_url = $this->get_trial_url();
9645
+ $cc_string = $require_subscription ?
9646
+ sprintf( __fs( 'no-commitment-for-x-days', $this->_slug ), $paid_plan->trial_period ) :
9647
+ __fs( 'no-cc-required', $this->_slug ) . '!';
9648
+
9649
+
9650
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
9651
+
9652
+ if ( $total_paid_plans === $trial_plans_count ) {
9653
+ // All paid plans have trials.
9654
+ $message = sprintf(
9655
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
9656
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
9657
+ strtolower( __fs( 'awesome', $this->_slug ) ),
9658
+ $paid_plan->trial_period
9659
+ );
9660
+ } else {
9661
+ $plans_string = '';
9662
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
9663
+ $plans_string .= sprintf( '<a href="%s">%s</a>', $upgrade_url, $trial_plans[ $i ]->title );
9664
+
9665
+ if ( $i < $trial_plans_count - 2 ) {
9666
+ $plans_string .= ', ';
9667
+ } else if ( $i == $trial_plans_count - 2 ) {
9668
+ $plans_string .= ' and ';
9669
+ }
9670
+ }
9671
+
9672
+ // Not all paid plans have trials.
9673
+ $message = sprintf(
9674
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
9675
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
9676
+ $plans_string,
9677
+ $paid_plan->trial_period
9678
+ );
9679
+ }
9680
+
9681
+ $message .= ' ' . $cc_string;
9682
+
9683
+ // Add start trial button.
9684
+ $message .= ' ' . sprintf(
9685
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
9686
+ $upgrade_url,
9687
+ __fs( 'start-free-trial', $this->_slug )
9688
+ );
9689
+
9690
+ $this->_admin_notices->add_sticky(
9691
+ $this->apply_filters( 'trial_promotion_message', $message ),
9692
+ 'trial_promotion',
9693
+ '',
9694
+ 'promotion'
9695
+ );
9696
+
9697
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
9698
+ }
9699
+
9700
+ /* Action Links
9701
+ ------------------------------------------------------------------------------------------------------------------*/
9702
+ private $_action_links_hooked = false;
9703
+ private $_action_links = array();
9704
+
9705
+ /**
9706
+ * @author Vova Feldman (@svovaf)
9707
+ * @since 1.0.0
9708
+ *
9709
+ * @return bool
9710
+ */
9711
+ private function is_plugin_action_links_hooked() {
9712
+ $this->_logger->entrance( json_encode( $this->_action_links_hooked ) );
9713
+
9714
+ return $this->_action_links_hooked;
9715
+ }
9716
+
9717
+ /**
9718
+ * Hook to plugin action links filter.
9719
+ *
9720
+ * @author Vova Feldman (@svovaf)
9721
+ * @since 1.0.0
9722
+ */
9723
+ private function hook_plugin_action_links() {
9724
+ $this->_logger->entrance();
9725
+
9726
+ $this->_action_links_hooked = true;
9727
+
9728
+ $this->_logger->log( 'Adding action links hooks.' );
9729
+
9730
+ // Add action link to settings page.
9731
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
9732
+ &$this,
9733
+ '_modify_plugin_action_links_hook'
9734
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
9735
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
9736
+ &$this,
9737
+ '_modify_plugin_action_links_hook'
9738
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
9739
+ }
9740
+
9741
+ /**
9742
+ * Add plugin action link.
9743
+ *
9744
+ * @author Vova Feldman (@svovaf)
9745
+ * @since 1.0.0
9746
+ *
9747
+ * @param $label
9748
+ * @param $url
9749
+ * @param bool $external
9750
+ * @param int $priority
9751
+ * @param bool $key
9752
+ */
9753
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
9754
+ $this->_logger->entrance();
9755
+
9756
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
9757
+ $this->_action_links[ $priority ] = array();
9758
+ }
9759
+
9760
+ if ( false === $key ) {
9761
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
9762
+ }
9763
+
9764
+ $this->_action_links[ $priority ][] = array(
9765
+ 'label' => $label,
9766
+ 'href' => $url,
9767
+ 'key' => $key,
9768
+ 'external' => $external
9769
+ );
9770
+ }
9771
+
9772
+ /**
9773
+ * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
9774
+ *
9775
+ * @author Vova Feldman (@svovaf)
9776
+ * @since 1.0.0
9777
+ */
9778
+ function _add_upgrade_action_link() {
9779
+ $this->_logger->entrance();
9780
+
9781
+ if ( $this->is_registered() ) {
9782
+ if ( ! $this->is_paying() && $this->has_paid_plan() ) {
9783
+ $this->add_plugin_action_link(
9784
+ __fs( 'upgrade', $this->_slug ),
9785
+ $this->get_upgrade_url(),
9786
+ false,
9787
+ 7,
9788
+ 'upgrade'
9789
+ );
9790
+ }
9791
+
9792
+ if ( $this->has_addons() ) {
9793
+ $this->add_plugin_action_link(
9794
+ __fs( 'add-ons', $this->_slug ),
9795
+ $this->_get_admin_page_url( 'addons' ),
9796
+ false,
9797
+ 9,
9798
+ 'addons'
9799
+ );
9800
+ }
9801
+ }
9802
+ }
9803
+
9804
+ /**
9805
+ * Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
9806
+ *
9807
+ * @author Leo Fajardo (@leorw)
9808
+ * @since 1.1.9
9809
+ */
9810
+ function _add_license_action_link() {
9811
+ $this->_logger->entrance();
9812
+
9813
+ if ( $this->is_free_plan() && $this->is_addon() ) {
9814
+ return;
9815
+ }
9816
+
9817
+ $link_text = __fs(
9818
+ $this->is_free_plan() ? 'activate-license' : 'change-license',
9819
+ $this->_slug
9820
+ );
9821
+
9822
+ $this->add_plugin_action_link(
9823
+ $link_text,
9824
+ '#',
9825
+ false,
9826
+ 11,
9827
+ ( 'activate-license ' . $this->_slug )
9828
+ );
9829
+ }
9830
+
9831
+ /**
9832
+ * Get the URL of the page that should be loaded right after the plugin activation.
9833
+ *
9834
+ * @author Vova Feldman (@svovaf)
9835
+ * @since 1.1.7.4
9836
+ *
9837
+ * @return string
9838
+ */
9839
+ function get_after_plugin_activation_redirect_url() {
9840
+ $url = false;
9841
+ $plugin_fs = false;
9842
+
9843
+ if ( ! $this->is_addon() ) {
9844
+ $first_time_path = $this->_menu->get_first_time_path();
9845
+ $plugin_fs = $this;
9846
+ $url = $plugin_fs->is_activation_mode() ?
9847
+ $plugin_fs->get_activation_url() :
9848
+ ( empty( $first_time_path ) ?
9849
+ $this->_get_admin_page_url() :
9850
+ $first_time_path );
9851
+ } else {
9852
+ if ( $this->is_parent_plugin_installed() ) {
9853
+ $plugin_fs = self::get_parent_instance();
9854
+ }
9855
+
9856
+ if ( is_object( $plugin_fs ) ) {
9857
+ if ( ! $plugin_fs->is_registered() ) {
9858
+ // Forward to parent plugin connect when parent not registered.
9859
+ $url = $plugin_fs->get_activation_url();
9860
+ } else {
9861
+ // Forward to account page.
9862
+ $url = $plugin_fs->_get_admin_page_url( 'account' );
9863
+ }
9864
+ }
9865
+ }
9866
+
9867
+ return $url;
9868
+ }
9869
+
9870
+ /**
9871
+ * Forward page to activation page.
9872
+ *
9873
+ * @author Vova Feldman (@svovaf)
9874
+ * @since 1.0.3
9875
+ */
9876
+ function _redirect_on_activation_hook() {
9877
+ $url = $this->get_after_plugin_activation_redirect_url();
9878
+
9879
+ if ( is_string( $url ) ) {
9880
+ fs_redirect( $url );
9881
+ exit();
9882
+ }
9883
+ }
9884
+
9885
+ /**
9886
+ * Modify plugin's page action links collection.
9887
+ *
9888
+ * @author Vova Feldman (@svovaf)
9889
+ * @since 1.0.0
9890
+ *
9891
+ * @param array $links
9892
+ * @param $file
9893
+ *
9894
+ * @return array
9895
+ */
9896
+ function _modify_plugin_action_links_hook( $links, $file ) {
9897
+ $this->_logger->entrance();
9898
+
9899
+ $passed_deactivate = false;
9900
+ $deactivate_link = '';
9901
+ $before_deactivate = array();
9902
+ $after_deactivate = array();
9903
+ foreach ( $links as $key => $link ) {
9904
+ if ( 'deactivate' === $key ) {
9905
+ $deactivate_link = $link;
9906
+ $passed_deactivate = true;
9907
+ continue;
9908
+ }
9909
+
9910
+ if ( ! $passed_deactivate ) {
9911
+ $before_deactivate[ $key ] = $link;
9912
+ } else {
9913
+ $after_deactivate[ $key ] = $link;
9914
+ }
9915
+ }
9916
+
9917
+ ksort( $this->_action_links );
9918
+
9919
+ foreach ( $this->_action_links as $new_links ) {
9920
+ foreach ( $new_links as $link ) {
9921
+ $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
9922
+ }
9923
+ }
9924
+
9925
+ if ( ! empty( $deactivate_link ) ) {
9926
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
9927
+ /*
9928
+ * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
9929
+ *
9930
+ * If user is paying or in trial and have the free version installed,
9931
+ * assume that the deactivation is for the upgrade process, so this is not needed.
9932
+ */
9933
+ $deactivate_link .= '<i class="fs-slug" data-slug="' . $this->_slug . '"></i>';
9934
+ }
9935
+
9936
+ // Append deactivation link.
9937
+ $before_deactivate['deactivate'] = $deactivate_link;
9938
+ }
9939
+
9940
+ return array_merge( $before_deactivate, $after_deactivate );
9941
+ }
9942
+
9943
+ /**
9944
+ * Adds admin message.
9945
+ *
9946
+ * @author Vova Feldman (@svovaf)
9947
+ * @since 1.0.4
9948
+ *
9949
+ * @param string $message
9950
+ * @param string $title
9951
+ * @param string $type
9952
+ */
9953
+ function add_admin_message( $message, $title = '', $type = 'success' ) {
9954
+ $this->_admin_notices->add( $message, $title, $type );
9955
+ }
9956
+
9957
+ /**
9958
+ * Adds sticky admin message.
9959
+ *
9960
+ * @author Vova Feldman (@svovaf)
9961
+ * @since 1.1.0
9962
+ *
9963
+ * @param string $message
9964
+ * @param string $id
9965
+ * @param string $title
9966
+ * @param string $type
9967
+ */
9968
+ function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
9969
+ $this->_admin_notices->add_sticky( $message, $id, $title, $type );
9970
+ }
9971
+
9972
+ /* Plugin Auto-Updates (@since 1.0.4)
9973
+ ------------------------------------------------------------------------------------------------------------------*/
9974
+ /**
9975
+ * @var string[]
9976
+ */
9977
+ private static $_auto_updated_plugins;
9978
+
9979
+ /**
9980
+ * @todo TEST IF IT WORKS!!!
9981
+ *
9982
+ * Include plugins for automatic updates based on stored settings.
9983
+ *
9984
+ * @see http://wordpress.stackexchange.com/questions/131394/how-do-i-exclude-plugins-from-getting-automatically-updated/131404#131404
9985
+ *
9986
+ * @author Vova Feldman (@svovaf)
9987
+ * @since 1.0.4
9988
+ *
9989
+ * @param bool $update Whether to update (not used for plugins)
9990
+ * @param object $item The plugin's info
9991
+ *
9992
+ * @return bool
9993
+ */
9994
+ static function _include_plugins_in_auto_update( $update, $item ) {
9995
+ // Before version 3.8.2 the $item was the file name of the plugin,
9996
+ // while in 3.8.2 statistics were added (https://core.trac.wordpress.org/changeset/27905).
9997
+ $by_slug = ( (int) str_replace( '.', '', get_bloginfo( 'version' ) ) >= 382 );
9998
+
9999
+ if ( ! isset( self::$_auto_updated_plugins ) ) {
10000
+ $plugins = self::$_accounts->get_option( 'plugins', array() );
10001
+
10002
+ $identifiers = array();
10003
+ foreach ( $plugins as $p ) {
10004
+ /**
10005
+ * @var FS_Plugin $p
10006
+ */
10007
+ if ( isset( $p->auto_update ) && $p->auto_update ) {
10008
+ $identifiers[] = ( $by_slug ? $p->slug : plugin_basename( $p->file ) );
10009
+ }
10010
+ }
10011
+
10012
+ self::$_auto_updated_plugins = $identifiers;
10013
+ }
10014
+
10015
+ if ( in_array( $by_slug ? $item->slug : $item, self::$_auto_updated_plugins ) ) {
10016
+ return true;
10017
+ }
10018
+
10019
+ // Pass update decision to next filters
10020
+ return $update;
10021
+ }
10022
+
10023
+ #region Versioning ------------------------------------------------------------------
10024
+
10025
+ /**
10026
+ * Check if Freemius in SDK upgrade mode.
10027
+ *
10028
+ * @author Vova Feldman (@svovaf)
10029
+ * @since 1.0.9
10030
+ *
10031
+ * @return bool
10032
+ */
10033
+ function is_sdk_upgrade_mode() {
10034
+ return isset( $this->_storage->sdk_upgrade_mode ) ?
10035
+ $this->_storage->sdk_upgrade_mode :
10036
+ false;
10037
+ }
10038
+
10039
+ /**
10040
+ * Turn SDK upgrade mode off.
10041
+ *
10042
+ * @author Vova Feldman (@svovaf)
10043
+ * @since 1.0.9
10044
+ *
10045
+ * @return bool
10046
+ */
10047
+ function set_sdk_upgrade_complete() {
10048
+ $this->_storage->sdk_upgrade_mode = false;
10049
+ }
10050
+
10051
+ /**
10052
+ * Check if plugin upgrade mode.
10053
+ *
10054
+ * @author Vova Feldman (@svovaf)
10055
+ * @since 1.0.9
10056
+ *
10057
+ * @return bool
10058
+ */
10059
+ function is_plugin_upgrade_mode() {
10060
+ return isset( $this->_storage->plugin_upgrade_mode ) ?
10061
+ $this->_storage->plugin_upgrade_mode :
10062
+ false;
10063
+ }
10064
+
10065
+ /**
10066
+ * Turn plugin upgrade mode off.
10067
+ *
10068
+ * @author Vova Feldman (@svovaf)
10069
+ * @since 1.0.9
10070
+ *
10071
+ * @return bool
10072
+ */
10073
+ function set_plugin_upgrade_complete() {
10074
+ $this->_storage->plugin_upgrade_mode = false;
10075
+ }
10076
+
10077
+ #endregion ------------------------------------------------------------------
10078
+
10079
+ #region Permissions ------------------------------------------------------------------
10080
+
10081
+ /**
10082
+ * Check if specific permission requested.
10083
+ *
10084
+ * @author Vova Feldman (@svovaf)
10085
+ * @since 1.1.6
10086
+ *
10087
+ * @param string $permission
10088
+ *
10089
+ * @return bool
10090
+ */
10091
+ function is_permission_requested( $permission ) {
10092
+ return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
10093
+ }
10094
+
10095
+ #endregion Permissions ------------------------------------------------------------------
10096
+
10097
+ #region Marketing ------------------------------------------------------------------
10098
+
10099
+ /**
10100
+ * Check if current user purchased any other plugins before.
10101
+ *
10102
+ * @author Vova Feldman (@svovaf)
10103
+ * @since 1.0.9
10104
+ *
10105
+ * @return bool
10106
+ */
10107
+ function has_purchased_before() {
10108
+ // TODO: Implement has_purchased_before() method.
10109
+ }
10110
+
10111
+ /**
10112
+ * Check if current user classified as an agency.
10113
+ *
10114
+ * @author Vova Feldman (@svovaf)
10115
+ * @since 1.0.9
10116
+ *
10117
+ * @return bool
10118
+ */
10119
+ function is_agency() {
10120
+ // TODO: Implement is_agency() method.
10121
+ }
10122
+
10123
+ /**
10124
+ * Check if current user classified as a developer.
10125
+ *
10126
+ * @author Vova Feldman (@svovaf)
10127
+ * @since 1.0.9
10128
+ *
10129
+ * @return bool
10130
+ */
10131
+ function is_developer() {
10132
+ // TODO: Implement is_developer() method.
10133
+ }
10134
+
10135
+ /**
10136
+ * Check if current user classified as a business.
10137
+ *
10138
+ * @author Vova Feldman (@svovaf)
10139
+ * @since 1.0.9
10140
+ *
10141
+ * @return bool
10142
+ */
10143
+ function is_business() {
10144
+ // TODO: Implement is_business() method.
10145
+ }
10146
+
10147
+ #endregion ------------------------------------------------------------------
10148
+ }
freemius/includes/class-fs-api.php ADDED
@@ -0,0 +1,455 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Api
15
+ *
16
+ * Wraps Freemius API SDK to handle:
17
+ * 1. Clock sync.
18
+ * 2. Fallback to HTTP when HTTPS fails.
19
+ * 3. Adds caching layer to GET requests.
20
+ * 4. Adds consistency for failed requests by using last cached version.
21
+ */
22
+ class FS_Api {
23
+ /**
24
+ * @var FS_Api[]
25
+ */
26
+ private static $_instances = array();
27
+
28
+ /**
29
+ * @var FS_Option_Manager Freemius options, options-manager.
30
+ */
31
+ private static $_options;
32
+
33
+ /**
34
+ * @var FS_Cache_Manager API Caching layer
35
+ */
36
+ private static $_cache;
37
+
38
+ /**
39
+ * @var int Clock diff in seconds between current server to API server.
40
+ */
41
+ private static $_clock_diff;
42
+
43
+ /**
44
+ * @var Freemius_Api
45
+ */
46
+ private $_api;
47
+
48
+ /**
49
+ * @var string
50
+ */
51
+ private $_slug;
52
+
53
+ /**
54
+ * @var FS_Logger
55
+ * @since 1.0.4
56
+ */
57
+ private $_logger;
58
+
59
+ /**
60
+ * @param string $slug
61
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
62
+ * @param number $id Element's id.
63
+ * @param string $public_key Public key.
64
+ * @param bool $is_sandbox
65
+ * @param bool|string $secret_key Element's secret key.
66
+ *
67
+ * @return FS_Api
68
+ */
69
+ static function instance( $slug, $scope, $id, $public_key, $is_sandbox, $secret_key = false ) {
70
+ $identifier = md5( $slug . $scope . $id . $public_key . ( is_string( $secret_key ) ? $secret_key : '' ) . json_encode( $is_sandbox ) );
71
+
72
+ if ( ! isset( self::$_instances[ $identifier ] ) ) {
73
+ self::_init();
74
+
75
+ self::$_instances[ $identifier ] = new FS_Api( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox );
76
+ }
77
+
78
+ return self::$_instances[ $identifier ];
79
+ }
80
+
81
+ private static function _init() {
82
+ if ( isset( self::$_options ) ) {
83
+ return;
84
+ }
85
+
86
+ if ( ! class_exists( 'Freemius_Api' ) ) {
87
+ require_once( WP_FS__DIR_SDK . '/Freemius.php' );
88
+ }
89
+
90
+ self::$_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true );
91
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
92
+
93
+ self::$_clock_diff = self::$_options->get_option( 'api_clock_diff', 0 );
94
+ Freemius_Api::SetClockDiff( self::$_clock_diff );
95
+
96
+ if ( self::$_options->get_option( 'api_force_http', false ) ) {
97
+ Freemius_Api::SetHttp();
98
+ }
99
+ }
100
+
101
+ /**
102
+ * @param string $slug
103
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
104
+ * @param number $id Element's id.
105
+ * @param string $public_key Public key.
106
+ * @param bool|string $secret_key Element's secret key.
107
+ * @param bool $is_sandbox
108
+ */
109
+ private function __construct( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox ) {
110
+ $this->_api = new Freemius_Api( $scope, $id, $public_key, $secret_key, $is_sandbox );
111
+
112
+ $this->_slug = $slug;
113
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_api', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
114
+ }
115
+
116
+ /**
117
+ * Find clock diff between server and API server, and store the diff locally.
118
+ *
119
+ * @param bool|int $diff
120
+ *
121
+ * @return bool|int False if clock diff didn't change, otherwise returns the clock diff in seconds.
122
+ */
123
+ private function _sync_clock_diff( $diff = false ) {
124
+ $this->_logger->entrance();
125
+
126
+ // Sync clock and store.
127
+ $new_clock_diff = ( false === $diff ) ?
128
+ Freemius_Api::FindClockDiff() :
129
+ $diff;
130
+
131
+ if ( $new_clock_diff === self::$_clock_diff ) {
132
+ return false;
133
+ }
134
+
135
+ self::$_clock_diff = $new_clock_diff;
136
+
137
+ // Update API clock's diff.
138
+ Freemius_Api::SetClockDiff( self::$_clock_diff );
139
+
140
+ // Store new clock diff in storage.
141
+ self::$_options->set_option( 'api_clock_diff', self::$_clock_diff, true );
142
+
143
+ return $new_clock_diff;
144
+ }
145
+
146
+ /**
147
+ * Override API call to enable retry with servers' clock auto sync method.
148
+ *
149
+ * @param string $path
150
+ * @param string $method
151
+ * @param array $params
152
+ * @param bool $retry Is in retry or first call attempt.
153
+ *
154
+ * @return array|mixed|string|void
155
+ */
156
+ private function _call( $path, $method = 'GET', $params = array(), $retry = false ) {
157
+ $this->_logger->entrance( $method . ':' . $path );
158
+
159
+ if ( self::is_temporary_down() ) {
160
+ $result = $this->get_temporary_unavailable_error();
161
+ } else {
162
+ $result = $this->_api->Api( $path, $method, $params );
163
+
164
+ if ( null !== $result &&
165
+ isset( $result->error ) &&
166
+ isset( $result->error->code ) &&
167
+ 'request_expired' === $result->error->code
168
+ ) {
169
+ if ( ! $retry ) {
170
+ $diff = isset( $result->error->timestamp ) ?
171
+ ( time() - strtotime( $result->error->timestamp ) ) :
172
+ false;
173
+
174
+ // Try to sync clock diff.
175
+ if ( false !== $this->_sync_clock_diff( $diff ) ) {
176
+ // Retry call with new synced clock.
177
+ return $this->_call( $path, $method, $params, true );
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ if ( null !== $result && isset( $result->error ) && isset( $result->error->message ) ) {
184
+ // Log API errors.
185
+ $this->_logger->error( $result->error->message );
186
+ }
187
+
188
+ return $result;
189
+ }
190
+
191
+ /**
192
+ * Override API call to wrap it in servers' clock sync method.
193
+ *
194
+ * @param string $path
195
+ * @param string $method
196
+ * @param array $params
197
+ *
198
+ * @return array|mixed|string|void
199
+ * @throws Freemius_Exception
200
+ */
201
+ function call( $path, $method = 'GET', $params = array() ) {
202
+ return $this->_call( $path, $method, $params );
203
+ }
204
+
205
+ /**
206
+ * Get API request URL signed via query string.
207
+ *
208
+ * @param string $path
209
+ *
210
+ * @return string
211
+ */
212
+ function get_signed_url( $path ) {
213
+ return $this->_api->GetSignedUrl( $path );
214
+ }
215
+
216
+ /**
217
+ * @param string $path
218
+ * @param bool $flush
219
+ * @param int $expiration (optional) Time until expiration in seconds from now, defaults to 24 hours
220
+ *
221
+ * @return stdClass|mixed
222
+ */
223
+ function get( $path = '/', $flush = false, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
224
+ $this->_logger->entrance( $path );
225
+
226
+ $cache_key = $this->get_cache_key( $path );
227
+
228
+ // Always flush during development.
229
+ if ( WP_FS__DEV_MODE || $this->_api->IsSandbox() ) {
230
+ $flush = true;
231
+ }
232
+
233
+ $cached_result = self::$_cache->get( $cache_key );
234
+
235
+ if ( $flush || ! self::$_cache->has_valid( $cache_key ) ) {
236
+ $result = $this->call( $path );
237
+
238
+ if ( ! is_object( $result ) || isset( $result->error ) ) {
239
+ // Api returned an error.
240
+ if ( is_object( $cached_result ) &&
241
+ ! isset( $cached_result )
242
+ ) {
243
+ // If there was an error during a newer data fetch,
244
+ // fallback to older data version.
245
+ $result = $cached_result;
246
+ } else {
247
+ // If no older data version, return result without
248
+ // caching the error.
249
+ return $result;
250
+ }
251
+ }
252
+
253
+ self::$_cache->set( $cache_key, $result, $expiration );
254
+
255
+ $cached_result = $result;
256
+ }
257
+
258
+ return $cached_result;
259
+ }
260
+
261
+ private function get_cache_key( $path, $method = 'GET', $params = array() ) {
262
+ $canonized = $this->_api->CanonizePath( $path );
263
+ // $exploded = explode('/', $canonized);
264
+ // return $method . '_' . array_pop($exploded) . '_' . md5($canonized . json_encode($params));
265
+ return $method . ':' . $canonized . ( ! empty( $params ) ? '#' . md5( json_encode( $params ) ) : '' );
266
+ }
267
+
268
+ /**
269
+ * Test API connectivity.
270
+ *
271
+ * @author Vova Feldman (@svovaf)
272
+ * @since 1.0.9 If fails, try to fallback to HTTP.
273
+ * @since 1.1.6 Added a 5-min caching mechanism, to prevent from overloading the server if the API if
274
+ * temporary down.
275
+ *
276
+ * @return bool True if successful connectivity to the API.
277
+ */
278
+ static function test() {
279
+ self::_init();
280
+
281
+ $cache_key = 'ping_test';
282
+
283
+ $test = self::$_cache->get_valid( $cache_key, null );
284
+
285
+ if ( is_null( $test ) ) {
286
+ $test = Freemius_Api::Test();
287
+
288
+ if ( false === $test && Freemius_Api::IsHttps() ) {
289
+ // Fallback to HTTP, since HTTPS fails.
290
+ Freemius_Api::SetHttp();
291
+
292
+ self::$_options->set_option( 'api_force_http', true, true );
293
+
294
+ $test = Freemius_Api::Test();
295
+
296
+ if ( false === $test ) {
297
+ /**
298
+ * API connectivity test fail also in HTTP request, therefore,
299
+ * fallback to HTTPS to keep connection secure.
300
+ *
301
+ * @since 1.1.6
302
+ */
303
+ self::$_options->set_option( 'api_force_http', false, true );
304
+ }
305
+ }
306
+
307
+ self::$_cache->set( $cache_key, $test, WP_FS__TIME_5_MIN_IN_SEC );
308
+ }
309
+
310
+ return $test;
311
+ }
312
+
313
+ /**
314
+ * Check if API is temporary down.
315
+ *
316
+ * @author Vova Feldman (@svovaf)
317
+ * @since 1.1.6
318
+ *
319
+ * @return bool
320
+ */
321
+ static function is_temporary_down() {
322
+ self::_init();
323
+
324
+ $test = self::$_cache->get_valid( 'ping_test', null );
325
+
326
+ return ( false === $test );
327
+ }
328
+
329
+ /**
330
+ * @author Vova Feldman (@svovaf)
331
+ * @since 1.1.6
332
+ *
333
+ * @return object
334
+ */
335
+ private function get_temporary_unavailable_error() {
336
+ return (object) array(
337
+ 'error' => array(
338
+ 'type' => 'TemporaryUnavailable',
339
+ 'message' => 'API is temporary unavailable, please retry in ' . ( self::$_cache->get_record_expiration( 'ping_test' ) - WP_FS__SCRIPT_START_TIME ) . ' sec.',
340
+ 'code' => 'temporary_unavailable',
341
+ 'http' => 503
342
+ )
343
+ );
344
+ }
345
+
346
+ /**
347
+ * Ping API for connectivity test, and return result object.
348
+ *
349
+ * @author Vova Feldman (@svovaf)
350
+ * @since 1.0.9
351
+ *
352
+ * @param null|string $unique_anonymous_id
353
+ * @param array $params
354
+ *
355
+ * @return object
356
+ */
357
+ function ping( $unique_anonymous_id = null, $params = array() ) {
358
+ $this->_logger->entrance();
359
+
360
+ if ( self::is_temporary_down() ) {
361
+ return $this->get_temporary_unavailable_error();
362
+ }
363
+
364
+ $pong = is_null( $unique_anonymous_id ) ?
365
+ Freemius_Api::Ping() :
366
+ $this->_call( 'ping.json?' . http_build_query( array_merge(
367
+ array( 'uid' => $unique_anonymous_id ),
368
+ $params
369
+ ) ) );
370
+
371
+ if ( $this->is_valid_ping( $pong ) ) {
372
+ return $pong;
373
+ }
374
+
375
+ if ( self::should_try_with_http( $pong ) ) {
376
+ // Fallback to HTTP, since HTTPS fails.
377
+ Freemius_Api::SetHttp();
378
+
379
+ self::$_options->set_option( 'api_force_http', true, true );
380
+
381
+ $pong = is_null( $unique_anonymous_id ) ?
382
+ Freemius_Api::Ping() :
383
+ $this->_call( 'ping.json?' . http_build_query( array_merge(
384
+ array( 'uid' => $unique_anonymous_id ),
385
+ $params
386
+ ) ) );
387
+
388
+ if ( ! $this->is_valid_ping( $pong ) ) {
389
+ self::$_options->set_option( 'api_force_http', false, true );
390
+ }
391
+ }
392
+
393
+ return $pong;
394
+ }
395
+
396
+ /**
397
+ * Check if based on the API result we should try
398
+ * to re-run the same request with HTTP instead of HTTPS.
399
+ *
400
+ * @author Vova Feldman (@svovaf)
401
+ * @since 1.1.6
402
+ *
403
+ * @param $result
404
+ *
405
+ * @return bool
406
+ */
407
+ private static function should_try_with_http( $result ) {
408
+ if ( ! Freemius_Api::IsHttps() ) {
409
+ return false;
410
+ }
411
+
412
+ return ( ! is_object( $result ) ||
413
+ ! isset( $result->error ) ||
414
+ ! isset( $result->error->code ) ||
415
+ ! in_array( $result->error->code, array(
416
+ 'curl_missing',
417
+ 'cloudflare_ddos_protection',
418
+ 'maintenance_mode',
419
+ 'squid_cache_block',
420
+ 'too_many_requests',
421
+ ) ) );
422
+
423
+ }
424
+
425
+ /**
426
+ * Check if valid ping request result.
427
+ *
428
+ * @author Vova Feldman (@svovaf)
429
+ * @since 1.1.1
430
+ *
431
+ * @param mixed $pong
432
+ *
433
+ * @return bool
434
+ */
435
+ function is_valid_ping( $pong ) {
436
+ return Freemius_Api::Test( $pong );
437
+ }
438
+
439
+ function get_url( $path = '' ) {
440
+ return Freemius_Api::GetUrl( $path, $this->_api->IsSandbox() );
441
+ }
442
+
443
+ /**
444
+ * Clear API cache.
445
+ *
446
+ * @author Vova Feldman (@svovaf)
447
+ * @since 1.0.9
448
+ */
449
+ static function clear_cache() {
450
+ self::_init();
451
+
452
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
453
+ self::$_cache->clear( true );
454
+ }
455
+ }
freemius/includes/class-fs-logger.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Logger {
14
+ private $_id;
15
+ private $_on = false;
16
+ private $_echo = false;
17
+ private $_file_start = 0;
18
+
19
+ private static $LOGGERS = array();
20
+ private static $LOG = array();
21
+ private static $CNT = 0;
22
+ private static $_HOOKED_FOOTER = false;
23
+
24
+ private function __construct( $id, $on = false, $echo = false ) {
25
+ $this->_id = $id;
26
+
27
+ $bt = debug_backtrace();
28
+ $caller = $bt[2];
29
+
30
+ $this->_file_start = strpos( $caller['file'], 'plugins' ) + strlen( 'plugins/' );
31
+
32
+ if ( $on ) {
33
+ $this->on();
34
+ }
35
+ if ( $echo ) {
36
+ $this->echo_on();
37
+ }
38
+ }
39
+
40
+ /**
41
+ * @param string $id
42
+ * @param bool $on
43
+ * @param bool $echo
44
+ *
45
+ * @return FS_Logger
46
+ */
47
+ public static function get_logger( $id, $on = false, $echo = false ) {
48
+ $id = strtolower( $id );
49
+
50
+ if ( ! isset( self::$LOGGERS[ $id ] ) ) {
51
+ self::$LOGGERS[ $id ] = new FS_Logger( $id, $on, $echo );
52
+ }
53
+
54
+ return self::$LOGGERS[ $id ];
55
+ }
56
+
57
+ private static function _hook_footer() {
58
+ if ( self::$_HOOKED_FOOTER ) {
59
+ return;
60
+ }
61
+
62
+ if ( is_admin() ) {
63
+ add_action( 'admin_footer', 'FS_Logger::dump', 100 );
64
+ } else {
65
+ add_action( 'wp_footer', 'FS_Logger::dump', 100 );
66
+ }
67
+ }
68
+
69
+ function is_on() {
70
+ return $this->_on;
71
+ }
72
+
73
+ function on() {
74
+ $this->_on = true;
75
+
76
+ self::_hook_footer();
77
+ }
78
+
79
+ function echo_on() {
80
+ $this->on();
81
+
82
+ $this->_echo = true;
83
+ }
84
+
85
+ function is_echo_on() {
86
+ return $this->_echo;
87
+ }
88
+
89
+ function get_id() {
90
+ return $this->_id;
91
+ }
92
+
93
+ function get_file() {
94
+ return $this->_file_start;
95
+ }
96
+
97
+ private function _log( &$message, $type = 'log', $wrapper ) {
98
+ if ( ! $this->is_on() ) {
99
+ return;
100
+ }
101
+
102
+ $bt = debug_backtrace();
103
+ $depth = $wrapper ? 3 : 2;
104
+ while ( $depth < count( $bt ) - 1 && 'eval' === $bt[ $depth ]['function'] ) {
105
+ $depth ++;
106
+ }
107
+
108
+ $caller = $bt[ $depth ];
109
+
110
+ $log = array_merge( $caller, array(
111
+ 'cnt' => self::$CNT ++,
112
+ 'logger' => $this,
113
+ 'timestamp' => microtime(true),
114
+ 'type' => $type,
115
+ 'msg' => $message,
116
+ ) );
117
+
118
+ self::$LOG[] = $log;
119
+
120
+ if ( $this->is_echo_on() ) {
121
+ echo self::format_html( $log ) . "\n";
122
+ }
123
+ }
124
+
125
+ function log( $message, $wrapper = false ) {
126
+ $this->_log( $message, 'log', $wrapper );
127
+ }
128
+
129
+ function info( $message, $wrapper = false ) {
130
+ $this->_log( $message, 'info', $wrapper );
131
+ }
132
+
133
+ function warn( $message, $wrapper = false ) {
134
+ $this->_log( $message, 'warn', $wrapper );
135
+ }
136
+
137
+ function error( $message, $wrapper = false ) {
138
+ $this->_log( $message, 'error', $wrapper );
139
+ }
140
+
141
+ function entrance( $message = '', $wrapper = false ) {
142
+ $msg = 'Entrance' . ( empty( $message ) ? '' : ' > ' ) . $message;
143
+
144
+ $this->_log( $msg, 'log', $wrapper );
145
+ }
146
+
147
+ function departure( $message = '', $wrapper = false ) {
148
+ $msg = 'Departure' . ( empty( $message ) ? '' : ' > ' ) . $message;
149
+
150
+ $this->_log( $msg, 'log', $wrapper );
151
+ }
152
+
153
+ private static function format( $log, $show_type = true ) {
154
+ return '[' . str_pad( $log['cnt'], strlen( self::$CNT ), '0', STR_PAD_LEFT ) . '] [' . $log['logger']->_id . '] ' . ( $show_type ? '[' . $log['type'] . ']' : '' ) . $log['function'] . ' >> ' . $log['msg'] . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ') ' : '' ) . ' [' . $log['timestamp'] . ']';
155
+ }
156
+
157
+ private static function format_html( $log ) {
158
+ return '<div style="font-size: 11px; padding: 3px; background: #ccc; margin-bottom: 3px;">[' . $log['cnt'] . '] [' . $log['logger']->_id . '] [' . $log['type'] . '] <b><code style="color: blue;">' . $log['function'] . '</code> >> <b style="color: darkorange;">' . $log['msg'] . '</b></b>' . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ')' : '' ) . ' [' . $log['timestamp'] . ']</div>';
159
+ }
160
+
161
+ static function dump() {
162
+ ?>
163
+ <!-- BEGIN: Freemius PHP Console Log -->
164
+ <script type="text/javascript">
165
+ <?php
166
+ foreach (self::$LOG as $log)
167
+ {
168
+ echo 'console.' . $log['type'] . '(' . json_encode(self::format($log, false)) . ')' . "\n";
169
+ }
170
+ ?>
171
+ </script>
172
+ <!-- END: Freemius PHP Console Log -->
173
+ <?php
174
+ }
175
+
176
+ static function get_log() {
177
+ return self::$LOG;
178
+ }
179
+ }
freemius/includes/class-fs-plugin-updater.php ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ *
8
+ * @link https://github.com/easydigitaldownloads/EDD-License-handler/blob/master/EDD_SL_Plugin_Updater.php
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ // Uncomment this line for testing.
16
+ // set_site_transient( 'update_plugins', null );
17
+
18
+ class FS_Plugin_Updater {
19
+
20
+ /**
21
+ * @var Freemius
22
+ * @since 1.0.4
23
+ */
24
+ private $_fs;
25
+ /**
26
+ * @var FS_Logger
27
+ * @since 1.0.4
28
+ */
29
+ private $_logger;
30
+ /**
31
+ * @var object
32
+ * @since 1.1.8.1
33
+ */
34
+ private $_update_details;
35
+
36
+ function __construct( Freemius $freemius ) {
37
+ $this->_fs = $freemius;
38
+
39
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $freemius->get_slug() . '_updater', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
40
+
41
+ $this->_filters();
42
+ }
43
+
44
+ /**
45
+ * Initiate required filters.
46
+ *
47
+ * @author Vova Feldman (@svovaf)
48
+ * @since 1.0.4
49
+ */
50
+ private function _filters() {
51
+ // Override request for plugin information
52
+ add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
53
+
54
+ // WP 3.0+
55
+ add_filter( 'pre_set_site_transient_update_plugins', array(
56
+ &$this,
57
+ 'pre_set_site_transient_update_plugins_filter'
58
+ ) );
59
+
60
+ if ( ! $this->_fs->has_active_license() ) {
61
+ /**
62
+ * If user has the premium plugin's code but do NOT have an active license,
63
+ * encourage him to upgrade by showing that there's a new release, but instead
64
+ * of showing an update link, show upgrade link to the pricing page.
65
+ *
66
+ * @since 1.1.6
67
+ *
68
+ */
69
+ // WP 2.9+
70
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
71
+ &$this,
72
+ 'catch_plugin_update_row'
73
+ ), 9 );
74
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
75
+ &$this,
76
+ 'edit_and_echo_plugin_update_row'
77
+ ), 11, 2 );
78
+ }
79
+
80
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
81
+ add_filter( 'http_request_host_is_external', array(
82
+ $this,
83
+ 'http_request_host_is_external_filter'
84
+ ), 10, 3 );
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Capture plugin update row by turning output buffering.
90
+ *
91
+ * @author Vova Feldman (@svovaf)
92
+ * @since 1.1.6
93
+ */
94
+ function catch_plugin_update_row() {
95
+ ob_start();
96
+ }
97
+
98
+ /**
99
+ * Overrides default update message format with "renew your license" message.
100
+ *
101
+ * @author Vova Feldman (@svovaf)
102
+ * @since 1.1.6
103
+ */
104
+ function edit_and_echo_plugin_update_row( $file, $plugin_data ) {
105
+ $plugin_update_row = ob_get_clean();
106
+
107
+ $current = get_site_transient( 'update_plugins' );
108
+ if ( ! isset( $current->response[ $file ] ) ) {
109
+ echo $plugin_update_row;
110
+
111
+ return false;
112
+ }
113
+
114
+ $r = $current->response[ $file ];
115
+
116
+ $plugin_update_row = preg_replace(
117
+ '/(\<div.+>)(.+)(\<a.+\<a.+)\<\/div\>/is',
118
+ '$1 $2 ' . sprintf(
119
+ __fs( 'renew-license-now' ),
120
+ '<a href="' . $this->_fs->pricing_url() . '">', '</a>',
121
+ $r->new_version ) .
122
+ '$4',
123
+ $plugin_update_row
124
+ );
125
+
126
+ echo $plugin_update_row;
127
+ }
128
+
129
+ /**
130
+ * Since WP version 3.6, a new security feature was added that denies access to repository with a local ip.
131
+ * During development mode we want to be able updating plugin versions via our localhost repository. This
132
+ * filter white-list all domains including "api.freemius".
133
+ *
134
+ * @link http://www.emanueletessore.com/wordpress-download-failed-valid-url-provided/
135
+ *
136
+ * @author Vova Feldman (@svovaf)
137
+ * @since 1.0.4
138
+ *
139
+ * @param bool $allow
140
+ * @param string $host
141
+ * @param string $url
142
+ *
143
+ * @return bool
144
+ */
145
+ function http_request_host_is_external_filter( $allow, $host, $url ) {
146
+ return ( false !== strpos( $host, 'freemius' ) ) ? true : $allow;
147
+ }
148
+
149
+ /**
150
+ * Check for Updates at the defined API endpoint and modify the update array.
151
+ *
152
+ * This function dives into the update api just when WordPress creates its update array,
153
+ * then adds a custom API call and injects the custom plugin data retrieved from the API.
154
+ * It is reassembled from parts of the native WordPress plugin update code.
155
+ * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
156
+ *
157
+ * @author Vova Feldman (@svovaf)
158
+ * @since 1.0.4
159
+ *
160
+ * @uses FS_Api
161
+ *
162
+ * @param stdClass $transient_data Update array build by WordPress.
163
+ *
164
+ * @return array Modified update array with custom plugin data.
165
+ */
166
+ function pre_set_site_transient_update_plugins_filter( $transient_data ) {
167
+ $this->_logger->entrance();
168
+
169
+ if ( empty( $transient_data ) ||
170
+ defined( 'WP_FS__UNINSTALL_MODE' )
171
+ ) {
172
+ return $transient_data;
173
+ }
174
+
175
+ if ( ! isset( $this->_update_details ) ) {
176
+ // Get plugin's newest update.
177
+ $new_version = $this->_fs->get_update( false, false );
178
+
179
+ $this->_update_details = false;
180
+
181
+ if ( is_object( $new_version ) ) {
182
+ $this->_logger->log( 'Found newer plugin version ' . $new_version->version );
183
+
184
+ $plugin_details = new stdClass();
185
+ $plugin_details->slug = $this->_fs->get_slug();
186
+ $plugin_details->new_version = $new_version->version;
187
+ $plugin_details->url = WP_FS__ADDRESS;
188
+ $plugin_details->package = $new_version->url;
189
+ $plugin_details->plugin = $this->_fs->get_plugin_basename();
190
+
191
+ /**
192
+ * Cache plugin details locally since set_site_transient( 'update_plugins' )
193
+ * called multiple times and the non wp.org plugins are filtered after the
194
+ * call to .org.
195
+ *
196
+ * @since 1.1.8.1
197
+ */
198
+ $this->_update_details = $plugin_details;
199
+ }
200
+ }
201
+
202
+ if ( is_object( $this->_update_details ) ) {
203
+ // Add plugin to transient data.
204
+ $transient_data->response[ $this->_fs->get_plugin_basename() ] = $this->_update_details;
205
+ }
206
+
207
+ return $transient_data;
208
+ }
209
+
210
+ /**
211
+ * Try to fetch plugin's info from .org repository.
212
+ *
213
+ * @author Vova Feldman (@svovaf)
214
+ * @since 1.0.5
215
+ *
216
+ * @param string $action
217
+ * @param object $args
218
+ *
219
+ * @return bool|mixed
220
+ */
221
+ static function _fetch_plugin_info_from_repository( $action, $args ) {
222
+ $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
223
+ if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
224
+ $url = set_url_scheme( $url, 'https' );
225
+ }
226
+
227
+ $args = array(
228
+ 'timeout' => 15,
229
+ 'body' => array(
230
+ 'action' => $action,
231
+ 'request' => serialize( $args )
232
+ )
233
+ );
234
+
235
+ $request = wp_remote_post( $url, $args );
236
+
237
+ if ( is_wp_error( $request ) ) {
238
+ return false;
239
+ }
240
+
241
+ $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
242
+
243
+ if ( ! is_object( $res ) && ! is_array( $res ) ) {
244
+ return false;
245
+ }
246
+
247
+ return $res;
248
+ }
249
+
250
+ /**
251
+ * Updates information on the "View version x.x details" page with custom data.
252
+ *
253
+ * @author Vova Feldman (@svovaf)
254
+ * @since 1.0.4
255
+ *
256
+ * @uses FS_Api
257
+ *
258
+ * @param object $data
259
+ * @param string $action
260
+ * @param mixed $args
261
+ *
262
+ * @return object
263
+ */
264
+ function plugins_api_filter( $data, $action = '', $args = null ) {
265
+ $this->_logger->entrance();
266
+
267
+ if ( ( 'plugin_information' !== $action ) ||
268
+ ! isset( $args->slug )
269
+ ) {
270
+ return $data;
271
+ }
272
+
273
+ $addon = false;
274
+ $is_addon = false;
275
+
276
+ if ( $this->_fs->get_slug() !== $args->slug ) {
277
+ $addon = $this->_fs->get_addon_by_slug( $args->slug );
278
+
279
+ if ( ! is_object( $addon ) ) {
280
+ return $data;
281
+ }
282
+
283
+ $is_addon = true;
284
+ }
285
+
286
+ $plugin_in_repo = false;
287
+ if ( ! $is_addon ) {
288
+ // Try to fetch info from .org repository.
289
+ $data = self::_fetch_plugin_info_from_repository( $action, $args );
290
+
291
+ $plugin_in_repo = ( false !== $data );
292
+ }
293
+
294
+ if ( ! $plugin_in_repo ) {
295
+ $data = $args;
296
+
297
+ // Fetch as much as possible info from local files.
298
+ $plugin_local_data = $this->_fs->get_plugin_data();
299
+ $data->name = $plugin_local_data['Name'];
300
+ $data->author = $plugin_local_data['Author'];
301
+ $data->sections = array(
302
+ 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.',
303
+ );
304
+
305
+ // @todo Store extra plugin info on Freemius or parse readme.txt markup.
306
+ /*$info = $this->_fs->get_api_site_scope()->call('/information.json');
307
+
308
+ if ( !isset($info->error) ) {
309
+ $data = $info;
310
+ }*/
311
+ }
312
+
313
+ // Get plugin's newest update.
314
+ $new_version = $this->_fs->_fetch_latest_version( $is_addon ? $addon->id : false );
315
+
316
+ if ( $is_addon ) {
317
+ $data->name = $addon->title . ' ' . __fs( 'addon', $this->_fs->get_slug() );
318
+ $data->slug = $addon->slug;
319
+ $data->url = WP_FS__ADDRESS;
320
+ $data->package = $new_version->url;
321
+ }
322
+
323
+ if ( ! $plugin_in_repo ) {
324
+ $data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
325
+ $data->requires = $new_version->requires_platform_version;
326
+ $data->tested = $new_version->tested_up_to_version;
327
+ }
328
+
329
+ $data->version = $new_version->version;
330
+ $data->download_link = $new_version->url;
331
+
332
+ return $data;
333
+ }
334
+ }
freemius/includes/class-fs-security.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ define( 'WP_FS__SECURITY_PARAMS_PREFIX', 's_' );
14
+
15
+ class FS_Security {
16
+ /**
17
+ * @var FS_Security
18
+ * @since 1.0.3
19
+ */
20
+ private static $_instance;
21
+ /**
22
+ * @var FS_Logger
23
+ * @since 1.0.3
24
+ */
25
+ private static $_logger;
26
+
27
+ public static function instance() {
28
+ if ( ! isset( self::$_instance ) ) {
29
+ self::$_instance = new FS_Security();
30
+ self::$_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
31
+ }
32
+
33
+ return self::$_instance;
34
+ }
35
+
36
+ private function __construct() {
37
+ }
38
+
39
+ function get_secure_token( FS_Scope_Entity $entity, $timestamp, $action = '' ) {
40
+ return md5(
41
+ $timestamp .
42
+ $entity->id .
43
+ $entity->secret_key .
44
+ $entity->public_key .
45
+ $action
46
+ );
47
+ }
48
+
49
+ function get_context_params( FS_Scope_Entity $entity, $timestamp = false, $action = '' ) {
50
+ if ( false === $timestamp ) {
51
+ $timestamp = time();
52
+ }
53
+
54
+ return array(
55
+ 's_ctx_type' => $entity->get_type(),
56
+ 's_ctx_id' => $entity->id,
57
+ 's_ctx_ts' => $timestamp,
58
+ 's_ctx_secure' => $this->get_secure_token( $entity, $timestamp, $action ),
59
+ );
60
+ }
61
+ }
freemius/includes/debug/class-fs-debug-bar-panel.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Extends Debug Bar plugin by adding a panel to show all Freemius API requests.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7.3
18
+ *
19
+ * Class Freemius_Debug_Bar_Panel
20
+ */
21
+ class Freemius_Debug_Bar_Panel extends Debug_Bar_Panel {
22
+ function init() {
23
+ $this->title( 'Freemius' );
24
+ }
25
+
26
+ static function requests_count() {
27
+ if ( class_exists( 'Freemius_Api' ) ) {
28
+ $logger = Freemius_Api::GetLogger();
29
+ } else {
30
+ $logger = array();
31
+ }
32
+
33
+ return number_format( count( $logger ) );
34
+ }
35
+
36
+ static function total_time() {
37
+ if ( class_exists( 'Freemius_Api' ) ) {
38
+ $logger = Freemius_Api::GetLogger();
39
+ } else {
40
+ $logger = array();
41
+ }
42
+
43
+ $total_time = .0;
44
+ foreach ( $logger as $l ) {
45
+ $total_time += $l['total'];
46
+ }
47
+
48
+ return number_format( 100 * $total_time, 2 ) . ' ' . __fs( 'ms' );
49
+ }
50
+
51
+ function render() {
52
+ ?>
53
+ <div id='debug-bar-php'>
54
+ <?php fs_require_template( '/debug/api-calls.php' ) ?>
55
+ <br>
56
+ <?php fs_require_template( '/debug/scheduled-crons.php' ) ?>
57
+ <br>
58
+ <?php fs_require_template( '/debug/plugins-themes-sync.php' ) ?>
59
+ <br>
60
+ <?php fs_require_template( '/debug/logger.php' ) ?>
61
+ </div>
62
+ <?php
63
+ }
64
+ }
freemius/includes/debug/debug-bar-start.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! WP_FS__DEBUG_SDK ) {
14
+ return;
15
+ }
16
+
17
+ /**
18
+ * Initialize Freemius custom debug panels.
19
+ *
20
+ * @param array $panels Debug bar panels objects
21
+ *
22
+ * @return array Debug bar panels with your custom panels
23
+ */
24
+ function fs_custom_panels_init( $panels ) {
25
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
26
+ if ( FS_API__LOGGER_ON ) {
27
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
28
+ $panels[] = new Freemius_Debug_Bar_Panel();
29
+ }
30
+ }
31
+
32
+ return $panels;
33
+ }
34
+
35
+ function fs_custom_status_init( $statuses ) {
36
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
37
+ if ( FS_API__LOGGER_ON ) {
38
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
39
+ $statuses[] = array(
40
+ 'fs_api_requests',
41
+ __fs( 'Freemius API' ),
42
+ Freemius_Debug_Bar_Panel::requests_count() . ' ' . __fs( 'Requests' ) .
43
+ ' (' . Freemius_Debug_Bar_Panel::total_time() . ')'
44
+ );
45
+ }
46
+ }
47
+
48
+ return $statuses;
49
+ }
50
+
51
+ add_filter( 'debug_bar_panels', 'fs_custom_panels_init' );
52
+ add_filter( 'debug_bar_statuses', 'fs_custom_status_init' );
freemius/includes/entities/class-fs-entity.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Get object's public variables.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.0.0
18
+ *
19
+ * @param object $object
20
+ *
21
+ * @return array
22
+ */
23
+ function fs_get_object_public_vars( $object ) {
24
+ return get_object_vars( $object );
25
+ }
26
+
27
+ class FS_Entity {
28
+ /**
29
+ * @var number
30
+ */
31
+ public $id;
32
+ /**
33
+ * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format.
34
+ */
35
+ public $updated;
36
+ /**
37
+ * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format.
38
+ */
39
+ public $created;
40
+
41
+ /**
42
+ * @param bool|stdClass $entity
43
+ */
44
+ function __construct( $entity = false ) {
45
+ if ( ! ( $entity instanceof stdClass ) ) {
46
+ return;
47
+ }
48
+
49
+ $props = fs_get_object_public_vars( $this );
50
+
51
+ foreach ( $props as $key => $def_value ) {
52
+ $this->{$key} = isset( $entity->{$key} ) ?
53
+ $entity->{$key} :
54
+ $def_value;
55
+ }
56
+ }
57
+
58
+ static function get_type() {
59
+ return 'type';
60
+ }
61
+
62
+ /**
63
+ * @author Vova Feldman (@svovaf)
64
+ * @since 1.0.6
65
+ *
66
+ * @param FS_Entity $entity1
67
+ * @param FS_Entity $entity2
68
+ *
69
+ * @return bool
70
+ */
71
+ static function equals( $entity1, $entity2 ) {
72
+ if ( is_null( $entity1 ) && is_null( $entity2 ) ) {
73
+ return true;
74
+ } else if ( is_object( $entity1 ) && is_object( $entity2 ) ) {
75
+ return ( $entity1->id == $entity2->id );
76
+ } else if ( is_object( $entity1 ) ) {
77
+ return is_null( $entity1->id );
78
+ } else {
79
+ return is_null( $entity2->id );
80
+ }
81
+ }
82
+
83
+ private $_is_updated = false;
84
+
85
+ /**
86
+ * Update object property.
87
+ *
88
+ * @author Vova Feldman (@svovaf)
89
+ * @since 1.0.9
90
+ *
91
+ * @param string|array[string]mixed $key
92
+ * @param string|bool $val
93
+ *
94
+ * @return bool
95
+ */
96
+ function update( $key, $val = false ) {
97
+ if ( ! is_array( $key ) ) {
98
+ $key = array( $key => $val );
99
+ }
100
+
101
+ $is_updated = false;
102
+
103
+ foreach ( $key as $k => $v ) {
104
+ if ( $this->{$k} === $v ) {
105
+ continue;
106
+ }
107
+
108
+ if ( ( is_string( $this->{$k} ) && is_numeric( $v ) ||
109
+ ( is_numeric( $this->{$k} ) && is_string( $v ) ) ) &&
110
+ $this->{$k} == $v
111
+ ) {
112
+ continue;
113
+ }
114
+
115
+ // Update value.
116
+ $this->{$k} = $v;
117
+
118
+ $is_updated = true;
119
+ }
120
+
121
+ $this->_is_updated = $is_updated;
122
+
123
+ return $is_updated;
124
+ }
125
+
126
+ /**
127
+ * Checks if entity was updated.
128
+ *
129
+ * @author Vova Feldman (@svovaf)
130
+ * @since 1.0.9
131
+ *
132
+ * @return bool
133
+ */
134
+ function is_updated() {
135
+ return $this->_is_updated;
136
+ }
137
+
138
+ /**
139
+ * @param $id
140
+ *
141
+ * @author Vova Feldman (@svovaf)
142
+ * @since 1.1.2
143
+ *
144
+ * @return bool
145
+ */
146
+ static function is_valid_id($id){
147
+ return is_numeric($id);
148
+ }
149
+ }
freemius/includes/entities/class-fs-payment.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2016, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_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 http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Info extends FS_Entity {
14
+ public $plugin_id;
15
+ public $description;
16
+ public $short_description;
17
+ public $banner_url;
18
+ public $card_banner_url;
19
+ public $selling_point_0;
20
+ public $selling_point_1;
21
+ public $selling_point_2;
22
+ public $screenshots;
23
+
24
+ /**
25
+ * @param stdClass|bool $plugin_info
26
+ */
27
+ function __construct( $plugin_info = false ) {
28
+ parent::__construct( $plugin_info );
29
+ }
30
+
31
+ static function get_type() {
32
+ return 'plugin';
33
+ }
34
+ }
freemius/includes/entities/class-fs-plugin-license.php ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_License extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plugin_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $user_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $plan_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $pricing_id;
33
+ /**
34
+ * @var int|null
35
+ */
36
+ public $quota;
37
+ /**
38
+ * @var int
39
+ */
40
+ public $activated;
41
+ /**
42
+ * @var int
43
+ */
44
+ public $activated_local;
45
+ /**
46
+ * @var string
47
+ */
48
+ public $expiration;
49
+ /**
50
+ * @var string
51
+ */
52
+ public $secret_key;
53
+ /**
54
+ * @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
55
+ * license.
56
+ */
57
+ public $is_free_localhost;
58
+ /**
59
+ * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
60
+ * block updates and support.
61
+ */
62
+ public $is_block_features;
63
+ /**
64
+ * @var bool
65
+ */
66
+ public $is_cancelled;
67
+
68
+ #endregion Properties
69
+
70
+ /**
71
+ * @param stdClass|bool $license
72
+ */
73
+ function __construct( $license = false ) {
74
+ parent::__construct( $license );
75
+ }
76
+
77
+ static function get_type() {
78
+ return 'license';
79
+ }
80
+
81
+ /**
82
+ * Check how many site activations left.
83
+ *
84
+ * @author Vova Feldman (@svovaf)
85
+ * @since 1.0.5
86
+ *
87
+ * @return int
88
+ */
89
+ function left() {
90
+ if ( $this->is_expired() ) {
91
+ return 0;
92
+ }
93
+
94
+ if ( $this->is_unlimited() ) {
95
+ return 999;
96
+ }
97
+
98
+ return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
99
+ }
100
+
101
+ /**
102
+ * Check if single site license.
103
+ *
104
+ * @author Vova Feldman (@svovaf)
105
+ * @since 1.1.8.1
106
+ *
107
+ * @return bool
108
+ */
109
+ function is_single_site() {
110
+ return ( is_numeric( $this->quota ) && 1 == $this->quota );
111
+ }
112
+
113
+ /**
114
+ * @author Vova Feldman (@svovaf)
115
+ * @since 1.0.5
116
+ *
117
+ * @return bool
118
+ */
119
+ function is_expired() {
120
+ return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
121
+ }
122
+
123
+ /**
124
+ * @author Vova Feldman (@svovaf)
125
+ * @since 1.0.6
126
+ *
127
+ * @return bool
128
+ */
129
+ function is_lifetime() {
130
+ return is_null( $this->expiration );
131
+ }
132
+
133
+ /**
134
+ * @author Vova Feldman (@svovaf)
135
+ * @since 1.2.0
136
+ *
137
+ * @return bool
138
+ */
139
+ function is_unlimited() {
140
+ return is_null( $this->quota );
141
+ }
142
+
143
+ /**
144
+ * Check if license is fully utilized.
145
+ *
146
+ * @author Vova Feldman (@svovaf)
147
+ * @since 1.0.6
148
+ *
149
+ * @param bool $is_localhost
150
+ *
151
+ * @return bool
152
+ */
153
+ function is_utilized( $is_localhost = null ) {
154
+ if ( is_null( $is_localhost ) ) {
155
+ $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
156
+ }
157
+
158
+ if ( $this->is_unlimited() ) {
159
+ return false;
160
+ }
161
+
162
+ return ! ( $this->is_free_localhost && $is_localhost ) &&
163
+ ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
164
+ }
165
+
166
+ /**
167
+ * Check if license's plan features are enabled.
168
+ *
169
+ * - Either if plan not expired
170
+ * - If expired, based on the configuration to block features or not.
171
+ *
172
+ * @author Vova Feldman (@svovaf)
173
+ * @since 1.0.6
174
+ *
175
+ * @return bool
176
+ */
177
+ function is_features_enabled() {
178
+ return ( ! $this->is_block_features || ! $this->is_expired() );
179
+ }
180
+
181
+ /**
182
+ * Subscription considered to be new without any payments
183
+ * if the license expires in less than 24 hours
184
+ * from the license creation.
185
+ *
186
+ * @author Vova Feldman (@svovaf)
187
+ * @since 1.0.9
188
+ *
189
+ * @return bool
190
+ */
191
+ function is_first_payment_pending() {
192
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
193
+ }
194
+ }
freemius/includes/entities/class-fs-plugin-plan.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Plan extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plugin_id;
21
+ /**
22
+ * @var string
23
+ */
24
+ public $name;
25
+ /**
26
+ * @var string
27
+ */
28
+ public $title;
29
+ /**
30
+ * @var string
31
+ */
32
+ public $description;
33
+ /**
34
+ * @var bool Defaults to true. If true, allow unlimited localhost installs with the same license.
35
+ */
36
+ public $is_free_localhost;
37
+ /**
38
+ * @var bool Defaults to true. If false, don't block features after license expiry - only block updates and
39
+ * support.
40
+ */
41
+ public $is_block_features;
42
+ /**
43
+ * @var int
44
+ */
45
+ public $license_type;
46
+ /**
47
+ * @var bool
48
+ */
49
+ public $is_https_support;
50
+ /**
51
+ * @var int Trial days.
52
+ */
53
+ public $trial_period;
54
+ /**
55
+ * @var string If true, require payment for trial.
56
+ */
57
+ public $is_require_subscription;
58
+ /**
59
+ * @var string Knowledge Base URL.
60
+ */
61
+ public $support_kb;
62
+ /**
63
+ * @var string Support Forum URL.
64
+ */
65
+ public $support_forum;
66
+ /**
67
+ * @var string Support email address.
68
+ */
69
+ public $support_email;
70
+ /**
71
+ * @var string Support phone.
72
+ */
73
+ public $support_phone;
74
+ /**
75
+ * @var string Support skype username.
76
+ */
77
+ public $support_skype;
78
+ /**
79
+ * @var bool Is personal success manager supported with the plan.
80
+ */
81
+ public $is_success_manager;
82
+ /**
83
+ * @var bool Is featured plan.
84
+ */
85
+ public $is_featured;
86
+
87
+ #endregion Properties
88
+
89
+ /**
90
+ * @param object|bool $plan
91
+ */
92
+ function __construct( $plan = false ) {
93
+ parent::__construct( $plan );
94
+
95
+ if ( is_object( $plan ) ) {
96
+ $this->name = strtolower( $plan->name );
97
+ }
98
+ }
99
+
100
+ static function get_type() {
101
+ return 'plan';
102
+ }
103
+
104
+ /**
105
+ * @author Vova Feldman (@svovaf)
106
+ * @since 1.0.9
107
+ *
108
+ * @return bool
109
+ */
110
+ function is_free() {
111
+ return ( 'free' === $this->name );
112
+ }
113
+
114
+ /**
115
+ * Checks if this plan supports "Technical Support".
116
+ *
117
+ * @author Leo Fajardo (leorw)
118
+ * @since 1.2.0
119
+ *
120
+ * @return bool
121
+ */
122
+ function has_technical_support() {
123
+ return ( ! empty( $this->support_email ) ||
124
+ ! empty( $this->support_skype ) ||
125
+ ! empty( $this->support_phone ) ||
126
+ ! empty( $this->is_success_manager )
127
+ );
128
+ }
129
+
130
+ /**
131
+ * @author Vova Feldman (@svovaf)
132
+ * @since 1.0.9
133
+ *
134
+ * @return bool
135
+ */
136
+ function has_trial() {
137
+ return ! $this->is_free() &&
138
+ is_numeric( $this->trial_period ) && ( $this->trial_period > 0 );
139
+ }
140
+ }
freemius/includes/entities/class-fs-plugin-tag.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Tag extends FS_Entity {
14
+ public $version;
15
+ public $url;
16
+
17
+ function __construct( $tag = false ) {
18
+ parent::__construct( $tag );
19
+ }
20
+
21
+ static function get_type() {
22
+ return 'tag';
23
+ }
24
+ }
freemius/includes/entities/class-fs-plugin.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin extends FS_Scope_Entity {
14
+ /**
15
+ * @since 1.0.6
16
+ * @var null|number
17
+ */
18
+ public $parent_plugin_id;
19
+ /**
20
+ * @var string
21
+ */
22
+ public $title;
23
+ /**
24
+ * @var string
25
+ */
26
+ public $slug;
27
+
28
+ #region Install Specific Properties
29
+
30
+ /**
31
+ * @var string
32
+ */
33
+ public $file;
34
+ /**
35
+ * @var string
36
+ */
37
+ public $version;
38
+ /**
39
+ * @var bool
40
+ */
41
+ public $auto_update;
42
+ /**
43
+ * @var FS_Plugin_Info
44
+ */
45
+ public $info;
46
+ /**
47
+ * @since 1.0.9
48
+ *
49
+ * @var bool
50
+ */
51
+ public $is_premium;
52
+ /**
53
+ * @since 1.0.9
54
+ *
55
+ * @var bool
56
+ */
57
+ public $is_live;
58
+
59
+ #endregion Install Specific Properties
60
+
61
+ /**
62
+ * @param stdClass|bool $plugin
63
+ */
64
+ function __construct( $plugin = false ) {
65
+ parent::__construct( $plugin );
66
+
67
+ $this->is_premium = false;
68
+ $this->is_live = true;
69
+
70
+ if ( isset( $plugin->info ) && is_object( $plugin->info ) ) {
71
+ $this->info = new FS_Plugin_Info( $plugin->info );
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Check if plugin is an add-on (has parent).
77
+ *
78
+ * @author Vova Feldman (@svovaf)
79
+ * @since 1.0.6
80
+ *
81
+ * @return bool
82
+ */
83
+ function is_addon() {
84
+ return isset( $this->parent_plugin_id ) && is_numeric( $this->parent_plugin_id );
85
+ }
86
+
87
+ static function get_type() {
88
+ return 'plugin';
89
+ }
90
+ }
freemius/includes/entities/class-fs-pricing.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius for EDD Add-On
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Pricing extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plan_id;
21
+ /**
22
+ * @var int
23
+ */
24
+ public $licenses;
25
+ /**
26
+ * @var null|float
27
+ */
28
+ public $monthly_price;
29
+ /**
30
+ * @var null|float
31
+ */
32
+ public $annual_price;
33
+ /**
34
+ * @var null|float
35
+ */
36
+ public $lifetime_price;
37
+
38
+ #endregion Properties
39
+
40
+ /**
41
+ * @param object|bool $pricing
42
+ */
43
+ function __construct( $pricing = false ) {
44
+ parent::__construct( $pricing );
45
+ }
46
+
47
+ static function get_type() {
48
+ return 'pricing';
49
+ }
50
+
51
+ /**
52
+ * @author Vova Feldman (@svovaf)
53
+ * @since 1.1.8
54
+ *
55
+ * @return bool
56
+ */
57
+ function has_monthly() {
58
+ return ( is_numeric( $this->monthly_price ) && $this->monthly_price > 0 );
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.8
64
+ *
65
+ * @return bool
66
+ */
67
+ function has_annual() {
68
+ return ( is_numeric( $this->annual_price ) && $this->annual_price > 0 );
69
+ }
70
+
71
+ /**
72
+ * @author Vova Feldman (@svovaf)
73
+ * @since 1.1.8
74
+ *
75
+ * @return bool
76
+ */
77
+ function has_lifetime() {
78
+ return ( is_numeric( $this->lifetime_price ) && $this->lifetime_price > 0 );
79
+ }
80
+
81
+ /**
82
+ * Check if unlimited licenses pricing.
83
+ *
84
+ * @author Vova Feldman (@svovaf)
85
+ * @since 1.1.8
86
+ *
87
+ * @return bool
88
+ */
89
+ function is_unlimited() {
90
+ return is_null( $this->licenses );
91
+ }
92
+
93
+
94
+ /**
95
+ * Check if pricing has more than one billing cycle.
96
+ *
97
+ * @author Vova Feldman (@svovaf)
98
+ * @since 1.1.8
99
+ *
100
+ * @return bool
101
+ */
102
+ function is_multi_cycle() {
103
+ $cycles = 0;
104
+ if ( $this->has_monthly() ) {
105
+ $cycles ++;
106
+ }
107
+ if ( $this->has_annual() ) {
108
+ $cycles ++;
109
+ }
110
+ if ( $this->has_lifetime() ) {
111
+ $cycles ++;
112
+ }
113
+
114
+ return $cycles > 1;
115
+ }
116
+
117
+ /**
118
+ * Get annual over monthly discount.
119
+ *
120
+ * @author Vova Feldman (@svovaf)
121
+ * @since 1.1.8
122
+ *
123
+ * @return int
124
+ */
125
+ function annual_discount_percentage() {
126
+ return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 );
127
+ }
128
+
129
+ /**
130
+ * Get annual over monthly savings.
131
+ *
132
+ * @author Vova Feldman (@svovaf)
133
+ * @since 1.1.8
134
+ *
135
+ * @return float
136
+ */
137
+ function annual_savings() {
138
+ return ( $this->monthly_price * 12 - $this->annual_price ) * ( $this->is_unlimited() ? 1 : $this->licenses );
139
+ }
140
+
141
+ }
freemius/includes/entities/class-fs-scope-entity.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Scope_Entity extends FS_Entity {
14
+ /**
15
+ * @var string
16
+ */
17
+ public $public_key;
18
+ /**
19
+ * @var string
20
+ */
21
+ public $secret_key;
22
+
23
+ /**
24
+ * @param bool|stdClass $scope_entity
25
+ */
26
+ function __construct( $scope_entity = false ) {
27
+ parent::__construct( $scope_entity );
28
+ }
29
+ }
freemius/includes/entities/class-fs-site.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Site extends FS_Scope_Entity {
14
+ /**
15
+ * @var string
16
+ */
17
+ public $slug;
18
+ /**
19
+ * @var number
20
+ */
21
+ public $site_id;
22
+ /**
23
+ * @var number
24
+ */
25
+ public $plugin_id;
26
+ /**
27
+ * @var number
28
+ */
29
+ public $user_id;
30
+ /**
31
+ * @var string
32
+ */
33
+ public $title;
34
+ /**
35
+ * @var string
36
+ */
37
+ public $url;
38
+ /**
39
+ * @var string
40
+ */
41
+ public $version;
42
+ /**
43
+ * @var string E.g. en-GB
44
+ */
45
+ public $language;
46
+ /**
47
+ * @var string E.g. UTF-8
48
+ */
49
+ public $charset;
50
+ /**
51
+ * @var string Platform version (e.g WordPress version).
52
+ */
53
+ public $platform_version;
54
+ /**
55
+ * @var string Programming language version (e.g PHP version).
56
+ */
57
+ public $programming_language_version;
58
+ /**
59
+ * @var FS_Plugin_Plan $plan
60
+ */
61
+ public $plan;
62
+ /**
63
+ * @var number|null
64
+ */
65
+ public $license_id;
66
+ /**
67
+ * @var number|null
68
+ */
69
+ public $trial_plan_id;
70
+ /**
71
+ * @var string|null
72
+ */
73
+ public $trial_ends;
74
+ /**
75
+ * @since 1.0.9
76
+ *
77
+ * @var bool
78
+ */
79
+ public $is_premium = false;
80
+
81
+ /**
82
+ * @param stdClass|bool $site
83
+ */
84
+ function __construct( $site = false ) {
85
+ $this->plan = new FS_Plugin_Plan();
86
+
87
+ parent::__construct( $site );
88
+
89
+ if ( is_object( $site ) ) {
90
+ $this->plan->id = $site->plan_id;
91
+ }
92
+ }
93
+
94
+ static function get_type() {
95
+ return 'install';
96
+ }
97
+
98
+ function is_localhost() {
99
+ // The server has no way to verify if localhost unless localhost appears in domain.
100
+ return WP_FS__IS_LOCALHOST_FOR_SERVER;
101
+ // return (substr($_SERVER['REMOTE_ADDR'], 0, 4) == '127.' || $_SERVER['REMOTE_ADDR'] == '::1');
102
+ }
103
+
104
+ /**
105
+ * Check if site in trial.
106
+ *
107
+ * @author Vova Feldman (@svovaf)
108
+ * @since 1.0.9
109
+ *
110
+ * @return bool
111
+ */
112
+ function is_trial() {
113
+ return is_numeric( $this->trial_plan_id ) && ( strtotime( $this->trial_ends ) > WP_FS__SCRIPT_START_TIME );
114
+ }
115
+
116
+ /**
117
+ * Check if user already utilized the trial with the current install.
118
+ *
119
+ * @author Vova Feldman (@svovaf)
120
+ * @since 1.0.9
121
+ *
122
+ * @return bool
123
+ */
124
+ function is_trial_utilized() {
125
+ return is_numeric( $this->trial_plan_id );
126
+ }
127
+ }
freemius/includes/entities/class-fs-subscription.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.9
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Subscription extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $user_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $install_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $plan_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $license_id;
33
+ /**
34
+ * @var float
35
+ */
36
+ public $total_gross;
37
+ /**
38
+ * @var float
39
+ */
40
+ public $amount_per_cycle;
41
+ /**
42
+ * @var int # of months
43
+ */
44
+ public $billing_cycle;
45
+ /**
46
+ * @var float
47
+ */
48
+ public $outstanding_balance;
49
+ /**
50
+ * @var int
51
+ */
52
+ public $failed_payments;
53
+ /**
54
+ * @var string
55
+ */
56
+ public $gateway;
57
+ /**
58
+ * @var string
59
+ */
60
+ public $external_id;
61
+ /**
62
+ * @var string|null
63
+ */
64
+ public $trial_ends;
65
+ /**
66
+ * @var string|null Datetime of the next payment, or null if cancelled
67
+ */
68
+ public $next_payment;
69
+ /**
70
+ * @var string|null
71
+ */
72
+ public $vat_id;
73
+ /**
74
+ * @var string Two characters country code
75
+ */
76
+ public $country_code;
77
+
78
+ #endregion Properties
79
+
80
+ /**
81
+ * @param object|bool $subscription
82
+ */
83
+ function __construct( $subscription = false ) {
84
+ parent::__construct( $subscription );
85
+ }
86
+
87
+ static function get_type() {
88
+ return 'subscription';
89
+ }
90
+
91
+ /**
92
+ * Check if subscription is active.
93
+ *
94
+ * @author Vova Feldman (@svovaf)
95
+ * @since 1.0.9
96
+ *
97
+ * @return bool
98
+ */
99
+ function is_active() {
100
+ return ! empty( $this->next_payment ) &&
101
+ ( strtotime( $this->next_payment ) > WP_FS__SCRIPT_START_TIME );
102
+ }
103
+
104
+ /**
105
+ * Subscription considered to be new without any payments
106
+ * if the next payment should be made within less than 24 hours
107
+ * from the subscription creation.
108
+ *
109
+ * @author Vova Feldman (@svovaf)
110
+ * @since 1.0.9
111
+ *
112
+ * @return bool
113
+ */
114
+ function is_first_payment_pending() {
115
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->next_payment ) - strtotime( $this->created ) );
116
+ }
117
+
118
+ /**
119
+ * @author Vova Feldman (@svovaf)
120
+ * @since 1.1.7
121
+ */
122
+ function has_trial() {
123
+ return ! is_null( $this->trial_ends );
124
+ }
125
+ }
freemius/includes/entities/class-fs-user.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_User extends FS_Scope_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ public $email;
21
+ /**
22
+ * @var string
23
+ */
24
+ public $first;
25
+ /**
26
+ * @var string
27
+ */
28
+ public $last;
29
+ /**
30
+ * @var bool
31
+ */
32
+ public $is_verified;
33
+ /**
34
+ * @var string|null
35
+ */
36
+ public $customer_id;
37
+ /**
38
+ * @var float
39
+ */
40
+ public $gross;
41
+
42
+ #endregion Properties
43
+
44
+ /**
45
+ * @param object|bool $user
46
+ */
47
+ function __construct( $user = false ) {
48
+ parent::__construct( $user );
49
+ }
50
+
51
+ function get_name() {
52
+ return trim( ucfirst( trim( is_string( $this->first ) ? $this->first : '' ) ) . ' ' . ucfirst( trim( is_string( $this->last ) ? $this->last : '' ) ) );
53
+ }
54
+
55
+ function is_verified() {
56
+ return ( isset( $this->is_verified ) && true === $this->is_verified );
57
+ }
58
+
59
+ static function get_type() {
60
+ return 'user';
61
+ }
62
+ }
freemius/includes/fs-core-functions.php ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ global $fs_core_logger;
14
+
15
+ $fs_core_logger = FS_Logger::get_logger( WP_FS__SLUG . '_core', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
16
+
17
+ if ( ! function_exists( 'fs_dummy' ) ) {
18
+ function fs_dummy() {
19
+ }
20
+ }
21
+
22
+ /* Url.
23
+ --------------------------------------------------------------------------------------------*/
24
+ function fs_get_url_daily_cache_killer() {
25
+ return date( '\YY\Mm\Dd' );
26
+ }
27
+
28
+ /* Templates / Views.
29
+ --------------------------------------------------------------------------------------------*/
30
+ if ( ! function_exists( 'fs_get_template_path' ) ) {
31
+ function fs_get_template_path( $path ) {
32
+ return WP_FS__DIR_TEMPLATES . '/' . trim( $path, '/' );
33
+ }
34
+
35
+ function fs_include_template( $path, &$params = null ) {
36
+ $VARS = &$params;
37
+ include( fs_get_template_path( $path ) );
38
+ }
39
+
40
+ function fs_include_once_template( $path, &$params = null ) {
41
+ $VARS = &$params;
42
+ include_once( fs_get_template_path( $path ) );
43
+ }
44
+
45
+ function fs_require_template( $path, &$params = null ) {
46
+ $VARS = &$params;
47
+ require( fs_get_template_path( $path ) );
48
+ }
49
+
50
+ function fs_require_once_template( $path, &$params = null ) {
51
+ $VARS = &$params;
52
+ require_once( fs_get_template_path( $path ) );
53
+ }
54
+
55
+ function fs_get_template( $path, &$params = null ) {
56
+ ob_start();
57
+
58
+ $VARS = &$params;
59
+ require_once( fs_get_template_path( $path ) );
60
+
61
+ return ob_get_clean();
62
+ }
63
+ }
64
+
65
+ /* Scripts and styles including.
66
+ --------------------------------------------------------------------------------------------*/
67
+ function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) {
68
+ global $fs_core_logger;
69
+ if ( $fs_core_logger->is_on() ) {
70
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
71
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_CSS . trim( $path, '/' ) ) );
72
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ) );
73
+ }
74
+
75
+ wp_enqueue_style( $handle, plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $media );
76
+ }
77
+
78
+ function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) {
79
+ global $fs_core_logger;
80
+ if ( $fs_core_logger->is_on() ) {
81
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
82
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_JS . trim( $path, '/' ) ) );
83
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ) );
84
+ }
85
+
86
+ wp_enqueue_script( $handle, plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $in_footer );
87
+ }
88
+
89
+ function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) {
90
+ return plugins_url( plugin_basename( $img_dir . '/' . trim( $path, '/' ) ) );
91
+ }
92
+
93
+ /* Request handlers.
94
+ --------------------------------------------------------------------------------------------*/
95
+ /**
96
+ * @param string $key
97
+ * @param mixed $def
98
+ *
99
+ * @return mixed
100
+ */
101
+ function fs_request_get( $key, $def = false ) {
102
+ return isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def;
103
+ }
104
+
105
+ function fs_request_has( $key ) {
106
+ return isset( $_REQUEST[ $key ] );
107
+ }
108
+
109
+ function fs_request_get_bool( $key, $def = false ) {
110
+ if ( ! isset( $_REQUEST[ $key ] ) ) {
111
+ return $def;
112
+ }
113
+
114
+ if ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) {
115
+ return true;
116
+ }
117
+
118
+ if ( 0 == $_REQUEST[ $key ] || 'false' === strtolower( $_REQUEST[ $key ] ) ) {
119
+ return false;
120
+ }
121
+
122
+ return $def;
123
+ }
124
+
125
+ function fs_request_is_post() {
126
+ return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
127
+ }
128
+
129
+ function fs_request_is_get() {
130
+ return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
131
+ }
132
+
133
+ function fs_get_action( $action_key = 'action' ) {
134
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
135
+ return strtolower( $_REQUEST[ $action_key ] );
136
+ }
137
+
138
+ if ( 'action' == $action_key ) {
139
+ $action_key = 'fs_action';
140
+
141
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
142
+ return strtolower( $_REQUEST[ $action_key ] );
143
+ }
144
+ }
145
+
146
+ return false;
147
+ }
148
+
149
+ function fs_request_is_action( $action, $action_key = 'action' ) {
150
+ return ( strtolower( $action ) === fs_get_action( $action_key ) );
151
+ }
152
+
153
+ function fs_is_plugin_page( $menu_slug ) {
154
+ return ( is_admin() && $_REQUEST['page'] === $menu_slug );
155
+ }
156
+
157
+ /* Core UI.
158
+ --------------------------------------------------------------------------------------------*/
159
+ /**
160
+ * @param string $slug
161
+ * @param string $page
162
+ * @param string $action
163
+ * @param string $title
164
+ * @param array $params
165
+ * @param bool $is_primary
166
+ * @param string|bool $icon_class Optional class for an icon (since 1.1.7).
167
+ * @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7).
168
+ * @param string $method Since 1.1.7
169
+ *
170
+ * @uses fs_ui_get_action_button()
171
+ */
172
+ function fs_ui_action_button(
173
+ $slug,
174
+ $page,
175
+ $action,
176
+ $title,
177
+ $params = array(),
178
+ $is_primary = true,
179
+ $icon_class = false,
180
+ $confirmation = false,
181
+ $method = 'GET'
182
+ ) {
183
+ echo fs_ui_get_action_button(
184
+ $slug,
185
+ $page,
186
+ $action,
187
+ $title,
188
+ $params,
189
+ $is_primary,
190
+ $icon_class,
191
+ $confirmation,
192
+ $method
193
+ );
194
+ }
195
+
196
+ /**
197
+ * @author Vova Feldman (@svovaf)
198
+ * @since 1.1.7
199
+ *
200
+ * @param string $slug
201
+ * @param string $page
202
+ * @param string $action
203
+ * @param string $title
204
+ * @param array $params
205
+ * @param bool $is_primary
206
+ * @param string|bool $icon_class Optional class for an icon.
207
+ * @param string|bool $confirmation Optional confirmation message before submit.
208
+ * @param string $method
209
+ *
210
+ * @return string
211
+ */
212
+ function fs_ui_get_action_button(
213
+ $slug,
214
+ $page,
215
+ $action,
216
+ $title,
217
+ $params = array(),
218
+ $is_primary = true,
219
+ $icon_class = false,
220
+ $confirmation = false,
221
+ $method = 'GET'
222
+ ) {
223
+ // Prepend icon (if set).
224
+ $title = ( is_string( $icon_class ) ? '<i class="' . $icon_class . '"></i> ' : '' ) . $title;
225
+
226
+ if ( is_string( $confirmation ) ) {
227
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="if (confirm(\'%s\')) this.parentNode.submit(); return false;">%s</a></form>',
228
+ freemius( $slug )->_get_admin_page_url( $page, $params ),
229
+ $method,
230
+ $action,
231
+ wp_nonce_field( $action, '_wpnonce', true, false ),
232
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
233
+ $confirmation,
234
+ $title
235
+ );
236
+ } else if ( 'GET' !== strtoupper( $method ) ) {
237
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="this.parentNode.submit(); return false;">%s</a></form>',
238
+ freemius( $slug )->_get_admin_page_url( $page, $params ),
239
+ $method,
240
+ $action,
241
+ wp_nonce_field( $action, '_wpnonce', true, false ),
242
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
243
+ $title
244
+ );
245
+ } else {
246
+ return sprintf( '<a href="%s" class="%s">%s</a></form>',
247
+ wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ),
248
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
249
+ $title
250
+ );
251
+ }
252
+ }
253
+
254
+ function fs_ui_action_link( $slug, $page, $action, $title, $params = array() ) {
255
+ ?><a class=""
256
+ href="<?php echo wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php
257
+ }
258
+
259
+ /*function fs_error_handler($errno, $errstr, $errfile, $errline)
260
+ {
261
+ if (false === strpos($errfile, 'freemius/'))
262
+ {
263
+ // @todo Dump Freemius errors to local log.
264
+ }
265
+
266
+ // switch ($errno) {
267
+ // case E_USER_ERROR:
268
+ // break;
269
+ // case E_WARNING:
270
+ // case E_USER_WARNING:
271
+ // break;
272
+ // case E_NOTICE:
273
+ // case E_USER_NOTICE:
274
+ // break;
275
+ // default:
276
+ // break;
277
+ // }
278
+ }
279
+
280
+ set_error_handler('fs_error_handler');*/
281
+
282
+ function fs_nonce_url( $actionurl, $action = - 1, $name = '_wpnonce' ) {
283
+ // $actionurl = str_replace( '&amp;', '&', $actionurl );
284
+ return add_query_arg( $name, wp_create_nonce( $action ), $actionurl );
285
+ }
286
+
287
+ if ( ! function_exists( 'fs_starts_with' ) ) {
288
+ /**
289
+ * Check if string starts with.
290
+ *
291
+ * @author Vova Feldman (@svovaf)
292
+ * @since 1.1.3
293
+ *
294
+ * @param string $haystack
295
+ * @param string $needle
296
+ *
297
+ * @return bool
298
+ */
299
+ function fs_starts_with( $haystack, $needle ) {
300
+ $length = strlen( $needle );
301
+
302
+ return ( substr( $haystack, 0, $length ) === $needle );
303
+ }
304
+ }
305
+
306
+ #region Url Canonization ------------------------------------------------------------------
307
+
308
+ if ( ! function_exists( 'fs_canonize_url' ) ) {
309
+ /**
310
+ * @author Vova Feldman (@svovaf)
311
+ * @since 1.1.3
312
+ *
313
+ * @param string $url
314
+ * @param bool $omit_host
315
+ * @param array $ignore_params
316
+ *
317
+ * @return string
318
+ */
319
+ function fs_canonize_url( $url, $omit_host = false, $ignore_params = array() ) {
320
+ $parsed_url = parse_url( strtolower( $url ) );
321
+
322
+ // if ( ! isset( $parsed_url['host'] ) ) {
323
+ // return $url;
324
+ // }
325
+
326
+ $canonical = ( ( $omit_host || ! isset( $parsed_url['host'] ) ) ? '' : $parsed_url['host'] ) . $parsed_url['path'];
327
+
328
+ if ( isset( $parsed_url['query'] ) ) {
329
+ parse_str( $parsed_url['query'], $queryString );
330
+ $canonical .= '?' . fs_canonize_query_string( $queryString, $ignore_params );
331
+ }
332
+
333
+ return $canonical;
334
+ }
335
+ }
336
+
337
+ if ( ! function_exists( 'fs_canonize_query_string' ) ) {
338
+ /**
339
+ * @author Vova Feldman (@svovaf)
340
+ * @since 1.1.3
341
+ *
342
+ * @param array $params
343
+ * @param array $ignore_params
344
+ * @param bool $params_prefix
345
+ *
346
+ * @return string
347
+ */
348
+ function fs_canonize_query_string( array $params, array &$ignore_params, $params_prefix = false ) {
349
+ if ( ! is_array( $params ) || 0 === count( $params ) ) {
350
+ return '';
351
+ }
352
+
353
+ // Urlencode both keys and values
354
+ $keys = fs_urlencode_rfc3986( array_keys( $params ) );
355
+ $values = fs_urlencode_rfc3986( array_values( $params ) );
356
+ $params = array_combine( $keys, $values );
357
+
358
+ // Parameters are sorted by name, using lexicographical byte value ordering.
359
+ // Ref: Spec: 9.1.1 (1)
360
+ uksort( $params, 'strcmp' );
361
+
362
+ $pairs = array();
363
+ foreach ( $params as $parameter => $value ) {
364
+ $lower_param = strtolower( $parameter );
365
+
366
+ // Skip ignore params.
367
+ if ( in_array( $lower_param, $ignore_params ) || ( false !== $params_prefix && startsWith( $lower_param, $params_prefix ) ) ) {
368
+ continue;
369
+ }
370
+
371
+ if ( is_array( $value ) ) {
372
+ // If two or more parameters share the same name, they are sorted by their value
373
+ // Ref: Spec: 9.1.1 (1)
374
+ natsort( $value );
375
+ foreach ( $value as $duplicate_value ) {
376
+ $pairs[] = $lower_param . '=' . $duplicate_value;
377
+ }
378
+ } else {
379
+ $pairs[] = $lower_param . '=' . $value;
380
+ }
381
+ }
382
+
383
+ if ( 0 === count( $pairs ) ) {
384
+ return '';
385
+ }
386
+
387
+ return implode( "&", $pairs );
388
+ }
389
+ }
390
+
391
+ if ( ! function_exists( 'fs_urlencode_rfc3986' ) ) {
392
+ /**
393
+ * @author Vova Feldman (@svovaf)
394
+ * @since 1.1.3
395
+ *
396
+ * @param string|string[] $input
397
+ *
398
+ * @return array|mixed|string
399
+ */
400
+ function fs_urlencode_rfc3986( $input ) {
401
+ if ( is_array( $input ) ) {
402
+ return array_map( 'fs_urlencode_rfc3986', $input );
403
+ } else if ( is_scalar( $input ) ) {
404
+ return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $input ) ) );
405
+ }
406
+
407
+ return '';
408
+ }
409
+ }
410
+
411
+ #endregion Url Canonization ------------------------------------------------------------------
412
+
413
+ function fs_download_image( $from, $to ) {
414
+ $ch = curl_init( $from );
415
+ $fp = fopen( fs_normalize_path( $to ), 'wb' );
416
+ curl_setopt( $ch, CURLOPT_FILE, $fp );
417
+ curl_setopt( $ch, CURLOPT_HEADER, 0 );
418
+ curl_exec( $ch );
419
+ curl_close( $ch );
420
+ fclose( $fp );
421
+ }
422
+
423
+ /* General Utilities
424
+ --------------------------------------------------------------------------------------------*/
425
+
426
+ /**
427
+ * Sorts an array by the value of the priority key.
428
+ *
429
+ * @author Daniel Iser (@danieliser)
430
+ * @since 1.1.7
431
+ *
432
+ * @param $a
433
+ * @param $b
434
+ *
435
+ * @return int
436
+ */
437
+ function fs_sort_by_priority( $a, $b ) {
438
+
439
+ // If b has a priority and a does not, b wins.
440
+ if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) {
441
+ return 1;
442
+ } // If b has a priority and a does not, b wins.
443
+ elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) {
444
+ return - 1;
445
+ } // If neither has a priority or both priorities are equal its a tie.
446
+ elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) {
447
+ return 0;
448
+ }
449
+
450
+ // If both have priority return the winner.
451
+ return ( $a['priority'] < $b['priority'] ) ? - 1 : 1;
452
+ }
453
+
freemius/includes/fs-essential-functions.php ADDED
@@ -0,0 +1,412 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.5
7
+ */
8
+
9
+ if ( ! function_exists( 'fs_normalize_path' ) ) {
10
+ if ( function_exists( 'wp_normalize_path' ) ) {
11
+ /**
12
+ * Normalize a filesystem path.
13
+ *
14
+ * Replaces backslashes with forward slashes for Windows systems, and ensures
15
+ * no duplicate slashes exist.
16
+ *
17
+ * @param string $path Path to normalize.
18
+ *
19
+ * @return string Normalized path.
20
+ */
21
+ function fs_normalize_path( $path ) {
22
+ return wp_normalize_path( $path );
23
+ }
24
+ } else {
25
+ function fs_normalize_path( $path ) {
26
+ $path = str_replace( '\\', '/', $path );
27
+ $path = preg_replace( '|/+|', '/', $path );
28
+
29
+ return $path;
30
+ }
31
+ }
32
+ }
33
+
34
+ #region Core Redirect (copied from BuddyPress) -----------------------------------------
35
+
36
+ if ( ! function_exists( 'fs_redirect' ) ) {
37
+ /**
38
+ * Redirects to another page, with a workaround for the IIS Set-Cookie bug.
39
+ *
40
+ * @link http://support.microsoft.com/kb/q176113/
41
+ * @since 1.5.1
42
+ * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
43
+ *
44
+ * @param string $location The path to redirect to
45
+ * @param int $status Status code to use
46
+ *
47
+ * @return bool False if $location is not set
48
+ */
49
+ function fs_redirect( $location, $status = 302 ) {
50
+ global $is_IIS;
51
+
52
+ if ( headers_sent() ) {
53
+ return false;
54
+ }
55
+
56
+ if ( ! $location ) // allows the wp_redirect filter to cancel a redirect
57
+ {
58
+ return false;
59
+ }
60
+
61
+ $location = fs_sanitize_redirect( $location );
62
+
63
+ if ( $is_IIS ) {
64
+ header( "Refresh: 0;url=$location" );
65
+ } else {
66
+ if ( php_sapi_name() != 'cgi-fcgi' ) {
67
+ status_header( $status );
68
+ } // This causes problems on IIS and some FastCGI setups
69
+ header( "Location: $location" );
70
+ }
71
+
72
+ return true;
73
+ }
74
+
75
+ if ( ! function_exists( 'fs_sanitize_redirect' ) ) {
76
+ /**
77
+ * Sanitizes a URL for use in a redirect.
78
+ *
79
+ * @since 2.3
80
+ *
81
+ * @param string $location
82
+ *
83
+ * @return string redirect-sanitized URL
84
+ */
85
+ function fs_sanitize_redirect( $location ) {
86
+ $location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location );
87
+ $location = fs_kses_no_null( $location );
88
+
89
+ // remove %0d and %0a from location
90
+ $strip = array( '%0d', '%0a' );
91
+ $found = true;
92
+ while ( $found ) {
93
+ $found = false;
94
+ foreach ( (array) $strip as $val ) {
95
+ while ( strpos( $location, $val ) !== false ) {
96
+ $found = true;
97
+ $location = str_replace( $val, '', $location );
98
+ }
99
+ }
100
+ }
101
+
102
+ return $location;
103
+ }
104
+ }
105
+
106
+ if ( ! function_exists( 'fs_kses_no_null' ) ) {
107
+ /**
108
+ * Removes any NULL characters in $string.
109
+ *
110
+ * @since 1.0.0
111
+ *
112
+ * @param string $string
113
+ *
114
+ * @return string
115
+ */
116
+ function fs_kses_no_null( $string ) {
117
+ $string = preg_replace( '/\0+/', '', $string );
118
+ $string = preg_replace( '/(\\\\0)+/', '', $string );
119
+
120
+ return $string;
121
+ }
122
+ }
123
+ }
124
+
125
+ #endregion Core Redirect (copied from BuddyPress) -----------------------------------------
126
+
127
+ if ( ! function_exists( '__fs' ) ) {
128
+ global $fs_text_overrides;
129
+
130
+ if ( ! isset( $fs_text_overrides ) ) {
131
+ $fs_text_overrides = array();
132
+ }
133
+
134
+ /**
135
+ * Retrieve a translated text by key.
136
+ *
137
+ * @author Vova Feldman (@svovaf)
138
+ * @since 1.1.4
139
+ *
140
+ * @param string $key
141
+ * @param string $slug
142
+ *
143
+ * @return string
144
+ *
145
+ * @global $fs_text , $fs_text_overrides
146
+ */
147
+ function __fs( $key, $slug = 'freemius' ) {
148
+ global $fs_text, $fs_text_overrides;
149
+
150
+ if ( ! isset( $fs_text ) ) {
151
+ require_once( ( defined( 'WP_FS__DIR_INCLUDES' ) ? WP_FS__DIR_INCLUDES : dirname( __FILE__ ) ) . '/i18n.php' );
152
+ }
153
+
154
+ if ( isset( $fs_text_overrides[ $slug ] ) ) {
155
+ if ( isset( $fs_text_overrides[ $slug ][ $key ] ) ) {
156
+ return $fs_text_overrides[ $slug ][ $key ];
157
+ }
158
+
159
+ $lower_key = strtolower( $key );
160
+ if ( isset( $fs_text_overrides[ $slug ][ $lower_key ] ) ) {
161
+ return $fs_text_overrides[ $slug ][ $lower_key ];
162
+ }
163
+ }
164
+
165
+ return isset( $fs_text[ $key ] ) ?
166
+ $fs_text[ $key ] :
167
+ $key;
168
+ }
169
+
170
+ /**
171
+ * Display a translated text by key.
172
+ *
173
+ * @author Vova Feldman (@svovaf)
174
+ * @since 1.1.4
175
+ *
176
+ * @param string $key
177
+ * @param string $slug
178
+ */
179
+ function _efs( $key, $slug = 'freemius' ) {
180
+ echo __fs( $key, $slug );
181
+ }
182
+
183
+ /**
184
+ * Override default i18n text phrases.
185
+ *
186
+ * @author Vova Feldman (@svovaf)
187
+ * @since 1.1.6
188
+ *
189
+ * @param string[] $key_value
190
+ * @param string $slug
191
+ *
192
+ * @global $fs_text_overrides
193
+ */
194
+ function fs_override_i18n( array $key_value, $slug = 'freemius' ) {
195
+ global $fs_text_overrides;
196
+
197
+ if ( ! isset( $fs_text_overrides[ $slug ] ) ) {
198
+ $fs_text_overrides[ $slug ] = array();
199
+ }
200
+
201
+ foreach ( $key_value as $key => $value ) {
202
+ $fs_text_overrides[ $slug ][ $key ] = $value;
203
+ }
204
+ }
205
+ }
206
+
207
+ if ( ! function_exists( 'fs_get_ip' ) ) {
208
+ /**
209
+ * Get client IP.
210
+ *
211
+ * @author Vova Feldman (@svovaf)
212
+ * @since 1.1.2
213
+ *
214
+ * @return string|null
215
+ */
216
+ function fs_get_ip() {
217
+ $fields = array(
218
+ 'HTTP_CF_CONNECTING_IP',
219
+ 'HTTP_CLIENT_IP',
220
+ 'HTTP_X_FORWARDED_FOR',
221
+ 'HTTP_X_FORWARDED',
222
+ 'HTTP_FORWARDED_FOR',
223
+ 'HTTP_FORWARDED',
224
+ 'REMOTE_ADDR',
225
+ );
226
+
227
+ foreach ( $fields as $ip_field ) {
228
+ if ( ! empty( $_SERVER[ $ip_field ] ) ) {
229
+ return $_SERVER[ $ip_field ];
230
+ }
231
+ }
232
+
233
+ return null;
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Leverage backtrace to find caller plugin main file path.
239
+ *
240
+ * @author Vova Feldman (@svovaf)
241
+ * @since 1.0.6
242
+ *
243
+ * @return string
244
+ */
245
+ function fs_find_caller_plugin_file() {
246
+ /**
247
+ * All the code below will be executed once on activation.
248
+ * If the user changes the main plugin's file name, the file_exists()
249
+ * will catch it.
250
+ */
251
+ if ( ! function_exists( 'get_plugins' ) ) {
252
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
253
+ }
254
+
255
+ $all_plugins = get_plugins();
256
+ $all_plugins_paths = array();
257
+
258
+ // Get active plugin's main files real full names (might be symlinks).
259
+ foreach ( $all_plugins as $relative_path => &$data ) {
260
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
261
+ }
262
+
263
+ $plugin_file = null;
264
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
265
+ if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
266
+ $plugin_file = $bt[ $i ]['file'];
267
+ break;
268
+ }
269
+ }
270
+
271
+ if ( is_null( $plugin_file ) ) {
272
+ // Throw an error to the developer in case of some edge case dev environment.
273
+ wp_die( __fs( 'failed-finding-main-path' ), __fs( 'error' ), array( 'back_link' => true ) );
274
+ }
275
+
276
+ return $plugin_file;
277
+ }
278
+
279
+ require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
280
+
281
+ /**
282
+ * Update SDK newest version reference.
283
+ *
284
+ * @author Vova Feldman (@svovaf)
285
+ * @since 1.1.6
286
+ *
287
+ * @param string $sdk_relative_path
288
+ * @param string|bool $plugin_file
289
+ *
290
+ * @global $fs_active_plugins
291
+ */
292
+ function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
293
+ global $fs_active_plugins;
294
+
295
+ if ( ! is_string( $plugin_file ) ) {
296
+ $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
297
+ }
298
+
299
+ $fs_active_plugins->newest = (object) array(
300
+ 'plugin_path' => $plugin_file,
301
+ 'sdk_path' => $sdk_relative_path,
302
+ 'version' => $fs_active_plugins->plugins[ $sdk_relative_path ]->version,
303
+ 'in_activation' => ! is_plugin_active( $plugin_file ),
304
+ 'timestamp' => time(),
305
+ );
306
+
307
+ // Update DB with latest SDK version and path.
308
+ update_option( 'fs_active_plugins', $fs_active_plugins );
309
+ }
310
+
311
+ /**
312
+ * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
313
+ *
314
+ * @author Vova Feldman (@svovaf)
315
+ * @since 1.1.6
316
+ *
317
+ * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
318
+ *
319
+ * @global $fs_active_plugins
320
+ */
321
+ function fs_newest_sdk_plugin_first() {
322
+ global $fs_active_plugins;
323
+
324
+ /**
325
+ * @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins).
326
+ *
327
+ * @link https://github.com/Freemius/wordpress-sdk/issues/26
328
+ */
329
+ // $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
330
+
331
+ $active_plugins = get_option( 'active_plugins' );
332
+ $newest_sdk_plugin_key = array_search( $fs_active_plugins->newest->plugin_path, $active_plugins );
333
+ if ( 0 == $newest_sdk_plugin_key ) {
334
+ // if it's 0 it's the first plugin already, no need to continue
335
+ return false;
336
+ }
337
+
338
+ array_splice( $active_plugins, $newest_sdk_plugin_key, 1 );
339
+ array_unshift( $active_plugins, $fs_active_plugins->newest->plugin_path );
340
+ update_option( 'active_plugins', $active_plugins );
341
+
342
+ return true;
343
+ }
344
+
345
+ /**
346
+ * Go over all Freemius SDKs in the system and find and "remember"
347
+ * the newest SDK which is associated with an active plugin.
348
+ *
349
+ * @author Vova Feldman (@svovaf)
350
+ * @since 1.1.6
351
+ *
352
+ * @global $fs_active_plugins
353
+ */
354
+ function fs_fallback_to_newest_active_sdk() {
355
+ global $fs_active_plugins;
356
+
357
+ $newest_sdk_data = null;
358
+ $newest_sdk_path = null;
359
+
360
+ foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
361
+ if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
362
+ ) {
363
+ // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
364
+ if ( ! is_plugin_active( $data->plugin_path ) ||
365
+ ! file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) )
366
+ ) {
367
+ unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
368
+
369
+ // No need to store the data since it will be stored in fs_update_sdk_newest_version()
370
+ // or explicitly with update_option().
371
+ } else {
372
+ $newest_sdk_data = $data;
373
+ $newest_sdk_path = $sdk_relative_path;
374
+ }
375
+ }
376
+ }
377
+
378
+ if ( is_null( $newest_sdk_data ) ) {
379
+ // Couldn't find any SDK reference.
380
+ $fs_active_plugins = new stdClass();
381
+ update_option( 'fs_active_plugins', $fs_active_plugins );
382
+ } else {
383
+ fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
384
+ }
385
+ }
386
+
387
+ #region Actions / Filters -----------------------------------------
388
+
389
+ /**
390
+ * Apply filter for specific plugin.
391
+ *
392
+ * @author Vova Feldman (@svovaf)
393
+ * @since 1.0.9
394
+ *
395
+ * @param string $slug Plugin slug
396
+ * @param string $tag The name of the filter hook.
397
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
398
+ *
399
+ * @return mixed The filtered value after all hooked functions are applied to it.
400
+ *
401
+ * @uses apply_filters()
402
+ */
403
+ function fs_apply_filter( $slug, $tag, $value ) {
404
+ $args = func_get_args();
405
+
406
+ return call_user_func_array( 'apply_filters', array_merge(
407
+ array( 'fs_' . $tag . '_' . $slug ),
408
+ array_slice( $args, 2 ) )
409
+ );
410
+ }
411
+
412
+ #endregion Actions / Filters -----------------------------------------
freemius/includes/fs-plugin-info-dialog.php ADDED
@@ -0,0 +1,936 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Plugin_Info_Dialog
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7
18
+ */
19
+ class FS_Plugin_Info_Dialog {
20
+ /**
21
+ * @since 1.1.7
22
+ *
23
+ * @var FS_Logger
24
+ */
25
+ private $_logger;
26
+
27
+ /**
28
+ * @since 1.1.7
29
+ *
30
+ * @var Freemius
31
+ */
32
+ private $_fs;
33
+
34
+ function __construct( Freemius $fs ) {
35
+ $this->_fs = $fs;
36
+
37
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $fs->get_slug() . '_info', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
38
+
39
+ // Remove default plugin information action.
40
+ remove_all_actions( 'install_plugins_pre_plugin-information' );
41
+
42
+ // Override action with custom plugins function for add-ons.
43
+ add_action( 'install_plugins_pre_plugin-information', array( &$this, 'install_plugin_information' ) );
44
+
45
+ // Override request for plugin information for Add-ons.
46
+ add_filter(
47
+ 'fs_plugins_api',
48
+ array( &$this, '_get_addon_info_filter' ),
49
+ WP_FS__DEFAULT_PRIORITY, 3 );
50
+ }
51
+
52
+ /**
53
+ * Generate add-on plugin information.
54
+ *
55
+ * @author Vova Feldman (@svovaf)
56
+ * @since 1.0.6
57
+ *
58
+ * @param array $data
59
+ * @param string $action
60
+ * @param object|null $args
61
+ *
62
+ * @return array|null
63
+ */
64
+ function _get_addon_info_filter( $data, $action = '', $args = null ) {
65
+ $this->_logger->entrance();
66
+
67
+ $parent_plugin_id = fs_request_get( 'parent_plugin_id', false );
68
+
69
+ if ( $this->_fs->get_id() != $parent_plugin_id ||
70
+ ( 'plugin_information' !== $action ) ||
71
+ ! isset( $args->slug )
72
+ ) {
73
+ return $data;
74
+ }
75
+
76
+ // Find add-on by slug.
77
+ $addons = $this->_fs->get_addons();
78
+ $selected_addon = false;
79
+ foreach ( $addons as $addon ) {
80
+ if ( $addon->slug == $args->slug ) {
81
+ $selected_addon = $addon;
82
+ break;
83
+ }
84
+ }
85
+
86
+ if ( false === $selected_addon ) {
87
+ return $data;
88
+ }
89
+
90
+ if ( ! isset( $selected_addon->info ) ) {
91
+ // Setup some default info.
92
+ $selected_addon->info = new stdClass();
93
+ $selected_addon->info->selling_point_0 = 'Selling Point 1';
94
+ $selected_addon->info->selling_point_1 = 'Selling Point 2';
95
+ $selected_addon->info->selling_point_2 = 'Selling Point 3';
96
+ $selected_addon->info->description = '<p>Tell your users all about your add-on</p>';
97
+ }
98
+
99
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
100
+
101
+ $data = $args;
102
+
103
+ $is_free = true;
104
+
105
+ // Load add-on pricing.
106
+ $has_pricing = false;
107
+ $has_features = false;
108
+ $plans = false;
109
+ $plans_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans.json" );
110
+ if ( ! isset( $plans_result->error ) ) {
111
+ $plans = $plans_result->plans;
112
+ if ( is_array( $plans ) ) {
113
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
114
+ $plans[ $i ] = new FS_Plugin_Plan( $plans[ $i ] );
115
+ $plan = $plans[ $i ];
116
+
117
+ $pricing_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/pricing.json" );
118
+ if ( ! isset( $pricing_result->error ) ) {
119
+ // Update plan's pricing.
120
+ $plan->pricing = $pricing_result->pricing;
121
+
122
+ if ( is_array( $plan->pricing ) && ! empty( $plan->pricing ) ) {
123
+ $is_free = false;
124
+
125
+ foreach ( $plan->pricing as &$pricing ) {
126
+ $pricing = new FS_Pricing( $pricing );
127
+ }
128
+ }
129
+
130
+ $has_pricing = true;
131
+ }
132
+
133
+ $features_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/features.json" );
134
+ if ( ! isset( $features_result->error ) &&
135
+ is_array( $features_result->features ) &&
136
+ 0 < count( $features_result->features )
137
+ ) {
138
+ // Update plan's pricing.
139
+ $plan->features = $features_result->features;
140
+
141
+ $has_features = true;
142
+ }
143
+ }
144
+ }
145
+ }
146
+
147
+ // Fetch latest version from Freemius.
148
+ $latest = $this->_fs->_fetch_latest_version( $selected_addon->id );
149
+
150
+ if ( ! $is_free ) {
151
+ // If paid add-on, then it's not on wordpress.org
152
+ $is_wordpress_org = false;
153
+ } else {
154
+ // If no versions found, then assume it's a .org plugin.
155
+ $is_wordpress_org = ( false === $latest );
156
+ }
157
+
158
+ if ( $is_wordpress_org ) {
159
+ $repo_data = FS_Plugin_Updater::_fetch_plugin_info_from_repository(
160
+ 'plugin_information', (object) array(
161
+ 'slug' => $selected_addon->slug,
162
+ 'is_ssl' => is_ssl(),
163
+ 'fields' => array(
164
+ 'banners' => true,
165
+ 'reviews' => true,
166
+ 'downloaded' => false,
167
+ 'active_installs' => true
168
+ )
169
+ ) );
170
+
171
+ if ( ! empty( $repo_data ) ) {
172
+ $data = $repo_data;
173
+ $data->wp_org_missing = false;
174
+ } else {
175
+ // Couldn't find plugin on .org.
176
+ $is_wordpress_org = false;
177
+
178
+ // Plugin is missing, not on Freemius nor WP.org.
179
+ $data->wp_org_missing = true;
180
+ }
181
+ }
182
+
183
+ if ( ! $is_wordpress_org ) {
184
+ $data->checkout_link = $this->_fs->checkout_url();
185
+ $data->fs_missing = ( false === $latest );
186
+
187
+ if ( $is_free ) {
188
+ $data->download_link = $this->_fs->_get_latest_download_local_url( $selected_addon->id );
189
+ }
190
+ }
191
+
192
+ if ( ! $is_wordpress_org ) {
193
+ // Fetch as much as possible info from local files.
194
+ $plugin_local_data = $this->_fs->get_plugin_data();
195
+ $data->name = $selected_addon->title;
196
+ $data->author = $plugin_local_data['Author'];
197
+ $view_vars = array( 'plugin' => $selected_addon );
198
+ $data->sections = array(
199
+ 'description' => fs_get_template( '/plugin-info/description.php', $view_vars ),
200
+ );
201
+
202
+ if ( ! empty( $selected_addon->info->banner_url ) ) {
203
+ $data->banners = array(
204
+ 'low' => $selected_addon->info->banner_url,
205
+ );
206
+ }
207
+
208
+ if ( ! empty( $selected_addon->info->screenshots ) ) {
209
+ $view_vars = array(
210
+ 'screenshots' => $selected_addon->info->screenshots,
211
+ 'plugin' => $selected_addon,
212
+ );
213
+ $data->sections['screenshots'] = fs_get_template( '/plugin-info/screenshots.php', $view_vars );
214
+ }
215
+
216
+ if ( is_object( $latest ) ) {
217
+ $data->version = $latest->version;
218
+ $data->last_updated = ! is_null( $latest->updated ) ? $latest->updated : $latest->created;
219
+ $data->requires = $latest->requires_platform_version;
220
+ $data->tested = $latest->tested_up_to_version;
221
+ } else {
222
+ // Add dummy version.
223
+ $data->version = '1.0.0';
224
+
225
+ // Add message to developer to deploy the plugin through Freemius.
226
+ }
227
+ }
228
+
229
+ if ( $has_pricing ) {
230
+ // Add plans to data.
231
+ $data->plans = $plans;
232
+
233
+ if ( $has_features ) {
234
+ $view_vars = array(
235
+ 'plans' => $plans,
236
+ 'plugin' => $selected_addon,
237
+ );
238
+ $data->sections['features'] = fs_get_template( '/plugin-info/features.php', $view_vars );
239
+ }
240
+ }
241
+
242
+ $data->is_paid = ! $is_free;
243
+ $data->external = ! $is_wordpress_org;
244
+
245
+ return $data;
246
+ }
247
+
248
+ /**
249
+ * @author Vova Feldman (@svovaf)
250
+ * @since 1.1.7
251
+ *
252
+ * @param FS_Plugin_Plan $plan
253
+ *
254
+ * @return string
255
+ */
256
+ private function get_billing_cycle( FS_Plugin_Plan $plan ) {
257
+ $billing_cycle = null;
258
+
259
+ if ( 1 === count( $plan->pricing ) && 1 == $plan->pricing[0]->licenses ) {
260
+ $pricing = $plan->pricing[0];
261
+ if ( isset( $pricing->annual_price ) ) {
262
+ $billing_cycle = 'annual';
263
+ } else if ( isset( $pricing->monthly_price ) ) {
264
+ $billing_cycle = 'monthly';
265
+ } else if ( isset( $pricing->lifetime_price ) ) {
266
+ $billing_cycle = 'lifetime';
267
+ }
268
+ } else {
269
+ foreach ( $plan->pricing as $pricing ) {
270
+ if ( isset( $pricing->annual_price ) ) {
271
+ $billing_cycle = 'annual';
272
+ } else if ( isset( $pricing->monthly_price ) ) {
273
+ $billing_cycle = 'monthly';
274
+ } else if ( isset( $pricing->lifetime_price ) ) {
275
+ $billing_cycle = 'lifetime';
276
+ }
277
+
278
+ if ( ! is_null( $billing_cycle ) ) {
279
+ break;
280
+ }
281
+ }
282
+ }
283
+
284
+ return $billing_cycle;
285
+ }
286
+
287
+ /**
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.1.7
290
+ *
291
+ * @param FS_Plugin_Plan $plan
292
+ * @param FS_Pricing $pricing
293
+ *
294
+ * @return float|null|string
295
+ */
296
+ private function get_price_tag( FS_Plugin_Plan $plan, FS_Pricing $pricing ) {
297
+ $price_tag = '';
298
+ if ( isset( $pricing->annual_price ) ) {
299
+ $price_tag = $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' );
300
+ } else if ( isset( $pricing->monthly_price ) ) {
301
+ $price_tag = $pricing->monthly_price . ' / mo';
302
+ } else if ( isset( $pricing->lifetime_price ) ) {
303
+ $price_tag = $pricing->lifetime_price;
304
+ }
305
+
306
+ return '$' . $price_tag;
307
+ }
308
+
309
+ /**
310
+ * @author Vova Feldman (@svovaf)
311
+ * @since 1.1.7
312
+ *
313
+ * @param object $api
314
+ * @param FS_Plugin_Plan|null $plan
315
+ *
316
+ * @return string
317
+ */
318
+ private function get_plugin_cta( $api, $plan = null ) {
319
+ if ( ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
320
+
321
+ if ( ! empty( $api->checkout_link ) && isset( $api->plans ) && 0 < is_array( $api->plans ) ) {
322
+ if ( is_null( $plan ) ) {
323
+ $plan = $api->plans[0];
324
+ }
325
+
326
+ return ' <a class="button button-primary right" href="' . $this->_fs->addon_checkout_url(
327
+ $plan->plugin_id,
328
+ $plan->pricing[0]->id,
329
+ $this->get_billing_cycle( $plan ),
330
+ $plan->has_trial()
331
+ ) . '" target="_parent">' .
332
+ ( ! $plan->has_trial() ?
333
+ __fs( 'purchase', $api->slug ) :
334
+ sprintf( __fs( 'start-free-x', $api->slug ), $this->get_trial_period( $plan ) )
335
+ ) .
336
+ '</a>';
337
+
338
+ // @todo Add Cart concept.
339
+ // echo ' <a class="button right" href="' . $status['url'] . '" target="_parent">' . __( 'Add to Cart' ) . '</a>';
340
+
341
+ } else if ( ! empty( $api->download_link ) ) {
342
+ $status = install_plugin_install_status( $api );
343
+
344
+
345
+ // Hosted on WordPress.org.
346
+ switch ( $status['status'] ) {
347
+ case 'install':
348
+ if ( $api->external &&
349
+ $this->_fs->is_org_repo_compliant() ||
350
+ ! $this->_fs->is_premium()
351
+ ) {
352
+ /**
353
+ * Add-on hosted on Freemius, not yet installed, and core
354
+ * plugin is wordpress.org compliant. Therefore, require a download
355
+ * since installing external plugins is not allowed by the wp.org guidelines.
356
+ */
357
+ return ' <a class="button button-primary right" href="' . esc_url( $api->download_link ) . '" target="_blank">' . __fs( 'download-latest', $api->slug ) . '</a>';
358
+ } else {
359
+ if ( $status['url'] ) {
360
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
361
+ }
362
+ }
363
+ break;
364
+ case 'update_available':
365
+ if ( $status['url'] ) {
366
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
367
+ }
368
+ break;
369
+ case 'newer_installed':
370
+ return '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';
371
+ break;
372
+ case 'latest_installed':
373
+ return '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
374
+ break;
375
+ }
376
+
377
+ }
378
+ }
379
+ }
380
+
381
+ /**
382
+ * @author Vova Feldman (@svovaf)
383
+ * @since 1.1.7
384
+ *
385
+ * @param FS_Plugin_Plan $plan
386
+ *
387
+ * @return string
388
+ */
389
+ private function get_trial_period( $plan ) {
390
+ $trial_period = (int) $plan->trial_period;
391
+
392
+ switch ( $trial_period ) {
393
+ case 30:
394
+ return 'month';
395
+ case 60:
396
+ return '2 months';
397
+ default:
398
+ return "{$plan->trial_period} days";
399
+ }
400
+ }
401
+
402
+ /**
403
+ * Display plugin information in dialog box form.
404
+ *
405
+ * Based on core install_plugin_information() function.
406
+ *
407
+ * @author Vova Feldman (@svovaf)
408
+ * @since 1.0.6
409
+ */
410
+ function install_plugin_information() {
411
+ global $tab;
412
+
413
+ if ( empty( $_REQUEST['plugin'] ) ) {
414
+ return;
415
+ }
416
+
417
+ $args = array(
418
+ 'slug' => wp_unslash( $_REQUEST['plugin'] ),
419
+ 'is_ssl' => is_ssl(),
420
+ 'fields' => array(
421
+ 'banners' => true,
422
+ 'reviews' => true,
423
+ 'downloaded' => false,
424
+ 'active_installs' => true
425
+ )
426
+ );
427
+
428
+ if ( is_array( $args ) ) {
429
+ $args = (object) $args;
430
+ }
431
+
432
+ if ( ! isset( $args->per_page ) ) {
433
+ $args->per_page = 24;
434
+ }
435
+
436
+ if ( ! isset( $args->locale ) ) {
437
+ $args->locale = get_locale();
438
+ }
439
+
440
+ $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args );
441
+
442
+ if ( is_wp_error( $api ) ) {
443
+ wp_die( $api );
444
+ }
445
+
446
+ $plugins_allowedtags = array(
447
+ 'a' => array(
448
+ 'href' => array(),
449
+ 'title' => array(),
450
+ 'target' => array(),
451
+ // Add image style for screenshots.
452
+ 'class' => array()
453
+ ),
454
+ 'style' => array(),
455
+ 'abbr' => array( 'title' => array() ),
456
+ 'acronym' => array( 'title' => array() ),
457
+ 'code' => array(),
458
+ 'pre' => array(),
459
+ 'em' => array(),
460
+ 'strong' => array(),
461
+ 'div' => array( 'class' => array() ),
462
+ 'span' => array( 'class' => array() ),
463
+ 'p' => array(),
464
+ 'ul' => array(),
465
+ 'ol' => array(),
466
+ 'li' => array( 'class' => array() ),
467
+ 'i' => array( 'class' => array() ),
468
+ 'h1' => array(),
469
+ 'h2' => array(),
470
+ 'h3' => array(),
471
+ 'h4' => array(),
472
+ 'h5' => array(),
473
+ 'h6' => array(),
474
+ 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
475
+ // 'table' => array(),
476
+ // 'td' => array(),
477
+ // 'tr' => array(),
478
+ // 'th' => array(),
479
+ // 'thead' => array(),
480
+ // 'tbody' => array(),
481
+ );
482
+
483
+ $plugins_section_titles = array(
484
+ 'description' => _x( 'Description', 'Plugin installer section title' ),
485
+ 'installation' => _x( 'Installation', 'Plugin installer section title' ),
486
+ 'faq' => _x( 'FAQ', 'Plugin installer section title' ),
487
+ 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
488
+ 'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
489
+ 'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
490
+ 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ),
491
+ );
492
+
493
+ // Sanitize HTML
494
+ // foreach ( (array) $api->sections as $section_name => $content ) {
495
+ // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
496
+ // }
497
+
498
+ foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
499
+ if ( isset( $api->$key ) ) {
500
+ $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
501
+ }
502
+ }
503
+
504
+ // Add after $api->slug is ready.
505
+ $plugins_section_titles['features'] = __fs( 'features-and-pricing', $api->slug );
506
+
507
+ $_tab = esc_attr( $tab );
508
+
509
+ $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
510
+ if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
511
+ $section_titles = array_keys( (array) $api->sections );
512
+ $section = array_shift( $section_titles );
513
+ }
514
+
515
+ iframe_header( __( 'Plugin Install' ) );
516
+
517
+ $_with_banner = '';
518
+
519
+ // var_dump($api->banners);
520
+ if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
521
+ $_with_banner = 'with-banner';
522
+ $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
523
+ $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
524
+ ?>
525
+ <style type="text/css">
526
+ #plugin-information-title.with-banner
527
+ {
528
+ background-image: url( <?php echo esc_url( $low ); ?> );
529
+ }
530
+
531
+ @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 )
532
+ {
533
+ #plugin-information-title.with-banner
534
+ {
535
+ background-image: url( <?php echo esc_url( $high ); ?> );
536
+ }
537
+ }
538
+ </style>
539
+ <?php
540
+ }
541
+
542
+ echo '<div id="plugin-information-scrollable">';
543
+ echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
544
+ echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
545
+
546
+ foreach ( (array) $api->sections as $section_name => $content ) {
547
+ if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
548
+ continue;
549
+ }
550
+
551
+ if ( isset( $plugins_section_titles[ $section_name ] ) ) {
552
+ $title = $plugins_section_titles[ $section_name ];
553
+ } else {
554
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
555
+ }
556
+
557
+ $class = ( $section_name === $section ) ? ' class="current"' : '';
558
+ $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) );
559
+ $href = esc_url( $href );
560
+ $san_section = esc_attr( $section_name );
561
+ echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
562
+ }
563
+
564
+ echo "</div>\n";
565
+
566
+ ?>
567
+ <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
568
+ <div class="fyi">
569
+ <?php if ( $api->is_paid ) : ?>
570
+ <?php if ( isset( $api->plans ) ) : ?>
571
+ <div class="plugin-information-pricing">
572
+ <?php foreach ( $api->plans as $plan ) : ?>
573
+ <?php
574
+ /**
575
+ * @var FS_Plugin_Plan $plan
576
+ */
577
+ ?>
578
+ <?php $first_pricing = $plan->pricing[0] ?>
579
+ <?php $is_multi_cycle = $first_pricing->is_multi_cycle() ?>
580
+ <div class="fs-plan<?php if ( ! $is_multi_cycle ) {
581
+ echo ' fs-single-cycle';
582
+ } ?>" data-plan-id="<?php echo $plan->id ?>">
583
+ <h3 data-plan="<?php echo $plan->id ?>"><?php printf( __fs( 'x-plan', $api->slug ), $plan->title ) ?></h3>
584
+ <?php $has_annual = $first_pricing->has_annual() ?>
585
+ <?php $has_monthly = $first_pricing->has_monthly() ?>
586
+ <div class="nav-tab-wrapper">
587
+ <?php $billing_cycles = array( 'monthly', 'annual', 'lifetime' ) ?>
588
+ <?php $i = 0;
589
+ foreach ( $billing_cycles as $cycle ) : ?>
590
+ <?php $prop = "{$cycle}_price";
591
+ if ( isset( $first_pricing->{$prop} ) ) : ?>
592
+ <?php $is_featured = ( 'annual' === $cycle && $is_multi_cycle ) ?>
593
+ <?php
594
+ $prices = array();
595
+ foreach ( $plan->pricing as $pricing ) {
596
+ if ( isset( $pricing->{$prop} ) ) {
597
+ $prices[] = array(
598
+ 'id' => $pricing->id,
599
+ 'licenses' => $pricing->licenses,
600
+ 'price' => $pricing->{$prop}
601
+ );
602
+ }
603
+ }
604
+ ?>
605
+ <a class="nav-tab" data-billing-cycle="<?php echo $cycle ?>"
606
+ data-pricing="<?php esc_attr_e( json_encode( $prices ) ) ?>">
607
+ <?php if ( $is_featured ) : ?>
608
+ <label>&#9733; <?php _efs( 'best', $api->slug ) ?> &#9733;</label>
609
+ <?php endif ?>
610
+ <?php _efs( $cycle, $api->slug ) ?>
611
+ </a>
612
+ <?php endif ?>
613
+ <?php $i ++; endforeach ?>
614
+ <?php wp_enqueue_script( 'jquery' ) ?>
615
+ <script type="text/javascript">
616
+ (function ($, undef) {
617
+ var
618
+ _formatBillingFrequency = function (cycle) {
619
+ switch (cycle) {
620
+ case 'monthly':
621
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('monthly', $api->slug)) ?>';
622
+ case 'annual':
623
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('annually', $api->slug)) ?>';
624
+ case 'lifetime':
625
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('once', $api->slug)) ?>';
626
+ }
627
+ },
628
+ _formatLicensesTitle = function (pricing) {
629
+ switch (pricing.licenses) {
630
+ case 1:
631
+ return '<?php _efs( 'license-single-site', $api->slug ) ?>';
632
+ case null:
633
+ return '<?php _efs( 'license-unlimited', $api->slug ) ?>';
634
+ default:
635
+ return '<?php _efs( 'license-x-sites', $api->slug ) ?>'.replace('%s', pricing.licenses);
636
+ }
637
+ },
638
+ _formatPrice = function (pricing, cycle, multipleLicenses) {
639
+ if (undef === multipleLicenses)
640
+ multipleLicenses = true;
641
+
642
+ var priceCycle;
643
+ switch (cycle) {
644
+ case 'monthly':
645
+ priceCycle = ' / <?php _efs('mo', $api->slug) ?>';
646
+ break;
647
+ case 'lifetime':
648
+ priceCycle = '';
649
+ break;
650
+ case 'annual':
651
+ default:
652
+ priceCycle = ' / <?php _efs('year', $api->slug) ?>';
653
+ break;
654
+ }
655
+
656
+ if (!multipleLicenses && 1 == pricing.licenses) {
657
+ return '$' + pricing.price + priceCycle;
658
+ }
659
+
660
+ return _formatLicensesTitle(pricing) + ' - <var class="fs-price">$' + pricing.price + priceCycle + '</var>';
661
+ },
662
+ _checkoutUrl = function (plan, pricing, cycle) {
663
+ return '<?php echo esc_url_raw(remove_query_arg('billing_cycle', add_query_arg(array('plugin_id' => $plan->plugin_id), $api->checkout_link))) ?>' +
664
+ '&plan_id=' + plan +
665
+ '&pricing_id=' + pricing +
666
+ '&billing_cycle=' + cycle<?php if ($plan->has_trial()) { echo " + '&trial=true'"; }?>;
667
+ },
668
+ _updateCtaUrl = function (plan, pricing, cycle) {
669
+ $('.plugin-information-pricing .button, #plugin-information-footer .button').attr('href', _checkoutUrl(plan, pricing, cycle));
670
+ };
671
+
672
+ $(document).ready(function () {
673
+ var $plan = $('.plugin-information-pricing .fs-plan[data-plan-id=<?php echo $plan->id ?>]');
674
+ $plan.find('input[type=radio]').live('click', function () {
675
+ _updateCtaUrl(
676
+ $plan.attr('data-plan-id'),
677
+ $(this).val(),
678
+ $plan.find('.nav-tab-active').attr('data-billing-cycle')
679
+ );
680
+
681
+ $plan.find('.fs-trial-terms .fs-price').html(
682
+ $(this).parents('label').find('.fs-price').html()
683
+ );
684
+ });
685
+
686
+ $plan.find('.nav-tab').click(function () {
687
+ if ($(this).hasClass('nav-tab-active'))
688
+ return;
689
+
690
+ var $this = $(this),
691
+ billingCycle = $this.attr('data-billing-cycle'),
692
+ pricing = JSON.parse($this.attr('data-pricing')),
693
+ $pricesList = $this.parents('.fs-plan').find('.fs-pricing-body .fs-licenses'),
694
+ html = '';
695
+
696
+ // Un-select previously selected tab.
697
+ $plan.find('.nav-tab').removeClass('nav-tab-active');
698
+
699
+ // Select current tab.
700
+ $this.addClass('nav-tab-active');
701
+
702
+ // Render licenses prices.
703
+ if (1 == pricing.length) {
704
+ html = '<li><label><?php _efs( 'price', $api->slug ) ?>: ' + _formatPrice(pricing[0], billingCycle, false) + '</label></li>';
705
+ } else {
706
+ for (var i = 0; i < pricing.length; i++) {
707
+ html += '<li><label><input name="pricing-<?php echo $plan->id ?>" type="radio" value="' + pricing[i].id + '">' + _formatPrice(pricing[i], billingCycle) + '</label></li>';
708
+ }
709
+ }
710
+ $pricesList.html(html);
711
+
712
+ if (1 < pricing.length) {
713
+ // Select first license option.
714
+ $pricesList.find('li:first input').click();
715
+ }
716
+ else {
717
+ _updateCtaUrl(
718
+ $plan.attr('data-plan-id'),
719
+ pricing[0].id,
720
+ billingCycle
721
+ );
722
+ }
723
+
724
+ // Update billing frequency.
725
+ $plan.find('.fs-billing-frequency').html(_formatBillingFrequency(billingCycle));
726
+
727
+ if ('annual' === billingCycle) {
728
+ $plan.find('.fs-annual-discount').show();
729
+ } else {
730
+ $plan.find('.fs-annual-discount').hide();
731
+ }
732
+ });
733
+
734
+ <?php if ( $has_annual ) : ?>
735
+ // Select annual by default.
736
+ $plan.find('.nav-tab[data-billing-cycle=annual]').click();
737
+ <?php else : ?>
738
+ // Select first tab.
739
+ $plan.find('.nav-tab:first').click();
740
+ <?php endif ?>
741
+ });
742
+ }(jQuery));
743
+ </script>
744
+ </div>
745
+ <div class="fs-pricing-body">
746
+ <span class="fs-billing-frequency"></span>
747
+ <?php $annual_discount = ( $has_annual && $has_monthly ) ? $plan->pricing[0]->annual_discount_percentage() : 0 ?>
748
+ <?php if ( $annual_discount > 0 ) : ?>
749
+ <span
750
+ class="fs-annual-discount"><?php printf( __fs( 'save-x', $api->slug ), $annual_discount . '%' ) ?></span>
751
+ <?php endif ?>
752
+ <ul class="fs-licenses">
753
+ </ul>
754
+ <?php echo $this->get_plugin_cta( $api, $plan ) ?>
755
+ <div style="clear:both"></div>
756
+ <?php if ( $plan->has_trial() ) : ?>
757
+ <?php $trial_period = $this->get_trial_period( $plan ) ?>
758
+ <ul class="fs-trial-terms">
759
+ <li>
760
+ <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'no-commitment-x', $api->slug ), $trial_period ) ?>
761
+ </li>
762
+ <li>
763
+ <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'after-x-pay-as-little-y', $api->slug ), $trial_period, '<var class="fs-price">' . $this->get_price_tag( $plan, $plan->pricing[0] ) . '</var>' ) ?>
764
+ </li>
765
+ </ul>
766
+ <?php endif ?>
767
+ </div>
768
+ </div>
769
+ </div>
770
+ <?php endforeach ?>
771
+ <?php endif ?>
772
+ <?php endif ?>
773
+ <div>
774
+ <h3><?php _efs( 'details', $api->slug ) ?></h3>
775
+ <ul>
776
+ <?php if ( ! empty( $api->version ) ) { ?>
777
+ <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
778
+ <?php
779
+ }
780
+ if ( ! empty( $api->author ) ) {
781
+ ?>
782
+ <li>
783
+ <strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?>
784
+ </li>
785
+ <?php
786
+ }
787
+ if ( ! empty( $api->last_updated ) ) {
788
+ ?>
789
+ <li><strong><?php _e( 'Last Updated:' ); ?></strong> <span
790
+ title="<?php echo $api->last_updated; ?>">
791
+ <?php printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); ?>
792
+ </span></li>
793
+ <?php
794
+ }
795
+ if ( ! empty( $api->requires ) ) {
796
+ ?>
797
+ <li>
798
+ <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?>
799
+ </li>
800
+ <?php
801
+ }
802
+ if ( ! empty( $api->tested ) ) {
803
+ ?>
804
+ <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?>
805
+ </li>
806
+ <?php
807
+ }
808
+ if ( ! empty( $api->downloaded ) ) {
809
+ ?>
810
+ <li>
811
+ <strong><?php _e( 'Downloaded:' ); ?></strong> <?php printf( _n( '%s time', '%s times', $api->downloaded ), number_format_i18n( $api->downloaded ) ); ?>
812
+ </li>
813
+ <?php
814
+ }
815
+ if ( ! empty( $api->slug ) && empty( $api->external ) ) {
816
+ ?>
817
+ <li><a target="_blank"
818
+ href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a>
819
+ </li>
820
+ <?php
821
+ }
822
+ if ( ! empty( $api->homepage ) ) {
823
+ ?>
824
+ <li><a target="_blank"
825
+ href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a>
826
+ </li>
827
+ <?php
828
+ }
829
+ if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) {
830
+ ?>
831
+ <li><a target="_blank"
832
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
833
+ </li>
834
+ <?php } ?>
835
+ </ul>
836
+ </div>
837
+ <?php if ( ! empty( $api->rating ) ) { ?>
838
+ <h3><?php _e( 'Average Rating' ); ?></h3>
839
+ <?php wp_star_rating( array(
840
+ 'rating' => $api->rating,
841
+ 'type' => 'percent',
842
+ 'number' => $api->num_ratings
843
+ ) ); ?>
844
+ <small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small>
845
+ <?php
846
+ }
847
+
848
+ if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
849
+ foreach ( $api->ratings as $key => $ratecount ) {
850
+ // Avoid div-by-zero.
851
+ $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
852
+ ?>
853
+ <div class="counter-container">
854
+ <span class="counter-label"><a
855
+ href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>"
856
+ target="_blank"
857
+ title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span>
858
+ <span class="counter-back">
859
+ <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
860
+ </span>
861
+ <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span>
862
+ </div>
863
+ <?php
864
+ }
865
+ }
866
+ if ( ! empty( $api->contributors ) ) {
867
+ ?>
868
+ <h3><?php _e( 'Contributors' ); ?></h3>
869
+ <ul class="contributors">
870
+ <?php
871
+ foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
872
+ if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
873
+ continue;
874
+ }
875
+ if ( empty( $contrib_username ) ) {
876
+ $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
877
+ }
878
+ $contrib_username = sanitize_user( $contrib_username );
879
+ if ( empty( $contrib_profile ) ) {
880
+ echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</li>";
881
+ } else {
882
+ echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</a></li>";
883
+ }
884
+ }
885
+ ?>
886
+ </ul>
887
+ <?php if ( ! empty( $api->donate_link ) ) { ?>
888
+ <a target="_blank"
889
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
890
+ <?php } ?>
891
+ <?php } ?>
892
+ </div>
893
+ <div id="section-holder" class="wrap">
894
+ <?php
895
+ if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
896
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been tested with your current version of WordPress.' ) . '</p></div>';
897
+ } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
898
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been marked as compatible with your version of WordPress.' ) . '</p></div>';
899
+ }
900
+
901
+ foreach ( (array) $api->sections as $section_name => $content ) {
902
+ $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
903
+ $content = links_add_target( $content, '_blank' );
904
+
905
+ $san_section = esc_attr( $section_name );
906
+
907
+ $display = ( $section_name === $section ) ? 'block' : 'none';
908
+
909
+ if ( 'description' === $section_name &&
910
+ ( ( ! $api->external && $api->wp_org_missing ) ||
911
+ ( $api->external && $api->fs_missing ) )
912
+ ) {
913
+ $missing_notice = array(
914
+ 'type' => 'error',
915
+ 'id' => md5( microtime() ),
916
+ 'message' => __fs( ( $api->is_paid ? 'paid-addon-not-deployed' : 'free-addon-not-deployed' ), $api->slug ),
917
+ );
918
+ fs_require_template( 'admin-notice.php', $missing_notice );
919
+ }
920
+ echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
921
+ echo $content;
922
+ echo "\t</div>\n";
923
+ }
924
+ echo "</div>\n";
925
+ echo "</div>\n";
926
+ echo "</div>\n"; // #plugin-information-scrollable
927
+ echo "<div id='$tab-footer'>\n";
928
+
929
+ echo $this->get_plugin_cta( $api );
930
+
931
+ echo "</div>\n";
932
+
933
+ iframe_footer();
934
+ exit;
935
+ }
936
+ }
freemius/includes/i18n.php ADDED
@@ -0,0 +1,384 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * All strings can now be overridden.
15
+ *
16
+ * For example, if we want to override:
17
+ * 'you-are-step-away' => 'You are just one step away - %s',
18
+ *
19
+ * We can use the filter:
20
+ * fs_override_i18n( array(
21
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
22
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
23
+ * ), '{plugin_slug}' );
24
+ *
25
+ * Or with the Freemius instance:
26
+ *
27
+ * my_freemius->override_i18n( array(
28
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
29
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
30
+ * );
31
+ */
32
+ global $fs_text;
33
+
34
+ $fs_text = array(
35
+ 'account' => __( 'Account', 'freemius' ),
36
+ 'addon' => __( 'Add On', 'freemius' ),
37
+ 'contact-us' => __( 'Contact Us', 'freemius' ),
38
+ 'contact-support' => __( 'Contact Support', 'freemius' ),
39
+ 'change-ownership' => __( 'Change Ownership', 'freemius' ),
40
+ 'support' => __( 'Support', 'freemius' ),
41
+ 'support-forum' => __( 'Support Forum', 'freemius' ),
42
+ 'add-ons' => __( 'Add Ons', 'freemius' ),
43
+ 'upgrade' => _x( 'Upgrade', 'verb', 'freemius' ),
44
+ 'awesome' => __( 'Awesome', 'freemius' ),
45
+ 'pricing' => _x( 'Pricing', 'noun', 'freemius' ),
46
+ 'price' => _x( 'Price', 'noun', 'freemius' ),
47
+ 'unlimited-updates' => __( 'Unlimited Updates', 'freemius' ),
48
+ 'downgrade' => _x( 'Downgrade', 'verb', 'freemius' ),
49
+ 'cancel-trial' => __( 'Cancel Trial', 'freemius' ),
50
+ 'free-trial' => __( 'Free Trial', 'freemius' ),
51
+ 'start-free-x' => __( 'Start my free %s', 'freemius' ),
52
+ 'no-commitment-x' => __( 'No commitment for %s - cancel anytime', 'freemius' ),
53
+ 'after-x-pay-as-little-y' => __( 'After your free %s, pay as little as %s', 'freemius' ),
54
+ 'details' => __( 'Details', 'freemius' ),
55
+ 'account-details' => __( 'Account Details', 'freemius' ),
56
+ 'delete' => _x( 'Delete', 'verb', 'freemius' ),
57
+ 'show' => _x( 'Show', 'verb', 'freemius' ),
58
+ 'hide' => _x( 'Hide', 'verb', 'freemius' ),
59
+ 'edit' => _x( 'Edit', 'verb', 'freemius' ),
60
+ 'date' => __( 'Date', 'freemius' ),
61
+ 'amount' => __( 'Amount', 'freemius' ),
62
+ 'invoice' => __( 'Invoice', 'freemius' ),
63
+ 'billing' => __( 'Billing', 'freemius' ),
64
+ 'payments' => __( 'Payments', 'freemius' ),
65
+ 'delete-account' => __( 'Delete Account', 'freemius' ),
66
+ 'dismiss' => _x( 'Dismiss', 'as close a window', 'freemius' ),
67
+ 'plan' => _x( 'Plan', 'as product pricing plan', 'freemius' ),
68
+ 'change-plan' => __( 'Change Plan', 'freemius' ),
69
+ 'download-x-version' => _x( 'Download %s Version', 'as download professional version', 'freemius' ),
70
+ 'download-x-version-now' => _x( 'Download %s version now', 'as download professional version now', 'freemius' ),
71
+ 'download-latest' => _x( 'Download Latest', 'as download latest version', 'freemius' ),
72
+ 'you-have-x-license' => _x( 'You have a %s license.', 'E.g. you have a professional license.', 'freemius' ),
73
+ 'new' => __( 'New', 'freemius' ),
74
+ 'free' => __( 'Free', 'freemius' ),
75
+ 'trial' => _x( 'Trial', 'as trial plan', 'freemius' ),
76
+ 'purchase' => _x( 'Purchase', 'verb', 'freemius' ),
77
+ 'purchase-license' => __( 'Purchase License', 'freemius' ),
78
+ 'buy' => _x( 'Buy', 'verb', 'freemius' ),
79
+ 'buy-license' => __( 'Buy License', 'freemius' ),
80
+ 'license-single-site' => __( 'Single Site License', 'freemius' ),
81
+ 'license-unlimited' => __( 'Unlimited Licenses', 'freemius' ),
82
+ 'license-x-sites' => __( 'Up to %s Sites', 'freemius' ),
83
+ 'renew-license-now' => __( '%sRenew your license now%s to access version %s features and support.', 'freemius' ),
84
+ 'ask-for-upgrade-email-address' => __( "Enter the email address you've used for the upgrade below and we will resend you the license key.", 'freemius' ),
85
+ 'x-plan' => _x( '%s Plan', 'e.g. Professional Plan', 'freemius' ),
86
+ 'you-are-step-away' => __( 'You are just one step away - %s', 'freemius' ),
87
+ 'activate-x-now' => _x( 'Complete "%s" Activation Now', '%s - plugin name. As complete "Jetpack" activation now', 'freemius' ),
88
+ 'few-plugin-tweaks' => __( 'We made a few tweaks to the plugin, %s', 'freemius' ),
89
+ 'optin-x-now' => __( 'Opt-in to make "%s" Better!', 'freemius' ),
90
+ 'error' => __( 'Error', 'freemius' ),
91
+ 'failed-finding-main-path' => __( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'freemius' ),
92
+ #region Account
93
+
94
+ 'expiration' => _x( 'Expiration', 'as expiration date', 'freemius' ),
95
+ 'license' => _x( 'License', 'as software license', 'freemius' ),
96
+ 'not-verified' => __( 'not verified', 'freemius' ),
97
+ 'verify-email' => __( 'Verify Email', 'freemius' ),
98
+ 'expires-in' => _x( 'Expires in %s', 'e.g. expires in 2 months', 'freemius' ),
99
+ 'renews-in' => _x( 'Auto renews in %s', 'e.g. auto renews in 2 months', 'freemius' ),
100
+ 'no-expiration' => __( 'No expiration', 'freemius' ),
101
+ 'expired' => __( 'Expired', 'freemius' ),
102
+ 'cancelled' => __( 'Cancelled', 'freemius' ),
103
+ 'in-x' => _x( 'In %s', 'e.g. In 2 hours', 'freemius' ),
104
+ 'x-ago' => _x( '%s ago', 'e.g. 2 min ago', 'freemius' ),
105
+ 'version' => _x( 'Version', 'as plugin version', 'freemius' ),
106
+ 'name' => __( 'Name', 'freemius' ),
107
+ 'email' => __( 'Email', 'freemius' ),
108
+ 'email-address' => __( 'Email address', 'freemius' ),
109
+ 'verified' => __( 'Verified', 'freemius' ),
110
+ 'plugin' => __( 'Plugin', 'freemius' ),
111
+ 'plugins' => __( 'Plugins', 'freemius' ),
112
+ 'themes' => __( 'Themes', 'freemius' ),
113
+ 'path' => _x( 'Path', 'as file/folder path', 'freemius' ),
114
+ 'title' => __( 'Title', 'freemius' ),
115
+ 'free-version' => __( 'Free version', 'freemius' ),
116
+ 'premium-version' => __( 'Premium version', 'freemius' ),
117
+ 'slug' => _x( 'Slug', 'as WP plugin slug', 'freemius' ),
118
+ 'id' => __( 'ID', 'freemius' ),
119
+ 'users' => __( 'Users', 'freemius' ),
120
+ 'plugin-installs' => __( 'Plugin Installs', 'freemius' ),
121
+ 'sites' => _x( 'Sites', 'like websites', 'freemius' ),
122
+ 'user-id' => __( 'User ID', 'freemius' ),
123
+ 'site-id' => __( 'Site ID', 'freemius' ),
124
+ 'public-key' => __( 'Public Key', 'freemius' ),
125
+ 'secret-key' => __( 'Secret Key', 'freemius' ),
126
+ 'no-secret' => _x( 'No Secret', 'as secret encryption key missing', 'freemius' ),
127
+ 'no-id' => __( 'No ID', 'freemius' ),
128
+ 'sync-license' => _x( 'Sync License', 'as synchronize license', 'freemius' ),
129
+ 'sync' => _x( 'Sync', 'as synchronize', 'freemius' ),
130
+ 'activate-license' => __( 'Activate License', 'freemius' ),
131
+ 'activate-free-version' => __( 'Activate Free Version', 'freemius' ),
132
+ 'activate-license-message' => __( 'Please enter the license key that you received in the email right after the purchase:', 'freemius' ),
133
+ 'activating-license' => __( 'Activating license...', 'freemius' ),
134
+ 'change-license' => __( 'Change License', 'freemius' ),
135
+ 'update-license' => __( 'Update License', 'freemius' ),
136
+ 'deactivate-license' => __( 'Deactivate License', 'freemius' ),
137
+ 'activate' => __( 'Activate', 'freemius' ),
138
+ 'deactivate' => __( 'Deactivate', 'freemius' ),
139
+ 'skip-deactivate' => __( 'Skip & Deactivate', 'freemius' ),
140
+ 'no-deactivate' => __( 'No - just deactivate', 'freemius' ),
141
+ 'yes-do-your-thing' => __( 'Yes - do your thing', 'freemius' ),
142
+ 'active' => _x( 'Active', 'active mode', 'freemius' ),
143
+ 'is-active' => _x( 'Is Active', 'is active mode?', 'freemius' ),
144
+ 'install-now' => __( 'Install Now', 'freemius' ),
145
+ 'install-update-now' => __( 'Install Update Now', 'freemius' ),
146
+ 'more-information-about-x' => __( 'More information about %s', 'freemius' ),
147
+ 'localhost' => __( 'Localhost', 'freemius' ),
148
+ 'activate-x-plan' => _x( 'Activate %s Plan', 'as activate Professional plan', 'freemius' ),
149
+ 'x-left' => _x( '%s left', 'as 5 licenses left', 'freemius' ),
150
+ 'last-license' => __( 'Last license', 'freemius' ),
151
+ 'what-is-your-x' => __( 'What is your %s?', 'freemius' ),
152
+ 'activate-this-addon' => __( 'Activate this add-on', 'freemius' ),
153
+ 'deactivate-license-confirm' => __( 'Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?', 'freemius' ),
154
+ 'delete-account-x-confirm' => __( 'Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the "Cancel" button, and first "Downgrade" your account. Are you sure you would like to continue with the deletion?', 'freemius' ),
155
+ 'delete-account-confirm' => __( 'Deletion is not temporary. Only delete if you no longer want to use this plugin anymore. Are you sure you would like to continue with the deletion?', 'freemius' ),
156
+ 'downgrade-x-confirm' => __( 'Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s.', 'freemius' ),
157
+ 'cancel-trial-confirm' => __( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'freemius' ),
158
+ 'after-downgrade-non-blocking' => __( 'You can still enjoy all %s features but you will not have access to plugin updates and support.', 'freemius' ),
159
+ 'after-downgrade-blocking' => __( 'Once your license expire you can still use the Free version but you will NOT have access to the %s features.', 'freemius' ),
160
+ 'proceed-confirmation' => __( 'Are you sure you want to proceed?', 'freemius' ),
161
+ #endregion Account
162
+
163
+ 'add-ons-for-x' => __( 'Add Ons for %s', 'freemius' ),
164
+ 'add-ons-missing' => __( 'We could\'nt load the add-ons list. It\'s probably an issue on our side, please try to come back in few minutes.', 'freemius' ),
165
+ #region Plugin Deactivation
166
+ 'deactivation-share-reason' => __( 'If you have a moment, please let us know why you are deactivating', 'freemius' ),
167
+ 'deactivation-modal-button-confirm' => __( 'Yes - Deactivate', 'freemius' ),
168
+ 'deactivation-modal-button-submit' => __( 'Submit & Deactivate', 'freemius' ),
169
+ 'deactivation-modal-button-cancel' => _x( 'Cancel', 'the text of the cancel button of the plugin deactivation dialog box.', 'freemius' ),
170
+ 'reason-no-longer-needed' => __( 'I no longer need the plugin', 'freemius' ),
171
+ 'reason-found-a-better-plugin' => __( 'I found a better plugin', 'freemius' ),
172
+ 'reason-needed-for-a-short-period' => __( 'I only needed the plugin for a short period', 'freemius' ),
173
+ 'reason-broke-my-site' => __( 'The plugin broke my site', 'freemius' ),
174
+ 'reason-suddenly-stopped-working' => __( 'The plugin suddenly stopped working', 'freemius' ),
175
+ 'reason-cant-pay-anymore' => __( "I can't pay for it anymore", 'freemius' ),
176
+ 'reason-temporary-deactivation' => __( "It's a temporary deactivation. I'm just debugging an issue.", 'freemius' ),
177
+ 'reason-other' => _x( 'Other', 'the text of the "other" reason for deactivating the plugin that is shown in the modal box.', 'freemius' ),
178
+ 'ask-for-reason-message' => __( 'Kindly tell us the reason so we can improve.', 'freemius' ),
179
+ 'placeholder-plugin-name' => __( "What's the plugin's name?", 'freemius' ),
180
+ 'placeholder-comfortable-price' => __( 'What price would you feel comfortable paying?', 'freemius' ),
181
+ 'reason-couldnt-make-it-work' => __( "I couldn't understand how to make it work", 'freemius' ),
182
+ 'reason-great-but-need-specific-feature' => __( "The plugin is great, but I need specific feature that you don't support", 'freemius' ),
183
+ 'reason-not-working' => __( 'The plugin is not working', 'freemius' ),
184
+ 'reason-not-what-i-was-looking-for' => __( "It's not what I was looking for", 'freemius' ),
185
+ 'reason-didnt-work-as-expected' => __( "The plugin didn't work as expected", 'freemius' ),
186
+ 'placeholder-feature' => __( 'What feature?', 'freemius' ),
187
+ 'placeholder-share-what-didnt-work' => __( "Kindly share what didn't work so we can fix it for future users...", 'freemius' ),
188
+ 'placeholder-what-youve-been-looking-for' => __( "What you've been looking for?", 'freemius' ),
189
+ 'placeholder-what-did-you-expect' => __( "What did you expect?", 'freemius' ),
190
+ 'reason-didnt-work' => __( "The plugin didn't work", 'freemius' ),
191
+ 'reason-dont-like-to-share-my-information' => __( "I don't like to share my information with you", 'freemius' ),
192
+ 'dont-have-to-share-any-data' => __( "You might have missed it, but you don't have to share any data and can just %s the opt-in.", 'freemius' ),
193
+ #endregion Plugin Deactivation
194
+
195
+ #region Connect
196
+ 'hey-x' => _x( 'Hey %s,', 'greeting', 'freemius' ),
197
+ 'thanks-x' => _x( 'Thanks %s!', 'a greeting. E.g. Thanks John!', 'freemius' ),
198
+ 'connect-message' => __( 'In order to enjoy all our features and functionality, %s needs to connect your user, %s at %s, to %s', 'freemius' ),
199
+ 'connect-message_on-update' => __( 'Please help us improve %2$s! If you opt-in, some data about your usage of %2$s will be sent to %5$s. If you skip this, that\'s okay! %2$s will still work just fine.', 'freemius' ),
200
+ 'pending-activation-message' => __( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to complete the install.', 'freemius' ),
201
+ 'thanks-for-purchasing' => __( 'Thanks for purchasing %s! To get started, please enter your license key:', 'freemius' ),
202
+ 'license-sync-disclaimer' => __( 'The plugin will be periodically sending data to %s to check for plugin updates and verify the validity of your license.', 'freemius' ),
203
+ 'what-permissions' => __( 'What permissions are being granted?', 'freemius' ),
204
+ 'permissions-profile' => __( 'Your Profile Overview', 'freemius' ),
205
+ 'permissions-profile_desc' => __( 'Name and email address', 'freemius' ),
206
+ 'permissions-site' => __( 'Your Site Overview', 'freemius' ),
207
+ 'permissions-site_desc' => __( 'Site URL, WP version, PHP info, plugins & themes', 'freemius' ),
208
+ 'permissions-events' => __( 'Current Plugin Events', 'freemius' ),
209
+ 'permissions-events_desc' => __( 'Activation, deactivation and uninstall', 'freemius' ),
210
+ 'permissions-plugins_themes' => __( 'Plugins & Themes', 'freemius' ),
211
+ 'permissions-plugins_themes_desc' => __( 'Titles, versions and state.', 'freemius' ),
212
+ 'permissions-newsletter' => __( 'Newsletter', 'freemius' ),
213
+ 'permissions-newsletter_desc' => __( 'Updates, announcements, marketing, no spam', 'freemius' ),
214
+ 'privacy-policy' => __( 'Privacy Policy', 'freemius' ),
215
+ 'tos' => __( 'Terms of Service', 'freemius' ),
216
+ 'activating' => _x( 'Activating', 'as activating plugin', 'freemius' ),
217
+ 'sending-email' => _x( 'Sending email', 'as in the process of sending an email', 'freemius' ),
218
+ 'opt-in-connect' => _x( 'Allow & Continue', 'button label', 'freemius' ),
219
+ 'agree-activate-license' => _x( 'Agree & Activate License', 'button label', 'freemius' ),
220
+ 'skip' => _x( 'Skip', 'verb', 'freemius' ),
221
+ 'click-here-to-use-plugin-anonymously' => __( 'Click here to use the plugin anonymously', 'freemius' ),
222
+ 'resend-activation-email' => __( 'Re-send activation email', 'freemius' ),
223
+ 'license-key' => __( 'License key', 'freemius' ),
224
+ 'send-license-key' => __( 'Send License Key', 'freemius' ),
225
+ 'sending-license-key' => __( 'Sending license key', 'freemius' ),
226
+ 'have-license-key' => __( 'Have a license key?', 'freemius' ),
227
+ 'dont-have-license-key' => __( 'Don\'t have a license key?', 'freemius' ),
228
+ 'cant-find-license-key' => __( "Can't find your license key?", 'freemius' ),
229
+ 'email-not-found' => __( "We couldn't find your email address in the system, are you sure it's the right address?" ),
230
+ 'no-active-licenses' => __( "We can't see any active licenses associated with that email address, are you sure it's the right address?" ),
231
+ #endregion Connect
232
+
233
+ #region Screenshots
234
+ 'screenshots' => __( 'Screenshots', 'freemius' ),
235
+ 'view-full-size-x' => __( 'Click to view full-size screenshot %d', 'freemius' ),
236
+ #endregion Screenshots
237
+
238
+ #region Debug
239
+ 'freemius-debug' => __( 'Freemius Debug', 'freemius' ),
240
+ 'on' => _x( 'On', 'as turned on', 'freemius' ),
241
+ 'off' => _x( 'Off', 'as turned off', 'freemius' ),
242
+ 'debugging' => _x( 'Debugging', 'as code debugging', 'freemius' ),
243
+ 'freemius-state' => __( 'Freemius State', 'freemius' ),
244
+ 'connected' => _x( 'Connected', 'as connection was successful', 'freemius' ),
245
+ 'blocked' => _x( 'Blocked', 'as connection blocked', 'freemius' ),
246
+ 'api' => _x( 'API', 'as application program interface', 'freemius' ),
247
+ 'sdk' => _x( 'SDK', 'as software development kit versions', 'freemius' ),
248
+ 'sdk-versions' => _x( 'SDK Versions', 'as software development kit versions', 'freemius' ),
249
+ 'plugin-path' => _x( 'Plugin Path', 'as plugin folder path', 'freemius' ),
250
+ 'sdk-path' => _x( 'SDK Path', 'as sdk path', 'freemius' ),
251
+ 'addons-of-x' => __( 'Add Ons of Plugin %s', 'freemius' ),
252
+ 'delete-all-confirm' => __( 'Are you sure you want to delete all Freemius data?', 'freemius' ),
253
+ 'actions' => __( 'Actions', 'freemius' ),
254
+ 'delete-all-accounts' => __( 'Delete All Accounts', 'freemius' ),
255
+ 'start-fresh' => __( 'Start Fresh', 'freemius' ),
256
+ 'clear-api-cache' => __( 'Clear API Cache', 'freemius' ),
257
+ 'sync-data-from-server' => __( 'Sync Data From Server', 'freemius' ),
258
+ 'scheduled-crons' => __( 'Scheduled Crons', 'freemius' ),
259
+ 'plugins-themes-sync' => __( 'Plugins & Themes Sync', 'freemius' ),
260
+ #endregion Debug
261
+
262
+ #region Expressions
263
+ 'congrats' => _x( 'Congrats', 'as congratulations', 'freemius' ),
264
+ 'oops' => _x( 'Oops', 'exclamation', 'freemius' ),
265
+ 'yee-haw' => _x( 'Yee-haw', 'interjection expressing joy or exuberance', 'freemius' ),
266
+ 'woot' => _x( 'W00t', '(especially in electronic communication) used to express elation, enthusiasm, or triumph.', 'freemius' ),
267
+ 'right-on' => _x( 'Right on', 'a positive response', 'freemius' ),
268
+ 'hmm' => _x( 'Hmm', 'something somebody says when they are thinking about what you have just said. ', 'freemius' ),
269
+ 'ok' => __( 'O.K', 'freemius' ),
270
+ 'hey' => _x( 'Hey', 'exclamation', 'freemius' ),
271
+ 'heads-up' => _x( 'Heads up', 'advance notice of something that will need attention.', 'freemius' ),
272
+ #endregion Expressions
273
+
274
+ #region Admin Notices
275
+ 'you-have-latest' => __( 'Seems like you got the latest release.', 'freemius' ),
276
+ 'you-are-good' => __( 'You are all good!', 'freemius' ),
277
+ 'user-exist-message' => __( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'freemius' ),
278
+ 'user-exist-message_ownership' => __( 'If you would like to give up the ownership of the plugin\'s account to %s click the Change Ownership button.', 'freemius' ),
279
+ 'email-updated-message' => __( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'freemius' ),
280
+ 'name-updated-message' => __( 'Your name was successfully updated.', 'freemius' ),
281
+ 'x-updated' => __( 'You have successfully updated your %s.', 'freemius' ),
282
+ 'name-update-failed-message' => __( 'Please provide your full name.', 'freemius' ),
283
+ 'verification-email-sent-message' => __( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'freemius' ),
284
+ 'addons-info-external-message' => __( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'freemius' ),
285
+ 'no-cc-required' => __( 'No credit card required', 'freemius' ),
286
+ 'premium-activated-message' => __( 'Premium plugin version was successfully activated.', 'freemius' ),
287
+ 'successful-version-upgrade-message' => __( 'The upgrade of %s was successfully completed.', 'freemius' ),
288
+ 'activation-with-plan-x-message' => __( 'Your account was successfully activated with the %s plan.', 'freemius' ),
289
+ 'download-latest-x-version' => __( 'Download the latest %s version now', 'freemius' ),
290
+ 'download-latest-version' => __( 'Download the latest version now', 'freemius' ),
291
+ 'addon-successfully-purchased-message' => _x( '%s Add-on was successfully purchased.', '%s - product name, e.g. Facebook add-on was successfully...', 'freemius' ),
292
+ 'addon-successfully-upgraded-message' => __( 'Your %s Add-on plan was successfully upgraded.', 'freemius' ),
293
+ 'email-verified-message' => __( 'Your email has been successfully verified - you are AWESOME!', 'freemius' ),
294
+ 'plan-upgraded-message' => __( 'Your plan was successfully upgraded.', 'freemius' ),
295
+ 'plan-changed-to-x-message' => __( 'Your plan was successfully changed to %s.', 'freemius' ),
296
+ 'license-expired-blocking-message' => __( 'Your license has expired. You can still continue using the free plugin forever.', 'freemius' ),
297
+ 'license-cancelled' => __( 'Your license has been cancelled. If you think it\'s a mistake, please contact support.', 'freemius' ),
298
+ 'trial-started-message' => __( 'Your trial has been successfully started.', 'freemius' ),
299
+ 'license-activated-message' => __( 'Your license was successfully activated.', 'freemius' ),
300
+ 'no-active-license-message' => __( 'It looks like your site currently doesn\'t have an active license.', 'freemius' ),
301
+ 'license-deactivation-message' => __( 'Your license was successfully deactivated, you are back to the %s plan.', 'freemius' ),
302
+ 'license-deactivation-failed-message' => __( 'It looks like the license deactivation failed.', 'freemius' ),
303
+ 'license-activation-failed-message' => __( 'It looks like the license could not be activated.', 'freemius' ),
304
+ 'server-error-message' => __( 'Error received from the server:', 'freemius' ),
305
+ 'trial-expired-message' => __( 'Your trial has expired. You can still continue using all our free features.', 'freemius' ),
306
+ 'plan-x-downgraded-message' => __( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.', 'freemius' ),
307
+ 'plan-downgraded-failure-message' => __( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.', 'freemius' ),
308
+ 'trial-cancel-no-trial-message' => __( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'freemius' ),
309
+ 'trial-cancel-message' => __( 'Your %s free trial was successfully cancelled.', 'freemius' ),
310
+ 'version-x-released' => _x( 'Version %s was released.', '%s - numeric version number', 'freemius' ),
311
+ 'please-download-x' => __( 'Please download %s.', 'freemius' ),
312
+ 'latest-x-version' => _x( 'the latest %s version here', '%s - plan name, as the latest professional version here', 'freemius' ),
313
+ 'trial-x-promotion-message' => __( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'freemius' ),
314
+ 'start-free-trial' => _x( 'Start free trial', 'call to action', 'freemius' ),
315
+ 'trial-cancel-failure-message' => __( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'freemius' ),
316
+ 'trial-utilized' => __( 'You already utilized a trial before.', 'freemius' ),
317
+ 'in-trial-mode' => __( 'You are already running the plugin in a trial mode.', 'freemius' ),
318
+ 'trial-plan-x-not-exist' => __( 'Plan %s do not exist, therefore, can\'t start a trial.', 'freemius' ),
319
+ 'plan-x-no-trial' => __( 'Plan %s does not support a trial period.', 'freemius' ),
320
+ 'no-trials' => __( 'None of the plugin\'s plans supports a trial period.', 'freemius' ),
321
+ 'unexpected-api-error' => __( 'Unexpected API error. Please contact the plugin\'s author with the following error.', 'freemius' ),
322
+ 'no-commitment-for-x-days' => __( 'No commitment for %s days - cancel anytime!', 'freemius' ),
323
+ 'license-expired-non-blocking-message' => __( 'Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.', 'freemius' ),
324
+ 'could-not-activate-x' => __( 'Couldn\'t activate %s.', 'freemius' ),
325
+ 'contact-us-with-error-message' => __( 'Please contact us with the following message:', 'freemius' ),
326
+ 'plan-did-not-change-message' => __( 'It looks like you are still on the %s plan. If you did upgrade or change your plan, it\'s probably an issue on our side - sorry.', 'freemius' ),
327
+ 'contact-us-here' => __( 'Please contact us here', 'freemius' ),
328
+ 'plan-did-not-change-email-message' => __( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'freemius' ),
329
+ #endregion Admin Notices
330
+ #region Connectivity Issues
331
+ 'connectivity-test-fails-message' => __( 'From unknown reason, the API connectivity test failed.', 'freemius' ),
332
+ 'connectivity-test-maybe-temporary' => __( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?', 'freemius' ),
333
+ 'curl-missing-message' => __( 'We use PHP cURL library for the API calls, which is a very common library and usually installed out of the box. Unfortunately, cURL is not installed on your server.', 'freemius' ),
334
+ 'cloudflare-blocks-connection-message' => __( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'freemius' ),
335
+ 'x-requires-access-to-api' => _x( '%s requires an access to our API.', 'as pluginX requires an access to our API', 'freemius' ),
336
+ 'squid-blocks-connection-message' => __( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'freemius' ),
337
+ 'squid-no-clue-title' => __( 'I don\'t know what is Squid or ACL, help me!', 'freemius' ),
338
+ 'squid-no-clue-desc' => __( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'freemius' ),
339
+ 'sysadmin-title' => __( 'I\'m a system administrator', 'freemius' ),
340
+ 'squid-sysadmin-desc' => __( 'Great, please whitelist the following domains: %s. Once you done, deactivate the plugin and activate it again.', 'freemius' ),
341
+ 'curl-missing-no-clue-title' => __( 'I don\'t know what is cURL or how to install it, help me!', 'freemius' ),
342
+ 'curl-missing-no-clue-desc' => __( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'freemius' ),
343
+ 'curl-missing-sysadmin-desc' => __( 'Great, please install cURL and enable it in your php.ini file. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the plugin and reactivate it back again.', 'freemius' ),
344
+ 'happy-to-resolve-issue-asap' => __( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.', 'freemius' ),
345
+ 'contact-support-before-deactivation' => __( 'Sorry for the inconvenience and we are here to help if you give us a chance.', 'freemius' ),
346
+ 'fix-issue-title' => __( 'Yes - I\'m giving you a chance to fix it', 'freemius' ),
347
+ 'fix-issue-desc' => __( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.', 'freemius' ),
348
+ 'install-previous-title' => __( 'Let\'s try your previous version', 'freemius' ),
349
+ 'install-previous-desc' => __( 'Uninstall this version and install the previous one.', 'freemius' ),
350
+ 'deactivate-plugin-title' => __( 'That\'s exhausting, please deactivate', 'freemius' ),
351
+ 'deactivate-plugin-desc' => __( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'freemius' ),
352
+ 'fix-request-sent-message' => __( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.', 'freemius' ),
353
+ 'server-blocking-access' => _x( 'Your server is blocking the access to Freemius\' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s', '%1s - plugin title, %2s - API domain', 'freemius' ),
354
+ 'wrong-authentication-param-message' => __( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', 'freemius' ),
355
+ #endregion Connectivity Issues
356
+ #region Change Owner
357
+ 'change-owner-request-sent-x' => __( 'Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder.', 'freemius' ),
358
+ 'change-owner-request_owner-confirmed' => __( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'freemius' ),
359
+ 'change-owner-request_candidate-confirmed' => __( '%s is the new owner of the account.', 'freemius' ),
360
+ #endregion Change Owner
361
+ 'addon-x-cannot-run-without-y' => _x( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'freemius' ),
362
+ 'addon-x-cannot-run-without-parent' => _x( '%s cannot run without the plugin.', 'addonX cannot run...', 'freemius' ),
363
+ 'plugin-x-activation-message' => _x( '%s activation was successfully completed.', 'pluginX activation was successfully...', 'freemius' ),
364
+ 'features-and-pricing' => _x( 'Features & Pricing', 'Plugin installer section title', 'freemius' ),
365
+ 'free-addon-not-deployed' => __( 'Add-on must be deployed to WordPress.org or Freemius.', 'freemius' ),
366
+ 'paid-addon-not-deployed' => __( 'Paid add-on must be deployed to Freemius.', 'freemius' ),
367
+ #region Add-On Licensing
368
+ 'addon-no-license-message' => __( '%s is a premium only add-on. You have to purchase a license first before activating the plugin.', 'freemius' ),
369
+ 'addon-trial-cancelled-message' => __( '%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you\'ll have to purchase a license.', 'freemius' ),
370
+ #endregion Add-On Licensing
371
+ #region Billing Cycles
372
+ 'monthly' => _x( 'Monthly', 'as every month', 'freemius' ),
373
+ 'mo' => _x( 'mo', 'as monthly period', 'freemius' ),
374
+ 'annual' => _x( 'Annual', 'as once a year', 'freemius' ),
375
+ 'annually' => _x( 'Annually', 'as once a year', 'freemius' ),
376
+ 'once' => _x( 'Once', 'as once a year', 'freemius' ),
377
+ 'year' => _x( 'year', 'as annual period', 'freemius' ),
378
+ 'lifetime' => __( 'Lifetime', 'freemius' ),
379
+ 'best' => _x( 'Best', 'e.g. the best product', 'freemius' ),
380
+ 'billed-x' => _x( 'Billed %s', 'e.g. billed monthly', 'freemius' ),
381
+ 'save-x' => _x( 'Save %s', 'as a discount of $5 or 10%', 'freemius' ),
382
+ #endregion Billing Cycles
383
+ 'view-details' => __( 'View details', 'freemius' ),
384
+ );
freemius/includes/managers/class-fs-admin-menu-manager.php ADDED
@@ -0,0 +1,549 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Menu_Manager {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ protected $_plugin_slug;
21
+
22
+ /**
23
+ * @since 1.0.6
24
+ *
25
+ * @var string
26
+ */
27
+ private $_menu_slug;
28
+ /**
29
+ * @since 1.1.3
30
+ *
31
+ * @var string
32
+ */
33
+ private $_parent_slug;
34
+ /**
35
+ * @since 1.1.3
36
+ *
37
+ * @var string
38
+ */
39
+ private $_parent_type;
40
+ /**
41
+ * @since 1.1.3
42
+ *
43
+ * @var string
44
+ */
45
+ private $_type;
46
+ /**
47
+ * @since 1.1.3
48
+ *
49
+ * @var bool
50
+ */
51
+ private $_is_top_level;
52
+ /**
53
+ * @since 1.1.3
54
+ *
55
+ * @var bool
56
+ */
57
+ private $_is_override_exact;
58
+ /**
59
+ * @since 1.1.3
60
+ *
61
+ * @var string[]bool
62
+ */
63
+ private $_default_submenu_items;
64
+ /**
65
+ * @since 1.1.3
66
+ *
67
+ * @var string
68
+ */
69
+ private $_first_time_path;
70
+
71
+ #endregion Properties
72
+
73
+ /**
74
+ * @var FS_Logger
75
+ */
76
+ protected $_logger;
77
+
78
+ #region Singleton
79
+
80
+ /**
81
+ * @var FS_Admin_Menu_Manager[]
82
+ */
83
+ private static $_instances = array();
84
+
85
+ /**
86
+ * @param string $plugin_slug
87
+ *
88
+ * @return FS_Admin_Notice_Manager
89
+ */
90
+ static function instance( $plugin_slug ) {
91
+ if ( ! isset( self::$_instances[ $plugin_slug ] ) ) {
92
+ self::$_instances[ $plugin_slug ] = new FS_Admin_Menu_Manager( $plugin_slug );
93
+ }
94
+
95
+ return self::$_instances[ $plugin_slug ];
96
+ }
97
+
98
+ protected function __construct( $plugin_slug ) {
99
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $plugin_slug . '_admin_menu', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
100
+
101
+ $this->_plugin_slug = $plugin_slug;
102
+ }
103
+
104
+ #endregion Singleton
105
+
106
+ #region Helpers
107
+
108
+ private function get_option( &$options, $key, $default = false ) {
109
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
110
+ }
111
+
112
+ private function get_bool_option( &$options, $key, $default = false ) {
113
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
114
+ }
115
+
116
+ #endregion Helpers
117
+
118
+ /**
119
+ * @param array $menu
120
+ * @param bool $is_addon
121
+ */
122
+ function init( $menu, $is_addon = false ) {
123
+ $this->_menu_slug = $menu['slug'];
124
+
125
+ $this->_default_submenu_items = array();
126
+ // @deprecated
127
+ $this->_type = 'page';
128
+ $this->_is_top_level = true;
129
+ $this->_is_override_exact = false;
130
+ $this->_parent_slug = false;
131
+ // @deprecated
132
+ $this->_parent_type = 'page';
133
+
134
+ if ( ! $is_addon && isset( $menu ) ) {
135
+ $this->_default_submenu_items = array(
136
+ 'contact' => $this->get_bool_option( $menu, 'contact', true ),
137
+ 'support' => $this->get_bool_option( $menu, 'support', true ),
138
+ 'account' => $this->get_bool_option( $menu, 'account', true ),
139
+ 'pricing' => $this->get_bool_option( $menu, 'pricing', true ),
140
+ 'addons' => $this->get_bool_option( $menu, 'addons', true ),
141
+ );
142
+
143
+ // @deprecated
144
+ $this->_type = $this->get_option( $menu, 'type', 'page' );
145
+ $this->_is_override_exact = $this->get_bool_option( $menu, 'override_exact' );
146
+
147
+ if ( isset( $menu['parent'] ) ) {
148
+ $this->_parent_slug = $this->get_option( $menu['parent'], 'slug' );
149
+ // @deprecated
150
+ $this->_parent_type = $this->get_option( $menu['parent'], 'type', 'page' );
151
+
152
+ // If parent's slug is different, then it's NOT a top level menu item.
153
+ $this->_is_top_level = ( $this->_parent_slug === $this->_menu_slug );
154
+ } else {
155
+ /**
156
+ * If no parent then top level if:
157
+ * - Has custom admin menu ('page')
158
+ * - CPT menu type ('cpt')
159
+ */
160
+ // $this->_is_top_level = in_array( $this->_type, array(
161
+ // 'cpt',
162
+ // 'page'
163
+ // ) );
164
+ }
165
+
166
+ $this->_first_time_path = $this->get_option( $menu, 'first-path', false );
167
+ if ( ! empty( $this->_first_time_path ) && is_string( $this->_first_time_path ) ) {
168
+ $this->_first_time_path = admin_url( $this->_first_time_path, 'admin' );
169
+ }
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Check if top level menu.
175
+ *
176
+ * @author Vova Feldman (@svovaf)
177
+ * @since 1.1.3
178
+ *
179
+ * @return bool False if submenu item.
180
+ */
181
+ function is_top_level() {
182
+ return $this->_is_top_level;
183
+ }
184
+
185
+ /**
186
+ * Check if the page should be override on exact URL match.
187
+ *
188
+ * @author Vova Feldman (@svovaf)
189
+ * @since 1.1.3
190
+ *
191
+ * @return bool False if submenu item.
192
+ */
193
+ function is_override_exact() {
194
+ return $this->_is_override_exact;
195
+ }
196
+
197
+
198
+ /**
199
+ * Get the path of the page the user should be forwarded to after first activation.
200
+ *
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.3
203
+ *
204
+ * @return string
205
+ */
206
+ function get_first_time_path() {
207
+ return $this->_first_time_path;
208
+ }
209
+
210
+ /**
211
+ * Check if plugin's menu item is part of a custom top level menu.
212
+ *
213
+ * @author Vova Feldman (@svovaf)
214
+ * @since 1.1.3
215
+ *
216
+ * @return bool
217
+ */
218
+ function has_custom_parent() {
219
+ return ! $this->_is_top_level && is_string( $this->_parent_slug );
220
+ }
221
+
222
+ /**
223
+ * @author Vova Feldman (@svovaf)
224
+ * @since 1.1.3
225
+ *
226
+ * @return string
227
+ */
228
+ // function slug(){
229
+ // return $this->_menu_slug;
230
+ // }
231
+
232
+ /**
233
+ * @author Vova Feldman (@svovaf)
234
+ * @since 1.1.3
235
+ *
236
+ * @param string $id
237
+ * @param bool $default
238
+ *
239
+ * @return bool
240
+ */
241
+ function is_submenu_item_visible( $id, $default = true ) {
242
+ return fs_apply_filter(
243
+ $this->_plugin_slug,
244
+ 'is_submenu_visible',
245
+ $this->get_bool_option( $this->_default_submenu_items, $id, $default ),
246
+ $id
247
+ );
248
+ }
249
+
250
+ /**
251
+ * Calculates admin settings menu slug.
252
+ * If plugin's menu slug is a file (e.g. CPT), uses plugin's slug as the menu slug.
253
+ *
254
+ * @author Vova Feldman (@svovaf)
255
+ * @since 1.1.3
256
+ *
257
+ * @param string $page
258
+ *
259
+ * @return string
260
+ */
261
+ function get_slug( $page = '' ) {
262
+ return ( ( false === strpos( $this->_menu_slug, '.php?' ) ) ?
263
+ $this->_menu_slug :
264
+ $this->_plugin_slug ) . ( empty( $page ) ? '' : ( '-' . $page ) );
265
+ }
266
+
267
+ /**
268
+ * @author Vova Feldman (@svovaf)
269
+ * @since 1.1.3
270
+ *
271
+ * @return string
272
+ */
273
+ function get_parent_slug() {
274
+ return $this->_parent_slug;
275
+ }
276
+
277
+ /**
278
+ * @author Vova Feldman (@svovaf)
279
+ * @since 1.1.3
280
+ *
281
+ * @return string
282
+ */
283
+ function get_type() {
284
+ return $this->_type;
285
+ }
286
+
287
+ /**
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.1.3
290
+ *
291
+ * @return bool
292
+ */
293
+ function is_cpt() {
294
+ return ( 0 === strpos( $this->_menu_slug, 'edit.php?post_type=' ) ||
295
+ // Back compatibility.
296
+ 'cpt' === $this->_type
297
+ );
298
+ }
299
+
300
+ /**
301
+ * @author Vova Feldman (@svovaf)
302
+ * @since 1.1.3
303
+ *
304
+ * @return string
305
+ */
306
+ function get_parent_type() {
307
+ return $this->_parent_type;
308
+ }
309
+
310
+ /**
311
+ * @author Vova Feldman (@svovaf)
312
+ * @since 1.1.3
313
+ *
314
+ * @return string
315
+ */
316
+ function get_raw_slug() {
317
+ return $this->_menu_slug;
318
+ }
319
+
320
+ /**
321
+ * Get plugin's original menu slug.
322
+ *
323
+ * @author Vova Feldman (@svovaf)
324
+ * @since 1.1.3
325
+ *
326
+ * @return string
327
+ */
328
+ function get_original_menu_slug() {
329
+ if ( 'cpt' === $this->_type ) {
330
+ return add_query_arg( array(
331
+ 'post_type' => $this->_menu_slug
332
+ ), 'edit.php' );
333
+ }
334
+
335
+ if ( false === strpos( $this->_menu_slug, '.php?' ) ) {
336
+ return $this->_menu_slug;
337
+ } else {
338
+ return $this->_plugin_slug;
339
+ }
340
+ }
341
+
342
+ /**
343
+ * @author Vova Feldman (@svovaf)
344
+ * @since 1.1.3
345
+ *
346
+ * @return string
347
+ */
348
+ function get_top_level_menu_slug() {
349
+ return $this->has_custom_parent() ?
350
+ $this->get_parent_slug() :
351
+ $this->get_raw_slug();
352
+ }
353
+
354
+ /**
355
+ * Is user on plugin's admin activation page.
356
+ *
357
+ * @author Vova Feldman (@svovaf)
358
+ * @since 1.0.8
359
+ *
360
+ * @return bool
361
+ */
362
+ function is_activation_page() {
363
+ return isset( $_GET['page'] ) &&
364
+ ( ( strtolower( $this->_menu_slug ) === strtolower( $_GET['page'] ) ) ||
365
+ ( strtolower( $this->_plugin_slug ) === strtolower( $_GET['page'] ) ) );
366
+ }
367
+
368
+ #region Submenu Override
369
+
370
+ /**
371
+ * Override submenu's action.
372
+ *
373
+ * @author Vova Feldman (@svovaf)
374
+ * @since 1.1.0
375
+ *
376
+ * @param string $parent_slug
377
+ * @param string $menu_slug
378
+ * @param callable $function
379
+ *
380
+ * @return false|string If submenu exist, will return the hook name.
381
+ */
382
+ function override_submenu_action( $parent_slug, $menu_slug, $function ) {
383
+ global $submenu;
384
+
385
+ $menu_slug = plugin_basename( $menu_slug );
386
+ $parent_slug = plugin_basename( $parent_slug );
387
+
388
+ if ( ! isset( $submenu[ $parent_slug ] ) ) {
389
+ // Parent menu not exist.
390
+ return false;
391
+ }
392
+
393
+ $found_submenu_item = false;
394
+ foreach ( $submenu[ $parent_slug ] as $submenu_item ) {
395
+ if ( $menu_slug === $submenu_item[2] ) {
396
+ $found_submenu_item = $submenu_item;
397
+ break;
398
+ }
399
+ }
400
+
401
+ if ( false === $found_submenu_item ) {
402
+ // Submenu item not found.
403
+ return false;
404
+ }
405
+
406
+ // Remove current function.
407
+ $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
408
+ remove_all_actions( $hookname );
409
+
410
+ // Attach new action.
411
+ add_action( $hookname, $function );
412
+
413
+ return $hookname;
414
+ }
415
+
416
+ #endregion Submenu Override
417
+
418
+ #region Top level menu Override
419
+
420
+ /**
421
+ * Find plugin's admin dashboard main menu item.
422
+ *
423
+ * @author Vova Feldman (@svovaf)
424
+ * @since 1.0.2
425
+ *
426
+ * @return string[]|false
427
+ */
428
+ private function find_top_level_menu() {
429
+ global $menu;
430
+
431
+ $position = - 1;
432
+ $found_menu = false;
433
+
434
+ $menu_slug = $this->get_raw_slug();
435
+
436
+ $hook_name = get_plugin_page_hookname( $menu_slug, '' );
437
+ foreach ( $menu as $pos => $m ) {
438
+ if ( $menu_slug === $m[2] ) {
439
+ $position = $pos;
440
+ $found_menu = $m;
441
+ break;
442
+ }
443
+ }
444
+
445
+ if ( false === $found_menu ) {
446
+ return false;
447
+ }
448
+
449
+ return array(
450
+ 'menu' => $found_menu,
451
+ 'position' => $position,
452
+ 'hook_name' => $hook_name
453
+ );
454
+ }
455
+
456
+ /**
457
+ * Remove all sub-menu items.
458
+ *
459
+ * @author Vova Feldman (@svovaf)
460
+ * @since 1.0.7
461
+ *
462
+ * @return bool If submenu with plugin's menu slug was found.
463
+ */
464
+ private function remove_all_submenu_items() {
465
+ global $submenu;
466
+
467
+ $menu_slug = $this->get_raw_slug();
468
+
469
+ if ( ! isset( $submenu[ $menu_slug ] ) ) {
470
+ return false;
471
+ }
472
+
473
+ $submenu[ $menu_slug ] = array();
474
+
475
+ return true;
476
+ }
477
+
478
+ /**
479
+ *
480
+ * @author Vova Feldman (@svovaf)
481
+ * @since 1.0.9
482
+ *
483
+ * @return array[string]mixed
484
+ */
485
+ function remove_menu_item() {
486
+ $this->_logger->entrance();
487
+
488
+ // Find main menu item.
489
+ $menu = $this->find_top_level_menu();
490
+
491
+ if ( false === $menu ) {
492
+ return false;
493
+ }
494
+
495
+ // Remove it with its actions.
496
+ remove_all_actions( $menu['hook_name'] );
497
+
498
+ // Remove all submenu items.
499
+ $this->remove_all_submenu_items();
500
+
501
+ return $menu;
502
+ }
503
+
504
+ /**
505
+ *
506
+ * @author Vova Feldman (@svovaf)
507
+ * @since 1.1.4
508
+ *
509
+ * @param callable $function
510
+ *
511
+ * @return array[string]mixed
512
+ */
513
+ function override_menu_item( $function ) {
514
+ $found_menu = $this->remove_menu_item();
515
+
516
+ if ( false === $found_menu ) {
517
+ return false;
518
+ }
519
+
520
+ if ( ! $this->is_top_level() || ! $this->is_cpt() ) {
521
+ $menu_slug = plugin_basename( $this->get_slug() );
522
+
523
+ $hookname = get_plugin_page_hookname( $menu_slug, '' );
524
+
525
+ // Override menu action.
526
+ add_action( $hookname, $function );
527
+ } else {
528
+ global $menu;
529
+
530
+ // Remove original CPT menu.
531
+ unset( $menu[ $found_menu['position'] ] );
532
+
533
+ // Create new top-level menu action.
534
+ $hookname = add_menu_page(
535
+ $found_menu['menu'][3],
536
+ $found_menu['menu'][0],
537
+ 'manage_options',
538
+ $this->get_slug(),
539
+ $function,
540
+ $found_menu['menu'][6],
541
+ $found_menu['position']
542
+ );
543
+ }
544
+
545
+ return $hookname;
546
+ }
547
+
548
+ #endregion Top level menu Override
549
+ }
freemius/includes/managers/class-fs-admin-notice-manager.php ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Notice_Manager {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_slug;
18
+ /**
19
+ * @var string
20
+ */
21
+ protected $_title;
22
+ /**
23
+ * @var array[]
24
+ */
25
+ private $_admin_messages = array();
26
+ /**
27
+ * @var FS_Key_Value_Storage
28
+ */
29
+ private $_sticky_storage;
30
+ /**
31
+ * @var FS_Plugin_Manager[]
32
+ */
33
+ private static $_instances = array();
34
+ /**
35
+ * @var FS_Logger
36
+ */
37
+ protected $_logger;
38
+
39
+ /**
40
+ * @param string $slug
41
+ * @param string $title
42
+ *
43
+ * @return FS_Admin_Notice_Manager
44
+ */
45
+ static function instance( $slug, $title = '' ) {
46
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
47
+ self::$_instances[ $slug ] = new FS_Admin_Notice_Manager( $slug, $title );
48
+ }
49
+
50
+ return self::$_instances[ $slug ];
51
+ }
52
+
53
+ protected function __construct( $slug, $title = '' ) {
54
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_data', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
55
+
56
+ $this->_slug = $slug;
57
+ $this->_title = ! empty( $title ) ? $title : '';
58
+ $this->_sticky_storage = FS_Key_Value_Storage::instance( 'admin_notices', $this->_slug );
59
+
60
+ if ( is_admin() ) {
61
+ if ( 0 < count( $this->_sticky_storage ) ) {
62
+ // If there are sticky notices for the current slug, add a callback
63
+ // to the AJAX action that handles message dismiss.
64
+ add_action( "wp_ajax_{$slug}_dismiss_notice_action", array(
65
+ &$this,
66
+ 'dismiss_notice_ajax_callback'
67
+ ) );
68
+
69
+ foreach ( $this->_sticky_storage as $id => $msg ) {
70
+ // Add admin notice.
71
+ $this->add(
72
+ $msg['message'],
73
+ $msg['title'],
74
+ $msg['type'],
75
+ true,
76
+ $msg['all'],
77
+ $msg['id'],
78
+ false
79
+ );
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Remove sticky message by ID.
87
+ *
88
+ * @author Vova Feldman (@svovaf)
89
+ * @since 1.0.7
90
+ *
91
+ */
92
+ function dismiss_notice_ajax_callback() {
93
+ $this->_sticky_storage->remove( $_POST['message_id'] );
94
+ wp_die();
95
+ }
96
+
97
+ /**
98
+ * Rendered sticky message dismiss JavaScript.
99
+ *
100
+ * @author Vova Feldman (@svovaf)
101
+ * @since 1.0.7
102
+ */
103
+ static function _add_sticky_dismiss_javascript() {
104
+ $params = array();
105
+ fs_require_once_template( 'sticky-admin-notice-js.php', $params );
106
+ }
107
+
108
+ private static $_added_sticky_javascript = false;
109
+
110
+ /**
111
+ * Hook to the admin_footer to add sticky message dismiss JavaScript handler.
112
+ *
113
+ * @author Vova Feldman (@svovaf)
114
+ * @since 1.0.7
115
+ */
116
+ private static function has_sticky_messages() {
117
+ if ( ! self::$_added_sticky_javascript ) {
118
+ add_action( 'admin_footer', array( 'FS_Admin_Notice_Manager', '_add_sticky_dismiss_javascript' ) );
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Handle admin_notices by printing the admin messages stacked in the queue.
124
+ *
125
+ * @author Vova Feldman (@svovaf)
126
+ * @since 1.0.4
127
+ *
128
+ */
129
+ function _admin_notices_hook() {
130
+ $notice_type = 'admin_notices';
131
+
132
+ if ( function_exists( 'current_user_can' ) &&
133
+ ! current_user_can( 'manage_options' )
134
+ ) {
135
+ // Only show messages to admins.
136
+ return;
137
+ }
138
+
139
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
140
+ return;
141
+ }
142
+
143
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
144
+ fs_require_template( 'admin-notice.php', $msg );
145
+
146
+ if ( $msg['sticky'] ) {
147
+ self::has_sticky_messages();
148
+ }
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Handle all_admin_notices by printing the admin messages stacked in the queue.
154
+ *
155
+ * @author Vova Feldman (@svovaf)
156
+ * @since 1.0.4
157
+ *
158
+ */
159
+ function _all_admin_notices_hook() {
160
+ $notice_type = 'all_admin_notices';
161
+
162
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
163
+ return;
164
+ }
165
+
166
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
167
+ fs_require_template( 'all-admin-notice.php', $msg );
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Enqueue common stylesheet to style admin notice.
173
+ *
174
+ * @author Vova Feldman (@svovaf)
175
+ * @since 1.0.7
176
+ */
177
+ function _enqueue_styles() {
178
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
179
+ }
180
+
181
+ /**
182
+ * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked.
183
+ *
184
+ * @author Vova Feldman (@svovaf)
185
+ * @since 1.0.4
186
+ *
187
+ * @param string $message
188
+ * @param string $title
189
+ * @param string $type
190
+ * @param bool $is_sticky
191
+ * @param bool $all_admin
192
+ * @param string $id Message ID
193
+ * @param bool $store_if_sticky
194
+ *
195
+ * @uses add_action()
196
+ */
197
+ function add( $message, $title = '', $type = 'success', $is_sticky = false, $all_admin = false, $id = '', $store_if_sticky = true ) {
198
+ $key = ( $all_admin ? 'all_admin_notices' : 'admin_notices' );
199
+
200
+ if ( ! isset( $this->_admin_messages[ $key ] ) ) {
201
+ $this->_admin_messages[ $key ] = array();
202
+
203
+ add_action( $key, array( &$this, "_{$key}_hook" ) );
204
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_styles' ) );
205
+
206
+ }
207
+
208
+ if ( '' === $id ) {
209
+ $id = md5( $title . ' ' . $message . ' ' . $type );
210
+ }
211
+
212
+ $message_object = array(
213
+ 'message' => $message,
214
+ 'title' => $title,
215
+ 'type' => $type,
216
+ 'sticky' => $is_sticky,
217
+ 'id' => $id,
218
+ 'all' => $all_admin,
219
+ 'slug' => $this->_slug,
220
+ 'plugin' => $this->_title,
221
+ );
222
+
223
+ if ( $is_sticky && $store_if_sticky ) {
224
+ $this->_sticky_storage->{$id} = $message_object;
225
+ }
226
+
227
+ $this->_admin_messages[ $key ][ $id ] = $message_object;
228
+ }
229
+
230
+ /**
231
+ * @author Vova Feldman (@svovaf)
232
+ * @since 1.0.7
233
+ *
234
+ * @param string|string[] $ids
235
+ */
236
+ function remove_sticky( $ids ) {
237
+ if ( ! is_array( $ids ) ) {
238
+ $ids = array( $ids );
239
+ }
240
+
241
+ foreach ( $ids as $id ) {
242
+ // Remove from sticky storage.
243
+ $this->_sticky_storage->remove( $id );
244
+
245
+ // Remove from current admin messages.
246
+ if ( isset( $this->_admin_messages['all_admin_notices'] ) && isset( $this->_admin_messages['all_admin_notices'][ $id ] ) ) {
247
+ unset( $this->_admin_messages['all_admin_notices'][ $id ] );
248
+ }
249
+ if ( isset( $this->_admin_messages['admin_notices'] ) && isset( $this->_admin_messages['admin_notices'][ $id ] ) ) {
250
+ unset( $this->_admin_messages['admin_notices'][ $id ] );
251
+ }
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Check if sticky message exists by id.
257
+ *
258
+ * @author Vova Feldman (@svovaf)
259
+ * @since 1.0.9
260
+ *
261
+ * @param $id
262
+ *
263
+ * @return bool
264
+ */
265
+ function has_sticky( $id ) {
266
+ return isset( $this->_sticky_storage[ $id ] );
267
+ }
268
+
269
+ /**
270
+ * Adds sticky admin notification.
271
+ *
272
+ * @author Vova Feldman (@svovaf)
273
+ * @since 1.0.7
274
+ *
275
+ * @param string $message
276
+ * @param string $id Message ID
277
+ * @param string $title
278
+ * @param string $type
279
+ * @param bool $all_admin
280
+ */
281
+ function add_sticky( $message, $id, $title = '', $type = 'success', $all_admin = false ) {
282
+ $this->add( $message, $title, $type, true, $all_admin, $id );
283
+ }
284
+
285
+ /**
286
+ * Clear all sticky messages.
287
+ *
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.0.8
290
+ */
291
+ function clear_all_sticky() {
292
+ $this->_sticky_storage->clear_all();
293
+ }
294
+
295
+ /**
296
+ * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked.
297
+ *
298
+ * @author Vova Feldman (@svovaf)
299
+ * @since 1.0.4
300
+ *
301
+ * @param string $message
302
+ * @param string $title
303
+ * @param string $type
304
+ * @param bool $is_sticky
305
+ * @param string $id Message ID
306
+ */
307
+ function add_all( $message, $title = '', $type = 'success', $is_sticky = false, $id = '' ) {
308
+ $this->add( $message, $title, $type, $is_sticky, true, $id );
309
+ }
310
+ }
freemius/includes/managers/class-fs-cache-manager.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Cache_Manager {
14
+ /**
15
+ * @var FS_Option_Manager
16
+ */
17
+ private $_options;
18
+ /**
19
+ * @var FS_Logger
20
+ */
21
+ private $_logger;
22
+
23
+ /**
24
+ * @var FS_Cache_Manager[]
25
+ */
26
+ private static $_MANAGERS = array();
27
+
28
+ /**
29
+ * @author Vova Feldman (@svovaf)
30
+ * @since 1.1.3
31
+ *
32
+ * @param string $id
33
+ */
34
+ private function __construct( $id ) {
35
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_cach_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
36
+
37
+ $this->_logger->entrance();
38
+ $this->_logger->log( 'id = ' . $id );
39
+
40
+ $this->_options = FS_Option_Manager::get_manager( $id, true );
41
+ }
42
+
43
+ /**
44
+ * @author Vova Feldman (@svovaf)
45
+ * @since 1.1.6
46
+ *
47
+ * @param $id
48
+ *
49
+ * @return FS_Cache_Manager
50
+ */
51
+ static function get_manager( $id ) {
52
+ $id = strtolower( $id );
53
+
54
+ if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
55
+ self::$_MANAGERS[ $id ] = new FS_Cache_Manager( $id );
56
+ }
57
+
58
+ return self::$_MANAGERS[ $id ];
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.6
64
+ *
65
+ * @return bool
66
+ */
67
+ function is_empty() {
68
+ $this->_logger->entrance();
69
+
70
+ return $this->_options->is_empty();
71
+ }
72
+
73
+ /**
74
+ * @author Vova Feldman (@svovaf)
75
+ * @since 1.1.6
76
+ */
77
+ function clear() {
78
+ $this->_logger->entrance();
79
+
80
+ $this->_options->clear( true );
81
+ }
82
+
83
+ /**
84
+ * Delete cache manager from DB.
85
+ *
86
+ * @author Vova Feldman (@svovaf)
87
+ * @since 1.0.9
88
+ */
89
+ function delete() {
90
+ $this->_options->delete();
91
+ }
92
+
93
+ /**
94
+ * Check if there's a cached item.
95
+ *
96
+ * @author Vova Feldman (@svovaf)
97
+ * @since 1.1.6
98
+ *
99
+ * @param string $key
100
+ *
101
+ * @return bool
102
+ */
103
+ function has( $key ) {
104
+ $cache_entry = $this->_options->get_option( $key, false );
105
+
106
+ return ( is_object( $cache_entry ) &&
107
+ isset( $cache_entry->timestamp ) &&
108
+ is_numeric( $cache_entry->timestamp )
109
+ );
110
+ }
111
+
112
+ /**
113
+ * Check if there's a valid cached item.
114
+ *
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.1.6
117
+ *
118
+ * @param string $key
119
+ *
120
+ * @return bool
121
+ */
122
+ function has_valid( $key ) {
123
+ $cache_entry = $this->_options->get_option( $key, false );
124
+
125
+ return ( is_object( $cache_entry ) &&
126
+ isset( $cache_entry->timestamp ) &&
127
+ is_numeric( $cache_entry->timestamp ) &&
128
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
129
+ );
130
+ }
131
+
132
+ /**
133
+ * @author Vova Feldman (@svovaf)
134
+ * @since 1.1.6
135
+ *
136
+ * @param string $key
137
+ * @param mixed $default
138
+ *
139
+ * @return mixed
140
+ */
141
+ function get( $key, $default = null ) {
142
+ $this->_logger->entrance( 'key = ' . $key );
143
+
144
+ $cache_entry = $this->_options->get_option( $key, false );
145
+
146
+ if ( is_object( $cache_entry ) &&
147
+ isset( $cache_entry->timestamp ) &&
148
+ is_numeric( $cache_entry->timestamp )
149
+ ) {
150
+ return $cache_entry->result;
151
+ }
152
+
153
+ return $default;
154
+ }
155
+
156
+ /**
157
+ * @author Vova Feldman (@svovaf)
158
+ * @since 1.1.6
159
+ *
160
+ * @param string $key
161
+ * @param mixed $default
162
+ *
163
+ * @return mixed
164
+ */
165
+ function get_valid( $key, $default = null ) {
166
+ $this->_logger->entrance( 'key = ' . $key );
167
+
168
+ $cache_entry = $this->_options->get_option( $key, false );
169
+
170
+ if ( is_object( $cache_entry ) &&
171
+ isset( $cache_entry->timestamp ) &&
172
+ is_numeric( $cache_entry->timestamp ) &&
173
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
174
+ ) {
175
+ return $cache_entry->result;
176
+ }
177
+
178
+ return $default;
179
+ }
180
+
181
+ /**
182
+ * @author Vova Feldman (@svovaf)
183
+ * @since 1.1.6
184
+ *
185
+ * @param string $key
186
+ * @param mixed $value
187
+ * @param int $expiration
188
+ */
189
+ function set( $key, $value, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
190
+ $this->_logger->entrance( 'key = ' . $key );
191
+
192
+ $cache_entry = new stdClass();
193
+ $cache_entry->result = $value;
194
+ $cache_entry->timestamp = WP_FS__SCRIPT_START_TIME + $expiration;
195
+ $this->_options->set_option( $key, $cache_entry, true );
196
+ }
197
+
198
+ /**
199
+ * Get cached record expiration, or false if not cached or expired.
200
+ *
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.7.3
203
+ *
204
+ * @param string $key
205
+ *
206
+ * @return bool|int
207
+ */
208
+ function get_record_expiration( $key ) {
209
+ $this->_logger->entrance( 'key = ' . $key );
210
+
211
+ $cache_entry = $this->_options->get_option( $key, false );
212
+
213
+ if ( is_object( $cache_entry ) &&
214
+ isset( $cache_entry->timestamp ) &&
215
+ is_numeric( $cache_entry->timestamp ) &&
216
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
217
+ ) {
218
+ return $cache_entry->timestamp;
219
+ }
220
+
221
+ return false;
222
+ }
223
+
224
+ /**
225
+ * Purge cached item.
226
+ *
227
+ * @author Vova Feldman (@svovaf)
228
+ * @since 1.1.6
229
+ *
230
+ * @param string $key
231
+ */
232
+ function purge( $key ) {
233
+ $this->_logger->entrance( 'key = ' . $key );
234
+
235
+ $this->_options->unset_option( $key, true );
236
+ }
237
+ }
freemius/includes/managers/class-fs-key-value-storage.php ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
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
+ * @var string
51
+ */
52
+ protected $_slug;
53
+ /**
54
+ * @var array
55
+ */
56
+ protected $_data;
57
+
58
+ /**
59
+ * @var FS_Plugin_Manager[]
60
+ */
61
+ private static $_instances = array();
62
+ /**
63
+ * @var FS_Logger
64
+ */
65
+ protected $_logger;
66
+
67
+ /**
68
+ * @param string $id
69
+ * @param string $slug
70
+ *
71
+ * @return FS_Key_Value_Storage
72
+ */
73
+ static function instance( $id, $slug ) {
74
+ $key = $id . ':' . $slug;
75
+ if ( ! isset( self::$_instances[ $key ] ) ) {
76
+ self::$_instances[ $key ] = new FS_Key_Value_Storage( $id, $slug );
77
+ }
78
+
79
+ return self::$_instances[ $key ];
80
+ }
81
+
82
+ protected function __construct( $id, $slug ) {
83
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
84
+
85
+ $this->_slug = $slug;
86
+ $this->_id = $id;
87
+ $this->load();
88
+ }
89
+
90
+ protected function get_option_manager() {
91
+ return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
92
+ }
93
+
94
+ protected function get_all_data() {
95
+ return $this->get_option_manager()->get_option( $this->_id, array() );
96
+ }
97
+
98
+ /**
99
+ * Load plugin data from local DB.
100
+ *
101
+ * @author Vova Feldman (@svovaf)
102
+ * @since 1.0.7
103
+ */
104
+ function load() {
105
+ $all_plugins_data = $this->get_all_data();
106
+ $this->_data = isset( $all_plugins_data[ $this->_slug ] ) ?
107
+ $all_plugins_data[ $this->_slug ] :
108
+ array();
109
+ }
110
+
111
+ /**
112
+ * @author Vova Feldman (@svovaf)
113
+ * @since 1.0.7
114
+ *
115
+ * @param string $key
116
+ * @param mixed $value
117
+ * @param bool $flush
118
+ */
119
+ function store( $key, $value, $flush = true ) {
120
+ if ( $this->_logger->is_on() ) {
121
+ $this->_logger->entrance( $key . ' = ' . var_export( $value, true ) );
122
+ }
123
+
124
+ if ( array_key_exists( $key, $this->_data ) && $value === $this->_data[ $key ] ) {
125
+ // No need to store data if the value wasn't changed.
126
+ return;
127
+ }
128
+
129
+ $all_data = $this->get_all_data();
130
+
131
+ $this->_data[ $key ] = $value;
132
+
133
+ $all_data[ $this->_slug ] = $this->_data;
134
+
135
+ $options_manager = $this->get_option_manager();
136
+ $options_manager->set_option( $this->_id, $all_data, $flush );
137
+ }
138
+
139
+ /**
140
+ * @author Vova Feldman (@svovaf)
141
+ * @since 1.0.7
142
+ *
143
+ * @param bool $store
144
+ * @param string[] $exceptions Set of keys to keep and not clear.
145
+ */
146
+ function clear_all( $store = true, $exceptions = array() ) {
147
+ $new_data = array();
148
+ foreach ( $exceptions as $key ) {
149
+ if ( isset( $this->_data[ $key ] ) ) {
150
+ $new_data[ $key ] = $this->_data[ $key ];
151
+ }
152
+ }
153
+
154
+ $this->_data = $new_data;
155
+
156
+ if ( $store ) {
157
+ $all_data = $this->get_all_data();
158
+ $all_data[ $this->_slug ] = $this->_data;
159
+ $options_manager = $this->get_option_manager();
160
+ $options_manager->set_option( $this->_id, $all_data, true );
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Delete key-value storage.
166
+ *
167
+ * @author Vova Feldman (@svovaf)
168
+ * @since 1.0.9
169
+ */
170
+ function delete() {
171
+ $this->_data = array();
172
+
173
+ $all_data = $this->get_all_data();
174
+ unset( $all_data[ $this->_slug ] );
175
+ $options_manager = $this->get_option_manager();
176
+ $options_manager->set_option( $this->_id, $all_data, true );
177
+ }
178
+
179
+ /**
180
+ * @author Vova Feldman (@svovaf)
181
+ * @since 1.0.7
182
+ *
183
+ * @param string $key
184
+ * @param bool $store
185
+ */
186
+ function remove( $key, $store = true ) {
187
+ if ( ! array_key_exists( $key, $this->_data ) ) {
188
+ return;
189
+ }
190
+
191
+ unset( $this->_data[ $key ] );
192
+
193
+ if ( $store ) {
194
+ $all_data = $this->get_all_data();
195
+ $all_data[ $this->_slug ] = $this->_data;
196
+ $options_manager = $this->get_option_manager();
197
+ $options_manager->set_option( $this->_id, $all_data, true );
198
+ }
199
+ }
200
+
201
+ /**
202
+ * @author Vova Feldman (@svovaf)
203
+ * @since 1.0.7
204
+ *
205
+ * @param string $key
206
+ * @param mixed $default
207
+ *
208
+ * @return bool|\FS_Plugin
209
+ */
210
+ function get( $key, $default = false ) {
211
+ return array_key_exists( $key, $this->_data ) ?
212
+ $this->_data[ $key ] :
213
+ $default;
214
+ }
215
+
216
+
217
+ /* ArrayAccess + Magic Access (better for refactoring)
218
+ -----------------------------------------------------------------------------------*/
219
+ function __set( $k, $v ) {
220
+ $this->store( $k, $v );
221
+ }
222
+
223
+ function __isset( $k ) {
224
+ return array_key_exists( $k, $this->_data );
225
+ }
226
+
227
+ function __unset( $k ) {
228
+ $this->remove( $k );
229
+ }
230
+
231
+ function __get( $k ) {
232
+ return $this->get( $k, null );
233
+ }
234
+
235
+ function offsetSet( $k, $v ) {
236
+ if ( is_null( $k ) ) {
237
+ throw new Exception( 'Can\'t append value to request params.' );
238
+ } else {
239
+ $this->{$k} = $v;
240
+ }
241
+ }
242
+
243
+ function offsetExists( $k ) {
244
+ return array_key_exists( $k, $this->_data );
245
+ }
246
+
247
+ function offsetUnset( $k ) {
248
+ unset( $this->$k );
249
+ }
250
+
251
+ function offsetGet( $k ) {
252
+ return $this->get( $k, null );
253
+ }
254
+
255
+ /**
256
+ * (PHP 5 &gt;= 5.0.0)<br/>
257
+ * Return the current element
258
+ *
259
+ * @link http://php.net/manual/en/iterator.current.php
260
+ * @return mixed Can return any type.
261
+ */
262
+ public function current() {
263
+ return current( $this->_data );
264
+ }
265
+
266
+ /**
267
+ * (PHP 5 &gt;= 5.0.0)<br/>
268
+ * Move forward to next element
269
+ *
270
+ * @link http://php.net/manual/en/iterator.next.php
271
+ * @return void Any returned value is ignored.
272
+ */
273
+ public function next() {
274
+ next( $this->_data );
275
+ }
276
+
277
+ /**
278
+ * (PHP 5 &gt;= 5.0.0)<br/>
279
+ * Return the key of the current element
280
+ *
281
+ * @link http://php.net/manual/en/iterator.key.php
282
+ * @return mixed scalar on success, or null on failure.
283
+ */
284
+ public function key() {
285
+ return key( $this->_data );
286
+ }
287
+
288
+ /**
289
+ * (PHP 5 &gt;= 5.0.0)<br/>
290
+ * Checks if current position is valid
291
+ *
292
+ * @link http://php.net/manual/en/iterator.valid.php
293
+ * @return boolean The return value will be casted to boolean and then evaluated.
294
+ * Returns true on success or false on failure.
295
+ */
296
+ public function valid() {
297
+ $key = key( $this->_data );
298
+
299
+ return ( $key !== null && $key !== false );
300
+ }
301
+
302
+ /**
303
+ * (PHP 5 &gt;= 5.0.0)<br/>
304
+ * Rewind the Iterator to the first element
305
+ *
306
+ * @link http://php.net/manual/en/iterator.rewind.php
307
+ * @return void Any returned value is ignored.
308
+ */
309
+ public function rewind() {
310
+ reset( $this->_data );
311
+ }
312
+
313
+ /**
314
+ * (PHP 5 &gt;= 5.1.0)<br/>
315
+ * Count elements of an object
316
+ *
317
+ * @link http://php.net/manual/en/countable.count.php
318
+ * @return int The custom count as an integer.
319
+ * </p>
320
+ * <p>
321
+ * The return value is cast to an integer.
322
+ */
323
+ public function count() {
324
+ return count( $this->_data );
325
+ }
326
+ }
freemius/includes/managers/class-fs-license-manager.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_License_Manager /*extends FS_Abstract_Manager*/
14
+ {
15
+ //
16
+ //
17
+ // /**
18
+ // * @var FS_License_Manager[]
19
+ // */
20
+ // private static $_instances = array();
21
+ //
22
+ // static function instance( Freemius $fs ) {
23
+ // $slug = strtolower( $fs->get_slug() );
24
+ //
25
+ // if ( ! isset( self::$_instances[ $slug ] ) ) {
26
+ // self::$_instances[ $slug ] = new FS_License_Manager( $slug, $fs );
27
+ // }
28
+ //
29
+ // return self::$_instances[ $slug ];
30
+ // }
31
+ //
32
+ //// private function __construct($slug) {
33
+ //// parent::__construct($slug);
34
+ //// }
35
+ //
36
+ // function entry_id() {
37
+ // return 'licenses';
38
+ // }
39
+ //
40
+ // function sync( $id ) {
41
+ //
42
+ // }
43
+ //
44
+ // /**
45
+ // * @author Vova Feldman (@svovaf)
46
+ // * @since 1.0.5
47
+ // * @uses FS_Api
48
+ // *
49
+ // * @param number|bool $plugin_id
50
+ // *
51
+ // * @return FS_Plugin_License[]|stdClass Licenses or API error.
52
+ // */
53
+ // function api_get_user_plugin_licenses( $plugin_id = false ) {
54
+ // $api = $this->_fs->get_api_user_scope();
55
+ //
56
+ // if ( ! is_numeric( $plugin_id ) ) {
57
+ // $plugin_id = $this->_fs->get_id();
58
+ // }
59
+ //
60
+ // $result = $api->call( "/plugins/{$plugin_id}/licenses.json" );
61
+ //
62
+ // if ( ! isset( $result->error ) ) {
63
+ // for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
64
+ // $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
65
+ // }
66
+ //
67
+ // $result = $result->licenses;
68
+ // }
69
+ //
70
+ // return $result;
71
+ // }
72
+ //
73
+ // function api_get_many() {
74
+ //
75
+ // }
76
+ //
77
+ // function api_activate( $id ) {
78
+ //
79
+ // }
80
+ //
81
+ // function api_deactivate( $id ) {
82
+ //
83
+ // }
84
+
85
+ /**
86
+ * @param FS_Plugin_License[] $licenses
87
+ *
88
+ * @return bool
89
+ */
90
+ static function has_premium_license( $licenses ) {
91
+ if ( is_array( $licenses ) ) {
92
+ foreach ( $licenses as $license ) {
93
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
94
+ return true;
95
+ }
96
+ }
97
+ }
98
+
99
+ return false;
100
+ }
101
+ }
freemius/includes/managers/class-fs-option-manager.php ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * 3-layer lazy options manager.
15
+ * layer 3: Memory
16
+ * layer 2: Cache (if there's any caching plugin and if WP_FS__DEBUG_SDK is FALSE)
17
+ * layer 1: Database (options table). All options stored as one option record in the DB to reduce number of DB
18
+ * queries.
19
+ *
20
+ * If load() is not explicitly called, starts as empty manager. Same thing about saving the data - you have to
21
+ * explicitly call store().
22
+ *
23
+ * Class Freemius_Option_Manager
24
+ */
25
+ class FS_Option_Manager {
26
+ /**
27
+ * @var string
28
+ */
29
+ private $_id;
30
+ /**
31
+ * @var array
32
+ */
33
+ private $_options;
34
+ /**
35
+ * @var FS_Logger
36
+ */
37
+ private $_logger;
38
+
39
+ /**
40
+ * @var FS_Option_Manager[]
41
+ */
42
+ private static $_MANAGERS = array();
43
+
44
+ /**
45
+ * @author Vova Feldman (@svovaf)
46
+ * @since 1.0.3
47
+ *
48
+ * @param string $id
49
+ * @param bool $load
50
+ */
51
+ private function __construct( $id, $load = false ) {
52
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_opt_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
53
+
54
+ $this->_logger->entrance();
55
+ $this->_logger->log( 'id = ' . $id );
56
+
57
+ $this->_id = $id;
58
+
59
+ if ( $load ) {
60
+ $this->load();
61
+ }
62
+ }
63
+
64
+ /**
65
+ * @author Vova Feldman (@svovaf)
66
+ * @since 1.0.3
67
+ *
68
+ * @param $id
69
+ * @param $load
70
+ *
71
+ * @return FS_Option_Manager
72
+ */
73
+ static function get_manager( $id, $load = false ) {
74
+ $id = strtolower( $id );
75
+
76
+ if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
77
+ self::$_MANAGERS[ $id ] = new FS_Option_Manager( $id, $load );
78
+ } // If load required but not yet loaded, load.
79
+ else if ( $load && ! self::$_MANAGERS[ $id ]->is_loaded() ) {
80
+ self::$_MANAGERS[ $id ]->load();
81
+ }
82
+
83
+ return self::$_MANAGERS[ $id ];
84
+ }
85
+
86
+ private function _get_option_manager_name() {
87
+ // return WP_FS__SLUG . '_' . $this->_id;
88
+ return $this->_id;
89
+ }
90
+
91
+ /**
92
+ * @author Vova Feldman (@svovaf)
93
+ * @since 1.0.3
94
+ *
95
+ * @param bool $flush
96
+ */
97
+ function load( $flush = false ) {
98
+ $this->_logger->entrance();
99
+
100
+ $option_name = $this->_get_option_manager_name();
101
+
102
+ if ( $flush || ! isset( $this->_options ) ) {
103
+ if ( isset( $this->_options ) ) {
104
+ // Clear prev options.
105
+ $this->clear();
106
+ }
107
+
108
+ if ( ! WP_FS__DEBUG_SDK ) {
109
+ $this->_options = wp_cache_get( $option_name, WP_FS__SLUG );
110
+ }
111
+
112
+ // $this->_logger->info('wp_cache_get = ' . var_export($this->_options, true));
113
+
114
+ // if ( is_array( $this->_options ) ) {
115
+ // $this->clear();
116
+ // }
117
+
118
+ $cached = true;
119
+
120
+ if ( empty( $this->_options ) ) {
121
+ $this->_options = get_option( $option_name );
122
+
123
+ if ( is_string( $this->_options ) ) {
124
+ $this->_options = json_decode( $this->_options );
125
+ }
126
+
127
+ // $this->_logger->info('get_option = ' . var_export($this->_options, true));
128
+
129
+ if ( false === $this->_options ) {
130
+ $this->clear();
131
+ }
132
+
133
+ $cached = false;
134
+ }
135
+
136
+ if ( ! WP_FS__DEBUG_SDK && ! $cached ) // Set non encoded cache.
137
+ {
138
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
139
+ }
140
+ }
141
+ }
142
+
143
+ /**
144
+ * @author Vova Feldman (@svovaf)
145
+ * @since 1.0.3
146
+ *
147
+ * @return bool
148
+ */
149
+ function is_loaded() {
150
+ return isset( $this->_options );
151
+ }
152
+
153
+ /**
154
+ * @author Vova Feldman (@svovaf)
155
+ * @since 1.0.3
156
+ *
157
+ * @return bool
158
+ */
159
+ function is_empty() {
160
+ return ( $this->is_loaded() && false === $this->_options );
161
+ }
162
+
163
+ /**
164
+ * @author Vova Feldman (@svovaf)
165
+ * @since 1.0.6
166
+ *
167
+ * @param bool $flush
168
+ */
169
+ function clear( $flush = false ) {
170
+ $this->_logger->entrance();
171
+
172
+ $this->_options = array();
173
+
174
+ if ( $flush ) {
175
+ $this->store();
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Delete options manager from DB.
181
+ *
182
+ * @author Vova Feldman (@svovaf)
183
+ * @since 1.0.9
184
+ */
185
+ function delete() {
186
+ delete_option( $this->_get_option_manager_name() );
187
+ }
188
+
189
+ /**
190
+ * @author Vova Feldman (@svovaf)
191
+ * @since 1.0.6
192
+ *
193
+ * @param string $option
194
+ *
195
+ * @return bool
196
+ */
197
+ function has_option( $option ) {
198
+ return array_key_exists( $option, $this->_options );
199
+ }
200
+
201
+ /**
202
+ * @author Vova Feldman (@svovaf)
203
+ * @since 1.0.3
204
+ *
205
+ * @param string $option
206
+ * @param mixed $default
207
+ *
208
+ * @return mixed
209
+ */
210
+ function get_option( $option, $default = null ) {
211
+ $this->_logger->entrance( 'option = ' . $option );
212
+
213
+ if ( is_array( $this->_options ) ) {
214
+ return isset( $this->_options[ $option ] ) ? $this->_options[ $option ] : $default;
215
+ } else if ( is_object( $this->_options ) ) {
216
+ return isset( $this->_options->{$option} ) ? $this->_options->{$option} : $default;
217
+ }
218
+
219
+ return $default;
220
+ }
221
+
222
+ /**
223
+ * @author Vova Feldman (@svovaf)
224
+ * @since 1.0.3
225
+ *
226
+ * @param string $option
227
+ * @param mixed $value
228
+ * @param bool $flush
229
+ */
230
+ function set_option( $option, $value, $flush = false ) {
231
+ $this->_logger->entrance( 'option = ' . $option );
232
+
233
+ if ( ! $this->is_loaded() ) {
234
+ $this->clear();
235
+ }
236
+
237
+ if ( is_array( $this->_options ) ) {
238
+ $this->_options[ $option ] = $value;
239
+ } else if ( is_object( $this->_options ) ) {
240
+ $this->_options->{$option} = $value;
241
+ }
242
+
243
+ if ( $flush ) {
244
+ $this->store();
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Unset option.
250
+ *
251
+ * @author Vova Feldman (@svovaf)
252
+ * @since 1.0.3
253
+ *
254
+ * @param string $option
255
+ * @param bool $flush
256
+ */
257
+ function unset_option( $option, $flush = false ) {
258
+ $this->_logger->entrance( 'option = ' . $option );
259
+
260
+ if ( is_array( $this->_options ) ) {
261
+ if ( ! isset( $this->_options[ $option ] ) ) {
262
+ return;
263
+ }
264
+
265
+ unset( $this->_options[ $option ] );
266
+
267
+ } else if ( is_object( $this->_options ) ) {
268
+ if ( ! isset( $this->_options->{$option} ) ) {
269
+ return;
270
+ }
271
+
272
+ unset( $this->_options->{$option} );
273
+ }
274
+
275
+ if ( $flush ) {
276
+ $this->store();
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Dump options to database.
282
+ *
283
+ * @author Vova Feldman (@svovaf)
284
+ * @since 1.0.3
285
+ */
286
+ function store() {
287
+ $this->_logger->entrance();
288
+
289
+ $option_name = $this->_get_option_manager_name();
290
+
291
+ if ( $this->_logger->is_on() ) {
292
+ $this->_logger->info( $option_name . ' = ' . var_export( $this->_options, true ) );
293
+ }
294
+
295
+ // Update DB.
296
+ update_option( $option_name, $this->_options );
297
+
298
+ if ( ! WP_FS__DEBUG_SDK ) {
299
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
300
+ }
301
+ }
302
+ }
freemius/includes/managers/class-fs-plan-manager.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plan_Manager {
14
+ /**
15
+ * @var FS_Plan_Manager
16
+ */
17
+ private static $_instance;
18
+
19
+ /**
20
+ * @return FS_Plan_Manager
21
+ */
22
+ static function instance() {
23
+ if ( ! isset( self::$_instance ) ) {
24
+ self::$_instance = new FS_Plan_Manager();
25
+ }
26
+
27
+ return self::$_instance;
28
+ }
29
+
30
+ private function __construct() {
31
+ }
32
+
33
+ /**
34
+ * @param FS_Plugin_License[] $licenses
35
+ *
36
+ * @return bool
37
+ */
38
+ function has_premium_license( $licenses ) {
39
+ if ( is_array( $licenses ) ) {
40
+ /**
41
+ * @var FS_Plugin_License[] $licenses
42
+ */
43
+ foreach ( $licenses as $license ) {
44
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
45
+ return true;
46
+ }
47
+ }
48
+ }
49
+
50
+ return false;
51
+ }
52
+
53
+ /**
54
+ * Check if plugin has any paid plans.
55
+ *
56
+ * @author Vova Feldman (@svovaf)
57
+ * @since 1.0.7
58
+ *
59
+ * @param FS_Plugin_Plan[] $plans
60
+ *
61
+ * @return bool
62
+ */
63
+ function has_paid_plan( $plans ) {
64
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
65
+ return false;
66
+ }
67
+
68
+ /**
69
+ * @var FS_Plugin_Plan[] $plans
70
+ */
71
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
72
+ if ( ! $plans[ $i ]->is_free() ) {
73
+ return true;
74
+ }
75
+ }
76
+
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * Check if plugin has any free plan, or is it premium only.
82
+ *
83
+ * Note: If no plans configured, assume plugin is free.
84
+ *
85
+ * @author Vova Feldman (@svovaf)
86
+ * @since 1.0.7
87
+ *
88
+ * @param FS_Plugin_Plan[] $plans
89
+ *
90
+ * @return bool
91
+ */
92
+ function has_free_plan( $plans ) {
93
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
94
+ return true;
95
+ }
96
+
97
+ /**
98
+ * @var FS_Plugin_Plan[] $plans
99
+ */
100
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
101
+ if ( $plans[ $i ]->is_free() ) {
102
+ return true;
103
+ }
104
+ }
105
+
106
+ return false;
107
+ }
108
+
109
+ /**
110
+ * Find all plans that have trial.
111
+ *
112
+ * @author Vova Feldman (@svovaf)
113
+ * @since 1.0.9
114
+ *
115
+ * @param FS_Plugin_Plan[] $plans
116
+ *
117
+ * @return FS_Plugin_Plan[]
118
+ */
119
+ function get_trial_plans( $plans ) {
120
+ $trial_plans = array();
121
+
122
+ if ( is_array( $plans ) && 0 < count( $plans ) ) {
123
+ /**
124
+ * @var FS_Plugin_Plan[] $plans
125
+ */
126
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
127
+ if ( $plans[ $i ]->has_trial() ) {
128
+ $trial_plans[] = $plans[ $i ];
129
+ }
130
+ }
131
+ }
132
+
133
+ return $trial_plans;
134
+ }
135
+
136
+ /**
137
+ * Check if plugin has any trial plan.
138
+ *
139
+ * @author Vova Feldman (@svovaf)
140
+ * @since 1.0.9
141
+ *
142
+ * @param FS_Plugin_Plan[] $plans
143
+ *
144
+ * @return bool
145
+ */
146
+ function has_trial_plan( $plans ) {
147
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
148
+ return true;
149
+ }
150
+
151
+ /**
152
+ * @var FS_Plugin_Plan[] $plans
153
+ */
154
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
155
+ if ( $plans[ $i ]->has_trial() ) {
156
+ return true;
157
+ }
158
+ }
159
+
160
+ return false;
161
+ }
162
+ }
freemius/includes/managers/class-fs-plugin-manager.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Manager {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_slug;
18
+ /**
19
+ * @var FS_Plugin
20
+ */
21
+ protected $_plugin;
22
+
23
+ /**
24
+ * @var FS_Plugin_Manager[]
25
+ */
26
+ private static $_instances = array();
27
+ /**
28
+ * @var FS_Logger
29
+ */
30
+ protected $_logger;
31
+
32
+ /**
33
+ * @param string $slug
34
+ *
35
+ * @return FS_Plugin_Manager
36
+ */
37
+ static function instance( $slug ) {
38
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
39
+ self::$_instances[ $slug ] = new FS_Plugin_Manager( $slug );
40
+ }
41
+
42
+ return self::$_instances[ $slug ];
43
+ }
44
+
45
+ protected function __construct( $slug ) {
46
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . 'plugins', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
47
+
48
+ $this->_slug = $slug;
49
+ $this->load();
50
+ }
51
+
52
+ protected function get_option_manager() {
53
+ return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
54
+ }
55
+
56
+ protected function get_all_plugins() {
57
+ return $this->get_option_manager()->get_option( 'plugins', array() );
58
+ }
59
+
60
+ /**
61
+ * Load plugin data from local DB.
62
+ *
63
+ * @author Vova Feldman (@svovaf)
64
+ * @since 1.0.6
65
+ */
66
+ function load() {
67
+ $all_plugins = $this->get_all_plugins();
68
+ $this->_plugin = isset( $all_plugins[ $this->_slug ] ) ?
69
+ $all_plugins[ $this->_slug ] :
70
+ null;
71
+ }
72
+
73
+ /**
74
+ * Store plugin on local DB.
75
+ *
76
+ * @author Vova Feldman (@svovaf)
77
+ * @since 1.0.6
78
+ *
79
+ * @param bool|FS_Plugin $plugin
80
+ * @param bool $flush
81
+ *
82
+ * @return bool|\FS_Plugin
83
+ */
84
+ function store( $plugin = false, $flush = true ) {
85
+ $all_plugins = $this->get_all_plugins();
86
+
87
+ if ( false !== $plugin ) {
88
+ $this->_plugin = $plugin;
89
+ }
90
+
91
+ $all_plugins[ $this->_slug ] = $this->_plugin;
92
+
93
+ $options_manager = $this->get_option_manager();
94
+ $options_manager->set_option( 'plugins', $all_plugins, $flush );
95
+
96
+ return $this->_plugin;
97
+ }
98
+
99
+ /**
100
+ * Update local plugin data if different.
101
+ *
102
+ * @author Vova Feldman (@svovaf)
103
+ * @since 1.0.6
104
+ *
105
+ * @param \FS_Plugin $plugin
106
+ * @param bool $store
107
+ *
108
+ * @return bool True if plugin was updated.
109
+ */
110
+ function update( FS_Plugin $plugin, $store = true ) {
111
+ if ( ! ( $this->_plugin instanceof FS_Plugin ) ||
112
+ $this->_plugin->slug != $plugin->slug ||
113
+ $this->_plugin->public_key != $plugin->public_key ||
114
+ $this->_plugin->secret_key != $plugin->secret_key ||
115
+ $this->_plugin->parent_plugin_id != $plugin->parent_plugin_id ||
116
+ $this->_plugin->title != $plugin->title
117
+ ) {
118
+ $this->store( $plugin, $store );
119
+
120
+ return true;
121
+ }
122
+
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * @author Vova Feldman (@svovaf)
128
+ * @since 1.0.6
129
+ *
130
+ * @param FS_Plugin $plugin
131
+ * @param bool $store
132
+ */
133
+ function set( FS_Plugin $plugin, $store = false ) {
134
+ $this->_plugin = $plugin;
135
+
136
+ if ( $store ) {
137
+ $this->store();
138
+ }
139
+ }
140
+
141
+ /**
142
+ * @author Vova Feldman (@svovaf)
143
+ * @since 1.0.6
144
+ *
145
+ * @return bool|\FS_Plugin
146
+ */
147
+ function get() {
148
+ return isset( $this->_plugin ) ?
149
+ $this->_plugin :
150
+ false;
151
+ }
152
+
153
+
154
+ }
freemius/includes/sdk/Exceptions/ArgumentNotExistException.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_ArgumentNotExistException extends Freemius_InvalidArgumentException { }
freemius/includes/sdk/Exceptions/EmptyArgumentException.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_EmptyArgumentException extends Freemius_InvalidArgumentException { }
freemius/includes/sdk/Exceptions/Exception.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Thrown when an API call returns an exception.
4
+ *
5
+ */
6
+ class Freemius_Exception extends Exception
7
+ {
8
+ protected $_result;
9
+ protected $_type;
10
+ protected $_code;
11
+
12
+ /**
13
+ * Make a new API Exception with the given result.
14
+ *
15
+ * @param array $result The result from the API server.
16
+ */
17
+ public function __construct($result)
18
+ {
19
+ $this->_result = $result;
20
+
21
+ $code = 0;
22
+ $message = 'Unknown error, please check GetResult().';
23
+ $type = '';
24
+
25
+ if (isset($result['error']) && is_array($result['error']))
26
+ {
27
+ if (isset($result['error']['code']))
28
+ $code = $result['error']['code'];
29
+ if (isset($result['error']['message']))
30
+ $message = $result['error']['message'];
31
+ if (isset($result['error']['type']))
32
+ $type = $result['error']['type'];
33
+ }
34
+
35
+ $this->_type = $type;
36
+ $this->_code = $code;
37
+
38
+ parent::__construct($message, is_numeric($code) ? $code : 0);
39
+ }
40
+
41
+ /**
42
+ * Return the associated result object returned by the API server.
43
+ *
44
+ * @return array The result from the API server
45
+ */
46
+ public function getResult()
47
+ {
48
+ return $this->_result;
49
+ }
50
+
51
+ public function getStringCode()
52
+ {
53
+ return $this->_code;
54
+ }
55
+
56
+ public function getType()
57
+ {
58
+ return $this->_type;
59
+ }
60
+
61
+ /**
62
+ * To make debugging easier.
63
+ *
64
+ * @return string The string representation of the error
65
+ */
66
+ public function __toString()
67
+ {
68
+ $str = $this->getType() . ': ';
69
+
70
+ if ($this->code != 0)
71
+ $str .= $this->getStringCode() . ': ';
72
+
73
+ return $str . $this->getMessage();
74
+ }
75
+ }
freemius/includes/sdk/Exceptions/InvalidArgumentException.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_Exception' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_InvalidArgumentException extends Freemius_Exception { }
freemius/includes/sdk/Exceptions/OAuthException.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_Exception' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_OAuthException extends Freemius_Exception
7
+ {
8
+ public function __construct($pResult)
9
+ {
10
+ parent::__construct($pResult);
11
+ }
12
+ }
freemius/includes/sdk/Freemius.php ADDED
@@ -0,0 +1,576 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2014 Freemius, Inc.
4
+ *
5
+ * Licensed under the GPL v2 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://choosealicense.com/licenses/gpl-v2/
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ require_once( dirname( __FILE__ ) . '/FreemiusBase.php' );
19
+
20
+ define( 'FS_SDK__USER_AGENT', 'fs-php-' . Freemius_Api_Base::VERSION );
21
+
22
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_CURL' ) ) {
23
+ define( 'FS_SDK__SIMULATE_NO_CURL', false );
24
+ }
25
+
26
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
27
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
28
+ }
29
+
30
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
31
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
32
+ }
33
+
34
+ define( 'FS_SDK__HAS_CURL', ! FS_SDK__SIMULATE_NO_CURL && function_exists( 'curl_version' ) );
35
+
36
+ if ( ! FS_SDK__HAS_CURL ) {
37
+ $curl_version = array( 'version' => '7.0.0' );
38
+ } else {
39
+ $curl_version = curl_version();
40
+ }
41
+
42
+ define( 'FS_API__PROTOCOL', version_compare( $curl_version['version'], '7.37', '>=' ) ? 'https' : 'http' );
43
+
44
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
45
+ define( 'FS_API__LOGGER_ON', false );
46
+ }
47
+
48
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
49
+ define( 'FS_API__ADDRESS', '://api.freemius.com' );
50
+ }
51
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
52
+ define( 'FS_API__SANDBOX_ADDRESS', '://sandbox-api.freemius.com' );
53
+ }
54
+
55
+ class Freemius_Api extends Freemius_Api_Base {
56
+ private static $_logger = array();
57
+
58
+ /**
59
+ * @param string $pScope 'app', 'developer', 'user' or 'install'.
60
+ * @param number $pID Element's id.
61
+ * @param string $pPublic Public key.
62
+ * @param string|bool $pSecret Element's secret key.
63
+ * @param bool $pSandbox Whether or not to run API in sandbox mode.
64
+ */
65
+ public function __construct( $pScope, $pID, $pPublic, $pSecret = false, $pSandbox = false ) {
66
+ // If secret key not provided, use public key encryption.
67
+ if ( is_bool( $pSecret ) ) {
68
+ $pSecret = $pPublic;
69
+ }
70
+
71
+ parent::Init( $pScope, $pID, $pPublic, $pSecret, $pSandbox );
72
+ }
73
+
74
+ public static function GetUrl( $pCanonizedPath = '', $pIsSandbox = false ) {
75
+ $address = ( $pIsSandbox ? FS_API__SANDBOX_ADDRESS : FS_API__ADDRESS );
76
+
77
+ if ( ':' === $address[0] ) {
78
+ $address = self::$_protocol . $address;
79
+ }
80
+
81
+ return $address . $pCanonizedPath;
82
+ }
83
+
84
+ #region Servers Clock Diff ------------------------------------------------------
85
+
86
+ /**
87
+ * @var int Clock diff in seconds between current server to API server.
88
+ */
89
+ private static $_clock_diff = 0;
90
+
91
+ /**
92
+ * Set clock diff for all API calls.
93
+ *
94
+ * @since 1.0.3
95
+ *
96
+ * @param $pSeconds
97
+ */
98
+ public static function SetClockDiff( $pSeconds ) {
99
+ self::$_clock_diff = $pSeconds;
100
+ }
101
+
102
+ /**
103
+ * Find clock diff between current server to API server.
104
+ *
105
+ * @since 1.0.2
106
+ * @return int Clock diff in seconds.
107
+ */
108
+ public static function FindClockDiff() {
109
+ $time = time();
110
+ $pong = self::Ping();
111
+
112
+ return ( $time - strtotime( $pong->timestamp ) );
113
+ }
114
+
115
+ #endregion Servers Clock Diff ------------------------------------------------------
116
+
117
+ /**
118
+ * @var string http or https
119
+ */
120
+ private static $_protocol = FS_API__PROTOCOL;
121
+
122
+ /**
123
+ * Set API connection protocol.
124
+ *
125
+ * @since 1.0.4
126
+ */
127
+ public static function SetHttp() {
128
+ self::$_protocol = 'http';
129
+ }
130
+
131
+ /**
132
+ * @since 1.0.4
133
+ *
134
+ * @return bool
135
+ */
136
+ public static function IsHttps() {
137
+ return ( 'https' === self::$_protocol );
138
+ }
139
+
140
+ /**
141
+ * Sign request with the following HTTP headers:
142
+ * Content-MD5: MD5(HTTP Request body)
143
+ * Date: Current date (i.e Sat, 14 Feb 2015 20:24:46 +0000)
144
+ * Authorization: FS {scope_entity_id}:{scope_entity_public_key}:base64encode(sha256(string_to_sign,
145
+ * {scope_entity_secret_key}))
146
+ *
147
+ * @param string $pResourceUrl
148
+ * @param array $pCurlOptions
149
+ *
150
+ * @return array
151
+ */
152
+ function SignRequest( $pResourceUrl, $pCurlOptions ) {
153
+ $eol = "\n";
154
+ $content_md5 = '';
155
+ $now = ( time() - self::$_clock_diff );
156
+ $date = date( 'r', $now );
157
+ $content_type = '';
158
+
159
+ if ( isset( $pCurlOptions[ CURLOPT_POST ] ) && 0 < $pCurlOptions[ CURLOPT_POST ] ) {
160
+ $content_md5 = md5( $pCurlOptions[ CURLOPT_POSTFIELDS ] );
161
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Content-MD5: ' . $content_md5;
162
+ $content_type = 'application/json';
163
+ }
164
+
165
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Date: ' . $date;
166
+
167
+ $string_to_sign = implode( $eol, array(
168
+ $pCurlOptions[ CURLOPT_CUSTOMREQUEST ],
169
+ $content_md5,
170
+ $content_type,
171
+ $date,
172
+ $pResourceUrl
173
+ ) );
174
+
175
+ // If secret and public keys are identical, it means that
176
+ // the signature uses public key hash encoding.
177
+ $auth_type = ( $this->_secret !== $this->_public ) ? 'FS' : 'FSP';
178
+
179
+ // Add authorization header.
180
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Authorization: ' .
181
+ $auth_type . ' ' .
182
+ $this->_id . ':' .
183
+ $this->_public . ':' .
184
+ self::Base64UrlEncode(
185
+ hash_hmac( 'sha256', $string_to_sign, $this->_secret )
186
+ );
187
+
188
+ return $pCurlOptions;
189
+ }
190
+
191
+ /**
192
+ * Get API request URL signed via query string.
193
+ *
194
+ * @param string $pPath
195
+ *
196
+ * @throws Freemius_Exception
197
+ *
198
+ * @return string
199
+ */
200
+ function GetSignedUrl( $pPath ) {
201
+ $resource = explode( '?', $this->CanonizePath( $pPath ) );
202
+ $pResourceUrl = $resource[0];
203
+
204
+ $eol = "\n";
205
+ $content_md5 = '';
206
+ $content_type = '';
207
+ $now = ( time() - self::$_clock_diff );
208
+ $date = date( 'r', $now );
209
+
210
+ $string_to_sign = implode( $eol, array(
211
+ 'GET',
212
+ $content_md5,
213
+ $content_type,
214
+ $date,
215
+ $pResourceUrl
216
+ ) );
217
+
218
+ // If secret and public keys are identical, it means that
219
+ // the signature uses public key hash encoding.
220
+ $auth_type = ( $this->_secret !== $this->_public ) ? 'FS' : 'FSP';
221
+
222
+ return Freemius_Api::GetUrl(
223
+ $pResourceUrl . '?' .
224
+ ( 1 < count( $resource ) && ! empty( $resource[1] ) ? $resource[1] . '&' : '' ) .
225
+ http_build_query( array(
226
+ 'auth_date' => $date,
227
+ 'authorization' => $auth_type . ' ' . $this->_id . ':' .
228
+ $this->_public . ':' .
229
+ self::Base64UrlEncode( hash_hmac(
230
+ 'sha256', $string_to_sign, $this->_secret
231
+ ) )
232
+ ) ), $this->_isSandbox );
233
+ }
234
+
235
+ /**
236
+ * @param resource $pCurlHandler
237
+ * @param array $pCurlOptions
238
+ *
239
+ * @return mixed
240
+ */
241
+ private static function ExecuteRequest( &$pCurlHandler, &$pCurlOptions ) {
242
+ $start = microtime( true );
243
+
244
+ $result = curl_exec( $pCurlHandler );
245
+
246
+ if ( FS_API__LOGGER_ON ) {
247
+ $end = microtime( true );
248
+
249
+ $has_body = ( isset( $pCurlOptions[ CURLOPT_POST ] ) && 0 < $pCurlOptions[ CURLOPT_POST ] );
250
+
251
+ self::$_logger[] = array(
252
+ 'id' => count( self::$_logger ),
253
+ 'start' => $start,
254
+ 'end' => $end,
255
+ 'total' => ( $end - $start ),
256
+ 'method' => $pCurlOptions[ CURLOPT_CUSTOMREQUEST ],
257
+ 'path' => $pCurlOptions[ CURLOPT_URL ],
258
+ 'body' => $has_body ? $pCurlOptions[ CURLOPT_POSTFIELDS ] : null,
259
+ 'result' => $result,
260
+ 'code' => curl_getinfo( $pCurlHandler, CURLINFO_HTTP_CODE ),
261
+ 'backtrace' => debug_backtrace(),
262
+ );
263
+ }
264
+
265
+ return $result;
266
+ }
267
+
268
+ /**
269
+ * @return array
270
+ */
271
+ static function GetLogger() {
272
+ return self::$_logger;
273
+ }
274
+
275
+ /**
276
+ * @param string $pCanonizedPath
277
+ * @param string $pMethod
278
+ * @param array $pParams
279
+ * @param null|resource $pCurlHandler
280
+ * @param bool $pIsSandbox
281
+ * @param null|callable $pBeforeExecutionFunction
282
+ *
283
+ * @return object[]|object|null
284
+ *
285
+ * @throws \Freemius_Exception
286
+ */
287
+ private static function MakeStaticRequest(
288
+ $pCanonizedPath,
289
+ $pMethod = 'GET',
290
+ $pParams = array(),
291
+ $pCurlHandler = null,
292
+ $pIsSandbox = false,
293
+ $pBeforeExecutionFunction = null
294
+ ) {
295
+ if ( ! FS_SDK__HAS_CURL ) {
296
+ self::ThrowNoCurlException();
297
+ }
298
+
299
+ // Connectivity errors simulation.
300
+ if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
301
+ self::ThrowCloudFlareDDoSException();
302
+ } else if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
303
+ self::ThrowSquidAclException();
304
+ }
305
+
306
+ if ( ! $pCurlHandler ) {
307
+ $pCurlHandler = curl_init();
308
+ }
309
+
310
+ $opts = array(
311
+ CURLOPT_CONNECTTIMEOUT => 10,
312
+ CURLOPT_RETURNTRANSFER => true,
313
+ CURLOPT_TIMEOUT => 60,
314
+ CURLOPT_USERAGENT => FS_SDK__USER_AGENT,
315
+ );
316
+
317
+ if ( ! isset( $opts[ CURLOPT_HTTPHEADER ] ) || ! is_array( $opts[ CURLOPT_HTTPHEADER ] ) ) {
318
+ $opts[ CURLOPT_HTTPHEADER ] = array();
319
+ }
320
+
321
+ if ( 'POST' === $pMethod || 'PUT' === $pMethod ) {
322
+ if ( is_array( $pParams ) && 0 < count( $pParams ) ) {
323
+ $opts[ CURLOPT_HTTPHEADER ][] = 'Content-Type: application/json';
324
+ $opts[ CURLOPT_POST ] = count( $pParams );
325
+ $opts[ CURLOPT_POSTFIELDS ] = json_encode( $pParams );
326
+ }
327
+
328
+ $opts[ CURLOPT_RETURNTRANSFER ] = true;
329
+ }
330
+
331
+ $request_url = Freemius_Api::GetUrl( $pCanonizedPath, $pIsSandbox );
332
+
333
+ $opts[ CURLOPT_URL ] = $request_url;
334
+ $opts[ CURLOPT_CUSTOMREQUEST ] = $pMethod;
335
+
336
+ $resource = explode( '?', $pCanonizedPath );
337
+
338
+ // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
339
+ // for 2 seconds if the server does not support this header.
340
+ $opts[ CURLOPT_HTTPHEADER ][] = 'Expect:';
341
+
342
+ if ( 'https' === substr( strtolower( $request_url ), 0, 5 ) ) {
343
+ $opts[ CURLOPT_SSL_VERIFYHOST ] = false;
344
+ $opts[ CURLOPT_SSL_VERIFYPEER ] = false;
345
+ }
346
+
347
+ if ( false !== $pBeforeExecutionFunction &&
348
+ is_callable( $pBeforeExecutionFunction )
349
+ ) {
350
+ $opts = call_user_func( $pBeforeExecutionFunction, $resource[0], $opts );
351
+ }
352
+
353
+ curl_setopt_array( $pCurlHandler, $opts );
354
+ $result = self::ExecuteRequest( $pCurlHandler, $opts );
355
+
356
+ /*if (curl_errno($ch) == 60) // CURLE_SSL_CACERT
357
+ {
358
+ self::errorLog('Invalid or no certificate authority found, using bundled information');
359
+ curl_setopt($ch, CURLOPT_CAINFO,
360
+ dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
361
+ $result = curl_exec($ch);
362
+ }*/
363
+
364
+ // With dual stacked DNS responses, it's possible for a server to
365
+ // have IPv6 enabled but not have IPv6 connectivity. If this is
366
+ // the case, curl will try IPv4 first and if that fails, then it will
367
+ // fall back to IPv6 and the error EHOSTUNREACH is returned by the
368
+ // operating system.
369
+ if ( false === $result && empty( $opts[ CURLOPT_IPRESOLVE ] ) ) {
370
+ $matches = array();
371
+ $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
372
+ if ( preg_match( $regex, curl_error( $pCurlHandler ), $matches ) ) {
373
+ if ( strlen( @inet_pton( $matches[1] ) ) === 16 ) {
374
+ // self::errorLog('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.');
375
+ $opts[ CURLOPT_IPRESOLVE ] = CURL_IPRESOLVE_V4;
376
+ curl_setopt( $pCurlHandler, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
377
+ $result = self::ExecuteRequest( $pCurlHandler, $opts );
378
+ }
379
+ }
380
+ }
381
+
382
+ if ( $result === false ) {
383
+ self::ThrowCurlException( $pCurlHandler );
384
+ }
385
+
386
+ curl_close( $pCurlHandler );
387
+
388
+ if ( empty( $result ) ) {
389
+ return null;
390
+ }
391
+
392
+ $decoded = json_decode( $result );
393
+
394
+ if ( is_null( $decoded ) ) {
395
+ if ( preg_match( '/Please turn JavaScript on/i', $result ) &&
396
+ preg_match( '/text\/javascript/', $result )
397
+ ) {
398
+ self::ThrowCloudFlareDDoSException( $result );
399
+ } else if ( preg_match( '/Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect./', $result ) &&
400
+ preg_match( '/squid/', $result )
401
+ ) {
402
+ self::ThrowSquidAclException( $result );
403
+ } else {
404
+ $decoded = (object) array(
405
+ 'error' => (object) array(
406
+ 'type' => 'Unknown',
407
+ 'message' => $result,
408
+ 'code' => 'unknown',
409
+ 'http' => 402
410
+ )
411
+ );
412
+ }
413
+ }
414
+
415
+ return $decoded;
416
+ }
417
+
418
+
419
+ /**
420
+ * Makes an HTTP request. This method can be overridden by subclasses if
421
+ * developers want to do fancier things or use something other than curl to
422
+ * make the request.
423
+ *
424
+ * @param string $pCanonizedPath The URL to make the request to
425
+ * @param string $pMethod HTTP method
426
+ * @param array $pParams The parameters to use for the POST body
427
+ * @param null|resource $pCurlHandler Initialized curl handle
428
+ *
429
+ * @return object[]|object|null
430
+ *
431
+ * @throws Freemius_Exception
432
+ */
433
+ public function MakeRequest(
434
+ $pCanonizedPath,
435
+ $pMethod = 'GET',
436
+ $pParams = array(),
437
+ $pCurlHandler = null
438
+ ) {
439
+ $resource = explode( '?', $pCanonizedPath );
440
+
441
+ // Only sign request if not ping.json connectivity test.
442
+ $sign_request = ( '/v1/ping.json' !== strtolower( substr( $resource[0], - strlen( '/v1/ping.json' ) ) ) );
443
+
444
+ return self::MakeStaticRequest(
445
+ $pCanonizedPath,
446
+ $pMethod,
447
+ $pParams,
448
+ $pCurlHandler,
449
+ $this->_isSandbox,
450
+ $sign_request ? array( &$this, 'SignRequest' ) : null
451
+ );
452
+ }
453
+
454
+ #region Connectivity Test ------------------------------------------------------
455
+
456
+ /**
457
+ * If successful connectivity to the API endpoint using ping.json endpoint.
458
+ *
459
+ * - OR -
460
+ *
461
+ * Validate if ping result object is valid.
462
+ *
463
+ * @param mixed $pPong
464
+ *
465
+ * @return bool
466
+ */
467
+ public static function Test( $pPong = null ) {
468
+ $pong = is_null( $pPong ) ?
469
+ self::Ping() :
470
+ $pPong;
471
+
472
+ return (
473
+ is_object( $pong ) &&
474
+ isset( $pong->api ) &&
475
+ 'pong' === $pong->api
476
+ );
477
+ }
478
+
479
+ /**
480
+ * Ping API to test connectivity.
481
+ *
482
+ * @return object
483
+ */
484
+ public static function Ping() {
485
+ try {
486
+ $result = self::MakeStaticRequest( '/v' . FS_API__VERSION . '/ping.json' );
487
+ } catch ( Freemius_Exception $e ) {
488
+ // Map to error object.
489
+ $result = (object) $e->getResult();
490
+ } catch ( Exception $e ) {
491
+ // Map to error object.
492
+ $result = (object) array(
493
+ 'error' => array(
494
+ 'type' => 'Unknown',
495
+ 'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
496
+ 'code' => 'unknown',
497
+ 'http' => 402
498
+ )
499
+ );
500
+ }
501
+
502
+ return $result;
503
+ }
504
+
505
+ #endregion Connectivity Test ------------------------------------------------------
506
+
507
+ #region Connectivity Exceptions ------------------------------------------------------
508
+
509
+ /**
510
+ * @param resource $pCurlHandler
511
+ *
512
+ * @throws Freemius_Exception
513
+ */
514
+ private static function ThrowCurlException( $pCurlHandler ) {
515
+ $e = new Freemius_Exception( array(
516
+ 'error' => array(
517
+ 'code' => curl_errno( $pCurlHandler ),
518
+ 'message' => curl_error( $pCurlHandler ),
519
+ 'type' => 'CurlException',
520
+ ),
521
+ ) );
522
+
523
+ curl_close( $pCurlHandler );
524
+ throw $e;
525
+ }
526
+
527
+ /**
528
+ * @param string $pResult
529
+ *
530
+ * @throws Freemius_Exception
531
+ */
532
+ private static function ThrowNoCurlException( $pResult = '' ) {
533
+ throw new Freemius_Exception( array(
534
+ 'error' => (object) array(
535
+ 'type' => 'cUrlMissing',
536
+ 'message' => $pResult,
537
+ 'code' => 'curl_missing',
538
+ 'http' => 402
539
+ )
540
+ ) );
541
+ }
542
+
543
+ /**
544
+ * @param string $pResult
545
+ *
546
+ * @throws Freemius_Exception
547
+ */
548
+ private static function ThrowCloudFlareDDoSException( $pResult = '' ) {
549
+ throw new Freemius_Exception( array(
550
+ 'error' => (object) array(
551
+ 'type' => 'CloudFlareDDoSProtection',
552
+ 'message' => $pResult,
553
+ 'code' => 'cloudflare_ddos_protection',
554
+ 'http' => 402
555
+ )
556
+ ) );
557
+ }
558
+
559
+ /**
560
+ * @param string $pResult
561
+ *
562
+ * @throws Freemius_Exception
563
+ */
564
+ private static function ThrowSquidAclException( $pResult = '' ) {
565
+ throw new Freemius_Exception( array(
566
+ 'error' => (object) array(
567
+ 'type' => 'SquidCacheBlock',
568
+ 'message' => $pResult,
569
+ 'code' => 'squid_cache_block',
570
+ 'http' => 402
571
+ )
572
+ ) );
573
+ }
574
+
575
+ #endregion Connectivity Exceptions ------------------------------------------------------
576
+ }
freemius/includes/sdk/FreemiusBase.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2014 Freemius, Inc.
4
+ *
5
+ * Licensed under the GPL v2 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://choosealicense.com/licenses/gpl-v2/
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ define( 'FS_API__VERSION', '1' );
19
+ define( 'FS_SDK__PATH', dirname( __FILE__ ) );
20
+ define( 'FS_SDK__EXCEPTIONS_PATH', FS_SDK__PATH . '/Exceptions/' );
21
+
22
+ if ( ! function_exists( 'json_decode' ) ) {
23
+ throw new Exception( 'Freemius needs the JSON PHP extension.' );
24
+ }
25
+
26
+ // Include all exception files.
27
+ $exceptions = array(
28
+ 'Exception',
29
+ 'InvalidArgumentException',
30
+ 'ArgumentNotExistException',
31
+ 'EmptyArgumentException',
32
+ 'OAuthException'
33
+ );
34
+
35
+ foreach ( $exceptions as $e ) {
36
+ require_once FS_SDK__EXCEPTIONS_PATH . $e . '.php';
37
+ }
38
+
39
+ abstract class Freemius_Api_Base {
40
+ const VERSION = '1.0.4';
41
+ const FORMAT = 'json';
42
+
43
+ protected $_id;
44
+ protected $_public;
45
+ protected $_secret;
46
+ protected $_scope;
47
+ protected $_isSandbox;
48
+
49
+ /**
50
+ * @param string $pScope 'app', 'developer', 'user' or 'install'.
51
+ * @param number $pID Element's id.
52
+ * @param string $pPublic Public key.
53
+ * @param string $pSecret Element's secret key.
54
+ * @param bool $pIsSandbox Whether or not to run API in sandbox mode.
55
+ */
56
+ public function Init( $pScope, $pID, $pPublic, $pSecret, $pIsSandbox = false ) {
57
+ $this->_id = $pID;
58
+ $this->_public = $pPublic;
59
+ $this->_secret = $pSecret;
60
+ $this->_scope = $pScope;
61
+ $this->_isSandbox = $pIsSandbox;
62
+ }
63
+
64
+ public function IsSandbox() {
65
+ return $this->_isSandbox;
66
+ }
67
+
68
+ function CanonizePath( $pPath ) {
69
+ $pPath = trim( $pPath, '/' );
70
+ $query_pos = strpos( $pPath, '?' );
71
+ $query = '';
72
+
73
+ if ( false !== $query_pos ) {
74
+ $query = substr( $pPath, $query_pos );
75
+ $pPath = substr( $pPath, 0, $query_pos );
76
+ }
77
+
78
+ // Trim '.json' suffix.
79
+ $format_length = strlen( '.' . self::FORMAT );
80
+ $start = $format_length * ( - 1 ); //negative
81
+ if ( substr( strtolower( $pPath ), $start ) === ( '.' . self::FORMAT ) ) {
82
+ $pPath = substr( $pPath, 0, strlen( $pPath ) - $format_length );
83
+ }
84
+
85
+ switch ( $this->_scope ) {
86
+ case 'app':
87
+ $base = '/apps/' . $this->_id;
88
+ break;
89
+ case 'developer':
90
+ $base = '/developers/' . $this->_id;
91
+ break;
92
+ case 'user':
93
+ $base = '/users/' . $this->_id;
94
+ break;
95
+ case 'plugin':
96
+ $base = '/plugins/' . $this->_id;
97
+ break;
98
+ case 'install':
99
+ $base = '/installs/' . $this->_id;
100
+ break;
101
+ default:
102
+ throw new Freemius_Exception( 'Scope not implemented.' );
103
+ }
104
+
105
+ return '/v' . FS_API__VERSION . $base .
106
+ ( ! empty( $pPath ) ? '/' : '' ) . $pPath .
107
+ ( ( false === strpos( $pPath, '.' ) ) ? '.' . self::FORMAT : '' ) . $query;
108
+ }
109
+
110
+ abstract function MakeRequest( $pCanonizedPath, $pMethod = 'GET', $pParams = array() );
111
+
112
+ /**
113
+ * @param string $pPath
114
+ * @param string $pMethod
115
+ * @param array $pParams
116
+ *
117
+ * @return object[]|object|null
118
+ */
119
+ private function _Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
120
+ $pMethod = strtoupper( $pMethod );
121
+
122
+ try {
123
+ $result = $this->MakeRequest( $pPath, $pMethod, $pParams );
124
+ } catch ( Freemius_Exception $e ) {
125
+ // Map to error object.
126
+ $result = (object) $e->getResult();
127
+ } catch ( Exception $e ) {
128
+ // Map to error object.
129
+ $result = (object) array(
130
+ 'error' => array(
131
+ 'type' => 'Unknown',
132
+ 'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
133
+ 'code' => 'unknown',
134
+ 'http' => 402
135
+ )
136
+ );
137
+ }
138
+
139
+ return $result;
140
+ }
141
+
142
+ public function Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
143
+ return $this->_Api( $this->CanonizePath( $pPath ), $pMethod, $pParams );
144
+ }
145
+
146
+ /**
147
+ * Base64 encoding that does not need to be urlencode()ed.
148
+ * Exactly the same as base64_encode except it uses
149
+ * - instead of +
150
+ * _ instead of /
151
+ * No padded =
152
+ *
153
+ * @param string $input base64UrlEncoded string
154
+ *
155
+ * @return string
156
+ */
157
+ protected static function Base64UrlDecode( $input ) {
158
+ return base64_decode( strtr( $input, '-_', '+/' ) );
159
+ }
160
+
161
+ /**
162
+ * Base64 encoding that does not need to be urlencode()ed.
163
+ * Exactly the same as base64_encode except it uses
164
+ * - instead of +
165
+ * _ instead of /
166
+ *
167
+ * @param string $input string
168
+ *
169
+ * @return string base64Url encoded string
170
+ */
171
+ protected static function Base64UrlEncode( $input ) {
172
+ $str = strtr( base64_encode( $input ), '+/', '-_' );
173
+ $str = str_replace( '=', '', $str );
174
+
175
+ return $str;
176
+ }
177
+
178
+ }
freemius/includes/sdk/LICENSE.txt ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
340
+
freemius/includes/supplements/fs-essential-functions-1.1.7.1.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Find the plugin main file path based on any give file inside the plugin's folder.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7.1
18
+ *
19
+ * @param string $file Absolute path to a file inside a plugin's folder.
20
+ *
21
+ * @return string
22
+ */
23
+ function fs_find_direct_caller_plugin_file( $file ) {
24
+ /**
25
+ * All the code below will be executed once on activation.
26
+ * If the user changes the main plugin's file name, the file_exists()
27
+ * will catch it.
28
+ */
29
+ if ( ! function_exists( 'get_plugins' ) ) {
30
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
31
+ }
32
+
33
+ $all_plugins = get_plugins();
34
+
35
+ $file_real_path = fs_normalize_path( realpath( $file ) );
36
+
37
+ // Get active plugin's main files real full names (might be symlinks).
38
+ foreach ( $all_plugins as $relative_path => &$data ) {
39
+ if ( 0 === strpos( $file_real_path, fs_normalize_path( dirname( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) ) ) ) ) {
40
+ return $relative_path;
41
+ }
42
+ }
43
+
44
+ return null;
45
+ }
freemius/require.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2016, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.9
7
+ */
8
+
9
+ // Configuration should be loaded first.
10
+ require_once dirname( __FILE__ ) . '/config.php';
11
+
12
+ // Logger must be loaded before any other.
13
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-logger.php';
14
+ require_once WP_FS__DIR_INCLUDES . '/debug/debug-bar-start.php';
15
+
16
+ require_once WP_FS__DIR_INCLUDES . '/fs-core-functions.php';
17
+ // require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-abstract-manager.php';
18
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-option-manager.php';
19
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-cache-manager.php';
20
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-admin-notice-manager.php';
21
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-admin-menu-manager.php';
22
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-key-value-storage.php';
23
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-license-manager.php';
24
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-plan-manager.php';
25
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-plugin-manager.php';
26
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-entity.php';
27
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-scope-entity.php';
28
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-user.php';
29
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-site.php';
30
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin.php';
31
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-info.php';
32
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-tag.php';
33
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-plan.php';
34
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-pricing.php';
35
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-payment.php';
36
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-license.php';
37
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-subscription.php';
38
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-api.php';
39
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-plugin-updater.php';
40
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-security.php';
41
+ require_once WP_FS__DIR_INCLUDES . '/class-freemius-abstract.php';
42
+ require_once WP_FS__DIR_INCLUDES . '/sdk/Exceptions/Exception.php';
43
+ require_once WP_FS__DIR_INCLUDES . '/class-freemius.php';
freemius/start.php ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Freemius SDK Version.
15
+ *
16
+ * @var string
17
+ */
18
+ $this_sdk_version = '1.2.0';
19
+
20
+ #region SDK Selection Logic --------------------------------------------------------------------
21
+
22
+ /**
23
+ * Special logic added on 1.1.6 to make sure that every Freemius powered plugin
24
+ * will ALWAYS be loaded with the newest SDK from the active Freemius powered plugins.
25
+ *
26
+ * Since Freemius SDK is backward compatible, this will make sure that all Freemius powered
27
+ * plugins will run correctly.
28
+ *
29
+ * @since 1.1.6
30
+ */
31
+
32
+ global $fs_active_plugins;
33
+
34
+ $this_sdk_relative_path = plugin_basename( dirname( __FILE__ ) );
35
+
36
+ if ( ! isset( $fs_active_plugins ) ) {
37
+ // Require SDK essentials.
38
+ require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php';
39
+
40
+ // Load all Freemius powered active plugins.
41
+ $fs_active_plugins = get_option( 'fs_active_plugins', new stdClass() );
42
+
43
+ if ( ! isset( $fs_active_plugins->plugins ) ) {
44
+ $fs_active_plugins->plugins = array();
45
+ }
46
+ }
47
+
48
+ if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) {
49
+ require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php';
50
+ }
51
+
52
+ // Update current SDK info based on the SDK path.
53
+ if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) ||
54
+ $this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version
55
+ ) {
56
+ $fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array(
57
+ 'version' => $this_sdk_version,
58
+ 'timestamp' => time(),
59
+ 'plugin_path' => plugin_basename( fs_find_direct_caller_plugin_file( __FILE__ ) ),
60
+ );
61
+ }
62
+
63
+ $is_current_sdk_newest = isset( $fs_active_plugins->newest ) && ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path );
64
+
65
+ if ( ! isset( $fs_active_plugins->newest ) ) {
66
+ /**
67
+ * This will be executed only once, for the first time a Freemius powered plugin is activated.
68
+ */
69
+ fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
70
+
71
+ $is_current_sdk_newest = true;
72
+ } else if ( version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '<' ) ) {
73
+ /**
74
+ * Current SDK is newer than the newest stored SDK.
75
+ */
76
+ fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
77
+
78
+ if ( class_exists( 'Freemius' ) ) {
79
+ // Older SDK version was already loaded.
80
+
81
+ if ( ! $fs_active_plugins->newest->in_activation ) {
82
+ // Re-order plugins to load this plugin first.
83
+ fs_newest_sdk_plugin_first();
84
+ }
85
+
86
+ // Refresh page.
87
+ if ( fs_redirect( $_SERVER['REQUEST_URI'] ) ) {
88
+ exit();
89
+ }
90
+ }
91
+ } else {
92
+ if ( ! function_exists( 'get_plugins' ) ) {
93
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
94
+ }
95
+
96
+ $is_newest_sdk_plugin_activate = is_plugin_active( $fs_active_plugins->newest->plugin_path );
97
+
98
+ if ( $is_current_sdk_newest &&
99
+ ! $is_newest_sdk_plugin_activate &&
100
+ ! $fs_active_plugins->newest->in_activation
101
+ ) {
102
+ // If current SDK is the newest and the plugin is NOT active, it means
103
+ // that the current plugin in activation mode.
104
+ $fs_active_plugins->newest->in_activation = true;
105
+ update_option( 'fs_active_plugins', $fs_active_plugins );
106
+ }
107
+
108
+ $is_newest_sdk_path_valid = ( $is_newest_sdk_plugin_activate || $fs_active_plugins->newest->in_activation ) && file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this_sdk_relative_path . '/start.php' ) );
109
+
110
+ if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) {
111
+ // Plugin with newest SDK is no longer active, or SDK was moved to a different location.
112
+ unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] );
113
+ }
114
+
115
+ if ( ! ( $is_newest_sdk_plugin_activate || $fs_active_plugins->newest->in_activation ) ||
116
+ ! $is_newest_sdk_path_valid ||
117
+ // Is newest SDK downgraded.
118
+ ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
119
+ version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) )
120
+ ) {
121
+ /**
122
+ * Plugin with newest SDK is no longer active.
123
+ * OR
124
+ * The newest SDK was in the current plugin. BUT, seems like the version of
125
+ * the SDK was downgraded to a lower SDK.
126
+ */
127
+ // Find the active plugin with the newest SDK version and update the newest reference.
128
+ fs_fallback_to_newest_active_sdk();
129
+ } else {
130
+ if ( $is_newest_sdk_plugin_activate &&
131
+ $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
132
+ ( $fs_active_plugins->newest->in_activation ||
133
+ ( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) )
134
+ )
135
+
136
+ ) {
137
+ if ( $fs_active_plugins->newest->in_activation ) {
138
+ // Plugin no more in activation.
139
+ $fs_active_plugins->newest->in_activation = false;
140
+ update_option( 'fs_active_plugins', $fs_active_plugins );
141
+ }
142
+
143
+ // Reorder plugins to load plugin with newest SDK first.
144
+ if ( fs_newest_sdk_plugin_first() ) {
145
+ // Refresh page after re-order to make sure activated plugin loads newest SDK.
146
+ if ( class_exists( 'Freemius' ) ) {
147
+ if ( fs_redirect( $_SERVER['REQUEST_URI'] ) ) {
148
+ exit();
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ if ( class_exists( 'Freemius' ) ) {
157
+ // SDK was already loaded.
158
+ return;
159
+ }
160
+
161
+ if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) {
162
+ $newest_sdk_starter = fs_normalize_path( WP_PLUGIN_DIR . '/' . $fs_active_plugins->newest->sdk_path . '/start.php' );
163
+
164
+ if ( file_exists( $newest_sdk_starter ) ) {
165
+ // Reorder plugins to load plugin with newest SDK first.
166
+ fs_newest_sdk_plugin_first();
167
+
168
+ // There's a newer SDK version, load it instead of the current one!
169
+ require_once $newest_sdk_starter;
170
+
171
+ return;
172
+ }
173
+ }
174
+
175
+ #endregion SDK Selection Logic --------------------------------------------------------------------
176
+
177
+ #region Hooks & Filters Collection --------------------------------------------------------------------
178
+
179
+ /**
180
+ * Freemius hooks (actions & filters) tags structure:
181
+ *
182
+ * fs_{filter/action_name}_{plugin_slug}
183
+ *
184
+ * --------------------------------------------------------
185
+ *
186
+ * Usage with WordPress' add_action() / add_filter():
187
+ *
188
+ * add_action('fs_{filter/action_name}_{plugin_slug}', $callable);
189
+ *
190
+ * --------------------------------------------------------
191
+ *
192
+ * Usage with Freemius' instance add_action() / add_filter():
193
+ *
194
+ * // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix.
195
+ * my_freemius()->add_action('{action_name}', $callable);
196
+ *
197
+ * --------------------------------------------------------
198
+ *
199
+ * Freemius filters collection:
200
+ *
201
+ * fs_connect_url_{plugin_slug}
202
+ * fs_trial_promotion_message_{plugin_slug}
203
+ * fs_is_long_term_user_{plugin_slug}
204
+ * fs_uninstall_reasons_{plugin_slug}
205
+ * fs_is_plugin_update_{plugin_slug}
206
+ * fs_api_domains_{plugin_slug}
207
+ * fs_email_template_sections_{plugin_slug}
208
+ * fs_support_forum_submenu_{plugin_slug}
209
+ * fs_support_forum_url_{plugin_slug}
210
+ * fs_connect_message_{plugin_slug}
211
+ * fs_connect_message_on_update_{plugin_slug}
212
+ * fs_uninstall_confirmation_message_{plugin_slug}
213
+ * fs_pending_activation_message_{plugin_slug}
214
+ * fs_is_submenu_visible_{plugin_slug}
215
+ * fs_plugin_icon_{plugin_slug}
216
+ * fs_show_trial_{plugin_slug}
217
+ *
218
+ * --------------------------------------------------------
219
+ *
220
+ * Freemius actions collection:
221
+ *
222
+ * fs_after_license_loaded_{plugin_slug}
223
+ * fs_after_license_change_{plugin_slug}
224
+ * fs_after_plans_sync_{plugin_slug}
225
+ *
226
+ * fs_after_account_details_{plugin_slug}
227
+ * fs_after_account_user_sync_{plugin_slug}
228
+ * fs_after_account_plan_sync_{plugin_slug}
229
+ * fs_before_account_load_{plugin_slug}
230
+ * fs_after_account_connection_{plugin_slug}
231
+ * fs_account_property_edit_{plugin_slug}
232
+ * fs_account_email_verified_{plugin_slug}
233
+ * fs_account_page_load_before_departure_{plugin_slug}
234
+ * fs_before_account_delete_{plugin_slug}
235
+ * fs_after_account_delete_{plugin_slug}
236
+ *
237
+ * fs_sdk_version_update_{plugin_slug}
238
+ * fs_plugin_version_update_{plugin_slug}
239
+ *
240
+ * fs_initiated_{plugin_slug}
241
+ * fs_after_init_plugin_registered_{plugin_slug}
242
+ * fs_after_init_plugin_anonymous_{plugin_slug}
243
+ * fs_after_init_plugin_pending_activations_{plugin_slug}
244
+ * fs_after_init_addon_registered_{plugin_slug}
245
+ * fs_after_init_addon_anonymous_{plugin_slug}
246
+ * fs_after_init_addon_pending_activations_{plugin_slug}
247
+ *
248
+ * fs_after_premium_version_activation_{plugin_slug}
249
+ * fs_after_free_version_reactivation_{plugin_slug}
250
+ *
251
+ * fs_after_uninstall_{plugin_slug}
252
+ * fs_before_admin_menu_init_{plugin_slug}
253
+ */
254
+
255
+ #endregion Hooks & Filters Collection --------------------------------------------------------------------
256
+
257
+ if ( ! class_exists( 'Freemius' ) ) {
258
+
259
+ if ( ! defined( 'WP_FS__SDK_VERSION' ) ) {
260
+ define( 'WP_FS__SDK_VERSION', $this_sdk_version );
261
+ }
262
+
263
+ // Load SDK files.
264
+ require_once dirname( __FILE__ ) . '/require.php';
265
+
266
+ /**
267
+ * Quick shortcut to get Freemius for specified plugin.
268
+ * Used by various templates.
269
+ *
270
+ * @param string $slug
271
+ *
272
+ * @return Freemius
273
+ */
274
+ function freemius( $slug ) {
275
+ return Freemius::instance( $slug );
276
+ }
277
+
278
+ /**
279
+ * @param string $slug
280
+ * @param number $plugin_id
281
+ * @param string $public_key
282
+ * @param bool $is_live Is live or test plugin.
283
+ * @param bool $is_premium Hints freemius if running the premium plugin or not.
284
+ *
285
+ * @return Freemius
286
+ */
287
+ function fs_init( $slug, $plugin_id, $public_key, $is_live = true, $is_premium = true ) {
288
+ $fs = Freemius::instance( $slug );
289
+ $fs->init( $plugin_id, $public_key, $is_live, $is_premium );
290
+
291
+ return $fs;
292
+ }
293
+
294
+ /**
295
+ * @param array [string]string $plugin
296
+ *
297
+ * @return Freemius
298
+ * @throws Freemius_Exception
299
+ */
300
+ function fs_dynamic_init( $plugin ) {
301
+ $fs = Freemius::instance( $plugin['slug'] );
302
+ $fs->dynamic_init( $plugin );
303
+
304
+ return $fs;
305
+ }
306
+
307
+ function fs_dump_log() {
308
+ FS_Logger::dump();
309
+ }
310
+ }
freemius/templates/account.php ADDED
@@ -0,0 +1,688 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ /**
15
+ * @var Freemius $fs
16
+ */
17
+ $fs = freemius( $slug );
18
+
19
+ /**
20
+ * @var FS_Plugin_Tag $update
21
+ */
22
+ $update = $fs->get_update( false, false );
23
+
24
+ $is_paying = $fs->is_paying();
25
+ $user = $fs->get_user();
26
+ $site = $fs->get_site();
27
+ $name = $user->get_name();
28
+ $license = $fs->_get_license();
29
+ $subscription = $fs->_get_subscription();
30
+ $plan = $fs->get_plan();
31
+ $is_active_subscription = ( is_object( $subscription ) && $subscription->is_active() );
32
+ $is_paid_trial = $fs->is_paid_trial();
33
+ $show_upgrade = ( $fs->has_paid_plan() && ! $is_paying && ! $is_paid_trial );
34
+
35
+ if ( $show_upgrade ) {
36
+ $fs->_require_license_activation_dialog();
37
+ }
38
+ ?>
39
+ <div class="wrap">
40
+ <h2 class="nav-tab-wrapper">
41
+ <a href="<?php echo $fs->get_account_url() ?>"
42
+ class="nav-tab nav-tab-active"><?php _efs( 'account', $slug ) ?></a>
43
+ <?php if ( $fs->has_addons() ) : ?>
44
+ <a href="<?php echo $fs->_get_admin_page_url( 'addons' ) ?>"
45
+ class="nav-tab"><?php _efs( 'add-ons', $slug ) ?></a>
46
+ <?php endif ?>
47
+ <?php if ( $show_upgrade ) : ?>
48
+ <a href="<?php echo $fs->get_upgrade_url() ?>" class="nav-tab"><?php _efs( 'upgrade', $slug ) ?></a>
49
+ <?php if ( $fs->apply_filters( 'show_trial', true ) && ! $fs->is_trial_utilized() && $fs->has_trial_plan() ) : ?>
50
+ <a href="<?php echo $fs->get_trial_url() ?>" class="nav-tab"><?php _efs( 'free-trial', $slug ) ?></a>
51
+ <?php endif ?>
52
+ <?php endif ?>
53
+ <?php if ( ! $plan->is_free() ) : ?>
54
+ <a href="<?php echo $fs->get_account_tab_url( 'billing' ) ?>"
55
+ class="nav-tab"><?php _efs( 'billing', $slug ) ?></a>
56
+ <?php endif ?>
57
+ </h2>
58
+
59
+ <div id="poststuff">
60
+ <div id="fs_account">
61
+ <div class="has-sidebar has-right-sidebar">
62
+ <div class="has-sidebar-content">
63
+ <div class="postbox">
64
+ <h3><?php _efs( 'account-details', $slug ) ?></h3>
65
+
66
+ <div class="fs-header-actions">
67
+ <ul>
68
+ <li>
69
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
70
+ <input type="hidden" name="fs_action" value="delete_account">
71
+ <?php wp_nonce_field( 'delete_account' ) ?>
72
+ <a href="#" onclick="if (confirm('<?php
73
+ if ( $is_active_subscription ) {
74
+ echo esc_attr( sprintf( __fs( 'delete-account-x-confirm', $slug ), $plan->title ) );
75
+ } else {
76
+ _efs( 'delete-account-confirm', $slug );
77
+ }
78
+ ?>')) this.parentNode.submit(); return false;"><i
79
+ class="dashicons dashicons-no"></i> <?php _efs( 'delete-account', $slug ) ?></a>
80
+ </form>
81
+ </li>
82
+ <?php if ( $is_paying ) : ?>
83
+ <li>
84
+ &nbsp;•&nbsp;
85
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
86
+ <input type="hidden" name="fs_action" value="deactivate_license">
87
+ <?php wp_nonce_field( 'deactivate_license' ) ?>
88
+ <a href="#"
89
+ onclick="if (confirm('<?php _efs( 'deactivate-license-confirm', $slug ) ?>')) this.parentNode.submit(); return false;"><i
90
+ class="dashicons dashicons-admin-network"></i> <?php _efs( 'deactivate-license', $slug ) ?>
91
+ </a>
92
+ </form>
93
+ </li>
94
+ <?php if ( ! $license->is_lifetime() &&
95
+ $is_active_subscription
96
+ ) : ?>
97
+ <li>
98
+ &nbsp;•&nbsp;
99
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
100
+ <input type="hidden" name="fs_action" value="downgrade_account">
101
+ <?php wp_nonce_field( 'downgrade_account' ) ?>
102
+ <a href="#"
103
+ onclick="if (confirm('<?php printf( __fs( 'downgrade-x-confirm', $slug ), $plan->title, human_time_diff( time(), strtotime( $license->expiration ) ) ) ?> <?php if ( ! $license->is_block_features ) {
104
+ printf( __fs( 'after-downgrade-non-blocking', $slug ), $plan->title );
105
+ } else {
106
+ printf( __fs( 'after-downgrade-blocking', $slug ), $plan->title );
107
+ }?> <?php _efs( 'proceed-confirmation', $slug ) ?>')) this.parentNode.submit(); return false;"><i
108
+ class="dashicons dashicons-download"></i> <?php _efs( 'downgrade', $slug ) ?></a>
109
+ </form>
110
+ </li>
111
+ <?php endif ?>
112
+ <li>
113
+ &nbsp;•&nbsp;
114
+ <a href="<?php echo $fs->get_upgrade_url() ?>"><i
115
+ class="dashicons dashicons-grid-view"></i> <?php _efs( 'change-plan', $slug ) ?></a>
116
+ </li>
117
+ <?php elseif ( $is_paid_trial ) : ?>
118
+ <li>
119
+ &nbsp;•&nbsp;
120
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
121
+ <input type="hidden" name="fs_action" value="cancel_trial">
122
+ <?php wp_nonce_field( 'cancel_trial' ) ?>
123
+ <a href="#"
124
+ onclick="if (confirm('<?php _efs( 'cancel-trial-confirm' ) ?>')) this.parentNode.submit(); return false;"><i
125
+ class="dashicons dashicons-download"></i> <?php _efs( 'cancel-trial', $slug ) ?></a>
126
+ </form>
127
+ </li>
128
+ <?php endif ?>
129
+ <li>
130
+ &nbsp;•&nbsp;
131
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
132
+ <input type="hidden" name="fs_action" value="<?php echo $slug ?>_sync_license">
133
+ <?php wp_nonce_field( $slug . '_sync_license' ) ?>
134
+ <a href="#" onclick="this.parentNode.submit(); return false;"><i
135
+ class="dashicons dashicons-image-rotate"></i> <?php _efs( 'sync', $slug ) ?></a>
136
+ </form>
137
+ </li>
138
+
139
+ </ul>
140
+ </div>
141
+ <div class="inside">
142
+ <table id="fs_account_details" cellspacing="0" class="fs-key-value-table">
143
+ <?php
144
+ $profile = array();
145
+ $profile[] = array(
146
+ 'id' => 'user_name',
147
+ 'title' => __fs( 'name', $slug ),
148
+ 'value' => $name
149
+ );
150
+ // if (isset($user->email) && false !== strpos($user->email, '@'))
151
+ $profile[] = array(
152
+ 'id' => 'email',
153
+ 'title' => __fs( 'email', $slug ),
154
+ 'value' => $user->email
155
+ );
156
+
157
+ if ( is_numeric( $user->id ) ) {
158
+ $profile[] = array(
159
+ 'id' => 'user_id',
160
+ 'title' => __fs( 'user-id', $slug ),
161
+ 'value' => $user->id
162
+ );
163
+ }
164
+
165
+ $profile[] = array(
166
+ 'id' => 'site_id',
167
+ 'title' => __fs( 'site-id', $slug ),
168
+ 'value' => is_string( $site->id ) ?
169
+ $site->id :
170
+ __fs( 'no-id', $slug )
171
+ );
172
+
173
+ $profile[] = array(
174
+ 'id' => 'site_public_key',
175
+ 'title' => __fs( 'public-key', $slug ),
176
+ 'value' => $site->public_key
177
+ );
178
+
179
+ $profile[] = array(
180
+ 'id' => 'site_secret_key',
181
+ 'title' => __fs( 'secret-key', $slug ),
182
+ 'value' => ( ( is_string( $site->secret_key ) ) ?
183
+ $site->secret_key :
184
+ __fs( 'no-secret', $slug )
185
+ )
186
+ );
187
+
188
+ $profile[] = array(
189
+ 'id' => 'version',
190
+ 'title' => __fs( 'version', $slug ),
191
+ 'value' => $fs->get_plugin_version()
192
+ );
193
+
194
+ if ( $fs->has_paid_plan() ) {
195
+ if ( $fs->is_trial() ) {
196
+ $trial_plan = $fs->get_trial_plan();
197
+
198
+ $profile[] = array(
199
+ 'id' => 'plan',
200
+ 'title' => __fs( 'plan', $slug ),
201
+ 'value' => ( is_string( $trial_plan->name ) ?
202
+ strtoupper( $trial_plan->title ) :
203
+ __fs( 'trial', $slug ) )
204
+ );
205
+ } else {
206
+ $profile[] = array(
207
+ 'id' => 'plan',
208
+ 'title' => __fs( 'plan', $slug ),
209
+ 'value' => is_string( $site->plan->name ) ?
210
+ strtoupper( $site->plan->title ) :
211
+ strtoupper( __fs( 'free', $slug ) )
212
+ );
213
+
214
+ if ( is_object( $license ) ) {
215
+ $profile[] = array(
216
+ 'id' => 'license_key',
217
+ 'title' => __fs( 'License Key', $slug ),
218
+ 'value' => $license->secret_key,
219
+ );
220
+ }
221
+ }
222
+ }
223
+ ?>
224
+ <?php $odd = true;
225
+ foreach ( $profile as $p ) : ?>
226
+ <?php
227
+ if ( 'plan' === $p['id'] && ! $fs->has_paid_plan() ) {
228
+ // If plugin don't have any paid plans, there's no reason
229
+ // to show current plan.
230
+ continue;
231
+ }
232
+ ?>
233
+ <tr class="fs-field-<?php echo $p['id'] ?><?php if ( $odd ) : ?> alternate<?php endif ?>">
234
+ <td>
235
+ <nobr><?php echo $p['title'] ?>:</nobr>
236
+ </td>
237
+ <td<?php if ( 'plan' === $p['id'] ) { echo ' colspan="2"'; }?>>
238
+ <?php if ( in_array( $p['id'], array( 'license_key', 'site_secret_key' ) ) ) : ?>
239
+ <code><?php echo htmlspecialchars( substr( $p['value'], 0, 6 ) ) . str_pad( '', 23 * 6, '&bull;' ) . htmlspecialchars( substr( $p['value'], - 3 ) ) ?></code>
240
+ <input type="text" value="<?php echo htmlspecialchars( $p['value'] ) ?>" style="display: none"
241
+ readonly/>
242
+ <?php else : ?>
243
+ <code><?php echo htmlspecialchars( $p['value'] ) ?></code>
244
+ <?php endif ?>
245
+ <?php if ( 'email' === $p['id'] && ! $user->is_verified() ) : ?>
246
+ <label class="fs-tag fs-warn"><?php _efs( 'not-verified', $slug ) ?></label>
247
+ <?php endif ?>
248
+ <?php if ( 'plan' === $p['id'] ) : ?>
249
+ <?php if ( $fs->is_trial() ) : ?>
250
+ <label class="fs-tag fs-success"><?php _efs( 'trial', $slug ) ?></label>
251
+ <?php endif ?>
252
+ <?php if ( is_object( $license ) && ! $license->is_lifetime() ) : ?>
253
+ <?php if ( ! $is_active_subscription && ! $license->is_first_payment_pending() ) : ?>
254
+ <label
255
+ class="fs-tag fs-warn"><?php printf( __fs( 'expires-in', $slug ), human_time_diff( time(), strtotime( $license->expiration ) ) ) ?></label>
256
+ <?php elseif ( $is_active_subscription && ! $subscription->is_first_payment_pending() ) : ?>
257
+ <label
258
+ class="fs-tag fs-success"><?php printf( __fs( 'renews-in', $slug ), human_time_diff( time(), strtotime( $subscription->next_payment ) ) ) ?></label>
259
+ <?php endif ?>
260
+ <?php elseif ( $fs->is_trial() ) : ?>
261
+ <label
262
+ class="fs-tag fs-warn"><?php printf( __fs( 'expires-in', $slug ), human_time_diff( time(), strtotime( $site->trial_ends ) ) ) ?></label>
263
+ <?php endif ?>
264
+ <div class="button-group">
265
+ <?php $available_license = $fs->is_free_plan() ? $fs->_get_available_premium_license() : false ?>
266
+ <?php if ( false !== $available_license && ( $available_license->left() > 0 || ( $site->is_localhost() && $available_license->is_free_localhost ) ) ) : ?>
267
+ <?php $premium_plan = $fs->_get_plan_by_id( $available_license->plan_id ) ?>
268
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>"
269
+ method="POST">
270
+ <input type="hidden" name="fs_action" value="activate_license">
271
+ <input type="hidden" name="license_id" value="<?php echo $available_license->id ?>">
272
+ <?php wp_nonce_field( 'activate_license' ) ?>
273
+ <input type="submit" class="button button-primary"
274
+ value="<?php printf(
275
+ __fs( 'activate-x-plan', $slug ) . '%s',
276
+ $premium_plan->title,
277
+ ( $site->is_localhost() && $available_license->is_free_localhost ) ?
278
+ ' [' . __fs( 'localhost', $slug ) . ']' :
279
+ ( $available_license->is_single_site() ?
280
+ '' :
281
+ ' [' . ( 1 < $available_license->left() ?
282
+ sprintf( __fs( 'x-left', $slug ), $available_license->left() ) :
283
+ strtolower( __fs( 'last-license', $slug ) ) ) . ']'
284
+ )
285
+ ) ?> ">
286
+ </form>
287
+ <?php else : ?>
288
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>"
289
+ method="POST" class="button-group">
290
+ <?php if ($show_upgrade) : ?>
291
+ <a class="button activate-license-trigger <?php echo $slug ?>" href="#!"><?php _efs( 'activate-license', $slug ) ?></a>
292
+ <?php endif ?>
293
+ <input type="submit" class="button"
294
+ value="<?php _efs( 'sync-license', $slug ) ?>">
295
+ <input type="hidden" name="fs_action"
296
+ value="<?php echo $slug ?>_sync_license">
297
+ <?php wp_nonce_field( $slug . '_sync_license' ) ?>
298
+ <a href="<?php echo $fs->get_upgrade_url() ?>"
299
+ class="button<?php if ( $show_upgrade ) {
300
+ echo ' button-primary';
301
+ } ?> button-upgrade"><i
302
+ class="dashicons dashicons-cart"></i> <?php ( $show_upgrade ) ?
303
+ _efs( 'upgrade', $slug ) :
304
+ _efs( 'change-plan', $slug )
305
+ ?></a>
306
+ </form>
307
+ <?php endif ?>
308
+ </div>
309
+ <?php elseif ( 'version' === $p['id'] && $fs->has_paid_plan() ) : ?>
310
+ <?php if ( $fs->is_premium() ) : ?>
311
+ <label
312
+ class="fs-tag fs-<?php echo $fs->can_use_premium_code() ? 'success' : 'warn' ?>"><?php _efs( 'premium-version' ) ?></label>
313
+ <?php elseif ( $fs->can_use_premium_code() ) : ?>
314
+ <label class="fs-tag fs-warn"><?php _efs( 'free-version' ) ?></label>
315
+ <?php endif ?>
316
+ <?php endif ?>
317
+ </td>
318
+ <?php if ( 'plan' !== $p['id'] ) : ?>
319
+ <td class="fs-right">
320
+ <?php if ( 'email' === $p['id'] && ! $user->is_verified() ) : ?>
321
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
322
+ <input type="hidden" name="fs_action" value="verify_email">
323
+ <?php wp_nonce_field( 'verify_email' ) ?>
324
+ <input type="submit" class="button button-small"
325
+ value="<?php _efs( 'verify-email', $slug ) ?>">
326
+ </form>
327
+ <?php endif ?>
328
+ <?php if ( 'version' === $p['id'] ) : ?>
329
+ <div class="button-group">
330
+ <?php if ( $is_paying || $fs->is_trial() ) : ?>
331
+ <?php if ( ! $fs->is_allowed_to_install() ) : ?>
332
+ <a target="_blank" class="button button-primary"
333
+ href="<?php echo $fs->_get_latest_download_local_url() ?>"><?php echo sprintf( __fs( 'download-x-version', $slug ), ( $fs->is_trial() ? $trial_plan->title : $site->plan->title ) ) . ( is_object( $update ) ? ' [' . $update->version . ']' : '' ) ?></a>
334
+ <?php elseif ( is_object( $update ) ) : ?>
335
+ <a class="button button-primary"
336
+ href="<?php echo wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $fs->get_plugin_basename() ), 'upgrade-plugin_' . $fs->get_plugin_basename() ) ?>"><?php echo __fs( 'install-update-now', $slug ) . ' [' . $update->version . ']' ?></a>
337
+ <?php endif ?>
338
+ <?php endif; ?>
339
+ </div>
340
+ <?php
341
+ elseif ( in_array( $p['id'], array( 'license_key', 'site_secret_key' ) ) ) : ?>
342
+ <button class="button button-small"><?php _efs( 'show', $slug ) ?></button>
343
+ <?php
344
+ elseif (/*in_array($p['id'], array('site_secret_key', 'site_id', 'site_public_key')) ||*/
345
+ ( is_string( $user->secret_key ) && in_array( $p['id'], array(
346
+ 'email',
347
+ 'user_name'
348
+ ) ) )
349
+ ) : ?>
350
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST"
351
+ onsubmit="var val = prompt('<?php printf( __fs( 'what-is-your-x', $slug ), $p['title'] ) ?>', '<?php echo $p['value'] ?>'); if (null == val || '' === val) return false; jQuery('input[name=fs_<?php echo $p['id'] ?>_<?php echo $slug ?>]').val(val); return true;">
352
+ <input type="hidden" name="fs_action" value="update_<?php echo $p['id'] ?>">
353
+ <input type="hidden" name="fs_<?php echo $p['id'] ?>_<?php echo $slug ?>"
354
+ value="">
355
+ <?php wp_nonce_field( 'update_' . $p['id'] ) ?>
356
+ <input type="submit" class="button button-small"
357
+ value="<?php _efs( 'edit', $slug ) ?>">
358
+ </form>
359
+ <?php endif ?>
360
+ </td>
361
+ <?php endif ?>
362
+ </tr>
363
+ <?php $odd = ! $odd;
364
+ endforeach ?>
365
+ </table>
366
+ </div>
367
+ </div>
368
+ <script type="text/javascript">
369
+ (function ($) {
370
+ $('.fs-field-license_key button, .fs-field-site_secret_key button').click(function () {
371
+ var
372
+ $this = $(this),
373
+ $parent = $this.closest('tr'),
374
+ $input = $parent.find('input');
375
+
376
+ $parent.find('code').toggle();
377
+ $input.toggle();
378
+
379
+ if ($input.is(':visible')) {
380
+ $this.html('<?php _efs( 'hide', $slug ) ?>');
381
+ setTimeout(function () {
382
+ $input.select().focus();
383
+ }, 100);
384
+ }
385
+ else {
386
+ $this.html('<?php _efs( 'show', $slug ) ?>');
387
+ }
388
+ });
389
+ }(jQuery));
390
+
391
+ </script>
392
+
393
+ <?php
394
+ $account_addons = $fs->get_account_addons();
395
+ if ( ! is_array( $account_addons ) ) {
396
+ $account_addons = array();
397
+ }
398
+
399
+ $installed_addons = $fs->get_installed_addons();
400
+ $installed_addons_ids = array();
401
+ foreach ( $installed_addons as $fs_addon ) {
402
+ $installed_addons_ids[] = $fs_addon->get_id();
403
+ }
404
+
405
+ $addons_to_show = array_unique( array_merge( $installed_addons_ids, $account_addons ) );
406
+ ?>
407
+ <?php if ( 0 < count( $addons_to_show ) ) : ?>
408
+ <!-- Add-Ons -->
409
+ <div class="postbox">
410
+ <div class="">
411
+ <!-- <div class="inside">-->
412
+ <table id="fs_addons" class="widefat">
413
+ <thead>
414
+ <tr>
415
+ <th><h3><?php _efs( 'add-ons', $slug ) ?></h3></th>
416
+ <th><?php _efs( 'id', $slug ) ?></th>
417
+ <th><?php _efs( 'version', $slug ) ?></th>
418
+ <th><?php _efs( 'plan', $slug ) ?></th>
419
+ <th><?php _efs( 'license', $slug ) ?></th>
420
+ <th></th>
421
+ <?php if ( defined( 'WP_FS__DEV_MODE' ) && WP_FS__DEV_MODE ) : ?>
422
+ <th></th>
423
+ <?php endif ?>
424
+ </tr>
425
+ </thead>
426
+ <tbody>
427
+ <?php $odd = true;
428
+ foreach ( $addons_to_show as $addon_id ) : ?>
429
+ <?php
430
+ $addon = $fs->get_addon( $addon_id );
431
+ $is_addon_activated = $fs->is_addon_activated( $addon->slug );
432
+ $is_addon_connected = $fs->is_addon_connected( $addon->slug );
433
+
434
+ $fs_addon = $is_addon_connected ? freemius( $addon->slug ) : false;
435
+ if ( is_object( $fs_addon ) ) {
436
+ $is_paying = $fs_addon->is_paying();
437
+ $user = $fs_addon->get_user();
438
+ $site = $fs_addon->get_site();
439
+ $license = $fs_addon->_get_license();
440
+ $subscription = $fs_addon->_get_subscription();
441
+ $plan = $fs_addon->get_plan();
442
+ $is_active_subscription = ( is_object( $subscription ) && $subscription->is_active() );
443
+ $is_paid_trial = $fs_addon->is_paid_trial();
444
+ $show_upgrade = ( ! $is_paying && ! $is_paid_trial && ! $fs_addon->_has_premium_license() );
445
+ $is_current_license_expired = is_object( $license ) && $license->is_expired();
446
+ }
447
+
448
+ // var_dump( $is_paid_trial, $license, $site, $subscription );
449
+
450
+ ?>
451
+ <tr<?php if ( $odd ) {
452
+ echo ' class="alternate"';
453
+ } ?>>
454
+ <td>
455
+ <!-- Title -->
456
+ <?php echo $addon->title ?>
457
+ </td>
458
+ <?php if ( $is_addon_connected ) : ?>
459
+ <?php // Add-on Installed ?>
460
+ <?php $addon_site = $fs_addon->get_site(); ?>
461
+ <td>
462
+ <!-- ID -->
463
+ <?php echo $addon_site->id ?>
464
+ </td>
465
+ <td>
466
+ <!-- Version -->
467
+ <?php echo $fs_addon->get_plugin_version() ?>
468
+ </td>
469
+ <td>
470
+ <!-- Plan Title -->
471
+ <?php echo is_string( $addon_site->plan->name ) ? strtoupper( $addon_site->plan->title ) : 'FREE' ?>
472
+ </td>
473
+ <td>
474
+ <!-- Expiration -->
475
+ <?php
476
+ $tags = array();
477
+
478
+ if ( $fs_addon->is_trial() ) {
479
+ $tags[] = array( 'label' => __fs( 'trial', $slug ), 'type' => 'success' );
480
+
481
+ $tags[] = array(
482
+ 'label' => sprintf( __fs( ( $is_paid_trial ? 'renews-in' : 'expires-in' ), $slug ), human_time_diff( time(), strtotime( $site->trial_ends ) ) ),
483
+ 'type' => ( $is_paid_trial ? 'success' : 'warn' )
484
+ );
485
+ } else {
486
+ if ( is_object( $license ) ) {
487
+ if ( $license->is_cancelled ) {
488
+ $tags[] = array(
489
+ 'label' => __fs( 'cancelled', $slug ),
490
+ 'type' => 'error'
491
+ );
492
+ } else if ( $license->is_expired() ) {
493
+ $tags[] = array(
494
+ 'label' => __fs( 'expired', $slug ),
495
+ 'type' => 'error'
496
+ );
497
+ } else if ( $license->is_lifetime() ) {
498
+ $tags[] = array(
499
+ 'label' => __fs( 'no-expiration', $slug ),
500
+ 'type' => 'success'
501
+ );
502
+ } else if ( ! $is_active_subscription && ! $license->is_first_payment_pending() ) {
503
+ $tags[] = array(
504
+ 'label' => sprintf( __fs( 'expires-in', $slug ), human_time_diff( time(), strtotime( $license->expiration ) ) ),
505
+ 'type' => 'warn'
506
+ );
507
+ } else if ( $is_active_subscription && ! $subscription->is_first_payment_pending() ) {
508
+ $tags[] = array(
509
+ 'label' => sprintf( __fs( 'renews-in', $slug ), human_time_diff( time(), strtotime( $subscription->next_payment ) ) ),
510
+ 'type' => 'success'
511
+ );
512
+ }
513
+ }
514
+ }
515
+
516
+ foreach ( $tags as $t ) {
517
+ printf( '<label class="fs-tag fs-%s">%s</label>' . "\n", $t['type'], $t['label'] );
518
+ }
519
+ ?>
520
+ </td>
521
+ <?php
522
+ $buttons = array();
523
+ if ( $is_addon_activated ) {
524
+ if ( $is_paying ) {
525
+ $buttons[] = fs_ui_get_action_button(
526
+ $slug,
527
+ 'account',
528
+ 'deactivate_license',
529
+ __fs( 'deactivate-license', $slug ),
530
+ array( 'plugin_id' => $addon_id ),
531
+ false
532
+ );
533
+ } else if ( $is_paid_trial ) {
534
+ $buttons[] = fs_ui_get_action_button(
535
+ $slug,
536
+ 'account',
537
+ 'cancel_trial',
538
+ __fs( 'cancel-trial', $slug ),
539
+ array( 'plugin_id' => $addon_id ),
540
+ false,
541
+ 'dashicons dashicons-download',
542
+ __fs( 'cancel-trial-confirm', $slug ),
543
+ 'POST'
544
+ );
545
+ } else {
546
+ $premium_license = $fs_addon->_get_available_premium_license();
547
+
548
+ if ( is_object( $premium_license ) ) {
549
+ $site = $fs_addon->get_site();
550
+
551
+ $buttons[] = fs_ui_get_action_button(
552
+ $slug,
553
+ 'account',
554
+ 'activate_license',
555
+ sprintf( __fs( 'activate-x-plan', $slug ), $fs_addon->get_plan_title(), ( $site->is_localhost() && $premium_license->is_free_localhost ) ? '[localhost]' : ( 1 < $premium_license->left() ? $premium_license->left() . ' left' : '' ) ),
556
+ array(
557
+ 'plugin_id' => $addon_id,
558
+ 'license_id' => $premium_license->id,
559
+ )
560
+ );
561
+ }
562
+ }
563
+
564
+ if ( 0 == count( $buttons ) ) {
565
+ // Add sync license only if non of the other CTAs are visible.
566
+ $buttons[] = fs_ui_get_action_button(
567
+ $slug,
568
+ 'account',
569
+ $slug . '_sync_license',
570
+ __fs( 'sync-license', $slug ),
571
+ array( 'plugin_id' => $addon_id ),
572
+ false
573
+ );
574
+
575
+ }
576
+ } else if ( ! $show_upgrade ) {
577
+ if ( $fs->is_addon_installed( $addon->slug ) ) {
578
+ $addon_file = $fs->get_addon_basename( $addon->slug );
579
+ $buttons[] = sprintf(
580
+ '<a class="button button-primary" href="%s" title="%s" class="edit">%s</a>',
581
+ wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $addon_file, 'activate-plugin_' . $addon_file ),
582
+ esc_attr( __fs( 'activate-this-addon', $slug ) ),
583
+ __fs( 'activate', $slug )
584
+ );
585
+ } else {
586
+ if ( $fs->is_allowed_to_install() ) {
587
+ $buttons[] = sprintf(
588
+ '<a class="button button-primary" href="%s" class="edit">%s</a>',
589
+ wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $addon->slug ), 'install-plugin_' . $addon->slug ),
590
+ __fs( 'install-now', $slug )
591
+ );
592
+ } else {
593
+ $buttons[] = sprintf(
594
+ '<a target="_blank" class="button button-primary" href="%s" class="edit">%s</a>',
595
+ $fs->_get_latest_download_local_url( $addon_id ),
596
+ __fs( 'download-latest', $slug )
597
+ );
598
+ }
599
+ }
600
+ }
601
+
602
+ if ( $show_upgrade ) {
603
+ $buttons[] = sprintf( '<a href="%s" class="thickbox button button-primary" aria-label="%s" data-title="%s"><i class="dashicons dashicons-cart"></i> %s</a>',
604
+ esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug .
605
+ '&TB_iframe=true&width=600&height=550' ) ),
606
+ esc_attr( sprintf( __fs( 'more-information-about-x', $slug ), $addon->title ) ),
607
+ esc_attr( $addon->title ),
608
+ __fs( ( $fs_addon->has_free_plan() ? 'upgrade' : 'purchase' ), $slug )
609
+ );
610
+ }
611
+
612
+ $buttons_count = count( $buttons );
613
+ ?>
614
+
615
+ <td>
616
+ <!-- Actions -->
617
+ <?php if ($buttons_count > 1) : ?>
618
+ <div class="button-group">
619
+ <?php endif ?>
620
+ <?php foreach ( $buttons as $button ) : ?>
621
+ <?php echo $button ?>
622
+ <?php endforeach ?>
623
+ <?php if ($buttons_count > 1) : ?>
624
+ </div>
625
+ <?php endif ?>
626
+ </td>
627
+ <?php else : ?>
628
+ <?php // Add-on NOT Installed or was never connected.
629
+ ?>
630
+ <td colspan="4">
631
+ <!-- Action -->
632
+ <?php if ( $fs->is_addon_installed( $addon->slug ) ) : ?>
633
+ <?php $addon_file = $fs->get_addon_basename( $addon->slug ) ?>
634
+ <a class="button button-primary"
635
+ href="<?php echo wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $addon_file, 'activate-plugin_' . $addon_file ) ?>"
636
+ title="<?php esc_attr( __fs( 'activate-this-addon', $slug ) ) ?>"
637
+ class="edit"><?php _efs( 'activate', $slug ) ?></a>
638
+ <?php else : ?>
639
+ <?php if ( $fs->is_allowed_to_install() ) : ?>
640
+ <a class="button button-primary"
641
+ href="<?php echo wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $addon->slug ), 'install-plugin_' . $addon->slug ) ?>"><?php _efs( 'install-now', $slug ) ?></a>
642
+ <?php else : ?>
643
+ <a target="_blank" class="button button-primary"
644
+ href="<?php echo $fs->_get_latest_download_local_url( $addon_id ) ?>"><?php _efs( 'download-latest', $slug ) ?></a>
645
+ <?php endif ?>
646
+ <?php endif ?>
647
+ </td>
648
+ <?php endif ?>
649
+ <?php if ( defined( 'WP_FS__DEV_MODE' ) && WP_FS__DEV_MODE ) : ?>
650
+ <td>
651
+ <!-- Optional Delete Action -->
652
+ <?php
653
+ if ( $is_addon_activated ) {
654
+ fs_ui_action_button(
655
+ $slug, 'account',
656
+ 'delete_account',
657
+ __fs( 'delete', $slug ),
658
+ array( 'plugin_id' => $addon_id ),
659
+ false
660
+ );
661
+ }
662
+ ?>
663
+ </td>
664
+ <?php endif ?>
665
+ </tr>
666
+ <?php $odd = ! $odd;
667
+ endforeach ?>
668
+ </tbody>
669
+ </table>
670
+ </div>
671
+ </div>
672
+ <?php endif ?>
673
+
674
+ <?php $fs->do_action( 'after_account_details' ) ?>
675
+ </div>
676
+ </div>
677
+ </div>
678
+ </div>
679
+ </div>
680
+ <?php
681
+ $params = array(
682
+ 'page' => 'account',
683
+ 'module_id' => $fs->get_id(),
684
+ 'module_slug' => $slug,
685
+ 'module_version' => $fs->get_plugin_version(),
686
+ );
687
+ fs_require_template( 'powered-by.php', $params );
688
+ ?>
freemius/templates/add-ons.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ /**
15
+ * @var Freemius
16
+ */
17
+ $fs = freemius( $slug );
18
+
19
+ $open_addon_slug = fs_request_get( 'slug' );
20
+
21
+ $open_addon = false;
22
+
23
+ /**
24
+ * @var FS_Plugin[]
25
+ */
26
+ $addons = $fs->get_addons();
27
+
28
+ $has_addons = ( is_array( $addons ) && 0 < count( $addons ) );
29
+ ?>
30
+ <div id="fs_addons" class="wrap">
31
+ <h2><?php printf( __fs( 'add-ons-for-x', $slug ), $fs->get_plugin_name() ) ?></h2>
32
+
33
+ <div id="poststuff">
34
+ <?php if ( ! $has_addons ) : ?>
35
+ <h3><?php printf(
36
+ '%s... %s',
37
+ __fs( 'oops', $slug ),
38
+ __fs( 'add-ons-missing', $slug )
39
+ ) ?></h3>
40
+ <?php endif ?>
41
+ <ul class="fs-cards-list">
42
+ <?php if ( $has_addons ) : ?>
43
+ <?php foreach ( $addons as $addon ) : ?>
44
+ <?php
45
+ $open_addon = ( $open_addon || ( $open_addon_slug === $addon->slug ) );
46
+
47
+ $price = 0;
48
+ $plan = null;
49
+ $plans_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans.json" );
50
+ if ( ! isset( $plans_result->error ) ) {
51
+ $plans = $plans_result->plans;
52
+ if ( is_array( $plans ) && 0 < count( $plans ) ) {
53
+ $plan = new FS_Plugin_Plan( $plans[0] );
54
+ $pricing_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans/{$plan->id}/pricing.json" );
55
+ if ( ! isset( $pricing_result->error ) ) {
56
+ // Update plan's pricing.
57
+ $plan->pricing = $pricing_result->pricing;
58
+
59
+ if ( is_array( $plan->pricing ) && 0 < count( $plan->pricing ) ) {
60
+ $min_price = 999999;
61
+ foreach ( $plan->pricing as $pricing ) {
62
+ if ( ! is_null( $pricing->annual_price ) && $pricing->annual_price > 0 ) {
63
+ $min_price = min( $min_price, $pricing->annual_price );
64
+ } else if ( ! is_null( $pricing->monthly_price ) && $pricing->monthly_price > 0 ) {
65
+ $min_price = min( $min_price, 12 * $pricing->monthly_price );
66
+ }
67
+ }
68
+
69
+ if ( $min_price < 999999 ) {
70
+ $price = $min_price;
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ ?>
77
+ <li class="fs-card fs-addon" data-slug="<?php echo $addon->slug ?>">
78
+ <?php
79
+ echo sprintf( '<a href="%s" class="thickbox fs-overlay" aria-label="%s" data-title="%s"></a>',
80
+ esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug .
81
+ '&TB_iframe=true&width=600&height=550' ) ),
82
+ esc_attr( sprintf( __fs( 'more-information-about-x', $slug ), $addon->title ) ),
83
+ esc_attr( $addon->title )
84
+ );
85
+ ?>
86
+ <?php
87
+ if ( is_null( $addon->info ) ) {
88
+ $addon->info = new stdClass();
89
+ }
90
+ if ( ! isset( $addon->info->card_banner_url ) ) {
91
+ $addon->info->card_banner_url = '//dashboard.freemius.com/assets/img/marketing/blueprint-300x100.jpg';
92
+ }
93
+ if ( ! isset( $addon->info->short_description ) ) {
94
+ $addon->info->short_description = 'What\'s the one thing your add-on does really, really well?';
95
+ }
96
+ ?>
97
+ <div class="fs-inner">
98
+ <ul>
99
+ <li class="fs-card-banner"
100
+ style="background-image: url('<?php echo $addon->info->card_banner_url ?>');"></li>
101
+ <!-- <li class="fs-tag"></li>-->
102
+ <li class="fs-title"><?php echo $addon->title ?></li>
103
+ <li class="fs-offer">
104
+ <span
105
+ class="fs-price"><?php echo ( 0 == $price ) ? __fs( 'free', $slug ) : ('$' . number_format( $price, 2 ) . ($plan->has_trial() ? ' - ' . __fs('trial', $slug) : '')) ?></span>
106
+ </li>
107
+ <li class="fs-description"><?php echo ! empty( $addon->info->short_description ) ? $addon->info->short_description : 'SHORT DESCRIPTION' ?></li>
108
+ <li class="fs-cta"><a class="button"><?php _efs( 'view-details', $slug ) ?></a></li>
109
+ </ul>
110
+ </div>
111
+ </li>
112
+ <?php endforeach ?>
113
+ <?php endif ?>
114
+ </ul>
115
+ </div>
116
+ </div>
117
+ <script type="text/javascript">
118
+ (function ($) {
119
+ <?php if ( $open_addon ) : ?>
120
+
121
+ var interval = setInterval(function () {
122
+ // Open add-on information page.
123
+ $('.fs-card[data-slug=<?php echo $open_addon_slug ?>] a').click();
124
+ if ($('#TB_iframeContent').length > 0) {
125
+ clearInterval(interval);
126
+ interval = null;
127
+ }
128
+ }, 200);
129
+
130
+ <?php else : ?>
131
+
132
+
133
+ $('.fs-card.fs-addon').mouseover(function(){
134
+ $(this).find('.fs-cta .button').addClass('button-primary');
135
+ });
136
+
137
+ $('.fs-card.fs-addon').mouseout(function(){
138
+ $(this).find('.fs-cta .button').removeClass('button-primary');
139
+ });
140
+
141
+ <?php endif ?>
142
+ })(jQuery);
143
+ </script>
144
+ <?php
145
+ $params = array(
146
+ 'page' => 'addons',
147
+ 'module_id' => $fs->get_id(),
148
+ 'module_slug' => $slug,
149
+ 'module_version' => $fs->get_plugin_version(),
150
+ );
151
+ fs_require_template( 'powered-by.php', $params );
152
+ ?>
freemius/templates/admin-notice.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+ ?>
13
+ <div<?php if ( ! empty( $VARS['id'] ) ) : ?> data-id="<?php echo $VARS['id'] ?>"<?php endif ?><?php if ( ! empty( $VARS['slug'] ) ) : ?> data-slug="<?php echo $VARS['slug'] ?>"<?php endif ?>
14
+ class="<?php
15
+ switch ( $VARS['type'] ) {
16
+ case 'error':
17
+ echo 'error form-invalid';
18
+ break;
19
+ case 'promotion':
20
+ echo 'updated promotion';
21
+ break;
22
+ case 'update':
23
+ // echo 'update-nag update';
24
+ // break;
25
+ case 'success':
26
+ default:
27
+ echo 'updated success';
28
+ break;
29
+ }
30
+ ?> fs-notice<?php if ( ! empty( $VARS['sticky'] ) ) {
31
+ echo ' fs-sticky';
32
+ } ?><?php if ( ! empty( $VARS['plugin'] ) ) {
33
+ echo ' fs-has-title';
34
+ } ?>"><?php if ( ! empty( $VARS['plugin'] ) ) : ?>
35
+ <label class="fs-plugin-title"><?php echo $VARS['plugin'] ?></label>
36
+ <?php endif ?>
37
+ <?php if ( ! empty( $VARS['sticky'] ) ) : ?>
38
+ <div class="fs-close"><i class="dashicons dashicons-no"
39
+ title="<?php _efs( 'dismiss' ) ?>"></i> <span><?php _efs( 'dismiss' ) ?></span>
40
+ </div>
41
+ <?php endif ?>
42
+ <div class="fs-notice-body">
43
+ <?php if ( ! empty( $VARS['title'] ) ) : ?><b><?php echo $VARS['title'] ?></b> <?php endif ?>
44
+ <?php echo $VARS['message'] ?>
45
+ </div>
46
+ </div>
freemius/templates/all-admin-notice.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+ ?>
13
+ <div class="<?php
14
+ switch ($VARS['type']) {
15
+ case 'error':
16
+ echo 'error form-invalid';
17
+ break;
18
+ case 'update-nag':
19
+ echo 'update-nag ';
20
+ break;
21
+ case 'update':
22
+ case 'success':
23
+ default:
24
+ echo 'updated success';
25
+ break;
26
+ }
27
+ ?> fs-notice">
28
+ <?php if ('update-nag' !== $VARS['type']) : ?><p><?php endif ?>
29
+ <?php if (!empty($VARS['title'])) : ?>
30
+ <b><?php echo $VARS['title'] ?></b>
31
+ <?php endif ?>
32
+ <?php echo $VARS['message'] ?>
33
+ <?php if ('update-nag' !== $VARS['type']) : ?></p><?php endif ?>
34
+ <?php if ($VARS['sticky']) : ?><i class="dashicons dashicons-no"></i><?php endif ?>
35
+ </div>
freemius/templates/billing.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2016, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.2.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ /**
15
+ * @var Freemius $fs
16
+ */
17
+ $fs = freemius( $slug );
18
+
19
+ /**
20
+ * @var FS_Plugin_Tag $update
21
+ */
22
+ $update = $fs->get_update( false, false );
23
+
24
+ $is_paying = $fs->is_paying();
25
+ $user = $fs->get_user();
26
+ $site = $fs->get_site();
27
+ $name = $user->get_name();
28
+ $license = $fs->_get_license();
29
+ $subscription = $fs->_get_subscription();
30
+ $plan = $fs->get_plan();
31
+ $is_active_subscription = ( is_object( $subscription ) && $subscription->is_active() );
32
+ $is_paid_trial = $fs->is_paid_trial();
33
+ $show_upgrade = ( ! $is_paying && ! $is_paid_trial );
34
+ ?>
35
+
36
+ <div id="fs_account" class="wrap">
37
+ <h2 class="nav-tab-wrapper">
38
+ <a href="<?php echo $fs->get_account_url() ?>" class="nav-tab"><?php _efs( 'account', $slug ) ?></a>
39
+ <?php if ( $fs->has_addons() ) : ?>
40
+ <a href="<?php echo $fs->_get_admin_page_url( 'addons' ) ?>"
41
+ class="nav-tab"><?php _efs( 'add-ons', $slug ) ?></a>
42
+ <?php endif ?>
43
+ <?php if ( $fs->is_not_paying() && $fs->has_paid_plan() ) : ?>
44
+ <a href="<?php echo $fs->get_upgrade_url() ?>" class="nav-tab"><?php _efs( 'upgrade', $slug ) ?></a>
45
+ <?php if ( $fs->apply_filters( 'show_trial', true ) && ! $fs->is_trial_utilized() && $fs->has_trial_plan() ) : ?>
46
+ <a href="<?php echo $fs->get_trial_url() ?>"
47
+ class="nav-tab"><?php _efs( 'free-trial', $slug ) ?></a>
48
+ <?php endif ?>
49
+ <?php endif ?>
50
+ <?php if ( ! $plan->is_free() ) : ?>
51
+ <a href="<?php echo $fs->get_account_tab_url( 'billing' ) ?>"
52
+ class="nav-tab nav-tab-active"><?php _efs( 'billing', $slug ) ?></a>
53
+ <?php endif ?>
54
+ </h2>
55
+
56
+ <div id="poststuff">
57
+ <div>
58
+ <div class="has-sidebar has-right-sidebar">
59
+ <div class="has-sidebar-content">
60
+ <div class="postbox">
61
+ <h3><?php _efs( 'payments', $slug ) ?></h3>
62
+
63
+ <?php
64
+ $payments = $fs->_fetch_payments();
65
+ ?>
66
+
67
+ <div class="inside">
68
+ <table class="widefat">
69
+ <thead>
70
+ <tr>
71
+ <th><?php _efs( 'id', $slug ) ?></th>
72
+ <th><?php _efs( 'date', $slug ) ?></th>
73
+ <!-- <th>--><?php //_efs( 'transaction' ) ?><!--</th>-->
74
+ <th><?php _efs( 'amount', $slug ) ?></th>
75
+ <th><?php _efs( 'invoice', $slug ) ?></th>
76
+ </tr>
77
+ </thead>
78
+ <tbody>
79
+ <?php $odd = true ?>
80
+ <?php foreach ( $payments as $payment ) : ?>
81
+ <tr<?php echo $odd ? ' class="alternate"' : '' ?>>
82
+ <td><?php echo $payment->id ?></td>
83
+ <td><?php echo date( 'M j, Y', strtotime( $payment->created ) ) ?></td>
84
+ <td>$<?php echo $payment->gross ?></td>
85
+ <td><a href="<?php echo $fs->_get_invoice_api_url($payment->id) ?>" class="button button-small"
86
+ target="_blank"><?php _efs( 'invoice', $slug ) ?></a></td>
87
+ </tr>
88
+ <?php $odd = ! $odd; endforeach ?>
89
+ </tbody>
90
+ </table>
91
+ </div>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ </div>
96
+ </div>
97
+ </div>
98
+ <?php
99
+ $params = array(
100
+ 'page' => 'account',
101
+ 'module_id' => $fs->get_id(),
102
+ 'module_slug' => $slug,
103
+ 'module_version' => $fs->get_plugin_version(),
104
+ );
105
+ fs_require_template( 'powered-by.php', $params );
106
+ ?>
freemius/templates/checkout.php ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ wp_enqueue_script( 'jquery' );
14
+ wp_enqueue_script( 'json2' );
15
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
16
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
17
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
18
+
19
+ $slug = $VARS['slug'];
20
+ $fs = freemius( $slug );
21
+
22
+ $timestamp = time();
23
+
24
+ $context_params = array(
25
+ 'plugin_id' => $fs->get_id(),
26
+ 'plugin_public_key' => $fs->get_public_key(),
27
+ 'plugin_version' => $fs->get_plugin_version(),
28
+ );
29
+
30
+ // Get site context secure params.
31
+ if ( $fs->is_registered() ) {
32
+ $site = $fs->get_site();
33
+ $plugin_id = fs_request_get( 'plugin_id', $fs->get_id() );
34
+
35
+ if ($plugin_id != $fs->get_id()) {
36
+ if ( $fs->is_addon_activated( $plugin_id ) ) {
37
+ $fs_addon = Freemius::get_instance_by_id( $plugin_id );
38
+ $site = $fs_addon->get_site();
39
+ }
40
+ }
41
+
42
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
43
+ $site,
44
+ $timestamp,
45
+ 'checkout'
46
+ ) );
47
+ } else {
48
+ $current_user = Freemius::_get_current_wp_user();
49
+
50
+ // Add site and user info to the request, this information
51
+ // is NOT being stored unless the user complete the purchase
52
+ // and agrees to the TOS.
53
+ $context_params = array_merge( $context_params, array(
54
+ 'user_firstname' => $current_user->user_firstname,
55
+ 'user_lastname' => $current_user->user_lastname,
56
+ 'user_email' => $current_user->user_email,
57
+ // 'user_nickname' => $current_user->user_nicename,
58
+ // 'plugin_slug' => $slug,
59
+ // 'site_url' => get_site_url(),
60
+ // 'site_name' => get_bloginfo( 'name' ),
61
+ // 'platform_version' => get_bloginfo( 'version' ),
62
+ // 'language' => get_bloginfo( 'language' ),
63
+ // 'charset' => get_bloginfo( 'charset' ),
64
+ // 'account_url' => fs_nonce_url( $fs->_get_admin_page_url(
65
+ // 'account',
66
+ // array( 'fs_action' => 'sync_user' )
67
+ // ), 'sync_user' ),
68
+ ) );
69
+
70
+ $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
71
+
72
+ if ( is_object( $fs_user ) ) {
73
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
74
+ $fs_user,
75
+ $timestamp,
76
+ 'checkout'
77
+ ) );
78
+ }
79
+ }
80
+
81
+ if ( $fs->is_payments_sandbox() )
82
+ {
83
+ // Append plugin secure token for sandbox mode authentication.
84
+ $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
85
+ $fs->get_plugin(),
86
+ $timestamp,
87
+ 'checkout'
88
+ );
89
+
90
+ /**
91
+ * @since 1.1.7.3 Add security timestamp for sandbox even for anonymous user.
92
+ */
93
+ if ( empty( $context_params['s_ctx_ts'] ) ) {
94
+ $context_params['s_ctx_ts'] = $timestamp;
95
+ }
96
+ }
97
+
98
+ $return_url = $fs->_get_sync_license_url( isset( $_GET['plugin_id'] ) ? $_GET['plugin_id'] : $fs->get_id() );
99
+
100
+ $query_params = array_merge( $context_params, $_GET, array(
101
+ // Current plugin version.
102
+ 'plugin_version' => $fs->get_plugin_version(),
103
+ 'return_url' => $return_url,
104
+ // Admin CSS URL for style/design competability.
105
+ // 'wp_admin_css' => get_bloginfo('wpurl') . "/wp-admin/load-styles.php?c=1&load=buttons,wp-admin,dashicons",
106
+ ) );
107
+ ?>
108
+ <div class="fs-secure-notice">
109
+ <i class="dashicons dashicons-lock"></i>
110
+ <span><b>Secure HTTPS Checkout</b> - PCI compliant, running via iframe from external domain</span>
111
+ </div>
112
+ <div id="fs_contact" class="wrap" style="margin: 40px 0 -65px -20px;">
113
+ <div id="iframe"></div>
114
+ <script type="text/javascript">
115
+ // http://stackoverflow.com/questions/4583703/jquery-post-request-not-ajax
116
+ jQuery(function ($) {
117
+ $.extend({
118
+ form: function (url, data, method) {
119
+ if (method == null) method = 'POST';
120
+ if (data == null) data = {};
121
+
122
+ var form = $('<form>').attr({
123
+ method: method,
124
+ action: url
125
+ }).css({
126
+ display: 'none'
127
+ });
128
+
129
+ var addData = function (name, data) {
130
+ if ($.isArray(data)) {
131
+ for (var i = 0; i < data.length; i++) {
132
+ var value = data[i];
133
+ addData(name + '[]', value);
134
+ }
135
+ } else if (typeof data === 'object') {
136
+ for (var key in data) {
137
+ if (data.hasOwnProperty(key)) {
138
+ addData(name + '[' + key + ']', data[key]);
139
+ }
140
+ }
141
+ } else if (data != null) {
142
+ form.append($('<input>').attr({
143
+ type : 'hidden',
144
+ name : String(name),
145
+ value: String(data)
146
+ }));
147
+ }
148
+ };
149
+
150
+ for (var key in data) {
151
+ if (data.hasOwnProperty(key)) {
152
+ addData(key, data[key]);
153
+ }
154
+ }
155
+
156
+ return form.appendTo('body');
157
+ }
158
+ });
159
+ });
160
+
161
+ (function ($) {
162
+ $(function () {
163
+
164
+ var
165
+ // Keep track of the iframe height.
166
+ iframe_height = 800,
167
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
168
+ // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
169
+ // passed via query string or hard coded into the child page, it depends on your needs).
170
+ src = base_url + '/checkout/?<?php echo (isset($_REQUEST['XDEBUG_SESSION']) ? 'XDEBUG_SESSION=' . $_REQUEST['XDEBUG_SESSION'] . '&' : '') . http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
171
+
172
+ // Append the Iframe into the DOM.
173
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
174
+ .appendTo('#iframe');
175
+
176
+ FS.PostMessage.init(base_url);
177
+ FS.PostMessage.receiveOnce('height', function (data) {
178
+ var h = data.height;
179
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
180
+ iframe_height = h;
181
+ $("#iframe iframe").height(iframe_height + 'px');
182
+ }
183
+ });
184
+
185
+ FS.PostMessage.receiveOnce('install', function (data) {
186
+ // Post data to activation URL.
187
+ $.form('<?php echo fs_nonce_url($fs->_get_admin_page_url('account', array(
188
+ 'fs_action' => $slug . '_activate_new',
189
+ 'plugin_id' => isset($_GET['plugin_id']) ? $_GET['plugin_id'] : $fs->get_id()
190
+ )), $slug . '_activate_new') ?>', {
191
+ user_id : data.user.id,
192
+ user_secret_key : data.user.secret_key,
193
+ user_public_key : data.user.public_key,
194
+ install_id : data.install.id,
195
+ install_secret_key: data.install.secret_key,
196
+ install_public_key: data.install.public_key
197
+ }).submit();
198
+ });
199
+
200
+ FS.PostMessage.receiveOnce('pending_activation', function (data) {
201
+ $.form('<?php echo fs_nonce_url($fs->_get_admin_page_url('account', array(
202
+ 'fs_action' => $slug . '_activate_new',
203
+ 'plugin_id' => fs_request_get('plugin_id', $fs->get_id()),
204
+ 'pending_activation' => true,
205
+ )), $slug . '_activate_new') ?>', {
206
+ user_email: data.user_email
207
+ }).submit();
208
+ });
209
+
210
+ FS.PostMessage.receiveOnce('get_context', function () {
211
+ console.debug('receiveOnce', 'get_context');
212
+
213
+ // If the user didn't connect his account with Freemius,
214
+ // once he accepts the Terms of Service and Privacy Policy,
215
+ // and then click the purchase button, the context information
216
+ // of the user will be shared with Freemius in order to complete the
217
+ // purchase workflow and activate the license for the right user.
218
+ FS.PostMessage.post('context', {
219
+ plugin_id : '<?php echo $fs->get_id() ?>',
220
+ plugin_public_key: '<?php echo $fs->get_public_key() ?>',
221
+ plugin_version : '<?php echo $fs->get_plugin_version() ?>',
222
+ plugin_slug : '<?php echo $slug ?>',
223
+ site_name : '<?php echo get_bloginfo('name') ?>',
224
+ platform_version : '<?php echo get_bloginfo('version') ?>',
225
+ language : '<?php echo get_bloginfo('language') ?>',
226
+ charset : '<?php echo get_bloginfo('charset') ?>',
227
+ return_url : '<?php echo $return_url ?>',
228
+ account_url : '<?php echo fs_nonce_url($fs->_get_admin_page_url(
229
+ 'account',
230
+ array('fs_action' => 'sync_user')
231
+ ), 'sync_user') ?>',
232
+ activation_url : '<?php echo fs_nonce_url($fs->_get_admin_page_url('',
233
+ array(
234
+ 'fs_action' => $slug . '_activate_new',
235
+ 'plugin_id' => fs_request_get('plugin_id', $fs->get_id()),
236
+
237
+ )),
238
+ $slug . '_activate_new') ?>'
239
+ }, iframe[0]);
240
+ });
241
+
242
+ FS.PostMessage.receiveOnce('get_dimensions', function (data) {
243
+ console.debug('receiveOnce', 'get_dimensions');
244
+
245
+ FS.PostMessage.post('dimensions', {
246
+ height : $(document.body).height(),
247
+ scrollTop: $(document).scrollTop()
248
+ }, iframe[0]);
249
+ });
250
+ });
251
+ })(jQuery);
252
+ </script>
253
+ </div>
254
+ <?php
255
+ $params = array(
256
+ 'page' => 'checkout',
257
+ 'module_id' => $fs->get_id(),
258
+ 'module_slug' => $slug,
259
+ 'module_version' => $fs->get_plugin_version(),
260
+ );
261
+ fs_require_template( 'powered-by.php', $params );
262
+ ?>
freemius/templates/connect.php ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+ $is_pending_activation = $fs->is_pending_activation();
16
+ $is_premium_only = $fs->is_only_premium();
17
+ $has_paid_plans = $fs->has_paid_plan();
18
+ $is_premium_code = $fs->is_premium();
19
+ $is_freemium = $fs->is_freemium();
20
+
21
+ $fs->_enqueue_connect_essentials();
22
+
23
+ $current_user = Freemius::_get_current_wp_user();
24
+
25
+ $first_name = $current_user->user_firstname;
26
+ if ( empty( $first_name ) ) {
27
+ $first_name = $current_user->nickname;
28
+ }
29
+
30
+ $site_url = get_site_url();
31
+ $protocol_pos = strpos( $site_url, '://' );
32
+ if ( false !== $protocol_pos ) {
33
+ $site_url = substr( $site_url, $protocol_pos + 3 );
34
+ }
35
+
36
+ $freemius_site_url = $fs->has_paid_plan() ?
37
+ 'https://freemius.com/wordpress/' :
38
+ // Insights platform information.
39
+ 'https://freemius.com/wordpress/usage-tracking/';
40
+
41
+ $freemius_site_url .= '?' . http_build_query( array(
42
+ 'id' => $fs->get_id(),
43
+ 'slug' => $slug,
44
+ ) );
45
+
46
+ $freemius_link = '<a href="' . $freemius_site_url . '" target="_blank" tabindex="1">freemius.com</a>';
47
+
48
+ $error = fs_request_get( 'error' );
49
+
50
+ $require_license_key = $is_premium_only ||
51
+ ( $is_freemium && $is_premium_code && fs_request_get_bool( 'require_license', true ) );
52
+
53
+ if ( $is_pending_activation ) {
54
+ $require_license_key = false;
55
+ }
56
+
57
+ if ( $require_license_key ) {
58
+ $fs->_require_license_activation_dialog();
59
+ }
60
+ ?>
61
+ <div id="fs_connect"
62
+ class="wrap<?php if ( ! $fs->is_enable_anonymous() || $is_pending_activation || $require_license_key ) {
63
+ echo ' fs-anonymous-disabled';
64
+ } ?>">
65
+ <div class="fs-visual">
66
+ <b class="fs-site-icon"><i class="dashicons dashicons-wordpress"></i></b>
67
+ <i class="dashicons dashicons-plus fs-first"></i>
68
+ <?php
69
+ $vars = array( 'slug' => $slug );
70
+ fs_require_once_template( 'plugin-icon.php', $vars );
71
+ ?>
72
+ <i class="dashicons dashicons-plus fs-second"></i>
73
+ <img class="fs-connect-logo" width="80" height="80" src="//img.freemius.com/connect-logo.png"/>
74
+ </div>
75
+ <div class="fs-content">
76
+ <?php if ( ! empty( $error ) ) : ?>
77
+ <p class="fs-error"><?php echo $error ?></p>
78
+ <?php endif ?>
79
+ <p><?php
80
+ $button_label = 'opt-in-connect';
81
+
82
+ if ( $is_pending_activation ) {
83
+ $button_label = 'resend-activation-email';
84
+
85
+ echo $fs->apply_filters( 'pending_activation_message', sprintf(
86
+ __fs( 'thanks-x', $slug ) . '<br>' .
87
+ __fs( 'pending-activation-message', $slug ),
88
+ $first_name,
89
+ '<b>' . $fs->get_plugin_name() . '</b>',
90
+ '<b>' . $current_user->user_email . '</b>'
91
+ ) );
92
+ } else if ( $require_license_key ) {
93
+ $button_label = 'agree-activate-license';
94
+
95
+ echo $fs->apply_filters( 'connect-message_on-premium',
96
+ sprintf( __fs( 'hey-x', $slug ), $first_name ) . '<br>' .
97
+ sprintf( __fs( 'thanks-for-purchasing', $slug ), '<b>' . $fs->get_plugin_name() . '</b>' ),
98
+ $first_name,
99
+ $fs->get_plugin_name()
100
+ );
101
+ } else {
102
+ $filter = 'connect_message';
103
+ $default_optin_message = 'connect-message';
104
+
105
+ if ( $fs->is_plugin_update() ) {
106
+ // If Freemius was added on a plugin update, set different
107
+ // opt-in message.
108
+ $default_optin_message = 'connect-message_on-update';
109
+
110
+ // If user customized the opt-in message on update, use
111
+ // that message. Otherwise, fallback to regular opt-in
112
+ // custom message if exist.
113
+ if ( $fs->has_filter( 'connect_message_on_update' ) ) {
114
+ $filter = 'connect_message_on_update';
115
+ }
116
+ }
117
+
118
+ echo $fs->apply_filters( $filter,
119
+ sprintf(
120
+ __fs( 'hey-x', $slug ) . '<br>' .
121
+ __fs( $default_optin_message, $slug ),
122
+ $first_name,
123
+ '<b>' . $fs->get_plugin_name() . '</b>',
124
+ '<b>' . $current_user->user_login . '</b>',
125
+ '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
126
+ $freemius_link
127
+ ),
128
+ $first_name,
129
+ $fs->get_plugin_name(),
130
+ $current_user->user_login,
131
+ '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
132
+ $freemius_link
133
+ );
134
+ }
135
+ ?></p>
136
+ <?php if ( $require_license_key ) : ?>
137
+ <div class="fs-license-key-container">
138
+ <input id="fs_license_key" name="fs_key" type="text" required maxlength="32"
139
+ placeholder="<?php _efs( 'license-key', $slug ) ?>" tabindex="1"/>
140
+ <i class="dashicons dashicons-admin-network"></i>
141
+ <a class="show-license-resend-modal show-license-resend-modal-<?php echo $slug; ?>"
142
+ href="#"><?php _efs( 'cant-find-license-key' ); ?></a>
143
+ </div>
144
+ <?php endif ?>
145
+ </div>
146
+ <div class="fs-actions">
147
+ <?php if ( $fs->is_enable_anonymous() && ! $is_pending_activation && ! $require_license_key ) : ?>
148
+ <a href="<?php echo wp_nonce_url( $fs->_get_admin_page_url( '', array( 'fs_action' => $slug . '_skip_activation' ) ), $slug . '_skip_activation' ) ?>"
149
+ class="button button-secondary" tabindex="2"><?php _efs( 'skip', $slug ) ?></a>
150
+ <?php endif ?>
151
+
152
+ <?php $fs_user = Freemius::_get_user_by_email( $current_user->user_email ) ?>
153
+ <?php if ( is_object( $fs_user ) && ! $is_pending_activation ) : ?>
154
+ <form action="" method="POST">
155
+ <input type="hidden" name="fs_action" value="<?php echo $slug ?>_activate_existing">
156
+ <?php wp_nonce_field( 'activate_existing_' . $fs->get_public_key() ) ?>
157
+ <button class="button button-primary" tabindex="1"
158
+ type="submit"<?php if ( $require_license_key ) {
159
+ echo ' disabled="disabled"';
160
+ } ?>><?php _efs( $button_label, $slug ) ?></button>
161
+ </form>
162
+ <?php else : ?>
163
+ <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/">
164
+ <?php $params = $fs->get_opt_in_params() ?>
165
+ <?php foreach ( $params as $name => $value ) : ?>
166
+ <input type="hidden" name="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>">
167
+ <?php endforeach ?>
168
+ <button class="button button-primary" tabindex="1"
169
+ type="submit"<?php if ( $require_license_key ) {
170
+ echo ' disabled="disabled"';
171
+ } ?>><?php _efs( $button_label, $slug ) ?></button>
172
+ </form>
173
+ <?php endif ?>
174
+ </div><?php
175
+
176
+ // Set core permission list items.
177
+ $permissions = array(
178
+ 'profile' => array(
179
+ 'icon-class' => 'dashicons dashicons-admin-users',
180
+ 'label' => __fs( 'permissions-profile' ),
181
+ 'desc' => __fs( 'permissions-profile_desc' ),
182
+ 'priority' => 5,
183
+ ),
184
+ 'site' => array(
185
+ 'icon-class' => 'dashicons dashicons-admin-settings',
186
+ 'label' => __fs( 'permissions-site' ),
187
+ 'desc' => __fs( 'permissions-site_desc' ),
188
+ 'priority' => 10,
189
+ ),
190
+ 'events' => array(
191
+ 'icon-class' => 'dashicons dashicons-admin-plugins',
192
+ 'label' => __fs( 'permissions-events' ),
193
+ 'desc' => __fs( 'permissions-events_desc' ),
194
+ 'priority' => 20,
195
+ ),
196
+ // 'plugins_themes' => array(
197
+ // 'icon-class' => 'dashicons dashicons-admin-settings',
198
+ // 'label' => __fs( 'permissions-plugins_themes' ),
199
+ // 'desc' => __fs( 'permissions-plugins_themes_desc' ),
200
+ // 'priority' => 30,
201
+ // ),
202
+ );
203
+
204
+ // Add newsletter permissions if enabled.
205
+ if ( $fs->is_permission_requested( 'newsletter' ) ) {
206
+ $permissions['newsletter'] = array(
207
+ 'icon-class' => 'dashicons dashicons-email-alt',
208
+ 'label' => __fs( 'permissions-newsletter' ),
209
+ 'desc' => __fs( 'permissions-newsletter_desc' ),
210
+ 'priority' => 15,
211
+ );
212
+ }
213
+
214
+ // Allow filtering of the permissions list.
215
+ $permissions = $fs->apply_filters( 'permission_list', $permissions );
216
+
217
+ // Sort by priority.
218
+ uasort( $permissions, 'fs_sort_by_priority' );
219
+
220
+ if ( ! empty( $permissions ) ) : ?>
221
+ <div class="fs-permissions">
222
+ <?php if ( $require_license_key ) : ?>
223
+ <p class="fs-license-sync-disclaimer"><?php printf( __fs( 'license-sync-disclaimer', $slug ), $freemius_link ) ?></p>
224
+ <?php endif ?>
225
+ <a class="fs-trigger" href="#" tabindex="1"><?php _efs( 'what-permissions', $slug ) ?></a>
226
+ <ul><?php
227
+ foreach ( $permissions as $id => $permission ) : ?>
228
+ <li id="fs-permission-<?php esc_attr_e( $id ); ?>"
229
+ class="fs-permission fs-<?php esc_attr_e( $id ); ?>">
230
+ <i class="<?php esc_attr_e( $permission['icon-class'] ); ?>"></i>
231
+
232
+ <div>
233
+ <span><?php esc_html_e( $permission['label'] ); ?></span>
234
+
235
+ <p><?php esc_html_e( $permission['desc'] ); ?></p>
236
+ </div>
237
+ </li>
238
+ <?php endforeach; ?>
239
+ </ul>
240
+ </div>
241
+ <?php endif ?>
242
+ <?php if ( $is_premium_code && $is_freemium ) : ?>
243
+ <div class="fs-freemium-licensing">
244
+ <p>
245
+ <?php if ( $require_license_key ) : ?>
246
+ <?php _efs( 'dont-have-license-key', $slug ) ?>
247
+ <a data-require-license="false" tabindex="1"><?php _efs( 'activate-free-version', $slug ) ?></a>
248
+ <?php else : ?>
249
+ <?php _efs( 'have-license-key', $slug ) ?>
250
+ <a data-require-license="true" tabindex="1"><?php _efs( 'activate-license', $slug ) ?></a>
251
+ <?php endif ?>
252
+ </p>
253
+ </div>
254
+ <?php endif ?>
255
+ <div class="fs-terms">
256
+ <a href="https://freemius.com/privacy/" target="_blank"
257
+ tabindex="1"><?php _efs( 'privacy-policy', $slug ) ?></a>
258
+ &nbsp;&nbsp;-&nbsp;&nbsp;
259
+ <a href="https://freemius.com/terms/" target="_blank" tabindex="1"><?php _efs( 'tos', $slug ) ?></a>
260
+ </div>
261
+ </div>
262
+ <script type="text/javascript">
263
+ (function ($) {
264
+ var $primaryCta = $('.fs-actions .button.button-primary'),
265
+ $form = $('.fs-actions form'),
266
+ requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>,
267
+ $licenseSecret,
268
+ $licenseKeyInput = $('#fs_license_key');
269
+
270
+ $('.fs-actions .button').on('click', function () {
271
+ // Set loading mode.
272
+ $(document.body).css({'cursor': 'wait'});
273
+ });
274
+
275
+ $form.on('submit', function () {
276
+ /**
277
+ * @author Vova Feldman (@svovaf)
278
+ * @since 1.1.9
279
+ */
280
+ if (requireLicenseKey) {
281
+ if (null == $licenseSecret) {
282
+ $licenseSecret = $('<input type="hidden" name="license_secret_key" value="" />');
283
+ $form.append($licenseSecret);
284
+ }
285
+
286
+ // Update secret key if premium only plugin.
287
+ $licenseSecret.val($licenseKeyInput.val());
288
+ }
289
+
290
+ return true;
291
+ });
292
+
293
+ $primaryCta.on('click', function () {
294
+ $(this).addClass('fs-loading');
295
+ $(this).html('<?php _efs( $is_pending_activation ? 'sending-email' : 'activating' , $slug ) ?>...').css({'cursor': 'wait'});
296
+ });
297
+
298
+ $('.fs-permissions .fs-trigger').on('click', function () {
299
+ $('.fs-permissions').toggleClass('fs-open');
300
+ });
301
+
302
+ if (requireLicenseKey) {
303
+ /**
304
+ * Submit license key on enter.
305
+ *
306
+ * @author Vova Feldman (@svovaf)
307
+ * @since 1.1.9
308
+ */
309
+ $licenseKeyInput.keypress(function (e) {
310
+ if (e.which == 13) {
311
+ if ('' !== $(this).val()) {
312
+ $primaryCta.click();
313
+ return false;
314
+ }
315
+ }
316
+ });
317
+
318
+ /**
319
+ * Disable activation button when empty license key.
320
+ *
321
+ * @author Vova Feldman (@svovaf)
322
+ * @since 1.1.9
323
+ */
324
+ $licenseKeyInput.on('keyup paste delete cut', function () {
325
+ setTimeout(function () {
326
+ if ('' === $licenseKeyInput.val()) {
327
+ $primaryCta.attr('disabled', 'disabled');
328
+ } else {
329
+ $primaryCta.prop('disabled', false);
330
+ }
331
+ }, 100);
332
+ }).focus();
333
+ }
334
+
335
+ /**
336
+ * Set license mode trigger URL.
337
+ *
338
+ * @author Vova Feldman (@svovaf)
339
+ * @since 1.1.9
340
+ */
341
+ var $connectLicenseModeTrigger = $('#fs_connect .fs-freemium-licensing a');
342
+ if ($connectLicenseModeTrigger.length > 0) {
343
+ $connectLicenseModeTrigger.attr('href', window.location.href + '&require_license=' + $connectLicenseModeTrigger.attr('data-require-license'))
344
+ }
345
+ })(jQuery);
346
+ </script>
freemius/templates/contact.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ wp_enqueue_script( 'jquery' );
14
+ wp_enqueue_script( 'json2' );
15
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
16
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
17
+ fs_enqueue_local_style( 'fs_checkout', '/admin/common.css' );
18
+
19
+ $slug = $VARS['slug'];
20
+ $fs = freemius( $slug );
21
+
22
+ $context_params = array(
23
+ 'plugin_id' => $fs->get_id(),
24
+ 'plugin_public_key' => $fs->get_public_key(),
25
+ 'plugin_version' => $fs->get_plugin_version(),
26
+ );
27
+
28
+
29
+ // Get site context secure params.
30
+ if ( $fs->is_registered() ) {
31
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
32
+ $fs->get_site(),
33
+ time(),
34
+ 'contact'
35
+ ) );
36
+ }
37
+
38
+ $query_params = array_merge( $_GET, array_merge( $context_params, array(
39
+ 'plugin_version' => $fs->get_plugin_version(),
40
+ 'wp_login_url' => wp_login_url(),
41
+ 'site_url' => get_site_url(),
42
+ // 'wp_admin_css' => get_bloginfo('wpurl') . "/wp-admin/load-styles.php?c=1&load=buttons,wp-admin,dashicons",
43
+ ) ) );
44
+ ?>
45
+ <div class="fs-secure-notice">
46
+ <i class="dashicons dashicons-lock"></i>
47
+ <span><b>Secure HTTPS contact page</b>, running via iframe from external domain</span>
48
+ </div>
49
+ <div id="fs_contact" class="wrap" style="margin: 40px 0 -65px -20px;">
50
+ <div id="iframe"></div>
51
+ <script type="text/javascript">
52
+ (function ($) {
53
+ $(function () {
54
+
55
+ var
56
+ // Keep track of the iframe height.
57
+ iframe_height = 800,
58
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
59
+ src = base_url + '/contact/?<?php echo http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
60
+
61
+ // Append the Iframe into the DOM.
62
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
63
+ .appendTo('#iframe');
64
+
65
+ FS.PostMessage.init(base_url);
66
+ FS.PostMessage.receive('height', function (data) {
67
+ var h = data.height;
68
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
69
+ iframe_height = h;
70
+ $("#iframe iframe").height(iframe_height + 'px');
71
+ }
72
+ });
73
+ });
74
+ })(jQuery);
75
+ </script>
76
+ </div>
77
+ <?php
78
+ $params = array(
79
+ 'page' => 'contact',
80
+ 'module_id' => $fs->get_id(),
81
+ 'module_slug' => $slug,
82
+ 'module_version' => $fs->get_plugin_version(),
83
+ );
84
+ fs_require_template( 'powered-by.php', $params );
85
+ ?>
freemius/templates/debug.php ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ global $fs_active_plugins;
14
+
15
+ $fs_options = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
16
+ ?>
17
+ <h1><?php echo __fs( 'Freemius Debug' ) . ' - ' . __fs( 'SDK' ) . ' v.' . $fs_active_plugins->newest->version ?></h1>
18
+ <div>
19
+ <!-- Debugging Switch -->
20
+ <?php //$debug_mode = get_option( 'fs_debug_mode', null ) ?>
21
+ <span class="switch-label"><?php _efs( 'debugging' ) ?></span>
22
+
23
+ <div class="switch <?php echo WP_FS__DEBUG_SDK ? 'off' : 'on' ?>">
24
+ <div class="toggle"></div>
25
+ <span class="on"><?php _efs( 'on' ) ?></span>
26
+ <span class="off"><?php _efs( 'off' ) ?></span>
27
+ </div>
28
+ <script type="text/javascript">
29
+ (function ($) {
30
+ $(document).ready(function () {
31
+ // Switch toggle
32
+ $('.switch').click(function () {
33
+ $(this)
34
+ .toggleClass('on')
35
+ .toggleClass('off');
36
+
37
+ $.post(ajaxurl, {
38
+ action: 'fs_toggle_debug_mode',
39
+ is_on : ($(this).hasClass('off') ? 1 : 0)
40
+ }, function (response) {
41
+ if (1 == response) {
42
+ // Refresh page on success.
43
+ location.reload();
44
+ }
45
+ });
46
+ });
47
+ });
48
+ }(jQuery));
49
+ </script>
50
+ </div>
51
+ <h2><?php _efs( 'actions' ) ?></h2>
52
+ <table>
53
+ <tbody>
54
+ <tr>
55
+ <td>
56
+ <!-- Delete All Accounts -->
57
+ <form action="" method="POST">
58
+ <input type="hidden" name="fs_action" value="restart_freemius">
59
+ <?php wp_nonce_field( 'restart_freemius' ) ?>
60
+ <button class="button button-primary"
61
+ onclick="if (confirm('<?php _efs( 'delete-all-confirm' ) ?>')) this.parentNode.submit(); return false;"><?php _efs( 'delete-all-accounts' ) ?></button>
62
+ </form>
63
+ </td>
64
+ <td>
65
+ <!-- Clear API Cache -->
66
+ <form action="" method="POST">
67
+ <input type="hidden" name="fs_clear_api_cache" value="true">
68
+ <button class="button button-primary"><?php _efs( 'clear-api-cache' ) ?></button>
69
+ </form>
70
+ </td>
71
+ <td>
72
+ <!-- Sync Data with Server -->
73
+ <form action="" method="POST">
74
+ <input type="hidden" name="background_sync" value="true">
75
+ <button class="button button-primary"><?php _efs( 'sync-data-from-server' ) ?></button>
76
+ </form>
77
+ </td>
78
+ </tr>
79
+ </tbody>
80
+ </table>
81
+ <h2><?php _efs( 'sdk-versions' ) ?></h2>
82
+ <table id="fs_sdks" class="widefat">
83
+ <thead>
84
+ <tr>
85
+ <th><?php _efs( 'version' ) ?></th>
86
+ <th><?php _efs( 'sdk-path' ) ?></th>
87
+ <th><?php _efs( 'plugin-path' ) ?></th>
88
+ <th><?php _efs( 'is-active' ) ?></th>
89
+ </tr>
90
+ </thead>
91
+ <tbody>
92
+ <?php foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) : ?>
93
+ <?php $is_active = ( WP_FS__SDK_VERSION == $data->version ) ?>
94
+ <tr<?php if ( $is_active ) {
95
+ echo ' style="background: #E6FFE6; font-weight: bold"';
96
+ } ?>>
97
+ <td><?php echo $data->version ?></td>
98
+ <td><?php echo $sdk_path ?></td>
99
+ <td><?php echo $data->plugin_path ?></td>
100
+ <td><?php echo ( $is_active ) ? 'Active' : 'Inactive' ?></td>
101
+ </tr>
102
+ <?php endforeach ?>
103
+ </tbody>
104
+ </table>
105
+ <?php $plugins = $fs_options->get_option( 'plugins' ) ?>
106
+ <?php if ( is_array( $plugins ) && 0 < count( $plugins ) ) : ?>
107
+ <h2><?php _efs( 'plugins' ) ?></h2>
108
+ <table id="fs_plugins" class="widefat">
109
+ <thead>
110
+ <tr>
111
+ <th><?php _efs( 'id' ) ?></th>
112
+ <th><?php _efs( 'slug' ) ?></th>
113
+ <th><?php _efs( 'version' ) ?></th>
114
+ <th><?php _efs( 'title' ) ?></th>
115
+ <th><?php _efs( 'api' ) ?></th>
116
+ <th><?php _efs( 'freemius-state' ) ?></th>
117
+ <th><?php _efs( 'plugin-path' ) ?></th>
118
+ <th><?php _efs( 'public-key' ) ?></th>
119
+ </tr>
120
+ </thead>
121
+ <tbody>
122
+ <?php foreach ( $plugins as $slug => $data ) : ?>
123
+ <?php $is_active = is_plugin_active( $data->file ) ?>
124
+ <?php $fs = $is_active ? freemius( $slug ) : null ?>
125
+ <tr<?php if ( $is_active ) {
126
+ echo ' style="background: #E6FFE6; font-weight: bold"';
127
+ } ?>>
128
+ <td><?php echo $data->id ?></td>
129
+ <td><?php echo $slug ?></td>
130
+ <td><?php echo $data->version ?></td>
131
+ <td><?php echo $data->title ?></td>
132
+ <td><?php if ( $is_active ) {
133
+ echo $fs->has_api_connectivity() ?
134
+ __fs( 'connected' ) :
135
+ __fs( 'blocked' );
136
+ } ?></td>
137
+ <td><?php if ( $is_active ) {
138
+ echo $fs->is_on() ?
139
+ __fs( 'on' ) :
140
+ __fs( 'off' );
141
+ } ?></td>
142
+ <td><?php echo $data->file ?></td>
143
+ <td><?php echo $data->public_key ?></td>
144
+ </tr>
145
+ <?php endforeach ?>
146
+ </tbody>
147
+ </table>
148
+ <?php endif ?>
149
+ <?php
150
+ /**
151
+ * @var FS_Site[] $sites
152
+ */
153
+ $sites = $VARS['sites'];
154
+ ?>
155
+ <?php if ( is_array( $sites ) && 0 < count( $sites ) ) : ?>
156
+ <h2><?php _efs( 'plugin-installs' ) ?> / <?php _efs( 'sites' ) ?></h2>
157
+ <table id="fs_installs" class="widefat">
158
+ <thead>
159
+ <tr>
160
+ <th><?php _efs( 'id' ) ?></th>
161
+ <th><?php _efs( 'slug' ) ?></th>
162
+ <th><?php _efs( 'plan' ) ?></th>
163
+ <th><?php _efs( 'public-key' ) ?></th>
164
+ <th><?php _efs( 'secret-key' ) ?></th>
165
+ </tr>
166
+ </thead>
167
+ <tbody>
168
+ <?php foreach ( $sites as $slug => $site ) : ?>
169
+ <tr>
170
+ <td><?php echo $site->id ?></td>
171
+ <td><?php echo $slug ?></td>
172
+ <td><?php
173
+ echo is_object( $site->plan ) ?
174
+ base64_decode( $site->plan->name ) :
175
+ ''
176
+ ?></td>
177
+ <td><?php echo $site->public_key ?></td>
178
+ <td><?php echo $site->secret_key ?></td>
179
+ </tr>
180
+ <?php endforeach ?>
181
+ </tbody>
182
+ </table>
183
+ <?php endif ?>
184
+ <?php
185
+ $addons = $VARS['addons'];
186
+ ?>
187
+ <?php foreach ( $addons as $plugin_id => $plugin_addons ) : ?>
188
+ <h2><?php printf( __fs( 'addons-of-x' ), $plugin_id ) ?></h2>
189
+ <table id="fs_addons" class="widefat">
190
+ <thead>
191
+ <tr>
192
+ <th><?php _efs( 'id' ) ?></th>
193
+ <th><?php _efs( 'title' ) ?></th>
194
+ <th><?php _efs( 'slug' ) ?></th>
195
+ <th><?php _efs( 'version' ) ?></th>
196
+ <th><?php _efs( 'public-key' ) ?></th>
197
+ <th><?php _efs( 'secret-key' ) ?></th>
198
+ </tr>
199
+ </thead>
200
+ <tbody>
201
+ <?php
202
+ /**
203
+ * @var FS_Plugin[] $plugin_addons
204
+ */
205
+ foreach ( $plugin_addons as $addon ) : ?>
206
+ <tr>
207
+ <td><?php echo $addon->id ?></td>
208
+ <td><?php echo $addon->title ?></td>
209
+ <td><?php echo $addon->slug ?></td>
210
+ <td><?php echo $addon->version ?></td>
211
+ <td><?php echo $addon->public_key ?></td>
212
+ <td><?php echo $addon->secret_key ?></td>
213
+ </tr>
214
+ <?php endforeach ?>
215
+ </tbody>
216
+ </table>
217
+ <?php endforeach ?>
218
+ <?php
219
+ /**
220
+ * @var FS_User[] $users
221
+ */
222
+ $users = $VARS['users'];
223
+ ?>
224
+ <?php if ( is_array( $users ) && 0 < count( $users ) ) : ?>
225
+ <h2><?php _efs( 'users' ) ?></h2>
226
+ <table id="fs_users" class="widefat">
227
+ <thead>
228
+ <tr>
229
+ <th><?php _efs( 'id' ) ?></th>
230
+ <th><?php _efs( 'name' ) ?></th>
231
+ <th><?php _efs( 'email' ) ?></th>
232
+ <th><?php _efs( 'verified' ) ?></th>
233
+ <th><?php _efs( 'public-key' ) ?></th>
234
+ <th><?php _efs( 'secret-key' ) ?></th>
235
+ </tr>
236
+ </thead>
237
+ <tbody>
238
+ <?php foreach ( $users as $user_id => $user ) : ?>
239
+ <tr>
240
+ <td><?php echo $user->id ?></td>
241
+ <td><?php echo $user->get_name() ?></td>
242
+ <td><a href="mailto:<?php esc_attr_e( $user->email ) ?>"><?php echo $user->email ?></a></td>
243
+ <td><?php echo json_encode( $user->is_verified ) ?></td>
244
+ <td><?php echo $user->public_key ?></td>
245
+ <td><?php echo $user->secret_key ?></td>
246
+ </tr>
247
+ <?php endforeach ?>
248
+ </tbody>
249
+ </table>
250
+ <?php endif ?>
251
+ <?php
252
+ /**
253
+ * @var FS_Plugin_License[] $licenses
254
+ */
255
+ $licenses = $VARS['licenses'];
256
+ ?>
257
+ <?php if ( is_array( $licenses ) && 0 < count( $licenses ) ) : ?>
258
+ <h2><?php _efs( 'licenses' ) ?></h2>
259
+ <table id="fs_users" class="widefat">
260
+ <thead>
261
+ <tr>
262
+ <th><?php _efs( 'id' ) ?></th>
263
+ <th><?php _efs( 'plugin-id' ) ?></th>
264
+ <th><?php _efs( 'user-id' ) ?></th>
265
+ <th><?php _efs( 'plan-id' ) ?></th>
266
+ <th><?php _efs( 'quota' ) ?></th>
267
+ <th><?php _efs( 'activated' ) ?></th>
268
+ <th><?php _efs( 'blocking' ) ?></th>
269
+ <th><?php _efs( 'license-key' ) ?></th>
270
+ <th><?php _efs( 'expiration' ) ?></th>
271
+ </tr>
272
+ </thead>
273
+ <tbody>
274
+ <?php foreach ( $licenses as $slug => $module_licenses ) : ?>
275
+ <?php foreach ( $module_licenses as $id => $licenses ) : ?>
276
+ <?php if ( is_array( $licenses ) && 0 < count( $licenses ) ) : ?>
277
+ <?php foreach ( $licenses as $license ) : ?>
278
+ <tr>
279
+ <td><?php echo $license->id ?></td>
280
+ <td><?php echo $license->plugin_id ?></td>
281
+ <td><?php echo $license->user_id ?></td>
282
+ <td><?php echo $license->plan_id ?></td>
283
+ <td><?php echo $license->is_unlimited() ? 'Unlimited' : ( $license->is_single_site() ? 'Single Site' : $license->quota ) ?></td>
284
+ <td><?php echo $license->activated ?></td>
285
+ <td><?php echo $license->is_block_features ? 'Blocking' : 'Flexible' ?></td>
286
+ <td><?php echo htmlentities( $license->secret_key ) ?></td>
287
+ <td><?php echo $license->expiration ?></td>
288
+ </tr>
289
+ <?php endforeach ?>
290
+ <?php endif ?>
291
+ <?php endforeach ?>
292
+ <?php endforeach ?>
293
+ </tbody>
294
+ </table>
295
+ <?php endif ?>
freemius/templates/debug/api-calls.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( class_exists( 'Freemius_Api' ) ) {
14
+ $logger = Freemius_Api::GetLogger();
15
+ } else {
16
+ $logger = array();
17
+ }
18
+
19
+ $counters = array(
20
+ 'GET' => 0,
21
+ 'POST' => 0,
22
+ 'PUT' => 0,
23
+ 'DELETE' => 0
24
+ );
25
+
26
+ $show_body = false;
27
+ foreach ( $logger as $log ) {
28
+ $counters[ $log['method'] ] ++;
29
+
30
+ if ( ! is_null( $log['body'] ) ) {
31
+ $show_body = true;
32
+ }
33
+ }
34
+
35
+ $pretty_print = $show_body && defined( 'JSON_PRETTY_PRINT' ) && version_compare( phpversion(), '5.3', '>=' );
36
+
37
+ $root_path_len = strlen( ABSPATH );
38
+ ?>
39
+ <h1><?php _efs( 'API' ) ?></h1>
40
+
41
+ <h2><span>Total Time:</span><?php echo Freemius_Debug_Bar_Panel::total_time() ?></h2>
42
+
43
+ <h2><span>Total Requests:</span><?php echo Freemius_Debug_Bar_Panel::requests_count() ?></h2>
44
+ <?php foreach ( $counters as $method => $count ) : ?>
45
+ <h2><span><?php echo $method ?>:</span><?php echo number_format( $count ) ?></h2>
46
+ <?php endforeach ?>
47
+ <table class="widefat">
48
+ <thead>
49
+ <tr>
50
+ <th>#</th>
51
+ <th><?php _efs( 'Method' ) ?></th>
52
+ <th><?php _efs( 'Code' ) ?></th>
53
+ <th><?php _efs( 'Length' ) ?></th>
54
+ <th><?php _efs( 'Path' ) ?></th>
55
+ <?php if ( $show_body ) : ?>
56
+ <th><?php _efs( 'Body' ) ?></th>
57
+ <?php endif ?>
58
+ <th><?php _efs( 'Result' ) ?></th>
59
+ <th><?php _efs( 'Start' ) ?></th>
60
+ <th><?php _efs( 'End' ) ?></th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <?php foreach ( $logger as $log ) : ?>
65
+ <tr>
66
+ <td><?php echo $log['id'] ?>.</td>
67
+ <td><?php echo $log['method'] ?></td>
68
+ <td><?php echo $log['code'] ?></td>
69
+ <td><?php echo number_format( 100 * $log['total'], 2 ) . ' ' . __fs( 'ms' ) ?></td>
70
+ <td>
71
+ <?php
72
+ printf( '<a href="#" onclick="jQuery(this).parent().find(\'table\').toggle(); return false;">%s</a>',
73
+ $log['path']
74
+ );
75
+ ?>
76
+ <table class="widefat" style="display: none">
77
+ <tbody>
78
+ <?php for ( $i = 0, $bt = $log['backtrace'], $len = count( $bt ); $i < $len; $i ++ ) : ?>
79
+ <tr>
80
+ <td><?php echo( $len - $i ) ?></td>
81
+ <td><?php if ( isset( $bt[ $i ]['function'] ) ) {
82
+ echo ( isset( $bt[ $i ]['class'] ) ? $bt[ $i ]['class'] . $bt[ $i ]['type'] : '' ) . $bt[ $i ]['function'];
83
+ } ?></td>
84
+ <td><?php if ( isset( $bt[ $i ]['file'] ) ) {
85
+ echo substr( $bt[ $i ]['file'], $root_path_len ) . ':' . $bt[ $i ]['line'];
86
+ } ?></td>
87
+ </tr>
88
+ <?php endfor ?>
89
+ </tbody>
90
+ </table>
91
+ </td>
92
+ <?php if ( $show_body ) : ?>
93
+ <td>
94
+ <?php if ( 'GET' !== $log['method'] ) : ?>
95
+ <?php
96
+ $body = $log['body'];
97
+ printf(
98
+ '<a href="#" onclick="jQuery(this).parent().find(\'pre\').toggle(); return false;">%s</a>',
99
+ substr( $body, 0, 32 ) . ( 32 < strlen( $body ) ? '...' : '' )
100
+ );
101
+ if ( $pretty_print ) {
102
+ $body = json_encode( json_decode( $log['body'] ), JSON_PRETTY_PRINT );
103
+ }
104
+ ?>
105
+ <pre style="display: none"><code><?php echo esc_html( $body ) ?></code></pre>
106
+ <?php endif ?>
107
+ </td>
108
+ <?php endif ?>
109
+ <td>
110
+ <?php
111
+ $result = $log['result'];
112
+
113
+ $is_not_empty_result = ( is_string( $result ) && ! empty( $result ) );
114
+
115
+ if ( $is_not_empty_result ) {
116
+ printf(
117
+ '<a href="#" onclick="jQuery(this).parent().find(\'pre\').toggle(); return false;">%s</a>',
118
+ substr( $result, 0, 32 ) . ( 32 < strlen( $result ) ? '...' : '' )
119
+ );
120
+ }
121
+
122
+ if ( $is_not_empty_result && $pretty_print ) {
123
+ $decoded = json_decode( $result );
124
+ if ( ! is_null( $decoded ) ) {
125
+ $result = json_encode( $decoded, JSON_PRETTY_PRINT );
126
+ }
127
+ } else {
128
+ $result = is_string( $result ) ? $result : json_encode( $result );
129
+ }
130
+ ?>
131
+ <pre<?php if ( $is_not_empty_result ) : ?> style="display: none"<?php endif ?>><code><?php echo esc_html( $result ) ?></code></pre>
132
+ </td>
133
+ <td><?php echo number_format( 100 * ( $log['start'] - WP_FS__SCRIPT_START_TIME ), 2 ) . ' ' . __fs( 'ms' ) ?></td>
134
+ <td><?php echo number_format( 100 * ( $log['end'] - WP_FS__SCRIPT_START_TIME ), 2 ) . ' ' . __fs( 'ms' ) ?></td>
135
+ </tr>
136
+ <?php endforeach ?>
137
+ </tbody>
138
+ </table>
freemius/templates/debug/logger.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $log_book = FS_Logger::get_log();
14
+ ?>
15
+ <h1><?php _efs( 'Log' ) ?></h1>
16
+
17
+ <table class="widefat" style="font-size: 11px;">
18
+ <thead>
19
+ <tr>
20
+ <th>#</th>
21
+ <th><?php _efs( 'id' ) ?></th>
22
+ <th><?php _efs( 'type' ) ?></th>
23
+ <th><?php _efs( 'function' ) ?></th>
24
+ <th><?php _efs( 'message' ) ?></th>
25
+ <th><?php _efs( 'file' ) ?></th>
26
+ <th><?php _efs( 'timestamp' ) ?></th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+
31
+ <?php $i = 0;
32
+ foreach ( $log_book as $log ) : ?>
33
+ <tr<?php if ( $i % 2 ) {
34
+ echo ' class="alternate"';
35
+ } ?>>
36
+ <td><?php echo $log['cnt'] ?>.</td>
37
+ <td><?php echo $log['logger']->get_id() ?></td>
38
+ <td><?php echo $log['type'] ?></td>
39
+ <td><b><code style="color: blue;"><?php echo $log['function'] ?></code></b></td>
40
+ <td>
41
+ <?php
42
+ printf(
43
+ '<a href="#" style="color: darkorange !important;" onclick="jQuery(this).parent().find(\'div\').toggle(); return false;"><nobr>%s</nobr></a>',
44
+ substr( $log['msg'], 0, 32 ) . ( 32 < strlen( $log['msg'] ) ? '...' : '' )
45
+ );
46
+ ?>
47
+ <div style="display: none;">
48
+ <b style="color: darkorange;"><?php echo $log['msg'] ?></b>
49
+ </div>
50
+ </td>
51
+ <td><?php
52
+ if ( isset( $log['file'] ) ) {
53
+ echo substr( $log['file'], $log['logger']->get_file() ) . ':' . $log['line'] . ')';
54
+ }
55
+ ?></td>
56
+ <td><?php echo number_format( 100 * ( $log['timestamp'] - WP_FS__SCRIPT_START_TIME ), 2 ) . ' ' . __fs( 'ms' ) ?></td>
57
+ </tr>
58
+ <?php $i ++; endforeach ?>
59
+ </tbody>
60
+ </table>
freemius/templates/debug/plugins-themes-sync.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $fs_options = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
14
+ $all_plugins = $fs_options->get_option( 'all_plugins' );
15
+ $all_themes = $fs_options->get_option( 'all_themes' );
16
+ ?>
17
+ <h1><?php _efs( 'plugins-themes-sync' ) ?></h1>
18
+ <table class="widefat">
19
+ <thead>
20
+ <tr>
21
+ <th></th>
22
+ <th><?php _efs( 'total' ) ?></th>
23
+ <th><?php _efs( 'Last' ) ?></th>
24
+ </tr>
25
+ </thead>
26
+ <tbody>
27
+ <?php if ( is_object( $all_plugins ) ) : ?>
28
+ <tr>
29
+ <td><?php _efs( 'plugins' ) ?></td>
30
+ <td><?php echo count( $all_plugins->plugins ) ?></td>
31
+ <td><?php
32
+ if ( isset( $all_plugins->timestamp ) && is_numeric( $all_plugins->timestamp ) ) {
33
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $all_plugins->timestamp );
34
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
35
+ $diff . ' ' . __fs( 'sec' ) :
36
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $all_plugins->timestamp );
37
+
38
+ if ( WP_FS__SCRIPT_START_TIME < $all_plugins->timestamp ) {
39
+ printf( __fs( 'in-x' ), $human_diff );
40
+ } else {
41
+ printf( __fs( 'x-ago' ), $human_diff );
42
+ }
43
+ }
44
+ ?></td>
45
+ </tr>
46
+ <?php endif ?>
47
+ <?php if ( is_object( $all_themes ) ) : ?>
48
+ <tr>
49
+ <td><?php _efs( 'themes' ) ?></td>
50
+ <td><?php echo count( $all_themes->themes ) ?></td>
51
+ <td><?php
52
+ if ( isset( $all_themes->timestamp ) && is_numeric( $all_themes->timestamp ) ) {
53
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $all_themes->timestamp );
54
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
55
+ $diff . ' ' . __fs( 'sec' ) :
56
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $all_themes->timestamp );
57
+
58
+ if ( WP_FS__SCRIPT_START_TIME < $all_themes->timestamp ) {
59
+ printf( __fs( 'in-x' ), $human_diff );
60
+ } else {
61
+ printf( __fs( 'x-ago' ), $human_diff );
62
+ }
63
+ }
64
+ ?></td>
65
+ </tr>
66
+ <?php endif ?>
67
+ </tbody>
68
+ </table>
freemius/templates/debug/scheduled-crons.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $fs_options = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
14
+ $plugins = $fs_options->get_option( 'plugins' );
15
+ $scheduled_crons = array();
16
+ if ( is_array( $plugins ) && 0 < count( $plugins ) ) {
17
+ foreach ( $plugins as $slug => $data ) {
18
+ $fs = freemius( $slug );
19
+
20
+ $next_execution = $fs->next_sync_cron();
21
+ $last_execution = $fs->last_sync_cron();
22
+
23
+ if ( false !== $next_execution ) {
24
+ $scheduled_crons[ $slug ][] = array(
25
+ 'name' => $fs->get_plugin_name(),
26
+ 'slug' => $slug,
27
+ 'type' => 'sync_cron',
28
+ 'last' => $last_execution,
29
+ 'next' => $next_execution,
30
+ );
31
+ }
32
+
33
+ $next_install_execution = $fs->next_install_sync();
34
+ $last_install_execution = $fs->last_install_sync();
35
+
36
+ if ( false !== $next_install_execution || false !== $last_install_execution ) {
37
+ $scheduled_crons[ $slug ][] = array(
38
+ 'name' => $fs->get_plugin_name(),
39
+ 'slug' => $slug,
40
+ 'type' => 'install_sync',
41
+ 'last' => $last_install_execution,
42
+ 'next' => $next_install_execution,
43
+ );
44
+ }
45
+ }
46
+ }
47
+ ?>
48
+ <h1><?php _efs( 'scheduled-crons' ) ?></h1>
49
+ <table class="widefat">
50
+ <thead>
51
+ <tr>
52
+ <th><?php _efs( 'slug' ) ?></th>
53
+ <th><?php _efs( 'plugin' ) ?></th>
54
+ <th><?php _efs( 'type' ) ?></th>
55
+ <th><?php _efs( 'Last' ) ?></th>
56
+ <th><?php _efs( 'Next' ) ?></th>
57
+ </tr>
58
+ </thead>
59
+ <tbody>
60
+ <?php foreach ( $scheduled_crons as $slug => $crons ) : ?>
61
+ <?php foreach ( $crons as $cron ) : ?>
62
+ <tr>
63
+ <td><?php echo $slug ?></td>
64
+ <td><?php echo $cron['name'] ?></td>
65
+ <td><?php echo $cron['type'] ?></td>
66
+ <td><?php
67
+ if (is_numeric($cron['last'])) {
68
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $cron['last'] );
69
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
70
+ $diff . ' ' . __fs( 'sec' ) :
71
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $cron['last'] );
72
+
73
+ if ( WP_FS__SCRIPT_START_TIME < $cron['last'] ) {
74
+ printf( __fs( 'in-x' ), $human_diff );
75
+ } else {
76
+ printf( __fs( 'x-ago' ), $human_diff );
77
+ }
78
+
79
+ // echo ' ' . $cron['last'];
80
+ }
81
+ ?></td>
82
+ <td><?php
83
+ if (is_numeric($cron['next'])) {
84
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $cron['next'] );
85
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
86
+ $diff . ' ' . __fs( 'sec' ) :
87
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $cron['next'] );
88
+
89
+ if ( WP_FS__SCRIPT_START_TIME < $cron['next'] ) {
90
+ printf( __fs( 'in-x' ), $human_diff );
91
+ } else {
92
+ printf( __fs( 'x-ago' ), $human_diff );
93
+ }
94
+ }
95
+ ?></td>
96
+ </tr>
97
+ <?php endforeach ?>
98
+ <?php endforeach ?>
99
+ </tbody>
100
+ </table>
freemius/templates/email.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $sections = $VARS['sections'];
14
+ ?>
15
+ <table>
16
+ <?php
17
+ foreach ( $sections as $section_id => $section ) {
18
+ ?>
19
+ <thead>
20
+ <tr><th colspan="2" style="text-align: left; background: #333; color: #fff; padding: 5px;"><?php echo $section['title']; ?></th></tr>
21
+ </thead>
22
+ <tbody>
23
+ <?php
24
+ foreach ( $section['rows'] as $row_id => $row ) {
25
+ $col_count = count( $row );
26
+ ?>
27
+ <tr>
28
+ <?php
29
+ if ( 1 === $col_count ) { ?>
30
+ <td style="vertical-align: top;" colspan="2"><?php echo $row[0]; ?></td>
31
+ <?php
32
+ } else { ?>
33
+ <td style="vertical-align: top;"><b><?php echo $row[0]; ?>:</b></td>
34
+ <td><?php echo $row[1]; ?></td>
35
+ <?php
36
+ }
37
+ ?>
38
+ </tr>
39
+ <?php
40
+ }
41
+ ?>
42
+ </tbody>
43
+ <?php
44
+ }
45
+ ?>
46
+ </table>
freemius/templates/firewall-issues-js.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * API connectivity issues (CloudFlare's firewall) handler for handling different
4
+ * scenarios selected by the user after connectivity issue is detected, by sending
5
+ * AJAX call to the server in order to make the actual actions.
6
+ *
7
+ * @package Freemius
8
+ * @copyright Copyright (c) 2015, Freemius, Inc.
9
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10
+ * @since 1.0.9
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) {
14
+ exit;
15
+ }
16
+ ?>
17
+ <script type="text/javascript">
18
+ jQuery(document).ready(function ($) {
19
+ $('#fs_firewall_issue_options a.fs-resolve').click(function () {
20
+ var
21
+ error_type = $(this).attr('data-type'),
22
+ notice = $(this).parents('.fs-notice'),
23
+ slug = notice.attr('data-slug');
24
+
25
+ var data = {
26
+ action : slug + '_resolve_firewall_issues',
27
+ slug : slug,
28
+ error_type: error_type
29
+ };
30
+
31
+ if ('squid' === error_type) {
32
+ data.hosting_company = prompt('What is the name or URL of your hosting company?');
33
+ if (null == data.hosting_company)
34
+ return false;
35
+
36
+ if ('' === data.hosting_company) {
37
+ alert('We won\'t be able to help without knowing your hosting company.');
38
+ return false;
39
+ }
40
+ }
41
+
42
+ if ('retry_ping' === error_type) {
43
+ data.action = slug + '_retry_connectivity_test';
44
+ }
45
+
46
+ $(this).css({'cursor': 'wait'});
47
+
48
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
49
+ $.post(ajaxurl, data, function (response) {
50
+ if (1 == response) {
51
+ // Refresh page on success.
52
+ location.reload();
53
+ } else if ('http' === response.substr(0, 4)) {
54
+ // Ping actually worked, redirect.
55
+ window.location = response;
56
+ }
57
+ });
58
+ });
59
+ });
60
+ </script>
freemius/templates/forms/deactivation/contact.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.2.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ echo __fs( 'contact-support-before-deactivation', $slug )
17
+ . sprintf(" <a href='%s' class='button button-small button-primary'>%s</a>",
18
+ $fs->contact_url( 'technical_support' ),
19
+ __fs( 'contact-support', $slug )
20
+ );
freemius/templates/forms/deactivation/form.php ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.2
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ $confirmation_message = $fs->apply_filters( 'uninstall_confirmation_message', '' );
17
+
18
+ $reasons = $VARS['reasons'];
19
+
20
+ $reasons_list_items_html = '';
21
+
22
+ foreach ( $reasons as $reason ) {
23
+ $list_item_classes = 'reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' );
24
+
25
+ if ( isset( $reason['internal_message'] ) && ! empty( $reason['internal_message'] ) ) {
26
+ $list_item_classes .= ' has-internal-message';
27
+ $reason_internal_message = $reason['internal_message'];
28
+ } else {
29
+ $reason_internal_message = '';
30
+ }
31
+
32
+ $reason_list_item_html = <<< HTML
33
+ <li class="{$list_item_classes}"
34
+ data-input-type="{$reason['input_type']}"
35
+ data-input-placeholder="{$reason['input_placeholder']}">
36
+ <label>
37
+ <span>
38
+ <input type="radio" name="selected-reason" value="{$reason['id']}"/>
39
+ </span>
40
+ <span>{$reason['text']}</span>
41
+ </label>
42
+ <div class="internal-message">{$reason_internal_message}</div>
43
+ </li>
44
+ HTML;
45
+
46
+ $reasons_list_items_html .= $reason_list_item_html;
47
+ }
48
+
49
+ fs_enqueue_local_style( 'dialog-boxes', '/admin/dialog-boxes.css' );
50
+ ?>
51
+ <script type="text/javascript">
52
+ (function ($) {
53
+ var reasonsHtml = <?php echo json_encode( $reasons_list_items_html ); ?>,
54
+ modalHtml =
55
+ '<div class="fs-modal fs-modal-deactivation-feedback<?php echo empty( $confirmation_message ) ? ' no-confirmation-message' : ''; ?>">'
56
+ + ' <div class="fs-modal-dialog">'
57
+ + ' <div class="fs-modal-body">'
58
+ + ' <div class="fs-modal-panel" data-panel-id="confirm"><p><?php echo $confirmation_message; ?></p></div>'
59
+ + ' <div class="fs-modal-panel active" data-panel-id="reasons"><h3><strong><?php printf( __fs( 'deactivation-share-reason' , $slug ) ); ?>:</strong></h3><ul id="reasons-list">' + reasonsHtml + '</ul></div>'
60
+ + ' </div>'
61
+ + ' <div class="fs-modal-footer">'
62
+ + ' <a href="#" class="button button-secondary button-deactivate"></a>'
63
+ + ' <a href="#" class="button button-primary button-close"><?php printf( __fs( 'deactivation-modal-button-cancel' , $slug ) ); ?></a>'
64
+ + ' </div>'
65
+ + ' </div>'
66
+ + '</div>',
67
+ $modal = $(modalHtml),
68
+ $deactivateLink = $('#the-list .deactivate > [data-slug=<?php echo $VARS['slug']; ?>].fs-slug').prev(),
69
+ selectedReasonID = false;
70
+
71
+ $modal.appendTo($('body'));
72
+
73
+ registerEventHandlers();
74
+
75
+ function registerEventHandlers() {
76
+ $deactivateLink.click(function (evt) {
77
+ evt.preventDefault();
78
+
79
+ showModal();
80
+ });
81
+
82
+ $modal.on('input propertychange', '.reason-input input', function () {
83
+ if (!isOtherReasonSelected()) {
84
+ return;
85
+ }
86
+
87
+ var reason = $(this).val().trim();
88
+
89
+ /**
90
+ * If reason is not empty, remove the error-message class of the message container
91
+ * to change the message color back to default.
92
+ */
93
+ if (reason.length > 0) {
94
+ $('.message').removeClass('error-message');
95
+ enableDeactivateButton();
96
+ }
97
+ });
98
+
99
+ $modal.on('blur', '.reason-input input', function () {
100
+ var $userReason = $(this);
101
+
102
+ setTimeout(function () {
103
+ if (!isOtherReasonSelected()) {
104
+ return;
105
+ }
106
+
107
+ /**
108
+ * If reason is empty, add the error-message class to the message container
109
+ * to change the message color to red.
110
+ */
111
+ if (0 === $userReason.val().trim().length) {
112
+ $('.message').addClass('error-message');
113
+ disableDeactivateButton();
114
+ }
115
+ }, 150);
116
+ });
117
+
118
+ $modal.on('click', '.fs-modal-footer .button', function (evt) {
119
+ evt.preventDefault();
120
+
121
+ if ($(this).hasClass('disabled')) {
122
+ return;
123
+ }
124
+
125
+ var _parent = $(this).parents('.fs-modal:first');
126
+ var _this = $(this);
127
+
128
+ if (_this.hasClass('allow-deactivate')) {
129
+ var $radio = $('input[type="radio"]:checked');
130
+
131
+ if (0 === $radio.length) {
132
+ // If no selected reason, just deactivate the plugin.
133
+ window.location.href = $deactivateLink.attr('href');
134
+ return;
135
+ }
136
+
137
+ var $selected_reason = $radio.parents('li:first'),
138
+ $input = $selected_reason.find('textarea, input[type="text"]'),
139
+ userReason = ( 0 !== $input.length ) ? $input.val().trim() : '';
140
+
141
+ if (isOtherReasonSelected() && ( '' === userReason )) {
142
+ return;
143
+ }
144
+
145
+ $.ajax({
146
+ url : ajaxurl,
147
+ method : 'POST',
148
+ data : {
149
+ 'action' : 'submit-uninstall-reason',
150
+ 'reason_id' : $radio.val(),
151
+ 'reason_info': userReason
152
+ },
153
+ beforeSend: function () {
154
+ _parent.find('.fs-modal-footer .button').addClass('disabled');
155
+ _parent.find('.fs-modal-footer .button-secondary').text('Processing...');
156
+ },
157
+ complete : function () {
158
+ // Do not show the dialog box, deactivate the plugin.
159
+ window.location.href = $deactivateLink.attr('href');
160
+ }
161
+ });
162
+ } else if (_this.hasClass('button-deactivate')) {
163
+ // Change the Deactivate button's text and show the reasons panel.
164
+ _parent.find('.button-deactivate').addClass('allow-deactivate');
165
+
166
+ showPanel('reasons');
167
+ }
168
+ });
169
+
170
+ $modal.on('click', 'input[type="radio"]', function () {
171
+ var $selectedReasonOption = $(this);
172
+
173
+ // If the selection has not changed, do not proceed.
174
+ if (selectedReasonID === $selectedReasonOption.val())
175
+ return;
176
+
177
+ selectedReasonID = $selectedReasonOption.val();
178
+
179
+ var _parent = $(this).parents('li:first');
180
+
181
+ $modal.find('.reason-input').remove();
182
+ $modal.find( '.internal-message' ).hide();
183
+ $modal.find('.button-deactivate').text('<?php printf( __fs( 'deactivation-modal-button-submit' , $slug ) ); ?>');
184
+
185
+ enableDeactivateButton();
186
+
187
+ if ( _parent.hasClass( 'has-internal-message' ) ) {
188
+ _parent.find( '.internal-message' ).show();
189
+ }
190
+
191
+ if (_parent.hasClass('has-input')) {
192
+ var inputType = _parent.data('input-type'),
193
+ inputPlaceholder = _parent.data('input-placeholder'),
194
+ reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" />' : '<textarea rows="5"></textarea>' ) + '</div>';
195
+
196
+ _parent.append($(reasonInputHtml));
197
+ _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
198
+
199
+ if (isOtherReasonSelected()) {
200
+ showMessage('<?php printf( __fs( 'ask-for-reason-message' , $slug ) ); ?>');
201
+ disableDeactivateButton();
202
+ }
203
+ }
204
+ });
205
+
206
+ // If the user has clicked outside the window, cancel it.
207
+ $modal.on('click', function (evt) {
208
+ var $target = $(evt.target);
209
+
210
+ // If the user has clicked anywhere in the modal dialog, just return.
211
+ if ($target.hasClass('fs-modal-body') || $target.hasClass('fs-modal-footer')) {
212
+ return;
213
+ }
214
+
215
+ // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return.
216
+ if (!$target.hasClass('button-close') && ( $target.parents('.fs-modal-body').length > 0 || $target.parents('.fs-modal-footer').length > 0 )) {
217
+ return;
218
+ }
219
+
220
+ closeModal();
221
+ });
222
+ }
223
+
224
+ function isOtherReasonSelected() {
225
+ // Get the selected radio input element.
226
+ var $selectedReasonOption = $modal.find('input[type="radio"]:checked'),
227
+ selectedReason = $selectedReasonOption.parent().next().text().trim();
228
+
229
+ return ( 'Other' === selectedReason );
230
+ }
231
+
232
+ function showModal() {
233
+ resetModal();
234
+
235
+ // Display the dialog box.
236
+ $modal.addClass('active');
237
+
238
+ $('body').addClass('has-fs-modal');
239
+ }
240
+
241
+ function closeModal() {
242
+ $modal.removeClass('active');
243
+
244
+ $('body').removeClass('has-fs-modal');
245
+ }
246
+
247
+ function resetModal() {
248
+ selectedReasonID = false;
249
+
250
+ enableDeactivateButton();
251
+
252
+ // Uncheck all radio buttons.
253
+ $modal.find('input[type="radio"]').prop('checked', false);
254
+
255
+ // Remove all input fields ( textfield, textarea ).
256
+ $modal.find('.reason-input').remove();
257
+
258
+ $modal.find('.message').hide();
259
+
260
+ var $deactivateButton = $modal.find('.button-deactivate');
261
+
262
+ /*
263
+ * If the modal dialog has no confirmation message, that is, it has only one panel, then ensure
264
+ * that clicking the deactivate button will actually deactivate the plugin.
265
+ */
266
+ if ($modal.hasClass('no-confirmation-message')) {
267
+ $deactivateButton.addClass('allow-deactivate');
268
+
269
+ showPanel('reasons');
270
+ } else {
271
+ $deactivateButton.removeClass('allow-deactivate');
272
+
273
+ showPanel('confirm');
274
+ }
275
+ }
276
+
277
+ function showMessage(message) {
278
+ $modal.find('.message').text(message).show();
279
+ }
280
+
281
+ function enableDeactivateButton() {
282
+ $modal.find('.button-deactivate').removeClass('disabled');
283
+ }
284
+
285
+ function disableDeactivateButton() {
286
+ $modal.find('.button-deactivate').addClass('disabled');
287
+ }
288
+
289
+ function showPanel(panelType) {
290
+ $modal.find('.fs-modal-panel').removeClass('active ');
291
+ $modal.find('[data-panel-id="' + panelType + '"]').addClass('active');
292
+
293
+ updateButtonLabels();
294
+ }
295
+
296
+ function updateButtonLabels() {
297
+ var $deactivateButton = $modal.find('.button-deactivate');
298
+
299
+ // Reset the deactivate button's text.
300
+ if ('confirm' === getCurrentPanel()) {
301
+ $deactivateButton.text('<?php printf( __fs( 'deactivation-modal-button-confirm' , $slug ) ); ?>');
302
+ } else {
303
+ $deactivateButton.text('<?php printf( __fs( 'skip-deactivate' , $slug ) ); ?>');
304
+ }
305
+ }
306
+
307
+ function getCurrentPanel() {
308
+ return $modal.find('.fs-modal-panel.active').attr('data-panel-id');
309
+ }
310
+ })(jQuery);
311
+ </script>
freemius/templates/forms/deactivation/retry-skip.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.2.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ $skip_url = wp_nonce_url( $fs->_get_admin_page_url( '', array( 'fs_action' => $slug . '_skip_activation' ) ), $slug . '_skip_activation' );
17
+ $skip_text = strtolower( __fs( 'skip', $slug ) );
18
+ $use_plugin_anonymously_text = __fs( 'click-here-to-use-plugin-anonymously', $slug );
19
+
20
+ echo sprintf( __fs( 'dont-have-to-share-any-data', $slug ), "<a href='{$skip_url}'>{$skip_text}</a>" )
21
+ . " <a href='{$skip_url}' class='button button-small button-secondary'>{$use_plugin_anonymously_text}</a>";
freemius/templates/forms/license-activation.php ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.9
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ // The URL to redirect to after successfully activating the license from the "Plugins" page.
17
+ $sync_license_url = $VARS['sync-license-url'];
18
+
19
+ $cant_find_license_key_text = __fs( 'cant-find-license-key', $slug );
20
+ $message_above_input_field = __fs( 'activate-license-message', $slug );
21
+ $message_below_input_field = '';
22
+
23
+ if ( $fs->is_registered() ) {
24
+ $activate_button_text = __fs( $fs->is_free_plan() ? 'activate-license' : 'update-license', $slug );
25
+ } else {
26
+ $freemius_site_url = $fs->has_paid_plan() ?
27
+ 'https://freemius.com/wordpress/' :
28
+ // Insights platform information.
29
+ 'https://freemius.com/wordpress/usage-tracking/';
30
+
31
+ $freemius_link = '<a href="' . $freemius_site_url . '" target="_blank">freemius.com</a>';
32
+
33
+ $message_below_input_field = sprintf( __fs( 'license-sync-disclaimer', $slug ), $freemius_link );
34
+
35
+ $activate_button_text = __fs( 'agree-activate-license', $slug );
36
+ }
37
+
38
+ $license_key_text = __fs( 'license-key' , $slug );
39
+
40
+ $modal_content_html = <<< HTML
41
+ <div class="notice notice-error inline license-activation-message"><p></p></div>
42
+ <p>{$message_above_input_field}</p>
43
+ <input class="license_key" type="text" placeholder="{$license_key_text}" />
44
+ <a class="show-license-resend-modal show-license-resend-modal-{$slug}" href="#">{$cant_find_license_key_text}</a>
45
+ <p>{$message_below_input_field}</p>
46
+ HTML;
47
+
48
+ fs_enqueue_local_style( 'dialog-boxes', '/admin/dialog-boxes.css' );
49
+ ?>
50
+ <script type="text/javascript">
51
+ (function( $ ) {
52
+ $( document ).ready(function() {
53
+ var modalContentHtml = <?php echo json_encode($modal_content_html); ?>,
54
+ modalHtml =
55
+ '<div class="fs-modal fs-modal-license-activation">'
56
+ + ' <div class="fs-modal-dialog">'
57
+ + ' <div class="fs-modal-body">'
58
+ + ' <div class="fs-modal-panel active">' + modalContentHtml + '</div>'
59
+ + ' </div>'
60
+ + ' <div class="fs-modal-footer">'
61
+ + ' <a href="#" class="button button-secondary button-close"><?php _efs('deactivation-modal-button-cancel', $slug); ?></a>'
62
+ + ' <a href="#" class="button button-primary button-activate-license"><?php echo $activate_button_text; ?></a>'
63
+ + ' </div>'
64
+ + ' </div>'
65
+ + '</div>',
66
+ $modal = $(modalHtml),
67
+ $activateLicenseLink = $('span.activate-license.<?php echo $VARS['slug'] ?> a, .activate-license-trigger.<?php echo $VARS['slug'] ?>'),
68
+ $activateLicenseButton = $modal.find('.button-activate-license'),
69
+ $licenseKeyInput = $modal.find('input.license_key'),
70
+ $licenseActivationMessage = $modal.find( '.license-activation-message' ),
71
+ pluginSlug = '<?php echo $slug; ?>',
72
+ syncLicenseUrl = '<?php echo $sync_license_url; ?>';
73
+
74
+ $modal.appendTo($('body'));
75
+
76
+ registerEventHandlers();
77
+
78
+ function registerEventHandlers() {
79
+ $activateLicenseLink.click(function (evt) {
80
+ evt.preventDefault();
81
+
82
+ showModal();
83
+ });
84
+
85
+ $modal.on('input propertychange', 'input.license_key', function () {
86
+
87
+ var licenseKey = $(this).val().trim();
88
+
89
+ /**
90
+ * If license key is not empty, enable the license activation button.
91
+ */
92
+ if (licenseKey.length > 0) {
93
+ enableActivateLicenseButton();
94
+ }
95
+ });
96
+
97
+ $modal.on('blur', 'input.license_key', function () {
98
+ var licenseKey = $(this).val().trim();
99
+
100
+ /**
101
+ * If license key is empty, disable the license activation button.
102
+ */
103
+ if (0 === licenseKey.length) {
104
+ disableActivateLicenseButton();
105
+ }
106
+ });
107
+
108
+ $modal.on('click', '.button', function (evt) {
109
+ evt.preventDefault();
110
+
111
+ if ($(this).hasClass('disabled')) {
112
+ return;
113
+ }
114
+
115
+ var licenseKey = $licenseKeyInput.val().trim();
116
+
117
+ disableActivateLicenseButton();
118
+
119
+ if (0 === licenseKey.length) {
120
+ return;
121
+ }
122
+
123
+ $.ajax({
124
+ url: ajaxurl,
125
+ method: 'POST',
126
+ data: {
127
+ action : 'activate_license',
128
+ slug : pluginSlug,
129
+ license_key: licenseKey
130
+ },
131
+ beforeSend: function () {
132
+ $activateLicenseButton.text( '<?php _efs( 'activating-license', $slug ); ?>' );
133
+ },
134
+ success: function( result ) {
135
+ var resultObj = $.parseJSON( result );
136
+ if ( resultObj.success ) {
137
+ closeModal();
138
+
139
+ // Redirect to the "Account" page and sync the license.
140
+ window.location.href = syncLicenseUrl;
141
+ } else {
142
+ showError( resultObj.error );
143
+ resetActivateLicenseButton();
144
+ }
145
+ }
146
+ });
147
+ });
148
+
149
+ // If the user has clicked outside the window, close the modal.
150
+ $modal.on('click', function (evt) {
151
+ var $target = $(evt.target);
152
+
153
+ // If the user has clicked anywhere in the modal dialog, just return.
154
+ if ($target.hasClass('fs-modal-body') || $target.hasClass('fs-modal-footer')) {
155
+ return;
156
+ }
157
+
158
+ // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return.
159
+ if (( !$target.hasClass('button-close') ) && ( $target.parents('.fs-modal-body').length > 0 || $target.parents('.fs-modal-footer').length > 0 )) {
160
+ return;
161
+ }
162
+
163
+ closeModal();
164
+ });
165
+ }
166
+
167
+ function showModal() {
168
+ resetModal();
169
+
170
+ // Display the dialog box.
171
+ $modal.addClass('active');
172
+ $('body').addClass('has-fs-modal');
173
+
174
+ $licenseKeyInput.focus();
175
+ }
176
+
177
+ function closeModal() {
178
+ $modal.removeClass('active');
179
+ $('body').removeClass('has-fs-modal');
180
+ }
181
+
182
+ function resetActivateLicenseButton() {
183
+ enableActivateLicenseButton();
184
+ $activateLicenseButton.text( '<?php echo $activate_button_text; ?>' );
185
+ }
186
+
187
+ function resetModal() {
188
+ hideError();
189
+ resetActivateLicenseButton();
190
+ $licenseKeyInput.val( '' );
191
+ }
192
+
193
+ function enableActivateLicenseButton() {
194
+ $activateLicenseButton.removeClass( 'disabled' );
195
+ }
196
+
197
+ function disableActivateLicenseButton() {
198
+ $activateLicenseButton.addClass( 'disabled' );
199
+ }
200
+
201
+ function hideError() {
202
+ $licenseActivationMessage.hide();
203
+ }
204
+
205
+ function showError( msg ) {
206
+ $licenseActivationMessage.find( ' > p' ).html( msg );
207
+ $licenseActivationMessage.show();
208
+ }
209
+ });
210
+ })( jQuery );
211
+ </script>
freemius/templates/forms/resend-key.php ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.2.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ $message_above_input_field = __fs( 'ask-for-upgrade-email-address', $slug );
17
+ $send_button_text = __fs( 'send-license-key', $slug );
18
+ $cancel_button_text = __fs( 'deactivation-modal-button-cancel', $slug );
19
+ $email_address_placeholder = __fs( 'email-address', $slug );
20
+
21
+ $modal_content_html = <<< HTML
22
+ <div class="notice notice-error inline license-resend-message"><p></p></div>
23
+ <p>{$message_above_input_field}</p>
24
+ <div class="input-container">
25
+ <div class="button-container">
26
+ <a href="#" class="button button-primary button-send-license-key disabled">{$send_button_text}</a>
27
+ </div>
28
+ <div class="email-address-container">
29
+ <input class="email-address" type="text" placeholder="{$email_address_placeholder}">
30
+ </div>
31
+ </div>
32
+ HTML;
33
+
34
+ fs_enqueue_local_style( 'dialog-boxes', '/admin/dialog-boxes.css' );
35
+ ?>
36
+ <script type="text/javascript">
37
+ (function ($) {
38
+ $(document).ready(function () {
39
+ var modalContentHtml = <?php echo json_encode( $modal_content_html ); ?>,
40
+ modalHtml =
41
+ '<div class="fs-modal fs-modal-license-key-resend">'
42
+ + ' <div class="fs-modal-dialog">'
43
+ + ' <a class="button-close">✖</a>'
44
+ + ' <div class="fs-modal-body">'
45
+ + ' <div class="fs-modal-panel active">' + modalContentHtml + '</div>'
46
+ + ' </div>'
47
+ + ' </div>'
48
+ + '</div>',
49
+ $modal = $(modalHtml),
50
+ $sendLicenseKeyButton = $modal.find('.button-send-license-key'),
51
+ $emailAddressInput = $modal.find('input.email-address'),
52
+ $licenseResendMessage = $modal.find('.license-resend-message'),
53
+ moduleSlug = '<?php echo $slug; ?>',
54
+ isChild = false;
55
+
56
+ $modal.appendTo($('body'));
57
+
58
+ registerEventHandlers();
59
+
60
+ function registerEventHandlers() {
61
+ $('a.show-license-resend-modal-' + moduleSlug).click(function (evt) {
62
+ evt.preventDefault();
63
+
64
+ showModal();
65
+ });
66
+
67
+ $modal.on('input propertychange', 'input.email-address', function () {
68
+
69
+ var emailAddress = $(this).val().trim();
70
+
71
+ /**
72
+ * If email address is not empty, enable the send license key button.
73
+ */
74
+ if (emailAddress.length > 0) {
75
+ enableSendLicenseKeyButton();
76
+ }
77
+ });
78
+
79
+ $modal.on('blur', 'input.email-address', function () {
80
+ var emailAddress = $(this).val().trim();
81
+
82
+ /**
83
+ * If email address is empty, disable the send license key button.
84
+ */
85
+ if (0 === emailAddress.length) {
86
+ disableSendLicenseKeyButton();
87
+ }
88
+ });
89
+
90
+ $modal.on('click', '.button', function (evt) {
91
+ evt.preventDefault();
92
+
93
+ if ($(this).hasClass('disabled')) {
94
+ return;
95
+ }
96
+
97
+ if ($(this).hasClass('button-close')) {
98
+ closeModal();
99
+ return;
100
+ }
101
+
102
+ var emailAddress = $emailAddressInput.val().trim();
103
+
104
+ disableSendLicenseKeyButton();
105
+
106
+ if (0 === emailAddress.length) {
107
+ return;
108
+ }
109
+
110
+ $.ajax({
111
+ url : ajaxurl,
112
+ method : 'POST',
113
+ data : {
114
+ action: 'resend_license_key',
115
+ slug : moduleSlug,
116
+ email : emailAddress
117
+ },
118
+ beforeSend: function () {
119
+ $sendLicenseKeyButton.text('<?php _efs( 'sending-license-key', $slug ) ?>...');
120
+ },
121
+ success : function (result) {
122
+ var resultObj = $.parseJSON(result);
123
+ if (resultObj.success) {
124
+ closeModal();
125
+ } else {
126
+ showError(resultObj.error);
127
+ resetSendLicenseKeyButton();
128
+ }
129
+ }
130
+ });
131
+ });
132
+
133
+ // If the user has clicked outside the window, close the modal.
134
+ $modal.on('click', function (evt) {
135
+ var $target = $(evt.target);
136
+
137
+ // If the user has clicked anywhere in the modal dialog, just return.
138
+ if ($target.hasClass('fs-modal-body') || $target.parents('.fs-modal-body').length > 0) {
139
+ return;
140
+ }
141
+
142
+ closeModal();
143
+ });
144
+ }
145
+
146
+ function showModal() {
147
+ resetModal();
148
+
149
+ // Display the dialog box.
150
+ $modal.addClass('active');
151
+ $emailAddressInput.focus();
152
+
153
+ var $body = $('body');
154
+
155
+ isChild = $body.hasClass('has-fs-modal');
156
+ if (isChild) {
157
+ return;
158
+ }
159
+
160
+ $body.addClass('has-fs-modal');
161
+ }
162
+
163
+ function closeModal() {
164
+ $modal.removeClass('active');
165
+
166
+ // If child modal, do not remove the "has-fs-modal" class of the <body> element to keep its scrollbars hidden.
167
+ if (isChild) {
168
+ return;
169
+ }
170
+
171
+ $('body').removeClass('has-fs-modal');
172
+ }
173
+
174
+ function resetSendLicenseKeyButton() {
175
+ enableSendLicenseKeyButton();
176
+ $sendLicenseKeyButton.text('<?php echo $send_button_text; ?>');
177
+ }
178
+
179
+ function resetModal() {
180
+ hideError();
181
+ resetSendLicenseKeyButton();
182
+ $emailAddressInput.val('');
183
+ }
184
+
185
+ function enableSendLicenseKeyButton() {
186
+ $sendLicenseKeyButton.removeClass('disabled');
187
+ }
188
+
189
+ function disableSendLicenseKeyButton() {
190
+ $sendLicenseKeyButton.addClass('disabled');
191
+ }
192
+
193
+ function hideError() {
194
+ $licenseResendMessage.hide();
195
+ }
196
+
197
+ function showError(msg) {
198
+ $licenseResendMessage.find(' > p').html(msg);
199
+ $licenseResendMessage.show();
200
+ }
201
+ });
202
+ })(jQuery);
203
+ </script>
freemius/templates/plugin-icon.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ /**
17
+ * @since 1.1.7.5
18
+ */
19
+ $local_path = $fs->apply_filters( 'plugin_icon', false );
20
+
21
+ if ( is_string( $local_path ) ) {
22
+ $icons = array( $local_path );
23
+ } else {
24
+ global $fs_active_plugins;
25
+
26
+ $img_dir = WP_FS__DIR_IMG;
27
+
28
+ if ( 1 < count( $fs_active_plugins->plugins ) ) {
29
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
30
+ if ( $data->plugin_path == $fs->get_plugin_basename() ) {
31
+ $img_dir = WP_PLUGIN_DIR . '/' . $sdk_path . '/assets/img';
32
+ break;
33
+ }
34
+ }
35
+ }
36
+
37
+ $icons = glob( fs_normalize_path( $img_dir . '/' . $slug . '.*' ) );
38
+ if ( ! is_array( $icons ) || 0 === count( $icons ) ) {
39
+ $icon_found = false;
40
+ $local_path = fs_normalize_path( $img_dir . '/' . $slug . '.png' );
41
+ $have_write_permissions = is_writable( fs_normalize_path( $img_dir ) );
42
+
43
+ if ( WP_FS__IS_LOCALHOST && $fs->is_org_repo_compliant() && $have_write_permissions ) {
44
+ /**
45
+ * IMPORTANT: THIS CODE WILL NEVER RUN AFTER THE PLUGIN IS IN THE REPO.
46
+ *
47
+ * This code will only be executed once during the testing
48
+ * of the plugin in a local environment. The plugin icon file WILL
49
+ * already exist in the assets folder when the plugin is deployed to
50
+ * the repository.
51
+ */
52
+ $suffixes = array(
53
+ '-128x128.png',
54
+ '-128x128.jpg',
55
+ '-256x256.png',
56
+ '-256x256.jpg',
57
+ '.svg',
58
+ );
59
+
60
+ $base_url = 'https://plugins.svn.wordpress.org/' . $slug . '/assets/icon';
61
+
62
+ foreach ( $suffixes as $s ) {
63
+ $headers = get_headers( $base_url . $s );
64
+ if ( strpos( $headers[0], '200' ) ) {
65
+ $local_path = fs_normalize_path( $img_dir . '/' . $slug . '.' . substr( $s, strpos( $s, '.' ) + 1 ) );
66
+ fs_download_image( $base_url . $s, $local_path );
67
+ $icon_found = true;
68
+ break;
69
+ }
70
+ }
71
+ }
72
+
73
+ if ( ! $icon_found ) {
74
+ // No icons found, fallback to default icon.
75
+ if ( $have_write_permissions ) {
76
+ // If have write permissions, copy default icon.
77
+ copy( fs_normalize_path( $img_dir . '/plugin-icon.png' ), $local_path );
78
+ } else {
79
+ // If doesn't have write permissions, use default icon path.
80
+ $local_path = fs_normalize_path( $img_dir . '/plugin-icon.png' );
81
+ }
82
+ }
83
+
84
+ $icons = array( $local_path );
85
+ }
86
+ }
87
+
88
+ $icon_dir = dirname( $icons[0] );
89
+ $relative_url = fs_img_url( substr( $icons[0], strlen( $icon_dir ) ), $icon_dir );
90
+ ?>
91
+ <div class="fs-plugin-icon">
92
+ <img src="<?php echo $relative_url ?>" width="80" height="80" />
93
+ </div>
freemius/templates/plugin-info/description.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * @var FS_Plugin $plugin
15
+ */
16
+ $plugin = $VARS['plugin'];
17
+
18
+ if ( ! empty( $plugin->info->selling_point_0 ) ||
19
+ ! empty( $plugin->info->selling_point_1 ) ||
20
+ ! empty( $plugin->info->selling_point_2 )
21
+ ) : ?>
22
+ <div class="fs-selling-points">
23
+ <ul>
24
+ <?php for ( $i = 0; $i < 3; $i ++ ) : ?>
25
+ <?php if ( ! empty( $plugin->info->{'selling_point_' . $i} ) ) : ?>
26
+ <li><i class="dashicons dashicons-yes"></i>
27
+
28
+ <h3><?php echo $plugin->info->{'selling_point_' . $i} ?></h3></li>
29
+ <?php endif ?>
30
+ <?php endfor ?>
31
+ </ul>
32
+ </div>
33
+ <?php endif ?>
34
+ <div>
35
+ <?php
36
+ echo wp_kses( $plugin->info->description, array(
37
+ 'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),
38
+ 'b' => array(),
39
+ 'i' => array(),
40
+ 'p' => array(),
41
+ 'blockquote' => array(),
42
+ 'h2' => array(),
43
+ 'h3' => array(),
44
+ 'ul' => array(),
45
+ 'ol' => array(),
46
+ 'li' => array()
47
+ ) );
48
+ ?>
49
+ </div>
50
+ <?php if ( ! empty( $plugin->info->screenshots ) ) : ?>
51
+ <?php $screenshots = $plugin->info->screenshots ?>
52
+ <div class="fs-screenshots clearfix">
53
+ <h2><?php _efs( 'screenshots', $plugin->slug ) ?></h2>
54
+ <ul>
55
+ <?php $i = 0;
56
+ foreach ( $screenshots as $s => $url ) : ?>
57
+ <?php
58
+ // Relative URLs are replaced with WordPress.org base URL
59
+ // therefore we need to set absolute URLs.
60
+ $url = 'http' . ( WP_FS__IS_HTTPS ? 's' : '' ) . ':' . $url; ?>
61
+ <li class="<?php echo ( 0 === $i % 2 ) ? 'odd' : 'even' ?>">
62
+ <style>
63
+ #section-description .fs-screenshots <?php echo ".fs-screenshot-{$i}" ?>
64
+ {
65
+ background-image: url('<?php echo $url ?>');
66
+ }
67
+ </style>
68
+ <a href="<?php echo $url ?>"
69
+ title="<?php printf( __fs( 'view-full-size-x', $plugin->slug ), $i ) ?>"
70
+ class="fs-screenshot-<?php echo $i ?>"></a>
71
+ </li>
72
+ <?php $i ++; endforeach ?>
73
+ </ul>
74
+ </div>
75
+ <?php endif ?>
freemius/templates/plugin-info/features.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * @var FS_Plugin $plugin
15
+ */
16
+ $plugin = $VARS['plugin'];
17
+
18
+ $plans = $VARS['plans'];
19
+
20
+ $features_plan_map = array();
21
+ foreach ( $plans as $plan ) {
22
+ foreach ( $plan->features as $feature ) {
23
+ if ( ! isset( $features_plan_map[ $feature->id ] ) ) {
24
+ $features_plan_map[ $feature->id ] = array( 'feature' => $feature, 'plans' => array() );
25
+ }
26
+
27
+ $features_plan_map[ $feature->id ]['plans'][ $plan->id ] = $feature;
28
+ }
29
+
30
+ // Add support as a feature.
31
+ if ( ! empty( $plan->support_email ) ||
32
+ ! empty( $plan->support_skype ) ||
33
+ ! empty( $plan->support_phone ) ||
34
+ true === $plan->is_success_manager
35
+ ) {
36
+ if ( ! isset( $features_plan_map['support'] ) ) {
37
+ $support_feature = new stdClass();
38
+ $support_feature->id = 'support';
39
+ $support_feature->title = __fs( 'Support', $plugin->slug );
40
+ $features_plan_map[ $support_feature->id ] = array( 'feature' => $support_feature, 'plans' => array() );
41
+ } else {
42
+ $support_feature = $features_plan_map['support'];
43
+ }
44
+
45
+ $features_plan_map[ $support_feature->id ]['plans'][ $plan->id ] = $support_feature;
46
+ }
47
+ }
48
+
49
+ // Add updates as a feature for all plans.
50
+ $updates_feature = new stdClass();
51
+ $updates_feature->id = 'updates';
52
+ $updates_feature->title = __fs( 'unlimited-updates', $plugin->slug );
53
+ $features_plan_map[ $updates_feature->id ] = array( 'feature' => $updates_feature, 'plans' => array() );
54
+ foreach ( $plans as $plan ) {
55
+ $features_plan_map[ $updates_feature->id ]['plans'][ $plan->id ] = $updates_feature;
56
+ }
57
+ ?>
58
+ <div class="fs-features">
59
+ <table>
60
+ <thead>
61
+ <tr>
62
+ <th></th>
63
+ <?php foreach ( $plans as $plan ) : ?>
64
+ <th>
65
+ <?php echo $plan->title ?>
66
+ <span class="fs-price">
67
+ <?php foreach ( $plan->pricing as $pricing ) : ?>
68
+ <?php if ( 1 == $pricing->licenses ) : ?>
69
+ $<?php echo $pricing->annual_price ?> / year
70
+ <?php endif ?>
71
+ <?php endforeach ?>
72
+ </span>
73
+ </th>
74
+ <?php endforeach ?>
75
+ </tr>
76
+ </thead>
77
+ <tbody>
78
+ <?php $odd = true;
79
+ foreach ( $features_plan_map as $feature_id => $data ) : ?>
80
+ <tr class="fs-<?php echo $odd ? 'odd' : 'even' ?>">
81
+ <td><?php echo ucfirst( $data['feature']->title ) ?></td>
82
+ <?php foreach ( $plans as $plan ) : ?>
83
+ <td>
84
+ <?php if ( isset( $data['plans'][ $plan->id ] ) ) : ?>
85
+ <?php if ( ! empty( $data['plans'][ $plan->id ]->value ) ) : ?>
86
+ <b><?php echo $data['plans'][ $plan->id ]->value ?></b>
87
+ <?php else : ?>
88
+ <i class="dashicons dashicons-yes"></i>
89
+ <?php endif ?>
90
+ <?php endif ?>
91
+ </td>
92
+ <?php endforeach ?>
93
+ </tr>
94
+ <?php $odd = ! $odd; endforeach ?>
95
+ </tbody>
96
+ </table>
97
+ </div>
freemius/templates/plugin-info/screenshots.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * @var FS_Plugin $plugin
15
+ */
16
+ $plugin = $VARS['plugin'];
17
+
18
+ $screenshots = $VARS['screenshots'];
19
+ ?>
20
+ <ol>
21
+ <?php $i = 0;
22
+ foreach ( $screenshots as $s => $url ) : ?>
23
+ <?php
24
+ // Relative URLs are replaced with WordPress.org base URL
25
+ // therefore we need to set absolute URLs.
26
+ $url = 'http' . ( WP_FS__IS_HTTPS ? 's' : '' ) . ':' . $url; ?>
27
+ <li>
28
+ <a href="<?php echo $url ?>"
29
+ title="<?php printf( __fs( 'view-full-size-x', $plugin->slug ), $i ) ?>"><img
30
+ src="<?php echo $url ?>"></a>
31
+ </li>
32
+ <?php $i ++; endforeach ?>
33
+ </ol>
freemius/templates/powered-by.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $VARS = isset($VARS) ? $VARS : array();
14
+
15
+ wp_enqueue_script( 'jquery' );
16
+ wp_enqueue_script( 'json2' );
17
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
18
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
19
+ ?>
20
+
21
+ <div id="piframe"></div>
22
+ <script type="text/javascript">
23
+ (function ($) {
24
+ $(function () {
25
+ var
26
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
27
+ piframe = $('<iframe id="fs_promo_tab" src="' + base_url + '/promotional-tab/?<?php echo http_build_query($VARS) ?>#' + encodeURIComponent(document.location.href) + '" height="350" width="60" frameborder="0" style=" background: transparent; position: fixed; top: 20%; right: 0;" scrolling="no"></iframe>')
28
+ .appendTo('#piframe');
29
+
30
+ FS.PostMessage.init(base_url);
31
+ FS.PostMessage.receive('state', function (state) {
32
+ if ('closed' === state)
33
+ $('#fs_promo_tab').css('width', '60px');
34
+ else
35
+ $('#fs_promo_tab').css('width', '345px');
36
+ });
37
+ });
38
+ })(jQuery);
39
+ </script>
freemius/templates/pricing.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ wp_enqueue_script( 'jquery' );
14
+ wp_enqueue_script( 'json2' );
15
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
16
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
17
+
18
+ $slug = $VARS['slug'];
19
+ $fs = freemius( $slug );
20
+ $timestamp = time();
21
+
22
+ $context_params = array(
23
+ 'plugin_id' => $fs->get_id(),
24
+ 'plugin_public_key' => $fs->get_public_key(),
25
+ 'plugin_version' => $fs->get_plugin_version(),
26
+ );
27
+
28
+ // Get site context secure params.
29
+ if ( $fs->is_registered() ) {
30
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
31
+ $fs->get_site(),
32
+ $timestamp,
33
+ 'upgrade'
34
+ ) );
35
+ }
36
+
37
+ if ( $fs->is_payments_sandbox() ) // Append plugin secure token for sandbox mode authentication.)
38
+ {
39
+ $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
40
+ $fs->get_plugin(),
41
+ $timestamp,
42
+ 'checkout'
43
+ );
44
+ }
45
+
46
+ $query_params = array_merge( $context_params, $_GET, array(
47
+ 'next' => $fs->_get_sync_license_url( false, false ),
48
+ 'plugin_version' => $fs->get_plugin_version(),
49
+ // Billing cycle.
50
+ 'billing_cycle' => fs_request_get( 'billing_cycle', WP_FS__PERIOD_ANNUALLY ),
51
+ ) );
52
+ ?>
53
+
54
+ <div id="fs_pricing" class="wrap" style="margin: 0 0 -65px -20px;">
55
+ <div id="iframe"></div>
56
+ <form action="" method="POST">
57
+ <input type="hidden" name="user_id"/>
58
+ <input type="hidden" name="user_email"/>
59
+ <input type="hidden" name="site_id"/>
60
+ <input type="hidden" name="public_key"/>
61
+ <input type="hidden" name="secret_key"/>
62
+ <input type="hidden" name="action" value="account"/>
63
+ </form>
64
+
65
+ <script type="text/javascript">
66
+ (function ($, undef) {
67
+ $(function () {
68
+ var
69
+ // Keep track of the iframe height.
70
+ iframe_height = 800,
71
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
72
+ // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
73
+ // passed via query string or hard coded into the child page, it depends on your needs).
74
+ src = base_url + '/pricing/?<?php echo http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
75
+
76
+ // Append the Iframe into the DOM.
77
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
78
+ .appendTo('#iframe');
79
+
80
+ FS.PostMessage.init(base_url);
81
+
82
+ FS.PostMessage.receive('height', function (data) {
83
+ var h = data.height;
84
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
85
+ iframe_height = h;
86
+ $("#iframe iframe").height(iframe_height + 'px');
87
+ }
88
+ });
89
+
90
+ FS.PostMessage.receive('get_dimensions', function (data) {
91
+ FS.PostMessage.post('dimensions', {
92
+ height : $(document.body).height(),
93
+ scrollTop: $(document).scrollTop()
94
+ }, iframe[0]);
95
+ });
96
+ });
97
+ })(jQuery);
98
+ </script>
99
+ </div>
100
+ <?php
101
+ $params = array(
102
+ 'page' => 'pricing',
103
+ 'module_id' => $fs->get_id(),
104
+ 'module_slug' => $slug,
105
+ 'module_version' => $fs->get_plugin_version(),
106
+ );
107
+ fs_require_template( 'powered-by.php', $params );
108
+ ?>
freemius/templates/sticky-admin-notice-js.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sticky admin notices JavaScript handler for dismissing notice messages
4
+ * by sending AJAX call to the server in order to remove the message from the Database.
5
+ *
6
+ * @package Freemius
7
+ * @copyright Copyright (c) 2015, Freemius, Inc.
8
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
+ * @since 1.0.7
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+ ?>
16
+ <script type="text/javascript" >
17
+ jQuery(document).ready(function($) {
18
+ $('.fs-notice.fs-sticky .fs-close').click(function(){
19
+ var
20
+ notice = $(this).parents('.fs-notice'),
21
+ id = notice.attr('data-id'),
22
+ slug = notice.attr('data-slug');
23
+
24
+ notice.fadeOut('fast', function(){
25
+ var data = {
26
+ action: slug + '_dismiss_notice_action',
27
+ slug: slug,
28
+ message_id: id
29
+ };
30
+
31
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
32
+ $.post(ajaxurl, data, function(response) {
33
+
34
+ });
35
+
36
+ notice.remove();
37
+ });
38
+ });
39
+ });
40
+ </script>
includes/easy-custom-facebook-feed-widget.php CHANGED
@@ -122,8 +122,8 @@ class Easy_Custom_Facebook_Feed_Widget extends WP_Widget {
122
  );
123
 
124
  $defaults = array(
125
- 'title' => '',
126
- 'fb_appid' => '',
127
  'fanpage_url' => 'jwebsol',
128
  'layout' => 'half',
129
  'image_size' => 'normal',
@@ -313,5 +313,4 @@ class Easy_Custom_Facebook_Feed_Widget extends WP_Widget {
313
  return $instance;
314
  }
315
 
316
- } // class Foo_Widget
317
- ?>
122
  );
123
 
124
  $defaults = array(
125
+ 'title' => null,
126
+ 'fb_appid' => null,
127
  'fanpage_url' => 'jwebsol',
128
  'layout' => 'half',
129
  'image_size' => 'normal',
313
  return $instance;
314
  }
315
 
316
+ } // class Foo_Widget ?>
 
includes/easy-facebook-page-plugin-widget.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
- //ini_set('display_errors','Off');
3
  class Easy_Facebook_Page_Plugin_Widget extends WP_Widget {
4
 
5
  /**
@@ -42,99 +41,28 @@ class Easy_Facebook_Page_Plugin_Widget extends WP_Widget {
42
  * @param array $instance Previously saved values from database.
43
  */
44
  public function form( $instance ) {
45
-
46
-
47
- $locales = array( 'af_ZA' => 'Afrikaans',
48
- 'ar_AR' => 'Arabic',
49
- 'az_AZ' => 'Azeri',
50
- 'be_BY' => 'Belarusian',
51
- 'bg_BG' => 'Bulgarian',
52
- 'bn_IN' => 'Bengali',
53
- 'bs_BA' => 'Bosnian',
54
- 'ca_ES' => 'Catalan',
55
- 'cs_CZ' => 'Czech',
56
- 'cy_GB' => 'Welsh',
57
- 'da_DK' => 'Danish',
58
- 'de_DE' => 'German',
59
- 'el_GR' => 'Greek',
60
- 'en_US' => 'English (US)',
61
- 'en_GB' => 'English (UK)',
62
- 'eo_EO' => 'Esperanto',
63
- 'es_ES' => 'Spanish (Spain)',
64
- 'es_LA' => 'Spanish',
65
- 'et_EE' => 'Estonian',
66
- 'eu_ES' => 'Basque',
67
- 'fa_IR' => 'Persian',
68
- 'fb_LT' => 'Leet Speak',
69
- 'fi_FI' => 'Finnish',
70
- 'fo_FO' => 'Faroese',
71
- 'fr_FR' => 'French (France)',
72
- 'fr_CA' => 'French (Canada)',
73
- 'fy_NL' => 'NETHERLANDS (NL)',
74
- 'ga_IE' => 'Irish',
75
- 'gl_ES' => 'Galician',
76
- 'hi_IN' => 'Hindi',
77
- 'hr_HR' => 'Croatian',
78
- 'hu_HU' => 'Hungarian',
79
- 'hy_AM' => 'Armenian',
80
- 'id_ID' => 'Indonesian',
81
- 'is_IS' => 'Icelandic',
82
- 'it_IT' => 'Italian',
83
- 'ja_JP' => 'Japanese',
84
- 'ka_GE' => 'Georgian',
85
- 'km_KH' => 'Khmer',
86
- 'ko_KR' => 'Korean',
87
- 'ku_TR' => 'Kurdish',
88
- 'la_VA' => 'Latin',
89
- 'lt_LT' => 'Lithuanian',
90
- 'lv_LV' => 'Latvian',
91
- 'mk_MK' => 'Macedonian',
92
- 'ml_IN' => 'Malayalam',
93
- 'ms_MY' => 'Malay',
94
- 'nb_NO' => 'Norwegian (bokmal)',
95
- 'ne_NP' => 'Nepali',
96
- 'nl_NL' => 'Dutch',
97
- 'nn_NO' => 'Norwegian (nynorsk)',
98
- 'pa_IN' => 'Punjabi',
99
- 'pl_PL' => 'Polish',
100
- 'ps_AF' => 'Pashto',
101
- 'pt_PT' => 'Portuguese (Portugal)',
102
- 'pt_BR' => 'Portuguese (Brazil)',
103
- 'ro_RO' => 'Romanian',
104
- 'ru_RU' => 'Russian',
105
- 'sk_SK' => 'Slovak',
106
- 'sl_SI' => 'Slovenian',
107
- 'sq_AL' => 'Albanian',
108
- 'sr_RS' => 'Serbian',
109
- 'sv_SE' => 'Swedish',
110
- 'sw_KE' => 'Swahili',
111
- 'ta_IN' => 'Tamil',
112
- 'te_IN' => 'Telugu',
113
- 'th_TH' => 'Thai',
114
- 'tl_PH' => 'Filipino',
115
- 'tr_TR' => 'Turkish',
116
- 'uk_UA' => 'Ukrainian',
117
- 'ur_PK' => 'Urdu',
118
- 'vi_VN' => 'Vietnamese',
119
- 'zh_CN' => 'Simplified Chinese (China)',
120
- 'zh_HK' => 'Traditional Chinese (Hong Kong)',
121
- 'zh_TW' => 'Traditional Chinese (Taiwan)',
122
- );
123
-
124
  $defaults = array(
125
- 'title' => '',
126
- 'fb_appid' => '',
127
- 'fanpage_url' => 'https://www.facebook.com/jwebsol',
128
- 'box_width' => 250,
129
- 'box_height' => '',
130
- 'show_faces' => 1,
131
- 'show_stream' => 0,
132
- 'hide_cover' => 0,
133
- 'responsive' => 0,
134
- 'hide_cta' => 0,
135
  'small_header' => 0,
136
- 'locale' => 'en_US',
137
- 'locale_other'=> ''
 
138
  );
139
 
140
  $instance = wp_parse_args( (array) $instance, $defaults );
@@ -184,6 +112,29 @@ class Easy_Facebook_Page_Plugin_Widget extends WP_Widget {
184
  </select>
185
  <i><?php _e( 'Language of your page' , 'easy-facebook-likebox' ); ?></i>
186
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  <p>
189
  <label for="<?php echo $this->get_field_id( 'locale_other' ); ?>"><?php _e( 'Locale (Other):', 'easy-facebook-likebox' ); ?></label>
@@ -270,7 +221,7 @@ class Easy_Facebook_Page_Plugin_Widget extends WP_Widget {
270
 
271
  ?>
272
 
273
- <p style="background:#ddd; padding:5px; "><?php echo '[efb_likebox fanpage_url="'.$fanpage_url.'" '.$fb_appid.' box_width="'.$box_width.'" box_height="'.$box_height.'" locale="'.$locale.'" responsive="'.$responsive.'" show_faces="'.$show_faces.'" show_stream="'.$show_stream.'" hide_cover="'.$hide_cover.'" small_header="'.$small_header.'" hide_cta="'.$hide_cta.'" ]'?></p>
274
 
275
  <?php
276
  }
@@ -304,9 +255,12 @@ class Easy_Facebook_Page_Plugin_Widget extends WP_Widget {
304
  $instance['locale'] = ( ! empty( $new_instance['locale'] ) ) ? strip_tags( $new_instance['locale'] ) : '';
305
  $instance['locale_other'] = ( ! empty( $new_instance['locale_other'] ) ) ? strip_tags( $new_instance['locale_other'] ) : '';
306
 
 
 
 
307
 
308
  return $instance;
309
  }
310
-
311
  } // class Foo_Widget
312
  ?>
1
  <?php
 
2
  class Easy_Facebook_Page_Plugin_Widget extends WP_Widget {
3
 
4
  /**
41
  * @param array $instance Previously saved values from database.
42
  */
43
  public function form( $instance ) {
44
+
45
+ //Get locales
46
+ $locales = efbl_get_locales();
47
+
48
+ //Get effects
49
+ $css3_effects = get_css3_animations();
50
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  $defaults = array(
52
+ 'title' => '',
53
+ 'fb_appid' => '',
54
+ 'fanpage_url' => 'https://www.facebook.com/jwebsol',
55
+ 'box_width' => 250,
56
+ 'box_height' => '',
57
+ 'show_faces' => 1,
58
+ 'show_stream' => 0,
59
+ 'hide_cover' => 0,
60
+ 'responsive' => 0,
61
+ 'hide_cta' => 0,
62
  'small_header' => 0,
63
+ 'locale' => 'en_US',
64
+ 'locale_other' => '',
65
+ 'animate_effect' => 'fadeIn',
66
  );
67
 
68
  $instance = wp_parse_args( (array) $instance, $defaults );
112
  </select>
113
  <i><?php _e( 'Language of your page' , 'easy-facebook-likebox' ); ?></i>
114
  </p>
115
+
116
+ <p >
117
+ <label for="<?php echo $this->get_field_id( 'animate_effect' ); ?>"><?php _e( 'Animation:', 'easy-facebook-likebox' ); ?></label>
118
+
119
+
120
+ <select class="widefat" id="<?php echo $this->get_field_id( 'animate_effect' ); ?>" name="<?php echo $this->get_field_name( 'animate_effect' ); ?>">
121
+ <?php if($css3_effects){
122
+ foreach ($css3_effects as $key=>$value){?>
123
+ <optgroup label="<?php echo $key?>">
124
+
125
+ <?php
126
+ if($value){
127
+ foreach ($value as $val){?>
128
+
129
+ <option <?php selected( $animate_effect, $val , $echo = true); ?> value="<?php echo $val?>"><?php echo $val?></option>
130
+ <?php }
131
+ }?>
132
+ </optgroup>
133
+ <?php }
134
+ }?>
135
+ </select>
136
+ <i><?php _e( 'Select the CSS three animation effect' , 'easy-facebook-likebox' ); ?></i>
137
+ </p>
138
 
139
  <p>
140
  <label for="<?php echo $this->get_field_id( 'locale_other' ); ?>"><?php _e( 'Locale (Other):', 'easy-facebook-likebox' ); ?></label>
221
 
222
  ?>
223
 
224
+ <p style="background:#ddd; padding:5px; "><?php echo '[efb_likebox fanpage_url="'.$fanpage_url.'" '.$fb_appid.' box_width="'.$box_width.'" box_height="'.$box_height.'" locale="'.$locale.'" responsive="'.$responsive.'" show_faces="'.$show_faces.'" show_stream="'.$show_stream.'" hide_cover="'.$hide_cover.'" small_header="'.$small_header.'" hide_cta="'.$hide_cta.'" animate_effect="'.$animate_effect.'" ]'?></p>
225
 
226
  <?php
227
  }
255
  $instance['locale'] = ( ! empty( $new_instance['locale'] ) ) ? strip_tags( $new_instance['locale'] ) : '';
256
  $instance['locale_other'] = ( ! empty( $new_instance['locale_other'] ) ) ? strip_tags( $new_instance['locale_other'] ) : '';
257
 
258
+ $instance['animate_effect'] = ( ! empty( $new_instance['animate_effect'] ) ) ? strip_tags( $new_instance['animate_effect'] ) : '';
259
+
260
+
261
 
262
  return $instance;
263
  }
264
+
265
  } // class Foo_Widget
266
  ?>
languages/easy-facebook-likebox.pot CHANGED
@@ -145,6 +145,8 @@ msgstr ""
145
  msgid "Support and Updates"
146
  msgstr ""
147
 
 
 
148
  #: ../admin/views/instructinos.php:16
149
  msgid "Custom facebook feed widget or shortcode usage instructions."
150
  msgstr ""
145
  msgid "Support and Updates"
146
  msgstr ""
147
 
148
+
149
+
150
  #: ../admin/views/instructinos.php:16
151
  msgid "Custom facebook feed widget or shortcode usage instructions."
152
  msgstr ""
public/assets/css/animate.css ADDED
@@ -0,0 +1,3340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /*!
4
+ * animate.css -http://daneden.me/animate
5
+ * Version - 3.5.1
6
+ * Licensed under the MIT license - http://opensource.org/licenses/MIT
7
+ *
8
+ * Copyright (c) 2016 Daniel Eden
9
+ */
10
+
11
+ .animated {
12
+ -webkit-animation-duration: 1s;
13
+ animation-duration: 1s;
14
+ -webkit-animation-fill-mode: both;
15
+ animation-fill-mode: both;
16
+ }
17
+
18
+ .animated.infinite {
19
+ -webkit-animation-iteration-count: infinite;
20
+ animation-iteration-count: infinite;
21
+ }
22
+
23
+ .animated.hinge {
24
+ -webkit-animation-duration: 2s;
25
+ animation-duration: 2s;
26
+ }
27
+
28
+ .animated.flipOutX,
29
+ .animated.flipOutY,
30
+ .animated.bounceIn,
31
+ .animated.bounceOut {
32
+ -webkit-animation-duration: .75s;
33
+ animation-duration: .75s;
34
+ }
35
+
36
+ @-webkit-keyframes bounce {
37
+ from, 20%, 53%, 80%, to {
38
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
39
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
40
+ -webkit-transform: translate3d(0,0,0);
41
+ transform: translate3d(0,0,0);
42
+ }
43
+
44
+ 40%, 43% {
45
+ -webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
46
+ animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
47
+ -webkit-transform: translate3d(0, -30px, 0);
48
+ transform: translate3d(0, -30px, 0);
49
+ }
50
+
51
+ 70% {
52
+ -webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
53
+ animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
54
+ -webkit-transform: translate3d(0, -15px, 0);
55
+ transform: translate3d(0, -15px, 0);
56
+ }
57
+
58
+ 90% {
59
+ -webkit-transform: translate3d(0,-4px,0);
60
+ transform: translate3d(0,-4px,0);
61
+ }
62
+ }
63
+
64
+ @keyframes bounce {
65
+ from, 20%, 53%, 80%, to {
66
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
67
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
68
+ -webkit-transform: translate3d(0,0,0);
69
+ transform: translate3d(0,0,0);
70
+ }
71
+
72
+ 40%, 43% {
73
+ -webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
74
+ animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
75
+ -webkit-transform: translate3d(0, -30px, 0);
76
+ transform: translate3d(0, -30px, 0);
77
+ }
78
+
79
+ 70% {
80
+ -webkit-animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
81
+ animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
82
+ -webkit-transform: translate3d(0, -15px, 0);
83
+ transform: translate3d(0, -15px, 0);
84
+ }
85
+
86
+ 90% {
87
+ -webkit-transform: translate3d(0,-4px,0);
88
+ transform: translate3d(0,-4px,0);
89
+ }
90
+ }
91
+
92
+ .bounce {
93
+ -webkit-animation-name: bounce;
94
+ animation-name: bounce;
95
+ -webkit-transform-origin: center bottom;
96
+ transform-origin: center bottom;
97
+ }
98
+
99
+ @-webkit-keyframes flash {
100
+ from, 50%, to {
101
+ opacity: 1;
102
+ }
103
+
104
+ 25%, 75% {
105
+ opacity: 0;
106
+ }
107
+ }
108
+
109
+ @keyframes flash {
110
+ from, 50%, to {
111
+ opacity: 1;
112
+ }
113
+
114
+ 25%, 75% {
115
+ opacity: 0;
116
+ }
117
+ }
118
+
119
+ .flash {
120
+ -webkit-animation-name: flash;
121
+ animation-name: flash;
122
+ }
123
+
124
+ /* originally authored by Nick Pettit - https://github.com/nickpettit/glide */
125
+
126
+ @-webkit-keyframes pulse {
127
+ from {
128
+ -webkit-transform: scale3d(1, 1, 1);
129
+ transform: scale3d(1, 1, 1);
130
+ }
131
+
132
+ 50% {
133
+ -webkit-transform: scale3d(1.05, 1.05, 1.05);
134
+ transform: scale3d(1.05, 1.05, 1.05);
135
+ }
136
+
137
+ to {
138
+ -webkit-transform: scale3d(1, 1, 1);
139
+ transform: scale3d(1, 1, 1);
140
+ }
141
+ }
142
+
143
+ @keyframes pulse {
144
+ from {
145
+ -webkit-transform: scale3d(1, 1, 1);
146
+ transform: scale3d(1, 1, 1);
147
+ }
148
+
149
+ 50% {
150
+ -webkit-transform: scale3d(1.05, 1.05, 1.05);
151
+ transform: scale3d(1.05, 1.05, 1.05);
152
+ }
153
+
154
+ to {
155
+ -webkit-transform: scale3d(1, 1, 1);
156
+ transform: scale3d(1, 1, 1);
157
+ }
158
+ }
159
+
160
+ .pulse {
161
+ -webkit-animation-name: pulse;
162
+ animation-name: pulse;
163
+ }
164
+
165
+ @-webkit-keyframes rubberBand {
166
+ from {
167
+ -webkit-transform: scale3d(1, 1, 1);
168
+ transform: scale3d(1, 1, 1);
169
+ }
170
+
171
+ 30% {
172
+ -webkit-transform: scale3d(1.25, 0.75, 1);
173
+ transform: scale3d(1.25, 0.75, 1);
174
+ }
175
+
176
+ 40% {
177
+ -webkit-transform: scale3d(0.75, 1.25, 1);
178
+ transform: scale3d(0.75, 1.25, 1);
179
+ }
180
+
181
+ 50% {
182
+ -webkit-transform: scale3d(1.15, 0.85, 1);
183
+ transform: scale3d(1.15, 0.85, 1);
184
+ }
185
+
186
+ 65% {
187
+ -webkit-transform: scale3d(.95, 1.05, 1);
188
+ transform: scale3d(.95, 1.05, 1);
189
+ }
190
+
191
+ 75% {
192
+ -webkit-transform: scale3d(1.05, .95, 1);
193
+ transform: scale3d(1.05, .95, 1);
194
+ }
195
+
196
+ to {
197
+ -webkit-transform: scale3d(1, 1, 1);
198
+ transform: scale3d(1, 1, 1);
199
+ }
200
+ }
201
+
202
+ @keyframes rubberBand {
203
+ from {
204
+ -webkit-transform: scale3d(1, 1, 1);
205
+ transform: scale3d(1, 1, 1);
206
+ }
207
+
208
+ 30% {
209
+ -webkit-transform: scale3d(1.25, 0.75, 1);
210
+ transform: scale3d(1.25, 0.75, 1);
211
+ }
212
+
213
+ 40% {
214
+ -webkit-transform: scale3d(0.75, 1.25, 1);
215
+ transform: scale3d(0.75, 1.25, 1);
216
+ }
217
+
218
+ 50% {
219
+ -webkit-transform: scale3d(1.15, 0.85, 1);
220
+ transform: scale3d(1.15, 0.85, 1);
221
+ }
222
+
223
+ 65% {
224
+ -webkit-transform: scale3d(.95, 1.05, 1);
225
+ transform: scale3d(.95, 1.05, 1);
226
+ }
227
+
228
+ 75% {
229
+ -webkit-transform: scale3d(1.05, .95, 1);
230
+ transform: scale3d(1.05, .95, 1);
231
+ }
232
+
233
+ to {
234
+ -webkit-transform: scale3d(1, 1, 1);
235
+ transform: scale3d(1, 1, 1);
236
+ }
237
+ }
238
+
239
+ .rubberBand {
240
+ -webkit-animation-name: rubberBand;
241
+ animation-name: rubberBand;
242
+ }
243
+
244
+ @-webkit-keyframes shake {
245
+ from, to {
246
+ -webkit-transform: translate3d(0, 0, 0);
247
+ transform: translate3d(0, 0, 0);
248
+ }
249
+
250
+ 10%, 30%, 50%, 70%, 90% {
251
+ -webkit-transform: translate3d(-10px, 0, 0);
252
+ transform: translate3d(-10px, 0, 0);
253
+ }
254
+
255
+ 20%, 40%, 60%, 80% {
256
+ -webkit-transform: translate3d(10px, 0, 0);
257
+ transform: translate3d(10px, 0, 0);
258
+ }
259
+ }
260
+
261
+ @keyframes shake {
262
+ from, to {
263
+ -webkit-transform: translate3d(0, 0, 0);
264
+ transform: translate3d(0, 0, 0);
265
+ }
266
+
267
+ 10%, 30%, 50%, 70%, 90% {
268
+ -webkit-transform: translate3d(-10px, 0, 0);
269
+ transform: translate3d(-10px, 0, 0);
270
+ }
271
+
272
+ 20%, 40%, 60%, 80% {
273
+ -webkit-transform: translate3d(10px, 0, 0);
274
+ transform: translate3d(10px, 0, 0);
275
+ }
276
+ }
277
+
278
+ .shake {
279
+ -webkit-animation-name: shake;
280
+ animation-name: shake;
281
+ }
282
+
283
+ @-webkit-keyframes headShake {
284
+ 0% {
285
+ -webkit-transform: translateX(0);
286
+ transform: translateX(0);
287
+ }
288
+
289
+ 6.5% {
290
+ -webkit-transform: translateX(-6px) rotateY(-9deg);
291
+ transform: translateX(-6px) rotateY(-9deg);
292
+ }
293
+
294
+ 18.5% {
295
+ -webkit-transform: translateX(5px) rotateY(7deg);
296
+ transform: translateX(5px) rotateY(7deg);
297
+ }
298
+
299
+ 31.5% {
300
+ -webkit-transform: translateX(-3px) rotateY(-5deg);
301
+ transform: translateX(-3px) rotateY(-5deg);
302
+ }
303
+
304
+ 43.5% {
305
+ -webkit-transform: translateX(2px) rotateY(3deg);
306
+ transform: translateX(2px) rotateY(3deg);
307
+ }
308
+
309
+ 50% {
310
+ -webkit-transform: translateX(0);
311
+ transform: translateX(0);
312
+ }
313
+ }
314
+
315
+ @keyframes headShake {
316
+ 0% {
317
+ -webkit-transform: translateX(0);
318
+ transform: translateX(0);
319
+ }
320
+
321
+ 6.5% {
322
+ -webkit-transform: translateX(-6px) rotateY(-9deg);
323
+ transform: translateX(-6px) rotateY(-9deg);
324
+ }
325
+
326
+ 18.5% {
327
+ -webkit-transform: translateX(5px) rotateY(7deg);
328
+ transform: translateX(5px) rotateY(7deg);
329
+ }
330
+
331
+ 31.5% {
332
+ -webkit-transform: translateX(-3px) rotateY(-5deg);
333
+ transform: translateX(-3px) rotateY(-5deg);
334
+ }
335
+
336
+ 43.5% {
337
+ -webkit-transform: translateX(2px) rotateY(3deg);
338
+ transform: translateX(2px) rotateY(3deg);
339
+ }
340
+
341
+ 50% {
342
+ -webkit-transform: translateX(0);
343
+ transform: translateX(0);
344
+ }
345
+ }
346
+
347
+ .headShake {
348
+ -webkit-animation-timing-function: ease-in-out;
349
+ animation-timing-function: ease-in-out;
350
+ -webkit-animation-name: headShake;
351
+ animation-name: headShake;
352
+ }
353
+
354
+ @-webkit-keyframes swing {
355
+ 20% {
356
+ -webkit-transform: rotate3d(0, 0, 1, 15deg);
357
+ transform: rotate3d(0, 0, 1, 15deg);
358
+ }
359
+
360
+ 40% {
361
+ -webkit-transform: rotate3d(0, 0, 1, -10deg);
362
+ transform: rotate3d(0, 0, 1, -10deg);
363
+ }
364
+
365
+ 60% {
366
+ -webkit-transform: rotate3d(0, 0, 1, 5deg);
367
+ transform: rotate3d(0, 0, 1, 5deg);
368
+ }
369
+
370
+ 80% {
371
+ -webkit-transform: rotate3d(0, 0, 1, -5deg);
372
+ transform: rotate3d(0, 0, 1, -5deg);
373
+ }
374
+
375
+ to {
376
+ -webkit-transform: rotate3d(0, 0, 1, 0deg);
377
+ transform: rotate3d(0, 0, 1, 0deg);
378
+ }
379
+ }
380
+
381
+ @keyframes swing {
382
+ 20% {
383
+ -webkit-transform: rotate3d(0, 0, 1, 15deg);
384
+ transform: rotate3d(0, 0, 1, 15deg);
385
+ }
386
+
387
+ 40% {
388
+ -webkit-transform: rotate3d(0, 0, 1, -10deg);
389
+ transform: rotate3d(0, 0, 1, -10deg);
390
+ }
391
+
392
+ 60% {
393
+ -webkit-transform: rotate3d(0, 0, 1, 5deg);
394
+ transform: rotate3d(0, 0, 1, 5deg);
395
+ }
396
+
397
+ 80% {
398
+ -webkit-transform: rotate3d(0, 0, 1, -5deg);
399
+ transform: rotate3d(0, 0, 1, -5deg);
400
+ }
401
+
402
+ to {
403
+ -webkit-transform: rotate3d(0, 0, 1, 0deg);
404
+ transform: rotate3d(0, 0, 1, 0deg);
405
+ }
406
+ }
407
+
408
+ .swing {
409
+ -webkit-transform-origin: top center;
410
+ transform-origin: top center;
411
+ -webkit-animation-name: swing;
412
+ animation-name: swing;
413
+ }
414
+
415
+ @-webkit-keyframes tada {
416
+ from {
417
+ -webkit-transform: scale3d(1, 1, 1);
418
+ transform: scale3d(1, 1, 1);
419
+ }
420
+
421
+ 10%, 20% {
422
+ -webkit-transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
423
+ transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
424
+ }
425
+
426
+ 30%, 50%, 70%, 90% {
427
+ -webkit-transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
428
+ transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
429
+ }
430
+
431
+ 40%, 60%, 80% {
432
+ -webkit-transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
433
+ transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
434
+ }
435
+
436
+ to {
437
+ -webkit-transform: scale3d(1, 1, 1);
438
+ transform: scale3d(1, 1, 1);
439
+ }
440
+ }
441
+
442
+ @keyframes tada {
443
+ from {
444
+ -webkit-transform: scale3d(1, 1, 1);
445
+ transform: scale3d(1, 1, 1);
446
+ }
447
+
448
+ 10%, 20% {
449
+ -webkit-transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
450
+ transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
451
+ }
452
+
453
+ 30%, 50%, 70%, 90% {
454
+ -webkit-transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
455
+ transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
456
+ }
457
+
458
+ 40%, 60%, 80% {
459
+ -webkit-transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
460
+ transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
461
+ }
462
+
463
+ to {
464
+ -webkit-transform: scale3d(1, 1, 1);
465
+ transform: scale3d(1, 1, 1);
466
+ }
467
+ }
468
+
469
+ .tada {
470
+ -webkit-animation-name: tada;
471
+ animation-name: tada;
472
+ }
473
+
474
+ /* originally authored by Nick Pettit - https://github.com/nickpettit/glide */
475
+
476
+ @-webkit-keyframes wobble {
477
+ from {
478
+ -webkit-transform: none;
479
+ transform: none;
480
+ }
481
+
482
+ 15% {
483
+ -webkit-transform: translate3d(-25%, 0, 0) rotate3d(0, 0, 1, -5deg);
484
+ transform: translate3d(-25%, 0, 0) rotate3d(0, 0, 1, -5deg);
485
+ }
486
+
487
+ 30% {
488
+ -webkit-transform: translate3d(20%, 0, 0) rotate3d(0, 0, 1, 3deg);
489
+ transform: translate3d(20%, 0, 0) rotate3d(0, 0, 1, 3deg);
490
+ }
491
+
492
+ 45% {
493
+ -webkit-transform: translate3d(-15%, 0, 0) rotate3d(0, 0, 1, -3deg);
494
+ transform: translate3d(-15%, 0, 0) rotate3d(0, 0, 1, -3deg);
495
+ }
496
+
497
+ 60% {
498
+ -webkit-transform: translate3d(10%, 0, 0) rotate3d(0, 0, 1, 2deg);
499
+ transform: translate3d(10%, 0, 0) rotate3d(0, 0, 1, 2deg);
500
+ }
501
+
502
+ 75% {
503
+ -webkit-transform: translate3d(-5%, 0, 0) rotate3d(0, 0, 1, -1deg);
504
+ transform: translate3d(-5%, 0, 0) rotate3d(0, 0, 1, -1deg);
505
+ }
506
+
507
+ to {
508
+ -webkit-transform: none;
509
+ transform: none;
510
+ }
511
+ }
512
+
513
+ @keyframes wobble {
514
+ from {
515
+ -webkit-transform: none;
516
+ transform: none;
517
+ }
518
+
519
+ 15% {
520
+ -webkit-transform: translate3d(-25%, 0, 0) rotate3d(0, 0, 1, -5deg);
521
+ transform: translate3d(-25%, 0, 0) rotate3d(0, 0, 1, -5deg);
522
+ }
523
+
524
+ 30% {
525
+ -webkit-transform: translate3d(20%, 0, 0) rotate3d(0, 0, 1, 3deg);
526
+ transform: translate3d(20%, 0, 0) rotate3d(0, 0, 1, 3deg);
527
+ }
528
+
529
+ 45% {
530
+ -webkit-transform: translate3d(-15%, 0, 0) rotate3d(0, 0, 1, -3deg);
531
+ transform: translate3d(-15%, 0, 0) rotate3d(0, 0, 1, -3deg);
532
+ }
533
+
534
+ 60% {
535
+ -webkit-transform: translate3d(10%, 0, 0) rotate3d(0, 0, 1, 2deg);
536
+ transform: translate3d(10%, 0, 0) rotate3d(0, 0, 1, 2deg);
537
+ }
538
+
539
+ 75% {
540
+ -webkit-transform: translate3d(-5%, 0, 0) rotate3d(0, 0, 1, -1deg);
541
+ transform: translate3d(-5%, 0, 0) rotate3d(0, 0, 1, -1deg);
542
+ }
543
+
544
+ to {
545
+ -webkit-transform: none;
546
+ transform: none;
547
+ }
548
+ }
549
+
550
+ .wobble {
551
+ -webkit-animation-name: wobble;
552
+ animation-name: wobble;
553
+ }
554
+
555
+ @-webkit-keyframes jello {
556
+ from, 11.1%, to {
557
+ -webkit-transform: none;
558
+ transform: none;
559
+ }
560
+
561
+ 22.2% {
562
+ -webkit-transform: skewX(-12.5deg) skewY(-12.5deg);
563
+ transform: skewX(-12.5deg) skewY(-12.5deg);
564
+ }
565
+
566
+ 33.3% {
567
+ -webkit-transform: skewX(6.25deg) skewY(6.25deg);
568
+ transform: skewX(6.25deg) skewY(6.25deg);
569
+ }
570
+
571
+ 44.4% {
572
+ -webkit-transform: skewX(-3.125deg) skewY(-3.125deg);
573
+ transform: skewX(-3.125deg) skewY(-3.125deg);
574
+ }
575
+
576
+ 55.5% {
577
+ -webkit-transform: skewX(1.5625deg) skewY(1.5625deg);
578
+ transform: skewX(1.5625deg) skewY(1.5625deg);
579
+ }
580
+
581
+ 66.6% {
582
+ -webkit-transform: skewX(-0.78125deg) skewY(-0.78125deg);
583
+ transform: skewX(-0.78125deg) skewY(-0.78125deg);
584
+ }
585
+
586
+ 77.7% {
587
+ -webkit-transform: skewX(0.390625deg) skewY(0.390625deg);
588
+ transform: skewX(0.390625deg) skewY(0.390625deg);
589
+ }
590
+
591
+ 88.8% {
592
+ -webkit-transform: skewX(-0.1953125deg) skewY(-0.1953125deg);
593
+ transform: skewX(-0.1953125deg) skewY(-0.1953125deg);
594
+ }
595
+ }
596
+
597
+ @keyframes jello {
598
+ from, 11.1%, to {
599
+ -webkit-transform: none;
600
+ transform: none;
601
+ }
602
+
603
+ 22.2% {
604
+ -webkit-transform: skewX(-12.5deg) skewY(-12.5deg);
605
+ transform: skewX(-12.5deg) skewY(-12.5deg);
606
+ }
607
+
608
+ 33.3% {
609
+ -webkit-transform: skewX(6.25deg) skewY(6.25deg);
610
+ transform: skewX(6.25deg) skewY(6.25deg);
611
+ }
612
+
613
+ 44.4% {
614
+ -webkit-transform: skewX(-3.125deg) skewY(-3.125deg);
615
+ transform: skewX(-3.125deg) skewY(-3.125deg);
616
+ }
617
+
618
+ 55.5% {
619
+ -webkit-transform: skewX(1.5625deg) skewY(1.5625deg);
620
+ transform: skewX(1.5625deg) skewY(1.5625deg);
621
+ }
622
+
623
+ 66.6% {
624
+ -webkit-transform: skewX(-0.78125deg) skewY(-0.78125deg);
625
+ transform: skewX(-0.78125deg) skewY(-0.78125deg);
626
+ }
627
+
628
+ 77.7% {
629
+ -webkit-transform: skewX(0.390625deg) skewY(0.390625deg);
630
+ transform: skewX(0.390625deg) skewY(0.390625deg);
631
+ }
632
+
633
+ 88.8% {
634
+ -webkit-transform: skewX(-0.1953125deg) skewY(-0.1953125deg);
635
+ transform: skewX(-0.1953125deg) skewY(-0.1953125deg);
636
+ }
637
+ }
638
+
639
+ .jello {
640
+ -webkit-animation-name: jello;
641
+ animation-name: jello;
642
+ -webkit-transform-origin: center;
643
+ transform-origin: center;
644
+ }
645
+
646
+ @-webkit-keyframes bounceIn {
647
+ from, 20%, 40%, 60%, 80%, to {
648
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
649
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
650
+ }
651
+
652
+ 0% {
653
+ opacity: 0;
654
+ -webkit-transform: scale3d(.3, .3, .3);
655
+ transform: scale3d(.3, .3, .3);
656
+ }
657
+
658
+ 20% {
659
+ -webkit-transform: scale3d(1.1, 1.1, 1.1);
660
+ transform: scale3d(1.1, 1.1, 1.1);
661
+ }
662
+
663
+ 40% {
664
+ -webkit-transform: scale3d(.9, .9, .9);
665
+ transform: scale3d(.9, .9, .9);
666
+ }
667
+
668
+ 60% {
669
+ opacity: 1;
670
+ -webkit-transform: scale3d(1.03, 1.03, 1.03);
671
+ transform: scale3d(1.03, 1.03, 1.03);
672
+ }
673
+
674
+ 80% {
675
+ -webkit-transform: scale3d(.97, .97, .97);
676
+ transform: scale3d(.97, .97, .97);
677
+ }
678
+
679
+ to {
680
+ opacity: 1;
681
+ -webkit-transform: scale3d(1, 1, 1);
682
+ transform: scale3d(1, 1, 1);
683
+ }
684
+ }
685
+
686
+ @keyframes bounceIn {
687
+ from, 20%, 40%, 60%, 80%, to {
688
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
689
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
690
+ }
691
+
692
+ 0% {
693
+ opacity: 0;
694
+ -webkit-transform: scale3d(.3, .3, .3);
695
+ transform: scale3d(.3, .3, .3);
696
+ }
697
+
698
+ 20% {
699
+ -webkit-transform: scale3d(1.1, 1.1, 1.1);
700
+ transform: scale3d(1.1, 1.1, 1.1);
701
+ }
702
+
703
+ 40% {
704
+ -webkit-transform: scale3d(.9, .9, .9);
705
+ transform: scale3d(.9, .9, .9);
706
+ }
707
+
708
+ 60% {
709
+ opacity: 1;
710
+ -webkit-transform: scale3d(1.03, 1.03, 1.03);
711
+ transform: scale3d(1.03, 1.03, 1.03);
712
+ }
713
+
714
+ 80% {
715
+ -webkit-transform: scale3d(.97, .97, .97);
716
+ transform: scale3d(.97, .97, .97);
717
+ }
718
+
719
+ to {
720
+ opacity: 1;
721
+ -webkit-transform: scale3d(1, 1, 1);
722
+ transform: scale3d(1, 1, 1);
723
+ }
724
+ }
725
+
726
+ .bounceIn {
727
+ -webkit-animation-name: bounceIn;
728
+ animation-name: bounceIn;
729
+ }
730
+
731
+ @-webkit-keyframes bounceInDown {
732
+ from, 60%, 75%, 90%, to {
733
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
734
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
735
+ }
736
+
737
+ 0% {
738
+ opacity: 0;
739
+ -webkit-transform: translate3d(0, -3000px, 0);
740
+ transform: translate3d(0, -3000px, 0);
741
+ }
742
+
743
+ 60% {
744
+ opacity: 1;
745
+ -webkit-transform: translate3d(0, 25px, 0);
746
+ transform: translate3d(0, 25px, 0);
747
+ }
748
+
749
+ 75% {
750
+ -webkit-transform: translate3d(0, -10px, 0);
751
+ transform: translate3d(0, -10px, 0);
752
+ }
753
+
754
+ 90% {
755
+ -webkit-transform: translate3d(0, 5px, 0);
756
+ transform: translate3d(0, 5px, 0);
757
+ }
758
+
759
+ to {
760
+ -webkit-transform: none;
761
+ transform: none;
762
+ }
763
+ }
764
+
765
+ @keyframes bounceInDown {
766
+ from, 60%, 75%, 90%, to {
767
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
768
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
769
+ }
770
+
771
+ 0% {
772
+ opacity: 0;
773
+ -webkit-transform: translate3d(0, -3000px, 0);
774
+ transform: translate3d(0, -3000px, 0);
775
+ }
776
+
777
+ 60% {
778
+ opacity: 1;
779
+ -webkit-transform: translate3d(0, 25px, 0);
780
+ transform: translate3d(0, 25px, 0);
781
+ }
782
+
783
+ 75% {
784
+ -webkit-transform: translate3d(0, -10px, 0);
785
+ transform: translate3d(0, -10px, 0);
786
+ }
787
+
788
+ 90% {
789
+ -webkit-transform: translate3d(0, 5px, 0);
790
+ transform: translate3d(0, 5px, 0);
791
+ }
792
+
793
+ to {
794
+ -webkit-transform: none;
795
+ transform: none;
796
+ }
797
+ }
798
+
799
+ .bounceInDown {
800
+ -webkit-animation-name: bounceInDown;
801
+ animation-name: bounceInDown;
802
+ }
803
+
804
+ @-webkit-keyframes bounceInLeft {
805
+ from, 60%, 75%, 90%, to {
806
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
807
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
808
+ }
809
+
810
+ 0% {
811
+ opacity: 0;
812
+ -webkit-transform: translate3d(-3000px, 0, 0);
813
+ transform: translate3d(-3000px, 0, 0);
814
+ }
815
+
816
+ 60% {
817
+ opacity: 1;
818
+ -webkit-transform: translate3d(25px, 0, 0);
819
+ transform: translate3d(25px, 0, 0);
820
+ }
821
+
822
+ 75% {
823
+ -webkit-transform: translate3d(-10px, 0, 0);
824
+ transform: translate3d(-10px, 0, 0);
825
+ }
826
+
827
+ 90% {
828
+ -webkit-transform: translate3d(5px, 0, 0);
829
+ transform: translate3d(5px, 0, 0);
830
+ }
831
+
832
+ to {
833
+ -webkit-transform: none;
834
+ transform: none;
835
+ }
836
+ }
837
+
838
+ @keyframes bounceInLeft {
839
+ from, 60%, 75%, 90%, to {
840
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
841
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
842
+ }
843
+
844
+ 0% {
845
+ opacity: 0;
846
+ -webkit-transform: translate3d(-3000px, 0, 0);
847
+ transform: translate3d(-3000px, 0, 0);
848
+ }
849
+
850
+ 60% {
851
+ opacity: 1;
852
+ -webkit-transform: translate3d(25px, 0, 0);
853
+ transform: translate3d(25px, 0, 0);
854
+ }
855
+
856
+ 75% {
857
+ -webkit-transform: translate3d(-10px, 0, 0);
858
+ transform: translate3d(-10px, 0, 0);
859
+ }
860
+
861
+ 90% {
862
+ -webkit-transform: translate3d(5px, 0, 0);
863
+ transform: translate3d(5px, 0, 0);
864
+ }
865
+
866
+ to {
867
+ -webkit-transform: none;
868
+ transform: none;
869
+ }
870
+ }
871
+
872
+ .bounceInLeft {
873
+ -webkit-animation-name: bounceInLeft;
874
+ animation-name: bounceInLeft;
875
+ }
876
+
877
+ @-webkit-keyframes bounceInRight {
878
+ from, 60%, 75%, 90%, to {
879
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
880
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
881
+ }
882
+
883
+ from {
884
+ opacity: 0;
885
+ -webkit-transform: translate3d(3000px, 0, 0);
886
+ transform: translate3d(3000px, 0, 0);
887
+ }
888
+
889
+ 60% {
890
+ opacity: 1;
891
+ -webkit-transform: translate3d(-25px, 0, 0);
892
+ transform: translate3d(-25px, 0, 0);
893
+ }
894
+
895
+ 75% {
896
+ -webkit-transform: translate3d(10px, 0, 0);
897
+ transform: translate3d(10px, 0, 0);
898
+ }
899
+
900
+ 90% {
901
+ -webkit-transform: translate3d(-5px, 0, 0);
902
+ transform: translate3d(-5px, 0, 0);
903
+ }
904
+
905
+ to {
906
+ -webkit-transform: none;
907
+ transform: none;
908
+ }
909
+ }
910
+
911
+ @keyframes bounceInRight {
912
+ from, 60%, 75%, 90%, to {
913
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
914
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
915
+ }
916
+
917
+ from {
918
+ opacity: 0;
919
+ -webkit-transform: translate3d(3000px, 0, 0);
920
+ transform: translate3d(3000px, 0, 0);
921
+ }
922
+
923
+ 60% {
924
+ opacity: 1;
925
+ -webkit-transform: translate3d(-25px, 0, 0);
926
+ transform: translate3d(-25px, 0, 0);
927
+ }
928
+
929
+ 75% {
930
+ -webkit-transform: translate3d(10px, 0, 0);
931
+ transform: translate3d(10px, 0, 0);
932
+ }
933
+
934
+ 90% {
935
+ -webkit-transform: translate3d(-5px, 0, 0);
936
+ transform: translate3d(-5px, 0, 0);
937
+ }
938
+
939
+ to {
940
+ -webkit-transform: none;
941
+ transform: none;
942
+ }
943
+ }
944
+
945
+ .bounceInRight {
946
+ -webkit-animation-name: bounceInRight;
947
+ animation-name: bounceInRight;
948
+ }
949
+
950
+ @-webkit-keyframes bounceInUp {
951
+ from, 60%, 75%, 90%, to {
952
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
953
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
954
+ }
955
+
956
+ from {
957
+ opacity: 0;
958
+ -webkit-transform: translate3d(0, 3000px, 0);
959
+ transform: translate3d(0, 3000px, 0);
960
+ }
961
+
962
+ 60% {
963
+ opacity: 1;
964
+ -webkit-transform: translate3d(0, -20px, 0);
965
+ transform: translate3d(0, -20px, 0);
966
+ }
967
+
968
+ 75% {
969
+ -webkit-transform: translate3d(0, 10px, 0);
970
+ transform: translate3d(0, 10px, 0);
971
+ }
972
+
973
+ 90% {
974
+ -webkit-transform: translate3d(0, -5px, 0);
975
+ transform: translate3d(0, -5px, 0);
976
+ }
977
+
978
+ to {
979
+ -webkit-transform: translate3d(0, 0, 0);
980
+ transform: translate3d(0, 0, 0);
981
+ }
982
+ }
983
+
984
+ @keyframes bounceInUp {
985
+ from, 60%, 75%, 90%, to {
986
+ -webkit-animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
987
+ animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
988
+ }
989
+
990
+ from {
991
+ opacity: 0;
992
+ -webkit-transform: translate3d(0, 3000px, 0);
993
+ transform: translate3d(0, 3000px, 0);
994
+ }
995
+
996
+ 60% {
997
+ opacity: 1;
998
+ -webkit-transform: translate3d(0, -20px, 0);
999
+ transform: translate3d(0, -20px, 0);
1000
+ }
1001
+
1002
+ 75% {
1003
+ -webkit-transform: translate3d(0, 10px, 0);
1004
+ transform: translate3d(0, 10px, 0);
1005
+ }
1006
+
1007
+ 90% {
1008
+ -webkit-transform: translate3d(0, -5px, 0);
1009
+ transform: translate3d(0, -5px, 0);
1010
+ }
1011
+
1012
+ to {
1013
+ -webkit-transform: translate3d(0, 0, 0);
1014
+ transform: translate3d(0, 0, 0);
1015
+ }
1016
+ }
1017
+
1018
+ .bounceInUp {
1019
+ -webkit-animation-name: bounceInUp;
1020
+ animation-name: bounceInUp;
1021
+ }
1022
+
1023
+ @-webkit-keyframes bounceOut {
1024
+ 20% {
1025
+ -webkit-transform: scale3d(.9, .9, .9);
1026
+ transform: scale3d(.9, .9, .9);
1027
+ }
1028
+
1029
+ 50%, 55% {
1030
+ opacity: 1;
1031
+ -webkit-transform: scale3d(1.1, 1.1, 1.1);
1032
+ transform: scale3d(1.1, 1.1, 1.1);
1033
+ }
1034
+
1035
+ to {
1036
+ opacity: 0;
1037
+ -webkit-transform: scale3d(.3, .3, .3);
1038
+ transform: scale3d(.3, .3, .3);
1039
+ }
1040
+ }
1041
+
1042
+ @keyframes bounceOut {
1043
+ 20% {
1044
+ -webkit-transform: scale3d(.9, .9, .9);
1045
+ transform: scale3d(.9, .9, .9);
1046
+ }
1047
+
1048
+ 50%, 55% {
1049
+ opacity: 1;
1050
+ -webkit-transform: scale3d(1.1, 1.1, 1.1);
1051
+ transform: scale3d(1.1, 1.1, 1.1);
1052
+ }
1053
+
1054
+ to {
1055
+ opacity: 0;
1056
+ -webkit-transform: scale3d(.3, .3, .3);
1057
+ transform: scale3d(.3, .3, .3);
1058
+ }
1059
+ }
1060
+
1061
+ .bounceOut {
1062
+ -webkit-animation-name: bounceOut;
1063
+ animation-name: bounceOut;
1064
+ }
1065
+
1066
+ @-webkit-keyframes bounceOutDown {
1067
+ 20% {
1068
+ -webkit-transform: translate3d(0, 10px, 0);
1069
+ transform: translate3d(0, 10px, 0);
1070
+ }
1071
+
1072
+ 40%, 45% {
1073
+ opacity: 1;
1074
+ -webkit-transform: translate3d(0, -20px, 0);
1075
+ transform: translate3d(0, -20px, 0);
1076
+ }
1077
+
1078
+ to {
1079
+ opacity: 0;
1080
+ -webkit-transform: translate3d(0, 2000px, 0);
1081
+ transform: translate3d(0, 2000px, 0);
1082
+ }
1083
+ }
1084
+
1085
+ @keyframes bounceOutDown {
1086
+ 20% {
1087
+ -webkit-transform: translate3d(0, 10px, 0);
1088
+ transform: translate3d(0, 10px, 0);
1089
+ }
1090
+
1091
+ 40%, 45% {
1092
+ opacity: 1;
1093
+ -webkit-transform: translate3d(0, -20px, 0);
1094
+ transform: translate3d(0, -20px, 0);
1095
+ }
1096
+
1097
+ to {
1098
+ opacity: 0;
1099
+ -webkit-transform: translate3d(0, 2000px, 0);
1100
+ transform: translate3d(0, 2000px, 0);
1101
+ }
1102
+ }
1103
+
1104
+ .bounceOutDown {
1105
+ -webkit-animation-name: bounceOutDown;
1106
+ animation-name: bounceOutDown;
1107
+ }
1108
+
1109
+ @-webkit-keyframes bounceOutLeft {
1110
+ 20% {
1111
+ opacity: 1;
1112
+ -webkit-transform: translate3d(20px, 0, 0);
1113
+ transform: translate3d(20px, 0, 0);
1114
+ }
1115
+
1116
+ to {
1117
+ opacity: 0;
1118
+ -webkit-transform: translate3d(-2000px, 0, 0);
1119
+ transform: translate3d(-2000px, 0, 0);
1120
+ }
1121
+ }
1122
+
1123
+ @keyframes bounceOutLeft {
1124
+ 20% {
1125
+ opacity: 1;
1126
+ -webkit-transform: translate3d(20px, 0, 0);
1127
+ transform: translate3d(20px, 0, 0);
1128
+ }
1129
+
1130
+ to {
1131
+ opacity: 0;
1132
+ -webkit-transform: translate3d(-2000px, 0, 0);
1133
+ transform: translate3d(-2000px, 0, 0);
1134
+ }
1135
+ }
1136
+
1137
+ .bounceOutLeft {
1138
+ -webkit-animation-name: bounceOutLeft;
1139
+ animation-name: bounceOutLeft;
1140
+ }
1141
+
1142
+ @-webkit-keyframes bounceOutRight {
1143
+ 20% {
1144
+ opacity: 1;
1145
+ -webkit-transform: translate3d(-20px, 0, 0);
1146
+ transform: translate3d(-20px, 0, 0);
1147
+ }
1148
+
1149
+ to {
1150
+ opacity: 0;
1151
+ -webkit-transform: translate3d(2000px, 0, 0);
1152
+ transform: translate3d(2000px, 0, 0);
1153
+ }
1154
+ }
1155
+
1156
+ @keyframes bounceOutRight {
1157
+ 20% {
1158
+ opacity: 1;
1159
+ -webkit-transform: translate3d(-20px, 0, 0);
1160
+ transform: translate3d(-20px, 0, 0);
1161
+ }
1162
+
1163
+ to {
1164
+ opacity: 0;
1165
+ -webkit-transform: translate3d(2000px, 0, 0);
1166
+ transform: translate3d(2000px, 0, 0);
1167
+ }
1168
+ }
1169
+
1170
+ .bounceOutRight {
1171
+ -webkit-animation-name: bounceOutRight;
1172
+ animation-name: bounceOutRight;
1173
+ }
1174
+
1175
+ @-webkit-keyframes bounceOutUp {
1176
+ 20% {
1177
+ -webkit-transform: translate3d(0, -10px, 0);
1178
+ transform: translate3d(0, -10px, 0);
1179
+ }
1180
+
1181
+ 40%, 45% {
1182
+ opacity: 1;
1183
+ -webkit-transform: translate3d(0, 20px, 0);
1184
+ transform: translate3d(0, 20px, 0);
1185
+ }
1186
+
1187
+ to {
1188
+ opacity: 0;
1189
+ -webkit-transform: translate3d(0, -2000px, 0);
1190
+ transform: translate3d(0, -2000px, 0);
1191
+ }
1192
+ }
1193
+
1194
+ @keyframes bounceOutUp {
1195
+ 20% {
1196
+ -webkit-transform: translate3d(0, -10px, 0);
1197
+ transform: translate3d(0, -10px, 0);
1198
+ }
1199
+
1200
+ 40%, 45% {
1201
+ opacity: 1;
1202
+ -webkit-transform: translate3d(0, 20px, 0);
1203
+ transform: translate3d(0, 20px, 0);
1204
+ }
1205
+
1206
+ to {
1207
+ opacity: 0;
1208
+ -webkit-transform: translate3d(0, -2000px, 0);
1209
+ transform: translate3d(0, -2000px, 0);
1210
+ }
1211
+ }
1212
+
1213
+ .bounceOutUp {
1214
+ -webkit-animation-name: bounceOutUp;
1215
+ animation-name: bounceOutUp;
1216
+ }
1217
+
1218
+ @-webkit-keyframes fadeIn {
1219
+ from {
1220
+ opacity: 0;
1221
+ }
1222
+
1223
+ to {
1224
+ opacity: 1;
1225
+ }
1226
+ }
1227
+
1228
+ @keyframes fadeIn {
1229
+ from {
1230
+ opacity: 0;
1231
+ }
1232
+
1233
+ to {
1234
+ opacity: 1;
1235
+ }
1236
+ }
1237
+
1238
+ .fadeIn {
1239
+ -webkit-animation-name: fadeIn;
1240
+ animation-name: fadeIn;
1241
+ }
1242
+
1243
+ @-webkit-keyframes fadeInDown {
1244
+ from {
1245
+ opacity: 0;
1246
+ -webkit-transform: translate3d(0, -100%, 0);
1247
+ transform: translate3d(0, -100%, 0);
1248
+ }
1249
+
1250
+ to {
1251
+ opacity: 1;
1252
+ -webkit-transform: none;
1253
+ transform: none;
1254
+ }
1255
+ }
1256
+
1257
+ @keyframes fadeInDown {
1258
+ from {
1259
+ opacity: 0;
1260
+ -webkit-transform: translate3d(0, -100%, 0);
1261
+ transform: translate3d(0, -100%, 0);
1262
+ }
1263
+
1264
+ to {
1265
+ opacity: 1;
1266
+ -webkit-transform: none;
1267
+ transform: none;
1268
+ }
1269
+ }
1270
+
1271
+ .fadeInDown {
1272
+ -webkit-animation-name: fadeInDown;
1273
+ animation-name: fadeInDown;
1274
+ }
1275
+
1276
+ @-webkit-keyframes fadeInDownBig {
1277
+ from {
1278
+ opacity: 0;
1279
+ -webkit-transform: translate3d(0, -2000px, 0);
1280
+ transform: translate3d(0, -2000px, 0);
1281
+ }
1282
+
1283
+ to {
1284
+ opacity: 1;
1285
+ -webkit-transform: none;
1286
+ transform: none;
1287
+ }
1288
+ }
1289
+
1290
+ @keyframes fadeInDownBig {
1291
+ from {
1292
+ opacity: 0;
1293
+ -webkit-transform: translate3d(0, -2000px, 0);
1294
+ transform: translate3d(0, -2000px, 0);
1295
+ }
1296
+
1297
+ to {
1298
+ opacity: 1;
1299
+ -webkit-transform: none;
1300
+ transform: none;
1301
+ }
1302
+ }
1303
+
1304
+ .fadeInDownBig {
1305
+ -webkit-animation-name: fadeInDownBig;
1306
+ animation-name: fadeInDownBig;
1307
+ }
1308
+
1309
+ @-webkit-keyframes fadeInLeft {
1310
+ from {
1311
+ opacity: 0;
1312
+ -webkit-transform: translate3d(-100%, 0, 0);
1313
+ transform: translate3d(-100%, 0, 0);
1314
+ }
1315
+
1316
+ to {
1317
+ opacity: 1;
1318
+ -webkit-transform: none;
1319
+ transform: none;
1320
+ }
1321
+ }
1322
+
1323
+ @keyframes fadeInLeft {
1324
+ from {
1325
+ opacity: 0;
1326
+ -webkit-transform: translate3d(-100%, 0, 0);
1327
+ transform: translate3d(-100%, 0, 0);
1328
+ }
1329
+
1330
+ to {
1331
+ opacity: 1;
1332
+ -webkit-transform: none;
1333
+ transform: none;
1334
+ }
1335
+ }
1336
+
1337
+ .fadeInLeft {
1338
+ -webkit-animation-name: fadeInLeft;
1339
+ animation-name: fadeInLeft;
1340
+ }
1341
+
1342
+ @-webkit-keyframes fadeInLeftBig {
1343
+ from {
1344
+ opacity: 0;
1345
+ -webkit-transform: translate3d(-2000px, 0, 0);
1346
+ transform: translate3d(-2000px, 0, 0);
1347
+ }
1348
+
1349
+ to {
1350
+ opacity: 1;
1351
+ -webkit-transform: none;
1352
+ transform: none;
1353
+ }
1354
+ }
1355
+
1356
+ @keyframes fadeInLeftBig {
1357
+ from {
1358
+ opacity: 0;
1359
+ -webkit-transform: translate3d(-2000px, 0, 0);
1360
+ transform: translate3d(-2000px, 0, 0);
1361
+ }
1362
+
1363
+ to {
1364
+ opacity: 1;
1365
+ -webkit-transform: none;
1366
+ transform: none;
1367
+ }
1368
+ }
1369
+
1370
+ .fadeInLeftBig {
1371
+ -webkit-animation-name: fadeInLeftBig;
1372
+ animation-name: fadeInLeftBig;
1373
+ }
1374
+
1375
+ @-webkit-keyframes fadeInRight {
1376
+ from {
1377
+ opacity: 0;
1378
+ -webkit-transform: translate3d(100%, 0, 0);
1379
+ transform: translate3d(100%, 0, 0);
1380
+ }
1381
+
1382
+ to {
1383
+ opacity: 1;
1384
+ -webkit-transform: none;
1385
+ transform: none;
1386
+ }
1387
+ }
1388
+
1389
+ @keyframes fadeInRight {
1390
+ from {
1391
+ opacity: 0;
1392
+ -webkit-transform: translate3d(100%, 0, 0);
1393
+ transform: translate3d(100%, 0, 0);
1394
+ }
1395
+
1396
+ to {
1397
+ opacity: 1;
1398
+ -webkit-transform: none;
1399
+ transform: none;
1400
+ }
1401
+ }
1402
+
1403
+ .fadeInRight {
1404
+ -webkit-animation-name: fadeInRight;
1405
+ animation-name: fadeInRight;
1406
+ }
1407
+
1408
+ @-webkit-keyframes fadeInRightBig {
1409
+ from {
1410
+ opacity: 0;
1411
+ -webkit-transform: translate3d(2000px, 0, 0);
1412
+ transform: translate3d(2000px, 0, 0);
1413
+ }
1414
+
1415
+ to {
1416
+ opacity: 1;
1417
+ -webkit-transform: none;
1418
+ transform: none;
1419
+ }
1420
+ }
1421
+
1422
+ @keyframes fadeInRightBig {
1423
+ from {
1424
+ opacity: 0;
1425
+ -webkit-transform: translate3d(2000px, 0, 0);
1426
+ transform: translate3d(2000px, 0, 0);
1427
+ }
1428
+
1429
+ to {
1430
+ opacity: 1;
1431
+ -webkit-transform: none;
1432
+ transform: none;
1433
+ }
1434
+ }
1435
+
1436
+ .fadeInRightBig {
1437
+ -webkit-animation-name: fadeInRightBig;
1438
+ animation-name: fadeInRightBig;
1439
+ }
1440
+
1441
+ @-webkit-keyframes fadeInUp {
1442
+ from {
1443
+ opacity: 0;
1444
+ -webkit-transform: translate3d(0, 100%, 0);
1445
+ transform: translate3d(0, 100%, 0);
1446
+ }
1447
+
1448
+ to {
1449
+ opacity: 1;
1450
+ -webkit-transform: none;
1451
+ transform: none;
1452
+ }
1453
+ }
1454
+
1455
+ @keyframes fadeInUp {
1456
+ from {
1457
+ opacity: 0;
1458
+ -webkit-transform: translate3d(0, 100%, 0);
1459
+ transform: translate3d(0, 100%, 0);
1460
+ }
1461
+
1462
+ to {
1463
+ opacity: 1;
1464
+ -webkit-transform: none;
1465
+ transform: none;
1466
+ }
1467
+ }
1468
+
1469
+ .fadeInUp {
1470
+ -webkit-animation-name: fadeInUp;
1471
+ animation-name: fadeInUp;
1472
+ }
1473
+
1474
+ @-webkit-keyframes fadeInUpBig {
1475
+ from {
1476
+ opacity: 0;
1477
+ -webkit-transform: translate3d(0, 2000px, 0);
1478
+ transform: translate3d(0, 2000px, 0);
1479
+ }
1480
+
1481
+ to {
1482
+ opacity: 1;
1483
+ -webkit-transform: none;
1484
+ transform: none;
1485
+ }
1486
+ }
1487
+
1488
+ @keyframes fadeInUpBig {
1489
+ from {
1490
+ opacity: 0;
1491
+ -webkit-transform: translate3d(0, 2000px, 0);
1492
+ transform: translate3d(0, 2000px, 0);
1493
+ }
1494
+
1495
+ to {
1496
+ opacity: 1;
1497
+ -webkit-transform: none;
1498
+ transform: none;
1499
+ }
1500
+ }
1501
+
1502
+ .fadeInUpBig {
1503
+ -webkit-animation-name: fadeInUpBig;
1504
+ animation-name: fadeInUpBig;
1505
+ }
1506
+
1507
+ @-webkit-keyframes fadeOut {
1508
+ from {
1509
+ opacity: 1;
1510
+ }
1511
+
1512
+ to {
1513
+ opacity: 0;
1514
+ }
1515
+ }
1516
+
1517
+ @keyframes fadeOut {
1518
+ from {
1519
+ opacity: 1;
1520
+ }
1521
+
1522
+ to {
1523
+ opacity: 0;
1524
+ }
1525
+ }
1526
+
1527
+ .fadeOut {
1528
+ -webkit-animation-name: fadeOut;
1529
+ animation-name: fadeOut;
1530
+ }
1531
+
1532
+ @-webkit-keyframes fadeOutDown {
1533
+ from {
1534
+ opacity: 1;
1535
+ }
1536
+
1537
+ to {
1538
+ opacity: 0;
1539
+ -webkit-transform: translate3d(0, 100%, 0);
1540
+ transform: translate3d(0, 100%, 0);
1541
+ }
1542
+ }
1543
+
1544
+ @keyframes fadeOutDown {
1545
+ from {
1546
+ opacity: 1;
1547
+ }
1548
+
1549
+ to {
1550
+ opacity: 0;
1551
+ -webkit-transform: translate3d(0, 100%, 0);
1552
+ transform: translate3d(0, 100%, 0);
1553
+ }
1554
+ }
1555
+
1556
+ .fadeOutDown {
1557
+ -webkit-animation-name: fadeOutDown;
1558
+ animation-name: fadeOutDown;
1559
+ }
1560
+
1561
+ @-webkit-keyframes fadeOutDownBig {
1562
+ from {
1563
+ opacity: 1;
1564
+ }
1565
+
1566
+ to {
1567
+ opacity: 0;
1568
+ -webkit-transform: translate3d(0, 2000px, 0);
1569
+ transform: translate3d(0, 2000px, 0);
1570
+ }
1571
+ }
1572
+
1573
+ @keyframes fadeOutDownBig {
1574
+ from {
1575
+ opacity: 1;
1576
+ }
1577
+
1578
+ to {
1579
+ opacity: 0;
1580
+ -webkit-transform: translate3d(0, 2000px, 0);
1581
+ transform: translate3d(0, 2000px, 0);
1582
+ }
1583
+ }
1584
+
1585
+ .fadeOutDownBig {
1586
+ -webkit-animation-name: fadeOutDownBig;
1587
+ animation-name: fadeOutDownBig;
1588
+ }
1589
+
1590
+ @-webkit-keyframes fadeOutLeft {
1591
+ from {
1592
+ opacity: 1;
1593
+ }
1594
+
1595
+ to {
1596
+ opacity: 0;
1597
+ -webkit-transform: translate3d(-100%, 0, 0);
1598
+ transform: translate3d(-100%, 0, 0);
1599
+ }
1600
+ }
1601
+
1602
+ @keyframes fadeOutLeft {
1603
+ from {
1604
+ opacity: 1;
1605
+ }
1606
+
1607
+ to {
1608
+ opacity: 0;
1609
+ -webkit-transform: translate3d(-100%, 0, 0);
1610
+ transform: translate3d(-100%, 0, 0);
1611
+ }
1612
+ }
1613
+
1614
+ .fadeOutLeft {
1615
+ -webkit-animation-name: fadeOutLeft;
1616
+ animation-name: fadeOutLeft;
1617
+ }
1618
+
1619
+ @-webkit-keyframes fadeOutLeftBig {
1620
+ from {
1621
+ opacity: 1;
1622
+ }
1623
+
1624
+ to {
1625
+ opacity: 0;
1626
+ -webkit-transform: translate3d(-2000px, 0, 0);
1627
+ transform: translate3d(-2000px, 0, 0);
1628
+ }
1629
+ }
1630
+
1631
+ @keyframes fadeOutLeftBig {
1632
+ from {
1633
+ opacity: 1;
1634
+ }
1635
+
1636
+ to {
1637
+ opacity: 0;
1638
+ -webkit-transform: translate3d(-2000px, 0, 0);
1639
+ transform: translate3d(-2000px, 0, 0);
1640
+ }
1641
+ }
1642
+
1643
+ .fadeOutLeftBig {
1644
+ -webkit-animation-name: fadeOutLeftBig;
1645
+ animation-name: fadeOutLeftBig;
1646
+ }
1647
+
1648
+ @-webkit-keyframes fadeOutRight {
1649
+ from {
1650
+ opacity: 1;
1651
+ }
1652
+
1653
+ to {
1654
+ opacity: 0;
1655
+ -webkit-transform: translate3d(100%, 0, 0);
1656
+ transform: translate3d(100%, 0, 0);
1657
+ }
1658
+ }
1659
+
1660
+ @keyframes fadeOutRight {
1661
+ from {
1662
+ opacity: 1;
1663
+ }
1664
+
1665
+ to {
1666
+ opacity: 0;
1667
+ -webkit-transform: translate3d(100%, 0, 0);
1668
+ transform: translate3d(100%, 0, 0);
1669
+ }
1670
+ }
1671
+
1672
+ .fadeOutRight {
1673
+ -webkit-animation-name: fadeOutRight;
1674
+ animation-name: fadeOutRight;
1675
+ }
1676
+
1677
+ @-webkit-keyframes fadeOutRightBig {
1678
+ from {
1679
+ opacity: 1;
1680
+ }
1681
+
1682
+ to {
1683
+ opacity: 0;
1684
+ -webkit-transform: translate3d(2000px, 0, 0);
1685
+ transform: translate3d(2000px, 0, 0);
1686
+ }
1687
+ }
1688
+
1689
+ @keyframes fadeOutRightBig {
1690
+ from {
1691
+ opacity: 1;
1692
+ }
1693
+
1694
+ to {
1695
+ opacity: 0;
1696
+ -webkit-transform: translate3d(2000px, 0, 0);
1697
+ transform: translate3d(2000px, 0, 0);
1698
+ }
1699
+ }
1700
+
1701
+ .fadeOutRightBig {
1702
+ -webkit-animation-name: fadeOutRightBig;
1703
+ animation-name: fadeOutRightBig;
1704
+ }
1705
+
1706
+ @-webkit-keyframes fadeOutUp {
1707
+ from {
1708
+ opacity: 1;
1709
+ }
1710
+
1711
+ to {
1712
+ opacity: 0;
1713
+ -webkit-transform: translate3d(0, -100%, 0);
1714
+ transform: translate3d(0, -100%, 0);
1715
+ }
1716
+ }
1717
+
1718
+ @keyframes fadeOutUp {
1719
+ from {
1720
+ opacity: 1;
1721
+ }
1722
+
1723
+ to {
1724
+ opacity: 0;
1725
+ -webkit-transform: translate3d(0, -100%, 0);
1726
+ transform: translate3d(0, -100%, 0);
1727
+ }
1728
+ }
1729
+
1730
+ .fadeOutUp {
1731
+ -webkit-animation-name: fadeOutUp;
1732
+ animation-name: fadeOutUp;
1733
+ }
1734
+
1735
+ @-webkit-keyframes fadeOutUpBig {
1736
+ from {
1737
+ opacity: 1;
1738
+ }
1739
+
1740
+ to {
1741
+ opacity: 0;
1742
+ -webkit-transform: translate3d(0, -2000px, 0);
1743
+ transform: translate3d(0, -2000px, 0);
1744
+ }
1745
+ }
1746
+
1747
+ @keyframes fadeOutUpBig {
1748
+ from {
1749
+ opacity: 1;
1750
+ }
1751
+
1752
+ to {
1753
+ opacity: 0;
1754
+ -webkit-transform: translate3d(0, -2000px, 0);
1755
+ transform: translate3d(0, -2000px, 0);
1756
+ }
1757
+ }
1758
+
1759
+ .fadeOutUpBig {
1760
+ -webkit-animation-name: fadeOutUpBig;
1761
+ animation-name: fadeOutUpBig;
1762
+ }
1763
+
1764
+ @-webkit-keyframes flip {
1765
+ from {
1766
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, -360deg);
1767
+ transform: perspective(400px) rotate3d(0, 1, 0, -360deg);
1768
+ -webkit-animation-timing-function: ease-out;
1769
+ animation-timing-function: ease-out;
1770
+ }
1771
+
1772
+ 40% {
1773
+ -webkit-transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -190deg);
1774
+ transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -190deg);
1775
+ -webkit-animation-timing-function: ease-out;
1776
+ animation-timing-function: ease-out;
1777
+ }
1778
+
1779
+ 50% {
1780
+ -webkit-transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -170deg);
1781
+ transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -170deg);
1782
+ -webkit-animation-timing-function: ease-in;
1783
+ animation-timing-function: ease-in;
1784
+ }
1785
+
1786
+ 80% {
1787
+ -webkit-transform: perspective(400px) scale3d(.95, .95, .95);
1788
+ transform: perspective(400px) scale3d(.95, .95, .95);
1789
+ -webkit-animation-timing-function: ease-in;
1790
+ animation-timing-function: ease-in;
1791
+ }
1792
+
1793
+ to {
1794
+ -webkit-transform: perspective(400px);
1795
+ transform: perspective(400px);
1796
+ -webkit-animation-timing-function: ease-in;
1797
+ animation-timing-function: ease-in;
1798
+ }
1799
+ }
1800
+
1801
+ @keyframes flip {
1802
+ from {
1803
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, -360deg);
1804
+ transform: perspective(400px) rotate3d(0, 1, 0, -360deg);
1805
+ -webkit-animation-timing-function: ease-out;
1806
+ animation-timing-function: ease-out;
1807
+ }
1808
+
1809
+ 40% {
1810
+ -webkit-transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -190deg);
1811
+ transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -190deg);
1812
+ -webkit-animation-timing-function: ease-out;
1813
+ animation-timing-function: ease-out;
1814
+ }
1815
+
1816
+ 50% {
1817
+ -webkit-transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -170deg);
1818
+ transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -170deg);
1819
+ -webkit-animation-timing-function: ease-in;
1820
+ animation-timing-function: ease-in;
1821
+ }
1822
+
1823
+ 80% {
1824
+ -webkit-transform: perspective(400px) scale3d(.95, .95, .95);
1825
+ transform: perspective(400px) scale3d(.95, .95, .95);
1826
+ -webkit-animation-timing-function: ease-in;
1827
+ animation-timing-function: ease-in;
1828
+ }
1829
+
1830
+ to {
1831
+ -webkit-transform: perspective(400px);
1832
+ transform: perspective(400px);
1833
+ -webkit-animation-timing-function: ease-in;
1834
+ animation-timing-function: ease-in;
1835
+ }
1836
+ }
1837
+
1838
+ .animated.flip {
1839
+ -webkit-backface-visibility: visible;
1840
+ backface-visibility: visible;
1841
+ -webkit-animation-name: flip;
1842
+ animation-name: flip;
1843
+ }
1844
+
1845
+ @-webkit-keyframes flipInX {
1846
+ from {
1847
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
1848
+ transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
1849
+ -webkit-animation-timing-function: ease-in;
1850
+ animation-timing-function: ease-in;
1851
+ opacity: 0;
1852
+ }
1853
+
1854
+ 40% {
1855
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
1856
+ transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
1857
+ -webkit-animation-timing-function: ease-in;
1858
+ animation-timing-function: ease-in;
1859
+ }
1860
+
1861
+ 60% {
1862
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, 10deg);
1863
+ transform: perspective(400px) rotate3d(1, 0, 0, 10deg);
1864
+ opacity: 1;
1865
+ }
1866
+
1867
+ 80% {
1868
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, -5deg);
1869
+ transform: perspective(400px) rotate3d(1, 0, 0, -5deg);
1870
+ }
1871
+
1872
+ to {
1873
+ -webkit-transform: perspective(400px);
1874
+ transform: perspective(400px);
1875
+ }
1876
+ }
1877
+
1878
+ @keyframes flipInX {
1879
+ from {
1880
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
1881
+ transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
1882
+ -webkit-animation-timing-function: ease-in;
1883
+ animation-timing-function: ease-in;
1884
+ opacity: 0;
1885
+ }
1886
+
1887
+ 40% {
1888
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
1889
+ transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
1890
+ -webkit-animation-timing-function: ease-in;
1891
+ animation-timing-function: ease-in;
1892
+ }
1893
+
1894
+ 60% {
1895
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, 10deg);
1896
+ transform: perspective(400px) rotate3d(1, 0, 0, 10deg);
1897
+ opacity: 1;
1898
+ }
1899
+
1900
+ 80% {
1901
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, -5deg);
1902
+ transform: perspective(400px) rotate3d(1, 0, 0, -5deg);
1903
+ }
1904
+
1905
+ to {
1906
+ -webkit-transform: perspective(400px);
1907
+ transform: perspective(400px);
1908
+ }
1909
+ }
1910
+
1911
+ .flipInX {
1912
+ -webkit-backface-visibility: visible !important;
1913
+ backface-visibility: visible !important;
1914
+ -webkit-animation-name: flipInX;
1915
+ animation-name: flipInX;
1916
+ }
1917
+
1918
+ @-webkit-keyframes flipInY {
1919
+ from {
1920
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
1921
+ transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
1922
+ -webkit-animation-timing-function: ease-in;
1923
+ animation-timing-function: ease-in;
1924
+ opacity: 0;
1925
+ }
1926
+
1927
+ 40% {
1928
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, -20deg);
1929
+ transform: perspective(400px) rotate3d(0, 1, 0, -20deg);
1930
+ -webkit-animation-timing-function: ease-in;
1931
+ animation-timing-function: ease-in;
1932
+ }
1933
+
1934
+ 60% {
1935
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, 10deg);
1936
+ transform: perspective(400px) rotate3d(0, 1, 0, 10deg);
1937
+ opacity: 1;
1938
+ }
1939
+
1940
+ 80% {
1941
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, -5deg);
1942
+ transform: perspective(400px) rotate3d(0, 1, 0, -5deg);
1943
+ }
1944
+
1945
+ to {
1946
+ -webkit-transform: perspective(400px);
1947
+ transform: perspective(400px);
1948
+ }
1949
+ }
1950
+
1951
+ @keyframes flipInY {
1952
+ from {
1953
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
1954
+ transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
1955
+ -webkit-animation-timing-function: ease-in;
1956
+ animation-timing-function: ease-in;
1957
+ opacity: 0;
1958
+ }
1959
+
1960
+ 40% {
1961
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, -20deg);
1962
+ transform: perspective(400px) rotate3d(0, 1, 0, -20deg);
1963
+ -webkit-animation-timing-function: ease-in;
1964
+ animation-timing-function: ease-in;
1965
+ }
1966
+
1967
+ 60% {
1968
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, 10deg);
1969
+ transform: perspective(400px) rotate3d(0, 1, 0, 10deg);
1970
+ opacity: 1;
1971
+ }
1972
+
1973
+ 80% {
1974
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, -5deg);
1975
+ transform: perspective(400px) rotate3d(0, 1, 0, -5deg);
1976
+ }
1977
+
1978
+ to {
1979
+ -webkit-transform: perspective(400px);
1980
+ transform: perspective(400px);
1981
+ }
1982
+ }
1983
+
1984
+ .flipInY {
1985
+ -webkit-backface-visibility: visible !important;
1986
+ backface-visibility: visible !important;
1987
+ -webkit-animation-name: flipInY;
1988
+ animation-name: flipInY;
1989
+ }
1990
+
1991
+ @-webkit-keyframes flipOutX {
1992
+ from {
1993
+ -webkit-transform: perspective(400px);
1994
+ transform: perspective(400px);
1995
+ }
1996
+
1997
+ 30% {
1998
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
1999
+ transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
2000
+ opacity: 1;
2001
+ }
2002
+
2003
+ to {
2004
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
2005
+ transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
2006
+ opacity: 0;
2007
+ }
2008
+ }
2009
+
2010
+ @keyframes flipOutX {
2011
+ from {
2012
+ -webkit-transform: perspective(400px);
2013
+ transform: perspective(400px);
2014
+ }
2015
+
2016
+ 30% {
2017
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
2018
+ transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
2019
+ opacity: 1;
2020
+ }
2021
+
2022
+ to {
2023
+ -webkit-transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
2024
+ transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
2025
+ opacity: 0;
2026
+ }
2027
+ }
2028
+
2029
+ .flipOutX {
2030
+ -webkit-animation-name: flipOutX;
2031
+ animation-name: flipOutX;
2032
+ -webkit-backface-visibility: visible !important;
2033
+ backface-visibility: visible !important;
2034
+ }
2035
+
2036
+ @-webkit-keyframes flipOutY {
2037
+ from {
2038
+ -webkit-transform: perspective(400px);
2039
+ transform: perspective(400px);
2040
+ }
2041
+
2042
+ 30% {
2043
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, -15deg);
2044
+ transform: perspective(400px) rotate3d(0, 1, 0, -15deg);
2045
+ opacity: 1;
2046
+ }
2047
+
2048
+ to {
2049
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
2050
+ transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
2051
+ opacity: 0;
2052
+ }
2053
+ }
2054
+
2055
+ @keyframes flipOutY {
2056
+ from {
2057
+ -webkit-transform: perspective(400px);
2058
+ transform: perspective(400px);
2059
+ }
2060
+
2061
+ 30% {
2062
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, -15deg);
2063
+ transform: perspective(400px) rotate3d(0, 1, 0, -15deg);
2064
+ opacity: 1;
2065
+ }
2066
+
2067
+ to {
2068
+ -webkit-transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
2069
+ transform: perspective(400px) rotate3d(0, 1, 0, 90deg);
2070
+ opacity: 0;
2071
+ }
2072
+ }
2073
+
2074
+ .flipOutY {
2075
+ -webkit-backface-visibility: visible !important;
2076
+ backface-visibility: visible !important;
2077
+ -webkit-animation-name: flipOutY;
2078
+ animation-name: flipOutY;
2079
+ }
2080
+
2081
+ @-webkit-keyframes lightSpeedIn {
2082
+ from {
2083
+ -webkit-transform: translate3d(100%, 0, 0) skewX(-30deg);
2084
+ transform: translate3d(100%, 0, 0) skewX(-30deg);
2085
+ opacity: 0;
2086
+ }
2087
+
2088
+ 60% {
2089
+ -webkit-transform: skewX(20deg);
2090
+ transform: skewX(20deg);
2091
+ opacity: 1;
2092
+ }
2093
+
2094
+ 80% {
2095
+ -webkit-transform: skewX(-5deg);
2096
+ transform: skewX(-5deg);
2097
+ opacity: 1;
2098
+ }
2099
+
2100
+ to {
2101
+ -webkit-transform: none;
2102
+ transform: none;
2103
+ opacity: 1;
2104
+ }
2105
+ }
2106
+
2107
+ @keyframes lightSpeedIn {
2108
+ from {
2109
+ -webkit-transform: translate3d(100%, 0, 0) skewX(-30deg);
2110
+ transform: translate3d(100%, 0, 0) skewX(-30deg);
2111
+ opacity: 0;
2112
+ }
2113
+
2114
+ 60% {
2115
+ -webkit-transform: skewX(20deg);
2116
+ transform: skewX(20deg);
2117
+ opacity: 1;
2118
+ }
2119
+
2120
+ 80% {
2121
+ -webkit-transform: skewX(-5deg);
2122
+ transform: skewX(-5deg);
2123
+ opacity: 1;
2124
+ }
2125
+
2126
+ to {
2127
+ -webkit-transform: none;
2128
+ transform: none;
2129
+ opacity: 1;
2130
+ }
2131
+ }
2132
+
2133
+ .lightSpeedIn {
2134
+ -webkit-animation-name: lightSpeedIn;
2135
+ animation-name: lightSpeedIn;
2136
+ -webkit-animation-timing-function: ease-out;
2137
+ animation-timing-function: ease-out;
2138
+ }
2139
+
2140
+ @-webkit-keyframes lightSpeedOut {
2141
+ from {
2142
+ opacity: 1;
2143
+ }
2144
+
2145
+ to {
2146
+ -webkit-transform: translate3d(100%, 0, 0) skewX(30deg);
2147
+ transform: translate3d(100%, 0, 0) skewX(30deg);
2148
+ opacity: 0;
2149
+ }
2150
+ }
2151
+
2152
+ @keyframes lightSpeedOut {
2153
+ from {
2154
+ opacity: 1;
2155
+ }
2156
+
2157
+ to {
2158
+ -webkit-transform: translate3d(100%, 0, 0) skewX(30deg);
2159
+ transform: translate3d(100%, 0, 0) skewX(30deg);
2160
+ opacity: 0;
2161
+ }
2162
+ }
2163
+
2164
+ .lightSpeedOut {
2165
+ -webkit-animation-name: lightSpeedOut;
2166
+ animation-name: lightSpeedOut;
2167
+ -webkit-animation-timing-function: ease-in;
2168
+ animation-timing-function: ease-in;
2169
+ }
2170
+
2171
+ @-webkit-keyframes rotateIn {
2172
+ from {
2173
+ -webkit-transform-origin: center;
2174
+ transform-origin: center;
2175
+ -webkit-transform: rotate3d(0, 0, 1, -200deg);
2176
+ transform: rotate3d(0, 0, 1, -200deg);
2177
+ opacity: 0;
2178
+ }
2179
+
2180
+ to {
2181
+ -webkit-transform-origin: center;
2182
+ transform-origin: center;
2183
+ -webkit-transform: none;
2184
+ transform: none;
2185
+ opacity: 1;
2186
+ }
2187
+ }
2188
+
2189
+ @keyframes rotateIn {
2190
+ from {
2191
+ -webkit-transform-origin: center;
2192
+ transform-origin: center;
2193
+ -webkit-transform: rotate3d(0, 0, 1, -200deg);
2194
+ transform: rotate3d(0, 0, 1, -200deg);
2195
+ opacity: 0;
2196
+ }
2197
+
2198
+ to {
2199
+ -webkit-transform-origin: center;
2200
+ transform-origin: center;
2201
+ -webkit-transform: none;
2202
+ transform: none;
2203
+ opacity: 1;
2204
+ }
2205
+ }
2206
+
2207
+ .rotateIn {
2208
+ -webkit-animation-name: rotateIn;
2209
+ animation-name: rotateIn;
2210
+ }
2211
+
2212
+ @-webkit-keyframes rotateInDownLeft {
2213
+ from {
2214
+ -webkit-transform-origin: left bottom;
2215
+ transform-origin: left bottom;
2216
+ -webkit-transform: rotate3d(0, 0, 1, -45deg);
2217
+ transform: rotate3d(0, 0, 1, -45deg);
2218
+ opacity: 0;
2219
+ }
2220
+
2221
+ to {
2222
+ -webkit-transform-origin: left bottom;
2223
+ transform-origin: left bottom;
2224
+ -webkit-transform: none;
2225
+ transform: none;
2226
+ opacity: 1;
2227
+ }
2228
+ }
2229
+
2230
+ @keyframes rotateInDownLeft {
2231
+ from {
2232
+ -webkit-transform-origin: left bottom;
2233
+ transform-origin: left bottom;
2234
+ -webkit-transform: rotate3d(0, 0, 1, -45deg);
2235
+ transform: rotate3d(0, 0, 1, -45deg);
2236
+ opacity: 0;
2237
+ }
2238
+
2239
+ to {
2240
+ -webkit-transform-origin: left bottom;
2241
+ transform-origin: left bottom;
2242
+ -webkit-transform: none;
2243
+ transform: none;
2244
+ opacity: 1;
2245
+ }
2246
+ }
2247
+
2248
+ .rotateInDownLeft {
2249
+ -webkit-animation-name: rotateInDownLeft;
2250
+ animation-name: rotateInDownLeft;
2251
+ }
2252
+
2253
+ @-webkit-keyframes rotateInDownRight {
2254
+ from {
2255
+ -webkit-transform-origin: right bottom;
2256
+ transform-origin: right bottom;
2257
+ -webkit-transform: rotate3d(0, 0, 1, 45deg);
2258
+ transform: rotate3d(0, 0, 1, 45deg);
2259
+ opacity: 0;
2260
+ }
2261
+
2262
+ to {
2263
+ -webkit-transform-origin: right bottom;
2264
+ transform-origin: right bottom;
2265
+ -webkit-transform: none;
2266
+ transform: none;
2267
+ opacity: 1;
2268
+ }
2269
+ }
2270
+
2271
+ @keyframes rotateInDownRight {
2272
+ from {
2273
+ -webkit-transform-origin: right bottom;
2274
+ transform-origin: right bottom;
2275
+ -webkit-transform: rotate3d(0, 0, 1, 45deg);
2276
+ transform: rotate3d(0, 0, 1, 45deg);
2277
+ opacity: 0;
2278
+ }
2279
+
2280
+ to {
2281
+ -webkit-transform-origin: right bottom;
2282
+ transform-origin: right bottom;
2283
+ -webkit-transform: none;
2284
+ transform: none;
2285
+ opacity: 1;
2286
+ }
2287
+ }
2288
+
2289
+ .rotateInDownRight {
2290
+ -webkit-animation-name: rotateInDownRight;
2291
+ animation-name: rotateInDownRight;
2292
+ }
2293
+
2294
+ @-webkit-keyframes rotateInUpLeft {
2295
+ from {
2296
+ -webkit-transform-origin: left bottom;
2297
+ transform-origin: left bottom;
2298
+ -webkit-transform: rotate3d(0, 0, 1, 45deg);
2299
+ transform: rotate3d(0, 0, 1, 45deg);
2300
+ opacity: 0;
2301
+ }
2302
+
2303
+ to {
2304
+ -webkit-transform-origin: left bottom;
2305
+ transform-origin: left bottom;
2306
+ -webkit-transform: none;
2307
+ transform: none;
2308
+ opacity: 1;
2309
+ }
2310
+ }
2311
+
2312
+ @keyframes rotateInUpLeft {
2313
+ from {
2314
+ -webkit-transform-origin: left bottom;
2315
+ transform-origin: left bottom;
2316
+ -webkit-transform: rotate3d(0, 0, 1, 45deg);
2317
+ transform: rotate3d(0, 0, 1, 45deg);
2318
+ opacity: 0;
2319
+ }
2320
+
2321
+ to {
2322
+ -webkit-transform-origin: left bottom;
2323
+ transform-origin: left bottom;
2324
+ -webkit-transform: none;
2325
+ transform: none;
2326
+ opacity: 1;
2327
+ }
2328
+ }
2329
+
2330
+ .rotateInUpLeft {
2331
+ -webkit-animation-name: rotateInUpLeft;
2332
+ animation-name: rotateInUpLeft;
2333
+ }
2334
+
2335
+ @-webkit-keyframes rotateInUpRight {
2336
+ from {
2337
+ -webkit-transform-origin: right bottom;
2338
+ transform-origin: right bottom;
2339
+ -webkit-transform: rotate3d(0, 0, 1, -90deg);
2340
+ transform: rotate3d(0, 0, 1, -90deg);
2341
+ opacity: 0;
2342
+ }
2343
+
2344
+ to {
2345
+ -webkit-transform-origin: right bottom;
2346
+ transform-origin: right bottom;
2347
+ -webkit-transform: none;
2348
+ transform: none;
2349
+ opacity: 1;
2350
+ }
2351
+ }
2352
+
2353
+ @keyframes rotateInUpRight {
2354
+ from {
2355
+ -webkit-transform-origin: right bottom;
2356
+ transform-origin: right bottom;
2357
+ -webkit-transform: rotate3d(0, 0, 1, -90deg);
2358
+ transform: rotate3d(0, 0, 1, -90deg);
2359
+ opacity: 0;
2360
+ }
2361
+
2362
+ to {
2363
+ -webkit-transform-origin: right bottom;
2364
+ transform-origin: right bottom;
2365
+ -webkit-transform: none;
2366
+ transform: none;
2367
+ opacity: 1;
2368
+ }
2369
+ }
2370
+
2371
+ .rotateInUpRight {
2372
+ -webkit-animation-name: rotateInUpRight;
2373
+ animation-name: rotateInUpRight;
2374
+ }
2375
+
2376
+ @-webkit-keyframes rotateOut {
2377
+ from {
2378
+ -webkit-transform-origin: center;
2379
+ transform-origin: center;
2380
+ opacity: 1;
2381
+ }
2382
+
2383
+ to {
2384
+ -webkit-transform-origin: center;
2385
+ transform-origin: center;
2386
+ -webkit-transform: rotate3d(0, 0, 1, 200deg);
2387
+ transform: rotate3d(0, 0, 1, 200deg);
2388
+ opacity: 0;
2389
+ }
2390
+ }
2391
+
2392
+ @keyframes rotateOut {
2393
+ from {
2394
+ -webkit-transform-origin: center;
2395
+ transform-origin: center;
2396
+ opacity: 1;
2397
+ }
2398
+
2399
+ to {
2400
+ -webkit-transform-origin: center;
2401
+ transform-origin: center;
2402
+ -webkit-transform: rotate3d(0, 0, 1, 200deg);
2403
+ transform: rotate3d(0, 0, 1, 200deg);
2404
+ opacity: 0;
2405
+ }
2406
+ }
2407
+
2408
+ .rotateOut {
2409
+ -webkit-animation-name: rotateOut;
2410
+ animation-name: rotateOut;
2411
+ }
2412
+
2413
+ @-webkit-keyframes rotateOutDownLeft {
2414
+ from {
2415
+ -webkit-transform-origin: left bottom;
2416
+ transform-origin: left bottom;
2417
+ opacity: 1;
2418
+ }
2419
+
2420
+ to {
2421
+ -webkit-transform-origin: left bottom;
2422
+ transform-origin: left bottom;
2423
+ -webkit-transform: rotate3d(0, 0, 1, 45deg);
2424
+ transform: rotate3d(0, 0, 1, 45deg);
2425
+ opacity: 0;
2426
+ }
2427
+ }
2428
+
2429
+ @keyframes rotateOutDownLeft {
2430
+ from {
2431
+ -webkit-transform-origin: left bottom;
2432
+ transform-origin: left bottom;
2433
+ opacity: 1;
2434
+ }
2435
+
2436
+ to {
2437
+ -webkit-transform-origin: left bottom;
2438
+ transform-origin: left bottom;
2439
+ -webkit-transform: rotate3d(0, 0, 1, 45deg);
2440
+ transform: rotate3d(0, 0, 1, 45deg);
2441
+ opacity: 0;
2442
+ }
2443
+ }
2444
+
2445
+ .rotateOutDownLeft {
2446
+ -webkit-animation-name: rotateOutDownLeft;
2447
+ animation-name: rotateOutDownLeft;
2448
+ }
2449
+
2450
+ @-webkit-keyframes rotateOutDownRight {
2451
+ from {
2452
+ -webkit-transform-origin: right bottom;
2453
+ transform-origin: right bottom;
2454
+ opacity: 1;
2455
+ }
2456
+
2457
+ to {
2458
+ -webkit-transform-origin: right bottom;
2459
+ transform-origin: right bottom;
2460
+ -webkit-transform: rotate3d(0, 0, 1, -45deg);
2461
+ transform: rotate3d(0, 0, 1, -45deg);
2462
+ opacity: 0;
2463
+ }
2464
+ }
2465
+
2466
+ @keyframes rotateOutDownRight {
2467
+ from {
2468
+ -webkit-transform-origin: right bottom;
2469
+ transform-origin: right bottom;
2470
+ opacity: 1;
2471
+ }
2472
+
2473
+ to {
2474
+ -webkit-transform-origin: right bottom;
2475
+ transform-origin: right bottom;
2476
+ -webkit-transform: rotate3d(0, 0, 1, -45deg);
2477
+ transform: rotate3d(0, 0, 1, -45deg);
2478
+ opacity: 0;
2479
+ }
2480
+ }
2481
+
2482
+ .rotateOutDownRight {
2483
+ -webkit-animation-name: rotateOutDownRight;
2484
+ animation-name: rotateOutDownRight;
2485
+ }
2486
+
2487
+ @-webkit-keyframes rotateOutUpLeft {
2488
+ from {
2489
+ -webkit-transform-origin: left bottom;
2490
+ transform-origin: left bottom;
2491
+ opacity: 1;
2492
+ }
2493
+
2494
+ to {
2495
+ -webkit-transform-origin: left bottom;
2496
+ transform-origin: left bottom;
2497
+ -webkit-transform: rotate3d(0, 0, 1, -45deg);
2498
+ transform: rotate3d(0, 0, 1, -45deg);
2499
+ opacity: 0;
2500
+ }
2501
+ }
2502
+
2503
+ @keyframes rotateOutUpLeft {
2504
+ from {
2505
+ -webkit-transform-origin: left bottom;
2506
+ transform-origin: left bottom;
2507
+ opacity: 1;
2508
+ }
2509
+
2510
+ to {
2511
+ -webkit-transform-origin: left bottom;
2512
+ transform-origin: left bottom;
2513
+ -webkit-transform: rotate3d(0, 0, 1, -45deg);
2514
+ transform: rotate3d(0, 0, 1, -45deg);
2515
+ opacity: 0;
2516
+ }
2517
+ }
2518
+
2519
+ .rotateOutUpLeft {
2520
+ -webkit-animation-name: rotateOutUpLeft;
2521
+ animation-name: rotateOutUpLeft;
2522
+ }
2523
+
2524
+ @-webkit-keyframes rotateOutUpRight {
2525
+ from {
2526
+ -webkit-transform-origin: right bottom;
2527
+ transform-origin: right bottom;
2528
+ opacity: 1;
2529
+ }
2530
+
2531
+ to {
2532
+ -webkit-transform-origin: right bottom;
2533
+ transform-origin: right bottom;
2534
+ -webkit-transform: rotate3d(0, 0, 1, 90deg);
2535
+ transform: rotate3d(0, 0, 1, 90deg);
2536
+ opacity: 0;
2537
+ }
2538
+ }
2539
+
2540
+ @keyframes rotateOutUpRight {
2541
+ from {
2542
+ -webkit-transform-origin: right bottom;
2543
+ transform-origin: right bottom;
2544
+ opacity: 1;
2545
+ }
2546
+
2547
+ to {
2548
+ -webkit-transform-origin: right bottom;
2549
+ transform-origin: right bottom;
2550
+ -webkit-transform: rotate3d(0, 0, 1, 90deg);
2551
+ transform: rotate3d(0, 0, 1, 90deg);
2552
+ opacity: 0;
2553
+ }
2554
+ }
2555
+
2556
+ .rotateOutUpRight {
2557
+ -webkit-animation-name: rotateOutUpRight;
2558
+ animation-name: rotateOutUpRight;
2559
+ }
2560
+
2561
+ @-webkit-keyframes hinge {
2562
+ 0% {
2563
+ -webkit-transform-origin: top left;
2564
+ transform-origin: top left;
2565
+ -webkit-animation-timing-function: ease-in-out;
2566
+ animation-timing-function: ease-in-out;
2567
+ }
2568
+
2569
+ 20%, 60% {
2570
+ -webkit-transform: rotate3d(0, 0, 1, 80deg);
2571
+ transform: rotate3d(0, 0, 1, 80deg);
2572
+ -webkit-transform-origin: top left;
2573
+ transform-origin: top left;
2574
+ -webkit-animation-timing-function: ease-in-out;
2575
+ animation-timing-function: ease-in-out;
2576
+ }
2577
+
2578
+ 40%, 80% {
2579
+ -webkit-transform: rotate3d(0, 0, 1, 60deg);
2580
+ transform: rotate3d(0, 0, 1, 60deg);
2581
+ -webkit-transform-origin: top left;
2582
+ transform-origin: top left;
2583
+ -webkit-animation-timing-function: ease-in-out;
2584
+ animation-timing-function: ease-in-out;
2585
+ opacity: 1;
2586
+ }
2587
+
2588
+ to {
2589
+ -webkit-transform: translate3d(0, 700px, 0);
2590
+ transform: translate3d(0, 700px, 0);
2591
+ opacity: 0;
2592
+ }
2593
+ }
2594
+
2595
+ @keyframes hinge {
2596
+ 0% {
2597
+ -webkit-transform-origin: top left;
2598
+ transform-origin: top left;
2599
+ -webkit-animation-timing-function: ease-in-out;
2600
+ animation-timing-function: ease-in-out;
2601
+ }
2602
+
2603
+ 20%, 60% {
2604
+ -webkit-transform: rotate3d(0, 0, 1, 80deg);
2605
+ transform: rotate3d(0, 0, 1, 80deg);
2606
+ -webkit-transform-origin: top left;
2607
+ transform-origin: top left;
2608
+ -webkit-animation-timing-function: ease-in-out;
2609
+ animation-timing-function: ease-in-out;
2610
+ }
2611
+
2612
+ 40%, 80% {
2613
+ -webkit-transform: rotate3d(0, 0, 1, 60deg);
2614
+ transform: rotate3d(0, 0, 1, 60deg);
2615
+ -webkit-transform-origin: top left;
2616
+ transform-origin: top left;
2617
+ -webkit-animation-timing-function: ease-in-out;
2618
+ animation-timing-function: ease-in-out;
2619
+ opacity: 1;
2620
+ }
2621
+
2622
+ to {
2623
+ -webkit-transform: translate3d(0, 700px, 0);
2624
+ transform: translate3d(0, 700px, 0);
2625
+ opacity: 0;
2626
+ }
2627
+ }
2628
+
2629
+ .hinge {
2630
+ -webkit-animation-name: hinge;
2631
+ animation-name: hinge;
2632
+ }
2633
+
2634
+ /* originally authored by Nick Pettit - https://github.com/nickpettit/glide */
2635
+
2636
+ @-webkit-keyframes rollIn {
2637
+ from {
2638
+ opacity: 0;
2639
+ -webkit-transform: translate3d(-100%, 0, 0) rotate3d(0, 0, 1, -120deg);
2640
+ transform: translate3d(-100%, 0, 0) rotate3d(0, 0, 1, -120deg);
2641
+ }
2642
+
2643
+ to {
2644
+ opacity: 1;
2645
+ -webkit-transform: none;
2646
+ transform: none;
2647
+ }
2648
+ }
2649
+
2650
+ @keyframes rollIn {
2651
+ from {
2652
+ opacity: 0;
2653
+ -webkit-transform: translate3d(-100%, 0, 0) rotate3d(0, 0, 1, -120deg);
2654
+ transform: translate3d(-100%, 0, 0) rotate3d(0, 0, 1, -120deg);
2655
+ }
2656
+
2657
+ to {
2658
+ opacity: 1;
2659
+ -webkit-transform: none;
2660
+ transform: none;
2661
+ }
2662
+ }
2663
+
2664
+ .rollIn {
2665
+ -webkit-animation-name: rollIn;
2666
+ animation-name: rollIn;
2667
+ }
2668
+
2669
+ /* originally authored by Nick Pettit - https://github.com/nickpettit/glide */
2670
+
2671
+ @-webkit-keyframes rollOut {
2672
+ from {
2673
+ opacity: 1;
2674
+ }
2675
+
2676
+ to {
2677
+ opacity: 0;
2678
+ -webkit-transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg);
2679
+ transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg);
2680
+ }
2681
+ }
2682
+
2683
+ @keyframes rollOut {
2684
+ from {
2685
+ opacity: 1;
2686
+ }
2687
+
2688
+ to {
2689
+ opacity: 0;
2690
+ -webkit-transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg);
2691
+ transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg);
2692
+ }
2693
+ }
2694
+
2695
+ .rollOut {
2696
+ -webkit-animation-name: rollOut;
2697
+ animation-name: rollOut;
2698
+ }
2699
+
2700
+ @-webkit-keyframes zoomIn {
2701
+ from {
2702
+ opacity: 0;
2703
+ -webkit-transform: scale3d(.3, .3, .3);
2704
+ transform: scale3d(.3, .3, .3);
2705
+ }
2706
+
2707
+ 50% {
2708
+ opacity: 1;
2709
+ }
2710
+ }
2711
+
2712
+ @keyframes zoomIn {
2713
+ from {
2714
+ opacity: 0;
2715
+ -webkit-transform: scale3d(.3, .3, .3);
2716
+ transform: scale3d(.3, .3, .3);
2717
+ }
2718
+
2719
+ 50% {
2720
+ opacity: 1;
2721
+ }
2722
+ }
2723
+
2724
+ .zoomIn {
2725
+ -webkit-animation-name: zoomIn;
2726
+ animation-name: zoomIn;
2727
+ }
2728
+
2729
+ @-webkit-keyframes zoomInDown {
2730
+ from {
2731
+ opacity: 0;
2732
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(0, -1000px, 0);
2733
+ transform: scale3d(.1, .1, .1) translate3d(0, -1000px, 0);
2734
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2735
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2736
+ }
2737
+
2738
+ 60% {
2739
+ opacity: 1;
2740
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
2741
+ transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
2742
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2743
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2744
+ }
2745
+ }
2746
+
2747
+ @keyframes zoomInDown {
2748
+ from {
2749
+ opacity: 0;
2750
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(0, -1000px, 0);
2751
+ transform: scale3d(.1, .1, .1) translate3d(0, -1000px, 0);
2752
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2753
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2754
+ }
2755
+
2756
+ 60% {
2757
+ opacity: 1;
2758
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
2759
+ transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
2760
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2761
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2762
+ }
2763
+ }
2764
+
2765
+ .zoomInDown {
2766
+ -webkit-animation-name: zoomInDown;
2767
+ animation-name: zoomInDown;
2768
+ }
2769
+
2770
+ @-webkit-keyframes zoomInLeft {
2771
+ from {
2772
+ opacity: 0;
2773
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(-1000px, 0, 0);
2774
+ transform: scale3d(.1, .1, .1) translate3d(-1000px, 0, 0);
2775
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2776
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2777
+ }
2778
+
2779
+ 60% {
2780
+ opacity: 1;
2781
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(10px, 0, 0);
2782
+ transform: scale3d(.475, .475, .475) translate3d(10px, 0, 0);
2783
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2784
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2785
+ }
2786
+ }
2787
+
2788
+ @keyframes zoomInLeft {
2789
+ from {
2790
+ opacity: 0;
2791
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(-1000px, 0, 0);
2792
+ transform: scale3d(.1, .1, .1) translate3d(-1000px, 0, 0);
2793
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2794
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2795
+ }
2796
+
2797
+ 60% {
2798
+ opacity: 1;
2799
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(10px, 0, 0);
2800
+ transform: scale3d(.475, .475, .475) translate3d(10px, 0, 0);
2801
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2802
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2803
+ }
2804
+ }
2805
+
2806
+ .zoomInLeft {
2807
+ -webkit-animation-name: zoomInLeft;
2808
+ animation-name: zoomInLeft;
2809
+ }
2810
+
2811
+ @-webkit-keyframes zoomInRight {
2812
+ from {
2813
+ opacity: 0;
2814
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(1000px, 0, 0);
2815
+ transform: scale3d(.1, .1, .1) translate3d(1000px, 0, 0);
2816
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2817
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2818
+ }
2819
+
2820
+ 60% {
2821
+ opacity: 1;
2822
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(-10px, 0, 0);
2823
+ transform: scale3d(.475, .475, .475) translate3d(-10px, 0, 0);
2824
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2825
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2826
+ }
2827
+ }
2828
+
2829
+ @keyframes zoomInRight {
2830
+ from {
2831
+ opacity: 0;
2832
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(1000px, 0, 0);
2833
+ transform: scale3d(.1, .1, .1) translate3d(1000px, 0, 0);
2834
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2835
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2836
+ }
2837
+
2838
+ 60% {
2839
+ opacity: 1;
2840
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(-10px, 0, 0);
2841
+ transform: scale3d(.475, .475, .475) translate3d(-10px, 0, 0);
2842
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2843
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2844
+ }
2845
+ }
2846
+
2847
+ .zoomInRight {
2848
+ -webkit-animation-name: zoomInRight;
2849
+ animation-name: zoomInRight;
2850
+ }
2851
+
2852
+ @-webkit-keyframes zoomInUp {
2853
+ from {
2854
+ opacity: 0;
2855
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0);
2856
+ transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0);
2857
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2858
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2859
+ }
2860
+
2861
+ 60% {
2862
+ opacity: 1;
2863
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
2864
+ transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
2865
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2866
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2867
+ }
2868
+ }
2869
+
2870
+ @keyframes zoomInUp {
2871
+ from {
2872
+ opacity: 0;
2873
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0);
2874
+ transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0);
2875
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2876
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2877
+ }
2878
+
2879
+ 60% {
2880
+ opacity: 1;
2881
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
2882
+ transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
2883
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2884
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2885
+ }
2886
+ }
2887
+
2888
+ .zoomInUp {
2889
+ -webkit-animation-name: zoomInUp;
2890
+ animation-name: zoomInUp;
2891
+ }
2892
+
2893
+ @-webkit-keyframes zoomOut {
2894
+ from {
2895
+ opacity: 1;
2896
+ }
2897
+
2898
+ 50% {
2899
+ opacity: 0;
2900
+ -webkit-transform: scale3d(.3, .3, .3);
2901
+ transform: scale3d(.3, .3, .3);
2902
+ }
2903
+
2904
+ to {
2905
+ opacity: 0;
2906
+ }
2907
+ }
2908
+
2909
+ @keyframes zoomOut {
2910
+ from {
2911
+ opacity: 1;
2912
+ }
2913
+
2914
+ 50% {
2915
+ opacity: 0;
2916
+ -webkit-transform: scale3d(.3, .3, .3);
2917
+ transform: scale3d(.3, .3, .3);
2918
+ }
2919
+
2920
+ to {
2921
+ opacity: 0;
2922
+ }
2923
+ }
2924
+
2925
+ .zoomOut {
2926
+ -webkit-animation-name: zoomOut;
2927
+ animation-name: zoomOut;
2928
+ }
2929
+
2930
+ @-webkit-keyframes zoomOutDown {
2931
+ 40% {
2932
+ opacity: 1;
2933
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
2934
+ transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
2935
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2936
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2937
+ }
2938
+
2939
+ to {
2940
+ opacity: 0;
2941
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(0, 2000px, 0);
2942
+ transform: scale3d(.1, .1, .1) translate3d(0, 2000px, 0);
2943
+ -webkit-transform-origin: center bottom;
2944
+ transform-origin: center bottom;
2945
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2946
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2947
+ }
2948
+ }
2949
+
2950
+ @keyframes zoomOutDown {
2951
+ 40% {
2952
+ opacity: 1;
2953
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
2954
+ transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
2955
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2956
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
2957
+ }
2958
+
2959
+ to {
2960
+ opacity: 0;
2961
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(0, 2000px, 0);
2962
+ transform: scale3d(.1, .1, .1) translate3d(0, 2000px, 0);
2963
+ -webkit-transform-origin: center bottom;
2964
+ transform-origin: center bottom;
2965
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2966
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
2967
+ }
2968
+ }
2969
+
2970
+ .zoomOutDown {
2971
+ -webkit-animation-name: zoomOutDown;
2972
+ animation-name: zoomOutDown;
2973
+ }
2974
+
2975
+ @-webkit-keyframes zoomOutLeft {
2976
+ 40% {
2977
+ opacity: 1;
2978
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(42px, 0, 0);
2979
+ transform: scale3d(.475, .475, .475) translate3d(42px, 0, 0);
2980
+ }
2981
+
2982
+ to {
2983
+ opacity: 0;
2984
+ -webkit-transform: scale(.1) translate3d(-2000px, 0, 0);
2985
+ transform: scale(.1) translate3d(-2000px, 0, 0);
2986
+ -webkit-transform-origin: left center;
2987
+ transform-origin: left center;
2988
+ }
2989
+ }
2990
+
2991
+ @keyframes zoomOutLeft {
2992
+ 40% {
2993
+ opacity: 1;
2994
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(42px, 0, 0);
2995
+ transform: scale3d(.475, .475, .475) translate3d(42px, 0, 0);
2996
+ }
2997
+
2998
+ to {
2999
+ opacity: 0;
3000
+ -webkit-transform: scale(.1) translate3d(-2000px, 0, 0);
3001
+ transform: scale(.1) translate3d(-2000px, 0, 0);
3002
+ -webkit-transform-origin: left center;
3003
+ transform-origin: left center;
3004
+ }
3005
+ }
3006
+
3007
+ .zoomOutLeft {
3008
+ -webkit-animation-name: zoomOutLeft;
3009
+ animation-name: zoomOutLeft;
3010
+ }
3011
+
3012
+ @-webkit-keyframes zoomOutRight {
3013
+ 40% {
3014
+ opacity: 1;
3015
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(-42px, 0, 0);
3016
+ transform: scale3d(.475, .475, .475) translate3d(-42px, 0, 0);
3017
+ }
3018
+
3019
+ to {
3020
+ opacity: 0;
3021
+ -webkit-transform: scale(.1) translate3d(2000px, 0, 0);
3022
+ transform: scale(.1) translate3d(2000px, 0, 0);
3023
+ -webkit-transform-origin: right center;
3024
+ transform-origin: right center;
3025
+ }
3026
+ }
3027
+
3028
+ @keyframes zoomOutRight {
3029
+ 40% {
3030
+ opacity: 1;
3031
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(-42px, 0, 0);
3032
+ transform: scale3d(.475, .475, .475) translate3d(-42px, 0, 0);
3033
+ }
3034
+
3035
+ to {
3036
+ opacity: 0;
3037
+ -webkit-transform: scale(.1) translate3d(2000px, 0, 0);
3038
+ transform: scale(.1) translate3d(2000px, 0, 0);
3039
+ -webkit-transform-origin: right center;
3040
+ transform-origin: right center;
3041
+ }
3042
+ }
3043
+
3044
+ .zoomOutRight {
3045
+ -webkit-animation-name: zoomOutRight;
3046
+ animation-name: zoomOutRight;
3047
+ }
3048
+
3049
+ @-webkit-keyframes zoomOutUp {
3050
+ 40% {
3051
+ opacity: 1;
3052
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
3053
+ transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
3054
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
3055
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
3056
+ }
3057
+
3058
+ to {
3059
+ opacity: 0;
3060
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0);
3061
+ transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0);
3062
+ -webkit-transform-origin: center bottom;
3063
+ transform-origin: center bottom;
3064
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
3065
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
3066
+ }
3067
+ }
3068
+
3069
+ @keyframes zoomOutUp {
3070
+ 40% {
3071
+ opacity: 1;
3072
+ -webkit-transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
3073
+ transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
3074
+ -webkit-animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
3075
+ animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190);
3076
+ }
3077
+
3078
+ to {
3079
+ opacity: 0;
3080
+ -webkit-transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0);
3081
+ transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0);
3082
+ -webkit-transform-origin: center bottom;
3083
+ transform-origin: center bottom;
3084
+ -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
3085
+ animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
3086
+ }
3087
+ }
3088
+
3089
+ .zoomOutUp {
3090
+ -webkit-animation-name: zoomOutUp;
3091
+ animation-name: zoomOutUp;
3092
+ }
3093
+
3094
+ @-webkit-keyframes slideInDown {
3095
+ from {
3096
+ -webkit-transform: translate3d(0, -100%, 0);
3097
+ transform: translate3d(0, -100%, 0);
3098
+ visibility: visible;
3099
+ }
3100
+
3101
+ to {
3102
+ -webkit-transform: translate3d(0, 0, 0);
3103
+ transform: translate3d(0, 0, 0);
3104
+ }
3105
+ }
3106
+
3107
+ @keyframes slideInDown {
3108
+ from {
3109
+ -webkit-transform: translate3d(0, -100%, 0);
3110
+ transform: translate3d(0, -100%, 0);
3111
+ visibility: visible;
3112
+ }
3113
+
3114
+ to {
3115
+ -webkit-transform: translate3d(0, 0, 0);
3116
+ transform: translate3d(0, 0, 0);
3117
+ }
3118
+ }
3119
+
3120
+ .slideInDown {
3121
+ -webkit-animation-name: slideInDown;
3122
+ animation-name: slideInDown;
3123
+ }
3124
+
3125
+ @-webkit-keyframes slideInLeft {
3126
+ from {
3127
+ -webkit-transform: translate3d(-100%, 0, 0);
3128
+ transform: translate3d(-100%, 0, 0);
3129
+ visibility: visible;
3130
+ }
3131
+
3132
+ to {
3133
+ -webkit-transform: translate3d(0, 0, 0);
3134
+ transform: translate3d(0, 0, 0);
3135
+ }
3136
+ }
3137
+
3138
+ @keyframes slideInLeft {
3139
+ from {
3140
+ -webkit-transform: translate3d(-100%, 0, 0);
3141
+ transform: translate3d(-100%, 0, 0);
3142
+ visibility: visible;
3143
+ }
3144
+
3145
+ to {
3146
+ -webkit-transform: translate3d(0, 0, 0);
3147
+ transform: translate3d(0, 0, 0);
3148
+ }
3149
+ }
3150
+
3151
+ .slideInLeft {
3152
+ -webkit-animation-name: slideInLeft;
3153
+ animation-name: slideInLeft;
3154
+ }
3155
+
3156
+ @-webkit-keyframes slideInRight {
3157
+ from {
3158
+ -webkit-transform: translate3d(100%, 0, 0);
3159
+ transform: translate3d(100%, 0, 0);
3160
+ visibility: visible;
3161
+ }
3162
+
3163
+ to {
3164
+ -webkit-transform: translate3d(0, 0, 0);
3165
+ transform: translate3d(0, 0, 0);
3166
+ }
3167
+ }
3168
+
3169
+ @keyframes slideInRight {
3170
+ from {
3171
+ -webkit-transform: translate3d(100%, 0, 0);
3172
+ transform: translate3d(100%, 0, 0);
3173
+ visibility: visible;
3174
+ }
3175
+
3176
+ to {
3177
+ -webkit-transform: translate3d(0, 0, 0);
3178
+ transform: translate3d(0, 0, 0);
3179
+ }
3180
+ }
3181
+
3182
+ .slideInRight {
3183
+ -webkit-animation-name: slideInRight;
3184
+ animation-name: slideInRight;
3185
+ }
3186
+
3187
+ @-webkit-keyframes slideInUp {
3188
+ from {
3189
+ -webkit-transform: translate3d(0, 100%, 0);
3190
+ transform: translate3d(0, 100%, 0);
3191
+ visibility: visible;
3192
+ }
3193
+
3194
+ to {
3195
+ -webkit-transform: translate3d(0, 0, 0);
3196
+ transform: translate3d(0, 0, 0);
3197
+ }
3198
+ }
3199
+
3200
+ @keyframes slideInUp {
3201
+ from {
3202
+ -webkit-transform: translate3d(0, 100%, 0);
3203
+ transform: translate3d(0, 100%, 0);
3204
+ visibility: visible;
3205
+ }
3206
+
3207
+ to {
3208
+ -webkit-transform: translate3d(0, 0, 0);
3209
+ transform: translate3d(0, 0, 0);
3210
+ }
3211
+ }
3212
+
3213
+ .slideInUp {
3214
+ -webkit-animation-name: slideInUp;
3215
+ animation-name: slideInUp;
3216
+ }
3217
+
3218
+ @-webkit-keyframes slideOutDown {
3219
+ from {
3220
+ -webkit-transform: translate3d(0, 0, 0);
3221
+ transform: translate3d(0, 0, 0);
3222
+ }
3223
+
3224
+ to {
3225
+ visibility: hidden;
3226
+ -webkit-transform: translate3d(0, 100%, 0);
3227
+ transform: translate3d(0, 100%, 0);
3228
+ }
3229
+ }
3230
+
3231
+ @keyframes slideOutDown {
3232
+ from {
3233
+ -webkit-transform: translate3d(0, 0, 0);
3234
+ transform: translate3d(0, 0, 0);
3235
+ }
3236
+
3237
+ to {
3238
+ visibility: hidden;
3239
+ -webkit-transform: translate3d(0, 100%, 0);
3240
+ transform: translate3d(0, 100%, 0);
3241
+ }
3242
+ }
3243
+
3244
+ .slideOutDown {
3245
+ -webkit-animation-name: slideOutDown;
3246
+ animation-name: slideOutDown;
3247
+ }
3248
+
3249
+ @-webkit-keyframes slideOutLeft {
3250
+ from {
3251
+ -webkit-transform: translate3d(0, 0, 0);
3252
+ transform: translate3d(0, 0, 0);
3253
+ }
3254
+
3255
+ to {
3256
+ visibility: hidden;
3257
+ -webkit-transform: translate3d(-100%, 0, 0);
3258
+ transform: translate3d(-100%, 0, 0);
3259
+ }
3260
+ }
3261
+
3262
+ @keyframes slideOutLeft {
3263
+ from {
3264
+ -webkit-transform: translate3d(0, 0, 0);
3265
+ transform: translate3d(0, 0, 0);
3266
+ }
3267
+
3268
+ to {
3269
+ visibility: hidden;
3270
+ -webkit-transform: translate3d(-100%, 0, 0);
3271
+ transform: translate3d(-100%, 0, 0);
3272
+ }
3273
+ }
3274
+
3275
+ .slideOutLeft {
3276
+ -webkit-animation-name: slideOutLeft;
3277
+ animation-name: slideOutLeft;
3278
+ }
3279
+
3280
+ @-webkit-keyframes slideOutRight {
3281
+ from {
3282
+ -webkit-transform: translate3d(0, 0, 0);
3283
+ transform: translate3d(0, 0, 0);
3284
+ }
3285
+
3286
+ to {
3287
+ visibility: hidden;
3288
+ -webkit-transform: translate3d(100%, 0, 0);
3289
+ transform: translate3d(100%, 0, 0);
3290
+ }
3291
+ }
3292
+
3293
+ @keyframes slideOutRight {
3294
+ from {
3295
+ -webkit-transform: translate3d(0, 0, 0);
3296
+ transform: translate3d(0, 0, 0);
3297
+ }
3298
+
3299
+ to {
3300
+ visibility: hidden;
3301
+ -webkit-transform: translate3d(100%, 0, 0);
3302
+ transform: translate3d(100%, 0, 0);
3303
+ }
3304
+ }
3305
+
3306
+ .slideOutRight {
3307
+ -webkit-animation-name: slideOutRight;
3308
+ animation-name: slideOutRight;
3309
+ }
3310
+
3311
+ @-webkit-keyframes slideOutUp {
3312
+ from {
3313
+ -webkit-transform: translate3d(0, 0, 0);
3314
+ transform: translate3d(0, 0, 0);
3315
+ }
3316
+
3317
+ to {
3318
+ visibility: hidden;
3319
+ -webkit-transform: translate3d(0, -100%, 0);
3320
+ transform: translate3d(0, -100%, 0);
3321
+ }
3322
+ }
3323
+
3324
+ @keyframes slideOutUp {
3325
+ from {
3326
+ -webkit-transform: translate3d(0, 0, 0);
3327
+ transform: translate3d(0, 0, 0);
3328
+ }
3329
+
3330
+ to {
3331
+ visibility: hidden;
3332
+ -webkit-transform: translate3d(0, -100%, 0);
3333
+ transform: translate3d(0, -100%, 0);
3334
+ }
3335
+ }
3336
+
3337
+ .slideOutUp {
3338
+ -webkit-animation-name: slideOutUp;
3339
+ animation-name: slideOutUp;
3340
+ }
public/assets/css/public.css CHANGED
@@ -4,6 +4,54 @@
4
  display: none;
5
  }
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  /* To fill the container and nothing else */
8
 
9
  .responsive , .responsive span, .responsive span iframe[style], .responsive span img {
@@ -13,7 +61,7 @@
13
  /*Magnific popup CSS*/
14
  .white-popup {
15
  position: relative;
16
- background: #FFF;
17
  width: auto;
18
  max-width: 720px;
19
  margin: 20px auto;
@@ -128,13 +176,11 @@
128
  #efblcf .efbl_story_photo iframe {
129
  margin:0px;
130
  padding:0px;
131
- width: 100%;
132
- border: 0px;
133
  }
134
  #efblcf.fullwidth .efbl_youtube_video, #efblcf.fullwidth .efbl_vimeo_video {
135
-
136
  height:400px;
137
-
138
  }
139
 
140
  #efblcf.halfwidth .efbl_story_photo{
@@ -243,9 +289,10 @@
243
  box-sizing: border-box;
244
  }
245
  #efblcf .efbl_shared_story.efbl_has_link_image .efbl_link_image{
246
- float:left;
247
- width: auto;
248
- margin-right: 10px;
 
249
  }
250
  #efblcf .efbl_shared_story .efbl_link_text{
251
  width:100%;
@@ -275,16 +322,20 @@
275
  }
276
 
277
  /*Ppopup CSS*/
278
- #efblcf_holder img, #efblcf_holder video, #efblcf_holder iframe {
279
  width:100%;
280
  height:auto;
281
- border: 0px;
282
  }
 
 
 
283
  #efblcf_holder .efbl_popup_image, #efblcf_holder .efbl_popup_if_video, #efblcf_holder .efbl_popup_video, #efblcf_holder .efbl_popupp_footer{
284
  display:none;
285
  }
286
  #efblcf_holder .efbl_popupp_footer{
287
  padding:10px;
 
 
288
  }
289
  #efblcf_holder .efbl_popupp_footer p{
290
  line-height: 1.3em;
@@ -426,6 +477,43 @@ line-height: 1.3em;
426
  opacity: 0;
427
  }
428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  @media only screen and (max-width:768px){
430
  #efblcf.thumbnail .efbl_story_photo, #efblcf.thumbnail .efbl_post_content, #efblcf.halfwidth .efbl_story_photo, #efblcf.halfwidth .efbl_post_content{
431
  width: 100%;
@@ -454,4 +542,5 @@ line-height: 1.3em;
454
  bottom:-30px;
455
  }
456
 
457
- }
 
4
  display: none;
5
  }
6
 
7
+ .efbl-like-box {
8
+ position: relative;
9
+ }
10
+ img.efbl-loader {
11
+ position: absolute;
12
+ left: 35%;
13
+ top: 35%;
14
+ width: 10%;
15
+ }
16
+ #efblcf_holder .efbl_popup_left_container{
17
+ position: relative;
18
+ }
19
+ #efblcf_holder .efbl_popup_left_container a{
20
+ outline: none;
21
+ position: absolute;
22
+ z-index: 1000;
23
+ top: 0;
24
+ bottom: 35px;
25
+ height: auto;
26
+ width: 25%;
27
+ opacity: 0;
28
+ cursor: pointer;
29
+ }
30
+ #efblcf_holder .efbl_popup_left_container a:hover{
31
+ opacity: 1;
32
+ }
33
+ #efblcf_holder .efbl_popup_left_container a i{
34
+ font-size: 100px;
35
+ position: absolute;
36
+ top: 38%;
37
+ color: white;
38
+ }
39
+ #efblcf_holder .efbl_popup_left_container a.efbl-popup-next i{
40
+ right: 25px;
41
+ }
42
+ #efblcf_holder .efbl_popup_left_container a.efbl-popup-prev i{
43
+ left: 25px;
44
+ }
45
+ #efblcf_holder a.efbl-popup-next{
46
+ right: 0;
47
+ }
48
+
49
+ .efbl_popup_image{
50
+ width: auto;
51
+ display: block;
52
+ margin: 0px auto;
53
+ }
54
+
55
  /* To fill the container and nothing else */
56
 
57
  .responsive , .responsive span, .responsive span iframe[style], .responsive span img {
61
  /*Magnific popup CSS*/
62
  .white-popup {
63
  position: relative;
64
+ background: #000;
65
  width: auto;
66
  max-width: 720px;
67
  margin: 20px auto;
176
  #efblcf .efbl_story_photo iframe {
177
  margin:0px;
178
  padding:0px;
 
 
179
  }
180
  #efblcf.fullwidth .efbl_youtube_video, #efblcf.fullwidth .efbl_vimeo_video {
181
+ width:100%;
182
  height:400px;
183
+ margin-bottom: 0px;
184
  }
185
 
186
  #efblcf.halfwidth .efbl_story_photo{
289
  box-sizing: border-box;
290
  }
291
  #efblcf .efbl_shared_story.efbl_has_link_image .efbl_link_image{
292
+ float: left;
293
+ width: 25%;
294
+ margin-right: 10px;
295
+ height: auto;
296
  }
297
  #efblcf .efbl_shared_story .efbl_link_text{
298
  width:100%;
322
  }
323
 
324
  /*Ppopup CSS*/
325
+ #efblcf_holder video, #efblcf_holder iframe {
326
  width:100%;
327
  height:auto;
 
328
  }
329
+ #efblcf_holder video{
330
+ height: 100%;
331
+ }
332
  #efblcf_holder .efbl_popup_image, #efblcf_holder .efbl_popup_if_video, #efblcf_holder .efbl_popup_video, #efblcf_holder .efbl_popupp_footer{
333
  display:none;
334
  }
335
  #efblcf_holder .efbl_popupp_footer{
336
  padding:10px;
337
+ background: #fff;
338
+ border-radius: 5px;
339
  }
340
  #efblcf_holder .efbl_popupp_footer p{
341
  line-height: 1.3em;
477
  opacity: 0;
478
  }
479
 
480
+ /**
481
+ * Fade animation for first dialog
482
+ */
483
+
484
+ .mfp-fade.mfp-bg {
485
+ opacity: 0;
486
+
487
+ -webkit-transition: all 0.15s ease-out;
488
+ -moz-transition: all 0.15s ease-out;
489
+ transition: all 0.15s ease-out;
490
+ }
491
+ /* overlay animate in */
492
+ .mfp-fade.mfp-bg.mfp-ready {
493
+ opacity: 0.8;
494
+ }
495
+ /* overlay animate out */
496
+ .mfp-fade.mfp-bg.mfp-removing {
497
+ opacity: 0;
498
+ }
499
+
500
+ /* content at start */
501
+ .mfp-fade.mfp-wrap .mfp-content {
502
+ opacity: 0;
503
+
504
+ -webkit-transition: all 0.15s ease-out;
505
+ -moz-transition: all 0.15s ease-out;
506
+ transition: all 0.15s ease-out;
507
+ }
508
+ /* content animate it */
509
+ .mfp-fade.mfp-wrap.mfp-ready .mfp-content {
510
+ opacity: 1;
511
+ }
512
+ /* content animate out */
513
+ .mfp-fade.mfp-wrap.mfp-removing .mfp-content {
514
+ opacity: 0;
515
+ }
516
+
517
  @media only screen and (max-width:768px){
518
  #efblcf.thumbnail .efbl_story_photo, #efblcf.thumbnail .efbl_post_content, #efblcf.halfwidth .efbl_story_photo, #efblcf.halfwidth .efbl_post_content{
519
  width: 100%;
542
  bottom:-30px;
543
  }
544
 
545
+ }
546
+
public/assets/images/loader.gif ADDED
Binary file
public/assets/images/loader_icon.gif ADDED
Binary file
public/assets/js/public.js CHANGED
@@ -1,20 +1,25 @@
1
  jQuery(document).ready(function($) {
2
-
3
- $('.efbl_feed_popup').magnificPopup({
4
- type: 'inline',
5
- preloader: false,
6
- mainClass: 'my-mfp-zoom-in',
7
- callbacks: {
8
- beforeOpen: function() {
9
-
10
-
11
- var $story_link = this.st.el.data('storylink'),
12
- $story_link_text = this.st.el.data('linktext'),
13
- $caption = this.st.el.data('caption'),
14
- $image_url = this.st.el.data('imagelink'),
15
- $iframe_vid_url = this.st.el.data('videolink'),
16
- $video_url = this.st.el.data('video');
17
-
 
 
 
 
 
18
  if($image_url){
19
  $('#efblcf_holder .efbl_popup_image').attr('src', $image_url);
20
  $('#efblcf_holder .efbl_popup_image').css('display', 'block');
@@ -39,28 +44,51 @@ jQuery(document).ready(function($) {
39
 
40
 
41
  }
42
-
 
 
 
 
 
43
  if($caption){
44
  $('#efblcf_holder .efbl_popupp_footer').html('<p>'+$caption+' <a class="efbl_popup_readmore" href="'+$story_link+'" target="_blank">'+$story_link_text+'</a></p>');
45
  $('#efblcf_holder .efbl_popupp_footer').css('display', 'block');
46
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
-
49
  },
 
50
  beforeClose: function (){
51
 
52
- //Clear the container for new instance
53
- $('#efblcf_holder .efbl_popup_image').attr('src', '');
54
- $('#efblcf_holder .efbl_popup_image').css('display', 'none');
55
-
56
- $('#efblcf_holder .efbl_popup_if_video').attr('src', '');
57
- $('#efblcf_holder .efbl_popup_if_video').css('display', 'none');
58
-
59
- $('#efblcf_holder .efbl_popup_video').attr('src', '');
60
- $('#efblcf_holder .efbl_popup_video').css('display', 'none');
61
-
62
- $('#efblcf_holder .efbl_popupp_footer').html('');
63
- $('#efblcf_holder .efbl_popupp_footer').css('display', 'none');
64
 
65
  }
66
  }
@@ -77,5 +105,70 @@ jQuery(document).ready(function($) {
77
  $(this).siblings('.efbl_comments_wraper').toggleClass( "efbl_cwraper_slide" );
78
  });
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  });
1
  jQuery(document).ready(function($) {
2
+
3
+ // Magic function that will prepare and render markup.
4
+ function efbl_render_poup_markup(object){
5
+
6
+ var $story_link = object.data('storylink'),
7
+ $story_link_text = object.data('linktext'),
8
+ $caption = object.data('caption'),
9
+ $image_url = object.data('imagelink'),
10
+ $iframe_vid_url = object.data('videolink'),
11
+ $video_url = object.data('video'),
12
+ $itemnumber = object.data('itemnumber'),
13
+ $windowWidth = window.innerWidth,
14
+ $windowHeight = window.innerHeight - 200;
15
+
16
+ $('.white-popup .efbl_popup_left_container').css({
17
+ "width": "auto",
18
+ "height": ""+$windowHeight+"",
19
+ });
20
+
21
+ $('.efbl_popup_image').css('height', $windowHeight);
22
+
23
  if($image_url){
24
  $('#efblcf_holder .efbl_popup_image').attr('src', $image_url);
25
  $('#efblcf_holder .efbl_popup_image').css('display', 'block');
44
 
45
 
46
  }
47
+
48
+ //$('.efbl-popup-next').attr('data-itemnumber', $itemnumber+1);
49
+ //$('.efbl-popup-prev').attr('data-itemnumber', $itemnumber-1);
50
+
51
+ $('#item_number').val($itemnumber);
52
+
53
  if($caption){
54
  $('#efblcf_holder .efbl_popupp_footer').html('<p>'+$caption+' <a class="efbl_popup_readmore" href="'+$story_link+'" target="_blank">'+$story_link_text+'</a></p>');
55
  $('#efblcf_holder .efbl_popupp_footer').css('display', 'block');
56
  }
57
+
58
+ }
59
+
60
+ function reset_popup_holder(){
61
+ //Clear the container for new instance
62
+ $('#efblcf_holder .efbl_popup_image').attr('src', '');
63
+ $('#efblcf_holder .efbl_popup_image').css('display', 'none');
64
+
65
+ $('#efblcf_holder .efbl_popup_if_video').attr('src', '');
66
+ $('#efblcf_holder .efbl_popup_if_video').css('display', 'none');
67
+
68
+ $('#efblcf_holder .efbl_popup_video').attr('src', '');
69
+ $('#efblcf_holder .efbl_popup_video').css('display', 'none');
70
+
71
+ $('#efblcf_holder .efbl_popupp_footer').html('');
72
+ $('#efblcf_holder .efbl_popupp_footer').css('display', 'none');
73
+ }
74
+
75
+ $('.efbl_feed_popup').magnificPopup({
76
+ type: 'inline',
77
+ preloader: false,
78
+ mainClass: 'mfp-fade',
79
+ // Delay in milliseconds before popup is removed
80
+ removalDelay: 300,
81
+ callbacks: {
82
+ beforeOpen: function() {
83
+ //console.log(this.st.el.next());
84
+
85
+ efbl_render_poup_markup(this.st.el);
86
 
 
87
  },
88
+
89
  beforeClose: function (){
90
 
91
+ reset_popup_holder();
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  }
94
  }
105
  $(this).siblings('.efbl_comments_wraper').toggleClass( "efbl_cwraper_slide" );
106
  });
107
 
108
+ $('body').on('click','.efbl-popup-next',function(){
109
+
110
+ //reset the existing content
111
+ reset_popup_holder();
112
+
113
+
114
+ var $next_pre_itemnumber = $('#item_number').val();
115
+ $next_pre_itemnumber = parseInt ($next_pre_itemnumber) + 1;
116
+ //var $next_pre_itemnumber = $self.data('itemnumber');
117
+
118
+ var numItems = $('.efbl_feed_popup').length
119
+
120
+ if($next_pre_itemnumber > numItems){
121
+ $next_pre_itemnumber = 1;
122
+ }
123
+
124
+ efbl_render_poup_markup($('.efbl-cff-item_number-' + $next_pre_itemnumber));
125
+ //$('.mfp-close').trigger('click');
126
+
127
+ // setTimeout(function(){
128
+ // $('.efbl-cff-item_number-'+$next_pre_itemnumber).trigger('click');
129
+ // }, 320)
130
+
131
+
132
+ });
133
+
134
+ $('body').on('click','.efbl-popup-prev',function(){
135
+
136
+ //reset the existing content
137
+ reset_popup_holder();
138
+
139
+ var $next_pre_itemnumber = $('#item_number').val();
140
+
141
+ var numItems = $('.efbl_feed_popup').length
142
+ if($next_pre_itemnumber == 1){
143
+ $next_pre_itemnumber = numItems;
144
+ }else{
145
+ $next_pre_itemnumber = parseInt($next_pre_itemnumber) - 1;
146
+
147
+ }
148
+
149
+ efbl_render_poup_markup($('.efbl-cff-item_number-'+$next_pre_itemnumber));
150
+
151
+ });
152
+
153
+ /*
154
+ * Check if the like box has loaded. If yes then remove loader and add animation class!
155
+ */
156
+
157
+ window.onload = function() {
158
+ FB.Event.subscribe('xfbml.render', function(response) {
159
+ var animclasses = $('.efbl-like-box .fb-page').data('animclass');
160
+
161
+ $('.efbl-loader').remove();
162
+
163
+ $('.efbl-like-box iframe').addClass('animated ' + animclasses);
164
+
165
+ });
166
+
167
+ };
168
+
169
+
170
+
171
+
172
+
173
 
174
  });
public/easy-facebook-likebox.php CHANGED
@@ -34,7 +34,7 @@ class Easy_Facebook_Likebox {
34
  *
35
  * @var string
36
  */
37
- const VERSION = '4.3.0';
38
 
39
  /**
40
  * @TODO - Rename "plugin-name" to the name your your plugin
@@ -61,6 +61,15 @@ class Easy_Facebook_Likebox {
61
  */
62
  protected static $instance = null;
63
 
 
 
 
 
 
 
 
 
 
64
  /**
65
  * Initialize the plugin by setting localization and loading public scripts
66
  * and styles.
@@ -274,6 +283,8 @@ class Easy_Facebook_Likebox {
274
  */
275
  public function enqueue_styles() {
276
  wp_enqueue_style( $this->plugin_slug . '-plugin-styles', plugins_url( 'assets/css/public.css', __FILE__ ), array(), self::VERSION );
 
 
277
 
278
  wp_enqueue_style( $this->plugin_slug . '-popup-styles', plugins_url( 'assets/popup/magnific-popup.css', __FILE__ ), array(), self::VERSION );
279
  }
@@ -302,9 +313,12 @@ class Easy_Facebook_Likebox {
302
 
303
  public function efb_feed_shortcode($atts, $content=""){
304
  return $this->render_fbfeed_box($atts);
 
 
305
  }
306
 
307
  public function render_fbfeed_box($atts) {
 
308
  $defaults = '';
309
  $instance = wp_parse_args( (array) $atts, $defaults );
310
 
@@ -327,6 +341,7 @@ class Easy_Facebook_Likebox {
327
  *
328
  * @since 4.0
329
  */
 
330
  public function render_fb_page_plugin($options) {
331
  /*echo "<pre>";
332
  print_r($options);
@@ -355,20 +370,32 @@ class Easy_Facebook_Likebox {
355
  $responsive = ( $responsive == 1 ) ? 'data-adapt-container-width=true' : 'data-adapt-container-width=false';
356
  $hide_cta = ( $hide_cta == 1 ) ? 'data-hide-cta=true' : 'data-hide-cta=false';
357
  $small_header = ( $small_header == 1 ) ? 'data-small-header="true"' : 'data-small-header="false"' ;
358
-
 
 
359
  $returner = '<div id="fb-root"></div>
360
  <script>(function(d, s, id) {
361
  var js, fjs = d.getElementsByTagName(s)[0];
362
  if (d.getElementById(id)) return;
363
  js = d.createElement(s); js.id = id;
 
364
  js.src = "//connect.facebook.net/'.$locale.'/all.js#xfbml=1&appId='.$fb_appid.'";
365
  fjs.parentNode.insertBefore(js, fjs);
366
  }(document, \'script\', \'facebook-jssdk\'));</script>';
367
-
368
- $returner .= '<div class="fb-page " data-href="https://www.facebook.com/'.$page_name_id.'" '.$hide_cover.' data-width="'.$box_width.'" data-height="'.$box_height.'" '.$show_faces.' '.$show_stream.' '.$responsive.' '.$hide_cta.' '.$small_header.'></div>';
 
 
 
 
 
 
 
 
369
 
370
  return $returner;
371
-
 
372
  }
373
 
374
  function efbl_display_popup(){
34
  *
35
  * @var string
36
  */
37
+ const VERSION = '4.3.1';
38
 
39
  /**
40
  * @TODO - Rename "plugin-name" to the name your your plugin
61
  */
62
  protected static $instance = null;
63
 
64
+ /**
65
+ * Instance of the like box render funcion
66
+ *
67
+ * @since 1.1.0
68
+ *
69
+ * @var object
70
+ */
71
+ public $likebox_instance = 1;
72
+
73
  /**
74
  * Initialize the plugin by setting localization and loading public scripts
75
  * and styles.
283
  */
284
  public function enqueue_styles() {
285
  wp_enqueue_style( $this->plugin_slug . '-plugin-styles', plugins_url( 'assets/css/public.css', __FILE__ ), array(), self::VERSION );
286
+
287
+ wp_enqueue_style( $this->plugin_slug . '-animate', plugins_url( 'assets/css/animate.css', __FILE__ ), array(), self::VERSION );
288
 
289
  wp_enqueue_style( $this->plugin_slug . '-popup-styles', plugins_url( 'assets/popup/magnific-popup.css', __FILE__ ), array(), self::VERSION );
290
  }
313
 
314
  public function efb_feed_shortcode($atts, $content=""){
315
  return $this->render_fbfeed_box($atts);
316
+
317
+
318
  }
319
 
320
  public function render_fbfeed_box($atts) {
321
+
322
  $defaults = '';
323
  $instance = wp_parse_args( (array) $atts, $defaults );
324
 
341
  *
342
  * @since 4.0
343
  */
344
+
345
  public function render_fb_page_plugin($options) {
346
  /*echo "<pre>";
347
  print_r($options);
370
  $responsive = ( $responsive == 1 ) ? 'data-adapt-container-width=true' : 'data-adapt-container-width=false';
371
  $hide_cta = ( $hide_cta == 1 ) ? 'data-hide-cta=true' : 'data-hide-cta=false';
372
  $small_header = ( $small_header == 1 ) ? 'data-small-header="true"' : 'data-small-header="false"' ;
373
+
374
+ $preLoader = plugins_url( 'assets/images/loader.gif', __FILE__ );
375
+
376
  $returner = '<div id="fb-root"></div>
377
  <script>(function(d, s, id) {
378
  var js, fjs = d.getElementsByTagName(s)[0];
379
  if (d.getElementById(id)) return;
380
  js = d.createElement(s); js.id = id;
381
+ js.async=true;
382
  js.src = "//connect.facebook.net/'.$locale.'/all.js#xfbml=1&appId='.$fb_appid.'";
383
  fjs.parentNode.insertBefore(js, fjs);
384
  }(document, \'script\', \'facebook-jssdk\'));</script>';
385
+
386
+ $likebox_instance = $this->likebox_instance;
387
+
388
+ $returner .= ' <div class="efbl-like-box '.$likebox_instance.'">
389
+ <img class="efbl-loader" src="'.$preLoader.'" >
390
+ <div class="fb-page" data-animclass="'.$animate_effect.'" data-href="https://www.facebook.com/'.$page_name_id.'" '.$hide_cover.' data-width="'.$box_width.'" data-height="'.$box_height.'" '.$show_faces.' '.$show_stream.' '.$responsive.' '.$hide_cta.' '.$small_header.'>
391
+ </div>
392
+
393
+ </div>
394
+ ';
395
 
396
  return $returner;
397
+
398
+ $this->likebox_instance++;
399
  }
400
 
401
  function efbl_display_popup(){
public/includes/core-functions.php CHANGED
@@ -108,5 +108,180 @@ if(!function_exists('efbl_parse_url')){
108
 
109
  return $fanpage_url;
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  }
112
  }
108
 
109
  return $fanpage_url;
110
 
111
+ }
112
+ }
113
+
114
+ if(!function_exists('efbl_get_locales')){
115
+ /**
116
+ * Compile and filter the list of locales.
117
+ *
118
+ *
119
+ * @return return the list of locales.
120
+ */
121
+ function efbl_get_locales(){
122
+
123
+ $locales = array( 'af_ZA' => 'Afrikaans',
124
+ 'ar_AR' => 'Arabic',
125
+ 'az_AZ' => 'Azeri',
126
+ 'be_BY' => 'Belarusian',
127
+ 'bg_BG' => 'Bulgarian',
128
+ 'bn_IN' => 'Bengali',
129
+ 'bs_BA' => 'Bosnian',
130
+ 'ca_ES' => 'Catalan',
131
+ 'cs_CZ' => 'Czech',
132
+ 'cy_GB' => 'Welsh',
133
+ 'da_DK' => 'Danish',
134
+ 'de_DE' => 'German',
135
+ 'el_GR' => 'Greek',
136
+ 'en_US' => 'English (US)',
137
+ 'en_GB' => 'English (UK)',
138
+ 'eo_EO' => 'Esperanto',
139
+ 'es_ES' => 'Spanish (Spain)',
140
+ 'es_LA' => 'Spanish',
141
+ 'et_EE' => 'Estonian',
142
+ 'eu_ES' => 'Basque',
143
+ 'fa_IR' => 'Persian',
144
+ 'fb_LT' => 'Leet Speak',
145
+ 'fi_FI' => 'Finnish',
146
+ 'fo_FO' => 'Faroese',
147
+ 'fr_FR' => 'French (France)',
148
+ 'fr_CA' => 'French (Canada)',
149
+ 'fy_NL' => 'NETHERLANDS (NL)',
150
+ 'ga_IE' => 'Irish',
151
+ 'gl_ES' => 'Galician',
152
+ 'hi_IN' => 'Hindi',
153
+ 'hr_HR' => 'Croatian',
154
+ 'hu_HU' => 'Hungarian',
155
+ 'hy_AM' => 'Armenian',
156
+ 'id_ID' => 'Indonesian',
157
+ 'is_IS' => 'Icelandic',
158
+ 'it_IT' => 'Italian',
159
+ 'ja_JP' => 'Japanese',
160
+ 'ka_GE' => 'Georgian',
161
+ 'km_KH' => 'Khmer',
162
+ 'ko_KR' => 'Korean',
163
+ 'ku_TR' => 'Kurdish',
164
+ 'la_VA' => 'Latin',
165
+ 'lt_LT' => 'Lithuanian',
166
+ 'lv_LV' => 'Latvian',
167
+ 'mk_MK' => 'Macedonian',
168
+ 'ml_IN' => 'Malayalam',
169
+ 'ms_MY' => 'Malay',
170
+ 'nb_NO' => 'Norwegian (bokmal)',
171
+ 'ne_NP' => 'Nepali',
172
+ 'nl_NL' => 'Dutch',
173
+ 'nn_NO' => 'Norwegian (nynorsk)',
174
+ 'pa_IN' => 'Punjabi',
175
+ 'pl_PL' => 'Polish',
176
+ 'ps_AF' => 'Pashto',
177
+ 'pt_PT' => 'Portuguese (Portugal)',
178
+ 'pt_BR' => 'Portuguese (Brazil)',
179
+ 'ro_RO' => 'Romanian',
180
+ 'ru_RU' => 'Russian',
181
+ 'sk_SK' => 'Slovak',
182
+ 'sl_SI' => 'Slovenian',
183
+ 'sq_AL' => 'Albanian',
184
+ 'sr_RS' => 'Serbian',
185
+ 'sv_SE' => 'Swedish',
186
+ 'sw_KE' => 'Swahili',
187
+ 'ta_IN' => 'Tamil',
188
+ 'te_IN' => 'Telugu',
189
+ 'th_TH' => 'Thai',
190
+ 'tl_PH' => 'Filipino',
191
+ 'tr_TR' => 'Turkish',
192
+ 'uk_UA' => 'Ukrainian',
193
+ 'ur_PK' => 'Urdu',
194
+ 'vi_VN' => 'Vietnamese',
195
+ 'zh_CN' => 'Simplified Chinese (China)',
196
+ 'zh_HK' => 'Traditional Chinese (Hong Kong)',
197
+ 'zh_TW' => 'Traditional Chinese (Taiwan)',
198
+ );
199
+
200
+ return apply_filters(
201
+ 'efbl_locale_names',
202
+ $locales
203
+ );
204
+ }
205
+ }
206
+ if( !function_exists( 'get_css3_animations' ) ){
207
+ function get_css3_animations(){
208
+
209
+ $css3_effects = array(
210
+ 'Static' => array(
211
+ 'No Effect',
212
+ ),
213
+ 'Attention Seekers' => array(
214
+ 'bounce',
215
+ 'flash',
216
+ 'pulse',
217
+ 'rubberBand',
218
+ 'shake',
219
+ 'swing',
220
+ ),
221
+
222
+ 'Bouncing Entrances' => array(
223
+ 'bounceIn',
224
+ 'bounceInDown',
225
+ 'bounceInLeft',
226
+ 'bounceInRight',
227
+ 'bounceInUp',
228
+ ),
229
+
230
+ 'Fading Entrances' => array(
231
+ 'fadeIn',
232
+ 'fadeInDown',
233
+ 'fadeInDownBig',
234
+ 'fadeInLeft',
235
+ 'fadeInLeftBig',
236
+ 'fadeInRight',
237
+ 'fadeInRightBig',
238
+ 'fadeInUp',
239
+ 'fadeInUpBig',
240
+ ),
241
+
242
+ 'Flippers' => array(
243
+ 'flip',
244
+ 'flipInX',
245
+ 'flipInY',
246
+ 'flipOutX',
247
+ 'flipOutY',
248
+ ),
249
+
250
+ 'Rotating Entrances' => array(
251
+ 'rotateIn',
252
+ 'rotateInDownLeft',
253
+ 'rotateInDownRight',
254
+ 'rotateInUpLeft',
255
+ 'rotateInUpRight',
256
+ ),
257
+
258
+ 'Sliding Entrances' => array(
259
+ 'slideInUp',
260
+ 'slideInDown',
261
+ 'slideInLeft',
262
+ 'rotateInUpLeft',
263
+ 'slideInRight',
264
+ ),
265
+
266
+ 'Zoom Entrances' => array(
267
+ 'zoomIn',
268
+ 'zoomInDown',
269
+ 'zoomInLeft',
270
+ 'zoomInRight',
271
+ 'zoomInUp',
272
+ ),
273
+
274
+ 'Specials' => array(
275
+ 'hinge',
276
+ 'rollIn',
277
+ 'rollOut',
278
+ ),
279
+ );
280
+
281
+ return apply_filters(
282
+ 'efbl_css3_effects',
283
+ $css3_effects
284
+ );
285
+
286
  }
287
  }
public/views/feed.php CHANGED
@@ -13,10 +13,9 @@
13
 
14
 
15
  extract($instance);
16
- //error_reporting( E_ERROR | E_PARSE );
17
- error_reporting( 0 );
18
  //Switch to test mode to disable cache
19
- $test_mode = false;
20
  if(empty($fanpage_url)){
21
  $page_id = 'jwebsol';
22
  }else {
@@ -202,11 +201,8 @@ if( !empty($fbData->data) ) {
202
  //Get the image suource of author
203
  $auth_img_src = 'https://graph.facebook.com/' . $page_id . '/picture?type=large';
204
 
205
- if( !isset( $author_image ) ){
206
  //get author image src
207
  $author_image ='<a href="https://facebook.com/'.$page_id.'" target="'.$link_target.'"><img src="'.$auth_img_src.'" title="'. $story->from->name .'" width="40" height="40" /></a>';
208
- }
209
-
210
  if($story->object_id and $show_image){
211
 
212
  //Get story image
@@ -294,7 +290,8 @@ if( !empty($fbData->data) ) {
294
  </div>
295
 
296
  </div>';
297
-
 
298
  //Story content
299
  $story_content = '<p class="efbl_story_text">'.($post_text).'</a>';
300
 
@@ -517,7 +514,10 @@ if( !empty($fbData->data) ) {
517
  <img src="" class="efbl_popup_image" />
518
  <iframe src="" class="efbl_popup_if_video" ></iframe>
519
  <video src="" class="efbl_popup_video" id="html_video" controls></video>
520
-
 
 
 
521
  </div>
522
 
523
  <div class="efbl_popupp_footer">
13
 
14
 
15
  extract($instance);
16
+ error_reporting( E_ERROR | E_PARSE );
 
17
  //Switch to test mode to disable cache
18
+ $test_mode = true;
19
  if(empty($fanpage_url)){
20
  $page_id = 'jwebsol';
21
  }else {
201
  //Get the image suource of author
202
  $auth_img_src = 'https://graph.facebook.com/' . $page_id . '/picture?type=large';
203
 
 
204
  //get author image src
205
  $author_image ='<a href="https://facebook.com/'.$page_id.'" target="'.$link_target.'"><img src="'.$auth_img_src.'" title="'. $story->from->name .'" width="40" height="40" /></a>';
 
 
206
  if($story->object_id and $show_image){
207
 
208
  //Get story image
290
  </div>
291
 
292
  </div>';
293
+
294
+
295
  //Story content
296
  $story_content = '<p class="efbl_story_text">'.($post_text).'</a>';
297
 
514
  <img src="" class="efbl_popup_image" />
515
  <iframe src="" class="efbl_popup_if_video" ></iframe>
516
  <video src="" class="efbl_popup_video" id="html_video" controls></video>
517
+ <div class="efbl-popup-nav">
518
+ <a class="efbl-popup-prev"><i class="fa fa-angle-left" aria-hidden="true"></i></a>
519
+ <a class="efbl-popup-next"><i class="fa fa-angle-right" aria-hidden="true"></i></a>
520
+ </div>
521
  </div>
522
 
523
  <div class="efbl_popupp_footer">