404 to 301 - Version 3.0.0

Version Description

(20/06/2018) = New Features

  • Individual optional settings for each error log item (Individual redirec, log, email alert can be set).
  • Clear error logs without removing custom redirects.
  • Added error logs grouping with count.
  • WPML compatible.
  • Integrated Freemius for addon, support and analytics (optional).

Improvements

  • Complete code revamp. More improved structure.
  • Set custom options from previous logs if same item exists.
  • Made 3rd party integration easier.
Download this release

Release Info

Developer joelcj91
Plugin Icon 128x128 404 to 301
Version 3.0.0
Comparing to
See all releases

Code changes from version 2.3.3 to 3.0.0

Files changed (112) hide show
  1. 404-to-301.php +135 -87
  2. LICENSE +674 -0
  3. README.md +26 -0
  4. admin/class-404-to-301-admin.php +0 -559
  5. admin/class-404-to-301-logs.php +0 -601
  6. admin/core/class-wp-list-table-4.4.php +0 -1377
  7. admin/core/class-wp-list-table-old.php +0 -1143
  8. admin/css/min/admin.css +0 -49
  9. admin/images/foxe.png +0 -0
  10. admin/js/admin.js +0 -75
  11. admin/partials/404-to-301-admin-agreement-tab.php +0 -52
  12. admin/partials/404-to-301-admin-credits-tab.php +0 -103
  13. admin/partials/404-to-301-admin-custom-redirect.php +0 -37
  14. admin/partials/404-to-301-admin-display.php +0 -58
  15. admin/partials/404-to-301-admin-general-tab.php +0 -110
  16. composer.json +11 -0
  17. includes/admin/class-jj4t3-admin.php +376 -0
  18. includes/admin/class-jj4t3-log-listing.php +1002 -0
  19. includes/admin/css/admin.css +36 -0
  20. includes/admin/css/admin.min.css +1 -0
  21. {admin → includes/admin}/css/index.php +0 -0
  22. includes/admin/images/gray-grad.png +0 -0
  23. {admin/css/min → includes/admin/images}/index.php +0 -0
  24. {admin/images → includes/admin}/index.php +0 -0
  25. includes/admin/js/admin.js +112 -0
  26. includes/admin/js/admin.min.js +1 -0
  27. {admin → includes/admin/js}/index.php +0 -0
  28. includes/admin/views/admin.php +33 -0
  29. includes/admin/views/custom-redirect.php +71 -0
  30. {admin/js → includes/admin/views}/index.php +0 -0
  31. includes/admin/views/settings.php +90 -0
  32. includes/class-404-to-301-activator.php +0 -90
  33. includes/class-404-to-301-i18n.php +0 -39
  34. includes/class-404-to-301-loader.php +0 -143
  35. includes/class-404-to-301.php +0 -178
  36. includes/class-jj-404-to-301.php +139 -0
  37. includes/class-jj4t3-activator-deactivator-uninstaller.php +145 -0
  38. includes/class-jj4t3-i18n.php +43 -0
  39. {admin/partials → includes/functions}/index.php +0 -0
  40. includes/functions/jj4t3-general-functions.php +376 -0
  41. includes/public/class-jj4t3-404-actions.php +445 -0
  42. includes/public/class-jj4t3-404-data.php +253 -0
  43. includes/public/class-jj4t3-404-email.php +223 -0
  44. includes/public/class-jj4t3-404-logging.php +99 -0
  45. {public → includes/public}/index.php +0 -0
  46. languages/404-to-301-pt_PT.mo +0 -0
  47. languages/404-to-301-pt_PT.po +496 -514
  48. languages/404-to-301.pot +135 -498
  49. languages/index.php +1 -0
  50. public/class-404-to-301-public.php +0 -371
  51. readme.txt +33 -19
  52. screenshot-1.png +0 -0
  53. screenshot-2.png +0 -0
  54. screenshot-3.png +0 -0
  55. uninstall.php +0 -38
  56. vendor/freemius/.github/ISSUE_TEMPLATE.md +29 -0
  57. vendor/freemius/LICENSE.txt +674 -0
  58. vendor/freemius/assets/css/admin/account.css +1 -0
  59. vendor/freemius/assets/css/admin/add-ons.css +2 -0
  60. vendor/freemius/assets/css/admin/affiliation.css +1 -0
  61. vendor/freemius/assets/css/admin/checkout.css +1 -0
  62. vendor/freemius/assets/css/admin/common.css +2 -0
  63. vendor/freemius/assets/css/admin/connect.css +1 -0
  64. vendor/freemius/assets/css/admin/deactivation-feedback.css +1 -0
  65. vendor/freemius/assets/css/admin/debug.css +1 -0
  66. vendor/freemius/assets/css/admin/dialog-boxes.css +2 -0
  67. vendor/freemius/assets/css/admin/gdpr-optin-notice.css +1 -0
  68. vendor/freemius/assets/css/admin/index.php +3 -0
  69. vendor/freemius/assets/css/admin/license-activation.css +1 -0
  70. vendor/freemius/assets/css/customizer.css +1 -0
  71. vendor/freemius/assets/css/index.php +3 -0
  72. vendor/freemius/assets/img/404-to-301-log-manager.png +0 -0
  73. vendor/freemius/assets/img/404-to-301.png +0 -0
  74. vendor/freemius/assets/img/index.php +3 -0
  75. vendor/freemius/assets/img/plugin-icon.png +0 -0
  76. vendor/freemius/assets/img/theme-icon.png +0 -0
  77. vendor/freemius/assets/index.php +3 -0
  78. vendor/freemius/assets/js/index.php +3 -0
  79. vendor/freemius/assets/js/nojquery.ba-postmessage.js +140 -0
  80. vendor/freemius/assets/js/nojquery.ba-postmessage.min.js +12 -0
  81. vendor/freemius/assets/js/postmessage.js +135 -0
  82. vendor/freemius/assets/scss/_colors.scss +68 -0
  83. vendor/freemius/assets/scss/_functions.scss +0 -0
  84. vendor/freemius/assets/scss/_load.scss +4 -0
  85. vendor/freemius/assets/scss/_mixins.scss +270 -0
  86. vendor/freemius/assets/scss/_start.scss +4 -0
  87. vendor/freemius/assets/scss/_vars.scss +6 -0
  88. vendor/freemius/assets/scss/admin/_ajax-loader.scss +49 -0
  89. vendor/freemius/assets/scss/admin/_auto-install.scss +33 -0
  90. vendor/freemius/assets/scss/admin/_deactivation-feedback.scss +55 -0
  91. vendor/freemius/assets/scss/admin/_gdpr-consent.scss +81 -0
  92. vendor/freemius/assets/scss/admin/_license-activation.scss +47 -0
  93. vendor/freemius/assets/scss/admin/_license-key-resend.scss +68 -0
  94. vendor/freemius/assets/scss/admin/_modal-common.scss +194 -0
  95. vendor/freemius/assets/scss/admin/_multisite-options.scss +40 -0
  96. vendor/freemius/assets/scss/admin/_themes.scss +21 -0
  97. vendor/freemius/assets/scss/admin/_tooltip.scss +66 -0
  98. vendor/freemius/assets/scss/admin/account.scss +302 -0
  99. vendor/freemius/assets/scss/admin/add-ons.scss +449 -0
  100. vendor/freemius/assets/scss/admin/affiliation.scss +97 -0
  101. vendor/freemius/assets/scss/admin/checkout.scss +5 -0
  102. vendor/freemius/assets/scss/admin/common.scss +218 -0
  103. vendor/freemius/assets/scss/admin/connect.scss +548 -0
  104. vendor/freemius/assets/scss/admin/debug.scss +135 -0
  105. vendor/freemius/assets/scss/admin/dialog-boxes.scss +8 -0
  106. vendor/freemius/assets/scss/admin/gdpr-optin-notice.scss +17 -0
  107. vendor/freemius/assets/scss/admin/index.php +3 -0
  108. vendor/freemius/assets/scss/customizer.scss +125 -0
  109. vendor/freemius/assets/scss/index.php +3 -0
  110. vendor/freemius/config.php +388 -0
  111. vendor/freemius/includes/class-freemius-abstract.php +597 -0
  112. vendor/freemius/includes/class-freemius.php +12053 -0
404-to-301.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
  /**
3
  * Plugin Name: 404 to 301
4
- * Plugin URI: https://thefoxe.com/products/404-to-301/
5
  * Description: Automatically redirect all <strong>404 errors</strong> to any page using <strong>301 redirect for SEO</strong>. You can <strong>redirect and log</strong> every 404 errors. No more 404 errors in Webmaster tool.
6
- * Version: 2.3.3
7
  * Author: Joel James
8
- * Author URI: https://thefoxe.com/
9
- * Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4
10
  * License: GPL-2.0+
11
- * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
  * Text Domain: 404-to-301
13
  * Domain Path: /languages
14
  *
@@ -24,89 +24,137 @@
24
  *
25
  * You should have received a copy of the GNU General Public License
26
  * along with 404 to 301. If not, see <http://www.gnu.org/licenses/>.
27
- *
28
  * @category Core
29
- * @package I4T3
30
- * @author Joel James <me@joelsays.com>
31
  * @license http://www.gnu.org/licenses/ GNU General Public License
32
- * @link https://thefoxe.com/products/404-to-301
33
  */
 
34
  // If this file is called directly, abort.
35
- if ( ! defined( 'WPINC' ) ) {
36
- die( 'Damn it.! Dude you are looking for what?' );
37
- }
38
-
39
- if ( ! class_exists( '_404_To_301' ) ) {
40
-
41
- // Constants array
42
- $constants = array(
43
- 'I4T3_NAME' => '404-to-301',
44
- 'I4T3_DOMAIN' => '404-to-301',
45
- 'I4T3_PATH' => plugins_url( '/404-to-301/' ),
46
- 'I4T3_PLUGIN_DIR' => dirname(__FILE__),
47
- 'I4T3_BASE' => __FILE__,
48
- 'I4T3_SETTINGS_PAGE' => admin_url( 'admin.php?page=i4t3-settings' ),
49
- 'I4T3_HELP_PAGE' => admin_url( 'admin.php?page=i4t3-settings&tab=credits' ),
50
- 'I4T3_LOGS_PAGE' => admin_url( 'admin.php?page=i4t3-logs' ),
51
- 'I4T3_DB_VERSION' => '8',
52
- 'I4T3_VERSION' => '2.3.3',
53
- 'I4T3_TABLE' => $GLOBALS['wpdb']->prefix . '404_to_301',
54
- // Set who all can access 404 settings.
55
- // You can change this if you want to give others access.
56
- 'I4T3_ADMIN_PERMISSION' => 'manage_options'
57
- );
58
-
59
- foreach ($constants as $constant => $value) {
60
- // Define constants if not defined already
61
- if ( ! defined( $constant ) ) {
62
- define( $constant, $value );
63
- }
64
- }
65
-
66
- /**
67
- * The function that runs during plugin activation.
68
- *
69
- * @since 2.0.0
70
- * @access public
71
- *
72
- * @return void
73
- */
74
- function activate_i4t3() {
75
-
76
- include_once I4T3_PLUGIN_DIR . '/includes/class-404-to-301-activator.php';
77
-
78
- _404_To_301_Activator::activate();
79
- }
80
-
81
- // plugin activation hook
82
- register_activation_hook(__FILE__, 'activate_i4t3');
83
-
84
- /**
85
- * The core plugin class that is used to define
86
- * dashboard-specific hooks, and public-facing site hooks.
87
- */
88
- require_once plugin_dir_path(__FILE__) . 'includes/class-404-to-301.php';
89
-
90
- /**
91
- * Begins execution of the plugin.
92
- *
93
- * Since everything within the plugin is registered via hooks,
94
- * then kicking off the plugin from this point in the file does
95
- * not affect the page life cycle.
96
- *
97
- * @since 2.0.0
98
- * @access public
99
- *
100
- * @return void
101
- */
102
- function run_i4t3() {
103
-
104
- $plugin = new _404_To_301();
105
- $plugin->run();
106
- }
107
-
108
- run_i4t3();
109
-
110
- }
111
-
112
- //*** Thank you for your interest in 404 to 301 - Developed and managed by Joel James ***//
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
  * Plugin Name: 404 to 301
4
+ * Plugin URI: https://duckdev.com/products/404-to-301/
5
  * Description: Automatically redirect all <strong>404 errors</strong> to any page using <strong>301 redirect for SEO</strong>. You can <strong>redirect and log</strong> every 404 errors. No more 404 errors in Webmaster tool.
6
+ * Version: 3.0.0
7
  * Author: Joel James
8
+ * Author URI: https://duckdev.com/
9
+ * Donate link: https://paypal.me/JoelCJ
10
  * License: GPL-2.0+
11
+ * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
12
  * Text Domain: 404-to-301
13
  * Domain Path: /languages
14
  *
24
  *
25
  * You should have received a copy of the GNU General Public License
26
  * along with 404 to 301. If not, see <http://www.gnu.org/licenses/>.
27
+ *
28
  * @category Core
29
+ * @package JJ4T3
30
+ * @author Joel James <mail@cjoel.com>
31
  * @license http://www.gnu.org/licenses/ GNU General Public License
32
+ * @link https://duckdev.com/products/404-to-301/
33
  */
34
+
35
  // If this file is called directly, abort.
36
+ defined( 'ABSPATH' ) or exit;
37
+
38
+ // Stay lazy if our class is already there.
39
+ if ( ! class_exists( 'JJ_404_to_301' ) ) :
40
+
41
+ /**
42
+ * File that contains main plugin class.
43
+ */
44
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-jj-404-to-301.php';
45
+
46
+ /**
47
+ * Setup plugin constants.
48
+ *
49
+ * We need a few constants in our plugin.
50
+ * These values should be constant and con't
51
+ * be altered later.
52
+ *
53
+ * @since 2.0.0
54
+ * @access private
55
+ *
56
+ * @return void
57
+ */
58
+ function jj4t3_set_constants() {
59
+
60
+ $constants = array(
61
+ 'JJ4T3_NAME' => '404-to-301',
62
+ 'JJ4T3_DOMAIN' => '404-to-301',
63
+ 'JJ4T3_DIR' => plugin_dir_path( __FILE__ ),
64
+ 'JJ4T3_URL' => plugin_dir_url( __FILE__ ),
65
+ 'JJ4T3_BASE_FILE' => __FILE__,
66
+ 'JJ4T3_VERSION' => '3.0.0',
67
+ 'JJ4T3_DB_VERSION' => '11.0',
68
+ 'JJ4T3_TABLE' => $GLOBALS['wpdb']->prefix . '404_to_301',
69
+ // Set who all can access plugin settings.
70
+ // You can change this if you want to give others access.
71
+ 'JJ4T3_ACCESS' => 'manage_options',
72
+ );
73
+
74
+ foreach ( $constants as $constant => $value ) {
75
+ if ( ! defined( $constant ) ) {
76
+ define( $constant, $value );
77
+ }
78
+ }
79
+ }
80
+
81
+ /**
82
+ * The main function for that returns JJ_404_to_301
83
+ *
84
+ * The main function responsible for returning the one true JJ_404_to_301
85
+ * instance to functions everywhere.
86
+ *
87
+ * Use this function like you would a global variable, except without needing
88
+ * to declare the global.
89
+ *
90
+ * Example: <?php $jj4t3 = JJ_404_to_301(); ?>
91
+ *
92
+ * @since 3.0.0
93
+ *
94
+ * @return JJ_404_to_301|object
95
+ */
96
+ function JJ_404_to_301() {
97
+
98
+ return JJ_404_to_301::instance();
99
+ }
100
+
101
+ /**
102
+ * Create a helper function for easy SDK access.
103
+ *
104
+ * This function is used to integrate Freemius SDK to 404 to 301 plugin
105
+ * for addons, support and analytics (if allowed).
106
+ *
107
+ * @since 3.0.0
108
+ *
109
+ * @return Freemius
110
+ */
111
+ function jj4t3_freemius() {
112
+
113
+ global $jj4t3_fs;
114
+
115
+ // If freemius is already initialized.
116
+ if ( ! isset( $jj4t3_fs ) ) {
117
+
118
+ // Include Freemius SDK.
119
+ require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
120
+
121
+ // Initialize freemius sdk.
122
+ $jj4t3_fs = fs_dynamic_init( array(
123
+ 'id' => '2192',
124
+ 'slug' => '404-to-301',
125
+ 'type' => 'plugin',
126
+ 'public_key' => 'pk_9d470f3128e5e491ea5a2da6bf4bf',
127
+ 'is_premium' => false,
128
+ 'has_addons' => true,
129
+ 'has_paid_plans' => false,
130
+ 'menu' => array(
131
+ 'slug' => 'jj4t3-logs',
132
+ 'account' => false,
133
+ 'support' => false,
134
+ 'contact' => false,
135
+ ),
136
+ ) );
137
+ }
138
+
139
+ return $jj4t3_fs;
140
+ }
141
+
142
+ // Set constants.
143
+ jj4t3_set_constants();
144
+
145
+ // Init Freemius.
146
+ jj4t3_freemius();
147
+
148
+ // Init 404 to 301.
149
+ JJ_404_to_301();
150
+
151
+ // Uninstaller for 404 to 301.
152
+ jj4t3_freemius()->add_action( 'after_uninstall', array(
153
+ 'JJ4T3_Activator_Deactivator_Uninstaller',
154
+ 'uninstall'
155
+ ) );
156
+
157
+ // Signal that SDK was initiated.
158
+ do_action( 'jj4t3_fs_loaded' );
159
+
160
+ endif; // End if class_exists check.
LICENSE ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ {one line to give the program's name and a brief idea of what it does.}
635
+ Copyright (C) {year} {name of author}
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ {project} Copyright (C) {year} {fullname}
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <http://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
README.md ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ > ####WARNING: This latest version is not live yet. Use with caution!
2
+
3
+ # [404 to 301](https://wordpress.org/plugins/404-to-301) - No more 404 errors!
4
+
5
+ Automatically redirect all 404 errors to any page using 301 redirect to boost your SEO in WordPress. This plugin also can log all 404 erros and list it to you. Also you can optionally get email alerts on 404 errors!
6
+
7
+ <hr/>
8
+
9
+ <strong>Contributors:</strong> <a href="https://github.com/joel-james/">Joel James</a>, <a href="https://github.com/gaiusmathew/">Gaius Mathew</a><br/>
10
+ <strong>Requires at least:</strong> WordPress 3.0<br/>
11
+ <strong>Tested up to:</strong> WordPress 4.9<br/>
12
+ <strong>Stable tag:</strong> 3.0.0<br/>
13
+
14
+ <h4>Important Links and Documentation</h4>
15
+
16
+ <ul>
17
+ <li><a href="https://duckdev.com/products/404-to-301/"><strong>Plugin Website</strong></a></li>
18
+ <li><a href="https://wordpress.org/plugins/404-to-301/"><strong>WordPress Page</strong></a></li>
19
+ <li><a href="https://wordpress.org/support/plugin/404-to-301/"><strong>Plugin Support Forum</strong></a></li>
20
+ <li><a href="https://duckdev.com/support/docs/category/404-to-301/"><strong>Documentation</strong></a></li>
21
+ </ul>
22
+
23
+
24
+ <pre>Pull requests are always welcome!</pre>
25
+
26
+ <strong>PS</strong>: Send pull request to <strong>dev</strong> branch
admin/class-404-to-301-admin.php DELETED
@@ -1,559 +0,0 @@
1
- <?php
2
-
3
- // If this file is called directly, abort.
4
- if (!defined('WPINC')) {
5
- die('Damn it.! Dude you are looking for what?');
6
- }
7
-
8
- /**
9
- * The dashboard-specific functionality of the plugin.
10
- *
11
- * Defines the plugin name, version, and enqueue the dashboard-specific stylesheet, JavaScript
12
- * and all other admin side functions.
13
- *
14
- * @category Core
15
- * @package I4T3
16
- * @subpackage Admin
17
- * @author Joel James <me@joelsays.com>
18
- * @license http://www.gnu.org/licenses/ GNU General Public License
19
- * @link https://thefoxe.com/products/404-to-301
20
- */
21
- class _404_To_301_Admin {
22
-
23
- /**
24
- * The options from db.
25
- *
26
- * @since 2.0.0
27
- * @access private
28
- * @var string $gnrl_options Get the options saved in db.
29
- */
30
- private $gnrl_options;
31
-
32
- /**
33
- * The logs list table.
34
- *
35
- * @since 2.1.0
36
- * @access private
37
- * @var mixed $list_table Class object for listing table.
38
- */
39
- private $list_table;
40
-
41
- /**
42
- * Initialize the class and set its properties.
43
- *
44
- * @since 2.0.0
45
- * @access public
46
- *
47
- * @var string $gnrl_options The option settings of the plugin.
48
- *
49
- * @return void
50
- */
51
- public function __construct() {
52
-
53
- $this->gnrl_options = get_option('i4t3_gnrl_options');
54
- }
55
-
56
- /**
57
- * Register the stylesheet for the Dashboard.
58
- *
59
- * This function is used to register all the required stylesheets for
60
- * dashboard. Styles will be registered only for i4t3 pages for performance.
61
- *
62
- * @since 2.0.0
63
- * @access public
64
- * @uses wp_enqueue_style To register style
65
- *
66
- * @return void
67
- */
68
- public function enqueue_styles() {
69
-
70
- global $pagenow;
71
-
72
- if( ( $pagenow == 'admin.php' ) && ( in_array( $_GET['page'], array('i4t3-settings', 'i4t3-logs' ) ) ) ) {
73
- wp_enqueue_style(
74
- I4T3_NAME,
75
- plugin_dir_url(__FILE__) . 'css/min/admin.css',
76
- array(),
77
- I4T3_VERSION,
78
- 'all'
79
- );
80
- }
81
- }
82
-
83
- /**
84
- * Register the scripts for the Dashboard.
85
- *
86
- * This function is used to register all the required scripts for
87
- * dashboard. Scripts will be registered only for i4t3 pages for performance.
88
- *
89
- * @since 2.0.0
90
- * @access public
91
- * @uses wp_enqueue_script To register script
92
- *
93
- * @return void
94
- */
95
- public function enqueue_scripts() {
96
-
97
- global $pagenow;
98
-
99
- if( ( $pagenow == 'admin.php' ) && ( in_array( $_GET['page'], array( 'i4t3-settings', 'i4t3-logs' ) ) ) ) {
100
- wp_enqueue_script(
101
- I4T3_NAME,
102
- plugin_dir_url(__FILE__) . 'js/admin.js',
103
- array('jquery'),
104
- I4T3_VERSION,
105
- false
106
- );
107
- // Internationalization
108
- wp_localize_script(
109
- I4T3_NAME,
110
- 'i4t3strings',
111
- array(
112
- 'redirect' => esc_html__( 'Custom Redirect', I4T3_DOMAIN ),
113
- )
114
- );
115
- }
116
- }
117
-
118
- /**
119
- * Run upgrade functions
120
- *
121
- * If 404 to 301 is upgraded, we may need to perform few updations in db
122
- *
123
- * @since 2.0.0
124
- * @access public
125
- * @uses get_option() To get the activation redirect option from db.
126
- *
127
- * @return void
128
- */
129
- public function i4t3_upgrade_if_new() {
130
-
131
- if( ! get_option( 'i4t3_version_no' ) || ( get_option( 'i4t3_version_no' ) < I4T3_VERSION ) ) {
132
- // call activator class once more
133
- if( ! class_exists( '_404_To_301_Activator' ) ) {
134
- include_once I4T3_PLUGIN_DIR . '/includes/class-404-to-301-activator.php';
135
- }
136
- _404_To_301_Activator::activate();
137
- // update plugin version
138
- update_option('i4t3_version_no', I4T3_VERSION );
139
- }
140
- }
141
-
142
- /**
143
- * Changing email notification recipient
144
- *
145
- * Using filter to change email notification recipient address from
146
- * default admin email.
147
- *
148
- * @since 2.0.7
149
- * @access public
150
- * @uses get_option() To get the email address option from db.
151
- *
152
- * @return string $email.
153
- */
154
- public function i4t3_change_notify_email( $email ) {
155
-
156
- if( ! empty( $this->gnrl_options['email_notify_address'] ) ) {
157
- $email_option = $this->gnrl_options['email_notify_address'];
158
- if( is_email( $email_option ) ) {
159
- $email = $email_option;
160
- }
161
- }
162
-
163
- return $email;
164
- }
165
-
166
- /**
167
- * Creating admin menus for 404 to 301.
168
- *
169
- * @since 2.0.0
170
- * @access public
171
- * @uses action hook add_submenu_page Action hook to add new admin menu sub page.
172
- *
173
- * @return void
174
- */
175
- public function i4t3_create_404_to_301_menu() {
176
-
177
- // Error log menu
178
- $hook = add_menu_page(
179
- __( '404 Error Logs', '404-to-301' ),
180
- __( '404 Error Logs', '404-to-301' ),
181
- I4T3_ADMIN_PERMISSION,
182
- 'i4t3-logs',
183
- array( $this, 'i4t3_render_list_page' ),
184
- 'dashicons-redo',
185
- 90
186
- );
187
-
188
- add_action( "load-$hook", array( $this, 'screen_option' ) );
189
-
190
- // 404 to 301 settings menu
191
- add_submenu_page(
192
- 'i4t3-logs',
193
- __('404 to 301 Settings', '404-to-301'),
194
- __('404 Settings', '404-to-301'),
195
- I4T3_ADMIN_PERMISSION,
196
- 'i4t3-settings',
197
- array( $this, 'i4t3_admin_page' )
198
- );
199
-
200
- // admin menu item acion hook
201
- do_action('i4t3_admin_page');
202
- }
203
-
204
- /**
205
- * To set the screen of the error listing page.
206
- *
207
- * @since 2.1.0
208
- * @access public
209
- *
210
- * @return string
211
- */
212
- public static function set_screen( $status, $option, $value ) {
213
-
214
- return $value;
215
- }
216
-
217
- /**
218
- * To make screen options for 404 to 301 listing.
219
- *
220
- * This function is used to show screen options like entries per page,
221
- * show/hide columns etc.
222
- *
223
- * @since 2.1.0
224
- * @access public
225
- *
226
- * @return void
227
- */
228
- public function screen_option() {
229
-
230
- $option = 'per_page';
231
- $args = array(
232
- 'label' => __('Error Logs', '404-to-301'),
233
- 'default' => 20,
234
- 'option' => 'logs_per_page'
235
- );
236
-
237
- add_screen_option( $option, $args );
238
-
239
- $this->list_table = new _404_To_301_Logs();
240
- }
241
-
242
- /**
243
- * Output buffer function
244
- *
245
- * To avoid header already sent issue
246
- *
247
- * @link https://tommcfarlin.com/wp_redirect-headers-already-sent/
248
- * @since 2.1.4
249
- * @access public
250
- *
251
- * @return void
252
- */
253
- public function add_buffer() {
254
-
255
- ob_start();
256
- }
257
-
258
- /**
259
- * Creating log table page.
260
- *
261
- * @since 2.0.0
262
- * @access public
263
- * @uses class _404_To_301_Logs To initialize and load the log listing table.
264
- *
265
- * @return void
266
- */
267
- public function i4t3_render_list_page() { ?>
268
-
269
- <div class="wrap">
270
- <h2><?php _e('404 Error Logs', '404-to-301'); ?></h2>
271
-
272
- <div id="poststuff">
273
- <div id="post-body" class="metabox-holder">
274
- <div id="post-body-content">
275
- <div class="meta-box-sortables ui-sortable">
276
- <form method="post">
277
- <?php
278
- $this->list_table->prepare_items();
279
- $this->list_table->display();
280
- ?>
281
- </form>
282
- </div>
283
- </div>
284
- </div>
285
- <br class="clear">
286
- </div>
287
- </div>
288
-
289
- <?php
290
- }
291
-
292
- /**
293
- * Rename admin menu text to : 404 to 301.
294
- *
295
- * @since 2.0.0
296
- * @access public
297
- * @var global $menu Menus registered in this site.
298
- *
299
- * @return void
300
- */
301
- public function i4t3_rename_plugin_menu() {
302
-
303
- global $menu;
304
- // change menu text
305
- $menu[90][0] = __('404 to 301', '404-to-301');
306
- }
307
-
308
- /**
309
- * Admin options page display.
310
- *
311
- * Includes admin page contents to manage i4t3 settings.
312
- * All html parts will be included in this page.
313
- *
314
- * @since 2.0.0
315
- * @access public
316
- *
317
- * @return void
318
- */
319
- public function i4t3_admin_page() {
320
-
321
- include_once I4T3_PLUGIN_DIR . '/admin/partials/404-to-301-admin-display.php';
322
- }
323
-
324
- /**
325
- * Registering i4t3 options.
326
- * This function is used to register all settings options to the db using
327
- * WordPress settings API.
328
- * If we want to register another setting, we can include that here.
329
- *
330
- * @since 2.0.0
331
- * @access public
332
- * @uses hooks register_setting Hook to register i4t3 options in db.
333
- *
334
- * @return void
335
- */
336
- public function i4t3_options_register() {
337
-
338
- register_setting(
339
- 'i4t3_gnrl_options',
340
- 'i4t3_gnrl_options'
341
- );
342
- }
343
-
344
- /**
345
- * Custom footer text for i4t3 pages.
346
- *
347
- * Function to alter the default footer text to show i4t3 credits only on i4t3 pages.
348
- *
349
- * @since 2.0.0
350
- * @access public
351
- *
352
- * @return mixed
353
- */
354
- public function i4t3_dashboard_footer() {
355
-
356
- // current page global var
357
- global $pagenow;
358
-
359
- if( ( $pagenow == 'admin.php' ) && ( in_array( $_GET['page'], array( 'i4t3-settings', 'i4t3-logs' ) ) ) ) {
360
-
361
- _e('Thank you for choosing 404 to 301 to improve your website', '404-to-301');
362
- echo ' | ';
363
- printf(__('Kindly give this plugin a %srating%s', '404-to-301'), '<a href="https://wordpress.org/support/view/plugin-reviews/404-to-301?filter=5#postform">', ' &#9733; &#9733; &#9733; &#9733; &#9733;</a>');
364
- } else {
365
- return;
366
- }
367
- }
368
-
369
- /**
370
- * Custom Plugin Action Link.
371
- *
372
- * Function to add a quick link to i4t3, when being listed on your
373
- * plugins list view.
374
- *
375
- * @since 2.0.0
376
- * @access public
377
- *
378
- * @return array $links Links to display.
379
- */
380
- public function i4t3_plugin_action_links($links, $file) {
381
-
382
- $plugin_file = basename('404-to-301.php');
383
-
384
- if ( basename( $file ) == $plugin_file ) {
385
- $settings_link = '<a href="admin.php?page=i4t3-settings">' . __('Settings', '404-to-301') . '</a>';
386
- $settings_link .= ' | <a href="admin.php?page=i4t3-logs">' . __('Logs', '404-to-301') . '</a>';
387
-
388
- array_unshift( $links, $settings_link );
389
- }
390
-
391
- return $links;
392
- }
393
-
394
- /**
395
- * This function includes required scripts for custom modal
396
- *
397
- * This function registers scripts required for WordPress
398
- * thickbox modal.
399
- *
400
- * @since 2.1.1
401
- * @access public
402
- *
403
- * @return void
404
- */
405
- public function add_thickbox() {
406
-
407
- return add_thickbox();
408
- }
409
-
410
- /**
411
- * Get custom redirect modal content
412
- *
413
- * @global object $wpdb WP DB object
414
- * @since 2.2.0
415
- * @access public
416
- *
417
- * @note Always die() for wp_ajax
418
- *
419
- * @return JSON
420
- */
421
- public function open_custom_redirect() {
422
-
423
- // verify if required value is available
424
- if ( ! isset( $_POST['url_404'] ) || is_null( $_POST['url_404'] ) ) {
425
- die();
426
- }
427
- // 404 path url
428
- $url_404 = trim( $_POST['url_404'] );
429
-
430
- global $wpdb;
431
- // make sure that the errors are hidden
432
- $wpdb->hide_errors();
433
- // get the custom redirect data for the given 404 path
434
- $sql = "SELECT redirect FROM " . I4T3_TABLE . " WHERE url = '" . $url_404 . "' AND redirect IS NOT NULL LIMIT 0,1";
435
- $url = $wpdb->get_var($sql);
436
- // make sure that the result is not error
437
- $url = ( empty( $url ) ) ? '' : $url;
438
- // make response array
439
- $data = array(
440
- 'url_404' => $url_404,
441
- 'url' => $url
442
- );
443
- // resturn josn output and die
444
- wp_send_json( $data );
445
- }
446
-
447
- /**
448
- * Save custom redirect value
449
- *
450
- * @global object $wpdb WP DB object
451
- * @since 2.2.0
452
- * @access public
453
- *
454
- * @note Always die() for wp_ajax
455
- *
456
- * @return void
457
- */
458
- public function save_custom_redirect() {
459
-
460
- // verify the nonce for ajax
461
- $secure = check_ajax_referer( 'i4t3_custom_redirect_nonce', 'nonce', false );
462
- if( ! $secure ) {
463
- die( 'Go take a bath' );
464
- }
465
-
466
- // if required values are not given, kill
467
- if ( ! isset( $_POST['url_404'] ) || ! isset( $_POST['url'] ) ) {
468
- die();
469
- }
470
- // get the required values from request
471
- $url_404 = $_POST['url_404'];
472
- $url = esc_url( $_POST['url'] );
473
-
474
- global $wpdb;
475
- // make sure that the errors are hidden
476
- $wpdb->hide_errors();
477
- // update the custom redirect value for the 404 path
478
- $wpdb->query(
479
- $wpdb->prepare(
480
- "UPDATE " . I4T3_TABLE . "
481
- SET redirect = '%s'
482
- WHERE url = '%s'",
483
- $url,
484
- $url_404
485
- )
486
- );
487
-
488
- die();
489
- }
490
-
491
- /**
492
- * This function displays the custom redirect modal html content
493
- *
494
- * @since 2.2.0
495
- * @acess public
496
- *
497
- * @return void
498
- */
499
- public function get_redirect_content() {
500
-
501
- include_once I4T3_PLUGIN_DIR . '/admin/partials/404-to-301-admin-custom-redirect.php';
502
- }
503
-
504
- /**
505
- * Get debug data.
506
- *
507
- * Function to output the debug data for the plugin. This will be useful
508
- * when asking for support. Just copy and paste these data to the email.
509
- *
510
- * Please DO NOT translate this part, as this need to be provided for debugging only.
511
- *
512
- * @since 2.0.0
513
- * @var array $gnrl_options Array of plugin settings
514
- * @var array $active_plugins Array of active plugins path
515
- * @return $html Html content to diplay.
516
- * @author Joel James
517
- */
518
- public function i4t3_get_debug_data() {
519
-
520
- $html = '';
521
- $gnrl_options = get_option('i4t3_gnrl_options');
522
- $active_plugins = get_option('active_plugins', array());
523
- $active_theme = wp_get_theme();
524
-
525
- // Dump the plugin settings data
526
- if (!empty($gnrl_options)) {
527
- $html .= '<h4>' . __('Settings Data', '404-to-301') . '</h4><p><pre>';
528
- foreach ($gnrl_options as $key => $option) {
529
- $html .= $key . ' : ' . $option . '<br/>';
530
- }
531
- $html .= '</pre></p><hr/>';
532
- }
533
- // Output basic info about the site
534
- $html .= '<h4>' . __('Basic Details', '404-to-301') . '</h4><p>
535
- ' . __('WordPress Version', '404-to-301') . ' : ' . get_bloginfo('version') . '<br/>
536
- ' . __('PHP Version', '404-to-301') . ' : ' . PHP_VERSION . '<br/>
537
- ' . __('Plugin Version', '404-to-301') . ' : ' . I4T3_VERSION . '<br/>
538
- ' . __('Home Page', '404-to-301') . ' : ' . home_url() . '<br/></p><hr/>';
539
-
540
- if ($active_theme->exists()) {
541
-
542
- $html .= '<h4>' . __('Active Theme Details', '404-to-301') . '</h4><p>
543
- ' . __('Name', '404-to-301') . ' : ' . $active_theme->get('Name') . '<br/>
544
- ' . __('Version', '404-to-301') . ' : ' . $active_theme->get('Version') . '<br/>
545
- ' . __('Theme URI', '404-to-301') . ' : ' . $active_theme->get('ThemeURI') . '<br/></p><hr/>';
546
- }
547
-
548
- // Dump the active plugins data
549
- if (!empty($active_plugins)) {
550
- $html .= '<h4>' . __('Active Plugins', '404-to-301') . '</h4><p>';
551
- foreach ($active_plugins as $plugin) {
552
- $html .= $plugin . '<br/>';
553
- }
554
- $html .= '</p>';
555
- }
556
-
557
- return $html;
558
- }
559
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/class-404-to-301-logs.php DELETED
@@ -1,601 +0,0 @@
1
- <?php
2
-
3
- // If this file is called directly, abort.
4
- if ( ! defined( 'WPINC' ) ) {
5
- die('Damn it.! Dude you are looking for what?');
6
- }
7
-
8
- /**
9
- * WP_List_Table is marked as private by WordPress. So they may change it.
10
- * Details here - https://codex.wordpress.org/Class_Reference/WP_List_Table
11
- * So we have copied this class and using independently to avoid future issues.
12
- */
13
- if ( ! class_exists('WP_List_Table_404') ) {
14
-
15
- global $wp_version;
16
- if( $wp_version >= 4.4 ) {
17
- include_once I4T3_PLUGIN_DIR . '/admin/core/class-wp-list-table-4.4.php';
18
- } else {
19
- include_once I4T3_PLUGIN_DIR . '/admin/core/class-wp-list-table-old.php';
20
- }
21
- }
22
-
23
- /**
24
- * The listing page class for error logs.
25
- *
26
- * This class defines all the methods to output the error logs display table using
27
- * WordPress listing table class.
28
- *
29
- * @category Core
30
- * @package I4T3
31
- * @subpackage ErrorLogsTable
32
- * @author Joel James <me@joelsays.com>
33
- * @license http://www.gnu.org/licenses/ GNU General Public License
34
- * @link https://thefoxe.com/products/404-to-301
35
- */
36
- class _404_To_301_Logs extends WP_List_Table_404 {
37
-
38
- /**
39
- * The table name of this plugin.
40
- *
41
- * @since 2.0.0
42
- * @access private
43
- * @author Joel James.
44
- * @var string $table The table name of this plugin in db.
45
- */
46
- private static $table;
47
-
48
- /**
49
- * Initialize the class and set its properties.
50
- *
51
- * @since 2.0.0
52
- * @access public
53
- * @var string $table The name of the table of plugin
54
- *
55
- * @return void
56
- */
57
- public function __construct() {
58
-
59
- self::$table = I4T3_TABLE;
60
-
61
- parent::__construct(
62
- array(
63
- 'singular' => __('404 Error Log', '404-to-301'), //singular name of the listed records
64
- 'plural' => __('404 Error Logs', '404-to-301'), //plural name of the listed records
65
- 'ajax' => false //does this table support ajax?
66
- )
67
- );
68
- }
69
-
70
- /**
71
- * Error log data to be displayed.
72
- *
73
- * Getting the error log data from the database and converts it to
74
- * the required structure.
75
- *
76
- * @param int $per_page Items per page
77
- * @param int $page_number Page number of the list
78
- *
79
- * @since 2.0.0
80
- * @access public
81
- * @global object $wpdb WP DB object
82
- * @uses apply_filters
83
- *
84
- * @return array $error_data Array of error log data.
85
- */
86
- public static function i4t3_get_log_data($per_page = 20, $page_number = 1) {
87
-
88
- global $wpdb;
89
-
90
- $offset = ( $page_number - 1 ) * $per_page;
91
-
92
- // If no sort, default to title
93
- $orderby = ( isset( $_REQUEST['orderby']) ) ? self::i4t3_get_sort_column_filtered( $_REQUEST['orderby']) : 'date';
94
-
95
- // If no order, default to asc
96
- $order = ( isset( $_REQUEST['order']) && 'asc' == $_REQUEST['order'] ) ? 'ASC' : 'DESC';
97
-
98
- $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . self::$table . " ORDER BY $orderby $order LIMIT %d OFFSET %d", array( $per_page, $offset ) ), 'ARRAY_A' );
99
-
100
- return $result;
101
- }
102
-
103
- /**
104
- * Filter the sorting parameters.
105
- *
106
- * This is used to filter the sorting parameters in order
107
- * to prevent SQL injection atacks. We will accept only our
108
- * required values. Else we will assign a default value.
109
- *
110
- * @param string $column Value from url
111
- *
112
- * @since 2.0.3
113
- * @access public
114
- *
115
- * @return string $filtered_column.
116
- */
117
- public static function i4t3_get_sort_column_filtered($column) {
118
-
119
- $allowed_columns = array( 'date', 'url', 'ref', 'ip' );
120
-
121
- if( in_array($column, $allowed_columns ) ) {
122
- $filtered_column = esc_sql( $column );
123
- } else {
124
- $filtered_column = 'date';
125
- }
126
-
127
- return $filtered_column;
128
- }
129
-
130
- /**
131
- * Delete a single record from table.
132
- *
133
- * This function is used to clear the selected errors
134
- * from error logs table.
135
- *
136
- * @param int $id ID of error log
137
- *
138
- * @since 2.1.0
139
- * @access public
140
- *
141
- * @return void
142
- */
143
- public static function delete_error_logs($id) {
144
-
145
- global $wpdb;
146
-
147
- $wpdb->delete(
148
- self::$table,
149
- array(
150
- 'id' => $id
151
- ),
152
- array('%d')
153
- );
154
- }
155
-
156
- /**
157
- * Delete all records at once from database.
158
- *
159
- * This function is used to clear the error logs table.
160
- *
161
- * @since 2.1.0
162
- * @access public
163
- *
164
- * @return void
165
- */
166
- public static function delete_error_all_logs() {
167
-
168
- global $wpdb;
169
- // delete from logs table
170
- $wpdb->query("DELETE FROM " . self::$table . "");
171
- }
172
-
173
- /**
174
- * Get the count of total records in table.
175
- *
176
- * @since 2.1.0
177
- * @access public
178
- *
179
- * @return mixed
180
- */
181
- public static function record_count() {
182
-
183
- global $wpdb;
184
-
185
- $sql = "SELECT COUNT(id) FROM " . self::$table;
186
-
187
- return $wpdb->get_var($sql);
188
- }
189
-
190
- /**
191
- * Empty record text.
192
- *
193
- * Custom text to display where there is nothing to display in error
194
- * log table.
195
- *
196
- * @since 2.0.0
197
- * @access public
198
- *
199
- * @return void
200
- */
201
- public function no_items() {
202
-
203
- _e( 'Ulta pulta..! Seems like you had no errors to log.', '404-to-301' );
204
- }
205
-
206
- /**
207
- * Default columns in list table.
208
- *
209
- * To show columns in error log list table. If there is nothing
210
- * for switch, printing the whole array.
211
- *
212
- * @param array $item Column data
213
- * @param string $column_name Column name
214
- *
215
- * @since 2.0.0
216
- * @access public
217
- *
218
- * @return array
219
- */
220
- public function column_default( $item, $column_name ) {
221
-
222
- switch( $column_name ) {
223
- case 'date':
224
- case 'url':
225
- case 'ref':
226
- case 'ip':
227
- case 'ua':
228
- case 'redirect':
229
- return $item[ $column_name ];
230
- default:
231
- //Show the whole array for troubleshooting purposes
232
- return print_r( $item, true );
233
- }
234
- }
235
-
236
- /**
237
- * To output checkbox for bulk actions.
238
- *
239
- * This function is used to add new checkbox for all entries in
240
- * the listing table. We use this checkbox to perform bulk actions.
241
- *
242
- * @param array $item Column data
243
- *
244
- * @since 2.1.0
245
- * @access public
246
- *
247
- * @return string
248
- */
249
- function column_cb( $item ) {
250
-
251
- return sprintf( '<input type="checkbox" name="bulk-delete[]" value="%s"/>', $item['id'] );
252
- }
253
-
254
- /**
255
- * To output redirect option of the link.
256
- *
257
- * This function is used to add custom column for setting
258
- * custom redirect for a 404 link.
259
- *
260
- * @param array $item Column data
261
- *
262
- * @since 2.1.1
263
- * @access public
264
- *
265
- * @return string
266
- */
267
- function column_redirect( $item ) {
268
-
269
- $title = ( ! empty( $item['redirect'] ) ) ? $item['redirect'] : __( 'Default', '404-to-301' );
270
-
271
- return '<a href="javascript:void(0)" title="' . __('Customize', '404-to-301') . '" class="i4t3_redirect_thickbox" url_404="' . esc_url( $item['url'] ) . '">' . $title . '</a>';
272
- }
273
-
274
- /**
275
- * To modify the date column data
276
- *
277
- * This function is used to modify the column data for date in listing table.
278
- * We can change styles, texts etc. using this function.
279
- *
280
- * @param array $item Column data
281
- *
282
- * @since 2.0.0
283
- * @access public
284
- *
285
- * @return string $date_data Date column text data.
286
- */
287
- function column_date( $item ) {
288
-
289
- $delete_nonce = wp_create_nonce('i4t3_delete_log');
290
-
291
- $title = apply_filters('i4t3_log_list_date_column', date("j M Y, g:i a", strtotime($item['date'])));
292
-
293
- $confirm = __('Are you sure you want to delete this item?', '404-to-301');
294
-
295
- $actions = array(
296
- 'delete' => sprintf('<a href="?page=%s&action=%s&log=%s&_wpnonce=%s" onclick="return confirm(\'%s\');">' . __('Delete', '404-to-301') . '</a>', esc_attr($_REQUEST['page']), 'delete', absint($item['id']), $delete_nonce, $confirm)
297
- );
298
-
299
- return $title . $this->row_actions($actions);
300
- }
301
-
302
- /**
303
- * To modify the url column data
304
- *
305
- * This function is used to modify the column data for url in listing table.
306
- * We can change styles, texts etc. using this function.
307
- *
308
- * @param array $item Column data
309
- *
310
- * @since 2.0.0
311
- * @access public
312
- *
313
- * @return string $url_data Url column text data.
314
- */
315
- public function column_url( $item ) {
316
-
317
- $url = esc_url( $item['url'] );
318
-
319
- // Apply filter - i4t3_log_list_url_column
320
- $url_data = apply_filters( 'i4t3_log_list_url_column', $this->get_empty_text('<p class="i4t3-url-p">' . $url . '</p>', $url));
321
-
322
- return $url_data;
323
- }
324
-
325
- /**
326
- * To modify the ref column data
327
- *
328
- * This function is used to modify the column data for ref in listing table.
329
- * We can change styles, texts etc. using this function.
330
- *
331
- * @param array $item Column data
332
- *
333
- * @since 2.0.0
334
- * @access public
335
- *
336
- * @return string $ref_data Ref column text data.
337
- */
338
- public function column_ref( $item ) {
339
-
340
- $ref = ( $item['ref'] === 'N/A' ) ? 'N/A' : esc_url( $item['ref'] );
341
-
342
- // Apply filter - i4t3_log_list_ref_column
343
- $ref_data = apply_filters( 'i4t3_log_list_ref_column', $this->get_empty_text('<a href="' . $ref . '" target="_blank">' . $ref . '</a>', $ref ) );
344
-
345
- return $ref_data;
346
- }
347
-
348
- /**
349
- * To modify the user agent column data
350
- *
351
- * This function is used to modify the column data for user agent in listing table.
352
- * We can change styles, texts etc. using this function.
353
- *
354
- * @param array $item Column data
355
- *
356
- * @since 2.0.9
357
- * @access public
358
- *
359
- * @return string $ua_data Ref column text data.
360
- */
361
- public function column_ua($item) {
362
-
363
- $ua = sanitize_text_field( $item['ua'] );
364
-
365
- // Apply filter - i4t3_log_list_ref_column
366
- $ua_data = apply_filters( 'i4t3_log_list_ua_column', $this->get_empty_text( $ua, $ua ) );
367
-
368
- return $ua_data;
369
- }
370
-
371
- /**
372
- * To modify the ip column data
373
- *
374
- * This function is used to modify the column data for ip in listing table.
375
- * We can change styles, texts etc. using this function.
376
- *
377
- * @param array $item Column data
378
- *
379
- * @since 2.0.9
380
- * @access public
381
- *
382
- * @return string $ip Ref column text data.
383
- */
384
- public function column_ip( $item ) {
385
-
386
- $ip = sanitize_text_field( $item['ip'] );
387
-
388
- // Apply filter - i4t3_log_list_ref_column
389
- $ip = apply_filters( 'i4t3_log_list_ip_column', $this->get_empty_text( $ip, $ip ) );
390
-
391
- return $ip;
392
- }
393
-
394
- /**
395
- * Column titles
396
- *
397
- * Custom column titles to be displayed in listing table. You can change this to anything
398
- *
399
- * @since 2.0.0
400
- * @access public
401
- *
402
- * @return array $columns Array of cloumn titles.
403
- */
404
- function get_columns() {
405
-
406
- $columns = array(
407
- 'cb' => '<input type="checkbox" style="width: 5%;" />',
408
- 'date' => __( 'Date', '404-to-301' ),
409
- 'url' => __( '404 Path', '404-to-301' ),
410
- 'ref' => __( 'From', '404-to-301' ), // referer
411
- 'ip' => __( 'IP Address', '404-to-301' ),
412
- 'ua' => __('User Agent', '404-to-301'),
413
- 'redirect' => __( 'Redirect', '404-to-301' )
414
- );
415
-
416
- return $columns;
417
- }
418
-
419
- /**
420
- * Make columns sortable
421
- *
422
- * To make our custom columns in list table sortable. We have included
423
- * 4 columns except 'User Agent' column here.
424
- *
425
- * @since 2.0.0
426
- * @access public
427
- *
428
- * @return array $sortable_columns Array of columns to enable sorting.
429
- */
430
- public function get_sortable_columns() {
431
-
432
- $sortable_columns = array(
433
- 'date' => array('date', true),
434
- 'url' => array('url', false),
435
- 'ref' => array('ref', false),
436
- 'ip' => array('ip', false)
437
- );
438
-
439
- return $sortable_columns;
440
- }
441
-
442
- /**
443
- * Bulk actions drop down
444
- *
445
- * Options to be added to the bulk actions drop down for users
446
- * to select. We have added 'Delete' actions.
447
- *
448
- * @since 2.0.0
449
- * @access public
450
- *
451
- * @return array $actions Options to be added to the action select box.
452
- */
453
- public function get_bulk_actions() {
454
-
455
- $actions = array(
456
- 'bulk-delete' => __( 'Delete Selected', '404-to-301' ),
457
- 'bulk-all-delete' => __( 'Delete All', '404-to-301' )
458
- );
459
-
460
- return $actions;
461
- }
462
-
463
- /**
464
- * Main function to output the listing table using WP_List_Table class
465
- *
466
- * As name says, this function is used to prepare the lsting table based
467
- * on the custom rules and filters that we have given.
468
- * This function extends the lsiting table class and uses our custom data
469
- * to list in the table.
470
- * Here we set pagination, columns, sorting etc.
471
- * $this->items - Push our custom log data to the listing table.
472
- *
473
- * @global object $wpdb WP DB object
474
- * @since 2.0.0
475
- * @access public
476
- * @uses hide_errors() To hide if there are SQL query errors.
477
- *
478
- * @return void
479
- */
480
- public function prepare_items() {
481
-
482
- $this->_column_headers = $this->get_column_info();
483
-
484
- /** Process bulk action */
485
- $this->process_bulk_action();
486
-
487
- $per_page = $this->get_items_per_page( 'logs_per_page', 5 );
488
- $current_page = $this->get_pagenum();
489
- $total_items = self::record_count();
490
-
491
- $this->set_pagination_args(
492
- array(
493
- 'total_items' => $total_items, //WE have to calculate the total number of items
494
- 'per_page' => $per_page //WE have to determine how many items to show on a page
495
- )
496
- );
497
-
498
- $this->items = self::i4t3_get_log_data( $per_page, $current_page );
499
- }
500
-
501
- /**
502
- * To perform bulk actions.
503
- *
504
- * This function is used to check if bulk action is set in post.
505
- * If set it will call the required functions to perform the task.
506
- *
507
- * @since 2.1.0
508
- * @access public
509
- * @uses wp_verify_nonce To verify if the request is from WordPress.
510
- *
511
- * @return void
512
- */
513
- public function process_bulk_action() {
514
-
515
- //Detect when a bulk action is being triggered...
516
- if ( 'delete' === $this->current_action() ) {
517
-
518
- // In our file that handles the request, verify the nonce.
519
- $nonce = esc_attr( $_REQUEST['_wpnonce'] );
520
-
521
- if( ! wp_verify_nonce( $nonce, 'i4t3_delete_log' ) ) {
522
- wp_die( 'Go get a life script kiddies' );
523
- } else {
524
- self::delete_error_logs( absint( $_GET['log'] ) );
525
- wp_redirect( esc_url( add_query_arg() ) );
526
- exit;
527
- }
528
- }
529
-
530
- $this->bulk_delete_actions();
531
- }
532
-
533
- /**
534
- * To perform bulk delete actions.
535
- *
536
- * This function is used to perform the bulk delete
537
- * actions. Selected data delete and whole data delete
538
- * is being performed here.
539
- *
540
- * @since 2.1.0
541
- * @access public
542
- * @uses wp_verify_nonce To verify if the request is from WordPress.
543
- *
544
- * @return void
545
- */
546
- private function bulk_delete_actions() {
547
-
548
- if( isset($_POST['_wpnonce'] ) ) {
549
-
550
- $nonce = '';
551
- $action = '';
552
- // security check!
553
- if ( ! empty( $_POST['_wpnonce'] ) ) {
554
- $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
555
- $action = 'bulk-' . $this->_args['plural'];
556
- }
557
-
558
- if ( ! wp_verify_nonce( $nonce, $action ) ) {
559
- wp_die( 'Go get a life script kiddies' );
560
- }
561
-
562
- // If the delete bulk action is triggered
563
- else if ( ( isset( $_POST['action']) && $_POST['action'] == 'bulk-delete' ) || ( isset($_POST['action2']) && $_POST['action2'] == 'bulk-delete' ) ) {
564
- $delete_ids = esc_sql($_POST['bulk-delete']);
565
- // loop over the array of record IDs and delete them
566
- foreach( $delete_ids as $id ) {
567
- self::delete_error_logs( $id );
568
- }
569
- wp_redirect( esc_url( add_query_arg() ) );
570
- exit;
571
- }
572
-
573
- // If the delete all bulk action is triggered
574
- elseif( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-all-delete' ) || ( isset( $_POST['action2']) && $_POST['action2'] == 'bulk-all-delete' ) ) {
575
- self::delete_error_all_logs();
576
- wp_redirect(esc_url(add_query_arg()));
577
- exit;
578
- }
579
- }
580
- }
581
-
582
- /**
583
- * To make clear error text if value is N/A.
584
- *
585
- * This function is used to show the N/A text in red colour if the field value
586
- * is not available.
587
- *
588
- * @since 2.1.0
589
- * @access public
590
- *
591
- * @return string
592
- */
593
- public function get_empty_text( $data, $na = 'N/A' ) {
594
-
595
- if ( $na == 'N/A' ) {
596
- return '<p class="i4t3-url-p">' . __('N/A', '404-to-301') . '</p>';
597
- }
598
-
599
- return $data;
600
- }
601
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/core/class-wp-list-table-4.4.php DELETED
@@ -1,1377 +0,0 @@
1
- <?php
2
- /**
3
- * Administration API: WP_List_Table class
4
- *
5
- * @package WordPress
6
- * @subpackage List_Table
7
- * @since 3.1.0
8
- */
9
-
10
- /**
11
- * Base class for displaying a list of items in an ajaxified HTML table.
12
- *
13
- * @since 3.1.0
14
- * @access private
15
- */
16
- class WP_List_Table_404 {
17
-
18
- /**
19
- * The current list of items.
20
- *
21
- * @since 3.1.0
22
- * @access public
23
- * @var array
24
- */
25
- public $items;
26
-
27
- /**
28
- * Various information about the current table.
29
- *
30
- * @since 3.1.0
31
- * @access protected
32
- * @var array
33
- */
34
- protected $_args;
35
-
36
- /**
37
- * Various information needed for displaying the pagination.
38
- *
39
- * @since 3.1.0
40
- * @access protected
41
- * @var array
42
- */
43
- protected $_pagination_args = array();
44
-
45
- /**
46
- * The current screen.
47
- *
48
- * @since 3.1.0
49
- * @access protected
50
- * @var object
51
- */
52
- protected $screen;
53
-
54
- /**
55
- * Cached bulk actions.
56
- *
57
- * @since 3.1.0
58
- * @access private
59
- * @var array
60
- */
61
- private $_actions;
62
-
63
- /**
64
- * Cached pagination output.
65
- *
66
- * @since 3.1.0
67
- * @access private
68
- * @var string
69
- */
70
- private $_pagination;
71
-
72
- /**
73
- * The view switcher modes.
74
- *
75
- * @since 4.1.0
76
- * @access protected
77
- * @var array
78
- */
79
- protected $modes = array();
80
-
81
- /**
82
- * Stores the value returned by ->get_column_info().
83
- *
84
- * @since 4.1.0
85
- * @access protected
86
- * @var array
87
- */
88
- protected $_column_headers;
89
-
90
- /**
91
- * {@internal Missing Summary}
92
- *
93
- * @access protected
94
- * @var array
95
- */
96
- protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
97
-
98
- /**
99
- * {@internal Missing Summary}
100
- *
101
- * @access protected
102
- * @var array
103
- */
104
- protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions',
105
- 'row_actions', 'months_dropdown', 'view_switcher', 'comments_bubble', 'get_items_per_page', 'pagination',
106
- 'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav',
107
- 'single_row_columns' );
108
-
109
- /**
110
- * Constructor.
111
- *
112
- * The child class should call this constructor from its own constructor to override
113
- * the default $args.
114
- *
115
- * @since 3.1.0
116
- * @access public
117
- *
118
- * @param array|string $args {
119
- * Array or string of arguments.
120
- *
121
- * @type string $plural Plural value used for labels and the objects being listed.
122
- * This affects things such as CSS class-names and nonces used
123
- * in the list table, e.g. 'posts'. Default empty.
124
- * @type string $singular Singular label for an object being listed, e.g. 'post'.
125
- * Default empty
126
- * @type bool $ajax Whether the list table supports AJAX. This includes loading
127
- * and sorting data, for example. If true, the class will call
128
- * the {@see _js_vars()} method in the footer to provide variables
129
- * to any scripts handling AJAX events. Default false.
130
- * @type string $screen String containing the hook name used to determine the current
131
- * screen. If left null, the current screen will be automatically set.
132
- * Default null.
133
- * }
134
- */
135
- public function __construct( $args = array() ) {
136
- $args = wp_parse_args( $args, array(
137
- 'plural' => '',
138
- 'singular' => '',
139
- 'ajax' => false,
140
- 'screen' => null,
141
- ) );
142
-
143
- $this->screen = convert_to_screen( $args['screen'] );
144
-
145
- add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
146
-
147
- if ( !$args['plural'] )
148
- $args['plural'] = $this->screen->base;
149
-
150
- $args['plural'] = sanitize_key( $args['plural'] );
151
- $args['singular'] = sanitize_key( $args['singular'] );
152
-
153
- $this->_args = $args;
154
-
155
- if ( $args['ajax'] ) {
156
- // wp_enqueue_script( 'list-table' );
157
- add_action( 'admin_footer', array( $this, '_js_vars' ) );
158
- }
159
-
160
- if ( empty( $this->modes ) ) {
161
- $this->modes = array(
162
- 'list' => __( 'List View' ),
163
- 'excerpt' => __( 'Excerpt View' )
164
- );
165
- }
166
- }
167
-
168
- /**
169
- * Make private properties readable for backwards compatibility.
170
- *
171
- * @since 4.0.0
172
- * @access public
173
- *
174
- * @param string $name Property to get.
175
- * @return mixed Property.
176
- */
177
- public function __get( $name ) {
178
- if ( in_array( $name, $this->compat_fields ) ) {
179
- return $this->$name;
180
- }
181
- }
182
-
183
- /**
184
- * Make private properties settable for backwards compatibility.
185
- *
186
- * @since 4.0.0
187
- * @access public
188
- *
189
- * @param string $name Property to check if set.
190
- * @param mixed $value Property value.
191
- * @return mixed Newly-set property.
192
- */
193
- public function __set( $name, $value ) {
194
- if ( in_array( $name, $this->compat_fields ) ) {
195
- return $this->$name = $value;
196
- }
197
- }
198
-
199
- /**
200
- * Make private properties checkable for backwards compatibility.
201
- *
202
- * @since 4.0.0
203
- * @access public
204
- *
205
- * @param string $name Property to check if set.
206
- * @return bool Whether the property is set.
207
- */
208
- public function __isset( $name ) {
209
- if ( in_array( $name, $this->compat_fields ) ) {
210
- return isset( $this->$name );
211
- }
212
- }
213
-
214
- /**
215
- * Make private properties un-settable for backwards compatibility.
216
- *
217
- * @since 4.0.0
218
- * @access public
219
- *
220
- * @param string $name Property to unset.
221
- */
222
- public function __unset( $name ) {
223
- if ( in_array( $name, $this->compat_fields ) ) {
224
- unset( $this->$name );
225
- }
226
- }
227
-
228
- /**
229
- * Make private/protected methods readable for backwards compatibility.
230
- *
231
- * @since 4.0.0
232
- * @access public
233
- *
234
- * @param callable $name Method to call.
235
- * @param array $arguments Arguments to pass when calling.
236
- * @return mixed|bool Return value of the callback, false otherwise.
237
- */
238
- public function __call( $name, $arguments ) {
239
- if ( in_array( $name, $this->compat_methods ) ) {
240
- return call_user_func_array( array( $this, $name ), $arguments );
241
- }
242
- return false;
243
- }
244
-
245
- /**
246
- * Checks the current user's permissions
247
- *
248
- * @since 3.1.0
249
- * @access public
250
- * @abstract
251
- */
252
- public function ajax_user_can() {
253
- die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
254
- }
255
-
256
- /**
257
- * Prepares the list of items for displaying.
258
- * @uses WP_List_Table::set_pagination_args()
259
- *
260
- * @since 3.1.0
261
- * @access public
262
- * @abstract
263
- */
264
- public function prepare_items() {
265
- die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
266
- }
267
-
268
- /**
269
- * An internal method that sets all the necessary pagination arguments
270
- *
271
- * @since 3.1.0
272
- * @access protected
273
- *
274
- * @param array|string $args Array or string of arguments with information about the pagination.
275
- */
276
- protected function set_pagination_args( $args ) {
277
- $args = wp_parse_args( $args, array(
278
- 'total_items' => 0,
279
- 'total_pages' => 0,
280
- 'per_page' => 0,
281
- ) );
282
-
283
- if ( !$args['total_pages'] && $args['per_page'] > 0 )
284
- $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
285
-
286
- // Redirect if page number is invalid and headers are not already sent.
287
- if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
288
- wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
289
- exit;
290
- }
291
-
292
- $this->_pagination_args = $args;
293
- }
294
-
295
- /**
296
- * Access the pagination args.
297
- *
298
- * @since 3.1.0
299
- * @access public
300
- *
301
- * @param string $key Pagination argument to retrieve. Common values include 'total_items',
302
- * 'total_pages', 'per_page', or 'infinite_scroll'.
303
- * @return int Number of items that correspond to the given pagination argument.
304
- */
305
- public function get_pagination_arg( $key ) {
306
- if ( 'page' === $key ) {
307
- return $this->get_pagenum();
308
- }
309
-
310
- if ( isset( $this->_pagination_args[$key] ) ) {
311
- return $this->_pagination_args[$key];
312
- }
313
- }
314
-
315
- /**
316
- * Whether the table has items to display or not
317
- *
318
- * @since 3.1.0
319
- * @access public
320
- *
321
- * @return bool
322
- */
323
- public function has_items() {
324
- return !empty( $this->items );
325
- }
326
-
327
- /**
328
- * Message to be displayed when there are no items
329
- *
330
- * @since 3.1.0
331
- * @access public
332
- */
333
- public function no_items() {
334
- _e( 'No items found.' );
335
- }
336
-
337
- /**
338
- * Display the search box.
339
- *
340
- * @since 3.1.0
341
- * @access public
342
- *
343
- * @param string $text The search button text
344
- * @param string $input_id The search input id
345
- */
346
- public function search_box( $text, $input_id ) {
347
- if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
348
- return;
349
-
350
- $input_id = $input_id . '-search-input';
351
-
352
- if ( ! empty( $_REQUEST['orderby'] ) )
353
- echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
354
- if ( ! empty( $_REQUEST['order'] ) )
355
- echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
356
- if ( ! empty( $_REQUEST['post_mime_type'] ) )
357
- echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
358
- if ( ! empty( $_REQUEST['detached'] ) )
359
- echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
360
- ?>
361
- <p class="search-box">
362
- <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
363
- <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
364
- <?php submit_button( $text, 'button', '', false, array('id' => 'search-submit') ); ?>
365
- </p>
366
- <?php
367
- }
368
-
369
- /**
370
- * Get an associative array ( id => link ) with the list
371
- * of views available on this table.
372
- *
373
- * @since 3.1.0
374
- * @access protected
375
- *
376
- * @return array
377
- */
378
- protected function get_views() {
379
- return array();
380
- }
381
-
382
- /**
383
- * Display the list of views available on this table.
384
- *
385
- * @since 3.1.0
386
- * @access public
387
- */
388
- public function views() {
389
- $views = $this->get_views();
390
- /**
391
- * Filter the list of available list table views.
392
- *
393
- * The dynamic portion of the hook name, `$this->screen->id`, refers
394
- * to the ID of the current screen, usually a string.
395
- *
396
- * @since 3.5.0
397
- *
398
- * @param array $views An array of available list table views.
399
- */
400
- $views = apply_filters( "views_{$this->screen->id}", $views );
401
-
402
- if ( empty( $views ) )
403
- return;
404
-
405
- $this->screen->render_screen_reader_content( 'heading_views' );
406
-
407
- echo "<ul class='subsubsub'>\n";
408
- foreach ( $views as $class => $view ) {
409
- $views[ $class ] = "\t<li class='$class'>$view";
410
- }
411
- echo implode( " |</li>\n", $views ) . "</li>\n";
412
- echo "</ul>";
413
- }
414
-
415
- /**
416
- * Get an associative array ( option_name => option_title ) with the list
417
- * of bulk actions available on this table.
418
- *
419
- * @since 3.1.0
420
- * @access protected
421
- *
422
- * @return array
423
- */
424
- protected function get_bulk_actions() {
425
- return array();
426
- }
427
-
428
- /**
429
- * Display the bulk actions dropdown.
430
- *
431
- * @since 3.1.0
432
- * @access protected
433
- *
434
- * @param string $which The location of the bulk actions: 'top' or 'bottom'.
435
- * This is designated as optional for backwards-compatibility.
436
- */
437
- protected function bulk_actions( $which = '' ) {
438
- if ( is_null( $this->_actions ) ) {
439
- $no_new_actions = $this->_actions = $this->get_bulk_actions();
440
- /**
441
- * Filter the list table Bulk Actions drop-down.
442
- *
443
- * The dynamic portion of the hook name, `$this->screen->id`, refers
444
- * to the ID of the current screen, usually a string.
445
- *
446
- * This filter can currently only be used to remove bulk actions.
447
- *
448
- * @since 3.5.0
449
- *
450
- * @param array $actions An array of the available bulk actions.
451
- */
452
- $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
453
- $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
454
- $two = '';
455
- } else {
456
- $two = '2';
457
- }
458
-
459
- if ( empty( $this->_actions ) )
460
- return;
461
-
462
- echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
463
- echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
464
- echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>\n";
465
-
466
- foreach ( $this->_actions as $name => $title ) {
467
- $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
468
-
469
- echo "\t" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>\n";
470
- }
471
-
472
- echo "</select>\n";
473
-
474
- submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
475
- echo "\n";
476
- }
477
-
478
- /**
479
- * Get the current action selected from the bulk actions dropdown.
480
- *
481
- * @since 3.1.0
482
- * @access public
483
- *
484
- * @return string|false The action name or False if no action was selected
485
- */
486
- public function current_action() {
487
- if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
488
- return false;
489
-
490
- if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
491
- return $_REQUEST['action'];
492
-
493
- if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
494
- return $_REQUEST['action2'];
495
-
496
- return false;
497
- }
498
-
499
- /**
500
- * Generate row actions div
501
- *
502
- * @since 3.1.0
503
- * @access protected
504
- *
505
- * @param array $actions The list of actions
506
- * @param bool $always_visible Whether the actions should be always visible
507
- * @return string
508
- */
509
- protected function row_actions( $actions, $always_visible = false ) {
510
- $action_count = count( $actions );
511
- $i = 0;
512
-
513
- if ( !$action_count )
514
- return '';
515
-
516
- $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
517
- foreach ( $actions as $action => $link ) {
518
- ++$i;
519
- ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
520
- $out .= "<span class='$action'>$link$sep</span>";
521
- }
522
- $out .= '</div>';
523
-
524
- $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
525
-
526
- return $out;
527
- }
528
-
529
- /**
530
- * Display a monthly dropdown for filtering items
531
- *
532
- * @since 3.1.0
533
- * @access protected
534
- *
535
- * @global wpdb $wpdb
536
- * @global WP_Locale $wp_locale
537
- *
538
- * @param string $post_type
539
- */
540
- protected function months_dropdown( $post_type ) {
541
- global $wpdb, $wp_locale;
542
-
543
- /**
544
- * Filter whether to remove the 'Months' drop-down from the post list table.
545
- *
546
- * @since 4.2.0
547
- *
548
- * @param bool $disable Whether to disable the drop-down. Default false.
549
- * @param string $post_type The post type.
550
- */
551
- if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
552
- return;
553
- }
554
-
555
- $extra_checks = "AND post_status != 'auto-draft'";
556
- if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
557
- $extra_checks .= " AND post_status != 'trash'";
558
- } elseif ( isset( $_GET['post_status'] ) ) {
559
- $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
560
- }
561
-
562
- $months = $wpdb->get_results( $wpdb->prepare( "
563
- SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
564
- FROM $wpdb->posts
565
- WHERE post_type = %s
566
- $extra_checks
567
- ORDER BY post_date DESC
568
- ", $post_type ) );
569
-
570
- /**
571
- * Filter the 'Months' drop-down results.
572
- *
573
- * @since 3.7.0
574
- *
575
- * @param object $months The months drop-down query results.
576
- * @param string $post_type The post type.
577
- */
578
- $months = apply_filters( 'months_dropdown_results', $months, $post_type );
579
-
580
- $month_count = count( $months );
581
-
582
- if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
583
- return;
584
-
585
- $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
586
- ?>
587
- <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
588
- <select name="m" id="filter-by-date">
589
- <option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
590
- <?php
591
- foreach ( $months as $arc_row ) {
592
- if ( 0 == $arc_row->year )
593
- continue;
594
-
595
- $month = zeroise( $arc_row->month, 2 );
596
- $year = $arc_row->year;
597
-
598
- printf( "<option %s value='%s'>%s</option>\n",
599
- selected( $m, $year . $month, false ),
600
- esc_attr( $arc_row->year . $month ),
601
- /* translators: 1: month name, 2: 4-digit year */
602
- sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
603
- );
604
- }
605
- ?>
606
- </select>
607
- <?php
608
- }
609
-
610
- /**
611
- * Display a view switcher
612
- *
613
- * @since 3.1.0
614
- * @access protected
615
- *
616
- * @param string $current_mode
617
- */
618
- protected function view_switcher( $current_mode ) {
619
- ?>
620
- <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
621
- <div class="view-switch">
622
- <?php
623
- foreach ( $this->modes as $mode => $title ) {
624
- $classes = array( 'view-' . $mode );
625
- if ( $current_mode === $mode )
626
- $classes[] = 'current';
627
- printf(
628
- "<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
629
- esc_url( add_query_arg( 'mode', $mode ) ),
630
- implode( ' ', $classes ),
631
- $title
632
- );
633
- }
634
- ?>
635
- </div>
636
- <?php
637
- }
638
-
639
- /**
640
- * Display a comment count bubble
641
- *
642
- * @since 3.1.0
643
- * @access protected
644
- *
645
- * @param int $post_id The post ID.
646
- * @param int $pending_comments Number of pending comments.
647
- */
648
- protected function comments_bubble( $post_id, $pending_comments ) {
649
- $approved_comments = get_comments_number();
650
-
651
- $approved_comments_number = number_format_i18n( $approved_comments );
652
- $pending_comments_number = number_format_i18n( $pending_comments );
653
-
654
- $approved_only_phrase = sprintf( _n( '%s comment', '%s comments', $approved_comments ), $approved_comments_number );
655
- $approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
656
- $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
657
-
658
- // No comments at all.
659
- if ( ! $approved_comments && ! $pending_comments ) {
660
- printf( '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>',
661
- __( 'No comments' )
662
- );
663
- // Approved comments have different display depending on some conditions.
664
- } elseif ( $approved_comments ) {
665
- printf( '<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
666
- esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'approved' ), admin_url( 'edit-comments.php' ) ) ),
667
- $approved_comments_number,
668
- $pending_comments ? $approved_phrase : $approved_only_phrase
669
- );
670
- } else {
671
- printf( '<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
672
- $approved_comments_number,
673
- $pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
674
- );
675
- }
676
-
677
- if ( $pending_comments ) {
678
- printf( '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
679
- esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'moderated' ), admin_url( 'edit-comments.php' ) ) ),
680
- $pending_comments_number,
681
- $pending_phrase
682
- );
683
- } else {
684
- printf( '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
685
- $pending_comments_number,
686
- $approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
687
- );
688
- }
689
- }
690
-
691
- /**
692
- * Get the current page number
693
- *
694
- * @since 3.1.0
695
- * @access public
696
- *
697
- * @return int
698
- */
699
- public function get_pagenum() {
700
- $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
701
-
702
- if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
703
- $pagenum = $this->_pagination_args['total_pages'];
704
-
705
- return max( 1, $pagenum );
706
- }
707
-
708
- /**
709
- * Get number of items to display on a single page
710
- *
711
- * @since 3.1.0
712
- * @access protected
713
- *
714
- * @param string $option
715
- * @param int $default
716
- * @return int
717
- */
718
- protected function get_items_per_page( $option, $default = 20 ) {
719
- $per_page = (int) get_user_option( $option );
720
- if ( empty( $per_page ) || $per_page < 1 )
721
- $per_page = $default;
722
-
723
- /**
724
- * Filter the number of items to be displayed on each page of the list table.
725
- *
726
- * The dynamic hook name, $option, refers to the `per_page` option depending
727
- * on the type of list table in use. Possible values include: 'edit_comments_per_page',
728
- * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
729
- * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
730
- * 'edit_{$post_type}_per_page', etc.
731
- *
732
- * @since 2.9.0
733
- *
734
- * @param int $per_page Number of items to be displayed. Default 20.
735
- */
736
- return (int) apply_filters( $option, $per_page );
737
- }
738
-
739
- /**
740
- * Display the pagination.
741
- *
742
- * @since 3.1.0
743
- * @access protected
744
- *
745
- * @param string $which
746
- */
747
- protected function pagination( $which ) {
748
- if ( empty( $this->_pagination_args ) ) {
749
- return;
750
- }
751
-
752
- $total_items = $this->_pagination_args['total_items'];
753
- $total_pages = $this->_pagination_args['total_pages'];
754
- $infinite_scroll = false;
755
- if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
756
- $infinite_scroll = $this->_pagination_args['infinite_scroll'];
757
- }
758
-
759
- if ( 'top' === $which && $total_pages > 1 ) {
760
- $this->screen->render_screen_reader_content( 'heading_pagination' );
761
- }
762
-
763
- $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
764
-
765
- $current = $this->get_pagenum();
766
-
767
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
768
-
769
- $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
770
-
771
- $page_links = array();
772
-
773
- $total_pages_before = '<span class="paging-input">';
774
- $total_pages_after = '</span>';
775
-
776
- $disable_first = $disable_last = $disable_prev = $disable_next = false;
777
-
778
- if ( $current == 1 ) {
779
- $disable_first = true;
780
- $disable_prev = true;
781
- }
782
- if ( $current == 2 ) {
783
- $disable_first = true;
784
- }
785
- if ( $current == $total_pages ) {
786
- $disable_last = true;
787
- $disable_next = true;
788
- }
789
- if ( $current == $total_pages - 1 ) {
790
- $disable_last = true;
791
- }
792
-
793
- if ( $disable_first ) {
794
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
795
- } else {
796
- $page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
797
- esc_url( remove_query_arg( 'paged', $current_url ) ),
798
- __( 'First page' ),
799
- '&laquo;'
800
- );
801
- }
802
-
803
- if ( $disable_prev ) {
804
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
805
- } else {
806
- $page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
807
- esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
808
- __( 'Previous page' ),
809
- '&lsaquo;'
810
- );
811
- }
812
-
813
- if ( 'bottom' === $which ) {
814
- $html_current_page = $current;
815
- $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input">';
816
- } else {
817
- $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />",
818
- '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
819
- $current,
820
- strlen( $total_pages )
821
- );
822
- }
823
- $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
824
- $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
825
-
826
- if ( $disable_next ) {
827
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
828
- } else {
829
- $page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
830
- esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
831
- __( 'Next page' ),
832
- '&rsaquo;'
833
- );
834
- }
835
-
836
- if ( $disable_last ) {
837
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
838
- } else {
839
- $page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
840
- esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
841
- __( 'Last page' ),
842
- '&raquo;'
843
- );
844
- }
845
-
846
- $pagination_links_class = 'pagination-links';
847
- if ( ! empty( $infinite_scroll ) ) {
848
- $pagination_links_class = ' hide-if-js';
849
- }
850
- $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
851
-
852
- if ( $total_pages ) {
853
- $page_class = $total_pages < 2 ? ' one-page' : '';
854
- } else {
855
- $page_class = ' no-pages';
856
- }
857
- $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
858
-
859
- echo $this->_pagination;
860
- }
861
-
862
- /**
863
- * Get a list of columns. The format is:
864
- * 'internal-name' => 'Title'
865
- *
866
- * @since 3.1.0
867
- * @access public
868
- * @abstract
869
- *
870
- * @return array
871
- */
872
- public function get_columns() {
873
- die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
874
- }
875
-
876
- /**
877
- * Get a list of sortable columns. The format is:
878
- * 'internal-name' => 'orderby'
879
- * or
880
- * 'internal-name' => array( 'orderby', true )
881
- *
882
- * The second format will make the initial sorting order be descending
883
- *
884
- * @since 3.1.0
885
- * @access protected
886
- *
887
- * @return array
888
- */
889
- protected function get_sortable_columns() {
890
- return array();
891
- }
892
-
893
- /**
894
- * Gets the name of the default primary column.
895
- *
896
- * @since 4.3.0
897
- * @access protected
898
- *
899
- * @return string Name of the default primary column, in this case, an empty string.
900
- */
901
- protected function get_default_primary_column_name() {
902
- $columns = $this->get_columns();
903
- $column = '';
904
-
905
- if ( empty( $columns ) ) {
906
- return $column;
907
- }
908
-
909
- // We need a primary defined so responsive views show something,
910
- // so let's fall back to the first non-checkbox column.
911
- foreach ( $columns as $col => $column_name ) {
912
- if ( 'cb' === $col ) {
913
- continue;
914
- }
915
-
916
- $column = $col;
917
- break;
918
- }
919
-
920
- return $column;
921
- }
922
-
923
- /**
924
- * Public wrapper for WP_List_Table::get_default_primary_column_name().
925
- *
926
- * @since 4.4.0
927
- * @access public
928
- *
929
- * @return string Name of the default primary column.
930
- */
931
- public function get_primary_column() {
932
- return $this->get_primary_column_name();
933
- }
934
-
935
- /**
936
- * Gets the name of the primary column.
937
- *
938
- * @since 4.3.0
939
- * @access protected
940
- *
941
- * @return string The name of the primary column.
942
- */
943
- protected function get_primary_column_name() {
944
- $columns = get_column_headers( $this->screen );
945
- $default = $this->get_default_primary_column_name();
946
-
947
- // If the primary column doesn't exist fall back to the
948
- // first non-checkbox column.
949
- if ( ! isset( $columns[ $default ] ) ) {
950
- $default = WP_List_Table::get_default_primary_column_name();
951
- }
952
-
953
- /**
954
- * Filter the name of the primary column for the current list table.
955
- *
956
- * @since 4.3.0
957
- *
958
- * @param string $default Column name default for the specific list table, e.g. 'name'.
959
- * @param string $context Screen ID for specific list table, e.g. 'plugins'.
960
- */
961
- $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
962
-
963
- if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
964
- $column = $default;
965
- }
966
-
967
- return $column;
968
- }
969
-
970
- /**
971
- * Get a list of all, hidden and sortable columns, with filter applied
972
- *
973
- * @since 3.1.0
974
- * @access protected
975
- *
976
- * @return array
977
- */
978
- protected function get_column_info() {
979
- // $_column_headers is already set / cached
980
- if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
981
- // Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
982
- // In 4.3, we added a fourth argument for primary column.
983
- $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
984
- foreach ( $this->_column_headers as $key => $value ) {
985
- $column_headers[ $key ] = $value;
986
- }
987
-
988
- return $column_headers;
989
- }
990
-
991
- $columns = get_column_headers( $this->screen );
992
- $hidden = get_hidden_columns( $this->screen );
993
-
994
- $sortable_columns = $this->get_sortable_columns();
995
- /**
996
- * Filter the list table sortable columns for a specific screen.
997
- *
998
- * The dynamic portion of the hook name, `$this->screen->id`, refers
999
- * to the ID of the current screen, usually a string.
1000
- *
1001
- * @since 3.5.0
1002
- *
1003
- * @param array $sortable_columns An array of sortable columns.
1004
- */
1005
- $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
1006
-
1007
- $sortable = array();
1008
- foreach ( $_sortable as $id => $data ) {
1009
- if ( empty( $data ) )
1010
- continue;
1011
-
1012
- $data = (array) $data;
1013
- if ( !isset( $data[1] ) )
1014
- $data[1] = false;
1015
-
1016
- $sortable[$id] = $data;
1017
- }
1018
-
1019
- $primary = $this->get_primary_column_name();
1020
- $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
1021
-
1022
- return $this->_column_headers;
1023
- }
1024
-
1025
- /**
1026
- * Return number of visible columns
1027
- *
1028
- * @since 3.1.0
1029
- * @access public
1030
- *
1031
- * @return int
1032
- */
1033
- public function get_column_count() {
1034
- list ( $columns, $hidden ) = $this->get_column_info();
1035
- $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
1036
- return count( $columns ) - count( $hidden );
1037
- }
1038
-
1039
- /**
1040
- * Print column headers, accounting for hidden and sortable columns.
1041
- *
1042
- * @since 3.1.0
1043
- * @access public
1044
- *
1045
- * @staticvar int $cb_counter
1046
- *
1047
- * @param bool $with_id Whether to set the id attribute or not
1048
- */
1049
- public function print_column_headers( $with_id = true ) {
1050
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1051
-
1052
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1053
- $current_url = remove_query_arg( 'paged', $current_url );
1054
-
1055
- if ( isset( $_GET['orderby'] ) ) {
1056
- $current_orderby = $_GET['orderby'];
1057
- } else {
1058
- $current_orderby = '';
1059
- }
1060
-
1061
- if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
1062
- $current_order = 'desc';
1063
- } else {
1064
- $current_order = 'asc';
1065
- }
1066
-
1067
- if ( ! empty( $columns['cb'] ) ) {
1068
- static $cb_counter = 1;
1069
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
1070
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
1071
- $cb_counter++;
1072
- }
1073
-
1074
- foreach ( $columns as $column_key => $column_display_name ) {
1075
- $class = array( 'manage-column', "column-$column_key" );
1076
-
1077
- if ( in_array( $column_key, $hidden ) ) {
1078
- $class[] = 'hidden';
1079
- }
1080
-
1081
- if ( 'cb' === $column_key )
1082
- $class[] = 'check-column';
1083
- elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
1084
- $class[] = 'num';
1085
-
1086
- if ( $column_key === $primary ) {
1087
- $class[] = 'column-primary';
1088
- }
1089
-
1090
- if ( isset( $sortable[$column_key] ) ) {
1091
- list( $orderby, $desc_first ) = $sortable[$column_key];
1092
-
1093
- if ( $current_orderby === $orderby ) {
1094
- $order = 'asc' === $current_order ? 'desc' : 'asc';
1095
- $class[] = 'sorted';
1096
- $class[] = $current_order;
1097
- } else {
1098
- $order = $desc_first ? 'desc' : 'asc';
1099
- $class[] = 'sortable';
1100
- $class[] = $desc_first ? 'asc' : 'desc';
1101
- }
1102
-
1103
- $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
1104
- }
1105
-
1106
- $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
1107
- $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1108
- $id = $with_id ? "id='$column_key'" : '';
1109
-
1110
- if ( !empty( $class ) )
1111
- $class = "class='" . join( ' ', $class ) . "'";
1112
-
1113
- echo "<$tag $scope $id $class>$column_display_name</$tag>";
1114
- }
1115
- }
1116
-
1117
- /**
1118
- * Display the table
1119
- *
1120
- * @since 3.1.0
1121
- * @access public
1122
- */
1123
- public function display() {
1124
- $singular = $this->_args['singular'];
1125
-
1126
- $this->display_tablenav( 'top' );
1127
-
1128
- $this->screen->render_screen_reader_content( 'heading_list' );
1129
- ?>
1130
- <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
1131
- <thead>
1132
- <tr>
1133
- <?php $this->print_column_headers(); ?>
1134
- </tr>
1135
- </thead>
1136
-
1137
- <tbody id="the-list"<?php
1138
- if ( $singular ) {
1139
- echo " data-wp-lists='list:$singular'";
1140
- } ?>>
1141
- <?php $this->display_rows_or_placeholder(); ?>
1142
- </tbody>
1143
-
1144
- <tfoot>
1145
- <tr>
1146
- <?php $this->print_column_headers( false ); ?>
1147
- </tr>
1148
- </tfoot>
1149
-
1150
- </table>
1151
- <?php
1152
- $this->display_tablenav( 'bottom' );
1153
- }
1154
-
1155
- /**
1156
- * Get a list of CSS classes for the list table table tag.
1157
- *
1158
- * @since 3.1.0
1159
- * @access protected
1160
- *
1161
- * @return array List of CSS classes for the table tag.
1162
- */
1163
- protected function get_table_classes() {
1164
- return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
1165
- }
1166
-
1167
- /**
1168
- * Generate the table navigation above or below the table
1169
- *
1170
- * @since 3.1.0
1171
- * @access protected
1172
- * @param string $which
1173
- */
1174
- protected function display_tablenav( $which ) {
1175
- if ( 'top' === $which ) {
1176
- wp_nonce_field( 'bulk-' . $this->_args['plural'] );
1177
- }
1178
- ?>
1179
- <div class="tablenav <?php echo esc_attr( $which ); ?>">
1180
-
1181
- <?php if ( $this->has_items() ): ?>
1182
- <div class="alignleft actions bulkactions">
1183
- <?php $this->bulk_actions( $which ); ?>
1184
- </div>
1185
- <?php endif;
1186
- $this->extra_tablenav( $which );
1187
- $this->pagination( $which );
1188
- ?>
1189
-
1190
- <br class="clear" />
1191
- </div>
1192
- <?php
1193
- }
1194
-
1195
- /**
1196
- * Extra controls to be displayed between bulk actions and pagination
1197
- *
1198
- * @since 3.1.0
1199
- * @access protected
1200
- *
1201
- * @param string $which
1202
- */
1203
- protected function extra_tablenav( $which ) {}
1204
-
1205
- /**
1206
- * Generate the tbody element for the list table.
1207
- *
1208
- * @since 3.1.0
1209
- * @access public
1210
- */
1211
- public function display_rows_or_placeholder() {
1212
- if ( $this->has_items() ) {
1213
- $this->display_rows();
1214
- } else {
1215
- echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
1216
- $this->no_items();
1217
- echo '</td></tr>';
1218
- }
1219
- }
1220
-
1221
- /**
1222
- * Generate the table rows
1223
- *
1224
- * @since 3.1.0
1225
- * @access public
1226
- */
1227
- public function display_rows() {
1228
- foreach ( $this->items as $item )
1229
- $this->single_row( $item );
1230
- }
1231
-
1232
- /**
1233
- * Generates content for a single row of the table
1234
- *
1235
- * @since 3.1.0
1236
- * @access public
1237
- *
1238
- * @param object $item The current item
1239
- */
1240
- public function single_row( $item ) {
1241
- echo '<tr>';
1242
- $this->single_row_columns( $item );
1243
- echo '</tr>';
1244
- }
1245
-
1246
- /**
1247
- *
1248
- * @param object $item
1249
- * @param string $column_name
1250
- */
1251
- protected function column_default( $item, $column_name ) {}
1252
-
1253
- /**
1254
- *
1255
- * @param object $item
1256
- */
1257
- protected function column_cb( $item ) {}
1258
-
1259
- /**
1260
- * Generates the columns for a single row of the table
1261
- *
1262
- * @since 3.1.0
1263
- * @access protected
1264
- *
1265
- * @param object $item The current item
1266
- */
1267
- protected function single_row_columns( $item ) {
1268
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1269
-
1270
- foreach ( $columns as $column_name => $column_display_name ) {
1271
- $classes = "$column_name column-$column_name";
1272
- if ( $primary === $column_name ) {
1273
- $classes .= ' has-row-actions column-primary';
1274
- }
1275
-
1276
- if ( in_array( $column_name, $hidden ) ) {
1277
- $classes .= ' hidden';
1278
- }
1279
-
1280
- // Comments column uses HTML in the display name with screen reader text.
1281
- // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
1282
- $data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
1283
-
1284
- $attributes = "class='$classes' $data";
1285
-
1286
- if ( 'cb' === $column_name ) {
1287
- echo '<th scope="row" class="check-column">';
1288
- echo $this->column_cb( $item );
1289
- echo '</th>';
1290
- } elseif ( method_exists( $this, '_column_' . $column_name ) ) {
1291
- echo call_user_func(
1292
- array( $this, '_column_' . $column_name ),
1293
- $item,
1294
- $classes,
1295
- $data,
1296
- $primary
1297
- );
1298
- } elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1299
- echo "<td $attributes>";
1300
- echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1301
- echo $this->handle_row_actions( $item, $column_name, $primary );
1302
- echo "</td>";
1303
- } else {
1304
- echo "<td $attributes>";
1305
- echo $this->column_default( $item, $column_name );
1306
- echo $this->handle_row_actions( $item, $column_name, $primary );
1307
- echo "</td>";
1308
- }
1309
- }
1310
- }
1311
-
1312
- /**
1313
- * Generates and display row actions links for the list table.
1314
- *
1315
- * @since 4.3.0
1316
- * @access protected
1317
- *
1318
- * @param object $item The item being acted upon.
1319
- * @param string $column_name Current column name.
1320
- * @param string $primary Primary column name.
1321
- * @return string The row actions HTML, or an empty string if the current column is the primary column.
1322
- */
1323
- protected function handle_row_actions( $item, $column_name, $primary ) {
1324
- return $column_name === $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : '';
1325
- }
1326
-
1327
- /**
1328
- * Handle an incoming ajax request (called from admin-ajax.php)
1329
- *
1330
- * @since 3.1.0
1331
- * @access public
1332
- */
1333
- public function ajax_response() {
1334
- $this->prepare_items();
1335
-
1336
- ob_start();
1337
- if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1338
- $this->display_rows();
1339
- } else {
1340
- $this->display_rows_or_placeholder();
1341
- }
1342
-
1343
- $rows = ob_get_clean();
1344
-
1345
- $response = array( 'rows' => $rows );
1346
-
1347
- if ( isset( $this->_pagination_args['total_items'] ) ) {
1348
- $response['total_items_i18n'] = sprintf(
1349
- _n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
1350
- number_format_i18n( $this->_pagination_args['total_items'] )
1351
- );
1352
- }
1353
- if ( isset( $this->_pagination_args['total_pages'] ) ) {
1354
- $response['total_pages'] = $this->_pagination_args['total_pages'];
1355
- $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1356
- }
1357
-
1358
- die( wp_json_encode( $response ) );
1359
- }
1360
-
1361
- /**
1362
- * Send required variables to JavaScript land
1363
- *
1364
- * @access public
1365
- */
1366
- public function _js_vars() {
1367
- $args = array(
1368
- 'class' => get_class( $this ),
1369
- 'screen' => array(
1370
- 'id' => $this->screen->id,
1371
- 'base' => $this->screen->base,
1372
- )
1373
- );
1374
-
1375
- printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
1376
- }
1377
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/core/class-wp-list-table-old.php DELETED
@@ -1,1143 +0,0 @@
1
- <?php
2
- /**
3
- * Base class for displaying a list of items in an ajaxified HTML table.
4
- * We are not using this class from core WordPress since it is not
5
- * recommended by WordPress itself.
6
- *
7
- * @since 3.1.0
8
- * @access private
9
- *
10
- * @package I4T3
11
- * @subpackage I4T3/List_Table
12
- */
13
- class WP_List_Table_404 {
14
-
15
- /**
16
- * The current list of items
17
- *
18
- * @since 3.1.0
19
- * @var array
20
- * @access public
21
- */
22
- public $items;
23
-
24
- /**
25
- * Various information about the current table
26
- *
27
- * @since 3.1.0
28
- * @var array
29
- * @access protected
30
- */
31
- protected $_args;
32
-
33
- /**
34
- * Various information needed for displaying the pagination
35
- *
36
- * @since 3.1.0
37
- * @var array
38
- */
39
- protected $_pagination_args = array();
40
-
41
- /**
42
- * The current screen
43
- *
44
- * @since 3.1.0
45
- * @var object
46
- * @access protected
47
- */
48
- protected $screen;
49
-
50
- /**
51
- * Cached bulk actions
52
- *
53
- * @since 3.1.0
54
- * @var array
55
- * @access private
56
- */
57
- private $_actions;
58
-
59
- /**
60
- * Cached pagination output
61
- *
62
- * @since 3.1.0
63
- * @var string
64
- * @access private
65
- */
66
- private $_pagination;
67
-
68
- /**
69
- * The view switcher modes.
70
- *
71
- * @since 4.1.0
72
- * @var array
73
- * @access protected
74
- */
75
- protected $modes = array();
76
-
77
- /**
78
- * Stores the value returned by ->get_column_info()
79
- *
80
- * @var array
81
- */
82
- protected $_column_headers;
83
-
84
- protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
85
-
86
- protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions',
87
- 'row_actions', 'months_dropdown', 'view_switcher', 'comments_bubble', 'get_items_per_page', 'pagination',
88
- 'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav',
89
- 'single_row_columns' );
90
-
91
- /**
92
- * Constructor.
93
- *
94
- * The child class should call this constructor from its own constructor to override
95
- * the default $args.
96
- *
97
- * @since 3.1.0
98
- * @access public
99
- *
100
- * @param array|string $args {
101
- * Array or string of arguments.
102
- *
103
- * @type string $plural Plural value used for labels and the objects being listed.
104
- * This affects things such as CSS class-names and nonces used
105
- * in the list table, e.g. 'posts'. Default empty.
106
- * @type string $singular Singular label for an object being listed, e.g. 'post'.
107
- * Default empty
108
- * @type bool $ajax Whether the list table supports AJAX. This includes loading
109
- * and sorting data, for example. If true, the class will call
110
- * the {@see _js_vars()} method in the footer to provide variables
111
- * to any scripts handling AJAX events. Default false.
112
- * @type string $screen String containing the hook name used to determine the current
113
- * screen. If left null, the current screen will be automatically set.
114
- * Default null.
115
- * }
116
- */
117
- public function __construct( $args = array() ) {
118
- $args = wp_parse_args( $args, array(
119
- 'plural' => '',
120
- 'singular' => '',
121
- 'ajax' => false,
122
- 'screen' => null,
123
- ) );
124
-
125
- $this->screen = convert_to_screen( $args['screen'] );
126
-
127
- add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
128
-
129
- if ( !$args['plural'] )
130
- $args['plural'] = $this->screen->base;
131
-
132
- $args['plural'] = sanitize_key( $args['plural'] );
133
- $args['singular'] = sanitize_key( $args['singular'] );
134
-
135
- $this->_args = $args;
136
-
137
- if ( $args['ajax'] ) {
138
- // wp_enqueue_script( 'list-table' );
139
- add_action( 'admin_footer', array( $this, '_js_vars' ) );
140
- }
141
-
142
- if ( empty( $this->modes ) ) {
143
- $this->modes = array(
144
- 'list' => __( 'List View', '404-to-301' ),
145
- 'excerpt' => __( 'Excerpt View', '404-to-301' )
146
- );
147
- }
148
- }
149
-
150
- /**
151
- * Make private properties readable for backwards compatibility.
152
- *
153
- * @since 4.0.0
154
- * @access public
155
- *
156
- * @param string $name Property to get.
157
- * @return mixed Property.
158
- */
159
- public function __get( $name ) {
160
- if ( in_array( $name, $this->compat_fields ) ) {
161
- return $this->$name;
162
- }
163
- }
164
-
165
- /**
166
- * Make private properties settable for backwards compatibility.
167
- *
168
- * @since 4.0.0
169
- * @access public
170
- *
171
- * @param string $name Property to check if set.
172
- * @param mixed $value Property value.
173
- * @return mixed Newly-set property.
174
- */
175
- public function __set( $name, $value ) {
176
- if ( in_array( $name, $this->compat_fields ) ) {
177
- return $this->$name = $value;
178
- }
179
- }
180
-
181
- /**
182
- * Make private properties checkable for backwards compatibility.
183
- *
184
- * @since 4.0.0
185
- * @access public
186
- *
187
- * @param string $name Property to check if set.
188
- * @return bool Whether the property is set.
189
- */
190
- public function __isset( $name ) {
191
- if ( in_array( $name, $this->compat_fields ) ) {
192
- return isset( $this->$name );
193
- }
194
- }
195
-
196
- /**
197
- * Make private properties un-settable for backwards compatibility.
198
- *
199
- * @since 4.0.0
200
- * @access public
201
- *
202
- * @param string $name Property to unset.
203
- */
204
- public function __unset( $name ) {
205
- if ( in_array( $name, $this->compat_fields ) ) {
206
- unset( $this->$name );
207
- }
208
- }
209
-
210
- /**
211
- * Make private/protected methods readable for backwards compatibility.
212
- *
213
- * @since 4.0.0
214
- * @access public
215
- *
216
- * @param callable $name Method to call.
217
- * @param array $arguments Arguments to pass when calling.
218
- * @return mixed|bool Return value of the callback, false otherwise.
219
- */
220
- public function __call( $name, $arguments ) {
221
- if ( in_array( $name, $this->compat_methods ) ) {
222
- return call_user_func_array( array( $this, $name ), $arguments );
223
- }
224
- return false;
225
- }
226
-
227
- /**
228
- * Checks the current user's permissions
229
- *
230
- * @since 3.1.0
231
- * @access public
232
- * @abstract
233
- */
234
- public function ajax_user_can() {
235
- die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
236
- }
237
-
238
- /**
239
- * Prepares the list of items for displaying.
240
- * @uses WP_List_Table::set_pagination_args()
241
- *
242
- * @since 3.1.0
243
- * @access public
244
- * @abstract
245
- */
246
- public function prepare_items() {
247
- die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
248
- }
249
-
250
- /**
251
- * An internal method that sets all the necessary pagination arguments
252
- *
253
- * @param array $args An associative array with information about the pagination
254
- * @access protected
255
- */
256
- protected function set_pagination_args( $args ) {
257
- $args = wp_parse_args( $args, array(
258
- 'total_items' => 0,
259
- 'total_pages' => 0,
260
- 'per_page' => 0,
261
- ) );
262
-
263
- if ( !$args['total_pages'] && $args['per_page'] > 0 )
264
- $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
265
-
266
- // Redirect if page number is invalid and headers are not already sent.
267
- if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
268
- wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
269
- exit;
270
- }
271
-
272
- $this->_pagination_args = $args;
273
- }
274
-
275
- /**
276
- * Access the pagination args.
277
- *
278
- * @since 3.1.0
279
- * @access public
280
- *
281
- * @param string $key Pagination argument to retrieve. Common values include 'total_items',
282
- * 'total_pages', 'per_page', or 'infinite_scroll'.
283
- * @return int Number of items that correspond to the given pagination argument.
284
- */
285
- public function get_pagination_arg( $key ) {
286
- if ( 'page' == $key )
287
- return $this->get_pagenum();
288
-
289
- if ( isset( $this->_pagination_args[$key] ) )
290
- return $this->_pagination_args[$key];
291
- }
292
-
293
- /**
294
- * Whether the table has items to display or not
295
- *
296
- * @since 3.1.0
297
- * @access public
298
- *
299
- * @return bool
300
- */
301
- public function has_items() {
302
- return !empty( $this->items );
303
- }
304
-
305
- /**
306
- * Message to be displayed when there are no items
307
- *
308
- * @since 3.1.0
309
- * @access public
310
- */
311
- public function no_items() {
312
- _e( 'No items found.' );
313
- }
314
-
315
- /**
316
- * Display the search box.
317
- *
318
- * @since 3.1.0
319
- * @access public
320
- *
321
- * @param string $text The search button text
322
- * @param string $input_id The search input id
323
- */
324
- public function search_box( $text, $input_id ) {
325
- if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
326
- return;
327
-
328
- $input_id = $input_id . '-search-input';
329
-
330
- if ( ! empty( $_REQUEST['orderby'] ) )
331
- echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
332
- if ( ! empty( $_REQUEST['order'] ) )
333
- echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
334
- if ( ! empty( $_REQUEST['post_mime_type'] ) )
335
- echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
336
- if ( ! empty( $_REQUEST['detached'] ) )
337
- echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
338
- ?>
339
- <p class="search-box">
340
- <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
341
- <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
342
- <?php submit_button( $text, 'button', '', false, array('id' => 'search-submit') ); ?>
343
- </p>
344
- <?php
345
- }
346
-
347
- /**
348
- * Get an associative array ( id => link ) with the list
349
- * of views available on this table.
350
- *
351
- * @since 3.1.0
352
- * @access protected
353
- *
354
- * @return array
355
- */
356
- protected function get_views() {
357
- return array();
358
- }
359
-
360
- /**
361
- * Display the list of views available on this table.
362
- *
363
- * @since 3.1.0
364
- * @access public
365
- */
366
- public function views() {
367
- $views = $this->get_views();
368
- /**
369
- * Filter the list of available list table views.
370
- *
371
- * The dynamic portion of the hook name, `$this->screen->id`, refers
372
- * to the ID of the current screen, usually a string.
373
- *
374
- * @since 3.5.0
375
- *
376
- * @param array $views An array of available list table views.
377
- */
378
- $views = apply_filters( "views_{$this->screen->id}", $views );
379
-
380
- if ( empty( $views ) )
381
- return;
382
-
383
- echo "<ul class='subsubsub'>\n";
384
- foreach ( $views as $class => $view ) {
385
- $views[ $class ] = "\t<li class='$class'>$view";
386
- }
387
- echo implode( " |</li>\n", $views ) . "</li>\n";
388
- echo "</ul>";
389
- }
390
-
391
- /**
392
- * Get an associative array ( option_name => option_title ) with the list
393
- * of bulk actions available on this table.
394
- *
395
- * @since 3.1.0
396
- * @access protected
397
- *
398
- * @return array
399
- */
400
- protected function get_bulk_actions() {
401
- return array();
402
- }
403
-
404
- /**
405
- * Display the bulk actions dropdown.
406
- *
407
- * @since 3.1.0
408
- * @access protected
409
- *
410
- * @param string $which The location of the bulk actions: 'top' or 'bottom'.
411
- * This is designated as optional for backwards-compatibility.
412
- */
413
- protected function bulk_actions( $which = '' ) {
414
- if ( is_null( $this->_actions ) ) {
415
- $no_new_actions = $this->_actions = $this->get_bulk_actions();
416
- /**
417
- * Filter the list table Bulk Actions drop-down.
418
- *
419
- * The dynamic portion of the hook name, `$this->screen->id`, refers
420
- * to the ID of the current screen, usually a string.
421
- *
422
- * This filter can currently only be used to remove bulk actions.
423
- *
424
- * @since 3.5.0
425
- *
426
- * @param array $actions An array of the available bulk actions.
427
- */
428
- $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
429
- $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
430
- $two = '';
431
- } else {
432
- $two = '2';
433
- }
434
-
435
- if ( empty( $this->_actions ) )
436
- return;
437
-
438
- echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . __( 'Select bulk action', '404-to-301' ) . "</label>";
439
- echo "<select name='action$two' id='bulk-action-selector-" . esc_attr( $which ) . "'>\n";
440
- echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions', '404-to-301' ) . "</option>\n";
441
-
442
- foreach ( $this->_actions as $name => $title ) {
443
- $class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
444
-
445
- echo "\t<option value='$name'$class>$title</option>\n";
446
- }
447
-
448
- echo "</select>\n";
449
-
450
- submit_button( __( 'Apply', '404-to-301' ), 'action', '', false, array( 'id' => "doaction$two" ) );
451
- echo "\n";
452
- }
453
-
454
- /**
455
- * Get the current action selected from the bulk actions dropdown.
456
- *
457
- * @since 3.1.0
458
- * @access public
459
- *
460
- * @return string|bool The action name or False if no action was selected
461
- */
462
- public function current_action() {
463
- if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
464
- return false;
465
-
466
- if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
467
- return $_REQUEST['action'];
468
-
469
- if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
470
- return $_REQUEST['action2'];
471
-
472
- return false;
473
- }
474
-
475
- /**
476
- * Generate row actions div
477
- *
478
- * @since 3.1.0
479
- * @access protected
480
- *
481
- * @param array $actions The list of actions
482
- * @param bool $always_visible Whether the actions should be always visible
483
- * @return string
484
- */
485
- protected function row_actions( $actions, $always_visible = false ) {
486
- $action_count = count( $actions );
487
- $i = 0;
488
-
489
- if ( !$action_count )
490
- return '';
491
-
492
- $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
493
- foreach ( $actions as $action => $link ) {
494
- ++$i;
495
- ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
496
- $out .= "<span class='$action'>$link$sep</span>";
497
- }
498
- $out .= '</div>';
499
-
500
- return $out;
501
- }
502
-
503
- /**
504
- * Display a monthly dropdown for filtering items
505
- *
506
- * @since 3.1.0
507
- * @access protected
508
- *
509
- * @param string $post_type
510
- */
511
- protected function months_dropdown( $post_type ) {
512
- global $wpdb, $wp_locale;
513
-
514
- /**
515
- * Filter whether to remove the 'Months' drop-down from the post list table.
516
- *
517
- * @since 4.2.0
518
- *
519
- * @param bool $disable Whether to disable the drop-down. Default false.
520
- * @param string $post_type The post type.
521
- */
522
- if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
523
- return;
524
- }
525
-
526
- $months = $wpdb->get_results( $wpdb->prepare( "
527
- SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
528
- FROM $wpdb->posts
529
- WHERE post_type = %s
530
- ORDER BY post_date DESC
531
- ", $post_type ) );
532
-
533
- /**
534
- * Filter the 'Months' drop-down results.
535
- *
536
- * @since 3.7.0
537
- *
538
- * @param object $months The months drop-down query results.
539
- * @param string $post_type The post type.
540
- */
541
- $months = apply_filters( 'months_dropdown_results', $months, $post_type );
542
-
543
- $month_count = count( $months );
544
-
545
- if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
546
- return;
547
-
548
- $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
549
- ?>
550
- <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
551
- <select name="m" id="filter-by-date">
552
- <option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
553
- <?php
554
- foreach ( $months as $arc_row ) {
555
- if ( 0 == $arc_row->year )
556
- continue;
557
-
558
- $month = zeroise( $arc_row->month, 2 );
559
- $year = $arc_row->year;
560
-
561
- printf( "<option %s value='%s'>%s</option>\n",
562
- selected( $m, $year . $month, false ),
563
- esc_attr( $arc_row->year . $month ),
564
- /* translators: 1: month name, 2: 4-digit year */
565
- sprintf( __( '%1$s %2$d', '404-to-301' ), $wp_locale->get_month( $month ), $year )
566
- );
567
- }
568
- ?>
569
- </select>
570
- <?php
571
- }
572
-
573
- /**
574
- * Display a view switcher
575
- *
576
- * @since 3.1.0
577
- * @access protected
578
- *
579
- * @param string $current_mode
580
- */
581
- protected function view_switcher( $current_mode ) {
582
- ?>
583
- <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
584
- <div class="view-switch">
585
- <?php
586
- foreach ( $this->modes as $mode => $title ) {
587
- $classes = array( 'view-' . $mode );
588
- if ( $current_mode == $mode )
589
- $classes[] = 'current';
590
- printf(
591
- "<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
592
- esc_url( add_query_arg( 'mode', $mode ) ),
593
- implode( ' ', $classes ),
594
- $title
595
- );
596
- }
597
- ?>
598
- </div>
599
- <?php
600
- }
601
-
602
- /**
603
- * Display a comment count bubble
604
- *
605
- * @since 3.1.0
606
- * @access protected
607
- *
608
- * @param int $post_id The post ID.
609
- * @param int $pending_comments Number of pending comments.
610
- */
611
- protected function comments_bubble( $post_id, $pending_comments ) {
612
- $pending_phrase = sprintf( __( '%s pending', '404-to-301' ), number_format( $pending_comments ) );
613
-
614
- if ( $pending_comments )
615
- echo '<strong>';
616
-
617
- echo "<a href='" . esc_url( add_query_arg( 'p', $post_id, admin_url( 'edit-comments.php' ) ) ) . "' title='" . esc_attr( $pending_phrase ) . "' class='post-com-count'><span class='comment-count'>" . number_format_i18n( get_comments_number() ) . "</span></a>";
618
-
619
- if ( $pending_comments )
620
- echo '</strong>';
621
- }
622
-
623
- /**
624
- * Get the current page number
625
- *
626
- * @since 3.1.0
627
- * @access public
628
- *
629
- * @return int
630
- */
631
- public function get_pagenum() {
632
- $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
633
-
634
- if( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
635
- $pagenum = $this->_pagination_args['total_pages'];
636
-
637
- return max( 1, $pagenum );
638
- }
639
-
640
- /**
641
- * Get number of items to display on a single page
642
- *
643
- * @since 3.1.0
644
- * @access protected
645
- *
646
- * @param string $option
647
- * @param int $default
648
- * @return int
649
- */
650
- protected function get_items_per_page( $option, $default = 20 ) {
651
- $per_page = (int) get_user_option( $option );
652
- if ( empty( $per_page ) || $per_page < 1 )
653
- $per_page = $default;
654
-
655
- /**
656
- * Filter the number of items to be displayed on each page of the list table.
657
- *
658
- * The dynamic hook name, $option, refers to the `per_page` option depending
659
- * on the type of list table in use. Possible values include: 'edit_comments_per_page',
660
- * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
661
- * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
662
- * 'edit_{$post_type}_per_page', etc.
663
- *
664
- * @since 2.9.0
665
- *
666
- * @param int $per_page Number of items to be displayed. Default 20.
667
- */
668
- return (int) apply_filters( $option, $per_page );
669
- }
670
-
671
- /**
672
- * Display the pagination.
673
- *
674
- * @since 3.1.0
675
- * @access protected
676
- *
677
- * @param string $which
678
- */
679
- protected function pagination( $which ) {
680
- if ( empty( $this->_pagination_args ) ) {
681
- return;
682
- }
683
-
684
- $total_items = $this->_pagination_args['total_items'];
685
- $total_pages = $this->_pagination_args['total_pages'];
686
- $infinite_scroll = false;
687
- if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
688
- $infinite_scroll = $this->_pagination_args['infinite_scroll'];
689
- }
690
-
691
- $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
692
-
693
- $current = $this->get_pagenum();
694
-
695
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
696
-
697
- $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
698
-
699
- $page_links = array();
700
-
701
- $disable_first = $disable_last = '';
702
- if ( $current == 1 ) {
703
- $disable_first = ' disabled';
704
- }
705
- if ( $current == $total_pages ) {
706
- $disable_last = ' disabled';
707
- }
708
- $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
709
- 'first-page' . $disable_first,
710
- esc_attr__( 'Go to the first page', '404-to-301' ),
711
- esc_url( remove_query_arg( 'paged', $current_url ) ),
712
- '&laquo;'
713
- );
714
-
715
- $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
716
- 'prev-page' . $disable_first,
717
- esc_attr__( 'Go to the previous page', '404-to-301' ),
718
- esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
719
- '&lsaquo;'
720
- );
721
-
722
- if ( 'bottom' == $which ) {
723
- $html_current_page = $current;
724
- } else {
725
- $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' title='%s' type='text' name='paged' value='%s' size='%d' />",
726
- '<label for="current-page-selector" class="screen-reader-text">' . __( 'Select Page', '404-to-301' ) . '</label>',
727
- esc_attr__( 'Current Page', '404-to-301' ),
728
- $current,
729
- strlen( $total_pages )
730
- );
731
- }
732
- $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
733
- $page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>';
734
-
735
- $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
736
- 'next-page' . $disable_last,
737
- esc_attr__( 'Go to the next page', '404-to-301' ),
738
- esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
739
- '&rsaquo;'
740
- );
741
-
742
- $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
743
- 'last-page' . $disable_last,
744
- esc_attr__( 'Go to the last page', '404-to-301' ),
745
- esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
746
- '&raquo;'
747
- );
748
-
749
- $pagination_links_class = 'pagination-links';
750
- if ( ! empty( $infinite_scroll ) ) {
751
- $pagination_links_class = ' hide-if-js';
752
- }
753
- $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
754
-
755
- if ( $total_pages ) {
756
- $page_class = $total_pages < 2 ? ' one-page' : '';
757
- } else {
758
- $page_class = ' no-pages';
759
- }
760
- $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
761
-
762
- echo $this->_pagination;
763
- }
764
-
765
- /**
766
- * Get a list of columns. The format is:
767
- * 'internal-name' => 'Title'
768
- *
769
- * @since 3.1.0
770
- * @access public
771
- * @abstract
772
- *
773
- * @return array
774
- */
775
- public function get_columns() {
776
- die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
777
- }
778
-
779
- /**
780
- * Get a list of sortable columns. The format is:
781
- * 'internal-name' => 'orderby'
782
- * or
783
- * 'internal-name' => array( 'orderby', true )
784
- *
785
- * The second format will make the initial sorting order be descending
786
- *
787
- * @since 3.1.0
788
- * @access protected
789
- *
790
- * @return array
791
- */
792
- protected function get_sortable_columns() {
793
- return array();
794
- }
795
-
796
- /**
797
- * Get a list of all, hidden and sortable columns, with filter applied
798
- *
799
- * @since 3.1.0
800
- * @access protected
801
- *
802
- * @return array
803
- */
804
- protected function get_column_info() {
805
- if ( isset( $this->_column_headers ) )
806
- return $this->_column_headers;
807
-
808
- $columns = get_column_headers( $this->screen );
809
- $hidden = get_hidden_columns( $this->screen );
810
-
811
- $sortable_columns = $this->get_sortable_columns();
812
- /**
813
- * Filter the list table sortable columns for a specific screen.
814
- *
815
- * The dynamic portion of the hook name, `$this->screen->id`, refers
816
- * to the ID of the current screen, usually a string.
817
- *
818
- * @since 3.5.0
819
- *
820
- * @param array $sortable_columns An array of sortable columns.
821
- */
822
- $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
823
-
824
- $sortable = array();
825
- foreach ( $_sortable as $id => $data ) {
826
- if ( empty( $data ) )
827
- continue;
828
-
829
- $data = (array) $data;
830
- if ( !isset( $data[1] ) )
831
- $data[1] = false;
832
-
833
- $sortable[$id] = $data;
834
- }
835
-
836
- $this->_column_headers = array( $columns, $hidden, $sortable );
837
-
838
- return $this->_column_headers;
839
- }
840
-
841
- /**
842
- * Return number of visible columns
843
- *
844
- * @since 3.1.0
845
- * @access public
846
- *
847
- * @return int
848
- */
849
- public function get_column_count() {
850
- list ( $columns, $hidden ) = $this->get_column_info();
851
- $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
852
- return count( $columns ) - count( $hidden );
853
- }
854
-
855
- /**
856
- * Print column headers, accounting for hidden and sortable columns.
857
- *
858
- * @since 3.1.0
859
- * @access public
860
- *
861
- * @param bool $with_id Whether to set the id attribute or not
862
- */
863
- public function print_column_headers( $with_id = true ) {
864
- list( $columns, $hidden, $sortable ) = $this->get_column_info();
865
-
866
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
867
- $current_url = remove_query_arg( 'paged', $current_url );
868
-
869
- if ( isset( $_GET['orderby'] ) )
870
- $current_orderby = $_GET['orderby'];
871
- else
872
- $current_orderby = '';
873
-
874
- if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
875
- $current_order = 'desc';
876
- else
877
- $current_order = 'asc';
878
-
879
- if ( ! empty( $columns['cb'] ) ) {
880
- static $cb_counter = 1;
881
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', '404-to-301' ) . '</label>'
882
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
883
- $cb_counter++;
884
- }
885
-
886
- foreach ( $columns as $column_key => $column_display_name ) {
887
- $class = array( 'manage-column', "column-$column_key" );
888
-
889
- $style = '';
890
- if ( in_array( $column_key, $hidden ) )
891
- $style = 'display:none;';
892
-
893
- $style = ' style="' . $style . '"';
894
-
895
- if ( 'cb' == $column_key )
896
- $class[] = 'check-column';
897
- elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
898
- $class[] = 'num';
899
-
900
- if ( isset( $sortable[$column_key] ) ) {
901
- list( $orderby, $desc_first ) = $sortable[$column_key];
902
-
903
- if ( $current_orderby == $orderby ) {
904
- $order = 'asc' == $current_order ? 'desc' : 'asc';
905
- $class[] = 'sorted';
906
- $class[] = $current_order;
907
- } else {
908
- $order = $desc_first ? 'desc' : 'asc';
909
- $class[] = 'sortable';
910
- $class[] = $desc_first ? 'asc' : 'desc';
911
- }
912
-
913
- $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
914
- }
915
-
916
- $id = $with_id ? "id='$column_key'" : '';
917
-
918
- if ( !empty( $class ) )
919
- $class = "class='" . join( ' ', $class ) . "'";
920
-
921
- echo "<th scope='col' $id $class $style>$column_display_name</th>";
922
- }
923
- }
924
-
925
- /**
926
- * Display the table
927
- *
928
- * @since 3.1.0
929
- * @access public
930
- */
931
- public function display() {
932
- $singular = $this->_args['singular'];
933
-
934
- $this->display_tablenav( 'top' );
935
-
936
- ?>
937
- <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
938
- <thead>
939
- <tr>
940
- <?php $this->print_column_headers(); ?>
941
- </tr>
942
- </thead>
943
-
944
- <tbody id="the-list"<?php
945
- if ( $singular ) {
946
- echo " data-wp-lists='list:$singular'";
947
- } ?>>
948
- <?php $this->display_rows_or_placeholder(); ?>
949
- </tbody>
950
-
951
- <tfoot>
952
- <tr>
953
- <?php $this->print_column_headers( false ); ?>
954
- </tr>
955
- </tfoot>
956
-
957
- </table>
958
- <?php
959
- $this->display_tablenav( 'bottom' );
960
- }
961
-
962
- /**
963
- * Get a list of CSS classes for the list table table tag.
964
- *
965
- * @since 3.1.0
966
- * @access protected
967
- *
968
- * @return array List of CSS classes for the table tag.
969
- */
970
- protected function get_table_classes() {
971
- return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
972
- }
973
-
974
- /**
975
- * Generate the table navigation above or below the table
976
- *
977
- * @since 3.1.0
978
- * @access protected
979
- * @param string $which
980
- */
981
- protected function display_tablenav( $which ) {
982
- if ( 'top' == $which )
983
- wp_nonce_field( 'bulk-' . $this->_args['plural'] );
984
- ?>
985
- <div class="tablenav <?php echo esc_attr( $which ); ?>">
986
-
987
- <div class="alignleft actions bulkactions">
988
- <?php $this->bulk_actions( $which ); ?>
989
- </div>
990
- <?php
991
- $this->extra_tablenav( $which );
992
- $this->pagination( $which );
993
- ?>
994
-
995
- <br class="clear" />
996
- </div>
997
- <?php
998
- }
999
-
1000
- /**
1001
- * Extra controls to be displayed between bulk actions and pagination
1002
- *
1003
- * @since 3.1.0
1004
- * @access protected
1005
- *
1006
- * @param string $which
1007
- */
1008
- protected function extra_tablenav( $which ) {}
1009
-
1010
- /**
1011
- * Generate the tbody element for the list table.
1012
- *
1013
- * @since 3.1.0
1014
- * @access public
1015
- */
1016
- public function display_rows_or_placeholder() {
1017
- if ( $this->has_items() ) {
1018
- $this->display_rows();
1019
- } else {
1020
- echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
1021
- $this->no_items();
1022
- echo '</td></tr>';
1023
- }
1024
- }
1025
-
1026
- /**
1027
- * Generate the table rows
1028
- *
1029
- * @since 3.1.0
1030
- * @access public
1031
- */
1032
- public function display_rows() {
1033
- foreach ( $this->items as $item )
1034
- $this->single_row( $item );
1035
- }
1036
-
1037
- /**
1038
- * Generates content for a single row of the table
1039
- *
1040
- * @since 3.1.0
1041
- * @access public
1042
- *
1043
- * @param object $item The current item
1044
- */
1045
- public function single_row( $item ) {
1046
- echo '<tr>';
1047
- $this->single_row_columns( $item );
1048
- echo '</tr>';
1049
- }
1050
-
1051
- protected function column_default( $item, $column_name ) {}
1052
-
1053
- protected function column_cb( $item ) {}
1054
-
1055
- /**
1056
- * Generates the columns for a single row of the table
1057
- *
1058
- * @since 3.1.0
1059
- * @access protected
1060
- *
1061
- * @param object $item The current item
1062
- */
1063
- protected function single_row_columns( $item ) {
1064
- list( $columns, $hidden ) = $this->get_column_info();
1065
-
1066
- foreach ( $columns as $column_name => $column_display_name ) {
1067
- $class = "class='$column_name column-$column_name'";
1068
-
1069
- $style = '';
1070
- if ( in_array( $column_name, $hidden ) )
1071
- $style = ' style="display:none;"';
1072
-
1073
- $attributes = "$class$style";
1074
-
1075
- if ( 'cb' == $column_name ) {
1076
- echo '<th scope="row" class="check-column">';
1077
- echo $this->column_cb( $item );
1078
- echo '</th>';
1079
- }
1080
- elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1081
- echo "<td $attributes>";
1082
- echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1083
- echo "</td>";
1084
- }
1085
- else {
1086
- echo "<td $attributes>";
1087
- echo $this->column_default( $item, $column_name );
1088
- echo "</td>";
1089
- }
1090
- }
1091
- }
1092
-
1093
- /**
1094
- * Handle an incoming ajax request (called from admin-ajax.php)
1095
- *
1096
- * @since 3.1.0
1097
- * @access public
1098
- */
1099
- public function ajax_response() {
1100
- $this->prepare_items();
1101
-
1102
- ob_start();
1103
- if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1104
- $this->display_rows();
1105
- } else {
1106
- $this->display_rows_or_placeholder();
1107
- }
1108
-
1109
- $rows = ob_get_clean();
1110
-
1111
- $response = array( 'rows' => $rows );
1112
-
1113
- if ( isset( $this->_pagination_args['total_items'] ) ) {
1114
- $response['total_items_i18n'] = sprintf(
1115
- _n( '1 item', '%s items', $this->_pagination_args['total_items'] ),
1116
- number_format_i18n( $this->_pagination_args['total_items'] )
1117
- );
1118
- }
1119
- if ( isset( $this->_pagination_args['total_pages'] ) ) {
1120
- $response['total_pages'] = $this->_pagination_args['total_pages'];
1121
- $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1122
- }
1123
-
1124
- die( wp_json_encode( $response ) );
1125
- }
1126
-
1127
- /**
1128
- * Send required variables to JavaScript land
1129
- *
1130
- * @access public
1131
- */
1132
- public function _js_vars() {
1133
- $args = array(
1134
- 'class' => get_class( $this ),
1135
- 'screen' => array(
1136
- 'id' => $this->screen->id,
1137
- 'base' => $this->screen->base,
1138
- )
1139
- );
1140
-
1141
- printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
1142
- }
1143
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/css/min/admin.css DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- * All of the CSS for your admin-specific functionality should be
3
- * included in this file.
4
- */
5
- /* Utils */
6
- .c4p-center {
7
- text-align: center;
8
- }
9
- .c4p-author-image {
10
- height: 10em;
11
- margin-top: 1em;
12
- margin-left: 1em;
13
- margin-right: 2em;
14
- /*margin: 2em 1.5em;*/
15
- }
16
- .c4p-full-card {
17
- max-width: none;
18
- }
19
- .c4p-left {
20
- float: left;
21
- }
22
- .c4p-right {
23
- float: right;
24
- }
25
- .c4p-clearfix:after {
26
- content: "";
27
- display: table;
28
- clear: both;
29
- }
30
- /* Notices */
31
- .updated, .error { margin: 15px 0 20px !important; }
32
- .i4t3-author-link { text-decoration: none; }
33
- .c4p-update-nag {
34
- padding: 0px 15px;
35
- width: 96%;
36
- margin: 15px 15px 0 2px;
37
- }
38
- /* Stats Section */
39
- /* .wp-list-table .column-id { width: 5%; } */
40
- .wp-list-table .column-date { width: 10%; }
41
- .wp-list-table .column-url { width: 25%; }
42
- .wp-list-table .column-ref { width: 20%; }
43
- .wp-list-table .column-ip { width: 15%;}
44
- .wp-list-table .column-ua { width: 15%;}
45
- .wp-list-table .column-ua { width: 15%;}
46
- .i4t3-url-p { color:#E53531 !important; }
47
- .i4t3-green { color: #006400 !important; }
48
- .i4t3-fixed-height{ height: 120px; margin-bottom: 20px; overflow: auto; padding: 0 20px 0 0; }
49
- .i4t3-notice { padding: 10px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/images/foxe.png DELETED
Binary file
admin/js/admin.js DELETED
@@ -1,75 +0,0 @@
1
- (function($) {
2
- 'use strict';
3
-
4
- /**
5
- * All of the code for our admin-specific JavaScript source
6
- * should reside in this file.
7
- *
8
- * Note that this assume you're going to use jQuery, so it prepares
9
- * the $ function reference to be used within the scope of this
10
- * function.
11
- *
12
- * From here, we are able to define handlers for when the DOM is
13
- * ready:
14
- *
15
- * $(function() {
16
- *
17
- * });
18
- *
19
- * Or when the window is loaded:
20
- *
21
- * $( window ).load(function() {
22
- *
23
- * });
24
- *
25
- * ...and so on.
26
- */
27
- $(function() {
28
- $('#i4t3_redirect_to').change(function() {
29
- var redirect_to = $(this).val();
30
- if(redirect_to == 'page') {
31
- $('#custom_page').show();
32
- $('#custom_url').hide();
33
- } else if(redirect_to == 'link') {
34
- $('#custom_url').show();
35
- $('#custom_page').hide();
36
- } else if(redirect_to == 'none') {
37
- $('#custom_page').hide();
38
- $('#custom_url').hide();
39
- }
40
- });
41
- // open custom redirect form modal
42
- $('.i4t3_redirect_thickbox').on('click', function() {
43
- var data = {
44
- 'action': 'i4t3_redirect_thickbox',
45
- 'url_404': $(this).attr('url_404')
46
- };
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
- tb_show(i4t3strings.redirect,"#TB_inline?width=700&height=300&inlineId=i4t3-redirect-modal");
51
- $('#i4t3_redirect_404').val(response.url_404);
52
- $('#i4t3_redirect_404_text').html(response.url_404);
53
- $('#i4t3_redirect_url').val(response.url);
54
- });
55
- });
56
- // save custom redirect value
57
- $('#i4t3_custom_redirect_submit').on('click', function() {
58
- $(this).addClass('disabled');
59
- $('.i4t3-spinner').css('visibility', 'visible');
60
- var data = {
61
- 'action': 'i4t3_redirect_form',
62
- 'url_404': $('#i4t3_redirect_404').val(),
63
- 'url': $('#i4t3_redirect_url').val(),
64
- 'nonce': $('#i4t3_custom_redirect_nonce').val()
65
- };
66
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
67
- $.post(ajaxurl, data, function(response) {
68
- // close the modal
69
- tb_remove();
70
- $('#i4t3_custom_redirect_submit').removeClass('disabled');
71
- $('.i4t3-spinner').css('visibility', 'hidden');
72
- });
73
- });
74
- })
75
- })(jQuery);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/partials/404-to-301-admin-agreement-tab.php DELETED
@@ -1,52 +0,0 @@
1
- <div class="notice i4t3-notice">
2
- <span>
3
- <div class="i4t3-fixed-height">
4
- <p>We would like to warn our users about other <em>not so legit</em> clones of 404 to 301 being sold out there. Keyword Swarm, for example, is a repackaged version of 404 to 301 plus all our premium add-ons(if any). We never authorized the author to resell our add-ons, and our license explicitly forbids it. 404 to 301 is free, and people should not pay for an unsupported fraudulent piece of software. In order to protect our intellectual property rights, we are asking you to review the following terms of use.</p>
5
- <p><strong>GNU General Public License v2</strong></p>
6
- <ol>
7
- <li>You may copy and distribute verbatim copies of 404 to 301's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of 404 to 301 a copy of this License along with 404 to 301. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.</li>
8
- <li>You may modify your copy or copies of 404 to 301 or any portion of it, thus forming a work based on 404 to 301, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
9
- <ol>
10
- <li>You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.</li>
11
- <li>You must cause any work that you distribute or publish, <strong>that in whole or in part contains or is derived from 404 to 301 or any part thereof, to be licensed as a whole at no charge</strong> to all third parties under the terms of this License.</li>
12
- <li>If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute 404 to 301 under these conditions, and telling the user how to view a copy of this License.</li>
13
- </ol>
14
- These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from 404 to 301, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on 404 to 301, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
15
- Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on 404 to 301.
16
- In addition, mere aggregation of another work not based on 404 to 301 with 404 to 301 (or with a work based on 404 to 301) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
17
- </li>
18
- <li>You may copy and distribute 404 to 301 (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
19
- <ol>
20
- <li>Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,</li>
21
- <li>Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,</li>
22
- <li>Accompany it with the information you received as to the offer to distribute corresponding source code.</li>
23
- </ol>
24
- The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
25
- If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.</li>
26
- <li>You may not copy, modify, sublicense, or distribute 404 to 301 except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute 404 to 301 is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.</li>
27
- <li>You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute 404 to 301 or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing 404 to 301 (or any work based on 404 to 301), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying 404 to 301 or works based on it.</li>
28
- <li>Each time you redistribute 404 to 301 (or any work based on 404 to 301), the recipient automatically receives a license from the original licensor to copy, distribute or modify 404 to 301 subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.</li>
29
- <li>If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, <strong>then as a consequence you may not distribute 404 to 301 at all</strong>. For example, if a patent license would not permit royalty-free redistribution of 404 to 301 by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of 404 to 301.
30
- If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
31
- It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
32
- This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.</li>
33
- <li>If the distribution and/or use of 404 to 301 is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places 404 to 301 under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.</li>
34
- <li>The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
35
- Each version is given a distinguishing version number.</li>
36
- <li>If you wish to incorporate parts of 404 to 301 into other free programs whose distribution conditions are different, <strong>write to the author to ask for permission</strong>. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.</li>
37
- <li><strong>NO WARRANTY</strong> - BECAUSE 404 to 301 IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR 404 to 301, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE 404 to 301 "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF 404 to 301 IS WITH YOU. SHOULD 404 to 301 PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.</li>
38
- <li>IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE 404 to 301 AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE 404 to 301 (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF 404 to 301 TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</li>
39
- </ol>
40
-
41
- <p><strong>Third Party Text Links</strong></p>
42
- <p>Third party text networks supply text for display in 404 to 301. These networks may collect your visitors' IP addresses, in native or hashed forms, for purposes of controlling the distribution of text links. 404 to 301 collects anonymous aggregated usage statistics.</p>
43
- <p>By clicking the button here below, you agree to the terms and conditions and give permission to place text links on your website when search engine crawlers access it. Your website's layout, performance and interaction with human visitors should not be altered or affected in any way. Please note that this feature can be deactivated at any time under <strong>404 to 301 Setting > Help & Info > Plugin Information > Disable UAN</strong>, without affecting any other feature available in 404 to 301.</p>
44
- <p>404 to 301 - Copyright &copy; 2016.</p>
45
- </div>
46
-
47
- <div>
48
- <a class="button-primary" href="<?php echo I4T3_SETTINGS_PAGE; ?>&i4t3_agreement=1" id="i4t3-accept-terms"><?php _e('I accept', '404-to-301'); ?></a>
49
- <a class="button-secondary" href="<?php echo I4T3_SETTINGS_PAGE; ?>&i4t3_agreement=0" id="i4t3-hide-admin-notice"><?php _e('I do not accept', '404-to-301'); ?></a>
50
- </div>
51
- </span>
52
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/partials/404-to-301-admin-credits-tab.php DELETED
@@ -1,103 +0,0 @@
1
- <div class="wrap">
2
- <br>
3
- <div id="poststuff">
4
- <div id="post-body" class="metabox-holder columns-2">
5
- <div id="post-body-content">
6
- <div class="postbox">
7
- <h3 class="hndle"><span><?php _e('About the plugin & developer', '404-to-301'); ?></span></h3>
8
- <div class="inside">
9
- <div class="c4p-clearfix">
10
- <div class="c4p-left">
11
- <img src="<?php echo I4T3_PATH . 'admin/images/foxe.png'; ?>" class="c4p-author-image" />
12
- </div>
13
- <div class="c4p-left" style="width: 70%">
14
- <?php $uname = ( $current_user->user_firstname == '' ) ? $current_user->user_login : $current_user->user_firstname; ?>
15
- <p><?php printf(__('Yo %s!', '404-to-301'), '<strong>' . $uname . '</strong>'); ?> <?php _e('Thank you for using 404 to 301', '404-to-301'); ?></p>
16
- <p>
17
- <?php _e('This plugin is brought to you by', '404-to-301'); ?> <a href="https://thefoxe.com/" class="i4t3-author-link" target="_blank" title="<?php _e('Visit author website', '404-to-301'); ?>"><strong>The Foxe</strong></a>, <?php _e('a web store developed and managed by Joel James.', '404-to-301'); ?>
18
- </p>
19
- <p>
20
- <hr/>
21
- </p>
22
- <p>
23
- <?php _e('So you installed this plugin and how is it doing? Feel free to', '404-to-301'); ?> <a href="https://thefoxe.com/contact/" class="i4t3-author-link" target="_blank" title="<?php _e('Contact the developer', '404-to-301'); ?>"><?php _e('get in touch with me', '404-to-301'); ?></a> <?php _e('anytime for help. I am always happy to help.', '404-to-301'); ?>
24
- </p>
25
- </div>
26
- </div>
27
- </div>
28
- </div>
29
- <div class="postbox">
30
- <h3 class="hndle"><span><?php _e('Debugging Data', '404-to-301'); ?></span></h3>
31
- <div class="inside">
32
- <div class="c4p-clearfix">
33
- <div class="c4p-left" style="width: 70%">
34
- <?php echo _404_To_301_Admin::i4t3_get_debug_data(); ?>
35
- </div>
36
- </div>
37
- </div>
38
- </div>
39
- </div>
40
- <div id="postbox-container-1" class="postbox-container">
41
-
42
- <div class="postbox">
43
- <h3 class="hndle ui-sortable-handle"><span class="dashicons dashicons-info"></span> <?php _e('Plugin Information', '404-to-301'); ?></h3>
44
- <div class="inside">
45
- <div class="misc-pub-section">
46
- <label><?php _e('Name', '404-to-301'); ?> : </label>
47
- <span><strong><?php _e('404 to 301', '404-to-301'); ?></strong></span>
48
- </div>
49
- <div class="misc-pub-section">
50
- <label><?php _e('Version', '404-to-301'); ?> : v<?php echo I4T3_VERSION; ?></label>
51
- <span></span>
52
- </div>
53
- <div class="misc-pub-section">
54
- <label><?php _e('Author', '404-to-301'); ?> : <a href="https://thefoxe.com/" class="i4t3-author-link" target="_blank" title="<?php _e('Visit author website', '404-to-301'); ?>">The Foxe</a></label>
55
- <span></span>
56
- </div>
57
- <div class="misc-pub-section">
58
- <label><a href="https://thefoxe.com/docs/docs/category/404-to-301/" class="i4t3-author-link" target="_blank" title="<?php _e('Visit plugin website', '404-to-301'); ?>"><strong><?php _e('Plugin documentation', '404-to-301'); ?></strong></a></label>
59
- <span></span>
60
- </div>
61
- <div class="misc-pub-section">
62
- <label><a href="https://thefoxe.com/products/404-to-301/" class="i4t3-author-link" target="_blank" title="<?php _e('Visit plugin website', '404-to-301'); ?>"><strong><?php _e('More details about the plugin', '404-to-301'); ?></strong></a></label>
63
- <span></span>
64
- </div>
65
- <div class="misc-pub-section">
66
- <label><?php _e('Need help?', '404-to-301'); ?></label>
67
- <span><strong><a href="https://thefoxe.com/contact/"><?php _e('Contact support', '404-to-301'); ?></a></strong></span>
68
- </div>
69
- </div>
70
- </div>
71
- <div class="postbox">
72
- <h3 class="hndle ui-sortable-handle"><span class="dashicons dashicons-admin-plugins"></span> <?php _e('Log Manager Addon', '404-to-301'); ?></h3>
73
- <div class="inside">
74
- <div class="misc-pub-section">
75
- <p><?php _e('Error Log Manager addon is available for 404 to 301 now. Make 404 error management more easy.', '404-to-301'); ?></p>
76
- <p><span class="dashicons dashicons-backup"></span> <?php _e('Instead of email alerts on every error, get Hourly, Daily, Twice a day, Weekly, Twice a week email alerts.', '404-to-301'); ?></p>
77
- <p><span class="dashicons dashicons-trash"></span> <?php _e('Automatically clear old error logs after few days to reduce db load.', '404-to-301'); ?></p>
78
- <p><a class="i4t3-author-link" href="https://thefoxe.com/products/404-to-301-log-manager/" target="_blank"><span class="dashicons dashicons-external"></span> <?php _e('See More Details', '404-to-301'); ?></a></p>
79
- </div>
80
- </div>
81
- </div>
82
- <div class="postbox">
83
- <h3 class="hndle ui-sortable-handle"><span class="dashicons dashicons-smiley"></span> <?php _e('Like the plugin', '404-to-301'); ?>?</h3>
84
- <div class="inside">
85
- <div class="misc-pub-section">
86
- <span class="dashicons dashicons-star-filled"></span> <label><strong><a href="https://wordpress.org/support/view/plugin-reviews/404-to-301?filter=5#postform" target="_blank" title="<?php _e('Rate now', '404-to-301'); ?>"><?php _e('Rate this on WordPress', '404-to-301'); ?></a></strong></label>
87
- </div>
88
- <div class="misc-pub-section">
89
- <label><span class="dashicons dashicons-heart"></span> <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4" target="_blank" title="<?php _e('Donate now', '404-to-301'); ?>"><?php _e('Make a small donation', '404-to-301'); ?></a></strong></label>
90
- </div>
91
- <div class="misc-pub-section">
92
- <label><span class="dashicons dashicons-admin-plugins"></span> <strong><a href="https://github.com/joel-james/404-to-301/" target="_blank" title="<?php _e('Contribute now', '404-to-301'); ?>"><?php _e('Contribute to the Plugin', '404-to-301'); ?></a></strong></label>
93
- </div>
94
- <div class="misc-pub-section">
95
- <label><span class="dashicons dashicons-twitter"></span> <strong><a href="https://twitter.com/home?status=I%20am%20using%20404%20to%20301%20plugin%20by%20%40Joel_James%20to%20handle%20all%20404%20errors%20in%20my%20%40WordPress%20site%20-%20it%20is%20awesome!%20%3E%20https://wordpress.org/plugins/404-to-301/" target="_blank" title="<?php _e('Tweet now', '404-to-301'); ?>"><?php _e('Tweet about the Plugin', '404-to-301'); ?></a></strong></label>
96
- </div>
97
- </div>
98
- </div>
99
-
100
- </div>
101
- </div>
102
- </div>
103
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/partials/404-to-301-admin-custom-redirect.php DELETED
@@ -1,37 +0,0 @@
1
- <div id="i4t3-redirect-modal" style="display:none;">
2
- <div id="i4t3-thickbox-content" class="wrap">
3
- <form id="i4t3_custom_redirect_form" action="javascript:void(0)">
4
- <table class="form-table">
5
- <tr>
6
- <th><?php _e('Redirecting from', '404-to-301'); ?> :</th>
7
- <td><strong><p id="i4t3_redirect_404_text">/404-not-found</p></strong></td>
8
- </tr>
9
- <tr>
10
- <th><?php _e('Redirect to', '404-to-301'); ?> :</th>
11
- <td>
12
- <input type="text" size="40" name="i4t3_custom_redirect" id="i4t3_redirect_url" value="">
13
- <p class="description"><?php _e('Enter the url if you want to set custom redirect for above 404 path. Enter the full url including http://. Leave empty if you want to follow deafult settings', '404-to-301'); ?>.</p>
14
- <input type="hidden" value="" id="i4t3_redirect_404">
15
- <input type="hidden" value="<?php echo wp_create_nonce( "i4t3_custom_redirect_nonce" ); ?>" id="i4t3_custom_redirect_nonce">
16
- </td>
17
- </tr>
18
- <tr>
19
- <td><span class="spinner i4t3-spinner"></span></td>
20
- <td>
21
- <?php
22
- submit_button(
23
- __('Save Redirect', '404-to-301'),
24
- 'primary',
25
- 'i4t3_custom_redirect_submit',
26
- false,
27
- array(
28
- 'id' => 'i4t3_custom_redirect_submit'
29
- )
30
- );
31
- ?>
32
- </td>
33
- </tr>
34
- </table>
35
- </form>
36
- </div>
37
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/partials/404-to-301-admin-display.php DELETED
@@ -1,58 +0,0 @@
1
- <?php
2
- if ( ! defined( 'WPINC' ) ) {
3
- die('Nice try dude. But I am sorry');
4
- }
5
- /**
6
- * Provide a dashboard view for the plugin
7
- *
8
- * This file is used to markup the dashboard pages of the plugin.
9
- *
10
- * @link https://thefoxe.com/products/404-to-301/
11
- * @since 2.0.0
12
- *
13
- * @package I4T3
14
- * @subpackage I4T3/admin/partials
15
- */
16
- ?>
17
-
18
- <!-- This should be primarily consist of HTML with a little bit of PHP in it. -->
19
- <?php $active_tab = ( !isset( $_GET['tab'] ) ) ? 'general' : $_GET['tab'];
20
-
21
- $general_class = '';
22
- $credits_class = '';
23
- ${$active_tab.'_class'} = 'nav-tab-active';
24
- ?>
25
-
26
- <div class="wrap">
27
- <h2>404 to 301 | <?php _e( 'Settings', '404-to-301' ); ?></h2><br>
28
- <?php if( isset($_GET['settings-updated']) ) { ?>
29
- <div class="updated">
30
- <p><strong>404 to 301 <?php _e( 'settings updated successfully', '404-to-301' ); ?></strong></p>
31
- </div>
32
- <?php } ?>
33
- <h2 class="nav-tab-wrapper">
34
- <a href="?page=i4t3-settings&tab=general" class="nav-tab <?php echo $general_class; ?>"><?php _e( 'General', '404-to-301' ); ?></a>
35
- <a href="?page=i4t3-settings&tab=credits" class="nav-tab <?php echo $credits_class ?>"><?php _e( 'Help & Info', '404-to-301' ); ?></a>
36
- </h2>
37
- </div>
38
-
39
- <?php
40
-
41
- switch ( $active_tab ) {
42
-
43
- case 'general':
44
- // Get list of active pages
45
- $args = array(
46
- 'post_type' => 'page',
47
- 'post_status' => 'publish'
48
- );
49
- $pages = get_pages( $args );
50
- include_once('404-to-301-admin-general-tab.php');
51
- break;
52
- case 'credits':
53
- $current_user = wp_get_current_user();
54
- include_once('404-to-301-admin-credits-tab.php');
55
- break;
56
- default:
57
- include_once('404-to-301-admin-general-tab.php');
58
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/partials/404-to-301-admin-general-tab.php DELETED
@@ -1,110 +0,0 @@
1
- <div class="wrap">
2
- <form method="post" action="options.php">
3
- <p>
4
- <?php settings_fields('i4t3_gnrl_options'); ?>
5
- <?php $options = get_option('i4t3_gnrl_options'); ?>
6
- <?php
7
- // To show/hide options
8
- $cp_style = 'style="display: none;"';
9
- $cl_style = 'style="display: none;"';
10
- switch ($options['redirect_to']) {
11
- case 'page':
12
- $cp_style = '';
13
- break;
14
-
15
- case 'link':
16
- $cl_style = '';
17
- break;
18
-
19
- default:
20
- break;
21
- }
22
- ?>
23
- <table class="form-table">
24
- <tbody>
25
-
26
- <tr>
27
- <th><?php _e('Redirect type', '404-to-301'); ?></th>
28
- <td>
29
- <select name='i4t3_gnrl_options[redirect_type]'>
30
- <option value='301' <?php selected($options['redirect_type'], '301'); ?>>301 <?php _e('Redirect (SEO)', '404-to-301'); ?></option>
31
- <option value='302' <?php selected($options['redirect_type'], '302'); ?>>302 <?php _e('Redirect', '404-to-301'); ?></option>
32
- <option value='307' <?php selected($options['redirect_type'], '307'); ?>>307 <?php _e('Redirect', '404-to-301'); ?></option>
33
- </select>
34
- <p class="description"><a target="_blank" href="https://moz.com/learn/seo/redirection"><strong><?php _e('Learn more', '404-to-301'); ?></strong></a> <?php _e('about these redirect types', '404-to-301'); ?></p>
35
- </td>
36
- </tr>
37
- <tr>
38
- <th><?php _e('Redirect to', '404-to-301'); ?></th>
39
- <td>
40
- <select name='i4t3_gnrl_options[redirect_to]' id='i4t3_redirect_to'>
41
- <option value='page' <?php selected($options['redirect_to'], 'page'); ?>><?php _e('Existing Page', '404-to-301'); ?></option>
42
- <option value='link' <?php selected($options['redirect_to'], 'link'); ?>><?php _e('Custom URL', '404-to-301'); ?></option>
43
- <option value='none' <?php selected($options['redirect_to'], 'none'); ?>><?php _e('No Redirect', '404-to-301'); ?></option>
44
- </select>
45
- <p class="description"><strong><?php _e('Existing Page', '404-to-301'); ?>:</strong> <?php _e('Select any WordPress page as a 404 page', '404-to-301'); ?>.</p>
46
- <p class="description"><strong><?php _e('Custom URL', '404-to-301'); ?>:</strong> <?php _e('Redirect 404 requests to a specific URL', '404-to-301'); ?>.</p>
47
- <p class="description"><strong><?php _e('No Redirect', '404-to-301'); ?>:</strong> <?php _e('To disable redirect', '404-to-301'); ?>.</p>
48
- <p class="description i4t3-green"><strong><?php _e('You can override this by setting individual custom redirects from error logs list.', '404-to-301'); ?></strong></p>
49
- </td>
50
- </tr>
51
- <tr id="custom_page" <?php echo $cp_style; ?>>
52
- <th><?php _e('Select the page', '404-to-301'); ?></th>
53
- <td>
54
- <select name='i4t3_gnrl_options[redirect_page]'>
55
- <?php foreach ($pages as $page) { ?>
56
- <option value='<?php echo $page->ID; ?>' <?php selected($options['redirect_page'], $page->ID); ?>><?php echo $page->post_title; ?></option>
57
- <?php } ?>
58
- </select>
59
- <p class="description"><?php _e('The default 404 page will be replaced by the page you choose in this list', '404-to-301'); ?>.</p>
60
- </td>
61
- </tr>
62
- <tr id="custom_url"<?php echo $cl_style; ?>>
63
- <th><?php _e('Custom URL', '404-to-301'); ?></th>
64
- <td>
65
- <input type="text" placeholder="<?php echo home_url(); ?>" name="i4t3_gnrl_options[redirect_link]" value="<?php echo $options['redirect_link']; ?>">
66
- <p class="description"><?php _e('Enter any url', '404-to-301'); ?> (<?php _e('including', '404-to-301'); ?> http://)</p>
67
- </td>
68
- </tr>
69
- <tr>
70
- <th><?php _e('Log 404 Errors', '404-to-301'); ?></th>
71
- <td>
72
- <select name='i4t3_gnrl_options[redirect_log]'>
73
- <option value='1' <?php selected($options['redirect_log'], 1); ?>><?php _e('Enable Error Logs', '404-to-301'); ?></option>
74
- <option value='0' <?php selected($options['redirect_log'], 0); ?>><?php _e('Disable Error Logs', '404-to-301'); ?></option>
75
- </select>
76
- <p class="description"><?php _e('Enable/Disable Logging', '404-to-301'); ?></p>
77
- </td>
78
- </tr>
79
- <tr>
80
- <th><?php _e('Email notifications', '404-to-301'); ?></th>
81
- <td>
82
- <?php $email_notify = 0;
83
- if (isset($options['email_notify'])) {
84
- $email_notify = $options['email_notify'];
85
- } ?>
86
- <input type="checkbox" name="i4t3_gnrl_options[email_notify]" value="1" <?php checked($email_notify, 1); ?> />
87
- <p class="description"><?php _e('If you check this, an email will be sent on every 404 log on the admin email account', '404-to-301'); ?>.</p>
88
- </td>
89
- </tr>
90
- <tr>
91
- <th><?php _e('Email address', '404-to-301'); ?></th>
92
- <td>
93
- <?php $notify_address = ( isset($options['email_notify_address']) ) ? $options['email_notify_address'] : get_option('admin_email'); ?>
94
- <input type="text" placeholder="<?php echo get_option('admin_email'); ?>" name="i4t3_gnrl_options[email_notify_address]" value="<?php echo $notify_address; ?>">
95
- <p class="description"><?php _e('Change the recipient email address for error log notifications', '404-to-301'); ?>.</p>
96
- </td>
97
- </tr>
98
- <tr>
99
- <th><?php _e('Exclude paths', '404-to-301'); ?></th>
100
- <td>
101
- <textarea rows="5" cols="50" placeholder="wp-content/plugins/abc-plugin/css/" name="i4t3_gnrl_options[exclude_paths]"><?php echo $options['exclude_paths']; ?></textarea>
102
- <p class="description"><?php _e('If you want to exclude few paths from error logs, enter here. One per line.', '404-to-301'); ?></p>
103
- </td>
104
- </tr>
105
- </tbody>
106
- </table>
107
- <?php submit_button(__('Save All Changes', '404-to-301')); ?>
108
- </p>
109
- </form>
110
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
composer.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name" : "joel-james/404-to-301",
3
+ "version" : "3.0.0",
4
+ "description": "Automatically redirect all <strong>404 errors</strong> to any page using <strong>301 redirect for SEO</strong>. You can <strong>redirect and log</strong> every 404 errors. No more 404 errors in Webmaster tool.",
5
+ "homepage" : "https://dclwp.com/",
6
+ "license" : "GPL-2.0+",
7
+ "type" : "wordpress-plugin",
8
+ "require" : {
9
+ "composer/installers": "~1.0"
10
+ }
11
+ }
includes/admin/class-jj4t3-admin.php ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * The dashboard-specific functionality of the plugin.
8
+ *
9
+ * Register all hooks related to admin area of the website.
10
+ *
11
+ * @category Core
12
+ * @package JJ4T3
13
+ * @subpackage Admin
14
+ * @author Joel James <mail@cjoel.com>
15
+ * @license http://www.gnu.org/licenses/ GNU General Public License
16
+ * @link https://duckdev.com/products/404-to-301/
17
+ */
18
+ class JJ4T3_Admin {
19
+
20
+ /**
21
+ * Error listing table.
22
+ *
23
+ * @var object
24
+ */
25
+ public $list_table;
26
+
27
+ /**
28
+ * Initialize the class.
29
+ *
30
+ * Register all hooks in this class.
31
+ * All admin facing functionality.
32
+ *
33
+ * @since 3.0.0
34
+ * @access public
35
+ */
36
+ public function __construct() {
37
+
38
+ add_filter( 'admin_init', array( $this, 'add_buffer' ) );
39
+ add_action( 'admin_enqueue_scripts', array( $this, 'styles' ) );
40
+ add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
41
+ add_action( 'admin_menu', array( $this, 'admin_menu' ) );
42
+ add_action( 'admin_menu', array( $this, 'rename_menu' ) );
43
+ add_action( 'admin_init', array( $this, 'register_settings' ) );
44
+ add_filter( 'set-screen-option', array( 'JJ4T3_Log_Listing', 'set_screen' ), 10, 3 );
45
+ add_action( 'admin_footer', array( $this, 'add_thickbox' ), 100 );
46
+ add_action( 'wp_ajax_jj4t3_redirect_thickbox', array( 'JJ4T3_Log_Listing', 'open_redirect' ), 100 );
47
+ add_action( 'wp_ajax_jj4t3_redirect_form', array( 'JJ4T3_Log_Listing', 'save_redirect' ) );
48
+ add_action( 'admin_footer', array( 'JJ4T3_Log_Listing', 'get_redirect_content' ), 100 );
49
+ add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 5 );
50
+ add_action( 'plugins_loaded', array( $this, 'upgrade' ) );
51
+ }
52
+
53
+ /**
54
+ * Output buffer function.
55
+ *
56
+ * To avoid header already sent issues.
57
+ *
58
+ * @link https://tommcfarlin.com/wp_redirect-headers-already-sent/
59
+ * @since 2.1.4
60
+ * @access public
61
+ *
62
+ * @uses ob_start() To load buffer.
63
+ *
64
+ * @return void
65
+ */
66
+ public function add_buffer() {
67
+
68
+ ob_start();
69
+ }
70
+
71
+ /**
72
+ * Register the stylesheet for the Dashboard.
73
+ *
74
+ * This function is used to register all the required stylesheets for
75
+ * dashboard.
76
+ * Styles will be registered only for our plugin pages for performance.
77
+ *
78
+ * @since 2.0.0
79
+ * @access public
80
+ * @global string $pagenow Current page.
81
+ * @uses wp_enqueue_style To register styles.
82
+ *
83
+ * @return void
84
+ */
85
+ public function styles() {
86
+
87
+ global $pagenow;
88
+
89
+ // Use minified assets if SCRIPT_DEBUG is turned off.
90
+ $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
91
+
92
+ if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'jj4t3-settings', 'jj4t3-logs' ) ) ) {
93
+
94
+ wp_enqueue_style( JJ4T3_NAME, JJ4T3_URL . 'includes/admin/css/admin' . $suffix . '.css', array(), JJ4T3_VERSION, 'all' );
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Register the scripts for the Dashboard.
100
+ *
101
+ * This function is used to register all the required scripts for
102
+ * dashboard.
103
+ * Scripts will be registered only for our plugin pages for performance.
104
+ *
105
+ * @since 2.0.0
106
+ * @access public
107
+ *
108
+ * @uses wp_enqueue_script To register script.
109
+ * @uses wp_localize_script To translate strings in js.
110
+ *
111
+ * @global string $pagenow Current page.
112
+ *
113
+ * @return void
114
+ */
115
+ public function scripts() {
116
+
117
+ global $pagenow;
118
+
119
+ // Use minified scripts if SCRIPT_DEBUG is turned off.
120
+ $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
121
+
122
+ if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'jj4t3-settings', 'jj4t3-logs' ) ) ) {
123
+
124
+ wp_enqueue_script( JJ4T3_NAME, JJ4T3_URL . 'includes/admin/js/admin' . $suffix . '.js', array( 'jquery' ), JJ4T3_VERSION, false );
125
+
126
+ // Strings to translate in js.
127
+ $strings = array( 'redirect' => esc_html__( 'Custom Redirect', JJ4T3_DOMAIN ) );
128
+
129
+ wp_localize_script( JJ4T3_NAME, 'jj4t3strings', $strings );
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Creating admin menus for 404 to 301.
135
+ *
136
+ * Creates one main menu and few sub menu items.
137
+ * Menu menu will be linked to 404 error logs by default.
138
+ * Set menu access permissions using JJ4T3_ACCESS constant.
139
+ * Regitsering action hook - "jj4t3_admin_page".
140
+ *
141
+ * @since 2.0.0
142
+ * @access public
143
+ *
144
+ * @uses add_submenu_page() Action hook to add new admin menu sub page.
145
+ *
146
+ * @return void
147
+ */
148
+ public function admin_menu() {
149
+
150
+ // Main menu for error logs list.
151
+ $hook = add_menu_page( __( '404 Error Logs', JJ4T3_DOMAIN ), __( '404 Errors', JJ4T3_DOMAIN ), JJ4T3_ACCESS, 'jj4t3-logs', array( $this, 'error_list' ), 'dashicons-redo', 90 );
152
+
153
+ // Render screen options on listing table.
154
+ add_action( "load-$hook", array( $this, 'screen_option' ) );
155
+
156
+ // 404 to 301 settings menu.
157
+ add_submenu_page( 'jj4t3-logs', __( '404 to 301 Settings', JJ4T3_DOMAIN ), __( '404 Settings', JJ4T3_DOMAIN ), JJ4T3_ACCESS, 'jj4t3-settings', array( $this, 'admin_page' ) );
158
+
159
+ /**
160
+ * Action hook to register new submenu item.
161
+ *
162
+ * You can user this action hook to register any custom
163
+ * submenu items to 404 to 301 menu.
164
+ * This can be used by add-ons of our plugins.
165
+ *
166
+ * @since 2.0.0
167
+ */
168
+ do_action( 'i4t3_admin_page' );
169
+ }
170
+
171
+ /**
172
+ * To make screen options for error listing.
173
+ *
174
+ * This function is used to show screen options like entries per page,
175
+ * show/hide columns etc.
176
+ * This feature is extended from WP_List_Table class.
177
+ *
178
+ * @since 2.1.0
179
+ * @access public
180
+ *
181
+ * @return void
182
+ */
183
+ public function screen_option() {
184
+
185
+ $args = array(
186
+ 'label' => __( 'Error Logs', JJ4T3_DOMAIN ),
187
+ 'default' => 20,
188
+ 'option' => 'logs_per_page'
189
+ );
190
+
191
+ add_screen_option( 'per_page', $args );
192
+
193
+ // Error log listing table.
194
+ $this->list_table = new JJ4T3_Log_Listing();
195
+ }
196
+
197
+ /**
198
+ * Show error listing table view.
199
+ *
200
+ * This method displays the listing table HTML to the page.
201
+ * Regitsering action hook - "jj4t3_log_list_above_form".
202
+ * Regitsering action hook - "jj4t3_log_list_below_form".
203
+ *
204
+ * @since 2.1.0
205
+ * @access public
206
+ *
207
+ * @return void
208
+ */
209
+ public function error_list() {
210
+ ?>
211
+ <div class="wrap">
212
+ <h2><?php _e( '404 Error Logs', JJ4T3_DOMAIN ); ?></h2>
213
+ <div id="poststuff">
214
+ <div id="post-body" class="metabox-holder">
215
+ <div id="post-body-content">
216
+ <div class="meta-box-sortables ui-sortable">
217
+ <?php $this->list_table->prepare_items();
218
+ /**
219
+ * Action hook to add something above listing page.
220
+ *
221
+ * Use this action hook to add custom filters and search
222
+ * boxes to the listing table top section.
223
+ *
224
+ * @param object $this Listing page class object.
225
+ *
226
+ * @since 3.0.0
227
+ */
228
+ do_action( 'jj4t3_log_list_above_form', $this->list_table );
229
+ ?>
230
+ <form method="get">
231
+ <input type="hidden" name="page" value="jj4t3-logs"/>
232
+ <?php $this->list_table->display(); ?>
233
+ </form>
234
+ <?php
235
+ /**
236
+ * Action hook to add something below the listing page.
237
+ *
238
+ * Use this action hook to add custom filters and search
239
+ * boxes to the listing table bottom section.
240
+ *
241
+ * @param object $this Listing page class object.
242
+ *
243
+ * @since 3.0.0
244
+ */
245
+ do_action( 'jj4t3_log_list_below_form', $this->list_table );
246
+ ?>
247
+ </div>
248
+ </div>
249
+ </div>
250
+ <br class="clear">
251
+ </div>
252
+ </div>
253
+ <?php
254
+ }
255
+
256
+ /**
257
+ * Rename admin menu text to : 404 to 301.
258
+ *
259
+ * @since 2.0.0
260
+ * @access public
261
+ *
262
+ * @global array $menu Menus registered in this site.
263
+ *
264
+ * @return void
265
+ */
266
+ public function rename_menu() {
267
+
268
+ global $menu;
269
+
270
+ $menu[90][0] = __( '404 to 301', JJ4T3_DOMAIN );
271
+ }
272
+
273
+ /**
274
+ * Registering i4t3 options.
275
+ * This function is used to register all settings options to the db using
276
+ * WordPress settings API.
277
+ * If we want to register another setting, we can include that here.
278
+ *
279
+ * @since 2.0.0
280
+ * @access public
281
+ * @uses hooks register_setting Hook to register i4t3 options in db.
282
+ *
283
+ * @return void
284
+ */
285
+ public function register_settings() {
286
+
287
+ register_setting( 'i4t3_gnrl_options', 'i4t3_gnrl_options' );
288
+ }
289
+
290
+ /**
291
+ * Admin options page display.
292
+ *
293
+ * Admin page template to manage plugin settings and
294
+ * other options.
295
+ * All template related things can be managed from this
296
+ * file.
297
+ *
298
+ * @since 2.0.0
299
+ * @access public
300
+ *
301
+ * @return void
302
+ */
303
+ public function admin_page() {
304
+
305
+ include_once JJ4T3_DIR . 'includes/admin/views/admin.php';
306
+ }
307
+
308
+ /**
309
+ * This function includes required scripts for thickbox.
310
+ *
311
+ * This function registers scripts required for WordPress thickbox modal.
312
+ *
313
+ * @since 2.1.1
314
+ * @access public
315
+ *
316
+ * @return mixed
317
+ */
318
+ public function add_thickbox() {
319
+
320
+ return add_thickbox();
321
+ }
322
+
323
+ /**
324
+ * Action links for plugins listing page.
325
+ *
326
+ * Add quick links to plugin settings page, error listing page
327
+ * from the plugins listing page.
328
+ *
329
+ * @param array $links Links array.
330
+ * @param array $file File name.
331
+ *
332
+ * @return array
333
+ */
334
+ public function action_links( $links, $file ) {
335
+
336
+ $plugin_file = basename( '404-to-301.php' );
337
+
338
+ if ( basename( $file ) === $plugin_file ) {
339
+ $settings_link = '<a href="admin.php?page=jj4t3-settings">' . __( 'Settings', JJ4T3_DOMAIN ) . '</a>';
340
+ $settings_link .= ' | <a href="admin.php?page=jj4t3-logs">' . __( 'Logs', JJ4T3_DOMAIN ) . '</a>';
341
+
342
+ // Add quick links to plugins listing page.
343
+ array_unshift( $links, $settings_link );
344
+ }
345
+
346
+ return $links;
347
+ }
348
+
349
+ /**
350
+ * Upgrade plugin on updates.
351
+ *
352
+ * If there are structural changes to make after new version release,
353
+ * make required changes.
354
+ *
355
+ * @since 3.0.0
356
+ * @access public
357
+ *
358
+ * @return void
359
+ */
360
+ public function upgrade() {
361
+
362
+ $current_version = get_option( 'i4t3_version_no', false );
363
+
364
+ if ( ! $current_version || ( $current_version < JJ4T3_VERSION ) ) {
365
+ if ( ! class_exists( 'JJ4T3_Activator_Deactivator_Uninstaller' ) ) {
366
+ include_once JJ4T3_DIR . 'includes/class-jj4t3-activator-deactivator-uninstaller.php';
367
+ }
368
+
369
+ // Run upgrade actions.
370
+ JJ4T3_Activator_Deactivator_Uninstaller::activate();
371
+
372
+ // Update the plugin version number.
373
+ update_option( 'i4t3_version_no', JJ4T3_VERSION );
374
+ }
375
+ }
376
+ }
includes/admin/class-jj4t3-log-listing.php ADDED
@@ -0,0 +1,1002 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+
7
+ // List table class from WordPress core.
8
+ if ( ! class_exists( 'WP_List_Table' ) ) {
9
+ include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10
+ }
11
+
12
+ /**
13
+ * The listing page class for error logs.
14
+ *
15
+ * This class defines all the methods to output the error logs display table using
16
+ * WordPress listing table class.
17
+ *
18
+ * @category Core
19
+ * @package JJ4T3
20
+ * @subpackage ErrorLogListing
21
+ * @author Joel James <mail@cjoel.com>
22
+ * @license http://www.gnu.org/licenses/ GNU General Public License
23
+ * @link https://duckdev.com/products/404-to-301/
24
+ */
25
+ class JJ4T3_Log_Listing extends WP_List_Table {
26
+
27
+ /**
28
+ * Group by column name.
29
+ *
30
+ * @since 3.0.0
31
+ * @access private
32
+ * @var string
33
+ */
34
+ private $group_by = '';
35
+
36
+ /**
37
+ * Initialize the class and set properties.
38
+ *
39
+ * @since 3.0.0
40
+ * @access public
41
+ */
42
+ public function __construct() {
43
+
44
+ parent::__construct(
45
+ array(
46
+ 'singular' => __( '404 Error Log', JJ4T3_DOMAIN ),
47
+ 'plural' => __( '404 Error Logs', JJ4T3_DOMAIN ),
48
+ 'ajax' => false,
49
+ )
50
+ );
51
+ }
52
+
53
+ /**
54
+ * Prepare listing table using WP_List_Table class.
55
+ *
56
+ * As name says, this function is used to prepare the lsting table based
57
+ * on the custom rules and filters that we have given.
58
+ * This function extends the lsiting table class and uses our custom data
59
+ * to list in the table.
60
+ * Here we set pagination, columns, sorting etc.
61
+ * $this->items - Push our custom log data to the listing table.
62
+ * Registering filter - "jj4t3_logs_list_per_page".
63
+ *
64
+ * @global object $wpdb WP DB object
65
+ * @since 2.0.0
66
+ * @access public
67
+ */
68
+ public function prepare_items() {
69
+
70
+ $this->_column_headers = $this->get_column_info();
71
+
72
+ // Execute bulk actions.
73
+ $actions = $this->process_actions();
74
+
75
+ // Redirect after actions, or after securoty check.
76
+ $this->safe_redirect( $actions );
77
+
78
+ // Set group by column.
79
+ $this->set_groupby();
80
+
81
+ /**
82
+ * Filter to alter no. of items per page.
83
+ *
84
+ * Change no. of items listed on a page. This value can be changed from
85
+ * error listing page screen options.
86
+ *
87
+ * @since 2.0.0
88
+ */
89
+ $per_page = apply_filters( 'jj4t3_logs_list_per_page', $this->get_items_per_page( 'logs_per_page', 20 ) );
90
+
91
+ // Current page number.
92
+ $page_number = $this->get_pagenum();
93
+
94
+ // Total error logs.
95
+ $total_items = $this->total_logs();
96
+
97
+ // Set pagination.
98
+ $this->set_pagination_args(
99
+ array(
100
+ 'total_items' => $total_items,
101
+ 'per_page' => $per_page,
102
+ )
103
+ );
104
+
105
+ // Set error logs data for the current page.
106
+ $this->items = $this->get_error_logs( $per_page, $page_number );
107
+ }
108
+
109
+ /**
110
+ * Get error logs data.
111
+ *
112
+ * Get error logs data from our custom database table.
113
+ * Apply all filtering, sorting and paginations.
114
+ * Registering filter - "jj4t3_logs_list_result".
115
+ *
116
+ * @param int $per_page Logs per page.
117
+ * @param int $page_number Current page number.
118
+ *
119
+ * @global object $wpdb WP DB object
120
+ * @since 3.0.0
121
+ * @access public
122
+ *
123
+ * @return array
124
+ */
125
+ private function get_error_logs( $per_page = 20, $page_number = 1 ) {
126
+
127
+ global $wpdb;
128
+
129
+ // Current offset.
130
+ $offset = ( $page_number - 1 ) * $per_page;
131
+
132
+ // Sort by column.
133
+ $orderby = $this->get_order_by();
134
+
135
+ // Set group b query, if set.
136
+ $groupby_query = empty( $this->group_by ) ? '' : ' GROUP BY ' . $this->group_by;
137
+ // Get count of grouped items.
138
+ $count = empty( $this->group_by ) ? '' : ', COUNT(id) as count ';
139
+
140
+ // Sort order.
141
+ $order = $this->get_order();
142
+
143
+ // Get error logs.
144
+ $result = $wpdb->get_results( $wpdb->prepare( "SELECT *" . $count . " FROM " . JJ4T3_TABLE . " WHERE status != 0 " . $groupby_query . " ORDER BY %s %s LIMIT %d OFFSET %d", array( $orderby, $order, $per_page, $offset ) ), 'ARRAY_A' );
145
+
146
+ /**
147
+ * Filter to alter the error logs listing data result.
148
+ *
149
+ * BE CAREFUL when you use this filter. If you alter the structure
150
+ * the entire listing table may get affected.
151
+ *
152
+ * @since 2.0.0
153
+ */
154
+ return apply_filters( 'jj4t3_logs_list_result', $result );
155
+ }
156
+
157
+ /**
158
+ * Get sort by column name.
159
+ *
160
+ * This is used to filter the sorting parameters in order
161
+ * to prevent SQL injection atacks. We will accept only our
162
+ * required values. Else we will assign a default value.
163
+ * Registering filter - "jj4t3_log_list_orderby".
164
+ *
165
+ * @since 2.0.3
166
+ * @access public
167
+ * @uses esc_sql() To escape string for SQL.
168
+ *
169
+ * @return string Filtered column name.
170
+ */
171
+ private function get_order_by() {
172
+
173
+ /**
174
+ * Filter to alter the log listing orderby param.
175
+ *
176
+ * Only accepted, valid column name will be accepted.
177
+ *
178
+ * @since 2.0.0
179
+ */
180
+ $orderby = apply_filters( 'jj4t3_log_list_orderby', jj4t3_from_request( 'orderby', 'date' ) );
181
+
182
+ /**
183
+ * Filter to alter the allowed order by values.
184
+ *
185
+ * Only these columns will be allowed. It is a security
186
+ * measure too.
187
+ *
188
+ * @param array array of allowed column names.
189
+ *
190
+ * @since 2.0.0
191
+ */
192
+ $allowed_columns = apply_filters( 'jj4t3_log_list_orderby_allowed', array( 'date', 'url', 'ref', 'ip' ) );
193
+
194
+ // Make sure only valid columns are considered.
195
+ $allowed_columns = array_intersect( $allowed_columns, array_keys( jj4t3_log_columns() ) );
196
+
197
+ // Check if given column is allowed.
198
+ if ( in_array( $orderby, $allowed_columns ) ) {
199
+ return esc_sql( $orderby );
200
+ }
201
+
202
+ return 'date';
203
+ }
204
+
205
+ /**
206
+ * Filter the sorting parameters.
207
+ *
208
+ * This is used to filter the sorting parameters in order
209
+ * to prevent SQL injection atacks. We will accept only our
210
+ * required values. Else we will assign a default value.
211
+ * Registering filter - "jj4t3_log_list_order".
212
+ *
213
+ * @since 2.0.3
214
+ * @access private
215
+ *
216
+ * @return string Filtered column name.
217
+ */
218
+ private function get_order() {
219
+
220
+ // Get order column name from request.
221
+ $order = jj4t3_from_request( 'order', 'DESC' ) == 'asc' ? 'ASC' : 'DESC';
222
+
223
+ /**
224
+ * Filter to alter the log listing order param.
225
+ *
226
+ * Only ASC and DESC will be accepted.
227
+ *
228
+ * @since 2.0.0
229
+ */
230
+ return apply_filters( 'jj4t3_log_list_order', $order );
231
+ }
232
+
233
+ /**
234
+ * Set gropuby value for grouping results.
235
+ *
236
+ * Groupby filter to avoid duplicate values in error log
237
+ * listing table. If a groupby column is set, it will show
238
+ * the count along with the logs.
239
+ * Registering filter - "jj4t3_log_list_groupby_allowed".
240
+ * Registering filter - "jj4t3_log_list_groupby".
241
+ *
242
+ * @since 3.0.0
243
+ * @access private
244
+ */
245
+ private function set_groupby() {
246
+
247
+ /**
248
+ * Filter to alter the allowed group by values.
249
+ *
250
+ * Only these columns will be allowed. It is a security
251
+ * measure too.
252
+ *
253
+ * @param array array of allowed column names.
254
+ *
255
+ * @since 2.0.0
256
+ */
257
+ $allowed_values = apply_filters( 'jj4t3_log_list_groupby_allowed', array( 'url', 'ref', 'ip', 'ua' ) );
258
+
259
+ // Make sure only valid columns are considered.
260
+ $allowed_values = array_intersect( $allowed_values, array_keys( jj4t3_log_columns() ) );
261
+
262
+ // Get group by value from request.
263
+ $group_by = jj4t3_from_request( 'group_by_top', '' );
264
+
265
+ // Verify if the group by value is allowed.
266
+ if ( ! in_array( $group_by, $allowed_values ) ) {
267
+ return;
268
+ }
269
+
270
+ /**
271
+ * Filter to alter the log listing groupby param.
272
+ *
273
+ * Only allowed column names are accepted.
274
+ *
275
+ * @since 2.0.0
276
+ */
277
+ $this->group_by = apply_filters( 'jj4t3_log_list_groupby', $group_by );
278
+ }
279
+
280
+ /**
281
+ * Get the count of total logs in table.
282
+ *
283
+ * Since we are using a custom table for data in
284
+ * listing, we need to get count of total items for proper pagination.
285
+ * Registering filter - "jj4t3_log_list_count".
286
+ *
287
+ * @global object $wpdb WP DB object
288
+ * @since 2.0.3
289
+ * @access private
290
+ *
291
+ * @return int Total count.
292
+ */
293
+ private function total_logs() {
294
+
295
+ global $wpdb;
296
+
297
+ if ( empty( $this->group_by ) ) {
298
+ $total = $wpdb->get_var( "SELECT COUNT(id) FROM " . JJ4T3_TABLE );
299
+ } else {
300
+ $total = $total = $wpdb->get_var( "SELECT COUNT(DISTINCT " . $this->group_by . ") FROM " . JJ4T3_TABLE );
301
+ }
302
+
303
+ /**
304
+ * Filter to alter total logs count.
305
+ *
306
+ * You MAY NOT have to use this filter.
307
+ *
308
+ * @since 2.0.0
309
+ */
310
+ return apply_filters( 'jj4t3_log_list_count', $total );
311
+ }
312
+
313
+ /**
314
+ * Listing table column titles.
315
+ *
316
+ * Custom column titles to be displayed in listing table.
317
+ * Registering filter - "jj4t3_log_list_column_names".
318
+ *
319
+ * @since 2.0.0
320
+ * @access public
321
+ *
322
+ * @return array $columns Array of cloumn titles.
323
+ */
324
+ public function get_columns() {
325
+
326
+ $columns = array(
327
+ 'cb' => '<input type="checkbox" style="width: 5%;" />',
328
+ 'date' => __( 'Date', JJ4T3_DOMAIN ),
329
+ 'url' => __( '404 Path', JJ4T3_DOMAIN ),
330
+ 'ref' => __( 'From', JJ4T3_DOMAIN ),
331
+ 'ip' => __( 'IP Address', JJ4T3_DOMAIN ),
332
+ 'ua' => __( 'User Agent', JJ4T3_DOMAIN ),
333
+ 'redirect' => __( 'Customization', JJ4T3_DOMAIN )
334
+ );
335
+
336
+ /**
337
+ * Filter hook to change column titles.
338
+ *
339
+ * If you are adding custom columns, remember to add
340
+ * those to "jj4t3_log_list_column_default" filter too.
341
+ *
342
+ * @since 3.0.0
343
+ */
344
+ return apply_filters( 'jj4t3_log_list_column_names', $columns );
345
+ }
346
+
347
+ /**
348
+ * Make columns sortable.
349
+ *
350
+ * To make our custom columns in list table sortable.
351
+ * Do not enable sorting for redirect and ua columns.
352
+ * Registering filter - "jj4t3_log_list_sortable_columns".
353
+ *
354
+ * @since 2.0.0
355
+ * @access protected
356
+ *
357
+ * @return array Array of columns to enable sorting.
358
+ */
359
+ protected function get_sortable_columns() {
360
+
361
+ $columns = array(
362
+ 'date' => array( 'date', true ),
363
+ 'url' => array( 'url', false ),
364
+ 'ref' => array( 'ref', false ),
365
+ 'ip' => array( 'ip', false )
366
+ );
367
+
368
+ /**
369
+ * Filter hook to change column titles.
370
+ *
371
+ * @note DO NOT add extra columns.
372
+ *
373
+ * @since 3.0.0
374
+ */
375
+ return apply_filters( 'jj4t3_log_list_sortable_columns', $columns );
376
+ }
377
+
378
+ /**
379
+ * Message to be displayed when there are no items.
380
+ *
381
+ * If there are no errors logged yet, show custom error message
382
+ * instead of default one.
383
+ * Registering filter - "jj4t3_log_list_no_items_message".
384
+ *
385
+ * @since 2.0.0
386
+ * @access public
387
+ *
388
+ * @return void
389
+ */
390
+ public function no_items() {
391
+
392
+ /**
393
+ * Filter hook to change no items message.
394
+ *
395
+ * @since 3.0.0
396
+ */
397
+ _e( apply_filters( 'jj4t3_log_list_no_items_message', __( 'Ah! You are so clean that you still got ZERO errors.', JJ4T3_DOMAIN ) ) );
398
+ }
399
+
400
+ /**
401
+ * Default columns in list table.
402
+ *
403
+ * To show columns in error log list table. If there is nothing
404
+ * for switch, printing the whole array.
405
+ * Registering filter - "jj4t3_log_list_column_default".
406
+ *
407
+ * @param array $item Column data
408
+ * @param string $column_name Column name
409
+ *
410
+ * @since 2.0.0
411
+ * @access protected
412
+ *
413
+ * @return array
414
+ */
415
+ protected function column_default( $item, $column_name ) {
416
+
417
+ $columns = array_keys( jj4t3_log_columns() );
418
+
419
+ /**
420
+ * Filter hook to change column names.
421
+ *
422
+ * @note DO NOT add extra columns.
423
+ *
424
+ * @since 3.0.0
425
+ */
426
+ $columns = apply_filters( 'jj4t3_log_list_column_default', $columns );
427
+
428
+ // If current column is allowed.
429
+ if ( in_array( $column_name, $columns ) ) {
430
+ return $item[ $column_name ];
431
+ }
432
+
433
+ // Show the whole array for troubleshooting purposes.
434
+ return print_r( $item, true );
435
+ }
436
+
437
+ /**
438
+ * To output checkbox for bulk actions.
439
+ *
440
+ * This function is used to add new checkbox for all entries in
441
+ * the listing table. We use this checkbox to perform bulk actions.
442
+ *
443
+ * @param array $item Column data
444
+ *
445
+ * @since 2.1.0
446
+ * @access public
447
+ *
448
+ * @return string
449
+ */
450
+ function column_cb( $item ) {
451
+
452
+ return sprintf( '<input type="checkbox" name="bulk-delete[]" value="%s"/>', $item['id'] );
453
+ }
454
+
455
+ /**
456
+ * Date column content.
457
+ *
458
+ * This function is used to modify the column data for date in listing table.
459
+ * We can change styles, texts etc. using this function.
460
+ * Registering filter - "jj4t3_log_list_date_column".
461
+ *
462
+ * @param array $item Column data
463
+ *
464
+ * @since 2.0.0
465
+ * @access public
466
+ *
467
+ * @return string
468
+ */
469
+ function column_date( $item ) {
470
+
471
+ $delete_nonce = wp_create_nonce( 'bulk-' . $this->_args['plural'] );
472
+
473
+ $title = mysql2date( "j M Y, g:i a", $item['date'] );
474
+
475
+ $confirm = __( 'Are you sure you want to delete this item?', JJ4T3_DOMAIN );
476
+
477
+ $actions = array( 'delete' => sprintf( '<a href="?page=jj4t3-logs&action=%s&bulk-delete=%s&_wpnonce=%s" onclick="return confirm(\'%s\');">' . __( 'Delete', JJ4T3_DOMAIN ) . '</a>', 'delete', absint( $item['id'] ), $delete_nonce, $confirm ) );
478
+
479
+ /**
480
+ * Filter to change date colum html content.
481
+ *
482
+ * @since 3.0.0
483
+ */
484
+ return apply_filters( 'jj4t3_log_list_date_column', $title . $this->row_actions( $actions ) );
485
+ }
486
+
487
+ /**
488
+ * URL column content.
489
+ *
490
+ * This function is used to modify the column data for url in listing table.
491
+ * We can change styles, texts etc. using this function.
492
+ * Registering filter - "jj4t3_log_list_url_column".
493
+ *
494
+ * @param array $item Column data
495
+ *
496
+ * @since 2.0.0
497
+ * @access public
498
+ *
499
+ * @return string URL column html content
500
+ */
501
+ function column_url( $item ) {
502
+
503
+ // Get default text if empty value.
504
+ $url = $this->get_empty_content( $item['url'] );
505
+ if ( ! $url ) {
506
+ $url = '<span class="jj4t3-url-p">' . esc_url( $item['url'] ) . '</span>';
507
+ }
508
+
509
+ /**
510
+ * Filter to change url colum content.
511
+ *
512
+ * Remember this filter value is a partial url field.
513
+ *
514
+ * @since 3.0.0
515
+ */
516
+ return apply_filters( 'jj4t3_log_list_url_column', $this->get_group_content( $url, 'url', $item ) );
517
+ }
518
+
519
+ /**
520
+ * Referer column content.
521
+ *
522
+ * This function is used to modify the column data for ref in listing table.
523
+ * We can change styles, texts etc. using this function.
524
+ * Registering filter - "jj4t3_log_list_ref_column".
525
+ *
526
+ * @param array $item Column data
527
+ *
528
+ * @since 2.0.0
529
+ * @access public
530
+ *
531
+ * @return string Ref column html content.
532
+ */
533
+ function column_ref( $item ) {
534
+
535
+ // Get default text if empty value.
536
+ $ref = $this->get_empty_content( $item['ref'] );
537
+ if ( ! $ref ) {
538
+ $ref = '<a href="' . esc_url( $item['ref'] ) . '" target="_blank">' . esc_url( $item['ref'] ) . '</a>';
539
+ }
540
+
541
+ /**
542
+ * Filter to change referer url colum content.
543
+ *
544
+ * @since 3.0.0
545
+ */
546
+ return apply_filters( 'jj4t3_log_list_ref_column', $this->get_group_content( $ref, 'ref', $item ) );
547
+ }
548
+
549
+ /**
550
+ * User agent column content.
551
+ *
552
+ * This function is used to modify the column data for user agent in listing table.
553
+ * We can change styles, texts etc. using this function.
554
+ * Registering filter - "jj4t3_log_list_ua_column".
555
+ *
556
+ * @param array $item Column data
557
+ *
558
+ * @since 2.0.9
559
+ * @access public
560
+ *
561
+ * @return string User Agent column html content
562
+ */
563
+ function column_ua( $item ) {
564
+
565
+ // Sanitize text content.
566
+ $ua = sanitize_text_field( $item['ua'] );
567
+
568
+ /**
569
+ * Filter to change user agent colum content.
570
+ *
571
+ * @since 3.0.0
572
+ */
573
+ return apply_filters( 'jj4t3_log_list_ua_column', $this->get_group_content( $ua, 'ua', $item ) );
574
+ }
575
+
576
+ /**
577
+ * IP column content.
578
+ *
579
+ * This function is used to modify the column data for ip in listing table.
580
+ * We can change styles, texts etc. using this function.
581
+ * Registering filter - "jj4t3_log_list_ip_column".
582
+ *
583
+ * @param array $item Column data
584
+ *
585
+ * @since 2.0.9
586
+ * @access public
587
+ *
588
+ * @return string IP column html content.
589
+ */
590
+ function column_ip( $item ) {
591
+
592
+ // Get default text if empty value.
593
+ $ip = $this->get_empty_content( $item['ip'] );
594
+ if ( ! $ip ) {
595
+ $ip = sanitize_text_field( $item['ip'] );
596
+ }
597
+
598
+ /**
599
+ * Filter to change IP colum content.
600
+ *
601
+ * @since 3.0.0
602
+ */
603
+ return apply_filters( 'jj4t3_log_list_ip_column', $this->get_group_content( $ip, 'ip', $item ) );
604
+ }
605
+
606
+ /**
607
+ * Custom redirect column content.
608
+ *
609
+ * This function is used to modify the column data for custom redirect in listing table.
610
+ *
611
+ * @param array $item Column data
612
+ *
613
+ * @since 2.0.9
614
+ * @access public
615
+ *
616
+ * @return string HTML content for redirect column.
617
+ */
618
+ function column_redirect( $item ) {
619
+
620
+ // Link for redirect.
621
+ $link = esc_url( $item['redirect'] );
622
+
623
+ // Get default text if empty value.
624
+ $title = empty( $link ) ? __( 'Default', JJ4T3_DOMAIN ) : $link;
625
+
626
+ $redirect = '<a href="javascript:void(0)" title="' . __( 'Customize', JJ4T3_DOMAIN ) . '" class="jj4t3_redirect_thickbox" url_404="' . esc_url( $item['url'] ) . '" wpnonce="' . wp_create_nonce( "jj4t3_redirect_nonce" ) . '">' . $title . '</a>';
627
+
628
+ return $redirect;
629
+ }
630
+
631
+ /**
632
+ * Get default text if empty.
633
+ *
634
+ * Get an error text with custom class to show if the
635
+ * current column value is empty or n/a.
636
+ *
637
+ * @param string $content Content to display.
638
+ * @param string $column Column name.
639
+ * @param array $item Items array.
640
+ *
641
+ * @since 3.0.0
642
+ * @access private
643
+ *
644
+ * @return string|boolean
645
+ */
646
+ private function get_group_content( $content, $column, $item ) {
647
+
648
+ $count_text = '';
649
+ // Check if current column name is grouped.
650
+ // Add count text then.
651
+ if ( ! empty( $item['count'] ) && $item['count'] > 1 && $column === $this->group_by ) {
652
+ $count_text = " (<strong>" . $item['count'] . "</strong>)";
653
+ }
654
+
655
+ return '<p>' . $content . $count_text . '</p>';
656
+ }
657
+
658
+ /**
659
+ * Get default text if empty.
660
+ *
661
+ * Get an error text with custom class to show if the
662
+ * current column value is empty or n/a.
663
+ *
664
+ * @param string $value Field value.
665
+ *
666
+ * @since 3.0.0
667
+ * @access private
668
+ *
669
+ * @return string|boolean
670
+ */
671
+ private function get_empty_content( $value ) {
672
+
673
+ // Get default error text.
674
+ if ( strtolower( $value ) === 'n/a' || empty( $value ) ) {
675
+ return '<span class="jj4t3-url-p">n/a</span>';
676
+ }
677
+
678
+ return false;
679
+ }
680
+
681
+ /**
682
+ * Bulk actions drop down.
683
+ *
684
+ * Options to be added to the bulk actions drop down for users
685
+ * to select. We have added 'Delete' actions.
686
+ * Registering filter - "jj4t3_log_list_bulk_actions".
687
+ *
688
+ * @since 2.0.0
689
+ * @access public
690
+ *
691
+ * @return array $actions Options to be added to the action select box.
692
+ */
693
+ public function get_bulk_actions() {
694
+
695
+ $actions = array(
696
+ 'bulk_delete' => __( 'Delete Selected', JJ4T3_DOMAIN ),
697
+ 'bulk_clean' => __( 'Delete All', JJ4T3_DOMAIN ),
698
+ 'bulk_delete_all' => __( 'Delete All (Keep redirects)', JJ4T3_DOMAIN ),
699
+ );
700
+
701
+ /**
702
+ * Filter hook to change actions.
703
+ *
704
+ * @note If you are adding extra actions
705
+ * Make sure it's actions are properly added.
706
+ *
707
+ * @since 3.0.0
708
+ */
709
+ return apply_filters( 'jj4t3_log_list_bulk_actions', $actions );
710
+ }
711
+
712
+ /**
713
+ * Add extra action dropdown for grouping the error logs.
714
+ *
715
+ * @param string $which Top or Bottom.
716
+ *
717
+ * @access protected
718
+ * @since 3.0.0
719
+ *
720
+ * @return void
721
+ */
722
+ public function extra_tablenav( $which ) {
723
+
724
+ if ( $this->has_items() && 'top' == $which ) {
725
+
726
+ // This filter is already documented above.
727
+ $allowed_values = apply_filters( 'jj4t3_log_list_groupby_allowed', array( 'url', 'ref', 'ip', 'ua' ) );
728
+ // Allowed/available columns.
729
+ $available_columns = jj4t3_log_columns();
730
+ // Consider only available columns.
731
+ $column_names = array_intersect( $allowed_values, array_keys( $available_columns ) );
732
+ // Add dropdown.
733
+ echo '<div class="alignleft actions bulkactions">';
734
+ echo '<select name="group_by_top" class="404_group_by">';
735
+ echo '<option value="">' . __( 'Group by', JJ4T3_DOMAIN ) . '</option>';
736
+ foreach ( $column_names as $column ) {
737
+ echo '<option value="' . $column . '" ' . selected( $column, $this->group_by ) . '>' . $available_columns[ $column ] . '</option>';
738
+ }
739
+ echo '</select>';
740
+ submit_button( __( 'Apply', JJ4T3_DOMAIN ), 'button', 'filter_action', false, array( 'id' => 'post-query' ) );
741
+ echo '</div>';
742
+ }
743
+ }
744
+
745
+ /**
746
+ * To perform bulk actions.
747
+ *
748
+ * After security check, perform bulk actions selected by
749
+ * the user. Only allowed actions will be performed.
750
+ *
751
+ * @since 2.1.0
752
+ * @access private
753
+ * @uses check_admin_referer() For security check.
754
+ *
755
+ * @return void|boolean
756
+ */
757
+ private function process_actions() {
758
+
759
+ // Get current action.
760
+ $action = $this->current_action();
761
+
762
+ // Get allowed actions array.
763
+ $allowed_actions = array_keys( $this->get_bulk_actions() );
764
+
765
+ // Verify only allowed actions are passed.
766
+ if ( ! in_array( $action, $allowed_actions ) && 'delete' !== $action ) {
767
+ return false;
768
+ }
769
+
770
+ // IDs of log entires to process.
771
+ $ids = jj4t3_from_request( 'bulk-delete', true );
772
+
773
+ // Run custom bulk actions.
774
+ // Add other custom actions in switch..
775
+ switch ( $action ) {
776
+ // Normal selected deletes.
777
+ case 'delete':
778
+ case 'bulk_delete':
779
+ case 'bulk_clean':
780
+ case 'bulk_delete_all':
781
+ $this->delete_logs( $ids, $action );
782
+ break;
783
+ // Add custom actions here.
784
+ }
785
+
786
+ return true;
787
+ }
788
+
789
+ /**
790
+ * Remove sensitive values from the URL.
791
+ *
792
+ * If WordPress nonce or admin referrer is found in url
793
+ * remove that and redirect to same page.
794
+ *
795
+ * @param boolean $action_performed If any actions performed.
796
+ *
797
+ * @access private
798
+ * @since 3.0.0
799
+ *
800
+ * @return void
801
+ */
802
+ private function safe_redirect( $action_performed = false ) {
803
+
804
+ // If sensitive data found, remove those and redirect.
805
+ if ( ! empty( $_GET['_wp_http_referer'] ) || ! empty( $_GET['_wpnonce'] ) ) {
806
+ // Redirect to current page.
807
+ wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
808
+ exit();
809
+ }
810
+
811
+ // If bulk actions performed, redirect.
812
+ if ( $action_performed === true ) {
813
+ // Redirect to current page.
814
+ wp_redirect( remove_query_arg( array( 'action', 'action2' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
815
+ exit();
816
+ }
817
+ }
818
+
819
+ /**
820
+ * Delete error logs.
821
+ *
822
+ * Bulk action processor to delete error logs according to
823
+ * the user selection. We are using IF ELSE loop instead of
824
+ * switch to easily handle conditions.
825
+ *
826
+ * @param mixed $ids ID(s) of the log(s).
827
+ * @param string $action Current bulk action.
828
+ *
829
+ * @since 2.0.0
830
+ * @access private
831
+ *
832
+ * @return void
833
+ */
834
+ private function delete_logs( $ids, $action ) {
835
+
836
+ global $wpdb;
837
+
838
+ if ( is_numeric( $ids ) && 'delete' === $action ) {
839
+ // If a single log is being deleted.
840
+ $query = "DELETE FROM " . JJ4T3_TABLE . " WHERE id = " . absint( $ids );
841
+ } elseif ( is_array( $ids ) && 'bulk_delete' === $action ) {
842
+ // If multiple selected logs are being deleted.
843
+ $ids = implode( ',', array_map( 'absint', $ids ) );
844
+ $query = "DELETE FROM " . JJ4T3_TABLE . " WHERE id IN($ids)";
845
+ } elseif ( 'bulk_delete_all' === $action ) {
846
+ // If deleting all logs except custom redirected ones.
847
+ // Delete the duplicate entries from custom redirects.
848
+ $query = "DELETE t1 FROM " . JJ4T3_TABLE . " t1, " . JJ4T3_TABLE . " t2 WHERE (t1.id < t2.id AND t1.url = t2.url) OR t1.redirect IS NULL OR t1.redirect = ''";
849
+ } elseif ( 'bulk_clean' === $action ) {
850
+ // If deleting all logs.
851
+ $query = "DELETE FROM " . JJ4T3_TABLE;
852
+ } else {
853
+ // Incase if invalid log ids.
854
+ return;
855
+ }
856
+
857
+ // Run query to delete logs.
858
+ $wpdb->query( $query );
859
+ }
860
+
861
+ /**
862
+ * Set screen options of error log listing.
863
+ *
864
+ * @param string $status Status.
865
+ * @param string $option Option name.
866
+ * @param mixed $value Value of the option.
867
+ *
868
+ * @since 2.1.0
869
+ * @access public
870
+ *
871
+ * @return string
872
+ */
873
+ public static function set_screen( $status, $option, $value ) {
874
+
875
+ return $value;
876
+ }
877
+
878
+ /**
879
+ * Get custom redirect modal content
880
+ *
881
+ * @global object $wpdb WP DB object
882
+ * @since 2.2.0
883
+ * @access public
884
+ *
885
+ * @return void
886
+ */
887
+ public static function open_redirect() {
888
+
889
+ // Yes, security check is a must when you alter something.
890
+ check_ajax_referer( 'jj4t3_redirect_nonce', 'nonce' );
891
+
892
+ // Verify if the 404 value is found.
893
+ if ( empty( $_POST['url_404'] ) ) {
894
+ wp_die();
895
+ }
896
+
897
+ $url_404 = $_POST['url_404'];
898
+
899
+ global $wpdb;
900
+
901
+ // Get custom redirect value from db, if exist.
902
+ $result = $wpdb->get_row( $wpdb->prepare( "SELECT redirect, options FROM " . JJ4T3_TABLE . " WHERE url = '%s' AND redirect IS NOT NULL LIMIT 0,1", esc_url( $url_404 ) ), 'OBJECT' );
903
+
904
+ // Get custom redirect type and url.
905
+ $url = empty( $result->redirect ) ? '' : esc_url( $result->redirect );
906
+
907
+ // Get custom options.
908
+ $options = empty( $result->options ) ? array() : maybe_unserialize( $result->options );
909
+
910
+ // Get result in an array.
911
+ $data = array(
912
+ 'url_404' => esc_url( $url_404 ),
913
+ 'url' => esc_url( $url ),
914
+ );
915
+
916
+ // Set the custom options for the 404.
917
+ $data['type'] = empty( $options['type'] ) ? jj4t3_get_option( 'redirect_type' ) : intval( $options['type'] );
918
+ $data['redirect'] = isset( $options['redirect'] ) ? intval( $options['redirect'] ) : -1;
919
+ $data['log'] = isset( $options['log'] ) ? intval( $options['log'] ) : -1;
920
+ $data['alert'] = isset( $options['alert'] ) ? intval( $options['alert'] ) : -1;
921
+
922
+ /**
923
+ * Filter to alter custom redirect modal response array.
924
+ *
925
+ * You should return response in array.
926
+ *
927
+ * @since 3.0.0
928
+ */
929
+ wp_send_json( apply_filters( 'jj4t3_log_list_custom_redirect_open', $data ) );
930
+ }
931
+
932
+ /**
933
+ * Save custom redirect value.
934
+ *
935
+ * When user set a custom redirect url for a 404 link, save the data
936
+ * from modal by updating all error logs of the current 404 links.
937
+ *
938
+ * @global object $wpdb WP DB object
939
+ * @since 2.2.0
940
+ * @access public
941
+ *
942
+ * @note Always die() for wp_ajax
943
+ *
944
+ * @return void
945
+ */
946
+ public static function save_redirect() {
947
+
948
+ // Yes, security check is a must when you alter something.
949
+ check_ajax_referer( 'jj4t3_redirect_nonce', 'jj4t3_redirect_nonce' );
950
+
951
+ // Custom options for the 404 path.
952
+ $options = maybe_serialize(
953
+ array(
954
+ 'redirect' => jj4t3_from_request( 'jj4t3_custom_redirect_redirect' ),
955
+ 'log' => jj4t3_from_request( 'jj4t3_custom_redirect_log' ),
956
+ 'alert' => jj4t3_from_request( 'jj4t3_custom_redirect_alert' ),
957
+ 'type' => jj4t3_from_request( 'jj4t3_custom_redirect_type' ),
958
+ )
959
+ );
960
+
961
+ // Get 404 url.
962
+ $url = jj4t3_from_request( 'jj4t3_custom_redirect', false ) ? esc_url( jj4t3_from_request( 'jj4t3_custom_redirect' ) ) : '';
963
+
964
+ global $wpdb;
965
+
966
+ // Get custom redirect url.
967
+ $url_404 = jj4t3_from_request( 'jj4t3_redirect_404', false ) ? esc_url( jj4t3_from_request( 'jj4t3_redirect_404' ) ) : '';
968
+
969
+ /**
970
+ * Action hook to run before updating a custom redirect.
971
+ *
972
+ * If you want to change the query or stop the update query, just wp_die()
973
+ * after your custom function.
974
+ *
975
+ * @param string $url_404 404 link.
976
+ * @param string $url Link to redirect.
977
+ *
978
+ * @since 3.0.0
979
+ */
980
+ do_action( 'jj4t3_log_list_custom_redirect_save', $url_404, $url );
981
+
982
+ // Run update query and set custom redirect.
983
+ $wpdb->query( $wpdb->prepare( "UPDATE " . JJ4T3_TABLE . " SET redirect = '%s', options = '%s' WHERE url = '%s'", $url, $options, $url_404 ) );
984
+
985
+ // Die ajax request.
986
+ wp_die();
987
+ }
988
+
989
+ /**
990
+ * This function displays the custom redirect modal html content
991
+ *
992
+ * @since 2.2.0
993
+ * @acess public
994
+ *
995
+ * @return void
996
+ */
997
+ public static function get_redirect_content() {
998
+
999
+ include_once JJ4T3_DIR . 'includes/admin/views/custom-redirect.php';
1000
+ }
1001
+
1002
+ }
includes/admin/css/admin.css ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .jj4t3-url-p {
2
+ color: #E53531 !important;
3
+ }
4
+
5
+ .jj4t3-fixed-height {
6
+ height: 120px;
7
+ margin-bottom: 20px;
8
+ overflow: auto;
9
+ padding: 0 20px 0 0;
10
+ }
11
+
12
+ .jj4t3-notice {
13
+ padding: 10px;
14
+ }
15
+
16
+ .jj4t3-p-desc {
17
+ font-size: 13px !important;
18
+ }
19
+
20
+ .jj4t3-h2 {
21
+ font-size: 23px;
22
+ line-height: 29px;
23
+ font-weight: bold !important;
24
+ }
25
+
26
+ h2 .subtitle a {
27
+ text-decoration: none;
28
+ }
29
+
30
+ .jj4t3-hide {
31
+ display: none;
32
+ }
33
+
34
+ .jj4t3-handle {
35
+ cursor: default !important;
36
+ }
includes/admin/css/admin.min.css ADDED
@@ -0,0 +1 @@
 
1
+ .jj4t3-url-p{color:#E53531!important}.jj4t3-fixed-height{height:120px;margin-bottom:20px;overflow:auto;padding:0 20px 0 0}.jj4t3-notice{padding:10px}.jj4t3-p-desc{font-size:13px!important}.jj4t3-h2{font-size:23px;line-height:29px;font-weight:700!important}h2 .subtitle a{text-decoration:none}.jj4t3-hide{display:none}.jj4t3-handle{cursor:default!important}
{admin → includes/admin}/css/index.php RENAMED
File without changes
includes/admin/images/gray-grad.png ADDED
Binary file
{admin/css/min → includes/admin/images}/index.php RENAMED
File without changes
{admin/images → includes/admin}/index.php RENAMED
File without changes
includes/admin/js/admin.js ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ( $ ) {
2
+ 'use strict';
3
+
4
+ /**
5
+ * All of the code for our admin-specific JavaScript source
6
+ * should reside in this file.
7
+ *
8
+ * Note that this assume you're going to use jQuery, so it prepares
9
+ * the $ function reference to be used within the scope of this
10
+ * function.
11
+ *
12
+ * From here, we are able to define handlers for when the DOM is
13
+ * ready:
14
+ *
15
+ * $(function() {
16
+ *
17
+ * });
18
+ *
19
+ * Or when the window is loaded:
20
+ *
21
+ * $( window ).load(function() {
22
+ *
23
+ * });
24
+ *
25
+ * ...and so on.
26
+ */
27
+ $( function () {
28
+
29
+ // Hide/Show fields when redirect to value changes.
30
+ $( '#jj4t3_redirect_to' ).change( function () {
31
+
32
+ switch ( $( this ).val() ) {
33
+
34
+ case 'page':
35
+ $( '#custom_page' ).show();
36
+ $( '#custom_url' ).hide();
37
+ break;
38
+
39
+ case 'link':
40
+ $( '#custom_url' ).show();
41
+ $( '#custom_page' ).hide();
42
+ break;
43
+
44
+ default:
45
+ $( '#custom_page' ).hide();
46
+ $( '#custom_url' ).hide();
47
+ break;
48
+ }
49
+ } );
50
+
51
+ // open custom redirect form modal.
52
+ $( '.jj4t3_redirect_thickbox' ).on( 'click', function () {
53
+
54
+ var data = {
55
+ 'action': 'jj4t3_redirect_thickbox',
56
+ 'url_404': $( this ).attr( 'url_404' ),
57
+ 'nonce': $( this ).attr( 'wpnonce' )
58
+ };
59
+
60
+ /** global: ajaxurl */
61
+ $.post( ajaxurl, data, function ( response ) {
62
+
63
+ /** global: jj4t3strings (available from localization) */
64
+ tb_show( jj4t3strings.redirect, '#TB_inline?width=700&height=370&inlineId=jj4t3-redirect-modal' );
65
+
66
+ $( '#jj4t3_redirect_404' ).val( response.url_404 );
67
+ $( '#jj4t3_redirect_404_text' ).html( response.url_404 );
68
+ $( '#jj4t3_redirect_url' ).val( response.url );
69
+ $( '#jj4t3_custom_redirect_type' ).val( response.type );
70
+
71
+ jj4t3Check( 'jj4t3_custom_redirect_redirect', response.redirect );
72
+ jj4t3Check( 'jj4t3_custom_redirect_log', response.log );
73
+ jj4t3Check( 'jj4t3_custom_redirect_alert', response.alert );
74
+ } );
75
+ } );
76
+
77
+ // Save custom redirect value.
78
+ $( '#jj4t3_custom_redirect_submit' ).on( 'click', function () {
79
+
80
+ $( this ).addClass( 'disabled' );
81
+
82
+ $( '.jj4t3-spinner' ).css( 'visibility', 'visible' );
83
+
84
+ // Form data.
85
+ var data = $( '#jj4t3_custom_redirect_form' ).serialize();
86
+
87
+ /** global: ajaxurl */
88
+ $.post( ajaxurl, data, function ( response ) {
89
+
90
+ // Close the modal.
91
+ tb_remove();
92
+ $( '#jj4t3_custom_redirect_submit' ).removeClass( 'disabled' );
93
+ $( '.j4t3-spinner' ).css( "visibility", 'hidden' );
94
+
95
+ // Redirect after update.
96
+ location.reload();
97
+ } );
98
+ } );
99
+
100
+ /**
101
+ * Set checkbox checked/not checked.
102
+ *
103
+ * @param object selecter Current selector element.
104
+ * @param mixed val Value.
105
+ */
106
+ var jj4t3Check = function ( name, val ) {
107
+
108
+ $( 'input[name=' + name + '][value=' + val + ']' ).prop( 'checked', true );
109
+ }
110
+ } );
111
+
112
+ })( jQuery );
includes/admin/js/admin.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(t){"use strict";t(function(){t("#jj4t3_redirect_to").change(function(){switch(t(this).val()){case"page":t("#custom_page").show(),t("#custom_url").hide();break;case"link":t("#custom_url").show(),t("#custom_page").hide();break;default:t("#custom_page").hide(),t("#custom_url").hide()}}),t(".jj4t3_redirect_thickbox").on("click",function(){var i={action:"jj4t3_redirect_thickbox",url_404:t(this).attr("url_404"),nonce:t(this).attr("wpnonce")};t.post(ajaxurl,i,function(i){tb_show(jj4t3strings.redirect,"#TB_inline?width=700&height=370&inlineId=jj4t3-redirect-modal"),t("#jj4t3_redirect_404").val(i.url_404),t("#jj4t3_redirect_404_text").html(i.url_404),t("#jj4t3_redirect_url").val(i.url),t("#jj4t3_custom_redirect_type").val(i.type),e("jj4t3_custom_redirect_redirect",i.redirect),e("jj4t3_custom_redirect_log",i.log),e("jj4t3_custom_redirect_alert",i.alert)})}),t("#jj4t3_custom_redirect_submit").on("click",function(){t(this).addClass("disabled"),t(".jj4t3-spinner").css("visibility","visible");var e=t("#jj4t3_custom_redirect_form").serialize();t.post(ajaxurl,e,function(e){tb_remove(),t("#jj4t3_custom_redirect_submit").removeClass("disabled"),t(".j4t3-spinner").css("visibility","hidden"),location.reload()})});var e=function(e,i){t("input[name="+e+"][value="+i+"]").prop("checked",!0)}})}(jQuery);
{admin → includes/admin/js}/index.php RENAMED
File without changes
includes/admin/views/admin.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * Provide a dashboard view for the plugin.
8
+ *
9
+ * This file is used to markup the dashboard pages of the plugin.
10
+ *
11
+ * @category Core
12
+ * @package I4T3
13
+ * @subpackage Admin View
14
+ * @author Joel James <mail@cjoel.com>
15
+ * @license http://www.gnu.org/licenses/ GNU General Public License
16
+ * @link https://duckdev.com/products/404-to-301
17
+ */
18
+ ?>
19
+ <div class="wrap">
20
+
21
+ <h2 class="jj4t3-h2"><?php _e( '404 to 301', JJ4T3_DOMAIN ); ?> <span class="subtitle"><?php printf( __( 'by <a href="%s">Joel James</a>', JJ4T3_DOMAIN ), 'https://duckdev.com' ); ?> ( v<?php echo JJ4T3_VERSION; ?> )</span></h2><br/>
22
+
23
+ <!-- Settings updated message -->
24
+ <?php settings_errors(); ?>
25
+
26
+ <h2 class="nav-tab-wrapper">
27
+ <a href="?page=jj4t3-settings" class="nav-tab nav-tab-active"><span class="dashicons dashicons-admin-generic"></span> <?php _e( 'Settings', JJ4T3_DOMAIN ); ?></a>
28
+ <?php do_action( 'jj4t3_settings_tab' ); // Action hook to add new items to tab. ?>
29
+ </h2>
30
+
31
+ <?php require_once 'settings.php'; ?>
32
+
33
+ </div><!-- /.wrap -->
includes/admin/views/custom-redirect.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit; ?>
5
+
6
+ <div id="jj4t3-redirect-modal" style="display:none;">
7
+ <div id="jj4t3-thickbox-content" class="wrap">
8
+ <form id="jj4t3_custom_redirect_form" action="javascript:void(0)">
9
+ <table class="form-table">
10
+ <tr>
11
+ <th><?php _e( 'Redirecting from', JJ4T3_DOMAIN ); ?> :</th>
12
+ <td><strong><p id="jj4t3_redirect_404_text"></p></strong></td>
13
+ </tr>
14
+ <tr>
15
+ <th><?php _e( 'Redirect', JJ4T3_DOMAIN ); ?> :</th>
16
+ <td>
17
+ <input type="radio" name="jj4t3_custom_redirect_redirect" value="-1" checked> <?php _e( 'Default', JJ4T3_DOMAIN ); ?>
18
+ <input type="radio" name="jj4t3_custom_redirect_redirect" value="1"> <?php _e( 'Enable', JJ4T3_DOMAIN ); ?>
19
+ <input type="radio" name="jj4t3_custom_redirect_redirect" value="0"> <?php _e( 'Disable', JJ4T3_DOMAIN ); ?>
20
+ </td>
21
+ </tr>
22
+ <tr>
23
+ <th><?php _e( 'Error logging', JJ4T3_DOMAIN ); ?> :</th>
24
+ <td>
25
+ <input type="radio" name="jj4t3_custom_redirect_log" value="-1" checked> <?php _e( 'Default', JJ4T3_DOMAIN ); ?>
26
+ <input type="radio" name="jj4t3_custom_redirect_log" value="1"> <?php _e( 'Enable', JJ4T3_DOMAIN ); ?>
27
+ <input type="radio" name="jj4t3_custom_redirect_log" value="0"> <?php _e( 'Disable', JJ4T3_DOMAIN ); ?>
28
+ </td>
29
+ </tr>
30
+ <tr>
31
+ <th><?php _e( 'Email alert', JJ4T3_DOMAIN ); ?> :</th>
32
+ <td>
33
+ <input type="radio" name="jj4t3_custom_redirect_alert" value="-1" checked> <?php _e( 'Default', JJ4T3_DOMAIN ); ?>
34
+ <input type="radio" name="jj4t3_custom_redirect_alert" value="1"> <?php _e( 'Enable', JJ4T3_DOMAIN ); ?>
35
+ <input type="radio" name="jj4t3_custom_redirect_alert" value="0"> <?php _e( 'Disable', JJ4T3_DOMAIN ); ?>
36
+ </td>
37
+ </tr>
38
+ <tr>
39
+ <th><?php _e( 'Redirect to', JJ4T3_DOMAIN ); ?> :</th>
40
+ <td>
41
+ <input type="text" size="40" name="jj4t3_custom_redirect" id="jj4t3_redirect_url" value="">
42
+ <p class="description"><?php _e( 'Enter the url if you want to set custom redirect for above 404 path. Enter the full url including http://. Leave empty if you want to follow deafult settings.', JJ4T3_DOMAIN ); ?></p>
43
+ <input type="hidden" value="" id="jj4t3_redirect_404" name="jj4t3_redirect_404">
44
+ <input type="hidden" value="<?php echo wp_create_nonce( "jj4t3_redirect_nonce" ); ?>" id="jj4t3_redirect_nonce" name="jj4t3_redirect_nonce">
45
+ <input type="hidden" value="jj4t3_redirect_form" name="action">
46
+ </td>
47
+ </tr>
48
+ <?php $statuses = jj4t3_redirect_statuses(); ?>
49
+ <?php if ( ! empty( $statuses ) ) : ?>
50
+ <tr>
51
+ <th><?php _e( 'Redirect type', JJ4T3_DOMAIN ); ?></th>
52
+ <td>
53
+ <select name="jj4t3_custom_redirect_type" id="jj4t3_custom_redirect_type">
54
+ <?php foreach ( $statuses as $status => $label ) : ?>
55
+ <option value='<?php echo $status; ?>' <?php selected( jj4t3_get_option( 'redirect_type' ), $status ); ?>><?php echo $label; ?></option>
56
+ <?php endforeach; ?>
57
+ </select>
58
+ <p class="description jj4t3-p-desc"><?php _e( 'Select redirect type to override default one.', JJ4T3_DOMAIN ); ?></p>
59
+ </td>
60
+ </tr>
61
+ <?php endif; ?>
62
+ <tr>
63
+ <td><span class="spinner jj4t3-spinner"></span></td>
64
+ <td>
65
+ <?php submit_button( __( 'Save Redirect', JJ4T3_DOMAIN ), 'primary', 'jj4t3_custom_redirect_submit', false, array( 'id' => 'jj4t3_custom_redirect_submit' ) ); ?>
66
+ </td>
67
+ </tr>
68
+ </table>
69
+ </form>
70
+ </div>
71
+ </div>
{admin/js → includes/admin/views}/index.php RENAMED
File without changes
includes/admin/views/settings.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit; ?>
5
+
6
+ <form method="post" action="options.php">
7
+ <?php settings_fields( 'i4t3_gnrl_options' ); ?>
8
+ <?php $options = get_option( 'i4t3_gnrl_options' ); ?>
9
+ <?php $cp_style = ( $options['redirect_to'] !== 'page' ) ? 'jj4t3-hide' : '' ?>
10
+ <?php $cl_style = ( $options['redirect_to'] !== 'link' ) ? 'jj4t3-hide' : '' ?>
11
+ <?php $cl_style = ( ! in_array( $options['redirect_to'], array( 'link', 'page', '0' ) ) ) ? '' : $cl_style; ?>
12
+ <table class="form-table">
13
+ <tbody>
14
+ <?php $statuses = jj4t3_redirect_statuses(); ?>
15
+ <?php if ( !empty( $statuses ) ) : ?>
16
+ <tr>
17
+ <th><?php _e( 'Redirect type', JJ4T3_DOMAIN ); ?></th>
18
+ <td>
19
+ <select name='i4t3_gnrl_options[redirect_type]'>
20
+ <?php foreach ( $statuses as $status => $label ) : ?>
21
+ <option value='<?php echo $status; ?>' <?php selected( $options['redirect_type'], $status ); ?>><?php echo $label; ?></option>
22
+ <?php endforeach; ?>
23
+ </select>
24
+ <p class="description jj4t3-p-desc"><a target="_blank" href="https://moz.com/learn/seo/redirection"><strong><?php _e( 'Learn more', JJ4T3_DOMAIN ); ?></strong></a> <?php _e( 'about these redirect types', JJ4T3_DOMAIN ); ?>
25
+ </p>
26
+ </td>
27
+ </tr>
28
+ <?php endif; ?>
29
+ <tr>
30
+ <th><?php _e( 'Redirect to', JJ4T3_DOMAIN ); ?></th>
31
+ <td>
32
+ <select name='i4t3_gnrl_options[redirect_to]' id='jj4t3_redirect_to'>
33
+ <option value='page' <?php selected( $options['redirect_to'], 'page' ); ?>><?php _e( 'Existing Page', JJ4T3_DOMAIN ); ?></option>
34
+ <option value='link' <?php selected( $options['redirect_to'], 'link' ); ?>><?php _e( 'Custom URL', JJ4T3_DOMAIN ); ?></option>
35
+ <option value='0' <?php selected( $options['redirect_to'], 0 ); ?>><?php _e( 'No Redirect', JJ4T3_DOMAIN ); ?></option>
36
+ </select>
37
+ <p class="description jj4t3-p-desc"><strong><?php _e( 'Existing Page', JJ4T3_DOMAIN ); ?>:</strong> <?php _e( 'Select any WordPress page as a 404 page', JJ4T3_DOMAIN ); ?>.</p>
38
+ <p class="description jj4t3-p-desc"><strong><?php _e( 'Custom URL', JJ4T3_DOMAIN ); ?>:</strong> <?php _e( 'Redirect 404 requests to a specific URL', JJ4T3_DOMAIN ); ?>.</p>
39
+ <p class="description jj4t3-p-desc"><strong><?php _e( 'No Redirect', JJ4T3_DOMAIN ); ?>:</strong> <?php _e( 'To disable redirect', JJ4T3_DOMAIN ); ?>.</p>
40
+ <p class="description jj4t3-p-desc"><strong><?php _e( 'You can override this by setting individual custom redirects from error logs list.', JJ4T3_DOMAIN ); ?></strong></p>
41
+ </td>
42
+ </tr>
43
+ <tr id="custom_page" class="<?php echo $cp_style; ?>">
44
+ <th><?php _e( 'Select the page', JJ4T3_DOMAIN ); ?></th>
45
+ <td>
46
+ <?php wp_dropdown_pages( array( 'name' => 'i4t3_gnrl_options[redirect_page]', 'selected' => $options['redirect_page'] ) ); ?>
47
+ <p class="description jj4t3-p-desc"><?php _e( 'The default 404 page will be replaced by the page you choose in this list.', JJ4T3_DOMAIN ); ?></p>
48
+ <p class="description jj4t3-p-desc"><?php printf( __( 'You can <a href="%s" target="_blank">create a custom 404</a> page and assign that page here.', JJ4T3_DOMAIN ), admin_url( 'post-new.php?post_type=page' ) ); ?></p>
49
+ </td>
50
+ </tr>
51
+ <tr id="custom_url" class="<?php echo $cl_style; ?>">
52
+ <th><?php _e( 'Custom URL', JJ4T3_DOMAIN ); ?></th>
53
+ <td>
54
+ <input type="url" size="40" placeholder="<?php echo home_url(); ?>" name="i4t3_gnrl_options[redirect_link]" value="<?php echo $options['redirect_link']; ?>">
55
+ <p class="description jj4t3-p-desc"><?php _e( 'Enter any url (including http://)', JJ4T3_DOMAIN ); ?></p>
56
+ </td>
57
+ </tr>
58
+ <tr>
59
+ <th><?php _e( 'Log 404 Errors', JJ4T3_DOMAIN ); ?></th>
60
+ <td>
61
+ <input type="checkbox" name="i4t3_gnrl_options[redirect_log]" value="1" <?php checked( jj4t3_get_option( 'redirect_log' ), 1 ); ?> />
62
+ <p class="description jj4t3-p-desc"><?php _e( 'Enable/Disable Logging', JJ4T3_DOMAIN ); ?></p>
63
+ </td>
64
+ </tr>
65
+ <tr>
66
+ <th><?php _e( 'Email notifications', JJ4T3_DOMAIN ); ?></th>
67
+ <td>
68
+ <input type="checkbox" name="i4t3_gnrl_options[email_notify]" value="1" <?php checked( jj4t3_get_option( 'email_notify' ), 1 ); ?> />
69
+ <p class="description jj4t3-p-desc"><?php _e( 'If you check this, an email will be sent on every 404 log on the admin email account.', JJ4T3_DOMAIN ); ?></p>
70
+ </td>
71
+ </tr>
72
+ <tr>
73
+ <th><?php _e( 'Email address', JJ4T3_DOMAIN ); ?></th>
74
+ <td>
75
+ <?php $notify_address = ( isset( $options['email_notify_address'] ) ) ? $options['email_notify_address'] : get_option( 'admin_email' ); ?>
76
+ <input type="email" placeholder="<?php echo get_option( 'admin_email' ); ?>" name="i4t3_gnrl_options[email_notify_address]" value="<?php echo $notify_address; ?>">
77
+ <p class="description jj4t3-p-desc"><?php _e( 'Change the recipient email address for error log notifications.', JJ4T3_DOMAIN ); ?></p>
78
+ </td>
79
+ </tr>
80
+ <tr>
81
+ <th><?php _e( 'Exclude paths', JJ4T3_DOMAIN ); ?></th>
82
+ <td>
83
+ <textarea rows="5" cols="50" placeholder="wp-content/plugins/abc-plugin/css/" name="i4t3_gnrl_options[exclude_paths]"><?php echo $options['exclude_paths']; ?></textarea>
84
+ <p class="description jj4t3-p-desc"><?php _e( 'If you want to exclude few paths from error logs, enter here. One per line.', JJ4T3_DOMAIN ); ?></p>
85
+ </td>
86
+ </tr>
87
+ </tbody>
88
+ </table>
89
+ <?php submit_button( __( 'Save settings', JJ4T3_DOMAIN ) ); ?>
90
+ </form><!-- /.form -->
includes/class-404-to-301-activator.php DELETED
@@ -1,90 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPINC')) {
4
- die('Damn it.! Dude you are looking for what?');
5
- }
6
-
7
- /**
8
- * Fired during plugin activation.
9
- *
10
- * This class defines all code necessary to run during the plugin's activation.
11
- *
12
- * @category Core
13
- * @package I4T3
14
- * @subpackage Activator
15
- * @author Joel James <me@joelsays.com>
16
- * @license http://www.gnu.org/licenses/ GNU General Public License
17
- * @link https://thefoxe.com/products/404-to-301
18
- */
19
- class _404_To_301_Activator {
20
-
21
- /**
22
- * Function to run during activation
23
- *
24
- * We register default options to the WordPress
25
- * if not exists already.
26
- *
27
- * @since 1.0.0
28
- * @access public
29
- *
30
- * @return void
31
- */
32
- public static function activate() {
33
-
34
- // default settings array
35
- $options = array(
36
- 'redirect_type' => '301',
37
- 'redirect_link' => home_url(),
38
- 'redirect_log' => 1,
39
- 'redirect_to' => 'link',
40
- 'redirect_page' => '',
41
- 'email_notify' => 0,
42
- 'email_notify_address' => get_option( 'admin_email' ),
43
- 'exclude_paths' => '/wp-content'
44
- );
45
-
46
- // If not already exist, adding values
47
- if ( ! get_option( 'i4t3_gnrl_options' ) ) {
48
- update_option( 'i4t3_gnrl_options' , $options );
49
- } else {
50
- // get old values if exists
51
- $old = get_option( 'i4t3_gnrl_options' );
52
- // loop through each new options
53
- // to check old value exist for each items.
54
- foreach ( $options as $key => $value ) {
55
- if ( array_key_exists( $key, $old ) ) {
56
- // if old value exists, update that
57
- $options[ $key ] = $old[ $key ];
58
- }
59
- }
60
- // update the old options
61
- update_option( 'i4t3_gnrl_options', $options );
62
- }
63
- // get plugin db version
64
- $db_version = get_option('i4t3_db_version');
65
-
66
- if ( ! $db_version || ( I4T3_DB_VERSION != $db_version ) ) {
67
-
68
- global $wpdb;
69
-
70
- $table = $wpdb->prefix . "404_to_301";
71
-
72
- $sql = "CREATE TABLE $table (
73
- id BIGINT NOT NULL AUTO_INCREMENT,
74
- date DATETIME NOT NULL,
75
- url VARCHAR(512) NOT NULL,
76
- ref VARCHAR(512) NOT NULL default '',
77
- ip VARCHAR(40) NOT NULL default '',
78
- ua VARCHAR(512) NOT NULL default '',
79
- redirect VARCHAR(512) NULL default '',
80
- PRIMARY KEY (id)
81
- );";
82
-
83
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
84
- // to be safe on db upgrades
85
- dbDelta($sql);
86
- // update db version
87
- update_option( 'i4t3_db_version', I4T3_DB_VERSION );
88
- }
89
- }
90
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-404-to-301-i18n.php DELETED
@@ -1,39 +0,0 @@
1
- <?php
2
-
3
- // If this file is called directly, abort.
4
- if ( ! defined( 'WPINC' ) ) {
5
- die( 'Damn it.! Dude you are looking for what?' );
6
- }
7
-
8
- /**
9
- * Define the internationalization functionality
10
- *
11
- * Loads and defines the internationalization files for this plugin
12
- * so that it is ready for translation.
13
- *
14
- * @category Core
15
- * @package I4T3
16
- * @subpackage Internationalization
17
- * @author Joel James <me@joelsays.com>
18
- * @license http://www.gnu.org/licenses/ GNU General Public License
19
- * @link https://thefoxe.com/products/404-to-301
20
- */
21
- class _404_To_301_i18n {
22
-
23
- /**
24
- * Load the plugin text domain for translation.
25
- *
26
- * @since 2.0.7
27
- * @access public
28
- *
29
- * @return void
30
- */
31
- public function load_textdomain() {
32
-
33
- load_plugin_textdomain(
34
- I4T3_DOMAIN,
35
- false,
36
- dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
37
- );
38
- }
39
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-404-to-301-loader.php DELETED
@@ -1,143 +0,0 @@
1
- <?php
2
-
3
- // If this file is called directly, abort.
4
- if ( ! defined( 'WPINC' ) ) {
5
- die( 'Damn it.! Dude you are looking for what?' );
6
- }
7
-
8
- /**
9
- * Register all actions and filters for the plugin.
10
- *
11
- * Maintain a list of all hooks that are registered throughout
12
- * the plugin, and register them with the WordPress API. Call the
13
- * run function to execute the list of actions and filters.
14
- *
15
- * @category Core
16
- * @package I4T3
17
- * @subpackage Loader
18
- * @author Joel James <me@joelsays.com>
19
- * @license http://www.gnu.org/licenses/ GNU General Public License
20
- * @link https://thefoxe.com/products/404-to-301
21
- */
22
- class _404_To_301_Loader {
23
-
24
- /**
25
- * The array of actions registered with WordPress.
26
- *
27
- * @since 2.0.0
28
- * @access protected
29
- * @var array $actions The actions registered with WordPress to fire when the plugin loads.
30
- */
31
- protected $actions;
32
-
33
- /**
34
- * The array of filters registered with WordPress.
35
- *
36
- * @since 2.0.0
37
- * @access protected
38
- * @var array $filters The filters registered with WordPress to fire when the plugin loads.
39
- */
40
- protected $filters;
41
-
42
- /**
43
- * Initialize the collections used to maintain the actions and filters.
44
- *
45
- * @since 2.0.0
46
- * @access public
47
- *
48
- * @return void
49
- */
50
- public function __construct() {
51
-
52
- // actions array
53
- $this->actions = array();
54
- // filters array
55
- $this->filters = array();
56
- }
57
-
58
- /**
59
- * Add a new action to the collection to be registered with WordPress.
60
- *
61
- * @param string $hook The name of the WordPress action that is being registered.
62
- * @param object $component A reference to the instance of the object on which the action is defined.
63
- * @param string $callback The name of the function definition on the $component.
64
- * @param int $priority The priority at which the function should be fired.
65
- * @param int $accepted_args The number of arguments that should be passed to the $callback.
66
- *
67
- * @since 2.0.0
68
- * @access public
69
- *
70
- * @return void
71
- */
72
- public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
73
-
74
- $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
75
- }
76
-
77
- /**
78
- * Add a new filter to the collection to be registered with WordPress.
79
- *
80
- * @param string $hook The name of the WordPress filter that is being registered.
81
- * @param object $component A reference to the instance of the object on which the filter is defined.
82
- * @param string $callback The name of the function definition on the $component.
83
- * @param int $priority The priority at which the function should be fired.
84
- * @param int $accepted_args The number of arguments that should be passed to the $callback.
85
- *
86
- * @since 2.0.0
87
- * @access public
88
- *
89
- * @return void
90
- */
91
- public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
92
-
93
- $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
94
- }
95
-
96
- /**
97
- * A utility function that is used to register the actions and hooks into a single
98
- * collection.
99
- *
100
- * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
101
- * @param string $hook The name of the WordPress filter that is being registered.
102
- * @param object $component A reference to the instance of the object on which the filter is defined.
103
- * @param string $callback The name of the function definition on the $component.
104
- * @param int $priority The priority at which the function should be fired.
105
- * @param int $accepted_args The number of arguments that should be passed to the $callback.
106
- *
107
- * @since 2.0.0
108
- * @access private
109
- *
110
- * @return array The collection of actions and filters registered with WordPress.
111
- */
112
- private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
113
-
114
- $hooks[] = array(
115
- 'hook' => $hook,
116
- 'component' => $component,
117
- 'callback' => $callback,
118
- 'priority' => $priority,
119
- 'accepted_args' => $accepted_args
120
- );
121
-
122
- return $hooks;
123
- }
124
-
125
- /**
126
- * Register the filters and actions with WordPress.
127
- *
128
- * @since 2.0.0
129
- * @access public
130
- *
131
- * @return void
132
- */
133
- public function run() {
134
-
135
- foreach( $this->filters as $hook ) {
136
- add_filter( $hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args'] );
137
- }
138
-
139
- foreach( $this->actions as $hook ) {
140
- add_action( $hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args'] );
141
- }
142
- }
143
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-404-to-301.php DELETED
@@ -1,178 +0,0 @@
1
- <?php
2
-
3
- // If this file is called directly, abort.
4
- if ( ! defined( 'WPINC' ) ) {
5
- die( 'Damn it.! Dude you are looking for what?' );
6
- }
7
-
8
- /**
9
- * The file that defines the core plugin class
10
- *
11
- * A class definition that includes attributes and functions used across both the
12
- * public-facing side of the site and the dashboard.
13
- * Also maintains the unique identifier of this plugin as well as the current
14
- * version of the plugin.
15
- *
16
- * @category Core
17
- * @package I4T3
18
- * @subpackage Core
19
- * @author Joel James <me@joelsays.com>
20
- * @license http://www.gnu.org/licenses/ GNU General Public License
21
- * @link https://thefoxe.com/products/404-to-301
22
- */
23
- class _404_To_301 {
24
-
25
- /**
26
- * The loader that's responsible for maintaining and registering all hooks that power
27
- * the plugin.
28
- *
29
- * @since 2.0.0
30
- * @access protected
31
- * @var _404_To_301_Loader $loader Maintains and registers all hooks for the plugin.
32
- */
33
- protected $loader;
34
-
35
- /**
36
- * Define the core functionality of the plugin.
37
- *
38
- * Set the plugin name, plugin version and the plugin table name that can be used throughout the plugin.
39
- * Load the dependencies, define the locale, and set the hooks for the Dashboard and
40
- * the public-facing side of the site.
41
- *
42
- * @since 1.0.0
43
- * @access public
44
- *
45
- * @return void
46
- */
47
- public function __construct() {
48
-
49
- $this->load_dependencies();
50
- $this->set_locale();
51
- $this->define_admin_hooks();
52
- $this->define_public_hooks();
53
- }
54
-
55
- /**
56
- * Load the required dependencies for this plugin.
57
- *
58
- * Include the following files that make up the plugin:
59
- *
60
- * - _404_To_301_Loader. Orchestrates the hooks of the plugin.
61
- * - _404_To_301_Admin. Defines all hooks for the dashboard.
62
- * - _404_To_301_Public. Defines all hooks for the public functions.
63
- * - _404_To_301_Logs. Defines all hooks for listing logs.
64
- *
65
- * Create an instance of the loader which will be used to register the hooks
66
- * with WordPress.
67
- *
68
- * @since 2.0.0
69
- * @access private
70
- *
71
- * @return void
72
- */
73
- private function load_dependencies() {
74
-
75
- include_once I4T3_PLUGIN_DIR . '/includes/class-404-to-301-loader.php';
76
- include_once I4T3_PLUGIN_DIR . '/includes/class-404-to-301-i18n.php';
77
- include_once I4T3_PLUGIN_DIR . '/admin/class-404-to-301-admin.php';
78
- include_once I4T3_PLUGIN_DIR . '/admin/class-404-to-301-logs.php';
79
- include_once I4T3_PLUGIN_DIR . '/public/class-404-to-301-public.php';
80
-
81
- $this->loader = new _404_To_301_Loader();
82
- }
83
-
84
- /**
85
- * Define the locale for this plugin for internationalization.
86
- *
87
- * Uses the Plugin_Name_i18n class in order to set the domain and to register the hook
88
- * with WordPress.
89
- *
90
- * @since 1.0.0
91
- * @access private
92
- *
93
- * @return void
94
- */
95
- private function set_locale() {
96
-
97
- $plugin_i18n = new _404_To_301_i18n();
98
-
99
- $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_textdomain');
100
- }
101
-
102
- /**
103
- * Register all of the hooks related to the dashboard functionality
104
- * of the plugin.
105
- *
106
- * This function is used to register all styles and JavaScripts for admin side.
107
- *
108
- * @since 2.0.0
109
- * @access private
110
- * @uses add_action()
111
- * @uses add_filter()
112
- *
113
- * @return void
114
- */
115
- private function define_admin_hooks() {
116
-
117
- $plugin_admin = new _404_To_301_Admin();
118
-
119
- $this->loader->add_filter('admin_init', $plugin_admin, 'add_buffer');
120
- $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
121
- $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
122
- $this->loader->add_action('admin_menu', $plugin_admin, 'i4t3_create_404_to_301_menu');
123
- $this->loader->add_action('admin_menu', $plugin_admin, 'i4t3_rename_plugin_menu');
124
- $this->loader->add_action('admin_init', $plugin_admin, 'i4t3_options_register');
125
- $this->loader->add_filter('admin_footer_text', $plugin_admin, 'i4t3_dashboard_footer');
126
- $this->loader->add_filter('plugin_action_links', $plugin_admin, 'i4t3_plugin_action_links', 10, 5);
127
- $this->loader->add_action('plugins_loaded', $plugin_admin, 'i4t3_upgrade_if_new');
128
- $this->loader->add_filter('i4t3_notify_admin_email_address', $plugin_admin, 'i4t3_change_notify_email');
129
- $this->loader->add_filter('set-screen-option', $plugin_admin, 'set_screen', 10, 3);
130
- $this->loader->add_action('admin_footer', $plugin_admin, 'add_thickbox', 100);
131
- $this->loader->add_action('admin_footer', $plugin_admin, 'get_redirect_content');
132
- $this->loader->add_action('wp_ajax_i4t3_redirect_thickbox', $plugin_admin, 'open_custom_redirect');
133
- $this->loader->add_action('wp_ajax_i4t3_redirect_form', $plugin_admin, 'save_custom_redirect');
134
- }
135
-
136
- /**
137
- * Register all of the hooks related to handle 404 actions of the plugin.
138
- *
139
- * @since 2.0.0
140
- * @access private
141
- * @uses add_filter()
142
- *
143
- * @return void
144
- */
145
- private function define_public_hooks() {
146
-
147
- $plugin_public = new _404_To_301_Public();
148
-
149
- // Main Hook to perform redirections on 404s
150
- $this->loader->add_filter('template_redirect', $plugin_public, 'i4t3_redirect_404');
151
- }
152
-
153
- /**
154
- * Run the loader to execute all of the hooks with WordPress.
155
- *
156
- * @since 2.0.0
157
- * @access public
158
- *
159
- * @return void
160
- */
161
- public function run() {
162
-
163
- $this->loader->run();
164
- }
165
-
166
- /**
167
- * The reference to the class that orchestrates the hooks with the plugin.
168
- *
169
- * @since 2.0.0
170
- * @access public
171
- *
172
- * @return i4t3_Loader Orchestrates the hooks of the plugin.
173
- */
174
- public function get_loader() {
175
-
176
- return $this->loader;
177
- }
178
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-jj-404-to-301.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * Main 404 to 301 plugin class
8
+ *
9
+ * A class definition that includes attributes and functions used across both the
10
+ * public-facing side of the site and the dashboard.
11
+ * This class creates a one and only instance of 404 to 301 plugin.
12
+ *
13
+ * @category Core
14
+ * @package JJ4T3
15
+ * @subpackage Core
16
+ * @author Joel James <mail@cjoel.com>
17
+ * @license http://www.gnu.org/licenses/ GNU General Public License
18
+ * @link https://duckdev.com/products/404-to-301/
19
+ */
20
+ final class JJ_404_to_301 {
21
+
22
+ /**
23
+ * Main 404 to 301 class instance.
24
+ *
25
+ * @var JJ_404_to_301
26
+ * @since 3.0.0
27
+ * @access private
28
+ */
29
+ private static $instance;
30
+
31
+ /**
32
+ * Main JJ_404_to_301 Instance.
33
+ *
34
+ * Insures that only one instance of JJ_404_to_301 exists in memory
35
+ * at any one time.
36
+ * Also prevents needing to define globals all over the place.
37
+ *
38
+ * @since 3.0.0
39
+ * @access public
40
+ * @staticvar array $instance
41
+ *
42
+ * @return JJ_404_to_301|object
43
+ */
44
+ public static function instance() {
45
+
46
+ if ( ! isset( self::$instance ) && ! ( self::$instance instanceof JJ_404_to_301 ) ) {
47
+
48
+ // Main plugin class.
49
+ self::$instance = new JJ_404_to_301();
50
+
51
+ // Include required files.
52
+ self::$instance->includes();
53
+ // Run activation actions.
54
+ self::$instance->activate();
55
+ // Load translation support.
56
+ self::$instance->locale();
57
+
58
+ // Required only when admin.
59
+ if ( is_admin() ) {
60
+ // Init admin class..
61
+ self::$instance->admin = new JJ4T3_Admin();
62
+ }
63
+
64
+ // Required only when not admin.
65
+ if ( ! is_admin() ) {
66
+ // Init 404 class.
67
+ self::$instance->actions = new JJ4T3_404_Actions();
68
+ }
69
+ }
70
+
71
+ return self::$instance;
72
+ }
73
+
74
+ /**
75
+ * Include plugin's required files.
76
+ *
77
+ * Load all required files for this plugin's
78
+ * perfect functionality.
79
+ * We will handle the conditional checks inside
80
+ * these files.
81
+ *
82
+ * @since 3.0.0
83
+ * @access private
84
+ *
85
+ * @return void
86
+ */
87
+ private function includes() {
88
+
89
+ include_once JJ4T3_DIR . 'includes/functions/jj4t3-general-functions.php';
90
+ include_once JJ4T3_DIR . 'includes/class-jj4t3-i18n.php';
91
+ include_once JJ4T3_DIR . 'includes/class-jj4t3-activator-deactivator-uninstaller.php';
92
+
93
+ // Required only when not admin.
94
+ if ( ! is_admin() ) {
95
+ include_once JJ4T3_DIR . 'includes/public/class-jj4t3-404-data.php';
96
+ include_once JJ4T3_DIR . 'includes/public/class-jj4t3-404-email.php';
97
+ include_once JJ4T3_DIR . 'includes/public/class-jj4t3-404-logging.php';
98
+ include_once JJ4T3_DIR . 'includes/public/class-jj4t3-404-actions.php';
99
+ }
100
+
101
+ // Required only when backend.
102
+ if ( is_admin() ) {
103
+ include_once JJ4T3_DIR . 'includes/admin/class-jj4t3-admin.php';
104
+ include_once JJ4T3_DIR . 'includes/admin/class-jj4t3-log-listing.php';
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Plugin activation actions.
110
+ *
111
+ * Actions to perform during plugin activation.
112
+ * We will be registering default options in this function.
113
+ *
114
+ * @uses register_activation_hook() To register activation hook.
115
+ * @since 3.0.0
116
+ * @access private
117
+ *
118
+ * @return void
119
+ */
120
+ private function activate() {
121
+
122
+ register_activation_hook( JJ4T3_BASE_FILE, array( 'JJ4T3_Activator_Deactivator_Uninstaller', 'activate' ) );
123
+ }
124
+
125
+ /**
126
+ * Initialize internationalization class.
127
+ *
128
+ * Load text domain for the internationalization functionality.
129
+ *
130
+ * @since 3.0.0
131
+ * @access private
132
+ *
133
+ * @return object Locale class object.
134
+ */
135
+ private function locale() {
136
+
137
+ return new JJ4T3_I18n();
138
+ }
139
+ }
includes/class-jj4t3-activator-deactivator-uninstaller.php ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * Fired during plugin activation.
8
+ *
9
+ * This class defines all code necessary to run during the plugin's activation.
10
+ * We will register our default settings here if not exists already.
11
+ *
12
+ * @category Core
13
+ * @package JJ4T3
14
+ * @subpackage Activator
15
+ * @author Joel James <mail@cjoel.com>
16
+ * @license http://www.gnu.org/licenses/ GNU General Public License
17
+ * @link https://duckdev.com/products/404-to-301/
18
+ */
19
+ class JJ4T3_Activator_Deactivator_Uninstaller {
20
+
21
+ /**
22
+ * Function to run during activation
23
+ *
24
+ * We register default options to the WordPress if not exists already.
25
+ * We will keep the old values if already exist.
26
+ *
27
+ * @since 3.0.0
28
+ * @access public
29
+ *
30
+ * @return void
31
+ */
32
+ public static function activate() {
33
+
34
+ // Default settings for our plugin.
35
+ $options = array(
36
+ 'redirect_type' => '301',
37
+ 'redirect_link' => home_url(),
38
+ 'redirect_log' => 1,
39
+ 'redirect_to' => 'link',
40
+ 'redirect_page' => '',
41
+ 'email_notify' => 0,
42
+ 'email_notify_address' => get_option( 'admin_email' ),
43
+ 'exclude_paths' => '/wp-content',
44
+ );
45
+
46
+ // Get existing options if exists.
47
+ $existing = get_option( 'i4t3_gnrl_options' );
48
+ // Check if valid dcl settings exist.
49
+ if ( $existing && is_array( $existing ) ) {
50
+ foreach ( $options as $key => $value ) {
51
+ if ( array_key_exists( $key, $existing ) ) {
52
+ $options[ $key ] = $existing[ $key ];
53
+ }
54
+ }
55
+ }
56
+
57
+ // Update/create our settings.
58
+ // We are using older prefix for our option names.
59
+ update_option( 'i4t3_gnrl_options', $options );
60
+
61
+ // Manage error log table.
62
+ self::log_table();
63
+ }
64
+
65
+ /**
66
+ * Create or update error logs table in database.
67
+ *
68
+ * Define our custom table schema and create the table if not exists.
69
+ * If already exists and changes found, update the table.
70
+ * dbDelta() will properly take care of these tasks safely.
71
+ *
72
+ * @global object $wpdb WordPress database helper object.
73
+ * @uses dbDelta() For safe db upgrades.
74
+ *
75
+ * @return void
76
+ */
77
+ private static function log_table() {
78
+
79
+ // Get db version number.
80
+ $db = get_option( 'i4t3_db_version' );
81
+
82
+ // If table is upto date, do nothing.
83
+ if ( defined( JJ4T3_DB_VERSION ) && $db === JJ4T3_DB_VERSION ) {
84
+ return;
85
+ }
86
+
87
+ global $wpdb;
88
+ // Out custom table name.
89
+ $table = $wpdb->prefix . "404_to_301";
90
+
91
+ // Define the table schema query.
92
+ $query = "CREATE TABLE $table (
93
+ id BIGINT NOT NULL AUTO_INCREMENT,
94
+ date DATETIME NOT NULL,
95
+ url VARCHAR(512) NOT NULL,
96
+ ref VARCHAR(512) NOT NULL default '',
97
+ ip VARCHAR(40) NOT NULL default '',
98
+ ua VARCHAR(512) NOT NULL default '',
99
+ redirect VARCHAR(512) NULL default '',
100
+ options LONGTEXT,
101
+ status BIGINT NOT NULL default 1,
102
+ PRIMARY KEY (id)
103
+ );";
104
+
105
+ // Handle DB upgrades in proper WordPress way.
106
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
107
+
108
+ // Update or create table in database.
109
+ dbDelta( $query );
110
+
111
+ // Update the db version number.
112
+ update_option( 'i4t3_db_version', JJ4T3_DB_VERSION );
113
+ }
114
+
115
+ /**
116
+ * Fired during plugin uninstall.
117
+ *
118
+ * We need to clear database by deleting all custom options
119
+ * and our custom logs table.
120
+ *
121
+ * @since 3.0.0
122
+ *
123
+ * @return void
124
+ */
125
+ public static function uninstall() {
126
+
127
+ // Plugin option names.
128
+ $options = array(
129
+ 'i4t3_gnrl_options',
130
+ 'i4t3_activated_time',
131
+ 'i4t3_db_version',
132
+ 'i4t3_version_no',
133
+ );
134
+
135
+ // Loop through each options.
136
+ foreach ( $options as $option ) {
137
+ delete_option( $option );
138
+ }
139
+
140
+ global $wpdb;
141
+
142
+ // Drop our custom table.
143
+ $wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "404_to_301" );
144
+ }
145
+ }
includes/class-jj4t3-i18n.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * Define the internationalization functionality
8
+ *
9
+ * Loads and defines the internationalization files for this plugin
10
+ * so that it is ready for translation.
11
+ *
12
+ * @category Core
13
+ * @package JJ4T3
14
+ * @subpackage Internationalization
15
+ * @author Joel James <mail@cjoel.com>
16
+ * @license http://www.gnu.org/licenses/ GNU General Public License
17
+ * @link https://duckdev.com/products/404-to-301/
18
+ */
19
+ class JJ4T3_i18n {
20
+
21
+ /**
22
+ * Initialize the class.
23
+ *
24
+ * @since 3.0.0
25
+ * @access private
26
+ */
27
+ public function __construct() {
28
+
29
+ add_action( 'plugins_loaded', array( $this, 'textdomain' ) );
30
+ }
31
+
32
+ /**
33
+ * Load the plugin text domain for translation.
34
+ *
35
+ * @since 3.0.0
36
+ * @access public
37
+ */
38
+ public function textdomain() {
39
+
40
+ load_plugin_textdomain( JJ4T3_DOMAIN, false, JJ4T3_DIR . '/languages/' );
41
+ }
42
+
43
+ }
{admin/partials → includes/functions}/index.php RENAMED
File without changes
includes/functions/jj4t3-general-functions.php ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * Get plugin setting value.
8
+ *
9
+ * Handle the exceptional case properly
10
+ * and return false.
11
+ *
12
+ * @param mixed $option Option name.
13
+ * @param mixed $default Default value if not exist.
14
+ *
15
+ * @since 3.0.0
16
+ * @access public
17
+ *
18
+ * @return string|array
19
+ */
20
+ function jj4t3_get_option( $option = false, $default = false ) {
21
+
22
+ if ( ! $option ) {
23
+ return $default;
24
+ }
25
+
26
+ // Get our plugin settings value.
27
+ $settings = (array) get_option( 'i4t3_gnrl_options', array() );
28
+
29
+ // Return false, if not exist.
30
+ if ( empty( $settings[ $option ] ) ) {
31
+ return $default;
32
+ }
33
+
34
+ return $settings[ $option ];
35
+ }
36
+
37
+ /**
38
+ * Update a single setting value.
39
+ *
40
+ * This helper function is used to update a single
41
+ * setting value of our plugin settings array.
42
+ * Default WordPress update_option() function can
43
+ * update the the array only.
44
+ *
45
+ * @param string $option Option name.
46
+ * @param mixed $value Value to update.
47
+ *
48
+ * @since 3.0.0
49
+ * @access public
50
+ *
51
+ * @return void
52
+ */
53
+ function jj4t3_update_option( $option, $value = '' ) {
54
+
55
+ $settings = (array) get_option( 'i4t3_gnrl_options', array() );
56
+
57
+ $settings[ $option ] = $value;
58
+
59
+ update_option( 'i4t3_gnrl_options', $settings );
60
+ }
61
+
62
+ /**
63
+ * Check if the redirect for 404 enabled.
64
+ *
65
+ * Check if the user selected "No Redirect" option
66
+ * for redirect.
67
+ * Registering filter - "jj4t3_redirect_enabled".
68
+ *
69
+ * @since 3.0.0
70
+ * @access public
71
+ *
72
+ * @return boolean
73
+ */
74
+ function jj4t3_redirect_enabled() {
75
+
76
+ // Get redirect to option value.
77
+ $enabled = jj4t3_redirect_to();
78
+
79
+ /**
80
+ * Filter hook to alter redirect option.
81
+ *
82
+ * Return boolean to enable/disable redirect.
83
+ *
84
+ * @since 2.0.0
85
+ */
86
+ return (bool) apply_filters( 'jj4t3_redirect_enabled', $enabled );
87
+ }
88
+
89
+ /**
90
+ * Check if the email notification is enabled.
91
+ *
92
+ * Registering filter - "jj4t3_email_notify_enabled".
93
+ *
94
+ * @since 3.0.0
95
+ * @access public
96
+ *
97
+ * @return boolean
98
+ */
99
+ function jj4t3_email_notify_enabled() {
100
+
101
+ // Get email notification option.
102
+ $enabled = jj4t3_get_option( 'email_notify' );
103
+
104
+ /**
105
+ * Filter hook to alter email notification option.
106
+ *
107
+ * Return boolean to enable/disable. For whatever value you return
108
+ * it will consider it's boolean only.
109
+ *
110
+ * @since 2.0.0
111
+ */
112
+ return (bool) apply_filters( 'jj4t3_email_notify_enabled', $enabled );
113
+ }
114
+
115
+ /**
116
+ * Check if the error logging is enabled.
117
+ *
118
+ * Registering filter - "jj4t3_log_enabled".
119
+ *
120
+ * @since 3.0.0
121
+ * @access public
122
+ *
123
+ * @return boolean
124
+ */
125
+ function jj4t3_log_enabled() {
126
+
127
+ // Get error logging option.
128
+ $enabled = jj4t3_get_option( 'redirect_log' );
129
+
130
+ /**
131
+ * Filter hook to alter error logging.
132
+ *
133
+ * Return boolean to enable/disable logging.For whatever value you return
134
+ * it will consider it's boolean only.
135
+ *
136
+ * @since 2.0.0
137
+ */
138
+ return (bool) apply_filters( 'jj4t3_log_enabled', $enabled );
139
+ }
140
+
141
+ /**
142
+ * Get enabled redirect to.
143
+ *
144
+ * Retured type of redirect target.
145
+ * If redirect is not enabled, return false.
146
+ * If unknown value is given return false.
147
+ *
148
+ * @since 3.0.0
149
+ * @access public
150
+ *
151
+ * @return string|boolean
152
+ */
153
+ function jj4t3_redirect_to() {
154
+
155
+ /**
156
+ * Filter hook to get redirect to option value.
157
+ *
158
+ * Accepts only 2 values - page, link.
159
+ * If any other value is returned, it will considered
160
+ * as the redirect is disabled.
161
+ *
162
+ * @since 2.0.0
163
+ */
164
+ $to = apply_filters( 'jj4t3_redirect_to', jj4t3_get_option( 'redirect_to' ) );
165
+
166
+ // Verify that only allowed values accepted.
167
+ if ( in_array( $to, array( 'page', 'link' ) ) ) {
168
+ return $to;
169
+ }
170
+
171
+ return false;
172
+ }
173
+
174
+ /**
175
+ * Get redirect type.
176
+ *
177
+ * This function is used to get the redirect
178
+ * status code selected by the user.
179
+ * Registering filter - jj4t3_redirect_type
180
+ * to alter redirect status code.
181
+ *
182
+ * @since 3.0.0
183
+ * @access private
184
+ *
185
+ * @return int Redirect status code.
186
+ */
187
+ function jj4t3_redirect_type() {
188
+
189
+ $type = (int) jj4t3_get_option( 'redirect_type' );
190
+
191
+ /**
192
+ * Filter to modify currently set redirect type.
193
+ *
194
+ * Return only valid HTTP status codes.
195
+ * If you are returning custom status codes other than the default
196
+ * values, please make sure that you have added that to "jj4t3_redirect_statuses"
197
+ * filter first. Otherwise it will be ignored.
198
+ *
199
+ * @since 2.0.0
200
+ */
201
+ $status = apply_filters( 'jj4t3_redirect_type', $type );
202
+
203
+ // Verify that redirect status is allowed.
204
+ if ( in_array( $status, array_keys( jj4t3_redirect_statuses() ) ) ) {
205
+ return $status;
206
+ }
207
+
208
+ return 301;
209
+ }
210
+
211
+ /**
212
+ * Check if the current user is real human.
213
+ *
214
+ * This function is used to check the current
215
+ * visitor is bot or real human based on the
216
+ * browser.
217
+ * If it is a bot, browser variables may not
218
+ * be there.
219
+ * DO NOT relay on this function for serious actions
220
+ * as it may be wrong in some cases.
221
+ *
222
+ * @global bool $is_gecko
223
+ * @global bool $is_opera
224
+ * @global bool $is_safari
225
+ * @global bool $is_chrome
226
+ * @global bool $is_IE
227
+ * @global bool $is_edge
228
+ * @global bool $is_NS4
229
+ * @global bool $is_lynx
230
+ *
231
+ * @since 3.0.0
232
+ * @access private
233
+ *
234
+ * @return boolean
235
+ */
236
+ function jj4t3_is_human() {
237
+
238
+ // If mobile OS is found it real user.
239
+ if ( wp_is_mobile() ) {
240
+
241
+ /**
242
+ * Filter to modify human vs bot checking.
243
+ *
244
+ * If you want to add additional conditions to the human checking
245
+ * function, use this filter and return a boolean.
246
+ * For whatever value you return it will consider it's boolean only.
247
+ *
248
+ * @param boolean is real human.
249
+ * @param string device type.
250
+ *
251
+ * @since 3.0.0
252
+ */
253
+ return (bool) apply_filters( 'jj4t3_is_human', true, 'mobile' );
254
+ }
255
+
256
+ // WordPress global variables for browsers.
257
+ global $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge, $is_NS4, $is_lynx;
258
+
259
+ $human = ( $is_gecko || $is_opera || $is_safari || $is_chrome || $is_IE || $is_edge || $is_NS4 || $is_lynx );
260
+
261
+ /**
262
+ * This filter is documented above.
263
+ */
264
+ return (bool) apply_filters( 'jj4t3_is_human', $human, 'desktop' );
265
+ }
266
+
267
+ /**
268
+ * Set allowed status codes to redirect.
269
+ *
270
+ * Currently we are using only 3 status codes.
271
+ * You can modify this to use more status using the filter.
272
+ * Registering filter - "jj4t3_redirect_statuses".
273
+ *
274
+ * @link https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html HTTP status codes.
275
+ * @since 3.0.0
276
+ * @access private
277
+ *
278
+ * @return array Allowed HTTP status codes.
279
+ */
280
+ function jj4t3_redirect_statuses() {
281
+
282
+ $statuses = array(
283
+ 301 => __( '301 Redirect (SEO)', JJ4T3_DOMAIN ),
284
+ 302 => __( '302 Redirect', JJ4T3_DOMAIN ),
285
+ 307 => __( '307 Redirect', JJ4T3_DOMAIN ),
286
+ );
287
+
288
+ /**
289
+ * Filter for allowed status codes.
290
+ *
291
+ * If you want to add additional HTTP status codes
292
+ * for redirect, please use this filter and add to
293
+ * the statuses array.
294
+ * DO NOT remove default values (301, 302 and 307) from
295
+ * the array.
296
+ *
297
+ * @since 3.0.0
298
+ */
299
+ return (array) apply_filters( 'jj4t3_redirect_statuses', $statuses );
300
+ }
301
+
302
+ /**
303
+ * Available columns in error logs table.
304
+ *
305
+ * This columns are being used few times. Use this to avoid
306
+ * unwanted names.
307
+ * Registering filter - "jj4t3_redirect_statuses".
308
+ *
309
+ * @since 3.0.0
310
+ * @access private
311
+ *
312
+ * @return array Allowed HTTP status codes.
313
+ */
314
+ function jj4t3_log_columns() {
315
+
316
+ $columns = array(
317
+ 'date' => __( 'Date', JJ4T3_DOMAIN ),
318
+ 'url' => __( '404 Path', JJ4T3_DOMAIN ),
319
+ 'ref' => __( 'From', JJ4T3_DOMAIN ),
320
+ 'ip' => __( 'IP Address', JJ4T3_DOMAIN ),
321
+ 'ua' => __( 'User Agent', JJ4T3_DOMAIN ),
322
+ 'redirect' => __( 'Redirect', JJ4T3_DOMAIN ),
323
+ );
324
+
325
+ /**
326
+ * Filter for available columns.
327
+ *
328
+ * These are the availble column names in 404
329
+ * error logs.
330
+ * Registering filter - "jj4t3_log_columns".
331
+ *
332
+ * @param array columns name and slug.
333
+ *
334
+ * @since 3.0.0
335
+ */
336
+ return (array) apply_filters( 'jj4t3_log_columns', $columns );
337
+ }
338
+
339
+ /**
340
+ * Retrive value from $_REQUEST.
341
+ *
342
+ * Helper function to retrive data from $_REQUEST
343
+ * We can use this function to get values from request
344
+ * and get a default value if the current key does not exist
345
+ * or empty.
346
+ * Output will be trimmed.
347
+ *
348
+ * @param string $key Key to get from request.
349
+ * @param mixed $default Default value.
350
+ *
351
+ * @since 3.0.0
352
+ * @access public
353
+ *
354
+ * @return array|string
355
+ */
356
+ function jj4t3_from_request( $key = '', $default = '' ) {
357
+
358
+ // Return default value if key is not given.
359
+ if ( empty( $key ) || ! is_string( $key ) ) {
360
+ return $default;
361
+ }
362
+
363
+ // Return default value if key not set.
364
+ if ( ! isset( $_REQUEST[ $key ] ) ) {
365
+ return $default;
366
+ }
367
+
368
+ // Trim output.
369
+ if ( is_string( $_REQUEST[ $key ] ) ) {
370
+ return trim( $_REQUEST[ $key ] );
371
+ } elseif ( is_array( $_REQUEST[ $key ] ) ) {
372
+ return array_map( 'trim', $_REQUEST[ $key ] );
373
+ }
374
+
375
+ return $default;
376
+ }
includes/public/class-jj4t3-404-actions.php ADDED
@@ -0,0 +1,445 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * The main 404 actions class.
8
+ *
9
+ * This class contains all functions performed during
10
+ * each 404 errors on the site.
11
+ *
12
+ * @category Core
13
+ * @package JJ4T3
14
+ * @subpackage Actions
15
+ * @author Joel James <mail@cjoel.com>
16
+ * @license http://www.gnu.org/licenses/ GNU General Public License
17
+ * @link https://duckdev.com/products/404-to-301/
18
+ */
19
+ class JJ4T3_404_Actions extends JJ4T3_404_Data {
20
+
21
+ /**
22
+ * Redirect url for current 404.
23
+ *
24
+ * @var string
25
+ * @access public
26
+ *
27
+ */
28
+ public $redirect_url = '';
29
+
30
+ /**
31
+ * Custom redirect url for current 404.
32
+ *
33
+ * @var string
34
+ * @access public
35
+ *
36
+ */
37
+ public $custom_redirect_url = '';
38
+
39
+ /**
40
+ * Redirect status code for currenr 404.
41
+ *
42
+ * @var string
43
+ * @access public
44
+ * @since 3.0.0
45
+ */
46
+ public $redirect_type = 301;
47
+
48
+ /**
49
+ * Is redirect enabled for current 404.
50
+ *
51
+ * @var boolean
52
+ * @access public
53
+ * @since 3.0.0
54
+ */
55
+ public $redirect_enabled = false;
56
+
57
+ /**
58
+ * Is logging enabled for current 404.
59
+ *
60
+ * @var boolean
61
+ * @access public
62
+ * @since 3.0.0
63
+ */
64
+ public $log_enabled = false;
65
+
66
+ /**
67
+ * Is email alert enabled for current 404.
68
+ *
69
+ * @var boolean
70
+ * @access public
71
+ * @since 3.0.0
72
+ */
73
+ public $alert_enabled = false;
74
+
75
+ /**
76
+ * Is common check passed for current 404.
77
+ *
78
+ * @var boolean
79
+ * @access public
80
+ * @since 3.0.0
81
+ */
82
+ public $common_check_passed = false;
83
+
84
+ /**
85
+ * Initialize the class and parent class.
86
+ *
87
+ * @since 3.0.0
88
+ * @access public
89
+ */
90
+ public function __construct() {
91
+
92
+ parent::__construct();
93
+
94
+ // Main filter that handles 404.
95
+ add_filter( 'wp', array( $this, 'handle_404' ) );
96
+ }
97
+
98
+ /**
99
+ * Perform 404 actions.
100
+ *
101
+ * Perform required actions on each 404 pages being visited.
102
+ * Log error details, Alert via email, Redirect.
103
+ *
104
+ * @since 3.0.0
105
+ * @access public
106
+ *
107
+ * @return void
108
+ */
109
+ public function handle_404() {
110
+
111
+ // Only if we can.
112
+ if ( ! is_404() || is_admin() ) {
113
+ return;
114
+ }
115
+
116
+ // Let's try folks.
117
+ try {
118
+
119
+ // Set options for current 404.
120
+ $this->set_options();
121
+
122
+ // Log errotr details to database.
123
+ $this->log_error();
124
+
125
+ // Send email alert about the error.
126
+ $this->email_alert();
127
+
128
+ // Redirect the user.
129
+ $this->redirect();
130
+
131
+ } catch ( Exception $ex ) {
132
+ // Stay cool.
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Log details of error to the database.
138
+ *
139
+ * @since 3.0.0
140
+ * @access public
141
+ *
142
+ * @return void
143
+ */
144
+ public function log_error() {
145
+
146
+ // Only if we can.
147
+ if ( ! $this->log_enabled ) {
148
+ return;
149
+ }
150
+
151
+ // Error logging class.
152
+ $logging = new JJ4T3_404_Logging( $this );
153
+ $logging->log_error();
154
+ }
155
+
156
+ /**
157
+ * Send email about the error.
158
+ *
159
+ * @since 3.0.0
160
+ * @access public
161
+ *
162
+ * @return void
163
+ */
164
+ public function email_alert() {
165
+
166
+ /**
167
+ * Filter to completely disable email alerts.
168
+ *
169
+ * @since 3.0.0
170
+ */
171
+ if ( ! apply_filters( 'jj4t3_can_email_alert', $this->alert_enabled ) ) {
172
+ return;
173
+ }
174
+
175
+
176
+ // Email alert class.
177
+ $email = new JJ4T3_404_Email( $this );
178
+ $email->send_email();
179
+ }
180
+
181
+ /**
182
+ * Redirect 404 requests.
183
+ *
184
+ * If a 404 page is requested, take visitors to a proper existing page.
185
+ * Registering new action hook "jj4t3_before_redirect".
186
+ *
187
+ * @since 3.0.0
188
+ * @access private
189
+ *
190
+ * @global object $wpdb WordPress DB object.
191
+ *
192
+ * @return void
193
+ */
194
+ public function redirect() {
195
+
196
+ // Only if we can.
197
+ if ( ! $this->redirect_enabled ) {
198
+ return;
199
+ }
200
+
201
+ if ( ! empty( $this->redirect_url ) ) {
202
+
203
+ /**
204
+ * Action hook to perform before redirect.
205
+ *
206
+ * @since 3.0.0
207
+ *
208
+ * @param string $url Link to redirect.
209
+ */
210
+ do_action( 'jj4t3_before_redirect', $this->redirect_url );
211
+
212
+ // Perform redirect using WordPres.
213
+ wp_redirect( $this->redirect_url, $this->redirect_type );
214
+ // Exit, because WordPress will not exit automatically.
215
+ exit;
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Set custom redirect url if set
221
+ *
222
+ * If custom redirect url is set for give 404 path,
223
+ * set that link.
224
+ * Registering filter "jj4t3_custom_redirect_url".
225
+ *
226
+ * @global object $wpdb WP DB object
227
+ * @since 2.2.0
228
+ * @access private
229
+ *
230
+ * @return void
231
+ */
232
+ private function set_options() {
233
+
234
+ if ( empty( $this->url ) ) {
235
+ return;
236
+ }
237
+
238
+ global $wpdb;
239
+ // Make sure that the errors are hidden.
240
+ $wpdb->hide_errors();
241
+
242
+ // Get custom redirect if set.
243
+ $result = $result = $wpdb->get_row( "SELECT redirect, options FROM " . JJ4T3_TABLE . " WHERE url = '" . $this->url . "' AND redirect IS NOT NULL LIMIT 0,1", "OBJECT" );
244
+
245
+ $options = empty( $result->options ) ? array() : maybe_unserialize( $result->options );
246
+
247
+ // Set all properties.
248
+ $this->set_common_check();
249
+ $this->set_redirect_url( $result );
250
+ $this->set_redirect_type( $options );
251
+ $this->set_redirect_status( $options );
252
+ $this->set_logging_status( $options );
253
+ $this->set_alert_status( $options );
254
+ }
255
+
256
+ /**
257
+ * Get url to redirect to.
258
+ *
259
+ * This function is used to get the url
260
+ * for redirecting to.
261
+ * If a custom redirect is set through admin dashboard or even through
262
+ * the filter "jj4t3_custom_redirect_url" for the current 404 page, it will be prioratised.
263
+ * Otherwise global redirect link.
264
+ * Registering filter - jj4t3_redirect_url.
265
+ *
266
+ * @param object $options Current 404 options.
267
+ *
268
+ * @since 3.0.0
269
+ * @access private
270
+ *
271
+ * @return void
272
+ */
273
+ private function set_redirect_url( $options ) {
274
+
275
+ $url = false;
276
+
277
+ $custom_redirect = empty( $options->redirect ) ? '' : $options->redirect;
278
+
279
+ /**
280
+ * Filter for modify/set current 404's custom redirect.
281
+ *
282
+ * Using this filter you can modify or set custom redirect
283
+ * for any 404 path.
284
+ * @note : If you want to remove custom redirect for a path, you can
285
+ * use this filter and return an empty/false value.
286
+ * If you have set a value here, this will get priority over global redirect.
287
+ *
288
+ * @since 3.0.0
289
+ */
290
+ $custom_redirect = apply_filters( 'jj4t3_custom_redirect_url', $custom_redirect, $this->url );
291
+
292
+ if ( ! empty( $custom_redirect ) ) {
293
+ $url = esc_url( $custom_redirect );
294
+ $this->custom_redirect_url = esc_url( $custom_redirect );
295
+ } else {
296
+ // Get redirect to.
297
+ $to = jj4t3_get_option( 'redirect_to' );
298
+ if ( 'page' === $to ) {
299
+ // If an existing page is selected, get permalink.
300
+ $url = get_permalink( jj4t3_get_option( 'redirect_page' ) );
301
+ } elseif ( 'link' === $to ) {
302
+ // If a link.
303
+ $url = jj4t3_get_option( 'redirect_link' );
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Filter hook to change redirect url.
309
+ *
310
+ * To alter redirect link. Return full absolute
311
+ * path to redirect.
312
+ *
313
+ * @since 3.0.0
314
+ */
315
+ $this->redirect_url = esc_url( apply_filters( 'jj4t3_redirect_url', $url ) );
316
+ }
317
+
318
+ /**
319
+ * Set redirect type for the current 404.
320
+ *
321
+ * This function is used to set the redirect type code
322
+ * for the current 404.
323
+ * Custom config for the 404 is considered first.
324
+ *
325
+ * @param object $options Current 404 options.
326
+ *
327
+ * @since 3.0.0
328
+ * @access public
329
+ *
330
+ * @return void
331
+ */
332
+ private function set_redirect_type( $options ) {
333
+
334
+ if ( isset( $options['type'] ) && is_numeric( $options['type'] ) ) {
335
+ $this->redirect_type = intval( $options[ 'type' ] );
336
+ } else {
337
+ $this->redirect_type = jj4t3_redirect_type();
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Set if we can log 404 errors to database.
343
+ *
344
+ * This function is used to check and verify
345
+ * if the error logging is set to enabled.
346
+ * Checking custom config for the 404 first.
347
+ *
348
+ * @param object $options Current 404 options.
349
+ *
350
+ * @since 3.0.0
351
+ * @access public
352
+ *
353
+ * @return void
354
+ */
355
+ private function set_logging_status( $options ) {
356
+
357
+ if ( isset( $options['log'] ) && in_array( $options['log'], array( 0, 1 ) ) ) {
358
+ $enabled = boolval( $options[ 'log' ] );
359
+ } else {
360
+ $enabled = jj4t3_log_enabled();
361
+ }
362
+
363
+ if ( $enabled && jj4t3_is_human() ) {
364
+ $this->log_enabled = true;
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Set if we can email notify on errors.
370
+ *
371
+ * This function is used to check and verify
372
+ * if the email notification is enabled.
373
+ * Checking custom config for the 404 first.
374
+ *
375
+ * @param object $options Current 404 options.
376
+ *
377
+ * @since 3.0.0
378
+ * @access public
379
+ *
380
+ * @return void
381
+ */
382
+ private function set_alert_status( $options ) {
383
+
384
+ if ( isset( $options['alert'] ) && in_array( $options['alert'], array( 0, 1 ) ) ) {
385
+ $enabled = boolval( $options[ 'alert' ] );
386
+ } else {
387
+ $enabled = jj4t3_email_notify_enabled();
388
+ }
389
+
390
+ if ( $enabled && jj4t3_is_human() ) {
391
+ $this->alert_enabled = true;
392
+ }
393
+ }
394
+
395
+ /**
396
+ * Set if we can perform redirect related actions.
397
+ *
398
+ * Verify that the common check passed.
399
+ * Verify that redirect is enabled by user (custom if any).
400
+ *
401
+ * @param object $options Current 404 options.
402
+ *
403
+ * @since 2.2.0
404
+ * @access public
405
+ *
406
+ * @return void
407
+ */
408
+ private function set_redirect_status( $options ) {
409
+
410
+ if ( isset( $options['redirect'] ) && in_array( $options['redirect'], array( 0, 1 ) ) ) {
411
+ $enabled = boolval( $options['redirect'] );
412
+ } else {
413
+ $enabled = jj4t3_redirect_enabled();
414
+ }
415
+
416
+ if ( $enabled && $this->common_check_passed ) {
417
+ $this->redirect_enabled = true;
418
+ }
419
+ }
420
+
421
+ /**
422
+ * Set if the common checks are passed.
423
+ *
424
+ * Verify that the current page is not excluded.
425
+ * Verify that the current page is not an BuddyPress page
426
+ * only if BuddyPress is active.
427
+ *
428
+ * @since 2.2.0
429
+ * @access public
430
+ *
431
+ * @return void
432
+ */
433
+ private function set_common_check() {
434
+
435
+ // Do not redirect if excluded by user.
436
+ if ( $this->is_excluded() ) {
437
+ $this->common_check_passed = false;
438
+ } elseif ( function_exists( 'bp_current_component' ) ) {
439
+ $this->common_check_passed = ( ! bp_current_component() );
440
+ } else {
441
+ $this->common_check_passed = true;
442
+ }
443
+ }
444
+
445
+ }
includes/public/class-jj4t3-404-data.php ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * The 404 error data class.
8
+ *
9
+ * This class set all required information about the current
10
+ * 404 page. This class can be extended to access the 404
11
+ * page details such as URL, Time, User Agent etc.
12
+ *
13
+ * @category Core
14
+ * @package JJ4T3
15
+ * @subpackage 404Data
16
+ * @author Joel James <mail@cjoel.com>
17
+ * @license http://www.gnu.org/licenses/ GNU General Public License
18
+ * @link https://duckdev.com/products/404-to-301/
19
+ */
20
+ class JJ4T3_404_Data {
21
+
22
+ /**
23
+ * Visitor IP address.
24
+ *
25
+ * @var string
26
+ * @access public
27
+ */
28
+ public $ip = '';
29
+
30
+ /**
31
+ * Visitor user agent.
32
+ *
33
+ * @var string
34
+ * @access public
35
+ */
36
+ public $ua = '';
37
+
38
+ /**
39
+ * Referring link.
40
+ *
41
+ * @var string
42
+ * @access public
43
+ */
44
+ public $ref = 'n/a';
45
+
46
+ /**
47
+ * Current requested path.
48
+ *
49
+ * @var array
50
+ * @access public
51
+ */
52
+ public $url = '';
53
+
54
+ /**
55
+ * Current date and time.
56
+ *
57
+ * @var array
58
+ * @access public
59
+ */
60
+ public $time = '';
61
+
62
+ /**
63
+ * Initialize the class.
64
+ *
65
+ * @since 3.0.0
66
+ * @access private
67
+ */
68
+ public function __construct() {
69
+
70
+ $this->set_ip();
71
+ $this->set_ref();
72
+ $this->set_ua();
73
+ $this->set_url();
74
+ $this->set_time();
75
+ }
76
+
77
+ /**
78
+ * Set visitors IP address.
79
+ *
80
+ * Get real IP address of the user.
81
+ * http://stackoverflow.com/a/55790/3845839
82
+ *
83
+ * @param string $ip Default value for IP Address.
84
+ *
85
+ * @since 2.2.6
86
+ * @access private
87
+ *
88
+ * @return void
89
+ */
90
+ private function set_ip( $ip = '' ) {
91
+
92
+ // IP varibals in priority oder.
93
+ $ips = array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' );
94
+ foreach ( $ips as $ip ) {
95
+ if ( isset( $_SERVER[ $ip ] ) ) {
96
+ $ip = $_SERVER[ $ip ];
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Filter to alter visitors IP address.
102
+ *
103
+ * @since 3.0.0
104
+ */
105
+ $this->ip = apply_filters( 'jj4t3_404_ip', $ip );
106
+ }
107
+
108
+ /**
109
+ * Set visitors user agent/browser.
110
+ *
111
+ * @param string $ua Default value for User Agent.
112
+ *
113
+ * @since 3.0.0
114
+ * @access private
115
+ *
116
+ * @return void
117
+ */
118
+ private function set_ua( $ua = '' ) {
119
+
120
+ if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
121
+ $ua = $_SERVER['HTTP_USER_AGENT'];
122
+ }
123
+
124
+ /**
125
+ * Filter to alter User Agent.
126
+ *
127
+ * @since 3.0.0
128
+ */
129
+ $this->ua = apply_filters( 'jj4t3_404_ua', $ua );
130
+ }
131
+
132
+ /**
133
+ * Set visitors referring link.
134
+ *
135
+ * @param string $ref Default value for Ref.
136
+ *
137
+ * @since 3.0.0
138
+ * @access private
139
+ *
140
+ * @return void
141
+ */
142
+ private function set_ref( $ref = '' ) {
143
+
144
+ if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
145
+ $ref = esc_url( $_SERVER['HTTP_REFERER'] );
146
+ }
147
+
148
+ /**
149
+ * Filter to alter referrer url.
150
+ *
151
+ * To alter the url where the visitor comes from.
152
+ *
153
+ * @since 3.0.0
154
+ */
155
+ $this->ref = apply_filters( 'jj4t3_404_ref', $ref );
156
+ }
157
+
158
+ /**
159
+ * Set visitors referring link.
160
+ *
161
+ * @param string $url Default value for 404 URL.
162
+ *
163
+ * @since 3.0.0
164
+ * @access private
165
+ *
166
+ * @return void
167
+ */
168
+ private function set_url( $url = '' ) {
169
+
170
+ if ( isset( $_SERVER['REQUEST_URI'] ) ) {
171
+ $url = untrailingslashit( esc_url( $_SERVER['REQUEST_URI'] ) );
172
+ }
173
+
174
+ /**
175
+ * Filter to alter current 404 path.
176
+ *
177
+ * It is not recommended to change this value.
178
+ *
179
+ * @since 3.0.0
180
+ */
181
+ $this->url = apply_filters( 'jj4t3_404_url', $url );
182
+ }
183
+
184
+ /**
185
+ * Set current time.
186
+ *
187
+ * @since 3.0.0
188
+ * @access private
189
+ *
190
+ * @return void
191
+ */
192
+ private function set_time() {
193
+
194
+ /**
195
+ * Filter to alter current time.
196
+ *
197
+ * @note If you using this filter, remember to
198
+ * return proper MySQL time format.
199
+ *
200
+ * @since 3.0.0
201
+ */
202
+ $this->time = apply_filters( 'jj4t3_404_time', current_time( 'mysql' ) );
203
+ }
204
+
205
+ /**
206
+ * Exclude specified paths from 404.
207
+ *
208
+ * If paths entered in exclude paths option is
209
+ * found in current 404 page, skip this from
210
+ * 404 actions.
211
+ *
212
+ * @since 2.0.8
213
+ * @access private
214
+ *
215
+ * @return boolean
216
+ */
217
+ public function is_excluded() {
218
+
219
+ $excluded = jj4t3_get_option( 'exclude_paths', '' );
220
+
221
+ $paths = array();
222
+
223
+ // If no exclude path set, return false early.
224
+ if ( ! empty( $excluded ) ) {
225
+ // Split by line break.
226
+ $paths = explode( "\n", $excluded );
227
+ }
228
+
229
+ /**
230
+ * Filter to alter exclude path values.
231
+ *
232
+ * @note You should return array if strings .
233
+ *
234
+ * @since 3.0.0
235
+ */
236
+ $paths = apply_filters( 'jj4t3_404_excluded_paths', $paths );
237
+
238
+ // If split failed, return false.
239
+ if ( empty( $paths ) ) {
240
+ return false;
241
+ }
242
+
243
+ // Verify that the excluded path is not matching current page.
244
+ foreach ( $paths as $path ) {
245
+ if ( strpos( $this->url, trim( $path ) ) !== false ) {
246
+ return true;
247
+ }
248
+ }
249
+
250
+ return false;
251
+ }
252
+
253
+ }
includes/public/class-jj4t3-404-email.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * The main 404 email alert class.
8
+ *
9
+ * This class handles the email alert task for the
10
+ * 404 errors found.
11
+ *
12
+ * @category Core
13
+ * @package JJ4T3
14
+ * @subpackage EmailAlert
15
+ * @author Joel James <mail@cjoel.com>
16
+ * @license http://www.gnu.org/licenses/ GNU General Public License
17
+ * @link https://duckdev.com/products/404-to-301/
18
+ */
19
+ class JJ4T3_404_Email {
20
+
21
+ /**
22
+ * Error data class object.
23
+ *
24
+ * @var object
25
+ * @access private
26
+ * @since 3.0.0
27
+ */
28
+ private $error_data;
29
+
30
+ /**
31
+ * Recipient email addresses.
32
+ *
33
+ * @var string|array
34
+ * @access public
35
+ */
36
+ public $recipient;
37
+
38
+ /**
39
+ * Email subject.
40
+ *
41
+ * @var string
42
+ * @access public
43
+ */
44
+ public $subject;
45
+
46
+ /**
47
+ * Email headers.
48
+ *
49
+ * @var array
50
+ * @access public
51
+ */
52
+ public $headers;
53
+
54
+ /**
55
+ * Email content body.
56
+ *
57
+ * @var string
58
+ * @access public
59
+ */
60
+ public $body;
61
+
62
+ /**
63
+ * Initialize the class and set properties.
64
+ *
65
+ * @param object $error_data Error logs data class.
66
+ *
67
+ * @since 3.0.0
68
+ * @access public
69
+ */
70
+ public function __construct( $error_data ) {
71
+
72
+ $this->error_data = $error_data;
73
+
74
+ // Set required properties.
75
+ $this->set_recipient();
76
+ $this->set_subject();
77
+ $this->set_headers();
78
+ $this->set_body();
79
+ }
80
+
81
+ /**
82
+ * Send email alert about the error.
83
+ *
84
+ * Registering new action hook "jj4t3_before_email".
85
+ *
86
+ * @since 3.0.0
87
+ * @access public
88
+ */
89
+ public function send_email() {
90
+
91
+ /**
92
+ * Action hook to perform before email alert.
93
+ *
94
+ * Sending email using wp_mail() function.
95
+ *
96
+ * @since 3.0.0
97
+ *
98
+ * @param string $this ->recipient Email recipient.
99
+ * @param string $this ->subject Email subject.
100
+ * @param string $this ->body Email body.
101
+ */
102
+ do_action( 'jj4t3_before_email', $this->recipient, $this->subject, $this->body );
103
+
104
+ //var_dump($this->recipient); exit;
105
+ // Send email using wp_mail().
106
+ wp_mail( $this->recipient, $this->subject, $this->body, $this->headers );
107
+ }
108
+
109
+ /**
110
+ * Set email recipients.
111
+ *
112
+ * Registering filter - "jj4t3_email_recipient".
113
+ *
114
+ * @since 3.0.0
115
+ * @access private
116
+ */
117
+ private function set_recipient() {
118
+
119
+ // Get email recipient if set.
120
+ $recipient = jj4t3_get_option( 'email_notify_address', get_option( 'admin_email' ) );
121
+
122
+ /**
123
+ * Filter to alter email recipient.
124
+ *
125
+ * @since 3.0.0
126
+ */
127
+ $this->recipient = apply_filters( 'jj4t3_email_recipient', $recipient );
128
+ }
129
+
130
+ /**
131
+ * Set subject for the 404 email alert.
132
+ *
133
+ * Registering filter - "jj4t3_email_subject".
134
+ *
135
+ * @since 3.0.0
136
+ * @access private
137
+ */
138
+ private function set_subject() {
139
+
140
+ // Include site title.
141
+ $message = __( 'Snap! One more 404 on ', JJ4T3_DOMAIN ) . get_bloginfo( 'name' );
142
+
143
+ /**
144
+ * Filter to alter email subject text.
145
+ *
146
+ * @since 3.0.0
147
+ */
148
+ $this->subject = apply_filters( 'jj4t3_email_subject', $message );
149
+ }
150
+
151
+ /**
152
+ * Set email headers.
153
+ *
154
+ * Registering filter - "jj4t3_email_headers".
155
+ *
156
+ * @since 3.0.0
157
+ * @access private
158
+ */
159
+ private function set_headers() {
160
+
161
+ /**
162
+ * Filter to alter From name of email alert.
163
+ *
164
+ * @since 3.0.0
165
+ */
166
+ $from_name = apply_filters( 'jj4t3_email_header_name', get_bloginfo( 'name' ) );
167
+
168
+ /**
169
+ * Filter to alter From email address of email alert.
170
+ *
171
+ * @since 3.0.0
172
+ */
173
+ $from_email = apply_filters( 'jj4t3_email_header_email', get_option( 'admin_email' ) );
174
+
175
+ $this->headers[] = "From: " . $from_name . " <" . $from_email . ">" . "\r\n";
176
+ $this->headers[] = "Content-Type: text/html; charset=UTF-8";
177
+ }
178
+
179
+ /**
180
+ * Set content for the email alert.
181
+ *
182
+ * Registering filter - "jj4t3_email_body".
183
+ *
184
+ * @since 3.0.0
185
+ * @access private
186
+ */
187
+ private function set_body() {
188
+
189
+ $message = "<p>" . __( 'Bummer! You have one more 404', JJ4T3_DOMAIN ) . "</p>";
190
+ $message .= '<table>';
191
+ // 404 path.
192
+ $message .= '<tr>';
193
+ $message .= '<th align="left">' . __( '404 Path', JJ4T3_DOMAIN ) . '</th>';
194
+ $message .= '<td align="left">' . $this->error_data->url . '</td>';
195
+ $message .= '</tr>';
196
+ // IP Address.
197
+ $message .= '<tr>';
198
+ $message .= '<th align="left">' . __( 'IP Address', JJ4T3_DOMAIN ) . '</th>';
199
+ $message .= '<td align="left">' . $this->error_data->ip . '</td>';
200
+ $message .= '</tr>';
201
+ // Date and time.
202
+ $message .= '<tr>';
203
+ $message .= '<th align="left">' . __( 'Time', JJ4T3_DOMAIN ) . '</th>';
204
+ $message .= '<td align="left">' . $this->error_data->time . '</td>';
205
+ $message .= '</tr>';
206
+ // Referral url.
207
+ $message .= '<tr>';
208
+ $message .= '<th align="left">' . __( 'Referral Page', JJ4T3_DOMAIN ) . '</th>';
209
+ $message .= '<td align="left">' . $this->error_data->ref . '</td>';
210
+ $message .= '</tr>';
211
+ $message .= '</table>';
212
+ // Who sent me this alert?
213
+ $message .= '<p>Alert sent by the <strong>404 to 301</strong> plugin for WordPress.</p>';
214
+
215
+ /**
216
+ * Filter to alter email content.
217
+ *
218
+ * @since 3.0.0
219
+ */
220
+ $this->body = apply_filters( 'jj4t3_email_body', $message );
221
+ }
222
+
223
+ }
includes/public/class-jj4t3-404-logging.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If this file is called directly, abort.
4
+ defined( 'ABSPATH' ) or exit;
5
+
6
+ /**
7
+ * The main 404 error logging class.
8
+ *
9
+ * This class logs the error data to the database.
10
+ *
11
+ * @category Core
12
+ * @package JJ4T3
13
+ * @subpackage ErrorLogging
14
+ * @author Joel James <mail@cjoel.com>
15
+ * @license http://www.gnu.org/licenses/ GNU General Public License
16
+ * @link https://duckdev.com/products/404-to-301/
17
+ */
18
+ class JJ4T3_404_Logging {
19
+
20
+ /**
21
+ * Error data class object.
22
+ *
23
+ * @var object
24
+ * @access public
25
+ * @since 3.0.0
26
+ */
27
+ public $data;
28
+
29
+ /**
30
+ * Initialize the class and set properties.
31
+ *
32
+ * @param object $error_data Error log data class.
33
+ *
34
+ * @since 3.0.0
35
+ * @access public
36
+ */
37
+ public function __construct( $error_data ) {
38
+
39
+ $this->data = $error_data;
40
+ }
41
+
42
+ /**
43
+ * Log details of error to the database.
44
+ *
45
+ * Registered new action hook "jj4t3_before_logging".
46
+ *
47
+ * @since 3.0.0
48
+ * @access public
49
+ * @global object $wpdb WordPress database.
50
+ */
51
+ public function log_error() {
52
+
53
+ global $wpdb;
54
+
55
+ $data = $this->get_data();
56
+
57
+ /**
58
+ * Action hook before logging.
59
+ *
60
+ * To perform actions before logging errors to db.
61
+ *
62
+ * @since 3.0.0
63
+ *
64
+ * @param array $data Error log data.
65
+ */
66
+ do_action( 'jj4t3_before_logging', $data );
67
+
68
+ // Insert data to db.
69
+ $wpdb->insert( JJ4T3_TABLE, $data );
70
+ }
71
+
72
+ /**
73
+ * Get error log data in proper format.
74
+ *
75
+ * @since 3.0.0
76
+ * @access public
77
+ *
78
+ * @return array $data Array of error log data.
79
+ */
80
+ private function get_data() {
81
+
82
+ // Set error data fields.
83
+ $data = array(
84
+ 'date' => $this->data->time,
85
+ 'ip' => $this->data->ip,
86
+ 'url' => $this->data->url,
87
+ 'ref' => $this->data->ref,
88
+ 'ua' => $this->data->ua,
89
+ );
90
+
91
+ // If a custom redirect is set.
92
+ if ( $this->data->custom_redirect_url ) {
93
+ $data['redirect'] = $this->data->custom_redirect_url;
94
+ }
95
+
96
+ return $data;
97
+ }
98
+
99
+ }
{public → includes/public}/index.php RENAMED
File without changes
languages/404-to-301-pt_PT.mo CHANGED
Binary file
languages/404-to-301-pt_PT.po CHANGED
@@ -3,8 +3,8 @@
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: 404 to 301\n"
6
- "POT-Creation-Date: 2016-06-03 18:46+0100\n"
7
- "PO-Revision-Date: 2016-06-16 23:47+0100\n"
8
  "Last-Translator: Pedro Mendonça <ped.gaspar@gmail.com>\n"
9
  "Language-Team: Pedro Mendonça <ped.gaspar@gmail.com>\n"
10
  "Language: pt_PT\n"
@@ -12,7 +12,7 @@ msgstr ""
12
  "Content-Type: text/plain; charset=UTF-8\n"
13
  "Content-Transfer-Encoding: 8bit\n"
14
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
- "X-Generator: Poedit 1.8.8\n"
16
  "X-Poedit-SourceCharset: UTF-8\n"
17
  "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
18
  "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;"
@@ -21,558 +21,215 @@ msgstr ""
21
  "X-Poedit-WPHeader: 404-to-301.php\n"
22
  "X-Poedit-SearchPath-0: .\n"
23
 
24
- #: admin/class-404-to-301-admin.php:112
25
  msgid "Custom Redirect"
26
  msgstr "Redireccionamento personalizado"
27
 
28
- #: admin/class-404-to-301-admin.php:179 admin/class-404-to-301-admin.php:180
29
- #: admin/class-404-to-301-admin.php:270 admin/class-404-to-301-logs.php:64
 
30
  msgid "404 Error Logs"
31
  msgstr "Registos de erros 404"
32
 
33
- #: admin/class-404-to-301-admin.php:193
 
 
 
 
34
  msgid "404 to 301 Settings"
35
  msgstr "Definições de 404 to 301"
36
 
37
- #: admin/class-404-to-301-admin.php:194
38
  msgid "404 Settings"
39
  msgstr "Definições de 404"
40
 
41
- #: admin/class-404-to-301-admin.php:232
42
  msgid "Error Logs"
43
  msgstr "Registos de erros"
44
 
45
- #. Plugin Name of the plugin/theme
46
- #: admin/class-404-to-301-admin.php:305
47
- #: admin/partials/404-to-301-admin-credits-tab.php:52
48
  msgid "404 to 301"
49
  msgstr "404 to 301"
50
 
51
- #: admin/class-404-to-301-admin.php:361
52
- msgid "Thank you for choosing 404 to 301 to improve your website"
53
- msgstr "Obrigado por escolher o 404 to 301 para optimizar o seu site"
54
-
55
- #: admin/class-404-to-301-admin.php:363
56
- #, php-format
57
- msgid "Kindly give this plugin a %srating%s"
58
- msgstr "Por favor, atribua a este plugin uma %sclassificação%s"
59
-
60
- #: admin/class-404-to-301-admin.php:385
61
- #: admin/partials/404-to-301-admin-display.php:27
62
  msgid "Settings"
63
  msgstr "Definições"
64
 
65
- #: admin/class-404-to-301-admin.php:386
66
  msgid "Logs"
67
  msgstr "Registos"
68
 
69
- #: admin/class-404-to-301-admin.php:543
70
- msgid "Settings Data"
71
- msgstr "Dados das definições"
72
-
73
- #: admin/class-404-to-301-admin.php:550
74
- msgid "Basic Details"
75
- msgstr "Detalhes básicos"
76
-
77
- #: admin/class-404-to-301-admin.php:551
78
- msgid "WordPress Version"
79
- msgstr "Versão do WordPress"
80
-
81
- #: admin/class-404-to-301-admin.php:552
82
- msgid "PHP Version"
83
- msgstr "Versão do PHP"
84
-
85
- #: admin/class-404-to-301-admin.php:553
86
- msgid "Plugin Version"
87
- msgstr "Versão do plugin"
88
-
89
- #: admin/class-404-to-301-admin.php:554
90
- msgid "Home Page"
91
- msgstr "Página inicial"
92
-
93
- #: admin/class-404-to-301-admin.php:558
94
- msgid "Active Theme Details"
95
- msgstr "Detalhes do tema activo"
96
-
97
- #: admin/class-404-to-301-admin.php:559
98
- #: admin/partials/404-to-301-admin-credits-tab.php:51
99
- msgid "Name"
100
- msgstr "Nome"
101
-
102
- #: admin/class-404-to-301-admin.php:560
103
- #: admin/partials/404-to-301-admin-credits-tab.php:55
104
- msgid "Version"
105
- msgstr "Versão"
106
-
107
- #: admin/class-404-to-301-admin.php:561
108
- msgid "Theme URI"
109
- msgstr "URI do tema"
110
-
111
- #: admin/class-404-to-301-admin.php:566
112
- msgid "Active Plugins"
113
- msgstr "Plugins activos"
114
-
115
- #: admin/class-404-to-301-logs.php:63
116
  msgid "404 Error Log"
117
  msgstr "Registo de erro 404"
118
 
119
- #: admin/class-404-to-301-logs.php:203
120
- msgid "Ulta pulta..! Seems like you had no errors to log."
121
- msgstr "Ena! Parece que não ocorreu nenhum erro para registar."
122
-
123
- #: admin/class-404-to-301-logs.php:269
124
- msgid "Default"
125
- msgstr "Por omissão"
126
-
127
- #: admin/class-404-to-301-logs.php:271
128
- msgid "Customize"
129
- msgstr "Personalizar"
130
-
131
- #: admin/class-404-to-301-logs.php:293
132
- msgid "Are you sure you want to delete this item?"
133
- msgstr "Tem a certeza que quer eliminar este item?"
134
-
135
- #: admin/class-404-to-301-logs.php:296
136
- msgid "Delete"
137
- msgstr "Eliminar"
138
-
139
- #: admin/class-404-to-301-logs.php:400
140
  msgid "Date"
141
  msgstr "Data"
142
 
143
- #: admin/class-404-to-301-logs.php:401 public/class-404-to-301-public.php:68
 
 
144
  msgid "404 Path"
145
  msgstr "Caminho de 404"
146
 
147
- #: admin/class-404-to-301-logs.php:402
 
148
  msgid "From"
149
  msgstr "De"
150
 
151
- #: admin/class-404-to-301-logs.php:403 public/class-404-to-301-public.php:64
 
 
152
  msgid "IP Address"
153
  msgstr "Endereço IP"
154
 
155
- #: admin/class-404-to-301-logs.php:404 public/class-404-to-301-public.php:72
 
156
  msgid "User Agent"
157
  msgstr "Agente do utilizador"
158
 
159
- #: admin/class-404-to-301-logs.php:405
160
- #: admin/partials/404-to-301-admin-general-tab.php:34
161
- #: admin/partials/404-to-301-admin-general-tab.php:35
162
- msgid "Redirect"
163
- msgstr "Redireccionamento"
164
-
165
- #: admin/class-404-to-301-logs.php:448
166
- msgid "Delete Selected"
167
- msgstr "Eliminar seleccionados"
168
-
169
- #: admin/class-404-to-301-logs.php:449
170
- msgid "Delete All"
171
- msgstr "Eliminar tudo"
172
-
173
- #: admin/class-404-to-301-logs.php:588
174
- msgid "N/A"
175
- msgstr "Não disponível"
176
-
177
- #: admin/core/class-wp-list-table-4.4.php:162
178
- #: admin/core/class-wp-list-table-old.php:144
179
- msgid "List View"
180
- msgstr "Vista de lista"
181
-
182
- #: admin/core/class-wp-list-table-4.4.php:163
183
- #: admin/core/class-wp-list-table-old.php:145
184
- msgid "Excerpt View"
185
- msgstr "Vista de excerto"
186
-
187
- #: admin/core/class-wp-list-table-4.4.php:334
188
- #: admin/core/class-wp-list-table-old.php:312
189
- msgid "No items found."
190
- msgstr "Nenhum item encontrado."
191
-
192
- #: admin/core/class-wp-list-table-4.4.php:462
193
- #: admin/core/class-wp-list-table-old.php:438
194
- msgid "Select bulk action"
195
- msgstr "Seleccionar acção por lotes"
196
-
197
- #: admin/core/class-wp-list-table-4.4.php:464
198
- #: admin/core/class-wp-list-table-old.php:440
199
- msgid "Bulk Actions"
200
- msgstr "Acções por lotes"
201
-
202
- #: admin/core/class-wp-list-table-4.4.php:474
203
- #: admin/core/class-wp-list-table-old.php:450
204
- msgid "Apply"
205
- msgstr "Aplicar"
206
-
207
- #: admin/core/class-wp-list-table-4.4.php:524
208
- #: admin/core/class-wp-list-table-4.4.php:1324
209
- msgid "Show more details"
210
- msgstr "Ver mais detalhes"
211
-
212
- #: admin/core/class-wp-list-table-4.4.php:587
213
- #: admin/core/class-wp-list-table-old.php:550
214
- msgid "Filter by date"
215
- msgstr "Filtrar por data"
216
-
217
- #: admin/core/class-wp-list-table-4.4.php:589
218
- #: admin/core/class-wp-list-table-old.php:552
219
- msgid "All dates"
220
- msgstr "Todas as datas"
221
-
222
- #: admin/core/class-wp-list-table-4.4.php:602
223
- #: admin/core/class-wp-list-table-old.php:565
224
- #, php-format
225
- msgid "%1$s %2$d"
226
- msgstr "%1$s de %2$d"
227
-
228
- #: admin/core/class-wp-list-table-4.4.php:654
229
- #, php-format
230
- msgid "%s comment"
231
- msgid_plural "%s comments"
232
- msgstr[0] "%s comentário"
233
- msgstr[1] "%s comentários"
234
-
235
- #: admin/core/class-wp-list-table-4.4.php:655
236
- #, php-format
237
- msgid "%s approved comment"
238
- msgid_plural "%s approved comments"
239
- msgstr[0] "%s comentário aprovado"
240
- msgstr[1] "%s comentários aprovados"
241
-
242
- #: admin/core/class-wp-list-table-4.4.php:656
243
- #, php-format
244
- msgid "%s pending comment"
245
- msgid_plural "%s pending comments"
246
- msgstr[0] "%s comentário pendente"
247
- msgstr[1] "%s comentários pendentes"
248
-
249
- #: admin/core/class-wp-list-table-4.4.php:661
250
- #: admin/core/class-wp-list-table-4.4.php:673
251
- #: admin/core/class-wp-list-table-4.4.php:686
252
- msgid "No comments"
253
- msgstr "Sem comentários"
254
-
255
- #: admin/core/class-wp-list-table-4.4.php:673
256
- msgid "No approved comments"
257
- msgstr "Sem comentários aprovados"
258
-
259
- #: admin/core/class-wp-list-table-4.4.php:686
260
- msgid "No pending comments"
261
- msgstr "Não há comentários pendentes"
262
-
263
- #: admin/core/class-wp-list-table-4.4.php:763
264
- #: admin/core/class-wp-list-table-4.4.php:1349
265
- #, php-format
266
- msgid "%s item"
267
- msgid_plural "%s items"
268
- msgstr[0] "%s item"
269
- msgstr[1] "%s itens"
270
-
271
- #: admin/core/class-wp-list-table-4.4.php:798
272
- msgid "First page"
273
- msgstr "Primeira página"
274
-
275
- #: admin/core/class-wp-list-table-4.4.php:808
276
- msgid "Previous page"
277
- msgstr "Página anterior"
278
-
279
- #: admin/core/class-wp-list-table-4.4.php:815
280
- #: admin/core/class-wp-list-table-4.4.php:818
281
- #: admin/core/class-wp-list-table-old.php:727
282
- msgid "Current Page"
283
- msgstr "Página actual"
284
-
285
- #: admin/core/class-wp-list-table-4.4.php:824
286
- #: admin/core/class-wp-list-table-old.php:733
287
- #, php-format
288
- msgctxt "paging"
289
- msgid "%1$s of %2$s"
290
- msgstr "%1$s de %2$s"
291
-
292
- #: admin/core/class-wp-list-table-4.4.php:831
293
- msgid "Next page"
294
- msgstr "Página seguinte"
295
-
296
- #: admin/core/class-wp-list-table-4.4.php:841
297
- msgid "Last page"
298
- msgstr "Última página"
299
-
300
- #: admin/core/class-wp-list-table-4.4.php:1069
301
- #: admin/core/class-wp-list-table-old.php:881
302
- msgid "Select All"
303
- msgstr "Seleccionar tudo"
304
 
305
- #: admin/core/class-wp-list-table-old.php:612
306
- #, php-format
307
- msgid "%s pending"
308
- msgstr "%s pendente(s)"
309
 
310
- #: admin/core/class-wp-list-table-old.php:691
311
- #: admin/core/class-wp-list-table-old.php:1115
312
- #, php-format
313
- msgid "1 item"
314
- msgid_plural "%s items"
315
- msgstr[0] "1 item"
316
- msgstr[1] "%s itens"
317
 
318
- #: admin/core/class-wp-list-table-old.php:710
319
- msgid "Go to the first page"
320
- msgstr "Ir para a primeira página"
321
 
322
- #: admin/core/class-wp-list-table-old.php:717
323
- msgid "Go to the previous page"
324
- msgstr "Ir para a página anterior"
 
 
 
325
 
326
- #: admin/core/class-wp-list-table-old.php:726
327
- msgid "Select Page"
328
- msgstr "Seleccionar página"
329
 
330
- #: admin/core/class-wp-list-table-old.php:737
331
- msgid "Go to the next page"
332
- msgstr "Ir para a página seguinte"
333
 
334
- #: admin/core/class-wp-list-table-old.php:744
335
- msgid "Go to the last page"
336
- msgstr "Ir para a última página"
337
 
338
- #: admin/partials/404-to-301-admin-agreement-tab.php:48
339
- msgid "I accept"
340
- msgstr "Aceito"
341
 
342
- #: admin/partials/404-to-301-admin-agreement-tab.php:49
343
- msgid "I do not accept"
344
- msgstr "Não aceito"
345
 
346
- #: admin/partials/404-to-301-admin-credits-tab.php:12
347
- msgid "About the plugin & developer"
348
- msgstr "Sobre o plugin e o programador"
349
 
350
- #: admin/partials/404-to-301-admin-credits-tab.php:20
351
  #, php-format
352
- msgid "Yo %s!"
353
- msgstr "Olá %s!"
354
-
355
- #: admin/partials/404-to-301-admin-credits-tab.php:20
356
- msgid "Thank you for using 404 to 301"
357
- msgstr "Obrigado por utilizar o 404 to 301."
358
-
359
- #: admin/partials/404-to-301-admin-credits-tab.php:22
360
- msgid "This plugin is brought to you by"
361
- msgstr "Este plugin é desenvolvido por"
362
-
363
- #: admin/partials/404-to-301-admin-credits-tab.php:22
364
- #: admin/partials/404-to-301-admin-credits-tab.php:59
365
- msgid "Visit author website"
366
- msgstr "Visite o website do autor"
367
-
368
- #: admin/partials/404-to-301-admin-credits-tab.php:22
369
- msgid "a web store developed and managed by Joel James."
370
- msgstr "uma loja online desenvolvida e gerida por Joel James."
371
-
372
- #: admin/partials/404-to-301-admin-credits-tab.php:28
373
- msgid "So you installed this plugin and how is it doing? Feel free to"
374
  msgstr ""
375
- "Então, instalou este plugin, que tal está a correr? Sinta-se à vontade para"
376
-
377
- #: admin/partials/404-to-301-admin-credits-tab.php:28
378
- msgid "Contact the developer"
379
- msgstr "Contacte o programador"
380
-
381
- #: admin/partials/404-to-301-admin-credits-tab.php:28
382
- msgid "get in touch with me"
383
- msgstr "entrar em contacto comigo"
384
-
385
- #: admin/partials/404-to-301-admin-credits-tab.php:28
386
- msgid "anytime for help. I am always happy to help."
387
- msgstr "a qualquer momento para ajuda. Tenho o maior prazer em ajudar."
388
-
389
- #: admin/partials/404-to-301-admin-credits-tab.php:35
390
- msgid "Debugging Data"
391
- msgstr "Dados de depuração"
392
-
393
- #: admin/partials/404-to-301-admin-credits-tab.php:48
394
- msgid "Plugin Information"
395
- msgstr "Informações do plugin"
396
-
397
- #: admin/partials/404-to-301-admin-credits-tab.php:59
398
- msgid "Author"
399
- msgstr "Autor"
400
-
401
- #: admin/partials/404-to-301-admin-credits-tab.php:63
402
- #: admin/partials/404-to-301-admin-credits-tab.php:67
403
- msgid "Visit plugin website"
404
- msgstr "Visite o site do plugin"
405
-
406
- #: admin/partials/404-to-301-admin-credits-tab.php:63
407
- msgid "Plugin documentation"
408
- msgstr "Documentação do plugin"
409
-
410
- #: admin/partials/404-to-301-admin-credits-tab.php:67
411
- msgid "More details about the plugin"
412
- msgstr "Mais detalhes sobre o plugin"
413
 
414
- #: admin/partials/404-to-301-admin-credits-tab.php:71
415
- msgid "Need help?"
416
- msgstr "Precisa de ajuda?"
417
-
418
- #: admin/partials/404-to-301-admin-credits-tab.php:72
419
- msgid "Contact support"
420
- msgstr "Contacte o suporte"
421
-
422
- #: admin/partials/404-to-301-admin-credits-tab.php:76
423
- msgid "Disable UAN"
424
- msgstr "Desactivar UAN"
425
-
426
- #: admin/partials/404-to-301-admin-credits-tab.php:78
427
- msgid "Enable UAN"
428
- msgstr "Activar UAN"
429
 
430
- #: admin/partials/404-to-301-admin-credits-tab.php:84
431
- msgid "Log Manager Addon"
432
- msgstr "Addon Log Manager"
 
433
 
434
- #: admin/partials/404-to-301-admin-credits-tab.php:87
435
- msgid ""
436
- "Error Log Manager addon is available for 404 to 301 now. Make 404 error "
437
- "management more easy."
438
  msgstr ""
439
- "O addon Log Manager está agora disponível para o 404 to 301. Torne a gestão "
440
- "de erros 404 mais fácil."
441
 
442
- #: admin/partials/404-to-301-admin-credits-tab.php:88
443
- msgid ""
444
- "Instead of email alerts on every error, get Hourly, Daily, Twice a day, "
445
- "Weekly, Twice a week email alerts."
446
  msgstr ""
447
- "Em vez de emails de alerta por cada erro, receba emails de alerta a cada "
448
- "hora, uma a duas vezes por dia, ou uma a duas vezes por semana."
449
 
450
- #: admin/partials/404-to-301-admin-credits-tab.php:89
451
- msgid "Automatically clear old error logs after few days to reduce db load."
452
  msgstr ""
453
- "Limpeza automática de registos de erros antigos após alguns dias, para "
454
- "reduzir o peso da base de dados."
455
-
456
- #: admin/partials/404-to-301-admin-credits-tab.php:90
457
- msgid "See More Details"
458
- msgstr "Ver mais detalhes"
459
-
460
- #: admin/partials/404-to-301-admin-credits-tab.php:95
461
- msgid "Like the plugin"
462
- msgstr "Gosta do plugin"
463
-
464
- #: admin/partials/404-to-301-admin-credits-tab.php:98
465
- msgid "Rate now"
466
- msgstr "Classificar agora"
467
-
468
- #: admin/partials/404-to-301-admin-credits-tab.php:98
469
- msgid "Rate this on WordPress"
470
- msgstr "Dê uma classificação no WordPress"
471
-
472
- #: admin/partials/404-to-301-admin-credits-tab.php:101
473
- msgid "Donate now"
474
- msgstr "Fazer donativo agora"
475
-
476
- #: admin/partials/404-to-301-admin-credits-tab.php:101
477
- msgid "Make a small donation"
478
- msgstr "Faça um pequeno donativo"
479
 
480
- #: admin/partials/404-to-301-admin-credits-tab.php:104
481
- msgid "Contribute now"
482
- msgstr "Contribuir agora"
483
-
484
- #: admin/partials/404-to-301-admin-credits-tab.php:104
485
- msgid "Contribute to the Plugin"
486
- msgstr "Contribua para o plugin"
487
-
488
- #: admin/partials/404-to-301-admin-credits-tab.php:107
489
- msgid "Tweet now"
490
- msgstr "Publicar no Twitter agora"
491
-
492
- #: admin/partials/404-to-301-admin-credits-tab.php:107
493
- msgid "Tweet about the Plugin"
494
- msgstr "Publique no Twitter sobre o plugin"
495
-
496
- #: admin/partials/404-to-301-admin-custom-redirect.php:6
497
- msgid "Redirecting from"
498
- msgstr "Redireccionar de"
499
 
500
- #: admin/partials/404-to-301-admin-custom-redirect.php:10
501
- #: admin/partials/404-to-301-admin-general-tab.php:41
502
  msgid "Redirect to"
503
  msgstr "Redireccionar para"
504
 
505
- #: admin/partials/404-to-301-admin-custom-redirect.php:13
506
  msgid ""
507
  "Enter the url if you want to set custom redirect for above 404 path. Enter "
508
  "the full url including http://. Leave empty if you want to follow deafult "
509
- "settings"
510
  msgstr ""
511
- "Insira o URL pretendido para o redireccionamento personalizado do caminho "
512
- "404 acima. Insira o caminho completo do URL incluindo http://. Deixe em "
513
- "branco para utilizar as definições por omissão."
514
 
515
- #: admin/partials/404-to-301-admin-custom-redirect.php:23
516
- msgid "Save Redirect"
517
- msgstr "Guardar redireccionamento"
518
-
519
- #: admin/partials/404-to-301-admin-display.php:30
520
- msgid "settings updated successfully"
521
- msgstr "definições actualizadas com sucesso"
522
-
523
- #: admin/partials/404-to-301-admin-display.php:34
524
- msgid "General"
525
- msgstr "Geral"
526
-
527
- #: admin/partials/404-to-301-admin-display.php:35
528
- msgid "Help & Info"
529
- msgstr "Ajuda e informações"
530
-
531
- #: admin/partials/404-to-301-admin-general-tab.php:30
532
  msgid "Redirect type"
533
  msgstr "Tipo de redireccionamento"
534
 
535
- #: admin/partials/404-to-301-admin-general-tab.php:33
536
- msgid "Redirect (SEO)"
537
- msgstr "Redireccionamento (SEO)"
538
 
539
- #: admin/partials/404-to-301-admin-general-tab.php:37
 
 
 
 
540
  msgid "Learn more"
541
  msgstr "Saiba mais"
542
 
543
- #: admin/partials/404-to-301-admin-general-tab.php:37
544
  msgid "about these redirect types"
545
  msgstr "sobre estes tipos de redireccionamento"
546
 
547
- #: admin/partials/404-to-301-admin-general-tab.php:44
548
- #: admin/partials/404-to-301-admin-general-tab.php:48
549
  msgid "Existing Page"
550
  msgstr "Página existente"
551
 
552
- #: admin/partials/404-to-301-admin-general-tab.php:45
553
- #: admin/partials/404-to-301-admin-general-tab.php:49
554
- #: admin/partials/404-to-301-admin-general-tab.php:66
555
  msgid "Custom URL"
556
  msgstr "URL personalizado"
557
 
558
- #: admin/partials/404-to-301-admin-general-tab.php:46
559
- #: admin/partials/404-to-301-admin-general-tab.php:50
560
  msgid "No Redirect"
561
  msgstr "Sem redireccionamento"
562
 
563
- #: admin/partials/404-to-301-admin-general-tab.php:48
564
  msgid "Select any WordPress page as a 404 page"
565
  msgstr "Seleccione qualquer página do WordPress como página 404"
566
 
567
- #: admin/partials/404-to-301-admin-general-tab.php:49
568
  msgid "Redirect 404 requests to a specific URL"
569
  msgstr "Redireccione pedidos 404 para um URL específico"
570
 
571
- #: admin/partials/404-to-301-admin-general-tab.php:50
572
  msgid "To disable redirect"
573
  msgstr "Para desactivar o redireccionamento"
574
 
575
- #: admin/partials/404-to-301-admin-general-tab.php:51
576
  msgid ""
577
  "You can override this by setting individual custom redirects from error logs "
578
  "list."
@@ -580,105 +237,430 @@ msgstr ""
580
  "Esta definição pode ser sobreposta por redireccionamentos personalizados "
581
  "individuais a partir da lista de registos de erros."
582
 
583
- #: admin/partials/404-to-301-admin-general-tab.php:55
584
  msgid "Select the page"
585
  msgstr "Seleccione a página"
586
 
587
- #: admin/partials/404-to-301-admin-general-tab.php:62
588
  msgid ""
589
- "The default 404 page will be replaced by the page you choose in this list"
590
  msgstr ""
591
- "A página 404 por omissão será substituída por uma página à escolha desta "
592
- "lista"
593
 
594
- #: admin/partials/404-to-301-admin-general-tab.php:69
595
- msgid "Enter any url"
596
- msgstr "Insira qualquer URL"
 
 
 
597
 
598
- #: admin/partials/404-to-301-admin-general-tab.php:69
599
- msgid "including"
600
- msgstr "incluindo"
601
 
602
- #: admin/partials/404-to-301-admin-general-tab.php:73
603
  msgid "Log 404 Errors"
604
  msgstr "Registar erros 404"
605
 
606
- #: admin/partials/404-to-301-admin-general-tab.php:76
607
- msgid "Enable Error Logs"
608
- msgstr "Activar registos de erros"
609
-
610
- #: admin/partials/404-to-301-admin-general-tab.php:77
611
- msgid "Disable Error Logs"
612
- msgstr "Desactivar registos de erros"
613
-
614
- #: admin/partials/404-to-301-admin-general-tab.php:79
615
  msgid "Enable/Disable Logging"
616
  msgstr "Activar/Desactivar registo"
617
 
618
- #: admin/partials/404-to-301-admin-general-tab.php:83
619
  msgid "Email notifications"
620
  msgstr "Notificações por email"
621
 
622
- #: admin/partials/404-to-301-admin-general-tab.php:90
623
  msgid ""
624
  "If you check this, an email will be sent on every 404 log on the admin email "
625
- "account"
626
  msgstr ""
627
- "Se activar esta opção, será enviado um email a cada registo de 404 para o "
628
- "email do administrador"
629
 
630
- #: admin/partials/404-to-301-admin-general-tab.php:94
631
  msgid "Email address"
632
  msgstr "Endereço de email"
633
 
634
- #: admin/partials/404-to-301-admin-general-tab.php:98
635
- msgid "Change the recipient email address for error log notifications"
636
  msgstr ""
637
- "Modifique o endereço de email do destinatário para as notificações de "
638
- "registo de erro"
639
 
640
- #: admin/partials/404-to-301-admin-general-tab.php:102
641
  msgid "Exclude paths"
642
  msgstr "Excluir caminhos"
643
 
644
- #: admin/partials/404-to-301-admin-general-tab.php:105
645
  msgid ""
646
  "If you want to exclude few paths from error logs, enter here. One per line."
647
  msgstr ""
648
  "Se quiser excluir alguns caminhos dos registos de erros, insira aqui, um por "
649
  "linha."
650
 
651
- #: admin/partials/404-to-301-admin-general-tab.php:110
652
- msgid "Save All Changes"
653
- msgstr "Guardar todas as alterações"
654
 
655
- #: public/class-404-to-301-public.php:61
656
- msgid "Bummer! You have one more 404"
657
- msgstr "Ups! Tem mais um 404."
 
 
 
 
 
 
 
 
658
 
659
- #: public/class-404-to-301-public.php:77
660
  msgid "Snap! One more 404 on "
661
  msgstr "Ups! Tem mais um 404 em "
662
 
663
- #. Plugin URI of the plugin/theme
664
- msgid "https://thefoxe.com/products/404-to-301/"
665
- msgstr "https://thefoxe.com/products/404-to-301/"
666
 
667
- #. Description of the plugin/theme
668
- msgid ""
669
- "Automatically redirect all <strong>404 errors</strong> to any page using "
670
- "<strong>301 redirect for SEO</strong>. You can <strong>redirect and log</"
671
- "strong> every 404 errors. No more 404 errors in Webmaster tool."
672
  msgstr ""
673
- "Redireccione automaticamente todos os <strong>erros 404</strong> para "
674
- "qualquer página através de <strong>redireccionamento 301 para SEO</strong>. "
675
- "Pode <strong>redireccionar e registar</strong> todos os erros 404. Ponha fim "
676
- "aos erros 404 na sua ferramenta de Webmaster."
677
-
678
- #. Author of the plugin/theme
679
- msgid "Joel James"
680
- msgstr "Joel James"
681
-
682
- #. Author URI of the plugin/theme
683
- msgid "https://thefoxe.com/"
684
- msgstr "https://thefoxe.com/"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: 404 to 301\n"
6
+ "POT-Creation-Date: 2018-06-20 00:50+0530\n"
7
+ "PO-Revision-Date: 2018-06-20 00:50+0530\n"
8
  "Last-Translator: Pedro Mendonça <ped.gaspar@gmail.com>\n"
9
  "Language-Team: Pedro Mendonça <ped.gaspar@gmail.com>\n"
10
  "Language: pt_PT\n"
12
  "Content-Type: text/plain; charset=UTF-8\n"
13
  "Content-Transfer-Encoding: 8bit\n"
14
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Generator: Poedit 1.8.7.1\n"
16
  "X-Poedit-SourceCharset: UTF-8\n"
17
  "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
18
  "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;"
21
  "X-Poedit-WPHeader: 404-to-301.php\n"
22
  "X-Poedit-SearchPath-0: .\n"
23
 
24
+ #: includes/admin/class-jj4t3-admin.php:127
25
  msgid "Custom Redirect"
26
  msgstr "Redireccionamento personalizado"
27
 
28
+ #: includes/admin/class-jj4t3-admin.php:151
29
+ #: includes/admin/class-jj4t3-admin.php:212
30
+ #: includes/admin/class-jj4t3-log-listing.php:47
31
  msgid "404 Error Logs"
32
  msgstr "Registos de erros 404"
33
 
34
+ #: includes/admin/class-jj4t3-admin.php:151
35
+ msgid "404 Errors"
36
+ msgstr ""
37
+
38
+ #: includes/admin/class-jj4t3-admin.php:157
39
  msgid "404 to 301 Settings"
40
  msgstr "Definições de 404 to 301"
41
 
42
+ #: includes/admin/class-jj4t3-admin.php:157
43
  msgid "404 Settings"
44
  msgstr "Definições de 404"
45
 
46
+ #: includes/admin/class-jj4t3-admin.php:186
47
  msgid "Error Logs"
48
  msgstr "Registos de erros"
49
 
50
+ #: includes/admin/class-jj4t3-admin.php:270 includes/admin/views/admin.php:21
 
 
51
  msgid "404 to 301"
52
  msgstr "404 to 301"
53
 
54
+ #: includes/admin/class-jj4t3-admin.php:339 includes/admin/views/admin.php:27
 
 
 
 
 
 
 
 
 
 
55
  msgid "Settings"
56
  msgstr "Definições"
57
 
58
+ #: includes/admin/class-jj4t3-admin.php:340
59
  msgid "Logs"
60
  msgstr "Registos"
61
 
62
+ #: includes/admin/class-jj4t3-log-listing.php:46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  msgid "404 Error Log"
64
  msgstr "Registo de erro 404"
65
 
66
+ #: includes/admin/class-jj4t3-log-listing.php:328
67
+ #: includes/functions/jj4t3-general-functions.php:317
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  msgid "Date"
69
  msgstr "Data"
70
 
71
+ #: includes/admin/class-jj4t3-log-listing.php:329
72
+ #: includes/functions/jj4t3-general-functions.php:318
73
+ #: includes/public/class-jj4t3-404-email.php:193
74
  msgid "404 Path"
75
  msgstr "Caminho de 404"
76
 
77
+ #: includes/admin/class-jj4t3-log-listing.php:330
78
+ #: includes/functions/jj4t3-general-functions.php:319
79
  msgid "From"
80
  msgstr "De"
81
 
82
+ #: includes/admin/class-jj4t3-log-listing.php:331
83
+ #: includes/functions/jj4t3-general-functions.php:320
84
+ #: includes/public/class-jj4t3-404-email.php:198
85
  msgid "IP Address"
86
  msgstr "Endereço IP"
87
 
88
+ #: includes/admin/class-jj4t3-log-listing.php:332
89
+ #: includes/functions/jj4t3-general-functions.php:321
90
  msgid "User Agent"
91
  msgstr "Agente do utilizador"
92
 
93
+ #: includes/admin/class-jj4t3-log-listing.php:333
94
+ msgid "Customization"
95
+ msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
+ #: includes/admin/class-jj4t3-log-listing.php:397
98
+ msgid "Ah! You are so clean that you still got ZERO errors."
99
+ msgstr ""
 
100
 
101
+ #: includes/admin/class-jj4t3-log-listing.php:475
102
+ msgid "Are you sure you want to delete this item?"
103
+ msgstr "Tem a certeza que quer eliminar este item?"
 
 
 
 
104
 
105
+ #: includes/admin/class-jj4t3-log-listing.php:477
106
+ msgid "Delete"
107
+ msgstr "Eliminar"
108
 
109
+ #: includes/admin/class-jj4t3-log-listing.php:624
110
+ #: includes/admin/views/custom-redirect.php:17
111
+ #: includes/admin/views/custom-redirect.php:25
112
+ #: includes/admin/views/custom-redirect.php:33
113
+ msgid "Default"
114
+ msgstr "Por omissão"
115
 
116
+ #: includes/admin/class-jj4t3-log-listing.php:626
117
+ msgid "Customize"
118
+ msgstr "Personalizar"
119
 
120
+ #: includes/admin/class-jj4t3-log-listing.php:696
121
+ msgid "Delete Selected"
122
+ msgstr "Eliminar seleccionados"
123
 
124
+ #: includes/admin/class-jj4t3-log-listing.php:697
125
+ msgid "Delete All"
126
+ msgstr "Eliminar tudo"
127
 
128
+ #: includes/admin/class-jj4t3-log-listing.php:698
129
+ msgid "Delete All (Keep redirects)"
130
+ msgstr ""
131
 
132
+ #: includes/admin/class-jj4t3-log-listing.php:735
133
+ msgid "Group by"
134
+ msgstr ""
135
 
136
+ #: includes/admin/class-jj4t3-log-listing.php:740
137
+ msgid "Apply"
138
+ msgstr "Aplicar"
139
 
140
+ #: includes/admin/views/admin.php:21
141
  #, php-format
142
+ msgid "by <a href=\"%s\">Joel James</a>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
+ #: includes/admin/views/custom-redirect.php:11
146
+ msgid "Redirecting from"
147
+ msgstr "Redireccionar de"
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
+ #: includes/admin/views/custom-redirect.php:15
150
+ #: includes/functions/jj4t3-general-functions.php:322
151
+ msgid "Redirect"
152
+ msgstr "Redireccionamento"
153
 
154
+ #: includes/admin/views/custom-redirect.php:18
155
+ #: includes/admin/views/custom-redirect.php:26
156
+ #: includes/admin/views/custom-redirect.php:34
157
+ msgid "Enable"
158
  msgstr ""
 
 
159
 
160
+ #: includes/admin/views/custom-redirect.php:19
161
+ #: includes/admin/views/custom-redirect.php:27
162
+ #: includes/admin/views/custom-redirect.php:35
163
+ msgid "Disable"
164
  msgstr ""
 
 
165
 
166
+ #: includes/admin/views/custom-redirect.php:23
167
+ msgid "Error logging"
168
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
+ #: includes/admin/views/custom-redirect.php:31
171
+ msgid "Email alert"
172
+ msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
+ #: includes/admin/views/custom-redirect.php:39
175
+ #: includes/admin/views/settings.php:30
176
  msgid "Redirect to"
177
  msgstr "Redireccionar para"
178
 
179
+ #: includes/admin/views/custom-redirect.php:42
180
  msgid ""
181
  "Enter the url if you want to set custom redirect for above 404 path. Enter "
182
  "the full url including http://. Leave empty if you want to follow deafult "
183
+ "settings."
184
  msgstr ""
 
 
 
185
 
186
+ #: includes/admin/views/custom-redirect.php:51
187
+ #: includes/admin/views/settings.php:17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  msgid "Redirect type"
189
  msgstr "Tipo de redireccionamento"
190
 
191
+ #: includes/admin/views/custom-redirect.php:58
192
+ msgid "Select redirect type to override default one."
193
+ msgstr ""
194
 
195
+ #: includes/admin/views/custom-redirect.php:65
196
+ msgid "Save Redirect"
197
+ msgstr "Guardar redireccionamento"
198
+
199
+ #: includes/admin/views/settings.php:24
200
  msgid "Learn more"
201
  msgstr "Saiba mais"
202
 
203
+ #: includes/admin/views/settings.php:24
204
  msgid "about these redirect types"
205
  msgstr "sobre estes tipos de redireccionamento"
206
 
207
+ #: includes/admin/views/settings.php:33 includes/admin/views/settings.php:37
 
208
  msgid "Existing Page"
209
  msgstr "Página existente"
210
 
211
+ #: includes/admin/views/settings.php:34 includes/admin/views/settings.php:38
212
+ #: includes/admin/views/settings.php:52
 
213
  msgid "Custom URL"
214
  msgstr "URL personalizado"
215
 
216
+ #: includes/admin/views/settings.php:35 includes/admin/views/settings.php:39
 
217
  msgid "No Redirect"
218
  msgstr "Sem redireccionamento"
219
 
220
+ #: includes/admin/views/settings.php:37
221
  msgid "Select any WordPress page as a 404 page"
222
  msgstr "Seleccione qualquer página do WordPress como página 404"
223
 
224
+ #: includes/admin/views/settings.php:38
225
  msgid "Redirect 404 requests to a specific URL"
226
  msgstr "Redireccione pedidos 404 para um URL específico"
227
 
228
+ #: includes/admin/views/settings.php:39
229
  msgid "To disable redirect"
230
  msgstr "Para desactivar o redireccionamento"
231
 
232
+ #: includes/admin/views/settings.php:40
233
  msgid ""
234
  "You can override this by setting individual custom redirects from error logs "
235
  "list."
237
  "Esta definição pode ser sobreposta por redireccionamentos personalizados "
238
  "individuais a partir da lista de registos de erros."
239
 
240
+ #: includes/admin/views/settings.php:44
241
  msgid "Select the page"
242
  msgstr "Seleccione a página"
243
 
244
+ #: includes/admin/views/settings.php:47
245
  msgid ""
246
+ "The default 404 page will be replaced by the page you choose in this list."
247
  msgstr ""
 
 
248
 
249
+ #: includes/admin/views/settings.php:48
250
+ #, php-format
251
+ msgid ""
252
+ "You can <a href=\"%s\" target=\"_blank\">create a custom 404</a> page and "
253
+ "assign that page here."
254
+ msgstr ""
255
 
256
+ #: includes/admin/views/settings.php:55
257
+ msgid "Enter any url (including http://)"
258
+ msgstr ""
259
 
260
+ #: includes/admin/views/settings.php:59
261
  msgid "Log 404 Errors"
262
  msgstr "Registar erros 404"
263
 
264
+ #: includes/admin/views/settings.php:62
 
 
 
 
 
 
 
 
265
  msgid "Enable/Disable Logging"
266
  msgstr "Activar/Desactivar registo"
267
 
268
+ #: includes/admin/views/settings.php:66
269
  msgid "Email notifications"
270
  msgstr "Notificações por email"
271
 
272
+ #: includes/admin/views/settings.php:69
273
  msgid ""
274
  "If you check this, an email will be sent on every 404 log on the admin email "
275
+ "account."
276
  msgstr ""
 
 
277
 
278
+ #: includes/admin/views/settings.php:73
279
  msgid "Email address"
280
  msgstr "Endereço de email"
281
 
282
+ #: includes/admin/views/settings.php:77
283
+ msgid "Change the recipient email address for error log notifications."
284
  msgstr ""
 
 
285
 
286
+ #: includes/admin/views/settings.php:81
287
  msgid "Exclude paths"
288
  msgstr "Excluir caminhos"
289
 
290
+ #: includes/admin/views/settings.php:84
291
  msgid ""
292
  "If you want to exclude few paths from error logs, enter here. One per line."
293
  msgstr ""
294
  "Se quiser excluir alguns caminhos dos registos de erros, insira aqui, um por "
295
  "linha."
296
 
297
+ #: includes/admin/views/settings.php:89
298
+ msgid "Save settings"
299
+ msgstr ""
300
 
301
+ #: includes/functions/jj4t3-general-functions.php:283
302
+ msgid "301 Redirect (SEO)"
303
+ msgstr ""
304
+
305
+ #: includes/functions/jj4t3-general-functions.php:284
306
+ msgid "302 Redirect"
307
+ msgstr ""
308
+
309
+ #: includes/functions/jj4t3-general-functions.php:285
310
+ msgid "307 Redirect"
311
+ msgstr ""
312
 
313
+ #: includes/public/class-jj4t3-404-email.php:141
314
  msgid "Snap! One more 404 on "
315
  msgstr "Ups! Tem mais um 404 em "
316
 
317
+ #: includes/public/class-jj4t3-404-email.php:189
318
+ msgid "Bummer! You have one more 404"
319
+ msgstr "Ups! Tem mais um 404."
320
 
321
+ #: includes/public/class-jj4t3-404-email.php:203
322
+ msgid "Time"
 
 
 
323
  msgstr ""
324
+
325
+ #: includes/public/class-jj4t3-404-email.php:208
326
+ msgid "Referral Page"
327
+ msgstr ""
328
+
329
+ #~ msgid "Thank you for choosing 404 to 301 to improve your website"
330
+ #~ msgstr "Obrigado por escolher o 404 to 301 para optimizar o seu site"
331
+
332
+ #~ msgid "Kindly give this plugin a %srating%s"
333
+ #~ msgstr "Por favor, atribua a este plugin uma %sclassificação%s"
334
+
335
+ #~ msgid "Settings Data"
336
+ #~ msgstr "Dados das definições"
337
+
338
+ #~ msgid "Basic Details"
339
+ #~ msgstr "Detalhes básicos"
340
+
341
+ #~ msgid "WordPress Version"
342
+ #~ msgstr "Versão do WordPress"
343
+
344
+ #~ msgid "PHP Version"
345
+ #~ msgstr "Versão do PHP"
346
+
347
+ #~ msgid "Plugin Version"
348
+ #~ msgstr "Versão do plugin"
349
+
350
+ #~ msgid "Home Page"
351
+ #~ msgstr "Página inicial"
352
+
353
+ #~ msgid "Active Theme Details"
354
+ #~ msgstr "Detalhes do tema activo"
355
+
356
+ #~ msgid "Name"
357
+ #~ msgstr "Nome"
358
+
359
+ #~ msgid "Version"
360
+ #~ msgstr "Versão"
361
+
362
+ #~ msgid "Theme URI"
363
+ #~ msgstr "URI do tema"
364
+
365
+ #~ msgid "Active Plugins"
366
+ #~ msgstr "Plugins activos"
367
+
368
+ #~ msgid "Ulta pulta..! Seems like you had no errors to log."
369
+ #~ msgstr "Ena! Parece que não ocorreu nenhum erro para registar."
370
+
371
+ #~ msgid "N/A"
372
+ #~ msgstr "Não disponível"
373
+
374
+ #~ msgid "List View"
375
+ #~ msgstr "Vista de lista"
376
+
377
+ #~ msgid "Excerpt View"
378
+ #~ msgstr "Vista de excerto"
379
+
380
+ #~ msgid "No items found."
381
+ #~ msgstr "Nenhum item encontrado."
382
+
383
+ #~ msgid "Select bulk action"
384
+ #~ msgstr "Seleccionar acção por lotes"
385
+
386
+ #~ msgid "Bulk Actions"
387
+ #~ msgstr "Acções por lotes"
388
+
389
+ #~ msgid "Show more details"
390
+ #~ msgstr "Ver mais detalhes"
391
+
392
+ #~ msgid "Filter by date"
393
+ #~ msgstr "Filtrar por data"
394
+
395
+ #~ msgid "All dates"
396
+ #~ msgstr "Todas as datas"
397
+
398
+ #~ msgid "%1$s %2$d"
399
+ #~ msgstr "%1$s de %2$d"
400
+
401
+ #~ msgid "%s comment"
402
+ #~ msgid_plural "%s comments"
403
+ #~ msgstr[0] "%s comentário"
404
+ #~ msgstr[1] "%s comentários"
405
+
406
+ #~ msgid "%s approved comment"
407
+ #~ msgid_plural "%s approved comments"
408
+ #~ msgstr[0] "%s comentário aprovado"
409
+ #~ msgstr[1] "%s comentários aprovados"
410
+
411
+ #~ msgid "%s pending comment"
412
+ #~ msgid_plural "%s pending comments"
413
+ #~ msgstr[0] "%s comentário pendente"
414
+ #~ msgstr[1] "%s comentários pendentes"
415
+
416
+ #~ msgid "No comments"
417
+ #~ msgstr "Sem comentários"
418
+
419
+ #~ msgid "No approved comments"
420
+ #~ msgstr "Sem comentários aprovados"
421
+
422
+ #~ msgid "No pending comments"
423
+ #~ msgstr "Não há comentários pendentes"
424
+
425
+ #~ msgid "%s item"
426
+ #~ msgid_plural "%s items"
427
+ #~ msgstr[0] "%s item"
428
+ #~ msgstr[1] "%s itens"
429
+
430
+ #~ msgid "First page"
431
+ #~ msgstr "Primeira página"
432
+
433
+ #~ msgid "Previous page"
434
+ #~ msgstr "Página anterior"
435
+
436
+ #~ msgid "Current Page"
437
+ #~ msgstr "Página actual"
438
+
439
+ #~ msgctxt "paging"
440
+ #~ msgid "%1$s of %2$s"
441
+ #~ msgstr "%1$s de %2$s"
442
+
443
+ #~ msgid "Next page"
444
+ #~ msgstr "Página seguinte"
445
+
446
+ #~ msgid "Last page"
447
+ #~ msgstr "Última página"
448
+
449
+ #~ msgid "Select All"
450
+ #~ msgstr "Seleccionar tudo"
451
+
452
+ #~ msgid "%s pending"
453
+ #~ msgstr "%s pendente(s)"
454
+
455
+ #~ msgid "1 item"
456
+ #~ msgid_plural "%s items"
457
+ #~ msgstr[0] "1 item"
458
+ #~ msgstr[1] "%s itens"
459
+
460
+ #~ msgid "Go to the first page"
461
+ #~ msgstr "Ir para a primeira página"
462
+
463
+ #~ msgid "Go to the previous page"
464
+ #~ msgstr "Ir para a página anterior"
465
+
466
+ #~ msgid "Select Page"
467
+ #~ msgstr "Seleccionar página"
468
+
469
+ #~ msgid "Go to the next page"
470
+ #~ msgstr "Ir para a página seguinte"
471
+
472
+ #~ msgid "Go to the last page"
473
+ #~ msgstr "Ir para a última página"
474
+
475
+ #~ msgid "I accept"
476
+ #~ msgstr "Aceito"
477
+
478
+ #~ msgid "I do not accept"
479
+ #~ msgstr "Não aceito"
480
+
481
+ #~ msgid "About the plugin & developer"
482
+ #~ msgstr "Sobre o plugin e o programador"
483
+
484
+ #~ msgid "Yo %s!"
485
+ #~ msgstr "Olá %s!"
486
+
487
+ #~ msgid "Thank you for using 404 to 301"
488
+ #~ msgstr "Obrigado por utilizar o 404 to 301."
489
+
490
+ #~ msgid "This plugin is brought to you by"
491
+ #~ msgstr "Este plugin é desenvolvido por"
492
+
493
+ #~ msgid "Visit author website"
494
+ #~ msgstr "Visite o website do autor"
495
+
496
+ #~ msgid "a web store developed and managed by Joel James."
497
+ #~ msgstr "uma loja online desenvolvida e gerida por Joel James."
498
+
499
+ #~ msgid "So you installed this plugin and how is it doing? Feel free to"
500
+ #~ msgstr ""
501
+ #~ "Então, instalou este plugin, que tal está a correr? Sinta-se à vontade "
502
+ #~ "para"
503
+
504
+ #~ msgid "Contact the developer"
505
+ #~ msgstr "Contacte o programador"
506
+
507
+ #~ msgid "get in touch with me"
508
+ #~ msgstr "entrar em contacto comigo"
509
+
510
+ #~ msgid "anytime for help. I am always happy to help."
511
+ #~ msgstr "a qualquer momento para ajuda. Tenho o maior prazer em ajudar."
512
+
513
+ #~ msgid "Debugging Data"
514
+ #~ msgstr "Dados de depuração"
515
+
516
+ #~ msgid "Plugin Information"
517
+ #~ msgstr "Informações do plugin"
518
+
519
+ #~ msgid "Author"
520
+ #~ msgstr "Autor"
521
+
522
+ #~ msgid "Visit plugin website"
523
+ #~ msgstr "Visite o site do plugin"
524
+
525
+ #~ msgid "Plugin documentation"
526
+ #~ msgstr "Documentação do plugin"
527
+
528
+ #~ msgid "More details about the plugin"
529
+ #~ msgstr "Mais detalhes sobre o plugin"
530
+
531
+ #~ msgid "Need help?"
532
+ #~ msgstr "Precisa de ajuda?"
533
+
534
+ #~ msgid "Contact support"
535
+ #~ msgstr "Contacte o suporte"
536
+
537
+ #~ msgid "Disable UAN"
538
+ #~ msgstr "Desactivar UAN"
539
+
540
+ #~ msgid "Enable UAN"
541
+ #~ msgstr "Activar UAN"
542
+
543
+ #~ msgid "Log Manager Addon"
544
+ #~ msgstr "Addon Log Manager"
545
+
546
+ #~ msgid ""
547
+ #~ "Error Log Manager addon is available for 404 to 301 now. Make 404 error "
548
+ #~ "management more easy."
549
+ #~ msgstr ""
550
+ #~ "O addon Log Manager está agora disponível para o 404 to 301. Torne a "
551
+ #~ "gestão de erros 404 mais fácil."
552
+
553
+ #~ msgid ""
554
+ #~ "Instead of email alerts on every error, get Hourly, Daily, Twice a day, "
555
+ #~ "Weekly, Twice a week email alerts."
556
+ #~ msgstr ""
557
+ #~ "Em vez de emails de alerta por cada erro, receba emails de alerta a cada "
558
+ #~ "hora, uma a duas vezes por dia, ou uma a duas vezes por semana."
559
+
560
+ #~ msgid "Automatically clear old error logs after few days to reduce db load."
561
+ #~ msgstr ""
562
+ #~ "Limpeza automática de registos de erros antigos após alguns dias, para "
563
+ #~ "reduzir o peso da base de dados."
564
+
565
+ #~ msgid "See More Details"
566
+ #~ msgstr "Ver mais detalhes"
567
+
568
+ #~ msgid "Like the plugin"
569
+ #~ msgstr "Gosta do plugin"
570
+
571
+ #~ msgid "Rate now"
572
+ #~ msgstr "Classificar agora"
573
+
574
+ #~ msgid "Rate this on WordPress"
575
+ #~ msgstr "Dê uma classificação no WordPress"
576
+
577
+ #~ msgid "Donate now"
578
+ #~ msgstr "Fazer donativo agora"
579
+
580
+ #~ msgid "Make a small donation"
581
+ #~ msgstr "Faça um pequeno donativo"
582
+
583
+ #~ msgid "Contribute now"
584
+ #~ msgstr "Contribuir agora"
585
+
586
+ #~ msgid "Contribute to the Plugin"
587
+ #~ msgstr "Contribua para o plugin"
588
+
589
+ #~ msgid "Tweet now"
590
+ #~ msgstr "Publicar no Twitter agora"
591
+
592
+ #~ msgid "Tweet about the Plugin"
593
+ #~ msgstr "Publique no Twitter sobre o plugin"
594
+
595
+ #~ msgid ""
596
+ #~ "Enter the url if you want to set custom redirect for above 404 path. "
597
+ #~ "Enter the full url including http://. Leave empty if you want to follow "
598
+ #~ "deafult settings"
599
+ #~ msgstr ""
600
+ #~ "Insira o URL pretendido para o redireccionamento personalizado do caminho "
601
+ #~ "404 acima. Insira o caminho completo do URL incluindo http://. Deixe em "
602
+ #~ "branco para utilizar as definições por omissão."
603
+
604
+ #~ msgid "settings updated successfully"
605
+ #~ msgstr "definições actualizadas com sucesso"
606
+
607
+ #~ msgid "General"
608
+ #~ msgstr "Geral"
609
+
610
+ #~ msgid "Help & Info"
611
+ #~ msgstr "Ajuda e informações"
612
+
613
+ #~ msgid "Redirect (SEO)"
614
+ #~ msgstr "Redireccionamento (SEO)"
615
+
616
+ #~ msgid ""
617
+ #~ "The default 404 page will be replaced by the page you choose in this list"
618
+ #~ msgstr ""
619
+ #~ "A página 404 por omissão será substituída por uma página à escolha desta "
620
+ #~ "lista"
621
+
622
+ #~ msgid "Enter any url"
623
+ #~ msgstr "Insira qualquer URL"
624
+
625
+ #~ msgid "including"
626
+ #~ msgstr "incluindo"
627
+
628
+ #~ msgid "Enable Error Logs"
629
+ #~ msgstr "Activar registos de erros"
630
+
631
+ #~ msgid "Disable Error Logs"
632
+ #~ msgstr "Desactivar registos de erros"
633
+
634
+ #~ msgid ""
635
+ #~ "If you check this, an email will be sent on every 404 log on the admin "
636
+ #~ "email account"
637
+ #~ msgstr ""
638
+ #~ "Se activar esta opção, será enviado um email a cada registo de 404 para o "
639
+ #~ "email do administrador"
640
+
641
+ #~ msgid "Change the recipient email address for error log notifications"
642
+ #~ msgstr ""
643
+ #~ "Modifique o endereço de email do destinatário para as notificações de "
644
+ #~ "registo de erro"
645
+
646
+ #~ msgid "Save All Changes"
647
+ #~ msgstr "Guardar todas as alterações"
648
+
649
+ #~ msgid "https://thefoxe.com/products/404-to-301/"
650
+ #~ msgstr "https://thefoxe.com/products/404-to-301/"
651
+
652
+ #~ msgid ""
653
+ #~ "Automatically redirect all <strong>404 errors</strong> to any page using "
654
+ #~ "<strong>301 redirect for SEO</strong>. You can <strong>redirect and log</"
655
+ #~ "strong> every 404 errors. No more 404 errors in Webmaster tool."
656
+ #~ msgstr ""
657
+ #~ "Redireccione automaticamente todos os <strong>erros 404</strong> para "
658
+ #~ "qualquer página através de <strong>redireccionamento 301 para SEO</"
659
+ #~ "strong>. Pode <strong>redireccionar e registar</strong> todos os erros "
660
+ #~ "404. Ponha fim aos erros 404 na sua ferramenta de Webmaster."
661
+
662
+ #~ msgid "Joel James"
663
+ #~ msgstr "Joel James"
664
+
665
+ #~ msgid "https://thefoxe.com/"
666
+ #~ msgstr "https://thefoxe.com/"
languages/404-to-301.pot CHANGED
@@ -2,14 +2,14 @@
2
  msgid ""
3
  msgstr ""
4
  "Project-Id-Version: 404 to 301\n"
5
- "POT-Creation-Date: 2016-06-02 14:02+0100\n"
6
  "PO-Revision-Date: 2016-03-22 23:53+0000\n"
7
  "Language-Team: \n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
12
- "X-Generator: Poedit 1.8.8\n"
13
  "X-Poedit-SourceCharset: UTF-8\n"
14
  "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
15
  "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;"
@@ -19,666 +19,303 @@ msgstr ""
19
  "Last-Translator: \n"
20
  "X-Poedit-SearchPath-0: .\n"
21
 
22
- #: admin/class-404-to-301-admin.php:171 admin/class-404-to-301-admin.php:172
23
- #: admin/class-404-to-301-admin.php:262 admin/class-404-to-301-logs.php:64
 
 
 
 
 
24
  msgid "404 Error Logs"
25
  msgstr ""
26
 
27
- #: admin/class-404-to-301-admin.php:185
 
 
 
 
28
  msgid "404 to 301 Settings"
29
  msgstr ""
30
 
31
- #: admin/class-404-to-301-admin.php:186
32
  msgid "404 Settings"
33
  msgstr ""
34
 
35
- #: admin/class-404-to-301-admin.php:224
36
  msgid "Error Logs"
37
  msgstr ""
38
 
39
- #. Plugin Name of the plugin/theme
40
- #: admin/class-404-to-301-admin.php:297
41
- #: admin/partials/404-to-301-admin-credits-tab.php:52
42
  msgid "404 to 301"
43
  msgstr ""
44
 
45
- #: admin/class-404-to-301-admin.php:353
46
- msgid "Thank you for choosing 404 to 301 to improve your website"
47
- msgstr ""
48
-
49
- #: admin/class-404-to-301-admin.php:355
50
- #, php-format
51
- msgid "Kindly give this plugin a %srating%s"
52
- msgstr ""
53
-
54
- #: admin/class-404-to-301-admin.php:377
55
- #: admin/partials/404-to-301-admin-display.php:27
56
  msgid "Settings"
57
  msgstr ""
58
 
59
- #: admin/class-404-to-301-admin.php:378
60
  msgid "Logs"
61
  msgstr ""
62
 
63
- #: admin/class-404-to-301-admin.php:535
64
- msgid "Settings Data"
65
- msgstr ""
66
-
67
- #: admin/class-404-to-301-admin.php:542
68
- msgid "Basic Details"
69
- msgstr ""
70
-
71
- #: admin/class-404-to-301-admin.php:543
72
- msgid "WordPress Version"
73
- msgstr ""
74
-
75
- #: admin/class-404-to-301-admin.php:544
76
- msgid "PHP Version"
77
- msgstr ""
78
-
79
- #: admin/class-404-to-301-admin.php:545
80
- msgid "Plugin Version"
81
- msgstr ""
82
-
83
- #: admin/class-404-to-301-admin.php:546
84
- msgid "Home Page"
85
- msgstr ""
86
-
87
- #: admin/class-404-to-301-admin.php:550
88
- msgid "Active Theme Details"
89
- msgstr ""
90
-
91
- #: admin/class-404-to-301-admin.php:551
92
- #: admin/partials/404-to-301-admin-credits-tab.php:51
93
- msgid "Name"
94
- msgstr ""
95
-
96
- #: admin/class-404-to-301-admin.php:552
97
- #: admin/partials/404-to-301-admin-credits-tab.php:55
98
- msgid "Version"
99
- msgstr ""
100
-
101
- #: admin/class-404-to-301-admin.php:553
102
- msgid "Theme URI"
103
- msgstr ""
104
-
105
- #: admin/class-404-to-301-admin.php:558
106
- msgid "Active Plugins"
107
- msgstr ""
108
-
109
- #: admin/class-404-to-301-logs.php:63
110
  msgid "404 Error Log"
111
  msgstr ""
112
 
113
- #: admin/class-404-to-301-logs.php:203
114
- msgid "Ulta pulta..! Seems like you had no errors to log."
115
- msgstr ""
116
-
117
- #: admin/class-404-to-301-logs.php:269
118
- msgid "Default"
119
- msgstr ""
120
-
121
- #: admin/class-404-to-301-logs.php:271
122
- msgid "Customize"
123
- msgstr ""
124
-
125
- #: admin/class-404-to-301-logs.php:293
126
- msgid "Are you sure you want to delete this item?"
127
- msgstr ""
128
-
129
- #: admin/class-404-to-301-logs.php:296
130
- msgid "Delete"
131
- msgstr ""
132
-
133
- #: admin/class-404-to-301-logs.php:400
134
  msgid "Date"
135
  msgstr ""
136
 
137
- #: admin/class-404-to-301-logs.php:401 public/class-404-to-301-public.php:68
 
 
138
  msgid "404 Path"
139
  msgstr ""
140
 
141
- #: admin/class-404-to-301-logs.php:402
 
142
  msgid "From"
143
  msgstr ""
144
 
145
- #: admin/class-404-to-301-logs.php:403 public/class-404-to-301-public.php:64
 
 
146
  msgid "IP Address"
147
  msgstr ""
148
 
149
- #: admin/class-404-to-301-logs.php:404 public/class-404-to-301-public.php:72
 
150
  msgid "User Agent"
151
  msgstr ""
152
 
153
- #: admin/class-404-to-301-logs.php:405
154
- #: admin/partials/404-to-301-admin-general-tab.php:34
155
- #: admin/partials/404-to-301-admin-general-tab.php:35
156
- msgid "Redirect"
157
- msgstr ""
158
-
159
- #: admin/class-404-to-301-logs.php:448
160
- msgid "Delete Selected"
161
- msgstr ""
162
-
163
- #: admin/class-404-to-301-logs.php:449
164
- msgid "Delete All"
165
- msgstr ""
166
-
167
- #: admin/class-404-to-301-logs.php:588
168
- msgid "N/A"
169
- msgstr ""
170
-
171
- #: admin/core/class-wp-list-table-4.4.php:162
172
- #: admin/core/class-wp-list-table-old.php:144
173
- #: admin/core/class-wp-list-table.php:162
174
- msgid "List View"
175
- msgstr ""
176
-
177
- #: admin/core/class-wp-list-table-4.4.php:163
178
- #: admin/core/class-wp-list-table-old.php:145
179
- #: admin/core/class-wp-list-table.php:163
180
- msgid "Excerpt View"
181
- msgstr ""
182
-
183
- #: admin/core/class-wp-list-table-4.4.php:334
184
- #: admin/core/class-wp-list-table-old.php:312
185
- #: admin/core/class-wp-list-table.php:334
186
- msgid "No items found."
187
- msgstr ""
188
-
189
- #: admin/core/class-wp-list-table-4.4.php:462
190
- #: admin/core/class-wp-list-table-old.php:438
191
- #: admin/core/class-wp-list-table.php:462
192
- msgid "Select bulk action"
193
  msgstr ""
194
 
195
- #: admin/core/class-wp-list-table-4.4.php:464
196
- #: admin/core/class-wp-list-table-old.php:440
197
- #: admin/core/class-wp-list-table.php:464
198
- msgid "Bulk Actions"
199
- msgstr ""
200
-
201
- #: admin/core/class-wp-list-table-4.4.php:474
202
- #: admin/core/class-wp-list-table-old.php:450
203
- #: admin/core/class-wp-list-table.php:474
204
- msgid "Apply"
205
- msgstr ""
206
-
207
- #: admin/core/class-wp-list-table-4.4.php:524
208
- #: admin/core/class-wp-list-table-4.4.php:1324
209
- #: admin/core/class-wp-list-table.php:524
210
- #: admin/core/class-wp-list-table.php:1324
211
- msgid "Show more details"
212
- msgstr ""
213
-
214
- #: admin/core/class-wp-list-table-4.4.php:587
215
- #: admin/core/class-wp-list-table-old.php:550
216
- #: admin/core/class-wp-list-table.php:587
217
- msgid "Filter by date"
218
- msgstr ""
219
-
220
- #: admin/core/class-wp-list-table-4.4.php:589
221
- #: admin/core/class-wp-list-table-old.php:552
222
- #: admin/core/class-wp-list-table.php:589
223
- msgid "All dates"
224
- msgstr ""
225
-
226
- #. translators: 1: month name, 2: 4-digit year
227
- #: admin/core/class-wp-list-table-4.4.php:602
228
- #: admin/core/class-wp-list-table-old.php:565
229
- #: admin/core/class-wp-list-table.php:602
230
- #, php-format
231
- msgid "%1$s %2$d"
232
  msgstr ""
233
 
234
- #: admin/core/class-wp-list-table-4.4.php:654
235
- #: admin/core/class-wp-list-table.php:654
236
- #, php-format
237
- msgid "%s comment"
238
- msgid_plural "%s comments"
239
- msgstr[0] ""
240
- msgstr[1] ""
241
-
242
- #: admin/core/class-wp-list-table-4.4.php:655
243
- #: admin/core/class-wp-list-table.php:655
244
- #, php-format
245
- msgid "%s approved comment"
246
- msgid_plural "%s approved comments"
247
- msgstr[0] ""
248
- msgstr[1] ""
249
-
250
- #: admin/core/class-wp-list-table-4.4.php:656
251
- #: admin/core/class-wp-list-table.php:656
252
- #, php-format
253
- msgid "%s pending comment"
254
- msgid_plural "%s pending comments"
255
- msgstr[0] ""
256
- msgstr[1] ""
257
-
258
- #: admin/core/class-wp-list-table-4.4.php:661
259
- #: admin/core/class-wp-list-table-4.4.php:673
260
- #: admin/core/class-wp-list-table-4.4.php:686
261
- #: admin/core/class-wp-list-table.php:661
262
- #: admin/core/class-wp-list-table.php:673
263
- #: admin/core/class-wp-list-table.php:686
264
- msgid "No comments"
265
- msgstr ""
266
-
267
- #: admin/core/class-wp-list-table-4.4.php:673
268
- #: admin/core/class-wp-list-table.php:673
269
- msgid "No approved comments"
270
- msgstr ""
271
-
272
- #: admin/core/class-wp-list-table-4.4.php:686
273
- #: admin/core/class-wp-list-table.php:686
274
- msgid "No pending comments"
275
- msgstr ""
276
-
277
- #: admin/core/class-wp-list-table-4.4.php:763
278
- #: admin/core/class-wp-list-table-4.4.php:1349
279
- #: admin/core/class-wp-list-table.php:763
280
- #: admin/core/class-wp-list-table.php:1349
281
- #, php-format
282
- msgid "%s item"
283
- msgid_plural "%s items"
284
- msgstr[0] ""
285
- msgstr[1] ""
286
-
287
- #: admin/core/class-wp-list-table-4.4.php:798
288
- #: admin/core/class-wp-list-table.php:798
289
- msgid "First page"
290
- msgstr ""
291
-
292
- #: admin/core/class-wp-list-table-4.4.php:808
293
- #: admin/core/class-wp-list-table.php:808
294
- msgid "Previous page"
295
- msgstr ""
296
-
297
- #: admin/core/class-wp-list-table-4.4.php:815
298
- #: admin/core/class-wp-list-table-4.4.php:818
299
- #: admin/core/class-wp-list-table-old.php:727
300
- #: admin/core/class-wp-list-table.php:815
301
- #: admin/core/class-wp-list-table.php:818
302
- msgid "Current Page"
303
- msgstr ""
304
-
305
- #: admin/core/class-wp-list-table-4.4.php:824
306
- #: admin/core/class-wp-list-table-old.php:733
307
- #: admin/core/class-wp-list-table.php:824
308
- #, php-format
309
- msgctxt "paging"
310
- msgid "%1$s of %2$s"
311
- msgstr ""
312
-
313
- #: admin/core/class-wp-list-table-4.4.php:831
314
- #: admin/core/class-wp-list-table.php:831
315
- msgid "Next page"
316
- msgstr ""
317
-
318
- #: admin/core/class-wp-list-table-4.4.php:841
319
- #: admin/core/class-wp-list-table.php:841
320
- msgid "Last page"
321
- msgstr ""
322
-
323
- #: admin/core/class-wp-list-table-4.4.php:1069
324
- #: admin/core/class-wp-list-table-old.php:881
325
- #: admin/core/class-wp-list-table.php:1069
326
- msgid "Select All"
327
- msgstr ""
328
-
329
- #: admin/core/class-wp-list-table-old.php:612
330
- #, php-format
331
- msgid "%s pending"
332
  msgstr ""
333
 
334
- #: admin/core/class-wp-list-table-old.php:691
335
- #: admin/core/class-wp-list-table-old.php:1115
336
- #, php-format
337
- msgid "1 item"
338
- msgid_plural "%s items"
339
- msgstr[0] ""
340
- msgstr[1] ""
341
-
342
- #: admin/core/class-wp-list-table-old.php:710
343
- msgid "Go to the first page"
344
  msgstr ""
345
 
346
- #: admin/core/class-wp-list-table-old.php:717
347
- msgid "Go to the previous page"
 
 
 
348
  msgstr ""
349
 
350
- #: admin/core/class-wp-list-table-old.php:726
351
- msgid "Select Page"
352
  msgstr ""
353
 
354
- #: admin/core/class-wp-list-table-old.php:737
355
- msgid "Go to the next page"
356
  msgstr ""
357
 
358
- #: admin/core/class-wp-list-table-old.php:744
359
- msgid "Go to the last page"
360
  msgstr ""
361
 
362
- #: admin/partials/404-to-301-admin-agreement-tab.php:48
363
- msgid "I accept"
364
  msgstr ""
365
 
366
- #: admin/partials/404-to-301-admin-agreement-tab.php:49
367
- msgid "I do not accept"
368
  msgstr ""
369
 
370
- #: admin/partials/404-to-301-admin-credits-tab.php:12
371
- msgid "About the plugin & developer"
372
  msgstr ""
373
 
374
- #: admin/partials/404-to-301-admin-credits-tab.php:20
375
  #, php-format
376
- msgid "Yo %s!"
377
- msgstr ""
378
-
379
- #: admin/partials/404-to-301-admin-credits-tab.php:20
380
- msgid "Thank you for using 404 to 301"
381
- msgstr ""
382
-
383
- #: admin/partials/404-to-301-admin-credits-tab.php:22
384
- msgid "This plugin is brought to you by"
385
- msgstr ""
386
-
387
- #: admin/partials/404-to-301-admin-credits-tab.php:22
388
- #: admin/partials/404-to-301-admin-credits-tab.php:59
389
- msgid "Visit author website"
390
- msgstr ""
391
-
392
- #: admin/partials/404-to-301-admin-credits-tab.php:22
393
- msgid "a web store developed and managed by Joel James."
394
- msgstr ""
395
-
396
- #: admin/partials/404-to-301-admin-credits-tab.php:28
397
- msgid "So you installed this plugin and how is it doing? Feel free to"
398
- msgstr ""
399
-
400
- #: admin/partials/404-to-301-admin-credits-tab.php:28
401
- msgid "Contact the developer"
402
- msgstr ""
403
-
404
- #: admin/partials/404-to-301-admin-credits-tab.php:28
405
- msgid "get in touch with me"
406
- msgstr ""
407
-
408
- #: admin/partials/404-to-301-admin-credits-tab.php:28
409
- msgid "anytime for help. I am always happy to help."
410
- msgstr ""
411
-
412
- #: admin/partials/404-to-301-admin-credits-tab.php:35
413
- msgid "Debugging Data"
414
- msgstr ""
415
-
416
- #: admin/partials/404-to-301-admin-credits-tab.php:48
417
- msgid "Plugin Information"
418
- msgstr ""
419
-
420
- #: admin/partials/404-to-301-admin-credits-tab.php:59
421
- msgid "Author"
422
- msgstr ""
423
-
424
- #: admin/partials/404-to-301-admin-credits-tab.php:63
425
- #: admin/partials/404-to-301-admin-credits-tab.php:67
426
- msgid "Visit plugin website"
427
- msgstr ""
428
-
429
- #: admin/partials/404-to-301-admin-credits-tab.php:63
430
- msgid "Plugin documentation"
431
- msgstr ""
432
-
433
- #: admin/partials/404-to-301-admin-credits-tab.php:67
434
- msgid "More details about the plugin"
435
- msgstr ""
436
-
437
- #: admin/partials/404-to-301-admin-credits-tab.php:71
438
- msgid "Need help?"
439
- msgstr ""
440
-
441
- #: admin/partials/404-to-301-admin-credits-tab.php:72
442
- msgid "Contact support"
443
- msgstr ""
444
-
445
- #: admin/partials/404-to-301-admin-credits-tab.php:76
446
- msgid "Disable UAN"
447
  msgstr ""
448
 
449
- #: admin/partials/404-to-301-admin-credits-tab.php:78
450
- msgid "Enable UAN"
451
- msgstr ""
452
-
453
- #: admin/partials/404-to-301-admin-credits-tab.php:84
454
- msgid "Log Manager Addon"
455
- msgstr ""
456
-
457
- #: admin/partials/404-to-301-admin-credits-tab.php:87
458
- msgid ""
459
- "Error Log Manager addon is available for 404 to 301 now. Make 404 error "
460
- "management more easy."
461
- msgstr ""
462
-
463
- #: admin/partials/404-to-301-admin-credits-tab.php:88
464
- msgid ""
465
- "Instead of email alerts on every error, get Hourly, Daily, Twice a day, "
466
- "Weekly, Twice a week email alerts."
467
- msgstr ""
468
-
469
- #: admin/partials/404-to-301-admin-credits-tab.php:89
470
- msgid "Automatically clear old error logs after few days to reduce db load."
471
- msgstr ""
472
-
473
- #: admin/partials/404-to-301-admin-credits-tab.php:90
474
- msgid "See More Details"
475
- msgstr ""
476
-
477
- #: admin/partials/404-to-301-admin-credits-tab.php:95
478
- msgid "Like the plugin"
479
- msgstr ""
480
-
481
- #: admin/partials/404-to-301-admin-credits-tab.php:98
482
- msgid "Rate now"
483
- msgstr ""
484
-
485
- #: admin/partials/404-to-301-admin-credits-tab.php:98
486
- msgid "Rate this on WordPress"
487
- msgstr ""
488
-
489
- #: admin/partials/404-to-301-admin-credits-tab.php:101
490
- msgid "Donate now"
491
- msgstr ""
492
-
493
- #: admin/partials/404-to-301-admin-credits-tab.php:101
494
- msgid "Make a small donation"
495
  msgstr ""
496
 
497
- #: admin/partials/404-to-301-admin-credits-tab.php:104
498
- msgid "Contribute now"
 
499
  msgstr ""
500
 
501
- #: admin/partials/404-to-301-admin-credits-tab.php:104
502
- msgid "Contribute to the Plugin"
 
 
503
  msgstr ""
504
 
505
- #: admin/partials/404-to-301-admin-credits-tab.php:107
506
- msgid "Tweet now"
 
 
507
  msgstr ""
508
 
509
- #: admin/partials/404-to-301-admin-credits-tab.php:107
510
- msgid "Tweet about the Plugin"
511
  msgstr ""
512
 
513
- #: admin/partials/404-to-301-admin-custom-redirect.php:6
514
- msgid "Redirecting from"
515
  msgstr ""
516
 
517
- #: admin/partials/404-to-301-admin-custom-redirect.php:10
518
- #: admin/partials/404-to-301-admin-general-tab.php:41
519
  msgid "Redirect to"
520
  msgstr ""
521
 
522
- #: admin/partials/404-to-301-admin-custom-redirect.php:13
523
  msgid ""
524
  "Enter the url if you want to set custom redirect for above 404 path. Enter "
525
  "the full url including http://. Leave empty if you want to follow deafult "
526
- "settings"
527
- msgstr ""
528
-
529
- #: admin/partials/404-to-301-admin-custom-redirect.php:23
530
- msgid "Save Redirect"
531
- msgstr ""
532
-
533
- #: admin/partials/404-to-301-admin-display.php:30
534
- msgid "settings updated successfully"
535
  msgstr ""
536
 
537
- #: admin/partials/404-to-301-admin-display.php:34
538
- msgid "General"
539
- msgstr ""
540
-
541
- #: admin/partials/404-to-301-admin-display.php:35
542
- msgid "Help & Info"
543
  msgstr ""
544
 
545
- #: admin/partials/404-to-301-admin-general-tab.php:30
546
- msgid "Redirect type"
547
  msgstr ""
548
 
549
- #: admin/partials/404-to-301-admin-general-tab.php:33
550
- msgid "Redirect (SEO)"
551
  msgstr ""
552
 
553
- #: admin/partials/404-to-301-admin-general-tab.php:37
554
  msgid "Learn more"
555
  msgstr ""
556
 
557
- #: admin/partials/404-to-301-admin-general-tab.php:37
558
  msgid "about these redirect types"
559
  msgstr ""
560
 
561
- #: admin/partials/404-to-301-admin-general-tab.php:44
562
- #: admin/partials/404-to-301-admin-general-tab.php:48
563
  msgid "Existing Page"
564
  msgstr ""
565
 
566
- #: admin/partials/404-to-301-admin-general-tab.php:45
567
- #: admin/partials/404-to-301-admin-general-tab.php:49
568
- #: admin/partials/404-to-301-admin-general-tab.php:66
569
  msgid "Custom URL"
570
  msgstr ""
571
 
572
- #: admin/partials/404-to-301-admin-general-tab.php:46
573
- #: admin/partials/404-to-301-admin-general-tab.php:50
574
  msgid "No Redirect"
575
  msgstr ""
576
 
577
- #: admin/partials/404-to-301-admin-general-tab.php:48
578
  msgid "Select any WordPress page as a 404 page"
579
  msgstr ""
580
 
581
- #: admin/partials/404-to-301-admin-general-tab.php:49
582
  msgid "Redirect 404 requests to a specific URL"
583
  msgstr ""
584
 
585
- #: admin/partials/404-to-301-admin-general-tab.php:50
586
  msgid "To disable redirect"
587
  msgstr ""
588
 
589
- #: admin/partials/404-to-301-admin-general-tab.php:51
590
  msgid ""
591
  "You can override this by setting individual custom redirects from error logs "
592
  "list."
593
  msgstr ""
594
 
595
- #: admin/partials/404-to-301-admin-general-tab.php:55
596
  msgid "Select the page"
597
  msgstr ""
598
 
599
- #: admin/partials/404-to-301-admin-general-tab.php:62
600
  msgid ""
601
- "The default 404 page will be replaced by the page you choose in this list"
602
  msgstr ""
603
 
604
- #: admin/partials/404-to-301-admin-general-tab.php:69
605
- msgid "Enter any url"
 
 
 
606
  msgstr ""
607
 
608
- #: admin/partials/404-to-301-admin-general-tab.php:69
609
- msgid "including"
610
  msgstr ""
611
 
612
- #: admin/partials/404-to-301-admin-general-tab.php:73
613
  msgid "Log 404 Errors"
614
  msgstr ""
615
 
616
- #: admin/partials/404-to-301-admin-general-tab.php:76
617
- msgid "Enable Error Logs"
618
- msgstr ""
619
-
620
- #: admin/partials/404-to-301-admin-general-tab.php:77
621
- msgid "Disable Error Logs"
622
- msgstr ""
623
-
624
- #: admin/partials/404-to-301-admin-general-tab.php:79
625
  msgid "Enable/Disable Logging"
626
  msgstr ""
627
 
628
- #: admin/partials/404-to-301-admin-general-tab.php:83
629
  msgid "Email notifications"
630
  msgstr ""
631
 
632
- #: admin/partials/404-to-301-admin-general-tab.php:90
633
  msgid ""
634
  "If you check this, an email will be sent on every 404 log on the admin email "
635
- "account"
636
  msgstr ""
637
 
638
- #: admin/partials/404-to-301-admin-general-tab.php:94
639
  msgid "Email address"
640
  msgstr ""
641
 
642
- #: admin/partials/404-to-301-admin-general-tab.php:98
643
- msgid "Change the recipient email address for error log notifications"
644
  msgstr ""
645
 
646
- #: admin/partials/404-to-301-admin-general-tab.php:102
647
  msgid "Exclude paths"
648
  msgstr ""
649
 
650
- #: admin/partials/404-to-301-admin-general-tab.php:105
651
  msgid ""
652
  "If you want to exclude few paths from error logs, enter here. One per line."
653
  msgstr ""
654
 
655
- #: admin/partials/404-to-301-admin-general-tab.php:110
656
- msgid "Save All Changes"
657
  msgstr ""
658
 
659
- #: public/class-404-to-301-public.php:61
660
- msgid "Bummer! You have one more 404"
661
  msgstr ""
662
 
663
- #: public/class-404-to-301-public.php:77
664
- msgid "Snap! One more 404 on "
665
  msgstr ""
666
 
667
- #. Plugin URI of the plugin/theme
668
- msgid "https://thefoxe.com/products/404-to-301/"
669
  msgstr ""
670
 
671
- #. Description of the plugin/theme
672
- msgid ""
673
- "Automatically redirect all <strong>404 errors</strong> to any page using "
674
- "<strong>301 redirect for SEO</strong>. You can <strong>redirect and log</"
675
- "strong> every 404 errors. No more 404 errors in Webmaster tool."
 
676
  msgstr ""
677
 
678
- #. Author of the plugin/theme
679
- msgid "Joel James"
680
  msgstr ""
681
 
682
- #. Author URI of the plugin/theme
683
- msgid "https://thefoxe.com/"
684
  msgstr ""
2
  msgid ""
3
  msgstr ""
4
  "Project-Id-Version: 404 to 301\n"
5
+ "POT-Creation-Date: 2018-06-20 00:50+0530\n"
6
  "PO-Revision-Date: 2016-03-22 23:53+0000\n"
7
  "Language-Team: \n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
12
+ "X-Generator: Poedit 1.8.7.1\n"
13
  "X-Poedit-SourceCharset: UTF-8\n"
14
  "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
15
  "_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;"
19
  "Last-Translator: \n"
20
  "X-Poedit-SearchPath-0: .\n"
21
 
22
+ #: includes/admin/class-jj4t3-admin.php:127
23
+ msgid "Custom Redirect"
24
+ msgstr ""
25
+
26
+ #: includes/admin/class-jj4t3-admin.php:151
27
+ #: includes/admin/class-jj4t3-admin.php:212
28
+ #: includes/admin/class-jj4t3-log-listing.php:47
29
  msgid "404 Error Logs"
30
  msgstr ""
31
 
32
+ #: includes/admin/class-jj4t3-admin.php:151
33
+ msgid "404 Errors"
34
+ msgstr ""
35
+
36
+ #: includes/admin/class-jj4t3-admin.php:157
37
  msgid "404 to 301 Settings"
38
  msgstr ""
39
 
40
+ #: includes/admin/class-jj4t3-admin.php:157
41
  msgid "404 Settings"
42
  msgstr ""
43
 
44
+ #: includes/admin/class-jj4t3-admin.php:186
45
  msgid "Error Logs"
46
  msgstr ""
47
 
48
+ #: includes/admin/class-jj4t3-admin.php:270 includes/admin/views/admin.php:21
 
 
49
  msgid "404 to 301"
50
  msgstr ""
51
 
52
+ #: includes/admin/class-jj4t3-admin.php:339 includes/admin/views/admin.php:27
 
 
 
 
 
 
 
 
 
 
53
  msgid "Settings"
54
  msgstr ""
55
 
56
+ #: includes/admin/class-jj4t3-admin.php:340
57
  msgid "Logs"
58
  msgstr ""
59
 
60
+ #: includes/admin/class-jj4t3-log-listing.php:46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  msgid "404 Error Log"
62
  msgstr ""
63
 
64
+ #: includes/admin/class-jj4t3-log-listing.php:328
65
+ #: includes/functions/jj4t3-general-functions.php:317
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  msgid "Date"
67
  msgstr ""
68
 
69
+ #: includes/admin/class-jj4t3-log-listing.php:329
70
+ #: includes/functions/jj4t3-general-functions.php:318
71
+ #: includes/public/class-jj4t3-404-email.php:193
72
  msgid "404 Path"
73
  msgstr ""
74
 
75
+ #: includes/admin/class-jj4t3-log-listing.php:330
76
+ #: includes/functions/jj4t3-general-functions.php:319
77
  msgid "From"
78
  msgstr ""
79
 
80
+ #: includes/admin/class-jj4t3-log-listing.php:331
81
+ #: includes/functions/jj4t3-general-functions.php:320
82
+ #: includes/public/class-jj4t3-404-email.php:198
83
  msgid "IP Address"
84
  msgstr ""
85
 
86
+ #: includes/admin/class-jj4t3-log-listing.php:332
87
+ #: includes/functions/jj4t3-general-functions.php:321
88
  msgid "User Agent"
89
  msgstr ""
90
 
91
+ #: includes/admin/class-jj4t3-log-listing.php:333
92
+ msgid "Customization"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  msgstr ""
94
 
95
+ #: includes/admin/class-jj4t3-log-listing.php:397
96
+ msgid "Ah! You are so clean that you still got ZERO errors."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  msgstr ""
98
 
99
+ #: includes/admin/class-jj4t3-log-listing.php:475
100
+ msgid "Are you sure you want to delete this item?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  msgstr ""
102
 
103
+ #: includes/admin/class-jj4t3-log-listing.php:477
104
+ msgid "Delete"
 
 
 
 
 
 
 
 
105
  msgstr ""
106
 
107
+ #: includes/admin/class-jj4t3-log-listing.php:624
108
+ #: includes/admin/views/custom-redirect.php:17
109
+ #: includes/admin/views/custom-redirect.php:25
110
+ #: includes/admin/views/custom-redirect.php:33
111
+ msgid "Default"
112
  msgstr ""
113
 
114
+ #: includes/admin/class-jj4t3-log-listing.php:626
115
+ msgid "Customize"
116
  msgstr ""
117
 
118
+ #: includes/admin/class-jj4t3-log-listing.php:696
119
+ msgid "Delete Selected"
120
  msgstr ""
121
 
122
+ #: includes/admin/class-jj4t3-log-listing.php:697
123
+ msgid "Delete All"
124
  msgstr ""
125
 
126
+ #: includes/admin/class-jj4t3-log-listing.php:698
127
+ msgid "Delete All (Keep redirects)"
128
  msgstr ""
129
 
130
+ #: includes/admin/class-jj4t3-log-listing.php:735
131
+ msgid "Group by"
132
  msgstr ""
133
 
134
+ #: includes/admin/class-jj4t3-log-listing.php:740
135
+ msgid "Apply"
136
  msgstr ""
137
 
138
+ #: includes/admin/views/admin.php:21
139
  #, php-format
140
+ msgid "by <a href=\"%s\">Joel James</a>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  msgstr ""
142
 
143
+ #: includes/admin/views/custom-redirect.php:11
144
+ msgid "Redirecting from"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  msgstr ""
146
 
147
+ #: includes/admin/views/custom-redirect.php:15
148
+ #: includes/functions/jj4t3-general-functions.php:322
149
+ msgid "Redirect"
150
  msgstr ""
151
 
152
+ #: includes/admin/views/custom-redirect.php:18
153
+ #: includes/admin/views/custom-redirect.php:26
154
+ #: includes/admin/views/custom-redirect.php:34
155
+ msgid "Enable"
156
  msgstr ""
157
 
158
+ #: includes/admin/views/custom-redirect.php:19
159
+ #: includes/admin/views/custom-redirect.php:27
160
+ #: includes/admin/views/custom-redirect.php:35
161
+ msgid "Disable"
162
  msgstr ""
163
 
164
+ #: includes/admin/views/custom-redirect.php:23
165
+ msgid "Error logging"
166
  msgstr ""
167
 
168
+ #: includes/admin/views/custom-redirect.php:31
169
+ msgid "Email alert"
170
  msgstr ""
171
 
172
+ #: includes/admin/views/custom-redirect.php:39
173
+ #: includes/admin/views/settings.php:30
174
  msgid "Redirect to"
175
  msgstr ""
176
 
177
+ #: includes/admin/views/custom-redirect.php:42
178
  msgid ""
179
  "Enter the url if you want to set custom redirect for above 404 path. Enter "
180
  "the full url including http://. Leave empty if you want to follow deafult "
181
+ "settings."
 
 
 
 
 
 
 
 
182
  msgstr ""
183
 
184
+ #: includes/admin/views/custom-redirect.php:51
185
+ #: includes/admin/views/settings.php:17
186
+ msgid "Redirect type"
 
 
 
187
  msgstr ""
188
 
189
+ #: includes/admin/views/custom-redirect.php:58
190
+ msgid "Select redirect type to override default one."
191
  msgstr ""
192
 
193
+ #: includes/admin/views/custom-redirect.php:65
194
+ msgid "Save Redirect"
195
  msgstr ""
196
 
197
+ #: includes/admin/views/settings.php:24
198
  msgid "Learn more"
199
  msgstr ""
200
 
201
+ #: includes/admin/views/settings.php:24
202
  msgid "about these redirect types"
203
  msgstr ""
204
 
205
+ #: includes/admin/views/settings.php:33 includes/admin/views/settings.php:37
 
206
  msgid "Existing Page"
207
  msgstr ""
208
 
209
+ #: includes/admin/views/settings.php:34 includes/admin/views/settings.php:38
210
+ #: includes/admin/views/settings.php:52
 
211
  msgid "Custom URL"
212
  msgstr ""
213
 
214
+ #: includes/admin/views/settings.php:35 includes/admin/views/settings.php:39
 
215
  msgid "No Redirect"
216
  msgstr ""
217
 
218
+ #: includes/admin/views/settings.php:37
219
  msgid "Select any WordPress page as a 404 page"
220
  msgstr ""
221
 
222
+ #: includes/admin/views/settings.php:38
223
  msgid "Redirect 404 requests to a specific URL"
224
  msgstr ""
225
 
226
+ #: includes/admin/views/settings.php:39
227
  msgid "To disable redirect"
228
  msgstr ""
229
 
230
+ #: includes/admin/views/settings.php:40
231
  msgid ""
232
  "You can override this by setting individual custom redirects from error logs "
233
  "list."
234
  msgstr ""
235
 
236
+ #: includes/admin/views/settings.php:44
237
  msgid "Select the page"
238
  msgstr ""
239
 
240
+ #: includes/admin/views/settings.php:47
241
  msgid ""
242
+ "The default 404 page will be replaced by the page you choose in this list."
243
  msgstr ""
244
 
245
+ #: includes/admin/views/settings.php:48
246
+ #, php-format
247
+ msgid ""
248
+ "You can <a href=\"%s\" target=\"_blank\">create a custom 404</a> page and "
249
+ "assign that page here."
250
  msgstr ""
251
 
252
+ #: includes/admin/views/settings.php:55
253
+ msgid "Enter any url (including http://)"
254
  msgstr ""
255
 
256
+ #: includes/admin/views/settings.php:59
257
  msgid "Log 404 Errors"
258
  msgstr ""
259
 
260
+ #: includes/admin/views/settings.php:62
 
 
 
 
 
 
 
 
261
  msgid "Enable/Disable Logging"
262
  msgstr ""
263
 
264
+ #: includes/admin/views/settings.php:66
265
  msgid "Email notifications"
266
  msgstr ""
267
 
268
+ #: includes/admin/views/settings.php:69
269
  msgid ""
270
  "If you check this, an email will be sent on every 404 log on the admin email "
271
+ "account."
272
  msgstr ""
273
 
274
+ #: includes/admin/views/settings.php:73
275
  msgid "Email address"
276
  msgstr ""
277
 
278
+ #: includes/admin/views/settings.php:77
279
+ msgid "Change the recipient email address for error log notifications."
280
  msgstr ""
281
 
282
+ #: includes/admin/views/settings.php:81
283
  msgid "Exclude paths"
284
  msgstr ""
285
 
286
+ #: includes/admin/views/settings.php:84
287
  msgid ""
288
  "If you want to exclude few paths from error logs, enter here. One per line."
289
  msgstr ""
290
 
291
+ #: includes/admin/views/settings.php:89
292
+ msgid "Save settings"
293
  msgstr ""
294
 
295
+ #: includes/functions/jj4t3-general-functions.php:283
296
+ msgid "301 Redirect (SEO)"
297
  msgstr ""
298
 
299
+ #: includes/functions/jj4t3-general-functions.php:284
300
+ msgid "302 Redirect"
301
  msgstr ""
302
 
303
+ #: includes/functions/jj4t3-general-functions.php:285
304
+ msgid "307 Redirect"
305
  msgstr ""
306
 
307
+ #: includes/public/class-jj4t3-404-email.php:141
308
+ msgid "Snap! One more 404 on "
309
+ msgstr ""
310
+
311
+ #: includes/public/class-jj4t3-404-email.php:189
312
+ msgid "Bummer! You have one more 404"
313
  msgstr ""
314
 
315
+ #: includes/public/class-jj4t3-404-email.php:203
316
+ msgid "Time"
317
  msgstr ""
318
 
319
+ #: includes/public/class-jj4t3-404-email.php:208
320
+ msgid "Referral Page"
321
  msgstr ""
languages/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
public/class-404-to-301-public.php DELETED
@@ -1,371 +0,0 @@
1
- <?php
2
-
3
- // If this file is called directly, abort.
4
- if (!defined('WPINC')) {
5
- die('Damn it.! Dude you are looking for what?');
6
- }
7
-
8
- /**
9
- * The public-facing functionality of the plugin.
10
- *
11
- * This class contains the public side functionalities like,
12
- * logging, redirecting etc.
13
- *
14
- * @category Core
15
- * @package I4T3
16
- * @subpackage Public
17
- * @author Joel James <me@joelsays.com>
18
- * @license http://www.gnu.org/licenses/ GNU General Public License
19
- * @link https://thefoxe.com/products/404-to-301
20
- */
21
- class _404_To_301_Public {
22
-
23
- /**
24
- * Initialize the class and set its properties.
25
- *
26
- * @since 2.0.0
27
- * @access public
28
- *
29
- * @return void
30
- */
31
- public function __construct() {
32
-
33
- $this->gnrl_options = get_option('i4t3_gnrl_options');
34
- }
35
-
36
- /**
37
- * Create the 404 Log Email to be sent.
38
- *
39
- * @param array $log_data Error logs data
40
- *
41
- * @since 2.0.0
42
- * @access private
43
- * @uses get_option To get admin email from database.
44
- * @uses get_bloginfo To get site title.
45
- *
46
- * @return void
47
- */
48
- private function i4t3_send_404_log_email($log_data) {
49
-
50
- // Filter to change the email address used for admin notifications
51
- $admin_email = apply_filters( 'i4t3_notify_admin_email_address', get_option('admin_email') );
52
-
53
- // Action hook that will be performed before sending 404 error mail
54
- do_action( 'i4t3_before_404_email_log', $log_data );
55
-
56
- // Get the site name
57
- $site_name = get_bloginfo('name');
58
-
59
- $headers[] = 'From: ' . $site_name . ' <' . $admin_email . '>' . "\r\n";
60
- $headers[] = 'Content-Type: text/html; charset=UTF-8';
61
- $message = '<p>' . __('Bummer! You have one more 404', '404-to-301') . '</p>';
62
- $message .= '<table>';
63
- $message .= '<tr>';
64
- $message .= '<th>' . __('IP Address', '404-to-301') . '</th>';
65
- $message .= '<td>' . $log_data['ip'] . '</td>';
66
- $message .= '</tr>';
67
- $message .= '<tr>';
68
- $message .= '<th>' . __('404 Path', '404-to-301') . '</th>';
69
- $message .= '<td>' . $log_data['url'] . '</td>';
70
- $message .= '</tr>';
71
- $message .= '<tr>';
72
- $message .= '<th>' . __('User Agent', '404-to-301') . '</th>';
73
- $message .= '<td>' . $log_data['ua'] . '</td>';
74
- $message .= '</tr>';
75
- $message .= '</table>';
76
- $is_sent = wp_mail(
77
- $admin_email, __('Snap! One more 404 on ', '404-to-301') . $site_name, $message, $headers
78
- );
79
- }
80
-
81
- /**
82
- * The main function to perform redirections and logs on 404s.
83
- * Creating log for 404 errors, sending admin notification email if enables,
84
- * redirecting visitors to the specific page etc. are done in this function.
85
- *
86
- * @since 2.0.0
87
- * @access public
88
- * @uses wp_redirect To redirect to a given link.
89
- * @uses do_action To add new action.
90
- *
91
- * @return void
92
- */
93
- public function i4t3_redirect_404() {
94
-
95
- // Check if 404 page and not admin side
96
- if ( $this->can_404() ) {
97
-
98
- $data = array();
99
- global $wpdb;
100
-
101
- // Get the settings options
102
- $logging_status = (!empty($this->gnrl_options['redirect_log']) ) ? $this->gnrl_options['redirect_log'] : 0;
103
-
104
- $redirect_type = ( $this->gnrl_options['redirect_type'] ) ? $this->gnrl_options['redirect_type'] : '301';
105
- // Get the email notification settings
106
- $is_email_send = (!empty($this->gnrl_options['email_notify']) && $this->gnrl_options['email_notify'] == 1 ) ? true : false;
107
-
108
- // Get error details if emailnotification or log is enabled
109
- if ($logging_status == 1 || $is_email_send) {
110
-
111
- // Action hook that will be performed before logging 404 errors
112
- do_action('i4t3_before_404_logging');
113
-
114
- $data = $this->get_error_data();
115
-
116
- }
117
-
118
- // Add log data to db if log is enabled by user
119
- if ($logging_status == 1 && !$this->i4t3_is_bot()) {
120
-
121
- $wpdb->insert(I4T3_TABLE, $data);
122
-
123
- // pop old entry if we exceeded the limit
124
- //$max = intval( $this->options['max_entries'] );
125
- //$max = 500;
126
- //$cutoff = $wpdb->get_var("SELECT id FROM I4T3_TABLE ORDER BY id DESC LIMIT $max,1");
127
- //if ($cutoff) {
128
- //$wpdb->delete(I4T3_TABLE, array('id' => intval($cutoff)), array('%d'));
129
- //}
130
- }
131
-
132
- // Send email notification if enabled
133
- if ( $is_email_send && !$this->i4t3_is_bot() ) {
134
- $this->i4t3_send_404_log_email( $data );
135
- }
136
- // check if custom redirect is set
137
- $url = $this->get_custom_redirect( $_SERVER );
138
- // if custom redirect is not set, get default url
139
- if( ! $url ) {
140
- // Get redirect settings
141
- $redirect_to = $this->gnrl_options['redirect_to'];
142
-
143
- switch ( $redirect_to ) {
144
- // Do not redirect if none is set
145
- case 'none':
146
- break;
147
- // Redirect to an existing WordPress site inside our site
148
- case 'page':
149
- $url = get_permalink($this->gnrl_options['redirect_page']);
150
- break;
151
- // Redirect to a custom link given by user
152
- case 'link':
153
- $url = $this->format_link($this->gnrl_options['redirect_link']);
154
- break;
155
- // If nothing, be chill and do nothing!
156
- default:
157
- break;
158
- }
159
- }
160
-
161
- do_action('i4t3_before_404_redirect');
162
- // Perform the redirect if $url is set
163
- if( ! empty( $url ) ) {
164
- // Action hook that will be performed before 404 redirect starts
165
- //echo $url; exit();
166
- wp_redirect( $url, $redirect_type );
167
- exit(); // exit, because WordPress will not exit automatically
168
- }
169
- }
170
- }
171
-
172
- /**
173
- * Format link to attach http:// if missing
174
- *
175
- * Sometimes user may forget to add http:// with redirect
176
- * url. So for safety we will format it to be in http:// start
177
- *
178
- * @param string $link Link to format
179
- *
180
- * @since 2.2.0
181
- * @access private
182
- *
183
- * @return string $link
184
- */
185
- private function format_link($link) {
186
-
187
- $link = ( ! preg_match("~^(?:f|ht)tps?://~i", $link ) ) ? "http://" . $link : $link;
188
-
189
- return trailingslashit( $link );
190
- }
191
-
192
- /**
193
- * Get custom redirect url if set
194
- *
195
- * If custom redirect url is set for give 404 path,
196
- * get that link.
197
- *
198
- * @global object $wpdb WP DB object
199
- *
200
- * @param array $server Server components data
201
- *
202
- * @since 2.2.0
203
- * @access public
204
- *
205
- * @return mixed
206
- */
207
- private function get_custom_redirect( $server ) {
208
-
209
- if( is_null( $server['REQUEST_URI']) || empty($server['REQUEST_URI'] ) ) {
210
- return false;
211
- }
212
-
213
- $uri = trailingslashit( $server['REQUEST_URI'] );
214
-
215
- global $wpdb;
216
- // make sure that the errors are hidden
217
- $wpdb->hide_errors();
218
- // get custom redirect path
219
- $redirect = $wpdb->get_var("SELECT redirect FROM " . I4T3_TABLE . " WHERE url = '" . $uri . "' AND redirect IS NOT NULL LIMIT 0,1");
220
-
221
- return ( ! empty( $redirect ) ) ? $this->format_link( $redirect ) : false;
222
- }
223
-
224
- /**
225
- * Check if we can perform redirect related actions
226
- *
227
- * @since 2.2.0
228
- * @access private
229
- *
230
- * @return boolean
231
- */
232
- private function can_404() {
233
-
234
- if( is_404() && ! is_admin() && ! $this->i4t3_excluded_paths() ) {
235
- // buddypress compatibility
236
- return function_exists( 'bp_current_component' ) ? ! bp_current_component() : true;
237
- }
238
-
239
- return false;
240
- }
241
-
242
- /**
243
- * Get error logs data.
244
- *
245
- * Get data to be logged related to the current
246
- * 404 path.
247
- *
248
- * @since 2.2.0
249
- * @access private
250
- * @uses get_clear_empty() To avoid empty error
251
- *
252
- * @return array $data
253
- */
254
- private function get_error_data() {
255
-
256
- // Get request data.
257
- $url = empty( $_SERVER['REQUEST_URI'] ) ? '' : trailingslashit( esc_url( $_SERVER['REQUEST_URI'] ) );
258
- $ref = empty( $_SERVER['HTTP_REFERER'] ) ? '' : esc_url( $_SERVER['HTTP_REFERER'] );
259
- $ua = empty( $_SERVER['HTTP_USER_AGENT'] ) ? '' : $_SERVER['HTTP_USER_AGENT'];
260
-
261
- $data['date'] = current_time('mysql');
262
- $data['ip'] = $this->get_ip();
263
- $data['url'] = $this->get_clear_empty( $url );
264
- $data['ref'] = $this->get_clear_empty( $ref );
265
- $data['ua'] = $this->get_clear_empty( $ua );
266
-
267
- return $data;
268
- }
269
-
270
- /**
271
- * Get real IP address of the uer.
272
- * http://stackoverflow.com/a/55790/3845839
273
- *
274
- * @since 2.2.6
275
- * @access private
276
- *
277
- * @return string
278
- */
279
- private function get_ip() {
280
-
281
- $ips = array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' );
282
- foreach ( $ips as $ip ) {
283
- if ( ! empty( $_SERVER[ $ip ] ) ) {
284
- $string = $_SERVER[ $ip ];
285
- } else {
286
- $string = '';
287
- }
288
-
289
- if ( ! empty ( $string ) ) {
290
- return $string;
291
- }
292
- }
293
-
294
- return 'N/A';
295
- }
296
-
297
- /**
298
- * Check if Bot is visiting.
299
- *
300
- * This function is used to check if a bot is being viewed our site content.
301
- *
302
- * @link http://stackoverflow.com/questions/677419/how-to-detect-search-engine-bots-with-php
303
- * @since 2.0.5
304
- * @access private
305
- *
306
- * @return boolean
307
- */
308
- private function i4t3_is_bot() {
309
-
310
- $botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
311
- "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
312
- "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
313
- "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
314
- "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
315
- "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
316
- "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
317
- "Butterfly","Twitturls","Me.dium","Twiceler"
318
- );
319
-
320
- foreach( $botlist as $bot ) {
321
- if( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], $bot ) !== false ) {
322
- return true;
323
- }
324
- }
325
-
326
- return false;
327
- }
328
-
329
- /**
330
- * Exclude specific uri strings/paths from errors
331
- *
332
- * @since 2.0.8
333
- * @access private
334
- *
335
- * @return boolean
336
- */
337
- private function i4t3_excluded_paths() {
338
-
339
- // Add links to be excluded in this array.
340
- $links_string = $this->gnrl_options['exclude_paths'];
341
- if( empty( $links_string ) ) {
342
- return false;
343
- }
344
- $links = explode( "\n", $links_string );
345
- if( ! empty( $links ) ) {
346
- foreach( $links as $link ) {
347
- if( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], trim( $link ) ) !== false ) {
348
- return true;
349
- }
350
- }
351
- }
352
-
353
- return false;
354
- }
355
-
356
- /**
357
- * Check if value is empty before trying to insert.
358
- *
359
- * @since 2.0.9.1
360
- * @access private
361
- *
362
- * @return string $data Formatted string
363
- */
364
- private function get_clear_empty($data = null) {
365
-
366
- $data = ( $data == null || empty($data) ) ? 'N/A' : substr( $data, 0, 512 );
367
-
368
- return htmlspecialchars( $data );
369
- }
370
-
371
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,10 +1,11 @@
1
  === 404 to 301 ===
2
- Contributors: joelcj91,foxe
3
  Tags: 404, 301, 302, 307, not found, 404 redirect, 404 to 301, 301 redirect, seo redirect, error redirect, 404 seo, custom 404 page
4
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XUVWY8HUBUXY4
5
  Requires at least: 3.5
6
  Tested up to: 4.9
7
- Stable tag: 2.3.3
 
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -26,7 +27,7 @@ If you care about your website, you should take steps to avoid 404 errors as it
26
  > - **Automatically clear** old error logs based on time period.<br />
27
  > - Get email alerts to multiple email recipients.<br />
28
  >
29
- > [Get this add-on now](https://thefoxe.com/products/404-to-301-log-manager/) | [See Docs](https://thefoxe.com/docs/docs/category/404-to-301/log-manager/)
30
 
31
  404 to 301 is a simple but amazing plugin which handles all 404 errors for you. It will redirect all 404 errors to any page that you set, using 301 (or any other) status. That means no more 404 errors! Even in Google webmaster tool you are safe!
32
  You will not see any 404 error reports in your webmaster tool dashboard.
@@ -43,25 +44,24 @@ You will not see any 404 error reports in your webmaster tool dashboard.
43
  > - You can optionally enable email notification on all 404 errors.<br />
44
  > - You can choose which redirect method to be used (301,302,307).<br />
45
  > - Will not irritate your visitors if they land on a non-existing page/url.<br />
46
- > - Super Light weight.<br />
47
  > - Increase your SEO by telling Google that all 404 pages are moved to some other page.<br />
48
  > - Completely free to use with lifetime updates.<br />
49
  > - Developer friendly.<br />
50
  > - Follows best WordPress coding standards.<br />
51
  > - Of course, available in [GitHub](https://github.com/joel-james/404-to-301)<br />
52
  >
53
- > [Installation](https://wordpress.org/plugins/404-to-301/installation/) | [Docs](https://thefoxe.com/docs/docs/category/404-to-301/) | [Screenshots](https://wordpress.org/plugins/404-to-301/screenshots/)
54
 
55
 
56
  **Bug Reports**
57
 
58
- Bug reports for 404 to 301 are always welcome. [Report here](https://thefoxe.com/bug-report/).
59
 
60
  **More information**
61
 
62
- - [404 to 301 - Plugin Homepage](https://thefoxe.com/products/404-to-301), containing more details and docs.
63
  - Follow the developer [@Twitter](https://twitter.com/Joel_James)
64
- - Other [WordPress plugins](https://profiles.wordpress.org/joelcj91/#content-plugins) by Joel James for [The Foxe](https://thefoxe.com)
65
 
66
  **404 Errors and Redirect - More Details**
67
 
@@ -80,10 +80,10 @@ If you are confused with these terms 404,301, redirect etc, [refer this page](ht
80
 
81
 
82
  = Need more help? =
83
- Please take a look at the [plugin documentation](https://thefoxe.com/docs/docs/category/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
84
 
85
  = Missing something? =
86
- If you would like to have an additional feature for this plugin, [let me know](http://thefoxe.com/support/)
87
 
88
  == Frequently Asked Questions ==
89
 
@@ -109,14 +109,14 @@ Yes. You can set that from error logs table.
109
 
110
  = I need more details =
111
 
112
- Please take a look at the [plugin documentation](https://thefoxe.com/docs/docs/category/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
113
 
114
 
115
  == Other Notes ==
116
 
117
  = Bug Reports =
118
 
119
- Bug reports for 404 to 301 are always welcome. [Report here](https://thefoxe.com/bug-report/).
120
 
121
 
122
  == Screenshots ==
@@ -128,6 +128,21 @@ Bug reports for 404 to 301 are always welcome. [Report here](https://thefoxe.com
128
 
129
  == Changelog ==
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  = 2.3.3 (31/08/2016) =
132
  **Bug Fixes**
133
 
@@ -150,7 +165,7 @@ Bug reports for 404 to 301 are always welcome. [Report here](https://thefoxe.com
150
 
151
  - Removed unused UAN button from help page.
152
  - Completely safe to use.
153
- - Tracking completely removed from the plugin since it was detected as spam. Read more [here](https://thefoxe.com/blog/404-to-301-plugin-detected-by-wordfence-here-is-what-actually-happened/).
154
 
155
  = 2.2.9 (16/08/2016) =
156
  **Bug Fixes**
@@ -208,7 +223,7 @@ Bug reports for 404 to 301 are always welcome. [Report here](https://thefoxe.com
208
  = 2.1.7 (20/04/2016) =
209
  **New Add-on**
210
 
211
- - New [Log Manager](https://thefoxe.com/products/404-to-301-log-manager/) add-on available now.
212
  - Get periodic email alerts instead of instant email alerts for every errors (add-on).
213
  - Automatically clear error logs (add-on).
214
 
@@ -264,7 +279,7 @@ Bug reports for 404 to 301 are always welcome. [Report here](https://thefoxe.com
264
  = 2.0.8 (28/10/2015) =
265
  **New Feature**
266
 
267
- - New option to exclude paths from error logs and redirect - [See details](https://thefoxe.com/docs/items/excluding-paths-from-error-logs-and-redirects/).
268
 
269
  **Bug Fixes**
270
 
@@ -358,8 +373,7 @@ Bug reports for 404 to 301 are always welcome. [Report here](https://thefoxe.com
358
 
359
  == Upgrade Notice ==
360
 
361
- = 2.3.3 (31/08/2016) =
362
  **Bug Fixes**
363
 
364
- - Using esc_url() for Ref and Url fields.
365
- - Fixed Cross Site Scripting vulnerability in "From" column - Thanks to [Plugin Vulnerabilities](https://www.pluginvulnerabilities.com/).
1
  === 404 to 301 ===
2
+ Contributors: joelcj91,duckdev
3
  Tags: 404, 301, 302, 307, not found, 404 redirect, 404 to 301, 301 redirect, seo redirect, error redirect, 404 seo, custom 404 page
4
+ Donate link: https://www.paypal.me/JoelCJ
5
  Requires at least: 3.5
6
  Tested up to: 4.9
7
+ Stable tag: 3.0.0
8
+ Requires PHP: 5.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
27
  > - **Automatically clear** old error logs based on time period.<br />
28
  > - Get email alerts to multiple email recipients.<br />
29
  >
30
+ > [Get this add-on now](https://duckdev.com/products/404-to-301-log-manager/) | [See Docs](https://duckdev.com/support/docs/404-to-301-log-manager/)
31
 
32
  404 to 301 is a simple but amazing plugin which handles all 404 errors for you. It will redirect all 404 errors to any page that you set, using 301 (or any other) status. That means no more 404 errors! Even in Google webmaster tool you are safe!
33
  You will not see any 404 error reports in your webmaster tool dashboard.
44
  > - You can optionally enable email notification on all 404 errors.<br />
45
  > - You can choose which redirect method to be used (301,302,307).<br />
46
  > - Will not irritate your visitors if they land on a non-existing page/url.<br />
 
47
  > - Increase your SEO by telling Google that all 404 pages are moved to some other page.<br />
48
  > - Completely free to use with lifetime updates.<br />
49
  > - Developer friendly.<br />
50
  > - Follows best WordPress coding standards.<br />
51
  > - Of course, available in [GitHub](https://github.com/joel-james/404-to-301)<br />
52
  >
53
+ > [Installation](https://wordpress.org/plugins/404-to-301/installation/) | [Docs](https://duckdev.com/support/docs/404-to-301/) | [Screenshots](https://wordpress.org/plugins/404-to-301/screenshots/)
54
 
55
 
56
  **Bug Reports**
57
 
58
+ Bug reports for 404 to 301 are always welcome. [Report here](https://duckdev.com/support/).
59
 
60
  **More information**
61
 
62
+ - [404 to 301 - Plugin Homepage](https://duckdev.com/products/404-to-301), containing more details and docs.
63
  - Follow the developer [@Twitter](https://twitter.com/Joel_James)
64
+ - Other [WordPress plugins](https://profiles.wordpress.org/joelcj91/#content-plugins) by Joel James for [Duck Dev](https://duckdev.com)
65
 
66
  **404 Errors and Redirect - More Details**
67
 
80
 
81
 
82
  = Need more help? =
83
+ Please take a look at the [plugin documentation](https://duckdev.com/support/docs/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
84
 
85
  = Missing something? =
86
+ If you would like to have an additional feature for this plugin, [let me know](https://duckdev.com/support/)
87
 
88
  == Frequently Asked Questions ==
89
 
109
 
110
  = I need more details =
111
 
112
+ Please take a look at the [plugin documentation](https://duckdev.com/support/docs/404-to-301/) or [open a support request](http://wordpress.org/support/plugin/404-to-301/).
113
 
114
 
115
  == Other Notes ==
116
 
117
  = Bug Reports =
118
 
119
+ Bug reports for 404 to 301 are always welcome. [Report here](https://duckdev.com/support/).
120
 
121
 
122
  == Screenshots ==
128
 
129
  == Changelog ==
130
 
131
+ = 3.0.0 (20/06/2018) =
132
+ **New Features**
133
+
134
+ - Individual optional settings for each error log item (Individual redirec, log, email alert can be set).
135
+ - Clear error logs without removing custom redirects.
136
+ - Added error logs grouping with count.
137
+ - [WPML compatible](https://wpml.org/plugin/404-to-301/).
138
+ - Integrated Freemius for addon, support and analytics (optional).
139
+
140
+ **Improvements**
141
+
142
+ - Complete code revamp. More improved structure.
143
+ - Set custom options from previous logs if same item exists.
144
+ - Made 3rd party integration easier.
145
+
146
  = 2.3.3 (31/08/2016) =
147
  **Bug Fixes**
148
 
165
 
166
  - Removed unused UAN button from help page.
167
  - Completely safe to use.
168
+ - Tracking completely removed from the plugin since it was detected as spam. Read more [here](https://duckdev.com/blog/404-to-301-plugin-detected-by-wordfence-here-is-what-actually-happened/).
169
 
170
  = 2.2.9 (16/08/2016) =
171
  **Bug Fixes**
223
  = 2.1.7 (20/04/2016) =
224
  **New Add-on**
225
 
226
+ - New [Log Manager](https://duckdev.com/products/404-to-301-log-manager/) add-on available now.
227
  - Get periodic email alerts instead of instant email alerts for every errors (add-on).
228
  - Automatically clear error logs (add-on).
229
 
279
  = 2.0.8 (28/10/2015) =
280
  **New Feature**
281
 
282
+ - New option to exclude paths from error logs and redirect.
283
 
284
  **Bug Fixes**
285
 
373
 
374
  == Upgrade Notice ==
375
 
376
+ = 3.0.0 (21/11/2016) =
377
  **Bug Fixes**
378
 
379
+ - New features and improvements.
 
screenshot-1.png DELETED
Binary file
screenshot-2.png DELETED
Binary file
screenshot-3.png DELETED
Binary file
uninstall.php DELETED
@@ -1,38 +0,0 @@
1
- <?php
2
-
3
- if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
4
- die('Damn it.! Dude you are looking for what?');
5
- }
6
-
7
- /**
8
- * Fired during plugin activation.
9
- *
10
- * This class defines all code necessary to run during the plugin's activation.
11
- *
12
- * @category Core
13
- * @package I4T3
14
- * @subpackage Uninstaller
15
- * @author Joel James <me@joelsays.com>
16
- * @license http://www.gnu.org/licenses/ GNU General Public License
17
- * @link https://thefoxe.com/products/404-to-301
18
- */
19
-
20
- // Deletes plugin options
21
- $options = array(
22
- 'i4t3_gnrl_options',
23
- 'i4t3_db_version',
24
- 'i4t3_version_no',
25
- 'i4t3_agreement'
26
- );
27
- foreach ( $options as $option ) {
28
- if ( get_option( $option ) ) {
29
- delete_option( $option );
30
- }
31
- }
32
-
33
- global $wpdb;
34
-
35
- // drop our custom table
36
- $wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "404_to_301" );
37
-
38
- /******* The end. Thanks for using 404 to 301 plugin ********/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/freemius/.github/ISSUE_TEMPLATE.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ **Actual Behavior**:
2
+ - `What is the issue? (*)`
3
+ - `What is the expected behavior?`
4
+
5
+ **Versions**: (*)
6
+ - `Freemius SDK Version:`
7
+ - `WordPress Version:`
8
+ - `PHP Version:`
9
+
10
+ **Plugin / Theme**: (*)
11
+ - `Name:`
12
+ - `Slug:`
13
+ - `Freemius ID:`
14
+
15
+ **Additional Information**:
16
+ - `Browser Type: (*)`
17
+ - `Browser Version: (*)`
18
+ - `OS: (*)`
19
+ - `Stack Traces:`
20
+
21
+ ----
22
+ **Note:** `(*)` indicates required information. Without this information, your issue may be auto-closed.
23
+
24
+ > You can find your Freemius SDK version at `/freemius/start.php`
25
+
26
+ > You can find your Freemius product ID in the Freemius dashboard: `SETTINGS -> INTEGRATION`.
27
+
28
+ > Do not modify the titles or questions. Simply add your responses to the ends of the questions.
29
+ Add more lines if needed.
vendor/freemius/LICENSE.txt ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ {one line to give the program's name and a brief idea of what it does.}
635
+ Copyright (C) {year} {name of author}
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ {project} Copyright (C) {year} {fullname}
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <http://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
vendor/freemius/assets/css/admin/account.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_account .postbox,#fs_account .widefat{max-width:700px}#fs_account h3{font-size:1.3em;padding:12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #F1F1F1}#fs_account h3 .dashicons{width:26px;height:26px;font-size:1.3em}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .dashicons{vertical-align:middle}#fs_account .fs-header-actions{position:absolute;top:17px;right:15px;font-size:0.9em}#fs_account .fs-header-actions ul{margin:0}#fs_account .fs-header-actions li{float:left}#fs_account .fs-header-actions li form{display:inline-block}#fs_account .fs-header-actions li a{text-decoration:none}#fs_account_details .button-group{float:right}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type="text"]{color:#0073AA;font-size:16px;background:none}.fs-key-value-table input[type="text"]{width:100%;font-weight:bold}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_sites .fs-scrollable-table .fs-table-body{max-height:200px;overflow:auto;border:1px solid #e5e5e5}#fs_sites .fs-scrollable-table .fs-table-body>table.widefat{border:none !important}#fs_sites .fs-scrollable-table .fs-main-column{width:100%}#fs_sites .fs-scrollable-table .fs-site-details td:first-of-type{text-align:right;color:grey;width:1px}#fs_sites .fs-scrollable-table .fs-site-details td:last-of-type{text-align:right}#fs_sites .fs-scrollable-table .fs-install-details table tr td{width:1px;white-space:nowrap}#fs_sites .fs-scrollable-table .fs-install-details table tr td:last-of-type{width:auto}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons thead{white-space:nowrap}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}#fs_billing_address{width:100%}#fs_billing_address tr td{width:50%;padding:5px}#fs_billing_address tr:first-of-type td{padding-top:0}#fs_billing_address span{font-weight:bold}#fs_billing_address input,#fs_billing_address select{display:block;width:100%;margin-top:5px}#fs_billing_address input::-moz-placeholder,#fs_billing_address select::-moz-placeholder{color:transparent;opacity:1}#fs_billing_address input:-ms-input-placeholder,#fs_billing_address select:-ms-input-placeholder{color:transparent}#fs_billing_address input::-webkit-input-placeholder,#fs_billing_address select::-webkit-input-placeholder{color:transparent}#fs_billing_address input.fs-read-mode,#fs_billing_address select.fs-read-mode{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode td span{display:none}#fs_billing_address.fs-read-mode input,#fs_billing_address.fs-read-mode select{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode input::-moz-placeholder,#fs_billing_address.fs-read-mode select::-moz-placeholder{color:#ccc;opacity:1}#fs_billing_address.fs-read-mode input:-ms-input-placeholder,#fs_billing_address.fs-read-mode select:-ms-input-placeholder{color:#ccc}#fs_billing_address.fs-read-mode input::-webkit-input-placeholder,#fs_billing_address.fs-read-mode select::-webkit-input-placeholder{color:#ccc}#fs_billing_address button{display:block;width:100%}
vendor/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}}
vendor/freemius/assets/css/admin/affiliation.css ADDED
@@ -0,0 +1 @@
 
1
+ @charset "UTF-8";#fs_affiliation_content_wrapper #messages{margin-top:25px}#fs_affiliation_content_wrapper h3{font-size:24px;padding:0;margin-left:0}#fs_affiliation_content_wrapper ul li{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;list-style-type:none}#fs_affiliation_content_wrapper ul li:before{content:'✓';margin-right:10px;font-weight:bold}#fs_affiliation_content_wrapper p:not(.description),#fs_affiliation_content_wrapper li,#fs_affiliation_content_wrapper label{font-size:16px !important;line-height:26px !important}#fs_affiliation_content_wrapper .button{margin-top:20px;margin-bottom:7px;line-height:35px;height:40px;font-size:16px}#fs_affiliation_content_wrapper .button#cancel_button{margin-right:5px}#fs_affiliation_content_wrapper form .input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form .input-container .input-label{font-weight:bold;display:block;width:100%}#fs_affiliation_content_wrapper form .input-container.input-container-text label,#fs_affiliation_content_wrapper form .input-container.input-container-text input,#fs_affiliation_content_wrapper form .input-container.input-container-text textarea{display:block}#fs_affiliation_content_wrapper form .input-container #add_domain,#fs_affiliation_content_wrapper form .input-container .remove-domain{text-decoration:none;display:inline-block;margin-top:3px}#fs_affiliation_content_wrapper form .input-container #add_domain:focus,#fs_affiliation_content_wrapper form .input-container .remove-domain:focus{box-shadow:none}#fs_affiliation_content_wrapper form .input-container #add_domain.disabled,#fs_affiliation_content_wrapper form .input-container .remove-domain.disabled{color:#aaa;cursor:default}#fs_affiliation_content_wrapper form #extra_domains_container .description{margin-top:0;position:relative;top:-4px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain{display:inline-block;margin-right:5px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain:last-of-type{margin-bottom:0}
vendor/freemius/assets/css/admin/checkout.css ADDED
@@ -0,0 +1 @@
 
1
+ @media screen and (max-width: 782px){#wpbody-content{padding-bottom:0 !important}}
vendor/freemius/assets/css/admin/common.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .theme-browser .theme .fs-premium-theme-badge{position:absolute;top:10px;right:0;background:#71ae00;color:#fff;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);font-size:1.1em}#iframe{line-height:0;font-size:0}.fs-full-size-wrapper{margin:40px 0 -65px -20px}@media (max-width: 600px){.fs-full-size-wrapper{margin:0 0 -65px -10px}}
2
+ .fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,0.3);color:#fff;padding:2px 10px;position:absolute;top:100%;bottom:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}div.fs-notice.updated,div.fs-notice.success,div.fs-notice.promotion{display:block !important}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;-moz-box-shadow:0 2px 2px rgba(6,113,6,0.3);-webkit-box-shadow:0 2px 2px rgba(6,113,6,0.3);box-shadow:0 2px 2px rgba(6,113,6,0.3);opacity:0.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}.fs-secure-notice a.fs-security-proof{color:green;text-decoration:none}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 600px){.fs-secure-notice{display:none}}@media screen and (max-width: 500px){#fs_promo_tab{display:none}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}.fs-submenu-item.pricing.upgrade-mode{color:greenyellow}.fs-submenu-item.pricing.trial-mode{color:#83e2ff}#adminmenu .update-plugins.fs-trial{background-color:#00b9eb}.fs-ajax-spinner{border:0;width:20px;height:20px;margin-right:5px;vertical-align:sub;display:inline-block;background:url("../../../../../../../wp-admin/images/wpspin_light-2x.gif");background-size:contain}.wrap.fs-section h2{text-align:left}
vendor/freemius/assets/css/admin/connect.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,0.3);box-shadow:0px 1px 2px rgba(0,0,0,0.3);margin:20px 0}@media screen and (max-width: 479px){#fs_connect{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;width:auto;margin:0 0 0 -10px}}#fs_connect .fs-content{background:#fff;padding:15px 20px}#fs_connect .fs-content .fs-error{background:snow;color:#d3135a;border:1px solid #d3135a;-moz-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);text-align:center;padding:5px;margin-bottom:10px}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-license-key-container{position:relative;width:280px;margin:10px auto 0 auto}#fs_connect .fs-license-key-container input{width:100%}#fs_connect .fs-license-key-container .dashicons{position:absolute;top:5px;right:5px}#fs_connect.require-license-key #sites_list_container td{cursor:pointer}#fs_connect #delegate_to_site_admins{margin-right:15px;float:right;height:26px;vertical-align:middle;line-height:37px;font-weight:bold;border-bottom:1px dashed;text-decoration:none}#fs_connect #delegate_to_site_admins.rtl{margin-left:15px;margin-right:0}#fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}#fs_connect .fs-actions .button{padding:0 10px 1px;line-height:35px;height:37px;font-size:16px;margin-bottom:0}#fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}#fs_connect .fs-actions .button.button-primary{padding-right:15px;padding-left:15px}#fs_connect .fs-actions .button.button-primary:after{content:' \279C'}#fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}#fs_connect .fs-actions .button.button-secondary{float:right}#fs_connect.fs-anonymous-disabled .fs-actions .button.button-primary{width:100%}#fs_connect .fs-permissions{padding:10px 20px;background:#FEFEFE;-moz-transition:background 0.5s ease;-o-transition:background 0.5s ease;-ms-transition:background 0.5s ease;-webkit-transition:background 0.5s ease;transition:background 0.5s ease}#fs_connect .fs-permissions .fs-license-sync-disclaimer{text-align:center;margin-top:0}#fs_connect .fs-permissions .fs-trigger{font-size:0.9em;text-decoration:none;text-align:center;display:block}#fs_connect .fs-permissions ul{height:0;overflow:hidden;margin:0}#fs_connect .fs-permissions ul li{margin-bottom:12px}#fs_connect .fs-permissions ul li:last-child{margin-bottom:0}#fs_connect .fs-permissions ul li i.dashicons{float:left;font-size:40px;width:40px;height:40px}#fs_connect .fs-permissions ul li div{margin-left:55px}#fs_connect .fs-permissions ul li div span{font-weight:bold;text-transform:uppercase;color:#23282d}#fs_connect .fs-permissions ul li div p{margin:2px 0 0 0}#fs_connect .fs-permissions.fs-open{background:#fff}#fs_connect .fs-permissions.fs-open ul{height:auto;margin:20px 20px 10px 20px}@media screen and (max-width: 479px){#fs_connect .fs-permissions{background:#fff}#fs_connect .fs-permissions .fs-trigger{display:none}#fs_connect .fs-permissions ul{height:auto;margin:20px}}#fs_connect .fs-freemium-licensing{padding:8px;background:#777;color:#fff}#fs_connect .fs-freemium-licensing p{text-align:center;display:block;margin:0;padding:0}#fs_connect .fs-freemium-licensing a{color:#C2EEFF;text-decoration:underline}#fs_connect .fs-visual{padding:12px;line-height:0;background:#fafafa;height:80px;position:relative}#fs_connect .fs-visual .fs-site-icon{position:absolute;left:20px;top:10px}#fs_connect .fs-visual .fs-connect-logo{position:absolute;right:20px;top:10px}#fs_connect .fs-visual .fs-plugin-icon{position:absolute;top:10px;left:50%;margin-left:-40px}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-site-icon,#fs_connect .fs-visual img,#fs_connect .fs-visual object{width:80px;height:80px}#fs_connect .fs-visual .dashicons-wordpress{font-size:64px;background:#01749a;color:#fff;width:64px;height:64px;padding:8px}#fs_connect .fs-visual .dashicons-plus{position:absolute;top:50%;font-size:30px;margin-top:-10px;color:#bbb}#fs_connect .fs-visual .dashicons-plus.fs-first{left:28%}#fs_connect .fs-visual .dashicons-plus.fs-second{left:65%}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-connect-logo,#fs_connect .fs-visual .fs-site-icon{border:1px solid #ccc;padding:1px;background:#fff}#fs_connect .fs-terms{text-align:center;font-size:0.85em;padding:5px;background:rgba(0,0,0,0.05)}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}#multisite_options_container{margin-top:10px;border:1px solid #ccc;padding:5px}#multisite_options_container a{text-decoration:none}#multisite_options_container a:focus{box-shadow:none}#multisite_options_container a.selected{font-weight:bold}#multisite_options_container.apply-on-all-sites{border:0 none;padding:0}#multisite_options_container.apply-on-all-sites #all_sites_options{border-spacing:0}#multisite_options_container.apply-on-all-sites #all_sites_options td:not(:first-child){display:none}#multisite_options_container #sites_list_container{display:none;overflow:auto}#multisite_options_container #sites_list_container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-tooltip-trigger{position:relative}.fs-tooltip-trigger:not(a){cursor:help}.fs-tooltip-trigger .fs-tooltip{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:rgba(0,0,0,0.8);color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl .fs-tooltip-trigger .fs-tooltip{text-align:right}.fs-tooltip-trigger .fs-tooltip::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:rgba(0,0,0,0.8) transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl .fs-tooltip-trigger .fs-tooltip::after{right:21px;left:auto}.fs-tooltip-trigger:hover .fs-tooltip{visibility:visible;opacity:1}#fs_marketing_optin{display:none;margin-top:10px;border:1px solid #ccc;padding:10px;line-height:1.5em}#fs_marketing_optin .fs-message{display:block;margin-bottom:5px;font-size:1.05em;font-weight:600}#fs_marketing_optin.error{border:1px solid #d3135a;background:#fee}#fs_marketing_optin.error .fs-message{color:#d3135a}#fs_marketing_optin .fs-input-container{margin-top:5px}#fs_marketing_optin .fs-input-container label{margin-top:5px;display:block}#fs_marketing_optin .fs-input-container label input{float:left;margin:1px 0 0 0}#fs_marketing_optin .fs-input-container label:first-child{display:block;margin-bottom:2px}#fs_marketing_optin .fs-input-label{display:block;margin-left:20px}#fs_marketing_optin .fs-input-label .underlined{text-decoration:underline}.rtl #fs_marketing_optin .fs-input-container label input{float:right}.rtl #fs_marketing_optin .fs-input-label{margin-left:0;margin-right:20px}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:' \000bb'}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-permissions ul li div{margin-right:55px;margin-left:0}.rtl #fs_connect .fs-permissions ul li i.dashicons{float:right}.rtl #fs_connect .fs-visual .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-visual .fs-connect-logo{right:auto;left:20px}#fs_theme_connect_wrapper{position:fixed;top:0;height:100%;width:100%;z-index:99990;background:rgba(0,0,0,0.75);text-align:center;overflow-y:auto}#fs_theme_connect_wrapper:before{content:"";display:inline-block;vertical-align:middle;height:100%}#fs_theme_connect_wrapper>button.close{color:white;cursor:pointer;height:40px;width:40px;position:absolute;right:0;border:0;background-color:transparent;top:32px}#fs_theme_connect_wrapper #fs_connect{top:0;text-align:left;display:inline-block;vertical-align:middle;margin-top:52px;margin-bottom:20px}#fs_theme_connect_wrapper #fs_connect .fs-terms{background:rgba(140,140,140,0.64)}#fs_theme_connect_wrapper #fs_connect .fs-terms,#fs_theme_connect_wrapper #fs_connect .fs-terms a{color:#c5c5c5}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}
vendor/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}
vendor/freemius/assets/css/admin/debug.css ADDED
@@ -0,0 +1 @@
 
1
+ .switch{position:relative;display:inline-block;font-size:1.6em;font-weight:bold;color:#ccc;text-shadow:0px 1px 1px rgba(255,255,255,0.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);border-radius:4px;background:#ececec;box-shadow:0px 0px 4px rgba(0,0,0,0.1),inset 0px 1px 3px 0px rgba(0,0,0,0.1);cursor:pointer}.switch span{display:inline-block;width:35px;text-transform:uppercase}.switch span.on{color:#6bc406}.switch .toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.3);border-radius:4px;background:#fff;background:-moz-linear-gradient(top, #ececec 0%, #fff 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));background:-webkit-linear-gradient(top, #ececec 0%, #fff 100%);background:-o-linear-gradient(top, #ececec 0%, #fff 100%);background:-ms-linear-gradient(top, #ececec 0%, #fff 100%);background:linear-gradient(top, #ececec 0%, #fff 100%);box-shadow:inset 0px 1px 0px 0px rgba(255,255,255,0.5);z-index:999;-moz-transition:all 0.15s ease-in-out;-o-transition:all 0.15s ease-in-out;-ms-transition:all 0.15s ease-in-out;-webkit-transition:all 0.15s ease-in-out;transition:all 0.15s ease-in-out}.switch.on .toggle{left:2%}.switch.off .toggle{left:54%}.switch.round{padding:0px 20px;border-radius:40px}.switch.round .toggle{border-radius:40px;width:14px;height:14px}.switch.round.on .toggle{left:3%;background:#6bc406}.switch.round.off .toggle{left:58%}.switch-label{font-size:20px;line-height:31px;margin:0 5px}#fs_log_book table{font-family:Consolas,Monaco,monospace;font-size:12px}#fs_log_book table th{color:#ccc}#fs_log_book table tr{background:#232525}#fs_log_book table tr.alternate{background:#2b2b2b}#fs_log_book table tr td.fs-col--logger{color:#5a7435}#fs_log_book table tr td.fs-col--type{color:#ffc861}#fs_log_book table tr td.fs-col--function{color:#a7b7b1;font-weight:bold}#fs_log_book table tr td.fs-col--message,#fs_log_book table tr td.fs-col--message a{color:#9a73ac !important}#fs_log_book table tr td.fs-col--file{color:#d07922}#fs_log_book table tr td.fs-col--timestamp{color:#6596be}
vendor/freemius/assets/css/admin/dialog-boxes.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal.fs-success .fs-modal-header{border-bottom-color:#46b450}.fs-modal.fs-success .fs-modal-body{background-color:#f7fff7}.fs-modal.fs-warn .fs-modal-header{border-bottom-color:#ffb900}.fs-modal.fs-warn .fs-modal-body{background-color:#fff8e5}.fs-modal.fs-error .fs-modal-header{border-bottom-color:#dc3232}.fs-modal.fs-error .fs-modal-body{background-color:#ffeaea}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-header{border-bottom:#eeeeee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative;margin-bottom:-10px}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:0.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all 0.2s ease-in-out;-o-transition:all 0.2s ease-in-out;-ms-transition:all 0.2s ease-in-out;-webkit-transition:all 0.2s ease-in-out;transition:all 0.2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-header .fs-close .dashicons,.fs-modal .fs-modal-header .fs-close:hover .dashicons{text-decoration:none}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px;line-height:1.5em}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}.rtl .fs-modal .fs-modal-header .fs-close{right:auto;left:20px}body.has-fs-modal{overflow:hidden}.fs-modal.fs-modal-deactivation-feedback .reason-input,.fs-modal.fs-modal-deactivation-feedback .internal-message{margin:3px 0 3px 22px}.fs-modal.fs-modal-deactivation-feedback .reason-input input,.fs-modal.fs-modal-deactivation-feedback .reason-input textarea,.fs-modal.fs-modal-deactivation-feedback .internal-message input,.fs-modal.fs-modal-deactivation-feedback .internal-message textarea{width:100%}.fs-modal.fs-modal-deactivation-feedback li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}@media (max-width: 650px){.fs-modal.fs-modal-deactivation-feedback li.reason li.reason{margin-bottom:10px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .reason-input,.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .internal-message{margin-left:29px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label{display:table}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label{float:left}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel{margin-top:0 !important}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel h3{margin-top:0;line-height:1.5em}#the-list .deactivate>.fs-slug{display:none}.fs-modal.fs-modal-license-activation .fs-modal-body input.license_key{width:100%}#license_options_container table,#license_options_container table select,#license_options_container table #available_license_key{width:100%}#license_options_container table td:first-child{width:1%}#license_options_container table #other_license_key_container label{position:relative;top:6px;float:left;margin-right:5px}#license_options_container table #other_license_key_container div{overflow:hidden;width:auto;height:30px;display:block;top:2px;position:relative}#license_options_container table #other_license_key_container div input{margin:0}#sites_list_container td{cursor:pointer}#multisite_options_container{margin-top:10px;border:1px solid #ccc;padding:5px}#multisite_options_container a{text-decoration:none}#multisite_options_container a:focus{box-shadow:none}#multisite_options_container a.selected{font-weight:bold}#multisite_options_container.apply-on-all-sites{border:0 none;padding:0}#multisite_options_container.apply-on-all-sites #all_sites_options{border-spacing:0}#multisite_options_container.apply-on-all-sites #all_sites_options td:not(:first-child){display:none}#multisite_options_container #sites_list_container{display:none;overflow:auto}#multisite_options_container #sites_list_container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-modal.fs-modal-license-key-resend .email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend.fs-freemium input.email-address{width:300px}.fs-modal.fs-modal-license-key-resend.fs-freemium label{display:block;margin-bottom:10px}.fs-modal.fs-modal-license-key-resend.fs-premium input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{float:right;margin-left:7px}@media (max-width: 650px){.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{margin-top:2px}}
2
+ .rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}.fs-ajax-loader{position:relative;width:170px;height:20px;margin:auto}.fs-ajax-loader .fs-ajax-loader-bar{position:absolute;top:0;background-color:#0074a3;width:20px;height:20px;-webkit-animation-name:bounce_ajaxLoader;-moz-animation-name:bounce_ajaxLoader;-ms-animation-name:bounce_ajaxLoader;-o-animation-name:bounce_ajaxLoader;animation-name:bounce_ajaxLoader;-webkit-animation-duration:1.5s;-moz-animation-duration:1.5s;-ms-animation-duration:1.5s;-o-animation-duration:1.5s;animation-duration:1.5s;animation-iteration-count:infinite;-o-animation-iteration-count:infinite;-ms-animation-iteration-count:infinite;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;-webkit-animation-direction:normal;-moz-animation-direction:normal;-ms-animation-direction:normal;-o-animation-direction:normal;animation-direction:normal;-moz-transform:0.3;-o-transform:0.3;-ms-transform:0.3;-webkit-transform:0.3;transform:0.3}.fs-ajax-loader .fs-ajax-loader-bar-1{left:0px;animation-delay:0.6s;-o-animation-delay:0.6s;-ms-animation-delay:0.6s;-webkit-animation-delay:0.6s;-moz-animation-delay:0.6s}.fs-ajax-loader .fs-ajax-loader-bar-2{left:19px;animation-delay:0.75s;-o-animation-delay:0.75s;-ms-animation-delay:0.75s;-webkit-animation-delay:0.75s;-moz-animation-delay:0.75s}.fs-ajax-loader .fs-ajax-loader-bar-3{left:38px;animation-delay:0.9s;-o-animation-delay:0.9s;-ms-animation-delay:0.9s;-webkit-animation-delay:0.9s;-moz-animation-delay:0.9s}.fs-ajax-loader .fs-ajax-loader-bar-4{left:57px;animation-delay:1.05s;-o-animation-delay:1.05s;-ms-animation-delay:1.05s;-webkit-animation-delay:1.05s;-moz-animation-delay:1.05s}.fs-ajax-loader .fs-ajax-loader-bar-5{left:76px;animation-delay:1.2s;-o-animation-delay:1.2s;-ms-animation-delay:1.2s;-webkit-animation-delay:1.2s;-moz-animation-delay:1.2s}.fs-ajax-loader .fs-ajax-loader-bar-6{left:95px;animation-delay:1.35s;-o-animation-delay:1.35s;-ms-animation-delay:1.35s;-webkit-animation-delay:1.35s;-moz-animation-delay:1.35s}.fs-ajax-loader .fs-ajax-loader-bar-7{left:114px;animation-delay:1.5s;-o-animation-delay:1.5s;-ms-animation-delay:1.5s;-webkit-animation-delay:1.5s;-moz-animation-delay:1.5s}.fs-ajax-loader .fs-ajax-loader-bar-8{left:133px;animation-delay:1.65s;-o-animation-delay:1.65s;-ms-animation-delay:1.65s;-webkit-animation-delay:1.65s;-moz-animation-delay:1.65s}@-moz-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-ms-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-o-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-webkit-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}.fs-modal-auto-install #request-filesystem-credentials-form h2,.fs-modal-auto-install #request-filesystem-credentials-form .request-filesystem-credentials-action-buttons{display:none}.fs-modal-auto-install #request-filesystem-credentials-form input[type=password],.fs-modal-auto-install #request-filesystem-credentials-form input[type=email],.fs-modal-auto-install #request-filesystem-credentials-form input[type=text]{-webkit-appearance:none;padding:10px 10px 5px 10px;width:300px;max-width:100%}.fs-modal-auto-install #request-filesystem-credentials-form>div,.fs-modal-auto-install #request-filesystem-credentials-form label,.fs-modal-auto-install #request-filesystem-credentials-form fieldset{width:300px;max-width:100%;margin:0 auto;display:block}
vendor/freemius/assets/css/admin/gdpr-optin-notice.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice[data-id^="gdpr_optin_actions"] .underlined{text-decoration:underline}.fs-notice[data-id^="gdpr_optin_actions"] ul .button,.fs-notice[data-id^="gdpr_optin_actions"] ul .action-description{vertical-align:middle}.fs-notice[data-id^="gdpr_optin_actions"] ul .action-description{display:inline-block;margin-left:3px}
vendor/freemius/assets/css/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/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}
vendor/freemius/assets/css/customizer.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_customizer_upsell .fs-customizer-plan{padding:10px 20px 20px 20px;border-radius:3px;background:#fff}#fs_customizer_upsell .fs-customizer-plan h2{position:relative;margin:0;line-height:2em;text-transform:uppercase}#fs_customizer_upsell .fs-customizer-plan h2 .button-link{top:-2px}#fs_customizer_upsell .fs-feature{position:relative}#fs_customizer_upsell .dashicons-yes{color:#0085ba;font-size:2em;vertical-align:bottom;margin-left:-7px;margin-right:10px}.rtl #fs_customizer_upsell .dashicons-yes{margin-left:10px;margin-right:-7px}#fs_customizer_upsell .dashicons-editor-help{color:#bbb;cursor:help}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:#000;color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{text-align:right}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:#000 transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{right:21px;left:auto}#fs_customizer_upsell .dashicons-editor-help:hover .fs-feature-desc{visibility:visible;opacity:1}#fs_customizer_upsell .button-primary{display:block;text-align:center;margin-top:10px}#fs_customizer_support{display:block !important}#fs_customizer_support .button{float:right}#fs_customizer_support .button-group{width:100%;display:block;margin-top:10px}#fs_customizer_support .button-group .button{float:none;width:50%;text-align:center}
vendor/freemius/assets/css/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/assets/img/404-to-301-log-manager.png ADDED
Binary file
vendor/freemius/assets/img/404-to-301.png ADDED
Binary file
vendor/freemius/assets/img/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/assets/img/plugin-icon.png ADDED
Binary file
vendor/freemius/assets/img/theme-icon.png ADDED
Binary file
vendor/freemius/assets/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/assets/js/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/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
+ }
vendor/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};
vendor/freemius/assets/js/postmessage.js ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($, undef) {
2
+ var global = this;
3
+
4
+ // Namespace.
5
+ global.FS = global.FS || {};
6
+
7
+ global.FS.PostMessage = function ()
8
+ {
9
+ var
10
+ _is_child = false,
11
+ _postman = new NoJQueryPostMessageMixin('postMessage', 'receiveMessage'),
12
+ _callbacks = {},
13
+ _base_url,
14
+ _parent_url = decodeURIComponent(document.location.hash.replace(/^#/, '')),
15
+ _parent_subdomain = _parent_url.substring(0, _parent_url.indexOf('/', ('https://' === _parent_url.substring(0, ('https://').length)) ? 8 : 7)),
16
+ _init = function () {
17
+ _postman.receiveMessage(function (e) {
18
+ var data = JSON.parse(e.data);
19
+
20
+ if (_callbacks[data.type]) {
21
+ for (var i = 0; i < _callbacks[data.type].length; i++) {
22
+ // Execute type callbacks.
23
+ _callbacks[data.type][i](data.data);
24
+ }
25
+ }
26
+ }, _base_url);
27
+ },
28
+ _hasParent = ('' !== _parent_url),
29
+ $window = $(window),
30
+ $html = $('html');
31
+
32
+ return {
33
+ init : function (url, iframes)
34
+ {
35
+ _base_url = url;
36
+ _init();
37
+
38
+ // Automatically receive forward messages.
39
+ FS.PostMessage.receiveOnce('forward', function (data){
40
+ window.location = data.url;
41
+ });
42
+
43
+ iframes = iframes || [];
44
+
45
+ if (iframes.length > 0) {
46
+ $window.on('scroll', function () {
47
+ for (var i = 0; i < iframes.length; i++) {
48
+ FS.PostMessage.postScroll(iframes[i]);
49
+ }
50
+ });
51
+ }
52
+ },
53
+ init_child : function ()
54
+ {
55
+ this.init(_parent_subdomain);
56
+
57
+ _is_child = true;
58
+
59
+ // Post height of a child right after window is loaded.
60
+ $(window).bind('load', function () {
61
+ FS.PostMessage.postHeight();
62
+
63
+ // Post message that window was loaded.
64
+ FS.PostMessage.post('loaded');
65
+ });
66
+ },
67
+ hasParent : function ()
68
+ {
69
+ return _hasParent;
70
+ },
71
+ postHeight : function (diff, wrapper) {
72
+ diff = diff || 0;
73
+ wrapper = wrapper || '#wrap_section';
74
+ this.post('height', {
75
+ height: diff + $(wrapper).outerHeight(true)
76
+ });
77
+ },
78
+ postScroll : function (iframe) {
79
+ this.post('scroll', {
80
+ top: $window.scrollTop(),
81
+ height: ($window.height() - parseFloat($html.css('paddingTop')) - parseFloat($html.css('marginTop')))
82
+ }, iframe);
83
+ },
84
+ post : function (type, data, iframe)
85
+ {
86
+ console.debug('PostMessage.post', type);
87
+
88
+ if (iframe)
89
+ {
90
+ // Post to iframe.
91
+ _postman.postMessage(JSON.stringify({
92
+ type: type,
93
+ data: data
94
+ }), iframe.src, iframe.contentWindow);
95
+ }
96
+ else {
97
+ // Post to parent.
98
+ _postman.postMessage(JSON.stringify({
99
+ type: type,
100
+ data: data
101
+ }), _parent_url, window.parent);
102
+ }
103
+ },
104
+ receive: function (type, callback)
105
+ {
106
+ console.debug('PostMessage.receive', type);
107
+
108
+ if (undef === _callbacks[type])
109
+ _callbacks[type] = [];
110
+
111
+ _callbacks[type].push(callback);
112
+ },
113
+ receiveOnce: function (type, callback)
114
+ {
115
+ if (this.is_set(type))
116
+ return;
117
+
118
+ this.receive(type, callback);
119
+ },
120
+ // Check if any callbacks assigned to a specified message type.
121
+ is_set: function (type)
122
+ {
123
+ return (undef != _callbacks[type]);
124
+ },
125
+ parent_url: function ()
126
+ {
127
+ return _parent_url;
128
+ },
129
+ parent_subdomain: function ()
130
+ {
131
+ return _parent_subdomain;
132
+ }
133
+ };
134
+ }();
135
+ })(jQuery);
vendor/freemius/assets/scss/_colors.scss ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $menu-hover-color: #333;
2
+ $darkest-color: #000;
3
+ $fms-live-color: #71ae00;
4
+ $fms-test-color: #f7941d;
5
+ $fms-link-color: #29abe1;
6
+ $fms-link-hover-color: darken(#29abe1, 10%);
7
+ $body-bkg: #111;
8
+ $special-color: #d3135a;
9
+ $body-color: #f1f1f1;
10
+ $fms-white: #f1f1f1;
11
+ $container-bkg: #222;
12
+ $container-bkg-odd: #262626;
13
+ $container-border-color: #333;
14
+ $table-head-bkg: #333;
15
+ $table-head-color: #999;
16
+ $info-color: #999;
17
+ $error-color: #ff0000;
18
+
19
+ $fs-logo-blue-color: #29abe1;
20
+ $fs-logo-green-color: #71ae00;
21
+ $fs-logo-magenta-color: #d3135a;
22
+
23
+ // WordPress colors.
24
+ $page-header-bkg: #333;
25
+ $page-header-color: $fms-white;
26
+ $text-dark-color: #333;
27
+ $text-light-color: #666;
28
+ $text-lightest-color: #999;
29
+
30
+ // Notices.
31
+ $wp-notice-success-color: #f7fff7;
32
+ $wp-notice-success-dark-color: #46b450;
33
+ $wp-notice-error-color: #ffeaea;
34
+ $wp-notice-error-dark-color: #dc3232;
35
+ $wp-notice-warn-color: #fff8e5;
36
+ $wp-notice-warn-dark-color: #ffb900;
37
+ $fs-notice-promotion-border-color: #00a0d2;
38
+ $fs-notice-promotion-bkg: #f2fcff;
39
+
40
+ // WP Buttons.
41
+ $button-primary-bkg: #6bc406;
42
+ $button-primary-color: $fms-white;
43
+ $button-secondary-bkg: #333;
44
+ $button-secondary-color: $fms-white;
45
+ $featured-color: #6bc406;
46
+ $wp-selected-color: #0074a3;
47
+
48
+ $wordpress_color: #01749A;
49
+ $blogger_color: #ff8100;
50
+ $wix_color: #fac102;
51
+ $shopify_color: #80d100;
52
+ $addthis_color: #fe6d4e;
53
+ $tumblr_color: #34506b;
54
+ $zepo_color: #00baf2;
55
+ $jquery_color: #000919;
56
+ $javascript_color: #00baf2;
57
+ $squarespace_color: #000;
58
+
59
+ $blog_color: #ff6600;
60
+ $facebook_color: #3b5998;
61
+ $twitter_color: #4099ff;
62
+ $linkedin_color: #4875b4;
63
+ $youtube_color: #ff3333;
64
+ $gplus_color: #c63d2d;
65
+
66
+ // Tooltip
67
+ $tooltip-color: #fff;
68
+ $tooltip-bkg-color: rgba(0,0,0,0.8);
vendor/freemius/assets/scss/_functions.scss ADDED
File without changes
vendor/freemius/assets/scss/_load.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import 'mixins';
2
+ @import "vars";
3
+ @import "functions";
4
+ @import "colors";
vendor/freemius/assets/scss/_mixins.scss ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ---- CSS3 SASS MIXINS ----
2
+ // https://github.com/madr/css3-sass-mixins
3
+ //
4
+ // Copyright (C) 2011 by Anders Ytterström
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in
14
+ // all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ // THE SOFTWARE.
23
+ //
24
+
25
+ // ---- LEGACY IE SUPPORT USING FILTERS ----
26
+ // Should IE filters be used or not?
27
+ // PROS: gradients, drop shadows etc will be handled by css.
28
+ // CONS: will harm the site performance badly,
29
+ // especially on sites with heavy rendering and scripting.
30
+ $useIEFilters: 0;
31
+ // might be 0 or 1. disabled by default.
32
+ // ---- /LEGACY IE SUPPORT USING FILTERS ----
33
+
34
+
35
+ @mixin background-size ($value) {
36
+ -webkit-background-size: $value;
37
+ background-size: $value;
38
+ }
39
+
40
+ @mixin border-image ($path, $offsets, $repeats) {
41
+ -moz-border-image: $path $offsets $repeats;
42
+ -o-border-image: $path $offsets $repeats;
43
+ -webkit-border-image: $path $offsets $repeats;
44
+ border-image: $path $offsets $repeats;
45
+ }
46
+
47
+ @mixin border-radius ($values...) {
48
+ -moz-border-radius: $values;
49
+ -webkit-border-radius: $values;
50
+ border-radius: $values;
51
+ /*-moz-background-clip: padding;
52
+ -webkit-background-clip: padding-box;
53
+ background-clip: padding-box;*/
54
+ }
55
+
56
+ @mixin box-shadow ($values...) {
57
+ -moz-box-shadow: $values;
58
+ -webkit-box-shadow: $values;
59
+ box-shadow: $values;
60
+ }
61
+
62
+ //@mixin box-shadow ($x, $y, $offset, $hex, $ie: $useIEFilters, $inset: null, $spread:null) {
63
+ // -moz-box-shadow: $x $y $offset $spread $hex $inset;
64
+ // -webkit-box-shadow: $x $y $offset $spread $hex $inset;
65
+ // box-shadow: $x $y $offset $spread $hex $inset;
66
+ //
67
+ // @if $ie == 1 {
68
+ // $iecolor: '#' + red($hex) + green($hex) + blue($hex);
69
+ // filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}');
70
+ // -ms-filter: quote(progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}'));
71
+ // }
72
+ //}
73
+
74
+ @mixin box-sizing($value) {
75
+ -moz-box-sizing: $value;
76
+ -webkit-box-sizing: $value;
77
+ box-sizing: $value;
78
+ }
79
+
80
+ // requires sass 3.2
81
+ @mixin keyframes($name){
82
+ @-moz-keyframes #{$name} { @content; }
83
+ @-ms-keyframes #{$name} { @content; }
84
+ @-o-keyframes #{$name} { @content; }
85
+ @-webkit-keyframes #{$name} { @content; }
86
+ @keyframes #{$name} { @content; }
87
+ }
88
+
89
+ @mixin linear-gradient($from, $to, $ie: $useIEFilters) {
90
+ @if $ie != 1 { background-color: $to; }
91
+
92
+ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, $from),color-stop(1, $to));
93
+ background-image: -webkit-linear-gradient(top, $from, $to);
94
+ background-image: -moz-linear-gradient(top, $from, $to);
95
+ background-image: -ms-linear-gradient(top, $from, $to);
96
+ background-image: -o-linear-gradient(top, $from, $to);
97
+ background-image: linear-gradient(top, bottom, $from, $to);
98
+
99
+ @if $ie == 1 {
100
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
101
+ }
102
+ }
103
+
104
+ @mixin horizontal-gradient($startColor: #555, $endColor: #333, $ie: $useIEFilters) {
105
+ @if $ie != 1 { background-color: $endColor; }
106
+
107
+ background-color: $endColor;
108
+ background-image: -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
109
+ background-image: -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
110
+ background-image: -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
111
+ background-image: -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
112
+ background-image: linear-gradient(to right, $startColor, $endColor); // Standard, IE10
113
+ background-repeat: repeat-x;
114
+ @if $ie == 1 {
115
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$startColor}', endColorstr='#{$endColor}', GradientType=1);
116
+ }
117
+ }
118
+
119
+ @mixin radial-gradient($from, $to, $ie: $useIEFilters) {
120
+ @if $ie != 1 { background-color: $to; }
121
+
122
+ background: -moz-radial-gradient(center, circle cover, $from 0%, $to 100%);
123
+ background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, $from), color-stop(100%, $to));
124
+ background: -webkit-radial-gradient(center, circle cover, $from 0%, $to 100%);
125
+ background: -o-radial-gradient(center, circle cover, $from 0%, $to 100%);
126
+ background: -ms-radial-gradient(center, circle cover, $from 0%, $to 100%);
127
+ background: radial-gradient(center, circle cover, $from 0%, $to 100%);
128
+ background-color: $from;
129
+
130
+ @if $ie == 1 {
131
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}', GradientType=1); /* IE6-9 fallback on horizontal gradient */
132
+ }
133
+ }
134
+
135
+ @mixin perspective($perspective) {
136
+ -moz-perspective: $perspective;
137
+ -ms-perspective: $perspective;
138
+ -webkit-perspective: $perspective;
139
+ perspective: $perspective;
140
+ -moz-transform-style: preserve-3d;
141
+ -ms-transform-style: preserve-3d;
142
+ -webkit-transform-style: preserve-3d;
143
+ transform-style: preserve-3d;
144
+ }
145
+
146
+ @mixin transform ($transforms) {
147
+ -moz-transform: $transforms;
148
+ -o-transform: $transforms;
149
+ -ms-transform: $transforms;
150
+ -webkit-transform: $transforms;
151
+ transform: $transforms;
152
+ }
153
+
154
+ @mixin matrix ($a, $b, $c, $d, $e, $f) {
155
+ -moz-transform: matrix($a, $b, $c, $d, #{$e}px, #{$f}px);
156
+ -o-transform: matrix($a, $b, $c, $d, $e, $f);
157
+ -ms-transform: matrix($a, $b, $c, $d, $e, $f);
158
+ -webkit-transform: matrix($a, $b, $c, $d, $e, $f);
159
+ transform: matrix($a, $b, $c, $d, $e, $f);
160
+ }
161
+
162
+ @mixin rotate ($deg) {
163
+ @include transform(rotate(#{$deg}deg));
164
+ }
165
+
166
+ @mixin scale ($size) {
167
+ @include transform(scale(#{$size}));
168
+ }
169
+
170
+ @mixin translate ($x, $y) {
171
+ @include transform(translate($x, $y));
172
+ }
173
+
174
+ @mixin transition ($value...) {
175
+ -moz-transition: $value;
176
+ -o-transition: $value;
177
+ -ms-transition: $value;
178
+ -webkit-transition: $value;
179
+ transition: $value;
180
+ }
181
+
182
+ @mixin animation($str) {
183
+ -webkit-animation: #{$str};
184
+ -moz-animation: #{$str};
185
+ -ms-animation: #{$str};
186
+ -o-animation: #{$str};
187
+ animation: #{$str};
188
+ }
189
+
190
+ @mixin animation-name($str) {
191
+ -webkit-animation-name: #{$str};
192
+ -moz-animation-name: #{$str};
193
+ -ms-animation-name: #{$str};
194
+ -o-animation-name: #{$str};
195
+ animation-name: #{$str};
196
+ }
197
+
198
+ @mixin animation-duration($str) {
199
+ -webkit-animation-duration: #{$str};
200
+ -moz-animation-duration: #{$str};
201
+ -ms-animation-duration: #{$str};
202
+ -o-animation-duration: #{$str};
203
+ animation-duration: #{$str};
204
+ }
205
+
206
+ @mixin animation-direction($str) {
207
+ -webkit-animation-direction: #{$str};
208
+ -moz-animation-direction: #{$str};
209
+ -ms-animation-direction: #{$str};
210
+ -o-animation-direction: #{$str};
211
+ animation-direction: #{$str};
212
+ }
213
+
214
+ @mixin animation-delay($str) {
215
+ animation-delay:#{$str};
216
+ -o-animation-delay:#{$str};
217
+ -ms-animation-delay:#{$str};
218
+ -webkit-animation-delay:#{$str};
219
+ -moz-animation-delay:#{$str};
220
+ }
221
+
222
+ @mixin animation-iteration-count($str) {
223
+ animation-iteration-count:#{$str};
224
+ -o-animation-iteration-count:#{$str};
225
+ -ms-animation-iteration-count:#{$str};
226
+ -webkit-animation-iteration-count:#{$str};
227
+ -moz-animation-iteration-count:#{$str};
228
+ }
229
+
230
+ @mixin animation-timing-function($str) {
231
+ -webkit-animation-timing-function: #{$str};
232
+ -moz-animation-timing-function: #{$str};
233
+ -ms-animation-timing-function: #{$str};
234
+ -o-animation-timing-function: #{$str};
235
+ animation-timing-function: #{$str};
236
+ }
237
+
238
+ // ==== /CSS3 SASS MIXINS ====
239
+
240
+ @mixin opacity($opacity) {
241
+ opacity: $opacity;
242
+ $opacity-ie: $opacity * 100;
243
+ filter: alpha(opacity=$opacity-ie); //IE8
244
+ }
245
+
246
+ @mixin size($width, $height: $width)
247
+ {
248
+ width: $width;
249
+ height: $height;
250
+ }
251
+
252
+ @mixin clearfix
253
+ {
254
+ &:after {
255
+ content: "";
256
+ display: table;
257
+ clear: both;
258
+ }
259
+ }
260
+
261
+ // Placeholder text
262
+ @mixin placeholder($color: $input-color-placeholder) {
263
+ // Firefox
264
+ &::-moz-placeholder {
265
+ color: $color;
266
+ opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
267
+ }
268
+ &:-ms-input-placeholder { color: $color; } // Internet Explorer 10+
269
+ &::-webkit-input-placeholder { color: $color; } // Safari and Chrome
270
+ }
vendor/freemius/assets/scss/_start.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import "vars";
2
+ @import "colors";
3
+ @import "mixins";
4
+ @import "functions";
vendor/freemius/assets/scss/_vars.scss ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ $is_production: true;
2
+
3
+ $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
+
5
+ $layout_width: 960px;
6
+ $admin_mobile_max_width: 782px;
vendor/freemius/assets/scss/admin/_ajax-loader.scss ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $color: $wp-selected-color;
2
+ $bkg-color: #fff;
3
+ $size: 20;
4
+
5
+ .fs-ajax-loader
6
+ {
7
+ position: relative;
8
+ width: #{8*$size + 10}px;
9
+ height: #{$size}px;
10
+ margin: auto;
11
+
12
+ .fs-ajax-loader-bar
13
+ {
14
+ position: absolute;
15
+ top: 0;
16
+ background-color: $color;
17
+ width: #{$size}px;
18
+ height: #{$size}px;
19
+ @include animation-name(bounce_ajaxLoader);
20
+ @include animation-duration(1.5s);
21
+ @include animation-iteration-count(infinite);
22
+ @include animation-direction(normal);
23
+ @include transform(.3);
24
+ }
25
+
26
+ @for $i from 0 through 7
27
+ {
28
+ .fs-ajax-loader-bar-#{$i + 1}
29
+ {
30
+ left: #{$i*($size - 1)}px;
31
+ @include animation-delay(#{0.6 + $i*0.15}s);
32
+ }
33
+ }
34
+ }
35
+
36
+ @include keyframes(bounce_ajaxLoader)
37
+ {
38
+ 0%
39
+ {
40
+ @include transform(scale(1));
41
+ background-color: $color;
42
+ }
43
+
44
+ 100%
45
+ {
46
+ @include transform(scale(.3));
47
+ background-color: $bkg-color;
48
+ }
49
+ }
vendor/freemius/assets/scss/admin/_auto-install.scss ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal-auto-install
2
+ {
3
+ $max-width: 300px;
4
+
5
+ #request-filesystem-credentials-form
6
+ {
7
+ h2,
8
+ .request-filesystem-credentials-action-buttons
9
+ {
10
+ display: none;
11
+ }
12
+
13
+ input[type=password],
14
+ input[type=email],
15
+ input[type=text]
16
+ {
17
+ -webkit-appearance: none;
18
+ padding: 10px 10px 5px 10px;
19
+ width: $max-width;
20
+ max-width: 100%;
21
+ }
22
+
23
+ > div,
24
+ label,
25
+ fieldset
26
+ {
27
+ width: $max-width;
28
+ max-width: 100%;
29
+ margin: 0 auto;
30
+ display: block;
31
+ }
32
+ }
33
+ }
vendor/freemius/assets/scss/admin/_deactivation-feedback.scss ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+
3
+ .fs-modal.fs-modal-deactivation-feedback {
4
+ .reason-input, .internal-message {
5
+ margin: 3px 0 3px 22px;
6
+
7
+ input, textarea {
8
+ width: 100%;
9
+ }
10
+ }
11
+
12
+ li.reason {
13
+ &.has-internal-message .internal-message {
14
+ border: 1px solid lighten($darkest-color, 80%);
15
+ padding: 7px;
16
+ display: none;
17
+ }
18
+
19
+ @media (max-width: 650px) {
20
+ li.reason {
21
+ margin-bottom: 10px;
22
+
23
+ .reason-input, .internal-message {
24
+ margin-left: 29px;
25
+ }
26
+
27
+ label {
28
+ display: table;
29
+
30
+ > span {
31
+ display: table-cell;
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ .anonymous-feedback-label {
40
+ float: left;
41
+ }
42
+
43
+ .fs-modal-panel {
44
+ margin-top: 0 !important;
45
+
46
+ h3 {
47
+ margin-top: 0;
48
+ line-height: 1.5em;
49
+ }
50
+ }
51
+ }
52
+
53
+ #the-list .deactivate > .fs-slug {
54
+ display: none;
55
+ }
vendor/freemius/assets/scss/admin/_gdpr-consent.scss ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #fs_marketing_optin
2
+ {
3
+ display: none;
4
+ margin-top: 10px;
5
+ border: 1px solid #ccc;
6
+ padding: 10px;
7
+ line-height: 1.5em;
8
+
9
+ .fs-message
10
+ {
11
+ display: block;
12
+ margin-bottom: 5px;
13
+ font-size: 1.05em;
14
+ font-weight: 600;
15
+ }
16
+
17
+ &.error
18
+ {
19
+ border: 1px solid $fs-logo-magenta-color;
20
+ background: #fee;
21
+
22
+ .fs-message
23
+ {
24
+ color: $fs-logo-magenta-color;
25
+ }
26
+ }
27
+
28
+ .fs-input-container
29
+ {
30
+ margin-top: 5px;
31
+
32
+ label
33
+ {
34
+ margin-top: 5px;
35
+ display: block;
36
+
37
+ input
38
+ {
39
+ float: left;
40
+ margin: 1px 0 0 0;
41
+ }
42
+
43
+ &:first-child
44
+ {
45
+ display: block;
46
+ margin-bottom: 2px;
47
+ }
48
+ }
49
+ }
50
+
51
+ .fs-input-label
52
+ {
53
+ display: block;
54
+ margin-left: 20px;
55
+
56
+ .underlined
57
+ {
58
+ text-decoration: underline;
59
+ }
60
+ }
61
+ }
62
+
63
+ .rtl
64
+ {
65
+ #fs_marketing_optin
66
+ {
67
+ .fs-input-container
68
+ {
69
+ label input
70
+ {
71
+ float: right;
72
+ }
73
+ }
74
+
75
+ .fs-input-label
76
+ {
77
+ margin-left: 0;
78
+ margin-right: 20px;
79
+ }
80
+ }
81
+ }
vendor/freemius/assets/scss/admin/_license-activation.scss ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-activation {
2
+ .fs-modal-body {
3
+ input.license_key {
4
+ width: 100%;
5
+ }
6
+ }
7
+ }
8
+
9
+ #license_options_container {
10
+ table {
11
+ &, select, #available_license_key {
12
+ width: 100%;
13
+ }
14
+
15
+ td:first-child {
16
+ width: 1%;
17
+ }
18
+
19
+ #other_license_key_container {
20
+ label {
21
+ position: relative;
22
+ top: 6px;
23
+ float: left;
24
+ margin-right: 5px;
25
+ }
26
+
27
+ div {
28
+ overflow: hidden;
29
+ width: auto;
30
+ height: 30px;
31
+ display: block;
32
+ top: 2px;
33
+ position: relative;
34
+
35
+ input {
36
+ margin: 0;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ #sites_list_container {
44
+ td {
45
+ cursor: pointer;
46
+ }
47
+ }
vendor/freemius/assets/scss/admin/_license-key-resend.scss ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-key-resend
2
+ {
3
+ .email-address-container
4
+ {
5
+ overflow: hidden;
6
+ padding-right: 2px;
7
+ }
8
+
9
+ &.fs-freemium
10
+ {
11
+ input.email-address
12
+ {
13
+ width: 300px;
14
+ }
15
+
16
+ label
17
+ {
18
+ display: block;
19
+ margin-bottom: 10px;
20
+ }
21
+ }
22
+
23
+ &.fs-premium
24
+ {
25
+ input.email-address
26
+ {
27
+ width: 100%;
28
+ }
29
+
30
+ .button-container
31
+ {
32
+ float: right;
33
+ margin-left: 7px;
34
+
35
+ @media (max-width: 650px) {
36
+ margin-top: 2px;
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ .rtl
43
+ {
44
+ .fs-modal.fs-modal-license-key-resend
45
+ {
46
+ .fs-modal-body
47
+ {
48
+ .input-container > .email-address-container
49
+ {
50
+ padding-left: 2px;
51
+ padding-right: 0;
52
+ }
53
+
54
+ .button-container
55
+ {
56
+ float: left;
57
+ margin-right: 7px;
58
+ margin-left: 0;
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ a.show-license-resend-modal
65
+ {
66
+ margin-top: 4px;
67
+ display: inline-block;
68
+ }
vendor/freemius/assets/scss/admin/_modal-common.scss ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+ @import "../mixins";
3
+
4
+ .fs-modal {
5
+ position: fixed;
6
+ overflow: auto;
7
+ height: 100%;
8
+ width: 100%;
9
+ top: 0;
10
+ z-index: 100000;
11
+ display: none;
12
+ background: rgba(0, 0, 0, 0.6);
13
+
14
+ .fs-modal-dialog {
15
+ background: transparent;
16
+ position: absolute;
17
+ left: 50%;
18
+ margin-left: -298px;
19
+ padding-bottom: 30px;
20
+ top: -100%;
21
+ z-index: 100001;
22
+ width: 596px;
23
+
24
+ @media (max-width: 650px) {
25
+ margin-left: -50%;
26
+ box-sizing: border-box;
27
+ padding-left: 10px;
28
+ padding-right: 10px;
29
+ width: 100%;
30
+
31
+ .fs-modal-panel > h3 > strong {
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+
37
+ &.active {
38
+ display: block;
39
+
40
+ &:before {
41
+ display: block;
42
+ }
43
+
44
+ .fs-modal-dialog {
45
+ top: 10%;
46
+ }
47
+ }
48
+
49
+ &.fs-success {
50
+ .fs-modal-header {
51
+ border-bottom-color: $wp-notice-success-dark-color;
52
+ }
53
+
54
+ .fs-modal-body {
55
+ background-color: $wp-notice-success-color;
56
+ }
57
+ }
58
+
59
+ &.fs-warn {
60
+ .fs-modal-header {
61
+ border-bottom-color: $wp-notice-warn-dark-color;
62
+ }
63
+
64
+ .fs-modal-body {
65
+ background-color: $wp-notice-warn-color;
66
+ }
67
+ }
68
+
69
+ &.fs-error {
70
+ .fs-modal-header {
71
+ border-bottom-color: $wp-notice-error-dark-color;
72
+ }
73
+
74
+ .fs-modal-body {
75
+ background-color: $wp-notice-error-color;
76
+ }
77
+ }
78
+
79
+
80
+ .fs-modal-body,
81
+ .fs-modal-footer {
82
+ border: 0;
83
+ background: #fefefe;
84
+ padding: 20px;
85
+ }
86
+
87
+ .fs-modal-header {
88
+ border-bottom: #eeeeee solid 1px;
89
+ background: #fbfbfb;
90
+ padding: 15px 20px;
91
+ position: relative;
92
+ margin-bottom: -10px;
93
+ // z-index: 2;
94
+
95
+ h4 {
96
+ margin: 0;
97
+ padding: 0;
98
+ text-transform: uppercase;
99
+ font-size: 1.2em;
100
+ font-weight: bold;
101
+ color: #cacaca;
102
+ text-shadow: 1px 1px 1px #fff;
103
+ letter-spacing: 0.6px;
104
+ -webkit-font-smoothing: antialiased;
105
+ }
106
+
107
+ .fs-close {
108
+ position: absolute;
109
+ right: 10px;
110
+ top: 12px;
111
+ cursor: pointer;
112
+ color: #bbb;
113
+ @include border-radius(20px);
114
+ padding: 3px;
115
+ @include transition(all 0.2s ease-in-out);
116
+
117
+ &:hover {
118
+ color: #fff;
119
+ background: #aaa;
120
+ }
121
+
122
+ &, &:hover
123
+ {
124
+ .dashicons
125
+ {
126
+ text-decoration: none;
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ .fs-modal-body {
133
+ border-bottom: 0;
134
+
135
+ p {
136
+ font-size: 14px;
137
+ }
138
+
139
+ h2 {
140
+ font-size: 20px;
141
+ line-height: 1.5em;
142
+ }
143
+
144
+ > div {
145
+ margin-top: 10px;
146
+
147
+ h2 {
148
+ font-weight: bold;
149
+ font-size: 20px;
150
+ margin-top: 0;
151
+ }
152
+ }
153
+ }
154
+
155
+ .fs-modal-footer {
156
+ border-top: #eeeeee solid 1px;
157
+ text-align: right;
158
+
159
+ > .button {
160
+ margin: 0 7px;
161
+
162
+ &:first-child {
163
+ margin: 0;
164
+ }
165
+ }
166
+ }
167
+
168
+ .fs-modal-panel {
169
+ > .notice.inline {
170
+ margin: 0;
171
+ display: none;
172
+ }
173
+
174
+ &:not(.active) {
175
+ display: none;
176
+ }
177
+ }
178
+ }
179
+
180
+ .rtl
181
+ {
182
+ .fs-modal {
183
+ .fs-modal-header {
184
+ .fs-close {
185
+ right: auto;
186
+ left: 20px;
187
+ }
188
+ }
189
+ }
190
+ }
191
+
192
+ body.has-fs-modal {
193
+ overflow: hidden;
194
+ }
vendor/freemius/assets/scss/admin/_multisite-options.scss ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #multisite_options_container {
2
+ margin-top: 10px;
3
+ border: 1px solid #ccc;
4
+ padding: 5px;
5
+
6
+ a {
7
+ text-decoration: none;
8
+
9
+ &:focus {
10
+ box-shadow: none;
11
+ }
12
+
13
+ &.selected {
14
+ font-weight: bold;
15
+ }
16
+ }
17
+
18
+ &.apply-on-all-sites {
19
+ border: 0 none;
20
+ padding: 0;
21
+
22
+ #all_sites_options {
23
+ border-spacing: 0;
24
+
25
+ td:not(:first-child) {
26
+ display: none;
27
+ }
28
+ }
29
+ }
30
+
31
+ #sites_list_container {
32
+ display: none;
33
+ overflow: auto;
34
+
35
+ table td {
36
+ border-top: 1px solid #ccc;
37
+ padding: 4px 2px;
38
+ }
39
+ }
40
+ }
vendor/freemius/assets/scss/admin/_themes.scss ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .theme-browser
2
+ {
3
+ .theme
4
+ {
5
+ .fs-premium-theme-badge
6
+ {
7
+ position: absolute;
8
+ top: 10px;
9
+ right: 0;
10
+ background: $fs-logo-green-color;
11
+ color: #fff;
12
+ text-transform: uppercase;
13
+ padding: 5px 10px;
14
+ @include border-radius(3px 0 0 3px);
15
+ font-weight: bold;
16
+ border-right: 0;
17
+ @include box-shadow(0 2px 1px -1px rgba(0, 0, 0, .3));
18
+ font-size: 1.1em;
19
+ }
20
+ }
21
+ }
vendor/freemius/assets/scss/admin/_tooltip.scss ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-tooltip-trigger
2
+ {
3
+ &:not(a)
4
+ {
5
+ cursor: help;
6
+ }
7
+
8
+ position: relative;
9
+
10
+ .fs-tooltip
11
+ {
12
+ opacity: 0;
13
+ visibility: hidden;
14
+ @include transition(opacity 0.3s ease-in-out);
15
+ position: absolute;
16
+ background: $tooltip-bkg-color;
17
+ color: $tooltip-color;
18
+ font-family: 'arial', serif;
19
+ font-size: 12px;
20
+ padding: 10px;
21
+ z-index: 999999;
22
+ bottom: 100%;
23
+ margin-bottom: 5px;
24
+ left: 0;
25
+ right: 0;
26
+ @include border-radius(5px);
27
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
28
+ line-height: 1.3em;
29
+ font-weight: bold;
30
+ text-align: left;
31
+
32
+ .rtl &
33
+ {
34
+ text-align: right;
35
+ }
36
+
37
+ &::after
38
+ {
39
+ content: ' ';
40
+ display: block;
41
+ width: 0;
42
+ height: 0;
43
+ border-style: solid;
44
+ border-width: 5px 5px 0 5px;
45
+ border-color: $tooltip-bkg-color transparent transparent transparent;
46
+ position: absolute;
47
+ top: 100%;
48
+ left: 21px;
49
+
50
+ .rtl &
51
+ {
52
+ right: 21px;
53
+ left: auto;
54
+ }
55
+ }
56
+ }
57
+
58
+ &:hover
59
+ {
60
+ .fs-tooltip
61
+ {
62
+ visibility: visible;
63
+ opacity: 1;
64
+ }
65
+ }
66
+ }
vendor/freemius/assets/scss/admin/account.scss ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_account
4
+ {
5
+ .postbox,
6
+ .widefat
7
+ {
8
+ max-width: 700px;
9
+ }
10
+
11
+ h3
12
+ {
13
+ font-size: 1.3em;
14
+ padding: 12px 15px;
15
+ margin: 0 0 12px 0;
16
+ line-height: 1.4;
17
+ border-bottom: 1px solid #F1F1F1;
18
+
19
+ .dashicons {
20
+ width: 26px;
21
+ height: 26px;
22
+ font-size: 1.3em;
23
+ }
24
+ }
25
+
26
+ i.dashicons
27
+ {
28
+ font-size: 1.2em;
29
+ height: 1.2em;
30
+ width: 1.2em;
31
+ }
32
+
33
+ .dashicons
34
+ {
35
+ vertical-align: middle;
36
+ }
37
+
38
+ .fs-header-actions
39
+ {
40
+ position: absolute;
41
+ top: 17px;
42
+ right: 15px;
43
+ font-size: 0.9em;
44
+
45
+ ul
46
+ {
47
+ margin: 0;
48
+ }
49
+
50
+ li
51
+ {
52
+ form
53
+ {
54
+ display: inline-block;
55
+ }
56
+
57
+ float: left;
58
+ a
59
+ {
60
+ text-decoration: none;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ #fs_account_details .button-group {
67
+ float: right;
68
+ }
69
+
70
+ .rtl #fs_account .fs-header-actions
71
+ {
72
+ left: 15px;
73
+ right: auto;
74
+ }
75
+
76
+ .fs-key-value-table
77
+ {
78
+ width: 100%;
79
+
80
+ form
81
+ {
82
+ display: inline-block;
83
+ }
84
+
85
+ tr
86
+ {
87
+ td:first-child
88
+ {
89
+ nobr
90
+ {
91
+ font-weight: bold;
92
+ }
93
+
94
+ text-align: right;
95
+
96
+ form
97
+ {
98
+ display: block;
99
+ }
100
+ }
101
+
102
+ td.fs-right
103
+ {
104
+ text-align: right;
105
+ }
106
+
107
+ &.fs-odd
108
+ {
109
+ background: #ebebeb;
110
+ }
111
+ }
112
+
113
+ td, th
114
+ {
115
+ padding: 10px;
116
+ }
117
+
118
+ code {
119
+ line-height: 28px;
120
+ }
121
+
122
+ var, code, input[type="text"]
123
+ {
124
+ color: #0073AA;
125
+ font-size: 16px;
126
+ background: none;
127
+ }
128
+
129
+ input[type="text"] {
130
+ width: 100%;
131
+ font-weight: bold;
132
+ }
133
+ }
134
+
135
+ label.fs-tag
136
+ {
137
+ background: #ffba00;
138
+ color: #fff;
139
+ display: inline-block;
140
+ border-radius: 3px;
141
+ padding: 5px;
142
+ font-size: 11px;
143
+ line-height: 11px;
144
+ vertical-align: baseline;
145
+
146
+ &.fs-warn
147
+ {
148
+ background: #ffba00;
149
+ }
150
+ &.fs-success
151
+ {
152
+ background: #46b450;
153
+ }
154
+ &.fs-error
155
+ {
156
+ background: #dc3232;
157
+ }
158
+ }
159
+
160
+ #fs_sites
161
+ {
162
+ .fs-scrollable-table
163
+ {
164
+ .fs-table-body {
165
+ max-height: 200px;
166
+ overflow: auto;
167
+ border: 1px solid #e5e5e5;
168
+
169
+ & > table.widefat {
170
+ border: none !important;
171
+ }
172
+ }
173
+
174
+ .fs-main-column {
175
+ width: 100%;
176
+ }
177
+
178
+ .fs-site-details
179
+ {
180
+ td:first-of-type
181
+ {
182
+ text-align: right;
183
+ color: grey;
184
+ width: 1px;
185
+ }
186
+
187
+ td:last-of-type
188
+ {
189
+ text-align: right;
190
+ }
191
+ }
192
+
193
+ .fs-install-details table
194
+ {
195
+ tr td
196
+ {
197
+ width: 1px;
198
+ white-space: nowrap;
199
+
200
+ &:last-of-type
201
+ {
202
+ width: auto;
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+
209
+ #fs_addons
210
+ {
211
+ h3
212
+ {
213
+ border: none;
214
+ margin-bottom: 0;
215
+ padding: 4px 5px;
216
+ }
217
+
218
+ td
219
+ {
220
+ vertical-align: middle;
221
+ }
222
+
223
+ thead {
224
+ white-space: nowrap;
225
+ }
226
+
227
+ td:first-child,
228
+ th:first-child
229
+ {
230
+ text-align: left;
231
+ font-weight: bold;
232
+ }
233
+ td:last-child,
234
+ th:last-child
235
+ {
236
+ text-align: right;
237
+ }
238
+ th
239
+ {
240
+ font-weight: bold;
241
+ }
242
+ }
243
+
244
+ #fs_billing_address {
245
+ width: 100%;
246
+
247
+ tr {
248
+ td {
249
+ width: 50%;
250
+ padding: 5px;
251
+ }
252
+
253
+ &:first-of-type {
254
+ td {
255
+ padding-top: 0;
256
+ }
257
+ }
258
+ }
259
+
260
+ @mixin read-mode {
261
+ border-color: transparent;
262
+ color: #777;
263
+ border-bottom: 1px dashed #ccc;
264
+ padding-left: 0;
265
+ background: none;
266
+ }
267
+
268
+ span {
269
+ font-weight: bold;
270
+ }
271
+
272
+ input, select {
273
+ @include placeholder(transparent);
274
+
275
+ display: block;
276
+ width: 100%;
277
+ margin-top: 5px;
278
+
279
+ &.fs-read-mode {
280
+ @include read-mode();
281
+ }
282
+ }
283
+
284
+
285
+ &.fs-read-mode {
286
+ td span {
287
+ display: none;
288
+ }
289
+
290
+ input, select
291
+ {
292
+ @include read-mode();
293
+ @include placeholder(#ccc);
294
+ }
295
+ }
296
+
297
+
298
+ button {
299
+ display: block;
300
+ width: 100%;
301
+ }
302
+ }
vendor/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
+ }
vendor/freemius/assets/scss/admin/affiliation.scss ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_affiliation_content_wrapper {
4
+ #messages {
5
+ margin-top: 25px;
6
+ }
7
+
8
+ h3 {
9
+ font-size: 24px;
10
+ padding: 0;
11
+ margin-left: 0;
12
+ }
13
+
14
+ ul {
15
+ li {
16
+ @include box-sizing(border-box);
17
+ list-style-type: none;
18
+
19
+ &:before {
20
+ content: '✓';
21
+ margin-right: 10px;
22
+ font-weight: bold;
23
+ }
24
+ }
25
+ }
26
+
27
+ p:not(.description), li, label {
28
+ font-size: 16px !important;
29
+ line-height: 26px !important;
30
+ }
31
+
32
+ .button {
33
+ margin-top: 20px;
34
+ margin-bottom: 7px;
35
+ line-height: 35px;
36
+ height: 40px;
37
+ font-size: 16px;
38
+
39
+ &#cancel_button {
40
+ margin-right: 5px;
41
+ }
42
+ }
43
+
44
+ form {
45
+ .input-container {
46
+ .input-label {
47
+ font-weight: bold;
48
+ display: block;
49
+ width: 100%;
50
+ }
51
+
52
+ &.input-container-text {
53
+ label, input, textarea {
54
+ display: block;
55
+ }
56
+ }
57
+
58
+ margin-bottom: 15px;
59
+
60
+ #add_domain, .remove-domain {
61
+ text-decoration: none;
62
+ display: inline-block;
63
+ margin-top: 3px;
64
+
65
+ &:focus {
66
+ box-shadow: none;
67
+ }
68
+
69
+ &.disabled {
70
+ color: #aaa;
71
+ cursor: default;
72
+ }
73
+ }
74
+ }
75
+
76
+ #extra_domains_container {
77
+ .description {
78
+ margin-top: 0;
79
+ position: relative;
80
+ top: -4px;
81
+ }
82
+
83
+ .extra-domain-input-container {
84
+ margin-bottom: 15px;
85
+
86
+ .domain {
87
+ display: inline-block;
88
+ margin-right: 5px;
89
+
90
+ &:last-of-type {
91
+ margin-bottom: 0;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
vendor/freemius/assets/scss/admin/checkout.scss ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ @media screen and (max-width: 782px) {
2
+ #wpbody-content {
3
+ padding-bottom: 0 !important;
4
+ }
5
+ }
vendor/freemius/assets/scss/admin/common.scss ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "themes";
3
+
4
+ #iframe
5
+ {
6
+ line-height: 0;
7
+ font-size: 0;
8
+ }
9
+
10
+ .fs-full-size-wrapper
11
+ {
12
+ margin: 40px 0 -65px -20px;
13
+
14
+ @media (max-width: 600px) {
15
+ margin: 0 0 -65px -10px;
16
+ }
17
+ }
18
+
19
+ .fs-notice
20
+ {
21
+ position: relative;
22
+
23
+ &.fs-has-title
24
+ {
25
+ margin-bottom: 30px !important;
26
+ }
27
+
28
+ &.success
29
+ {
30
+ color: green;
31
+ // font-weight: normal;
32
+ }
33
+
34
+ &.promotion
35
+ {
36
+ border-color: $fs-notice-promotion-border-color !important;
37
+ background-color: $fs-notice-promotion-bkg !important;
38
+ }
39
+
40
+ .fs-notice-body
41
+ {
42
+ margin: .5em 0;
43
+ padding: 2px;
44
+ }
45
+
46
+ .fs-close
47
+ {
48
+ // position: absolute;
49
+ // top: 2px;
50
+ // bottom: 2px;
51
+ // right: 2px;
52
+ // min-width: 100px;
53
+ // text-align: center;
54
+ // padding-right: 2px;
55
+ cursor: pointer;
56
+ color: #aaa;
57
+ float: right;
58
+
59
+ &:hover
60
+ {
61
+ color: #666;
62
+ // background: #A9A9A9;
63
+ }
64
+
65
+ > *
66
+ {
67
+ margin-top: 7px;
68
+ display: inline-block;
69
+ }
70
+ }
71
+
72
+ label.fs-plugin-title
73
+ {
74
+ background: rgba(0, 0, 0, 0.3);
75
+ color: #fff;
76
+ padding: 2px 10px;
77
+ position: absolute;
78
+ top: 100%;
79
+ bottom: auto;
80
+ right: auto;
81
+ @include border-radius(0 0 3px 3px);
82
+ left: 10px;
83
+ font-size: 12px;
84
+ font-weight: bold;
85
+ cursor: auto;
86
+ }
87
+ }
88
+
89
+ div.fs-notice
90
+ {
91
+ &.updated,
92
+ &.success,
93
+ &.promotion
94
+ {
95
+ display: block !important;
96
+ }
97
+ }
98
+
99
+ .rtl .fs-notice
100
+ {
101
+ .fs-close
102
+ {
103
+ // left: 2px;
104
+ // right: auto;
105
+ // padding-right: 0;
106
+ // padding-left: 2px;
107
+ float: left;
108
+ }
109
+ }
110
+
111
+ .fs-secure-notice
112
+ {
113
+ position: fixed;
114
+ top: 32px;
115
+ left: 160px;
116
+ right: 0;
117
+ background: rgb(235, 253, 235);
118
+ padding: 10px 20px;
119
+ color: green;
120
+ z-index: 9999;
121
+ @include box-shadow(0 2px 2px rgba(6, 113, 6, 0.3));
122
+ @include opacity(0.95);
123
+
124
+ &:hover
125
+ {
126
+ @include opacity(1);
127
+ }
128
+
129
+ a.fs-security-proof
130
+ {
131
+ color: green;
132
+ text-decoration: none;
133
+ }
134
+ }
135
+
136
+ @media screen and (max-width: 960px) {
137
+ .fs-secure-notice
138
+ {
139
+ left: 36px;
140
+ }
141
+ }
142
+
143
+ @media screen and (max-width: 600px) {
144
+ .fs-secure-notice
145
+ {
146
+ display: none;
147
+ }
148
+ }
149
+
150
+ @media screen and (max-width: 500px) {
151
+ #fs_promo_tab
152
+ {
153
+ display: none;
154
+ }
155
+ }
156
+
157
+ @media screen and (max-width: 782px) {
158
+ .fs-secure-notice
159
+ {
160
+ left: 0;
161
+ top: 46px;
162
+ text-align: center;
163
+ }
164
+ }
165
+
166
+ span.fs-submenu-item.fs-sub:before
167
+ {
168
+ // Add small arrow.
169
+ content: '\21B3';
170
+ padding: 0 5px;
171
+ }
172
+
173
+ .rtl
174
+ {
175
+ span.fs-submenu-item.fs-sub:before
176
+ {
177
+ // Add small RTL arrow.
178
+ content: '\21B2';
179
+ }
180
+ }
181
+
182
+ .fs-submenu-item
183
+ {
184
+ &.pricing
185
+ {
186
+ &.upgrade-mode
187
+ {
188
+ color: greenyellow;
189
+ }
190
+
191
+ &.trial-mode
192
+ {
193
+ color: #83e2ff;
194
+ }
195
+ }
196
+ }
197
+
198
+ #adminmenu .update-plugins.fs-trial
199
+ {
200
+ background-color: #00b9eb;
201
+ }
202
+ .fs-ajax-spinner
203
+ {
204
+ border: 0;
205
+ width: 20px;
206
+ height: 20px;
207
+ margin-right: 5px;
208
+ vertical-align: sub;
209
+ display: inline-block;
210
+ background: url('../../../../../../../wp-admin/images/wpspin_light-2x.gif');
211
+ background-size: contain;
212
+ }
213
+
214
+ .wrap.fs-section {
215
+ h2 {
216
+ text-align: left;
217
+ }
218
+ }
vendor/freemius/assets/scss/admin/connect.scss ADDED
@@ -0,0 +1,548 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ $form_width: 480px;
4
+
5
+ #fs_connect
6
+ {
7
+ width: $form_width;
8
+ @include box-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
9
+ margin: 20px 0;
10
+
11
+ @media screen and (max-width: ($form_width - 1)) {
12
+ @include box-shadow(none);
13
+ width: auto;
14
+ margin: 0 0 0 -10px;
15
+ }
16
+
17
+ .fs-content
18
+ {
19
+ background: #fff;
20
+ padding: 15px 20px;
21
+
22
+ .fs-error {
23
+ background: snow;
24
+ color: $fs-logo-magenta-color;
25
+ border: 1px solid $fs-logo-magenta-color;
26
+ @include box-shadow(0 1px 1px 0 rgba(0,0,0,.1));
27
+ text-align: center;
28
+ padding: 5px;
29
+ margin-bottom: 10px;
30
+ }
31
+
32
+ p
33
+ {
34
+ margin: 0;
35
+ padding: 0;
36
+ font-size: 1.2em;
37
+ }
38
+ }
39
+
40
+ .fs-license-key-container {
41
+ position: relative;
42
+ width: 280px;
43
+ margin: 10px auto 0 auto;
44
+
45
+ input {
46
+ width: 100%;
47
+ }
48
+
49
+ .dashicons {
50
+ position: absolute;
51
+ top: 5px;
52
+ right: 5px;
53
+ }
54
+ }
55
+
56
+ &.require-license-key {
57
+ #sites_list_container {
58
+ td {
59
+ cursor: pointer;
60
+ }
61
+ }
62
+ }
63
+
64
+ #delegate_to_site_admins {
65
+ margin-right: 15px;
66
+ float: right;
67
+ height: 26px;
68
+ vertical-align: middle;
69
+ line-height: 37px;
70
+ font-weight: bold;
71
+ border-bottom: 1px dashed;
72
+ text-decoration: none;
73
+
74
+ &.rtl {
75
+ margin-left: 15px;
76
+ margin-right: 0;
77
+ }
78
+ }
79
+
80
+ .fs-actions
81
+ {
82
+ padding: 10px 20px;
83
+ background: #C0C7CA;
84
+
85
+ .button
86
+ {
87
+ padding: 0 10px 1px;
88
+ line-height: 35px;
89
+ height: 37px;
90
+ font-size: 16px;
91
+ margin-bottom: 0;
92
+
93
+ .dashicons
94
+ {
95
+ font-size: 37px;
96
+ margin-left: -8px;
97
+ margin-right: 12px;
98
+ }
99
+
100
+ &.button-primary
101
+ {
102
+ padding-right: 15px;
103
+ padding-left: 15px;
104
+
105
+ &:after
106
+ {
107
+ content: ' \279C';
108
+ }
109
+
110
+ &.fs-loading
111
+ {
112
+ &:after
113
+ {
114
+ content: '';
115
+ }
116
+ }
117
+ }
118
+
119
+ &.button-secondary
120
+ {
121
+ float: right;
122
+ }
123
+ }
124
+
125
+ // .fs-skip
126
+ // {
127
+ // line-height: 38px;
128
+ // vertical-align: middle;
129
+ // text-decoration: none;
130
+ // margin-left: 10px;
131
+ // }
132
+ }
133
+
134
+ &.fs-anonymous-disabled
135
+ {
136
+ .fs-actions
137
+ {
138
+ .button.button-primary
139
+ {
140
+ width: 100%;
141
+ }
142
+ }
143
+ }
144
+
145
+ .fs-permissions
146
+ {
147
+ padding: 10px 20px;
148
+ background: #FEFEFE;
149
+ // background: #F1F1F1;
150
+ @include transition(background 0.5s ease);
151
+
152
+ .fs-license-sync-disclaimer {
153
+ text-align: center;
154
+ margin-top: 0;
155
+ }
156
+
157
+ .fs-trigger
158
+ {
159
+ font-size: 0.9em;
160
+ text-decoration: none;
161
+ text-align: center;
162
+ display: block;
163
+ }
164
+
165
+ ul
166
+ {
167
+ height: 0;
168
+ overflow: hidden;
169
+ margin: 0;
170
+
171
+ li
172
+ {
173
+ margin-bottom: 12px;
174
+
175
+ &:last-child
176
+ {
177
+ margin-bottom: 0;
178
+ }
179
+
180
+ i.dashicons
181
+ {
182
+ float: left;
183
+ font-size: 40px;
184
+ width: 40px;
185
+ height: 40px;
186
+ }
187
+
188
+ div
189
+ {
190
+ margin-left: 55px;
191
+
192
+ span
193
+ {
194
+ font-weight: bold;
195
+ text-transform: uppercase;
196
+ color: #23282d;
197
+ }
198
+
199
+ p
200
+ {
201
+ margin: 2px 0 0 0;
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ &.fs-open
208
+ {
209
+ background: #fff;
210
+
211
+ ul
212
+ {
213
+ height: auto;
214
+ margin: 20px 20px 10px 20px;
215
+ }
216
+ }
217
+
218
+ @media screen and (max-width: ($form_width - 1)) {
219
+ background: #fff;
220
+
221
+ .fs-trigger
222
+ {
223
+ display: none;
224
+ }
225
+
226
+ ul
227
+ {
228
+ height: auto;
229
+ margin: 20px;
230
+ }
231
+ }
232
+ }
233
+
234
+ .fs-freemium-licensing {
235
+ padding: 8px;
236
+ // background: #0085BA;
237
+ background: #777;
238
+ color: #fff;
239
+
240
+ p {
241
+ text-align: center;
242
+ display: block;
243
+ margin: 0;
244
+ padding: 0;
245
+ }
246
+
247
+ a {
248
+ color: #C2EEFF;
249
+ text-decoration: underline;
250
+ }
251
+ }
252
+
253
+ $icon_size: 80px;
254
+ $wp_logo_padding: $icon_size / 10;
255
+ $icons_top: 10px;
256
+
257
+ .fs-visual
258
+ {
259
+ padding: 12px;
260
+ line-height: 0;
261
+ background: #fafafa;
262
+ height: $icon_size;
263
+ position: relative;
264
+
265
+ .fs-site-icon
266
+ {
267
+ position: absolute;
268
+ left: 20px;
269
+ top: $icons_top;
270
+ }
271
+
272
+ .fs-connect-logo
273
+ {
274
+ position: absolute;
275
+ right: 20px;
276
+ top: $icons_top;
277
+ }
278
+
279
+ .fs-plugin-icon
280
+ {
281
+ position: absolute;
282
+ top: $icons_top;
283
+ left: 50%;
284
+ margin-left: - ($icon_size / 2);
285
+ }
286
+
287
+ .fs-plugin-icon,
288
+ .fs-site-icon,
289
+ img,
290
+ object
291
+ {
292
+ width: $icon_size;
293
+ height: $icon_size;
294
+ }
295
+
296
+ .dashicons-wordpress
297
+ {
298
+ font-size: $icon_size - ($wp_logo_padding * 2);
299
+ background: $wordpress_color;
300
+ color: #fff;
301
+ width: $icon_size - ($wp_logo_padding * 2);
302
+ height: $icon_size - ($wp_logo_padding * 2);
303
+ padding: $wp_logo_padding;
304
+ }
305
+
306
+ .dashicons-plus
307
+ {
308
+ position: absolute;
309
+ top: 50%;
310
+ font-size: 30px;
311
+ margin-top: -10px;
312
+ color: #bbb;
313
+
314
+ &.fs-first
315
+ {
316
+ left: 28%;
317
+ }
318
+ &.fs-second
319
+ {
320
+ left: 65%;
321
+ }
322
+ }
323
+
324
+ .fs-plugin-icon,
325
+ .fs-connect-logo,
326
+ .fs-site-icon
327
+ {
328
+ border: 1px solid #ccc;
329
+ padding: 1px;
330
+ background: #fff;
331
+ }
332
+ }
333
+
334
+ .fs-terms
335
+ {
336
+ text-align: center;
337
+ font-size: 0.85em;
338
+ padding: 5px;
339
+ background: rgba(0, 0, 0, 0.05);
340
+
341
+ &, a
342
+ {
343
+ color: #999;
344
+ }
345
+
346
+ a
347
+ {
348
+ text-decoration: none;
349
+ }
350
+ }
351
+ }
352
+
353
+ @import "multisite-options";
354
+ @import "tooltip";
355
+ @import "gdpr-consent";
356
+
357
+ .rtl
358
+ {
359
+ #fs_connect
360
+ {
361
+ .fs-actions
362
+ {
363
+ padding: 10px 20px;
364
+ background: #C0C7CA;
365
+
366
+ .button
367
+ {
368
+ .dashicons
369
+ {
370
+ font-size: 37px;
371
+ margin-left: -8px;
372
+ margin-right: 12px;
373
+ }
374
+
375
+ &.button-primary
376
+ {
377
+ &:after
378
+ {
379
+ content: ' \000bb';
380
+ }
381
+
382
+ &.fs-loading
383
+ {
384
+ &:after
385
+ {
386
+ content: '';
387
+ }
388
+ }
389
+ }
390
+
391
+ &.button-secondary
392
+ {
393
+ float: left;
394
+ }
395
+ }
396
+ }
397
+
398
+ .fs-permissions
399
+ {
400
+ ul
401
+ {
402
+ li
403
+ {
404
+ div
405
+ {
406
+ margin-right: 55px;
407
+ margin-left: 0;
408
+ }
409
+
410
+ i.dashicons
411
+ {
412
+ float: right;
413
+ }
414
+
415
+ }
416
+ }
417
+ }
418
+
419
+ .fs-visual
420
+ {
421
+ .fs-site-icon
422
+ {
423
+ right: 20px;
424
+ left: auto;
425
+ }
426
+
427
+ .fs-connect-logo
428
+ {
429
+ right: auto;
430
+ left: 20px;
431
+ }
432
+ }
433
+ }
434
+ }
435
+
436
+ #fs_theme_connect_wrapper {
437
+ position: fixed;
438
+ top: 0;
439
+ height: 100%;
440
+ width: 100%;
441
+ z-index: 99990;
442
+ background: rgba(0, 0, 0, 0.75);
443
+ text-align: center;
444
+ overflow-y: auto;
445
+
446
+ &:before {
447
+ content: "";
448
+ display: inline-block;
449
+ vertical-align: middle;
450
+ height: 100%;
451
+ }
452
+
453
+ > button.close {
454
+ color: white;
455
+ cursor: pointer;
456
+ height: 40px;
457
+ width: 40px;
458
+ position: absolute;
459
+ right: 0;
460
+ border: 0;
461
+ background-color: transparent;
462
+ top: 32px;
463
+ }
464
+
465
+ #fs_connect {
466
+ top: 0;
467
+ text-align: left;
468
+ display: inline-block;
469
+ vertical-align: middle;
470
+ margin-top: 52px;
471
+ margin-bottom: 20px;
472
+
473
+ .fs-terms
474
+ {
475
+ background: rgba(140, 140, 140, 0.64);
476
+
477
+ &, a
478
+ {
479
+ color: #c5c5c5;
480
+ }
481
+ }
482
+ }
483
+ }
484
+
485
+ .wp-pointer-content
486
+ {
487
+ #fs_connect
488
+ {
489
+ margin: 0;
490
+ @include box-shadow(none);
491
+ }
492
+ }
493
+
494
+ .fs-opt-in-pointer
495
+ {
496
+ .wp-pointer-content
497
+ {
498
+ padding: 0;
499
+ }
500
+
501
+ &.wp-pointer-top
502
+ {
503
+ .wp-pointer-arrow
504
+ {
505
+ border-bottom-color: #dfdfdf;
506
+ }
507
+ .wp-pointer-arrow-inner
508
+ {
509
+ border-bottom-color: #fafafa;
510
+ }
511
+ }
512
+
513
+ &.wp-pointer-bottom
514
+ {
515
+ .wp-pointer-arrow
516
+ {
517
+ border-top-color: #dfdfdf;
518
+ }
519
+ .wp-pointer-arrow-inner
520
+ {
521
+ border-top-color: #fafafa;
522
+ }
523
+ }
524
+
525
+ &.wp-pointer-left
526
+ {
527
+ .wp-pointer-arrow
528
+ {
529
+ border-right-color: #dfdfdf;
530
+ }
531
+ .wp-pointer-arrow-inner
532
+ {
533
+ border-right-color: #fafafa;
534
+ }
535
+ }
536
+
537
+ &.wp-pointer-right
538
+ {
539
+ .wp-pointer-arrow
540
+ {
541
+ border-left-color: #dfdfdf;
542
+ }
543
+ .wp-pointer-arrow-inner
544
+ {
545
+ border-left-color: #fafafa;
546
+ }
547
+ }
548
+ }
vendor/freemius/assets/scss/admin/debug.scss ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .switch
4
+ {
5
+ position: relative;
6
+ display: inline-block;
7
+ font-size: 1.6em;
8
+ font-weight: bold;
9
+ color: #ccc;
10
+ text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.8);
11
+ height: 18px;
12
+ padding: 6px 6px 5px 6px;
13
+ border: 1px solid #ccc;
14
+ border: 1px solid rgba(0, 0, 0, 0.2);
15
+ border-radius: 4px;
16
+ background: #ececec;
17
+ box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), inset 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
18
+ cursor: pointer;
19
+
20
+ span
21
+ {
22
+ display: inline-block; width: 35px;
23
+ text-transform: uppercase;
24
+
25
+ &.on
26
+ {
27
+ color: $button-primary-bkg;
28
+ }
29
+ }
30
+
31
+ .toggle
32
+ {
33
+ position: absolute;
34
+ top: 1px;
35
+ width: 37px;
36
+ height: 25px;
37
+ border: 1px solid #ccc;
38
+ border: 1px solid rgba(0, 0, 0, 0.3);
39
+ border-radius: 4px;
40
+ background: #fff;
41
+ background: -moz-linear-gradient(top, #ececec 0%, #fff 100%);
42
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));
43
+ background: -webkit-linear-gradient(top, #ececec 0%, #fff 100%);
44
+ background: -o-linear-gradient(top, #ececec 0%, #fff 100%);
45
+ background: -ms-linear-gradient(top, #ececec 0%, #fff 100%);
46
+ background: linear-gradient(top, #ececec 0%, #fff 100%);
47
+ box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, 0.5);
48
+ z-index: 999;
49
+ @include transition(all 0.15s ease-in-out);
50
+ }
51
+
52
+ &.on .toggle
53
+ {
54
+ left: 2%;
55
+ }
56
+ &.off .toggle
57
+ {
58
+ left: 54%;
59
+ }
60
+
61
+ /* Round switch */
62
+ &.round
63
+ {
64
+ padding: 0px 20px;
65
+ border-radius: 40px;
66
+
67
+ .toggle
68
+ {
69
+ border-radius: 40px;
70
+ width: 14px;
71
+ height: 14px;
72
+ }
73
+
74
+ &.on .toggle
75
+ {
76
+ left: 3%;
77
+ background: $button-primary-bkg;
78
+ }
79
+ &.off .toggle
80
+ {
81
+ left: 58%;
82
+ }
83
+ }
84
+ }
85
+
86
+ .switch-label
87
+ {
88
+ font-size: 20px;
89
+ line-height: 31px;
90
+ margin: 0 5px;
91
+ }
92
+
93
+ #fs_log_book {
94
+ table {
95
+ font-family: Consolas,Monaco,monospace;
96
+ font-size: 12px;
97
+
98
+ th {
99
+ color: #ccc;
100
+ }
101
+
102
+ tr {
103
+ background: #232525;
104
+
105
+ &.alternate {
106
+ background: #2b2b2b;
107
+ }
108
+
109
+ td {
110
+ &.fs-col--logger {
111
+ color: #5a7435;
112
+ }
113
+ &.fs-col--type {
114
+ color: #ffc861;
115
+ }
116
+ &.fs-col--function {
117
+ color: #a7b7b1;
118
+ font-weight: bold;
119
+ }
120
+ &.fs-col--message {
121
+ &, a
122
+ {
123
+ color: #9a73ac !important;
124
+ }
125
+ }
126
+ &.fs-col--file {
127
+ color: #d07922;
128
+ }
129
+ &.fs-col--timestamp {
130
+ color: #6596be;
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
vendor/freemius/assets/scss/admin/dialog-boxes.scss ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "modal-common";
3
+ @import "deactivation-feedback";
4
+ @import "license-activation";
5
+ @import "multisite-options";
6
+ @import "license-key-resend";
7
+ @import "ajax-loader";
8
+ @import "auto-install";
vendor/freemius/assets/scss/admin/gdpr-optin-notice.scss ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-notice[data-id^="gdpr_optin_actions"]
2
+ {
3
+ .underlined {
4
+ text-decoration: underline;
5
+ }
6
+
7
+ ul {
8
+ .button, .action-description {
9
+ vertical-align: middle;
10
+ }
11
+
12
+ .action-description {
13
+ display: inline-block;
14
+ margin-left: 3px;
15
+ }
16
+ }
17
+ }
vendor/freemius/assets/scss/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/assets/scss/customizer.scss ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "start";
2
+
3
+ #fs_customizer_upsell {
4
+ .fs-customizer-plan {
5
+ padding: 10px 20px 20px 20px;
6
+ border-radius: 3px;
7
+ background: #fff;
8
+
9
+ h2 {
10
+ position: relative;
11
+ margin: 0;
12
+ line-height: 2em;
13
+ text-transform: uppercase;
14
+
15
+ .button-link {
16
+ top: -2px;
17
+ }
18
+ }
19
+ }
20
+
21
+ .fs-feature {
22
+ position: relative;
23
+ }
24
+
25
+ .dashicons-yes {
26
+ color: #0085ba;
27
+ font-size: 2em;
28
+ vertical-align: bottom;
29
+ margin-left: -7px;
30
+ margin-right: 10px;
31
+
32
+ .rtl & {
33
+ margin-left: 10px;
34
+ margin-right: -7px;
35
+ }
36
+ }
37
+
38
+ .dashicons-editor-help
39
+ {
40
+ color: #bbb;
41
+ cursor: help;
42
+
43
+ $tooltip-color: #000;
44
+
45
+ .fs-feature-desc {
46
+ opacity: 0;
47
+ visibility: hidden;
48
+ @include transition(opacity 0.3s ease-in-out);
49
+
50
+ position: absolute;
51
+ background: $tooltip-color;
52
+ color: #fff;
53
+ font-family: 'arial', serif;
54
+ font-size: 12px;
55
+ padding: 10px;
56
+ z-index: 999999;
57
+ bottom: 100%;
58
+ margin-bottom: 5px;
59
+ left: 0;
60
+ right: 0;
61
+ @include border-radius(5px);
62
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.2));
63
+ line-height: 1.3em;
64
+ font-weight: bold;
65
+ text-align: left;
66
+
67
+ .rtl &
68
+ {
69
+ text-align: right;
70
+ }
71
+
72
+ &::after {
73
+ content: ' ';
74
+ display: block;
75
+ width: 0;
76
+ height: 0;
77
+ border-style: solid;
78
+ border-width: 5px 5px 0 5px;
79
+ border-color: $tooltip-color transparent transparent transparent;
80
+ position: absolute;
81
+ top: 100%;
82
+ left: 21px;
83
+
84
+ .rtl & {
85
+ right: 21px;
86
+ left: auto;
87
+ }
88
+ }
89
+ }
90
+
91
+ &:hover {
92
+ .fs-feature-desc {
93
+ visibility: visible;
94
+ opacity: 1;
95
+ }
96
+ }
97
+ }
98
+
99
+ .button-primary {
100
+ display: block;
101
+ text-align: center;
102
+ margin-top: 10px;
103
+ }
104
+ }
105
+
106
+ #fs_customizer_support
107
+ {
108
+ display: block !important;
109
+
110
+ .button {
111
+ float: right;
112
+ }
113
+
114
+ .button-group {
115
+ width: 100%;
116
+ display: block;
117
+ margin-top: 10px;
118
+
119
+ .button {
120
+ float: none;
121
+ width: 50%;
122
+ text-align: center;
123
+ }
124
+ }
125
+ }
vendor/freemius/assets/scss/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/config.php ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! defined( 'WP_FS__SLUG' ) ) {
14
+ define( 'WP_FS__SLUG', 'freemius' );
15
+ }
16
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
17
+ define( 'WP_FS__DEV_MODE', false );
18
+ }
19
+
20
+ #--------------------------------------------------------------------------------
21
+ #region API Connectivity Issues Simulation
22
+ #--------------------------------------------------------------------------------
23
+
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
32
+ }
33
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
34
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_CURL ) {
37
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
41
+ }
42
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
43
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
44
+ }
45
+
46
+ #endregion
47
+
48
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
49
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
50
+ }
51
+
52
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
53
+ /**
54
+ * @since 1.1.7.3
55
+ * @author Vova Feldman (@svovaf)
56
+ *
57
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
58
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
59
+ * between domains on a daily basis. Therefore, to eliminate the risk of
60
+ * multiple unwanted connectivity test pings, temporary ignore domain or
61
+ * server IP changes.
62
+ */
63
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
64
+ }
65
+
66
+ /**
67
+ * If your dev environment supports custom public network IP setup
68
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
69
+ * and uncomment it during dev.
70
+ */
71
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
72
+ // VVV default public network IP.
73
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
74
+
75
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
76
+ }
77
+
78
+ /**
79
+ * If true and running with secret key, the opt-in process
80
+ * will skip the email activation process which is invoked
81
+ * when the email of the context user already exist in Freemius
82
+ * database (as a security precaution, to prevent sharing user
83
+ * secret with unauthorized entity).
84
+ *
85
+ * IMPORTANT:
86
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
87
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
88
+ * CLOCK IS SYNCED.
89
+ */
90
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
91
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
92
+ }
93
+
94
+
95
+ #--------------------------------------------------------------------------------
96
+ #region Directories
97
+ #--------------------------------------------------------------------------------
98
+
99
+ if ( ! defined( 'WP_FS__DIR' ) ) {
100
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
101
+ }
102
+ if ( ! defined( 'WP_FS__DIR_INCLUDES' ) ) {
103
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
104
+ }
105
+ if ( ! defined( 'WP_FS__DIR_TEMPLATES' ) ) {
106
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
107
+ }
108
+ if ( ! defined( 'WP_FS__DIR_ASSETS' ) ) {
109
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
110
+ }
111
+ if ( ! defined( 'WP_FS__DIR_CSS' ) ) {
112
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
113
+ }
114
+ if ( ! defined( 'WP_FS__DIR_JS' ) ) {
115
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
116
+ }
117
+ if ( ! defined( 'WP_FS__DIR_IMG' ) ) {
118
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
119
+ }
120
+ if ( ! defined( 'WP_FS__DIR_SDK' ) ) {
121
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
122
+ }
123
+
124
+ #endregion
125
+
126
+ /**
127
+ * Domain / URL / Address
128
+ */
129
+ define( 'WP_FS__ROOT_DOMAIN_PRODUCTION', 'freemius.com' );
130
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
131
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
132
+
133
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
134
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
135
+ }
136
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
137
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
138
+ }
139
+
140
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
141
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
142
+ }
143
+
144
+ #--------------------------------------------------------------------------------
145
+ #region HTTP
146
+ #--------------------------------------------------------------------------------
147
+
148
+ if ( ! defined( 'WP_FS__IS_HTTP_REQUEST' ) ) {
149
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
150
+ }
151
+
152
+ if ( ! defined( 'WP_FS__IS_HTTPS' ) ) {
153
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
154
+ // Checks if CloudFlare's HTTPS (Flexible SSL support).
155
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
156
+ 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
157
+ ) ||
158
+ // Check if HTTPS request.
159
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
160
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
161
+ );
162
+ }
163
+
164
+ if ( ! defined( 'WP_FS__IS_POST_REQUEST' ) ) {
165
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
166
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
167
+ }
168
+
169
+ if ( ! defined( 'WP_FS__REMOTE_ADDR' ) ) {
170
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
171
+ }
172
+
173
+ if ( ! defined( 'WP_FS__IS_LOCALHOST' ) ) {
174
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
175
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
176
+ } else {
177
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
178
+ is_string( WP_FS__REMOTE_ADDR ) &&
179
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) === '127.' ||
180
+ WP_FS__REMOTE_ADDR === '::1' )
181
+ );
182
+ }
183
+ }
184
+
185
+ if ( ! defined( 'WP_FS__IS_LOCALHOST_FOR_SERVER' ) ) {
186
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
187
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
188
+ }
189
+
190
+ #endregion
191
+
192
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
193
+ // By default, run with Freemius production servers.
194
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
195
+ }
196
+
197
+ if ( ! defined( 'WP_FS__ADDRESS' ) ) {
198
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
199
+ }
200
+
201
+
202
+ #--------------------------------------------------------------------------------
203
+ #region API
204
+ #--------------------------------------------------------------------------------
205
+
206
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
207
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
208
+ }
209
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
210
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
211
+ }
212
+
213
+ // Set API address for local testing.
214
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
215
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
216
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
217
+ }
218
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
219
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
220
+ }
221
+ }
222
+
223
+ #endregion
224
+
225
+ #--------------------------------------------------------------------------------
226
+ #region Checkout
227
+ #--------------------------------------------------------------------------------
228
+
229
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_PRODUCTION' ) ) {
230
+ define( 'FS_CHECKOUT__ADDRESS_PRODUCTION', 'https://checkout.freemius.com' );
231
+ }
232
+
233
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_LOCALHOST' ) ) {
234
+ define( 'FS_CHECKOUT__ADDRESS_LOCALHOST', 'http://checkout.freemius-local.com:8080' );
235
+ }
236
+
237
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS' ) ) {
238
+ define( 'FS_CHECKOUT__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? FS_CHECKOUT__ADDRESS_PRODUCTION : FS_CHECKOUT__ADDRESS_LOCALHOST ) );
239
+ }
240
+
241
+ #endregion
242
+
243
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
244
+
245
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
246
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
247
+ }
248
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
249
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
250
+ }
251
+ if ( ! defined( 'WP_FS__GDPR_OPTION_NAME' ) ) {
252
+ define( 'WP_FS__GDPR_OPTION_NAME', WP_FS___OPTION_PREFIX . 'gdpr' );
253
+ }
254
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
255
+
256
+ /**
257
+ * Module types
258
+ *
259
+ * @since 1.2.2
260
+ */
261
+ define( 'WP_FS__MODULE_TYPE_PLUGIN', 'plugin' );
262
+ define( 'WP_FS__MODULE_TYPE_THEME', 'theme' );
263
+
264
+ /**
265
+ * Billing Frequencies
266
+ */
267
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
268
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
269
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
270
+
271
+ /**
272
+ * Plans
273
+ */
274
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
275
+ define( 'WP_FS__PLAN_FREE', 'free' );
276
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
277
+
278
+ /**
279
+ * Times in seconds
280
+ */
281
+ if ( ! defined( 'WP_FS__TIME_5_MIN_IN_SEC' ) ) {
282
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
283
+ }
284
+ if ( ! defined( 'WP_FS__TIME_10_MIN_IN_SEC' ) ) {
285
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
286
+ }
287
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
288
+ if ( ! defined( 'WP_FS__TIME_12_HOURS_IN_SEC' ) ) {
289
+ define( 'WP_FS__TIME_12_HOURS_IN_SEC', 43200 );
290
+ }
291
+ if ( ! defined( 'WP_FS__TIME_24_HOURS_IN_SEC' ) ) {
292
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', WP_FS__TIME_12_HOURS_IN_SEC * 2 );
293
+ }
294
+ if ( ! defined( 'WP_FS__TIME_WEEK_IN_SEC' ) ) {
295
+ define( 'WP_FS__TIME_WEEK_IN_SEC', 7 * WP_FS__TIME_24_HOURS_IN_SEC );
296
+ }
297
+
298
+ #--------------------------------------------------------------------------------
299
+ #region Debugging
300
+ #--------------------------------------------------------------------------------
301
+
302
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
303
+ $debug_mode = get_option( 'fs_debug_mode', null );
304
+
305
+ if ( $debug_mode === null ) {
306
+ $debug_mode = false;
307
+ add_option( 'fs_debug_mode', $debug_mode );
308
+ }
309
+
310
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
311
+ }
312
+
313
+ if ( ! defined( 'WP_FS__ECHO_DEBUG_SDK' ) ) {
314
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
315
+ }
316
+ if ( ! defined( 'WP_FS__LOG_DATETIME_FORMAT' ) ) {
317
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s' );
318
+ }
319
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
320
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
321
+ }
322
+
323
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
324
+ error_reporting( E_ALL );
325
+ }
326
+
327
+ #endregion
328
+
329
+ if ( ! defined( 'WP_FS__SCRIPT_START_TIME' ) ) {
330
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
331
+ }
332
+ if ( ! defined( 'WP_FS__DEFAULT_PRIORITY' ) ) {
333
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
334
+ }
335
+ if ( ! defined( 'WP_FS__LOWEST_PRIORITY' ) ) {
336
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
337
+ }
338
+
339
+ #--------------------------------------------------------------------------------
340
+ #region Multisite Network
341
+ #--------------------------------------------------------------------------------
342
+
343
+ /**
344
+ * Do not use this define directly, it will have the wrong value
345
+ * during plugin uninstall/deletion when the inclusion of the plugin
346
+ * is triggered due to registration with register_uninstall_hook().
347
+ *
348
+ * Instead, use fs_is_network_admin().
349
+ *
350
+ * @author Vova Feldman (@svovaf)
351
+ */
352
+ if ( ! defined( 'WP_FS__IS_NETWORK_ADMIN' ) ) {
353
+ define( 'WP_FS__IS_NETWORK_ADMIN',
354
+ is_network_admin() ||
355
+ ( is_multisite() &&
356
+ ( ( defined( 'DOING_AJAX' ) && DOING_AJAX &&
357
+ ( isset( $_REQUEST['_fs_network_admin'] ) /*||
358
+ ( ! empty( $_REQUEST['action'] ) && 'delete-plugin' === $_REQUEST['action'] )*/ )
359
+ ) ||
360
+ // Plugin uninstall.
361
+ defined( 'WP_UNINSTALL_PLUGIN' ) )
362
+ )
363
+ );
364
+ }
365
+
366
+ /**
367
+ * Do not use this define directly, it will have the wrong value
368
+ * during plugin uninstall/deletion when the inclusion of the plugin
369
+ * is triggered due to registration with register_uninstall_hook().
370
+ *
371
+ * Instead, use fs_is_blog_admin().
372
+ *
373
+ * @author Vova Feldman (@svovaf)
374
+ */
375
+ if ( ! defined( 'WP_FS__IS_BLOG_ADMIN' ) ) {
376
+ define( 'WP_FS__IS_BLOG_ADMIN', is_blog_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['_fs_blog_admin'] ) ) );
377
+ }
378
+
379
+ if ( ! defined( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED' ) ) {
380
+ // Set to true to show network level settings even if delegated to site admins.
381
+ define( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED', false );
382
+ }
383
+
384
+ #endregion
385
+
386
+ if ( ! defined( 'WP_FS__DEMO_MODE' ) ) {
387
+ define( 'WP_FS__DEMO_MODE', false );
388
+ }
vendor/freemius/includes/class-freemius-abstract.php ADDED
@@ -0,0 +1,597 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+
14
+ /**
15
+ * - Each instance of Freemius class represents a single plugin
16
+ * install by a single user (the installer of the plugin).
17
+ *
18
+ * - Each website can only have one install of the same plugin.
19
+ *
20
+ * - Install entity is only created after a user connects his account with Freemius.
21
+ *
22
+ * Class Freemius_Abstract
23
+ */
24
+ abstract class Freemius_Abstract {
25
+
26
+ #----------------------------------------------------------------------------------
27
+ #region Identity
28
+ #----------------------------------------------------------------------------------
29
+
30
+ /**
31
+ * Check if user has connected his account (opted-in).
32
+ *
33
+ * Note:
34
+ * If the user opted-in and opted-out on a later stage,
35
+ * this will still return true. If you want to check if the
36
+ * user is currently opted-in, use:
37
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
38
+ *
39
+ * @since 1.0.1
40
+ * @return bool
41
+ */
42
+ abstract function is_registered();
43
+
44
+ /**
45
+ * Check if the user skipped connecting the account with Freemius.
46
+ *
47
+ * @since 1.0.7
48
+ *
49
+ * @return bool
50
+ */
51
+ abstract function is_anonymous();
52
+
53
+ /**
54
+ * Check if the user currently in activation mode.
55
+ *
56
+ * @since 1.0.7
57
+ *
58
+ * @return bool
59
+ */
60
+ abstract function is_activation_mode();
61
+
62
+ #endregion
63
+
64
+ #----------------------------------------------------------------------------------
65
+ #region Usage Tracking
66
+ #----------------------------------------------------------------------------------
67
+
68
+ /**
69
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
70
+ *
71
+ * @author Leo Fajardo (@leorw)
72
+ * @since 1.2.1.5
73
+ *
74
+ * @return bool
75
+ */
76
+ abstract function is_tracking_allowed();
77
+
78
+ /**
79
+ * Returns TRUE if the user never opted-in or manually opted-out.
80
+ *
81
+ * @author Vova Feldman (@svovaf)
82
+ * @since 1.2.1.5
83
+ *
84
+ * @return bool
85
+ */
86
+ function is_tracking_prohibited() {
87
+ return ! $this->is_registered() || ! $this->is_tracking_allowed();
88
+ }
89
+
90
+ /**
91
+ * Opt-out from usage tracking.
92
+ *
93
+ * Note: This will not delete the account information but will stop all tracking.
94
+ *
95
+ * Returns:
96
+ * 1. FALSE - If the user never opted-in.
97
+ * 2. TRUE - If successfully opted-out.
98
+ * 3. object - API Result on failure.
99
+ *
100
+ * @author Leo Fajardo (@leorw)
101
+ * @since 1.2.1.5
102
+ *
103
+ * @return bool|object
104
+ */
105
+ abstract function stop_tracking();
106
+
107
+ /**
108
+ * Opt-in back into usage tracking.
109
+ *
110
+ * Note: This will only work if the user opted-in previously.
111
+ *
112
+ * Returns:
113
+ * 1. FALSE - If the user never opted-in.
114
+ * 2. TRUE - If successfully opted-in back to usage tracking.
115
+ * 3. object - API result on failure.
116
+ *
117
+ * @author Leo Fajardo (@leorw)
118
+ * @since 1.2.1.5
119
+ *
120
+ * @return bool|object
121
+ */
122
+ abstract function allow_tracking();
123
+
124
+ #endregion
125
+
126
+ #----------------------------------------------------------------------------------
127
+ #region Module Type
128
+ #----------------------------------------------------------------------------------
129
+
130
+ /**
131
+ * Checks if the plugin's type is "plugin". The other type is "theme".
132
+ *
133
+ * @author Leo Fajardo (@leorw)
134
+ * @since 1.2.2
135
+ *
136
+ * @return bool
137
+ */
138
+ abstract function is_plugin();
139
+
140
+ /**
141
+ * Checks if the module type is "theme". The other type is "plugin".
142
+ *
143
+ * @author Leo Fajardo (@leorw)
144
+ * @since 1.2.2
145
+ *
146
+ * @return bool
147
+ */
148
+ function is_theme() {
149
+ return ( ! $this->is_plugin() );
150
+ }
151
+
152
+ #endregion
153
+
154
+ #----------------------------------------------------------------------------------
155
+ #region Permissions
156
+ #----------------------------------------------------------------------------------
157
+
158
+ /**
159
+ * Check if plugin must be WordPress.org compliant.
160
+ *
161
+ * @since 1.0.7
162
+ *
163
+ * @return bool
164
+ */
165
+ abstract function is_org_repo_compliant();
166
+
167
+ /**
168
+ * Check if plugin is allowed to install executable files.
169
+ *
170
+ * @author Vova Feldman (@svovaf)
171
+ * @since 1.0.5
172
+ *
173
+ * @return bool
174
+ */
175
+ function is_allowed_to_install() {
176
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
177
+ }
178
+
179
+ #endregion
180
+
181
+ /**
182
+ * Check if user in trial or in free plan (not paying).
183
+ *
184
+ * @author Vova Feldman (@svovaf)
185
+ * @since 1.0.4
186
+ *
187
+ * @return bool
188
+ */
189
+ function is_not_paying() {
190
+ return ( $this->is_trial() || $this->is_free_plan() );
191
+ }
192
+
193
+ /**
194
+ * Check if the user has an activated and valid paid license on current plugin's install.
195
+ *
196
+ * @since 1.0.9
197
+ *
198
+ * @return bool
199
+ */
200
+ abstract function is_paying();
201
+
202
+ /**
203
+ * Check if the user is paying or in trial.
204
+ *
205
+ * @since 1.0.9
206
+ *
207
+ * @return bool
208
+ */
209
+ function is_paying_or_trial() {
210
+ return ( $this->is_paying() || $this->is_trial() );
211
+ }
212
+
213
+ /**
214
+ * Check if user in a trial or have feature enabled license.
215
+ *
216
+ * @author Vova Feldman (@svovaf)
217
+ * @since 1.1.7
218
+ *
219
+ * @return bool
220
+ */
221
+ abstract function can_use_premium_code();
222
+
223
+ #----------------------------------------------------------------------------------
224
+ #region Premium Only
225
+ #----------------------------------------------------------------------------------
226
+
227
+ /**
228
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
229
+ * included in the premium code.
230
+ *
231
+ * Example:
232
+ * if ( freemius()->is__premium_only() ) {
233
+ * ...
234
+ * }
235
+ */
236
+
237
+ /**
238
+ * Returns true when running premium plugin code.
239
+ *
240
+ * @since 1.0.9
241
+ *
242
+ * @return bool
243
+ */
244
+ function is__premium_only() {
245
+ return $this->is_premium();
246
+ }
247
+
248
+ /**
249
+ * Check if the user has an activated and valid paid license on current plugin's install.
250
+ *
251
+ * @since 1.0.9
252
+ *
253
+ * @return bool
254
+ *
255
+ */
256
+ function is_paying__premium_only() {
257
+ return ( $this->is__premium_only() && $this->is_paying() );
258
+ }
259
+
260
+ /**
261
+ * All code wrapped in this statement will be only included in the premium code.
262
+ *
263
+ * @since 1.0.9
264
+ *
265
+ * @param string $plan Plan name.
266
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
267
+ *
268
+ * @return bool
269
+ */
270
+ function is_plan__premium_only( $plan, $exact = false ) {
271
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
272
+ }
273
+
274
+ /**
275
+ * Check if plan matches active license' plan or active trial license' plan.
276
+ *
277
+ * All code wrapped in this statement will be only included in the premium code.
278
+ *
279
+ * @since 1.0.9
280
+ *
281
+ * @param string $plan Plan name.
282
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
283
+ *
284
+ * @return bool
285
+ */
286
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
287
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
288
+ }
289
+
290
+ /**
291
+ * Check if the user is paying or in trial.
292
+ *
293
+ * All code wrapped in this statement will be only included in the premium code.
294
+ *
295
+ * @since 1.0.9
296
+ *
297
+ * @return bool
298
+ */
299
+ function is_paying_or_trial__premium_only() {
300
+ return $this->is_premium() && $this->is_paying_or_trial();
301
+ }
302
+
303
+ /**
304
+ * Check if the user has an activated and valid paid license on current plugin's install.
305
+ *
306
+ * @since 1.0.4
307
+ *
308
+ * @return bool
309
+ *
310
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
311
+ * @using Alias to is_paying__premium_only()
312
+ */
313
+ function is_paying__fs__() {
314
+ return $this->is_paying__premium_only();
315
+ }
316
+
317
+ /**
318
+ * Check if user in a trial or have feature enabled license.
319
+ *
320
+ * All code wrapped in this statement will be only included in the premium code.
321
+ *
322
+ * @author Vova Feldman (@svovaf)
323
+ * @since 1.1.9
324
+ *
325
+ * @return bool
326
+ */
327
+ function can_use_premium_code__premium_only() {
328
+ return $this->is_premium() && $this->can_use_premium_code();
329
+ }
330
+
331
+ #endregion
332
+
333
+ #----------------------------------------------------------------------------------
334
+ #region Trial
335
+ #----------------------------------------------------------------------------------
336
+
337
+ /**
338
+ * Check if the user in a trial.
339
+ *
340
+ * @since 1.0.3
341
+ *
342
+ * @return bool
343
+ */
344
+ abstract function is_trial();
345
+
346
+ /**
347
+ * Check if trial already utilized.
348
+ *
349
+ * @since 1.0.9
350
+ *
351
+ * @return bool
352
+ */
353
+ abstract function is_trial_utilized();
354
+
355
+ #endregion
356
+
357
+ #----------------------------------------------------------------------------------
358
+ #region Plans
359
+ #----------------------------------------------------------------------------------
360
+
361
+ /**
362
+ * Check if the user is on the free plan of the product.
363
+ *
364
+ * @since 1.0.4
365
+ *
366
+ * @return bool
367
+ */
368
+ abstract function is_free_plan();
369
+
370
+ /**
371
+ * @since 1.0.2
372
+ *
373
+ * @param string $plan Plan name.
374
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
375
+ *
376
+ * @return bool
377
+ */
378
+ abstract function is_plan( $plan, $exact = false );
379
+
380
+ /**
381
+ * Check if plan based on trial. If not in trial mode, should return false.
382
+ *
383
+ * @since 1.0.9
384
+ *
385
+ * @param string $plan Plan name.
386
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
387
+ *
388
+ * @return bool
389
+ */
390
+ abstract function is_trial_plan( $plan, $exact = false );
391
+
392
+ /**
393
+ * Check if plan matches active license' plan or active trial license' plan.
394
+ *
395
+ * @since 1.0.9
396
+ *
397
+ * @param string $plan Plan name.
398
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
399
+ *
400
+ * @return bool
401
+ */
402
+ function is_plan_or_trial( $plan, $exact = false ) {
403
+ return $this->is_plan( $plan, $exact ) ||
404
+ $this->is_trial_plan( $plan, $exact );
405
+ }
406
+
407
+ /**
408
+ * Check if plugin has any paid plans.
409
+ *
410
+ * @author Vova Feldman (@svovaf)
411
+ * @since 1.0.7
412
+ *
413
+ * @return bool
414
+ */
415
+ abstract function has_paid_plan();
416
+
417
+ /**
418
+ * Check if plugin has any free plan, or is it premium only.
419
+ *
420
+ * Note: If no plans configured, assume plugin is free.
421
+ *
422
+ * @author Vova Feldman (@svovaf)
423
+ * @since 1.0.7
424
+ *
425
+ * @return bool
426
+ */
427
+ abstract function has_free_plan();
428
+
429
+ /**
430
+ * Check if plugin is premium only (no free plans).
431
+ *
432
+ * NOTE: is__premium_only() is very different method, don't get confused.
433
+ *
434
+ * @author Vova Feldman (@svovaf)
435
+ * @since 1.1.9
436
+ *
437
+ * @return bool
438
+ */
439
+ abstract function is_only_premium();
440
+
441
+ /**
442
+ * Check if module has a premium code version.
443
+ *
444
+ * Serviceware module might be freemium without any
445
+ * premium code version, where the paid features
446
+ * are all part of the service.
447
+ *
448
+ * @author Vova Feldman (@svovaf)
449
+ * @since 1.2.1.6
450
+ *
451
+ * @return bool
452
+ */
453
+ abstract function has_premium_version();
454
+
455
+ /**
456
+ * Check if module has any release on Freemius,
457
+ * or all plugin's code is on WordPress.org (Serviceware).
458
+ *
459
+ * @return bool
460
+ */
461
+ function has_release_on_freemius() {
462
+ return ! $this->is_org_repo_compliant() ||
463
+ $this->has_premium_version();
464
+ }
465
+
466
+ /**
467
+ * Checks if it's a freemium plugin.
468
+ *
469
+ * @author Vova Feldman (@svovaf)
470
+ * @since 1.1.9
471
+ *
472
+ * @return bool
473
+ */
474
+ function is_freemium() {
475
+ return $this->has_paid_plan() &&
476
+ $this->has_free_plan();
477
+ }
478
+
479
+ /**
480
+ * Check if module has only one plan.
481
+ *
482
+ * @author Vova Feldman (@svovaf)
483
+ * @since 1.2.1.7
484
+ *
485
+ * @return bool
486
+ */
487
+ abstract function is_single_plan();
488
+
489
+ #endregion
490
+
491
+ /**
492
+ * Check if running payments in sandbox mode.
493
+ *
494
+ * @since 1.0.4
495
+ *
496
+ * @return bool
497
+ */
498
+ abstract function is_payments_sandbox();
499
+
500
+ /**
501
+ * Check if running test vs. live plugin.
502
+ *
503
+ * @since 1.0.5
504
+ *
505
+ * @return bool
506
+ */
507
+ abstract function is_live();
508
+
509
+ /**
510
+ * Check if running premium plugin code.
511
+ *
512
+ * @since 1.0.5
513
+ *
514
+ * @return bool
515
+ */
516
+ abstract function is_premium();
517
+
518
+ /**
519
+ * Get upgrade URL.
520
+ *
521
+ * @author Vova Feldman (@svovaf)
522
+ * @since 1.0.2
523
+ *
524
+ * @param string $period Billing cycle.
525
+ *
526
+ * @return string
527
+ */
528
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
529
+
530
+ /**
531
+ * Check if Freemius was first added in a plugin update.
532
+ *
533
+ * @author Vova Feldman (@svovaf)
534
+ * @since 1.1.5
535
+ *
536
+ * @return bool
537
+ */
538
+ function is_plugin_update() {
539
+ return ! $this->is_plugin_new_install();
540
+ }
541
+
542
+ /**
543
+ * Check if Freemius was part of the plugin when the user installed it first.
544
+ *
545
+ * @author Vova Feldman (@svovaf)
546
+ * @since 1.1.5
547
+ *
548
+ * @return bool
549
+ */
550
+ abstract function is_plugin_new_install();
551
+
552
+ #----------------------------------------------------------------------------------
553
+ #region Marketing
554
+ #----------------------------------------------------------------------------------
555
+
556
+ /**
557
+ * Check if current user purchased any other plugins before.
558
+ *
559
+ * @author Vova Feldman (@svovaf)
560
+ * @since 1.0.9
561
+ *
562
+ * @return bool
563
+ */
564
+ abstract function has_purchased_before();
565
+
566
+ /**
567
+ * Check if current user classified as an agency.
568
+ *
569
+ * @author Vova Feldman (@svovaf)
570
+ * @since 1.0.9
571
+ *
572
+ * @return bool
573
+ */
574
+ abstract function is_agency();
575
+
576
+ /**
577
+ * Check if current user classified as a developer.
578
+ *
579
+ * @author Vova Feldman (@svovaf)
580
+ * @since 1.0.9
581
+ *
582
+ * @return bool
583
+ */
584
+ abstract function is_developer();
585
+
586
+ /**
587
+ * Check if current user classified as a business.
588
+ *
589
+ * @author Vova Feldman (@svovaf)
590
+ * @since 1.0.9
591
+ *
592
+ * @return bool
593
+ */
594
+ abstract function is_business();
595
+
596
+ #endregion
597
+ }
vendor/freemius/includes/class-freemius.php ADDED
@@ -0,0 +1,20822 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.3
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ // "final class"
13
+ class Freemius extends Freemius_Abstract {
14
+ /**
15
+ * SDK Version
16
+ *
17
+ * @var string
18
+ */
19
+ public $version = WP_FS__SDK_VERSION;
20
+
21
+ #region Plugin Info
22
+
23
+ /**
24
+ * @since 1.0.1
25
+ *
26
+ * @var string
27
+ */
28
+ private $_slug;
29
+
30
+ /**
31
+ * @since 1.0.0
32
+ *
33
+ * @var string
34
+ */
35
+ private $_plugin_basename;
36
+ /**
37
+ * @since 1.0.0
38
+ *
39
+ * @var string
40
+ */
41
+ private $_free_plugin_basename;
42
+ /**
43
+ * @since 1.0.0
44
+ *
45
+ * @var string
46
+ */
47
+ private $_plugin_dir_path;
48
+ /**
49
+ * @since 1.0.0
50
+ *
51
+ * @var string
52
+ */
53
+ private $_plugin_dir_name;
54
+ /**
55
+ * @since 1.0.0
56
+ *
57
+ * @var string
58
+ */
59
+ private $_plugin_main_file_path;
60
+ /**
61
+ * @var string[]
62
+ */
63
+ private $_plugin_data;
64
+ /**
65
+ * @since 1.0.9
66
+ *
67
+ * @var string
68
+ */
69
+ private $_plugin_name;
70
+ /**
71
+ * @since 1.2.2
72
+ *
73
+ * @var string
74
+ */
75
+ private $_module_type;
76
+
77
+ #endregion Plugin Info
78
+
79
+ /**
80
+ * @since 1.0.9
81
+ *
82
+ * @var bool If false, don't turn Freemius on.
83
+ */
84
+ private $_is_on;
85
+
86
+ /**
87
+ * @since 1.1.3
88
+ *
89
+ * @var bool If false, don't turn Freemius on.
90
+ */
91
+ private $_is_anonymous;
92
+
93
+ /**
94
+ * @since 1.0.9
95
+ * @var bool If false, issues with connectivity to Freemius API.
96
+ */
97
+ private $_has_api_connection;
98
+
99
+ /**
100
+ * @since 1.0.9
101
+ * @since 2.0.0 Default to true since we need the property during the instance construction, prior to the dynamic_init() execution.
102
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
103
+ */
104
+ private $_enable_anonymous = true;
105
+
106
+ /**
107
+ * @since 1.1.7.5
108
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
109
+ */
110
+ private $_anonymous_mode;
111
+
112
+ /**
113
+ * @since 1.1.9
114
+ * @var bool Hints the SDK if plugin have any free plans.
115
+ */
116
+ private $_is_premium_only;
117
+
118
+ /**
119
+ * @since 1.2.1.6
120
+ * @var bool Hints the SDK if plugin have premium code version at all.
121
+ */
122
+ private $_has_premium_version;
123
+
124
+ /**
125
+ * @since 1.2.1.6
126
+ * @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
127
+ */
128
+ private $_ignore_pending_mode;
129
+
130
+ /**
131
+ * @since 1.0.8
132
+ * @var bool Hints the SDK if the plugin has any paid plans.
133
+ */
134
+ private $_has_paid_plans;
135
+
136
+ /**
137
+ * @since 1.2.1.5
138
+ * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
139
+ * without a specified period, if positive - the number of trial days.
140
+ */
141
+ private $_trial_days = - 1;
142
+
143
+ /**
144
+ * @since 1.2.1.5
145
+ * @var bool Hints the SDK if the trial requires a payment method or not.
146
+ */
147
+ private $_is_trial_require_payment = false;
148
+
149
+ /**
150
+ * @since 1.0.7
151
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
152
+ */
153
+ private $_is_org_compliant;
154
+
155
+ /**
156
+ * @since 1.0.7
157
+ * @var bool Hints the SDK if the plugin is has add-ons.
158
+ */
159
+ private $_has_addons;
160
+
161
+ /**
162
+ * @since 1.1.6
163
+ * @var string[]bool.
164
+ */
165
+ private $_permissions;
166
+
167
+ /**
168
+ * @var FS_Storage
169
+ */
170
+ private $_storage;
171
+
172
+ /**
173
+ * @since 1.2.2.7
174
+ * @var FS_Cache_Manager
175
+ */
176
+ private $_cache;
177
+
178
+ /**
179
+ * @since 1.0.0
180
+ *
181
+ * @var FS_Logger
182
+ */
183
+ private $_logger;
184
+ /**
185
+ * @since 1.0.4
186
+ *
187
+ * @var FS_Plugin
188
+ */
189
+ private $_plugin = false;
190
+ /**
191
+ * @since 1.0.4
192
+ *
193
+ * @var FS_Plugin|false
194
+ */
195
+ private $_parent_plugin = false;
196
+ /**
197
+ * @since 1.1.1
198
+ *
199
+ * @var Freemius
200
+ */
201
+ private $_parent = false;
202
+ /**
203
+ * @since 1.0.1
204
+ *
205
+ * @var FS_User
206
+ */
207
+ private $_user = false;
208
+ /**
209
+ * @since 1.0.1
210
+ *
211
+ * @var FS_Site
212
+ */
213
+ private $_site = false;
214
+ /**
215
+ * @since 1.0.1
216
+ *
217
+ * @var FS_Plugin_License
218
+ */
219
+ private $_license;
220
+ /**
221
+ * @since 1.0.2
222
+ *
223
+ * @var FS_Plugin_Plan[]
224
+ */
225
+ private $_plans = false;
226
+ /**
227
+ * @var FS_Plugin_License[]
228
+ * @since 1.0.5
229
+ */
230
+ private $_licenses = false;
231
+
232
+ /**
233
+ * @since 1.0.1
234
+ *
235
+ * @var FS_Admin_Menu_Manager
236
+ */
237
+ private $_menu;
238
+
239
+ /**
240
+ * @var FS_Admin_Notices
241
+ */
242
+ private $_admin_notices;
243
+
244
+ /**
245
+ * @since 1.1.6
246
+ *
247
+ * @var FS_Admin_Notices
248
+ */
249
+ private static $_global_admin_notices;
250
+
251
+ /**
252
+ * @var FS_Logger
253
+ * @since 1.0.0
254
+ */
255
+ private static $_static_logger;
256
+
257
+ /**
258
+ * @var FS_Options
259
+ * @since 1.0.2
260
+ */
261
+ private static $_accounts;
262
+
263
+ /**
264
+ * @since 1.2.2
265
+ *
266
+ * @var number
267
+ */
268
+ private $_module_id;
269
+
270
+ /**
271
+ * @var Freemius[]
272
+ */
273
+ private static $_instances = array();
274
+
275
+ /**
276
+ * @since 1.2.3
277
+ *
278
+ * @var FS_Affiliate
279
+ */
280
+ private $affiliate = null;
281
+
282
+ /**
283
+ * @since 1.2.3
284
+ *
285
+ * @var FS_AffiliateTerms
286
+ */
287
+ private $plugin_affiliate_terms = null;
288
+
289
+ /**
290
+ * @since 1.2.3
291
+ *
292
+ * @var FS_AffiliateTerms
293
+ */
294
+ private $custom_affiliate_terms = null;
295
+
296
+ /**
297
+ * @since 2.0.0
298
+ *
299
+ * @var bool
300
+ */
301
+ private $_is_multisite_integrated;
302
+
303
+ /**
304
+ * @since 2.0.0
305
+ *
306
+ * @var bool True if the current request is for a network admin screen and the plugin is network active.
307
+ */
308
+ private $_is_network_active;
309
+
310
+ /**
311
+ * @since 2.0.0
312
+ *
313
+ * @var int|null The original blog ID the plugin was loaded with.
314
+ */
315
+ private $_blog_id = null;
316
+
317
+ /**
318
+ * @since 2.0.0
319
+ *
320
+ * @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
321
+ */
322
+ private $_context_is_network_or_blog_id = null;
323
+
324
+ /**
325
+ * @since 2.0.0
326
+ *
327
+ * @var string
328
+ */
329
+ private $_dynamically_added_top_level_page_hook_name = '';
330
+
331
+ #region Uninstall Reasons IDs
332
+
333
+ const REASON_NO_LONGER_NEEDED = 1;
334
+ const REASON_FOUND_A_BETTER_PLUGIN = 2;
335
+ const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
336
+ const REASON_BROKE_MY_SITE = 4;
337
+ const REASON_SUDDENLY_STOPPED_WORKING = 5;
338
+ const REASON_CANT_PAY_ANYMORE = 6;
339
+ const REASON_OTHER = 7;
340
+ const REASON_DIDNT_WORK = 8;
341
+ const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
342
+ const REASON_COULDNT_MAKE_IT_WORK = 10;
343
+ const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
344
+ const REASON_NOT_WORKING = 12;
345
+ const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
346
+ const REASON_DIDNT_WORK_AS_EXPECTED = 14;
347
+ const REASON_TEMPORARY_DEACTIVATION = 15;
348
+
349
+ #endregion
350
+
351
+ /* Ctor
352
+ ------------------------------------------------------------------------------------------------------------------*/
353
+
354
+ /**
355
+ * Main singleton instance.
356
+ *
357
+ * @author Vova Feldman (@svovaf)
358
+ * @since 1.0.0
359
+ *
360
+ * @param number $module_id
361
+ * @param string|bool $slug
362
+ * @param bool $is_init Since 1.2.1 Is initiation sequence.
363
+ */
364
+ private function __construct( $module_id, $slug = false, $is_init = false ) {
365
+ if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
366
+ $this->store_id_slug_type_path_map( $module_id, $slug );
367
+ }
368
+
369
+ $this->_module_id = $module_id;
370
+ $this->_slug = $this->get_slug();
371
+ $this->_module_type = $this->get_module_type();
372
+
373
+ $this->_blog_id = is_multisite() ? get_current_blog_id() : null;
374
+
375
+ $this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
376
+
377
+ $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
378
+
379
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
380
+
381
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
382
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
383
+ $this->_plugin_basename = $this->get_plugin_basename();
384
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
385
+
386
+ $this->_is_multisite_integrated = (
387
+ defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
388
+ ( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
389
+ );
390
+
391
+ $this->_is_network_active = (
392
+ is_multisite() &&
393
+ $this->_is_multisite_integrated &&
394
+ // Themes are always network activated, but the ACTUAL activation is per site.
395
+ $this->is_plugin() &&
396
+ ( is_plugin_active_for_network( $this->_plugin_basename ) ||
397
+ // Plugin network level activation or uninstall.
398
+ is_plugin_inactive( $this->_plugin_basename ) )
399
+ );
400
+
401
+ $this->_storage->set_network_active(
402
+ $this->_is_network_active,
403
+ $this->is_delegated_connection()
404
+ );
405
+
406
+ #region Migration
407
+
408
+ if ( is_multisite() ) {
409
+ /**
410
+ * If the install_timestamp exists on the site level but doesn't exist on the
411
+ * network level storage, it means that we need to process the storage with migration.
412
+ *
413
+ * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, install_timestamp will be already set in the network level storage.
414
+ *
415
+ * @author Vova Feldman (@svovaf)
416
+ * @since 2.0.0
417
+ */
418
+ if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
419
+ false !== $this->_storage->get( 'install_timestamp', false, false )
420
+ ) {
421
+ // Initiate storage migration.
422
+ $this->_storage->migrate_to_network();
423
+
424
+ // Migrate module cache to network level storage.
425
+ $this->_cache->migrate_to_network();
426
+ }
427
+ }
428
+
429
+ #endregion
430
+
431
+ $base_name_split = explode( '/', $this->_plugin_basename );
432
+ $this->_plugin_dir_name = $base_name_split[0];
433
+
434
+ if ( $this->_logger->is_on() ) {
435
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
436
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
437
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
438
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
439
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
440
+ }
441
+
442
+ // Remember link between file to slug.
443
+ $this->store_file_slug_map();
444
+
445
+ // Store plugin's initial install timestamp.
446
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
447
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
448
+ }
449
+
450
+ if ( ! is_object( $this->_plugin ) ) {
451
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
452
+ }
453
+
454
+ $this->_admin_notices = FS_Admin_Notices::instance(
455
+ $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
456
+ /**
457
+ * Ensure that the admin notice will always have a title by using the stored plugin title if available and
458
+ * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
459
+ *
460
+ * @author Leo Fajardo (@leorw)
461
+ * @since 1.2.2
462
+ */
463
+ ( is_object( $this->_plugin ) ? $this->_plugin->title : $this->get_plugin_name() ),
464
+ $this->get_unique_affix()
465
+ );
466
+
467
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
468
+ 'true' === fs_request_is_action( 'restart_freemius' )
469
+ ) {
470
+ FS_Api::clear_cache();
471
+ $this->_cache->clear();
472
+ }
473
+
474
+ $this->_register_hooks();
475
+
476
+ /**
477
+ * Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
478
+ * instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
479
+ * loaded in `_load_account` for versions of SDK starting from 2.0.0.
480
+ *
481
+ * @author Leo Fajardo (@leorw)
482
+ */
483
+ self::migrate_install_plan_to_plan_id( $this->_storage );
484
+
485
+ $this->_load_account();
486
+
487
+ $this->_version_updates_handler();
488
+ }
489
+
490
+ /**
491
+ * Checks whether this module has a settings menu.
492
+ *
493
+ * @author Leo Fajardo (@leorw)
494
+ * @since 1.2.2
495
+ *
496
+ * @return bool
497
+ */
498
+ function has_settings_menu() {
499
+ return ( $this->_is_network_active && fs_is_network_admin() ) ?
500
+ $this->_menu->has_network_menu() :
501
+ $this->_menu->has_menu();
502
+ }
503
+
504
+ /**
505
+ * Check if the context module is free wp.org theme.
506
+ *
507
+ * This method is helpful because:
508
+ * 1. wp.org themes are limited to a single submenu item,
509
+ * and sub-submenu items are most likely not allowed (never verified).
510
+ * 2. wp.org themes are not allowed to redirect the user
511
+ * after the theme activation, therefore, the agreed UX
512
+ * is showing the opt-in as a modal dialog box after
513
+ * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
514
+ *
515
+ * @author Vova Feldman (@svovaf)
516
+ * @since 1.2.2.7
517
+ *
518
+ * @return bool
519
+ */
520
+ function is_free_wp_org_theme() {
521
+ return (
522
+ $this->is_theme() &&
523
+ $this->is_org_repo_compliant() &&
524
+ ! $this->is_premium()
525
+ );
526
+ }
527
+
528
+ /**
529
+ * Checks whether this a submenu item is visible.
530
+ *
531
+ * @author Vova Feldman (@svovaf)
532
+ * @since 1.2.2.6
533
+ * @since 1.2.2.7 Even if the menu item was specified to be hidden, when it is the context page, then show the submenu item so the user will have the right context page.
534
+ *
535
+ * @param string $slug
536
+ * @param bool $ignore_free_wp_org_theme_context This is used to decide if the associated tab should be shown
537
+ * or hidden.
538
+ *
539
+ * @return bool
540
+ */
541
+ function is_submenu_item_visible( $slug, $ignore_free_wp_org_theme_context = false ) {
542
+ if ( $this->is_admin_page( $slug ) ) {
543
+ /**
544
+ * It is the current context page, so show the submenu item
545
+ * so the user will have the right context page, even if it
546
+ * was set to hidden.
547
+ */
548
+ return true;
549
+ }
550
+
551
+ if ( ! $this->has_settings_menu() ) {
552
+ // No menu settings at all.
553
+ return false;
554
+ }
555
+
556
+ if ( ! $ignore_free_wp_org_theme_context && $this->is_free_wp_org_theme() ) {
557
+ /**
558
+ * wp.org themes are limited to a single submenu item, and
559
+ * sub-submenu items are most likely not allowed (never verified).
560
+ */
561
+ return false;
562
+ }
563
+
564
+ return $this->_menu->is_submenu_item_visible( $slug );
565
+ }
566
+
567
+ /**
568
+ * Check if a Freemius page should be accessible via the UI.
569
+ *
570
+ * @author Vova Feldman (@svovaf)
571
+ * @since 1.2.2.7
572
+ *
573
+ * @param string $slug
574
+ *
575
+ * @return bool
576
+ */
577
+ function is_page_visible( $slug ) {
578
+ if ( $this->is_admin_page( $slug ) ) {
579
+ return true;
580
+ }
581
+
582
+ return $this->_menu->is_submenu_item_visible( $slug, true, true );
583
+ }
584
+
585
+ /**
586
+ * @author Vova Feldman (@svovaf)
587
+ * @since 1.0.9
588
+ */
589
+ private function _version_updates_handler() {
590
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
591
+ // Freemius version upgrade mode.
592
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
593
+ $this->_storage->sdk_version = $this->version;
594
+
595
+ if ( empty( $this->_storage->sdk_last_version ) ||
596
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
597
+ ) {
598
+ $this->_storage->sdk_upgrade_mode = true;
599
+ $this->_storage->sdk_downgrade_mode = false;
600
+ } else {
601
+ $this->_storage->sdk_downgrade_mode = true;
602
+ $this->_storage->sdk_upgrade_mode = false;
603
+
604
+ }
605
+
606
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
607
+ }
608
+
609
+ $plugin_version = $this->get_plugin_version();
610
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
611
+ // Plugin version upgrade mode.
612
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
613
+ $this->_storage->plugin_version = $plugin_version;
614
+
615
+ if ( empty( $this->_storage->plugin_last_version ) ||
616
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
617
+ ) {
618
+ $this->_storage->plugin_upgrade_mode = true;
619
+ $this->_storage->plugin_downgrade_mode = false;
620
+ } else {
621
+ $this->_storage->plugin_downgrade_mode = true;
622
+ $this->_storage->plugin_upgrade_mode = false;
623
+ }
624
+
625
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
626
+ // Different version of the plugin was installed before, therefore it's an update.
627
+ $this->_storage->is_plugin_new_install = false;
628
+ }
629
+
630
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
631
+ }
632
+ }
633
+
634
+ #--------------------------------------------------------------------------------
635
+ #region Data Migration on SDK Update
636
+ #--------------------------------------------------------------------------------
637
+
638
+ /**
639
+ * @author Vova Feldman (@svovaf)
640
+ * @since 1.1.5
641
+ *
642
+ * @param string $sdk_prev_version
643
+ * @param string $sdk_version
644
+ */
645
+ function _sdk_version_update( $sdk_prev_version, $sdk_version ) {
646
+ /**
647
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
648
+ */
649
+ if ( empty( $sdk_prev_version ) ) {
650
+ return;
651
+ }
652
+
653
+ if ( version_compare( $sdk_prev_version, '2.1.0', '<' ) &&
654
+ version_compare( $sdk_version, '2.1.0', '>=' )
655
+ ) {
656
+ $this->_storage->handle_gdpr_admin_notice = true;
657
+ }
658
+
659
+ if ( version_compare( $sdk_prev_version, '2.0.0', '<' ) &&
660
+ version_compare( $sdk_version, '2.0.0', '>=' )
661
+ ) {
662
+ $this->migrate_to_subscriptions_collection();
663
+
664
+ $this->consolidate_licenses();
665
+
666
+ // Clear trial_plan since it's now loaded from the plans collection when needed.
667
+ $this->_storage->remove( 'trial_plan', true, false );
668
+ }
669
+
670
+ if ( version_compare( $sdk_prev_version, '1.2.3', '<' ) &&
671
+ version_compare( $sdk_version, '1.2.3', '>=' )
672
+ ) {
673
+ /**
674
+ * Starting from version 1.2.3, paths are stored as relative paths and not absolute paths; so when upgrading to 1.2.3, make paths relative.
675
+ *
676
+ * @author Leo Fajardo (@leorw)
677
+ */
678
+ $this->make_paths_relative();
679
+ }
680
+
681
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
682
+ version_compare( $sdk_version, '1.1.5', '>=' )
683
+ ) {
684
+ // On version 1.1.5 merged connectivity and is_on data.
685
+ if ( isset( $this->_storage->connectivity_test ) ) {
686
+ if ( ! isset( $this->_storage->is_on ) ) {
687
+ unset( $this->_storage->connectivity_test );
688
+ } else {
689
+ $connectivity_data = $this->_storage->connectivity_test;
690
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
691
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
692
+
693
+ // Override.
694
+ $this->_storage->connectivity_test = $connectivity_data;
695
+
696
+ // Remove previous structure.
697
+ unset( $this->_storage->is_on );
698
+ }
699
+
700
+ }
701
+ }
702
+ }
703
+
704
+ /**
705
+ * @author Leo Fajardo (@leorw)
706
+ * @since 2.0.0
707
+ *
708
+ * @param \FS_Storage $storage
709
+ * @param bool|int|null $blog_id
710
+ */
711
+ private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
712
+ if ( empty( $storage->sdk_version ) ) {
713
+ // New installation of the plugin, no need to upgrade.
714
+ return;
715
+ }
716
+
717
+ if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
718
+ // Previous version is >= 2.0.0, so no need to migrate.
719
+ return;
720
+ }
721
+
722
+ // Alias.
723
+ $module_type = $storage->get_module_type();
724
+ $module_slug = $storage->get_module_slug();
725
+
726
+ $installs = self::get_all_sites( $module_type, $blog_id );
727
+ $install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
728
+
729
+ if ( ! is_object( $install ) ) {
730
+ return;
731
+ }
732
+
733
+ if ( isset( $install->plan ) && is_object( $install->plan ) ) {
734
+ if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
735
+ $install->plan_id = self::_decrypt( $install->plan->id );
736
+ }
737
+
738
+ unset( $install->plan );
739
+
740
+ $installs[ $module_slug ] = clone $install;
741
+
742
+ self::set_account_option_by_module(
743
+ $module_type,
744
+ 'sites',
745
+ $installs,
746
+ true,
747
+ $blog_id
748
+ );
749
+ }
750
+ }
751
+
752
+ /**
753
+ * @author Leo Fajardo (@leorw)
754
+ * @since 2.0.0
755
+ */
756
+ private function migrate_to_subscriptions_collection() {
757
+ if ( ! is_object( $this->_site ) ) {
758
+ return;
759
+ }
760
+
761
+ if ( isset( $this->_storage->subscription ) && is_object( $this->_storage->subscription ) ) {
762
+ $this->_storage->subscriptions = array( $this->_storage->subscription );
763
+ }
764
+ }
765
+
766
+ /**
767
+ * @author Leo Fajardo (@leorw)
768
+ * @since 2.0.0
769
+ */
770
+ private function consolidate_licenses() {
771
+ $plugin_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_PLUGIN );
772
+ if ( isset( $plugin_licenses[ $this->_slug ] ) ) {
773
+ $plugin_licenses = $plugin_licenses[ $this->_slug ];
774
+ } else {
775
+ $plugin_licenses = array();
776
+ }
777
+
778
+ $theme_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_THEME );
779
+ if ( isset( $theme_licenses[ $this->_slug ] ) ) {
780
+ $theme_licenses = $theme_licenses[ $this->_slug ];
781
+ } else {
782
+ $theme_licenses = array();
783
+ }
784
+
785
+ if ( empty( $plugin_licenses ) && empty( $theme_licenses ) ) {
786
+ return;
787
+ }
788
+
789
+ $all_licenses = array();
790
+ $user_id_license_ids_map = array();
791
+
792
+ foreach ( $plugin_licenses as $user_id => $user_licenses ) {
793
+ if ( is_array( $user_licenses ) ) {
794
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
795
+ $user_id_license_ids_map[ $user_id ] = array();
796
+ }
797
+
798
+ foreach ( $user_licenses as $user_license ) {
799
+ $all_licenses[] = $user_license;
800
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
801
+ }
802
+ }
803
+ }
804
+
805
+ foreach ( $theme_licenses as $user_id => $user_licenses ) {
806
+ if ( is_array( $user_licenses ) ) {
807
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
808
+ $user_id_license_ids_map[ $user_id ] = array();
809
+ }
810
+
811
+ foreach ( $user_licenses as $user_license ) {
812
+ $all_licenses[] = $user_license;
813
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
814
+ }
815
+ }
816
+ }
817
+
818
+ self::store_user_id_license_ids_map(
819
+ $user_id_license_ids_map,
820
+ $this->_module_id
821
+ );
822
+
823
+ $this->_store_licenses( true, $this->_module_id, $all_licenses );
824
+ }
825
+
826
+ /**
827
+ * Makes paths relative.
828
+ *
829
+ * @author Leo Fajardo (@leorw)
830
+ * @since 1.2.3
831
+ */
832
+ private function make_paths_relative() {
833
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
834
+
835
+ if ( isset( $id_slug_type_path_map[ $this->_module_id ]['path'] ) ) {
836
+ $id_slug_type_path_map[ $this->_module_id ]['path'] = $this->get_relative_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
837
+
838
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
839
+ }
840
+
841
+ if ( isset( $this->_storage->plugin_main_file ) ) {
842
+ $plugin_main_file = $this->_storage->plugin_main_file;
843
+
844
+ if ( isset( $plugin_main_file->path ) ) {
845
+ $this->_storage->plugin_main_file->path = $this->get_relative_path( $this->_storage->plugin_main_file->path );
846
+ } else if ( isset( $plugin_main_file->prev_path ) ) {
847
+ $this->_storage->plugin_main_file->prev_path = $this->get_relative_path( $this->_storage->plugin_main_file->prev_path );
848
+ }
849
+ }
850
+
851
+ // Remove invalid path that is still associated with the current slug if there's any.
852
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
853
+ foreach ( $file_slug_map as $plugin_basename => $slug ) {
854
+ if ( $slug === $this->_slug &&
855
+ $plugin_basename !== $this->_plugin_basename &&
856
+ ! file_exists( $this->get_absolute_path( $plugin_basename ) )
857
+ ) {
858
+ unset( $file_slug_map[ $plugin_basename ] );
859
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
860
+
861
+ break;
862
+ }
863
+ }
864
+ }
865
+
866
+ /**
867
+ * @author Vova Feldman (@svovaf)
868
+ * @since 1.2.2.7
869
+ *
870
+ * @param string $plugin_prev_version
871
+ * @param string $plugin_version
872
+ */
873
+ function _after_version_update( $plugin_prev_version, $plugin_version ) {
874
+ if ( $this->is_theme() ) {
875
+ // Expire the cache of the previous tabs since the theme may
876
+ // have setting updates.
877
+ $this->_cache->expire( 'tabs' );
878
+ $this->_cache->expire( 'tabs_stylesheets' );
879
+ }
880
+ }
881
+
882
+ /**
883
+ * A special migration logic for the $_accounts, executed for all the plugins in the system:
884
+ * - Moves some data to the network level storage.
885
+ * - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
886
+ * - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
887
+ * - If the plugin was connected to all sites by the same super-admin, set the plugin as if was network opted-in for all sites.
888
+ * - If there's at least one site that was connected by a super-admin, find the "main super-admin" (the one that installed the majority of the plugin installs) and set the plugin as if was network activated with the main super-admin, set all the sites that were skipped or opted-in with a different user to delegated mode. Then, prompt the currently logged super-admin to choose what to do with the ignored sites.
889
+ * - If there are any sites in the network which the connection decision was not yet taken for, set this plugin into network activation mode so a super-admin can choose what to do with the rest of the sites.
890
+ *
891
+ * @author Vova Feldman (@svovaf)
892
+ * @since 2.0.0
893
+ */
894
+ private static function migrate_accounts_to_network() {
895
+ $sites = self::get_sites();
896
+ $sites_count = count( $sites );
897
+ $connection_status = array();
898
+ $plugin_slugs = array();
899
+ foreach ( $sites as $site ) {
900
+ $blog_id = self::get_site_blog_id( $site );
901
+
902
+ self::$_accounts->migrate_to_network( $blog_id );
903
+
904
+ /**
905
+ * Build a list of all Freemius powered plugins slugs.
906
+ */
907
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
908
+ foreach ( $id_slug_type_path_map as $module_id => $data ) {
909
+ if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
910
+ $plugin_slugs[ $data['slug'] ] = true;
911
+ }
912
+ }
913
+
914
+ $installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
915
+
916
+ if ( is_array( $installs ) ) {
917
+ foreach ( $installs as $slug => $install ) {
918
+ if ( ! isset( $connection_status[ $slug ] ) ) {
919
+ $connection_status[ $slug ] = array();
920
+ }
921
+
922
+ if ( is_object( $install ) &&
923
+ FS_Site::is_valid_id( $install->id ) &&
924
+ FS_User::is_valid_id( $install->user_id )
925
+ ) {
926
+ $connection_status[ $slug ][ $blog_id ] = $install->user_id;
927
+ }
928
+ }
929
+ }
930
+ }
931
+
932
+ foreach ( $plugin_slugs as $slug => $true ) {
933
+ if ( ! isset( $connection_status[ $slug ] ) ) {
934
+ $connection_status[ $slug ] = array();
935
+ }
936
+
937
+ foreach ( $sites as $site ) {
938
+ $blog_id = self::get_site_blog_id( $site );
939
+
940
+ if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
941
+ continue;
942
+ }
943
+
944
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
945
+
946
+ $is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
947
+
948
+ if ( ! is_null( $is_anonymous ) ) {
949
+ // Since 1.1.3 is_anonymous is an array.
950
+ if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
951
+ $is_anonymous = $is_anonymous['is'];
952
+ }
953
+
954
+ if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
955
+ $connection_status[ $slug ][ $blog_id ] = 'skipped';
956
+ }
957
+ }
958
+
959
+ if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
960
+ $connection_status[ $slug ][ $blog_id ] = 'ignored';
961
+ }
962
+ }
963
+ }
964
+
965
+ $super_admins = array();
966
+
967
+ foreach ( $connection_status as $slug => $blogs_status ) {
968
+ $skips = 0;
969
+ $ignores = 0;
970
+ $connections = 0;
971
+ $opted_in_users = array();
972
+ $opted_in_super_admins = array();
973
+
974
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
975
+
976
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
977
+ if ( 'skipped' === $status_or_user_id ) {
978
+ $skips ++;
979
+ } else if ( 'ignored' === $status_or_user_id ) {
980
+ $ignores ++;
981
+ } else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
982
+ $connections ++;
983
+
984
+ if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
985
+ $opted_in_users[ $status_or_user_id ] = array();
986
+ }
987
+
988
+ $opted_in_users[ $status_or_user_id ][] = $blog_id;
989
+
990
+ if ( isset( $super_admins[ $status_or_user_id ] ) ||
991
+ self::is_super_admin( $status_or_user_id )
992
+ ) {
993
+ // Cache super-admin data.
994
+ $super_admins[ $status_or_user_id ] = true;
995
+
996
+ // Remember opted-in super-admins for the plugin.
997
+ $opted_in_super_admins[ $status_or_user_id ] = true;
998
+ }
999
+ }
1000
+ }
1001
+
1002
+ $main_super_admin_user_id = null;
1003
+ $all_migrated = false;
1004
+ if ( $sites_count == $skips ) {
1005
+ // All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
1006
+ $storage->is_anonymous_ms = $storage->is_anonymous;
1007
+
1008
+ $all_migrated = true;
1009
+ } else if ( $sites_count == $ignores ) {
1010
+ // Don't do anything, still in activation mode.
1011
+
1012
+ $all_migrated = true;
1013
+ } else if ( 0 < count( $opted_in_super_admins ) ) {
1014
+ // Find the super-admin with the majority of installs.
1015
+ $max_installs_by_super_admin = 0;
1016
+ foreach ( $opted_in_super_admins as $user_id => $true ) {
1017
+ $installs_count = count( $opted_in_users[ $user_id ] );
1018
+
1019
+ if ( $installs_count > $max_installs_by_super_admin ) {
1020
+ $max_installs_by_super_admin = $installs_count;
1021
+ $main_super_admin_user_id = $user_id;
1022
+ }
1023
+ }
1024
+
1025
+ if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
1026
+ // Super-admin opted-in for all sites in the network.
1027
+ $storage->is_network_connected = true;
1028
+
1029
+ $all_migrated = true;
1030
+ }
1031
+
1032
+ // Store network user.
1033
+ $storage->network_user_id = $main_super_admin_user_id;
1034
+
1035
+ $storage->network_install_blog_id = ( $sites_count == $connections ) ?
1036
+ // Since all sites are opted-in, associating with the main site.
1037
+ get_current_blog_id() :
1038
+ // Associating with the 1st found opted-in site.
1039
+ $opted_in_users[ $main_super_admin_user_id ][0];
1040
+
1041
+ /**
1042
+ * Make sure we migrate the plan ID of the network install, otherwise, if after the migration
1043
+ * the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
1044
+ * is different than the main site of the network, the $this->_site will not be set since the plan_id
1045
+ * will be empty.
1046
+ */
1047
+ $storage->migrate_to_network();
1048
+ self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
1049
+ } else {
1050
+ // At least one opt-in. All the opt-in were created by a non-super-admin.
1051
+ if ( 0 == $ignores ) {
1052
+ // All sites were opted-in or skipped, all by non-super-admin. So delegate all.
1053
+ $storage->store( 'is_delegated_connection', true, true );
1054
+
1055
+ $all_migrated = true;
1056
+ }
1057
+ }
1058
+
1059
+ if ( ! $all_migrated ) {
1060
+ /**
1061
+ * Delegate all sites that were:
1062
+ * 1) Opted-in by a user that is NOT the main-super-admin.
1063
+ * 2) Skipped and non of the sites was opted-in by a super-admin. If any site was opted-in by a super-admin, there will be a main-super-admin, and we consider the skip as if it was done by that user.
1064
+ */
1065
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1066
+ if ( $status_or_user_id == $main_super_admin_user_id ) {
1067
+ continue;
1068
+ }
1069
+
1070
+ if ( FS_User::is_valid_id( $status_or_user_id ) ||
1071
+ ( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
1072
+ ) {
1073
+ $storage->store( 'is_delegated_connection', true, $blog_id );
1074
+ }
1075
+ }
1076
+ }
1077
+
1078
+
1079
+ if ( ( $connections + $skips > 0 ) ) {
1080
+ if ( $ignores > 0 ) {
1081
+ /**
1082
+ * If admin already opted-in or skipped in any of the network sites, and also
1083
+ * have sites which the connection decision was not yet taken, set this plugin
1084
+ * into network activation mode so the super-admin can choose what to do with
1085
+ * the rest of the sites.
1086
+ */
1087
+ self::set_network_upgrade_mode( $storage );
1088
+ }
1089
+ }
1090
+ }
1091
+ }
1092
+
1093
+ /**
1094
+ * Set a module into network upgrade mode.
1095
+ *
1096
+ * @author Vova Feldman (@svovaf)
1097
+ * @since 2.0.0
1098
+ *
1099
+ * @param \FS_Storage $storage
1100
+ *
1101
+ * @return bool
1102
+ */
1103
+ private static function set_network_upgrade_mode( FS_Storage $storage ) {
1104
+ return $storage->is_network_activation = true;
1105
+ }
1106
+
1107
+ /**
1108
+ * Will return true after upgrading to the SDK with the network level integration,
1109
+ * when the super-admin involvement is required regarding the rest of the sites.
1110
+ *
1111
+ * @author Vova Feldman (@svovaf)
1112
+ * @since 2.0.0
1113
+ *
1114
+ * @return bool
1115
+ */
1116
+ function is_network_upgrade_mode() {
1117
+ return $this->_storage->get( 'is_network_activation' );
1118
+ }
1119
+
1120
+ /**
1121
+ * Clear flag after the upgrade mode completion.
1122
+ *
1123
+ * @author Vova Feldman (@svovaf)
1124
+ * @since 2.0.0
1125
+ *
1126
+ * @return bool True if network activation was on and now completed.
1127
+ */
1128
+ private function network_upgrade_mode_completed() {
1129
+ if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
1130
+ $this->_storage->remove( 'is_network_activation' );
1131
+
1132
+ return true;
1133
+ }
1134
+
1135
+ return false;
1136
+ }
1137
+
1138
+ #endregion
1139
+
1140
+ /**
1141
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
1142
+ * if this is a new plugin installation or a plugin update.
1143
+ *
1144
+ * There are 3 different use-cases:
1145
+ * 1) New plugin installation right with Freemius:
1146
+ * 1.1 _activate_plugin_event_hook() will be executed first
1147
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
1148
+ * and $this->_storage->plugin_last_version is not set,
1149
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
1150
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1151
+ * be already set to TRUE.
1152
+ *
1153
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
1154
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
1155
+ * the activation hook do NOT fires on updates since WP 3.1.
1156
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1157
+ * be empty, therefore, it will be set to FALSE.
1158
+ *
1159
+ * 3) Plugin update, had Freemius in prev version as well:
1160
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
1161
+ * before, $this->_storage->plugin_last_version will NOT be empty,
1162
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
1163
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
1164
+ * already set, therefore, it will not be modified.
1165
+ *
1166
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
1167
+ *
1168
+ * NOTE:
1169
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
1170
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
1171
+ * show the opt-in right away. The reason it will happen is because Freemius execution
1172
+ * will be turned off till the plugin is fully loaded at least once
1173
+ * (till $this->_storage->was_plugin_loaded is TRUE).
1174
+ *
1175
+ * @author Vova Feldman (@svovaf)
1176
+ * @since 1.1.9
1177
+ *
1178
+ */
1179
+ function _plugins_loaded() {
1180
+ // Update flag that plugin was loaded with Freemius at least once.
1181
+ $this->_storage->was_plugin_loaded = true;
1182
+
1183
+ /**
1184
+ * Bug fix - only set to false when it's a plugin, due to the
1185
+ * execution sequence of the theme hooks and our methods, if
1186
+ * this will be set for themes, Freemius will always assume
1187
+ * it's a theme update.
1188
+ *
1189
+ * @author Vova Feldman (@svovaf)
1190
+ * @since 1.2.2.2
1191
+ */
1192
+ if ( $this->is_plugin() &&
1193
+ ! isset( $this->_storage->is_plugin_new_install )
1194
+ ) {
1195
+ $this->_storage->is_plugin_new_install = false;
1196
+ }
1197
+ }
1198
+
1199
+ /**
1200
+ * Add special parameter to WP admin AJAX calls so when we
1201
+ * process AJAX calls we can identify its source properly.
1202
+ *
1203
+ * @author Leo Fajardo (@leorw)
1204
+ * @since 2.0.0
1205
+ */
1206
+ static function _enrich_ajax_url() {
1207
+ $admin_param = is_network_admin() ?
1208
+ '_fs_network_admin' :
1209
+ '_fs_blog_admin';
1210
+ ?>
1211
+ <script type="text/javascript">
1212
+ (function ($) {
1213
+ $(document).ajaxSend(function (event, jqxhr, settings) {
1214
+ if (settings.url &&
1215
+ -1 < settings.url.indexOf('admin-ajax.php') &&
1216
+ ! ( settings.url.indexOf( '<?php echo $admin_param ?>' ) > 0 )
1217
+ ) {
1218
+ if (settings.url.indexOf('?') > 0) {
1219
+ settings.url += '&';
1220
+ } else {
1221
+ settings.url += '?';
1222
+ }
1223
+
1224
+ settings.url += '<?php echo $admin_param ?>=true';
1225
+
1226
+ }
1227
+ });
1228
+ })(jQuery);
1229
+ </script>
1230
+ <?php
1231
+ }
1232
+
1233
+ /**
1234
+ * @author Vova Feldman (@svovaf)
1235
+ * @since 1.0.9
1236
+ */
1237
+ private function _register_hooks() {
1238
+ $this->_logger->entrance();
1239
+
1240
+ if ( is_admin() ) {
1241
+ add_action( 'plugins_loaded', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
1242
+
1243
+ if ( $this->is_plugin() ) {
1244
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
1245
+
1246
+ /**
1247
+ * @since 1.2.2
1248
+ *
1249
+ * Hook to both free and premium version activations to support
1250
+ * auto deactivation on the other version activation.
1251
+ */
1252
+ register_activation_hook(
1253
+ $plugin_dir . $this->_free_plugin_basename,
1254
+ array( &$this, '_activate_plugin_event_hook' )
1255
+ );
1256
+
1257
+ register_activation_hook(
1258
+ $plugin_dir . $this->premium_plugin_basename(),
1259
+ array( &$this, '_activate_plugin_event_hook' )
1260
+ );
1261
+ } else {
1262
+ add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
1263
+
1264
+ /**
1265
+ * Include the required hooks to capture the theme settings' page tabs
1266
+ * and cache them.
1267
+ *
1268
+ * @author Vova Feldman (@svovaf)
1269
+ * @since 1.2.2.7
1270
+ */
1271
+ if ( ! $this->_cache->has_valid( 'tabs' ) ) {
1272
+ add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
1273
+ // Add license activation AJAX callback.
1274
+ $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
1275
+
1276
+ add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
1277
+ }
1278
+
1279
+ add_action(
1280
+ 'admin_footer',
1281
+ array( &$this, '_add_freemius_tabs' ),
1282
+ /**
1283
+ * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
1284
+ * That's why the priority is 11 while the tabs capture logic is added
1285
+ * with priority 10.
1286
+ *
1287
+ * @author Vova Feldman (@svovaf)
1288
+ */
1289
+ 11
1290
+ );
1291
+
1292
+ add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
1293
+ }
1294
+
1295
+ /**
1296
+ * Part of the mechanism to identify new plugin install vs. plugin update.
1297
+ *
1298
+ * @author Vova Feldman (@svovaf)
1299
+ * @since 1.1.9
1300
+ */
1301
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
1302
+ /**
1303
+ * During the plugin activation (not theme), 'plugins_loaded' will be already executed
1304
+ * when the logic gets here since the activation logic first add the activate plugins,
1305
+ * then triggers 'plugins_loaded', and only then include the code of the plugin that
1306
+ * is activated. Which means that _plugins_loaded() will NOT be executed during the
1307
+ * plugin activation, and that IS intentional.
1308
+ *
1309
+ * @author Vova Feldman (@svovaf)
1310
+ */
1311
+ if ( $this->is_plugin() && $this->is_activation_mode( false ) ) {
1312
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
1313
+ } else {
1314
+ // If was activated before, then it was already loaded before.
1315
+ $this->_plugins_loaded();
1316
+ }
1317
+ }
1318
+
1319
+ if ( ! self::is_ajax() ) {
1320
+ if ( ! $this->is_addon() ) {
1321
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
1322
+ }
1323
+ }
1324
+
1325
+ if ( $this->_storage->handle_gdpr_admin_notice ) {
1326
+ add_action( 'init', array( &$this, '_maybe_show_gdpr_admin_notice' ) );
1327
+ }
1328
+
1329
+ add_action( 'init', array( &$this, '_maybe_add_gdpr_optin_ajax_handler') );
1330
+ }
1331
+
1332
+ if ( $this->is_plugin() ) {
1333
+ if ( $this->_is_network_active ) {
1334
+ add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
1335
+ }
1336
+
1337
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
1338
+ }
1339
+
1340
+ if ( is_multisite() ) {
1341
+ add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
1342
+ add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
1343
+ add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
1344
+ add_action( 'deleted_blog', array( &$this, '_after_site_deleted_callback' ), 10, 2 );
1345
+
1346
+ add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
1347
+ add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
1348
+ add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
1349
+ }
1350
+
1351
+ if ( $this->is_theme() && self::is_customizer() ) {
1352
+ // Register customizer upsell.
1353
+ add_action( 'customize_register', array( &$this, '_customizer_register' ) );
1354
+ }
1355
+
1356
+ add_action( 'admin_init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
1357
+
1358
+ if ( $this->is_theme() ) {
1359
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1360
+ }
1361
+
1362
+ add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
1363
+ add_action( 'admin_init', array( &$this, '_add_premium_version_upgrade_selection' ) );
1364
+
1365
+ $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
1366
+ $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
1367
+
1368
+ if ( $this->_is_network_active && fs_is_network_admin() ) {
1369
+ $this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
1370
+ }
1371
+
1372
+ $this->add_ajax_action( 'install_premium_version', array(
1373
+ &$this,
1374
+ '_install_premium_version_ajax_action'
1375
+ ) );
1376
+
1377
+ $this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
1378
+
1379
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
1380
+
1381
+ $this->add_action( 'sdk_version_update', array( &$this, '_sdk_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
1382
+
1383
+ $this->add_action(
1384
+ 'plugin_version_update',
1385
+ array( &$this, '_after_version_update' ),
1386
+ WP_FS__DEFAULT_PRIORITY,
1387
+ 2
1388
+ );
1389
+ $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
1390
+
1391
+ add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
1392
+ add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
1393
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_common_css' ) );
1394
+
1395
+ /**
1396
+ * Handle request to reset anonymous mode for `get_reconnect_url()`.
1397
+ *
1398
+ * @author Vova Feldman (@svovaf)
1399
+ * @since 1.2.1.5
1400
+ */
1401
+ if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
1402
+ $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
1403
+ ) {
1404
+ add_action( 'admin_init', array( &$this, 'connect_again' ) );
1405
+ }
1406
+ }
1407
+
1408
+ /**
1409
+ * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
1410
+ * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
1411
+ * plugin will trigger inclusion of the free or premium version and if one of them is active during the
1412
+ * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
1413
+ *
1414
+ * @author Leo Fajardo (@leorw)
1415
+ *
1416
+ * @since 1.2.0
1417
+ */
1418
+ private function unregister_uninstall_hook() {
1419
+ $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
1420
+ unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
1421
+ unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
1422
+
1423
+ update_option( 'uninstall_plugins', $uninstallable_plugins );
1424
+ }
1425
+
1426
+ /**
1427
+ * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
1428
+ */
1429
+ private function clear_module_main_file_cache() {
1430
+ if ( ! isset( $this->_storage->plugin_main_file ) ||
1431
+ empty( $this->_storage->plugin_main_file->path )
1432
+ ) {
1433
+ return;
1434
+ }
1435
+
1436
+ $plugin_main_file = clone $this->_storage->plugin_main_file;
1437
+
1438
+ // Store cached path (2nd layer cache).
1439
+ $plugin_main_file->prev_path = $plugin_main_file->path;
1440
+
1441
+ // Clear cached path.
1442
+ unset( $plugin_main_file->path );
1443
+
1444
+ $this->_storage->plugin_main_file = $plugin_main_file;
1445
+
1446
+ /**
1447
+ * Clear global cached path.
1448
+ *
1449
+ * @author Leo Fajardo (@leorw)
1450
+ * @since 1.2.2
1451
+ */
1452
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
1453
+ unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
1454
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
1455
+ }
1456
+
1457
+ /**
1458
+ * @author Leo Fajardo (@leorw)
1459
+ * @since 2.0.0
1460
+ */
1461
+ function _hook_action_links_and_register_account_hooks() {
1462
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1463
+
1464
+ if ( self::is_plugins_page() && $this->is_plugin() ) {
1465
+ $this->hook_plugin_action_links();
1466
+ }
1467
+
1468
+ $this->_register_account_hooks();
1469
+ }
1470
+
1471
+ /**
1472
+ * @author Vova Feldman (@svovaf)
1473
+ * @since 1.0.9
1474
+ */
1475
+ private function _register_account_hooks() {
1476
+ if ( ! is_admin() ) {
1477
+ return;
1478
+ }
1479
+
1480
+ /**
1481
+ * Always show the deactivation feedback form since we added
1482
+ * automatic free version deactivation upon premium code activation.
1483
+ *
1484
+ * @since 1.2.1.6
1485
+ */
1486
+ $this->add_ajax_action(
1487
+ 'submit_uninstall_reason',
1488
+ array( &$this, '_submit_uninstall_reason_action' )
1489
+ );
1490
+
1491
+ if ( $this->is_theme() && $this->is_premium() && ! $this->has_active_valid_license() ) {
1492
+ $this->add_ajax_action(
1493
+ 'delete_theme_update_data',
1494
+ array( &$this, '_delete_theme_update_data_action' )
1495
+ );
1496
+ }
1497
+
1498
+ if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
1499
+ if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
1500
+ ( $this->is_theme() && self::is_themes_page() )
1501
+ ) {
1502
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
1503
+ }
1504
+ }
1505
+ }
1506
+
1507
+ /**
1508
+ * Leverage backtrace to find caller plugin file path.
1509
+ *
1510
+ * @author Vova Feldman (@svovaf)
1511
+ * @since 1.0.6
1512
+ *
1513
+ * @param bool $is_init Is initiation sequence.
1514
+ *
1515
+ * @return string
1516
+ */
1517
+ private function _find_caller_plugin_file( $is_init = false ) {
1518
+ // Try to load the cached value of the file path.
1519
+ if ( isset( $this->_storage->plugin_main_file ) ) {
1520
+ $plugin_main_file = $this->_storage->plugin_main_file;
1521
+ if ( isset( $plugin_main_file->path ) ) {
1522
+ $absolute_path = $this->get_absolute_path( $plugin_main_file->path );
1523
+ if ( file_exists( $absolute_path ) ) {
1524
+ return $absolute_path;
1525
+ }
1526
+ }
1527
+ }
1528
+
1529
+ /**
1530
+ * @since 1.2.1
1531
+ *
1532
+ * `clear_module_main_file_cache()` is clearing the plugin's cached path on
1533
+ * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
1534
+ * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
1535
+ *
1536
+ * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
1537
+ * when the class instantiator isn't the module.
1538
+ */
1539
+ if ( ! $is_init ) {
1540
+ // Fetch prev path cache.
1541
+ if ( isset( $this->_storage->plugin_main_file ) &&
1542
+ isset( $this->_storage->plugin_main_file->prev_path )
1543
+ ) {
1544
+ $absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
1545
+ if ( file_exists( $absolute_path ) ) {
1546
+ return $absolute_path;
1547
+ }
1548
+ }
1549
+
1550
+ wp_die(
1551
+ $this->get_text_inline( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'failed-finding-main-path' ) .
1552
+ " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
1553
+ $this->get_text_inline( 'Error', 'error' ),
1554
+ array( 'back_link' => true )
1555
+ );
1556
+ }
1557
+
1558
+ /**
1559
+ * @since 1.2.1
1560
+ *
1561
+ * Only the original instantiator that calls dynamic_init can modify the module's path.
1562
+ */
1563
+ // Find caller module.
1564
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
1565
+ $this->_storage->plugin_main_file = (object) array(
1566
+ 'path' => $id_slug_type_path_map[ $this->_module_id ]['path'],
1567
+ );
1568
+
1569
+ return $this->get_absolute_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
1570
+ }
1571
+
1572
+ /**
1573
+ * @author Leo Fajardo (@leorw)
1574
+ * @since 1.2.3
1575
+ *
1576
+ * @param string $path
1577
+ *
1578
+ * @return string
1579
+ */
1580
+ private function get_relative_path( $path ) {
1581
+ $module_root_dir = $this->get_module_root_dir_path();
1582
+ if ( 0 === strpos( $path, $module_root_dir ) ) {
1583
+ $path = substr( $path, strlen( $module_root_dir ) );
1584
+ }
1585
+
1586
+ return $path;
1587
+ }
1588
+
1589
+ /**
1590
+ * @author Leo Fajardo (@leorw)
1591
+ * @since 1.2.3
1592
+ *
1593
+ * @param string $path
1594
+ * @param string|bool $module_type
1595
+ *
1596
+ * @return string
1597
+ */
1598
+ private function get_absolute_path( $path, $module_type = false ) {
1599
+ $module_root_dir = $this->get_module_root_dir_path( $module_type );
1600
+ if ( 0 !== strpos( $path, $module_root_dir ) ) {
1601
+ $path = fs_normalize_path( $module_root_dir . $path );
1602
+ }
1603
+
1604
+ return $path;
1605
+ }
1606
+
1607
+ /**
1608
+ * @author Leo Fajardo (@leorw)
1609
+ * @since 1.2.3
1610
+ *
1611
+ * @param string|bool $module_type
1612
+ *
1613
+ * @return string
1614
+ */
1615
+ private function get_module_root_dir_path( $module_type = false ) {
1616
+ $is_plugin = empty( $module_type ) ?
1617
+ $this->is_plugin() :
1618
+ ( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
1619
+
1620
+ return fs_normalize_path( trailingslashit( $is_plugin ?
1621
+ WP_PLUGIN_DIR :
1622
+ get_theme_root() ) );
1623
+ }
1624
+
1625
+ /**
1626
+ * @author Leo Fajardo (@leorw)
1627
+ *
1628
+ * @param number $module_id
1629
+ * @param string $slug
1630
+ *
1631
+ * @since 1.2.2
1632
+ */
1633
+ private function store_id_slug_type_path_map( $module_id, $slug ) {
1634
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
1635
+
1636
+ $store_option = false;
1637
+
1638
+ if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
1639
+ $id_slug_type_path_map[ $module_id ] = array(
1640
+ 'slug' => $slug
1641
+ );
1642
+
1643
+ $store_option = true;
1644
+ }
1645
+
1646
+ if ( ! isset( $id_slug_type_path_map[ $module_id ]['path'] ) ||
1647
+ /**
1648
+ * This verification is for cases when suddenly the same module
1649
+ * is installed but with a different folder name.
1650
+ *
1651
+ * @author Vova Feldman (@svovaf)
1652
+ * @since 1.2.3
1653
+ */
1654
+ ! file_exists( $this->get_absolute_path(
1655
+ $id_slug_type_path_map[ $module_id ]['path'],
1656
+ $id_slug_type_path_map[ $module_id ]['type']
1657
+ ) )
1658
+ ) {
1659
+ $caller_main_file_and_type = $this->get_caller_main_file_and_type();
1660
+
1661
+ $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
1662
+ $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
1663
+
1664
+ $store_option = true;
1665
+ }
1666
+
1667
+ if ( $store_option ) {
1668
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
1669
+ }
1670
+ }
1671
+
1672
+ /**
1673
+ * Identifies the caller type: plugin or theme.
1674
+ *
1675
+ * @author Leo Fajardo (@leorw)
1676
+ * @since 1.2.2
1677
+ *
1678
+ * @author Vova Feldman (@svovaf)
1679
+ * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
1680
+ * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
1681
+ * SDK an internal file instead of directly from functions.php.
1682
+ * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
1683
+ */
1684
+ private function get_caller_main_file_and_type() {
1685
+ self::require_plugin_essentials();
1686
+
1687
+ $all_plugins = get_plugins();
1688
+ $all_plugins_paths = array();
1689
+
1690
+ // Get active plugin's main files real full names (might be symlinks).
1691
+ foreach ( $all_plugins as $relative_path => &$data ) {
1692
+ if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
1693
+ /**
1694
+ * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
1695
+ * can't really include the SDK.
1696
+ *
1697
+ * @author Vova Feldman
1698
+ * @since 1.2.1.7
1699
+ */
1700
+ continue;
1701
+ }
1702
+
1703
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
1704
+ }
1705
+
1706
+ $caller_file_candidate = false;
1707
+ $caller_map = array();
1708
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1709
+ $themes_dir = fs_normalize_path( get_theme_root() );
1710
+
1711
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
1712
+ if ( empty( $bt[ $i ]['file'] ) ) {
1713
+ continue;
1714
+ }
1715
+
1716
+ if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
1717
+ // If file same as the prev file in the stack, skip it.
1718
+ continue;
1719
+ }
1720
+
1721
+ if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
1722
+ 'do_action',
1723
+ 'apply_filter',
1724
+ // The string split is stupid, but otherwise, theme check
1725
+ // throws info notices.
1726
+ 'requir' . 'e_once',
1727
+ 'requir' . 'e',
1728
+ 'includ' . 'e_once',
1729
+ 'includ' . 'e'
1730
+ ) )
1731
+ ) {
1732
+ // Ignore call stack hooks and files inclusion.
1733
+ continue;
1734
+ }
1735
+
1736
+ $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
1737
+
1738
+ if ( 'functions.php' === basename( $caller_file_path ) ) {
1739
+ /**
1740
+ * 1. Assumes that theme's starting execution file is functions.php.
1741
+ * 2. This complex logic fixes symlink issues (e.g. with Vargant).
1742
+ *
1743
+ * @author Vova Feldman (@svovaf)
1744
+ * @since 1.2.2.5
1745
+ */
1746
+
1747
+ if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
1748
+ $module_type = WP_FS__MODULE_TYPE_THEME;
1749
+
1750
+ /**
1751
+ * Relative path of the theme, e.g.:
1752
+ * `my-theme/functions.php`
1753
+ *
1754
+ * @author Leo Fajardo (@leorw)
1755
+ */
1756
+ $caller_file_candidate = basename( dirname( $caller_file_path ) ) .
1757
+ '/' .
1758
+ basename( $caller_file_path );
1759
+
1760
+ continue;
1761
+ }
1762
+ }
1763
+
1764
+ $caller_file_hash = md5( $caller_file_path );
1765
+
1766
+ if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
1767
+ foreach ( $all_plugins_paths as $plugin_path ) {
1768
+ if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
1769
+ $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
1770
+ break;
1771
+ }
1772
+ }
1773
+ }
1774
+
1775
+ if ( isset( $caller_map[ $caller_file_hash ] ) ) {
1776
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1777
+ $caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
1778
+ }
1779
+ }
1780
+
1781
+ return (object) array(
1782
+ 'module_type' => $module_type,
1783
+ 'path' => $caller_file_candidate
1784
+ );
1785
+ }
1786
+
1787
+ #----------------------------------------------------------------------------------
1788
+ #region Deactivation Feedback Form
1789
+ #----------------------------------------------------------------------------------
1790
+
1791
+ /**
1792
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
1793
+ * page.
1794
+ *
1795
+ * @author Vova Feldman (@svovaf)
1796
+ * @author Leo Fajardo (@leorw)
1797
+ * @since 1.1.2
1798
+ */
1799
+ function _add_deactivation_feedback_dialog_box() {
1800
+ /* Check the type of user:
1801
+ * 1. Long-term (long-term)
1802
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
1803
+ * 3. Short-term (short-term)
1804
+ */
1805
+ $is_long_term_user = true;
1806
+
1807
+ // Check if the site is at least 2 days old.
1808
+ $time_installed = $this->_storage->install_timestamp;
1809
+
1810
+ // Difference in seconds.
1811
+ $date_diff = time() - $time_installed;
1812
+
1813
+ // Convert seconds to days.
1814
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
1815
+
1816
+ if ( $date_diff_days < 2 ) {
1817
+ $is_long_term_user = false;
1818
+ }
1819
+
1820
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
1821
+
1822
+ if ( $is_long_term_user ) {
1823
+ $user_type = 'long-term';
1824
+ } else {
1825
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
1826
+ $user_type = 'non-registered-and-non-anonymous-short-term';
1827
+ } else {
1828
+ $user_type = 'short-term';
1829
+ }
1830
+ }
1831
+
1832
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
1833
+
1834
+ // Load the HTML template for the deactivation feedback dialog box.
1835
+ $vars = array(
1836
+ 'reasons' => $uninstall_reasons,
1837
+ 'id' => $this->_module_id
1838
+ );
1839
+
1840
+ /**
1841
+ * @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.
1842
+ */
1843
+ fs_require_template( 'forms/deactivation/form.php', $vars );
1844
+ }
1845
+
1846
+ /**
1847
+ * @author Leo Fajardo (@leorw)
1848
+ * @since 1.1.2
1849
+ *
1850
+ * @param string $user_type
1851
+ *
1852
+ * @return array The uninstall reasons for the specified user type.
1853
+ */
1854
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
1855
+ $module_type = $this->_module_type;
1856
+
1857
+ $internal_message_template_var = array(
1858
+ 'id' => $this->_module_id
1859
+ );
1860
+
1861
+ $plan = $this->get_plan();
1862
+
1863
+ if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
1864
+ $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
1865
+ } else {
1866
+ $contact_support_template = '';
1867
+ }
1868
+
1869
+ $reason_found_better_plugin = array(
1870
+ 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
1871
+ 'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
1872
+ 'input_type' => 'textfield',
1873
+ 'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
1874
+ );
1875
+
1876
+ $reason_temporary_deactivation = array(
1877
+ 'id' => self::REASON_TEMPORARY_DEACTIVATION,
1878
+ 'text' => sprintf(
1879
+ $this->get_text_inline( "It's a temporary %s. I'm just debugging an issue.", 'reason-temporary-x' ),
1880
+ strtolower( $this->is_plugin() ?
1881
+ $this->get_text_inline( 'Deactivation', 'deactivation' ) :
1882
+ $this->get_text_inline( 'Theme Switch', 'theme-switch' )
1883
+ )
1884
+ ),
1885
+ 'input_type' => '',
1886
+ 'input_placeholder' => ''
1887
+ );
1888
+
1889
+ $reason_other = array(
1890
+ 'id' => self::REASON_OTHER,
1891
+ 'text' => $this->get_text_inline( 'Other', 'reason-other' ),
1892
+ 'input_type' => 'textfield',
1893
+ 'input_placeholder' => ''
1894
+ );
1895
+
1896
+ $long_term_user_reasons = array(
1897
+ array(
1898
+ 'id' => self::REASON_NO_LONGER_NEEDED,
1899
+ 'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
1900
+ 'input_type' => '',
1901
+ 'input_placeholder' => ''
1902
+ ),
1903
+ $reason_found_better_plugin,
1904
+ array(
1905
+ 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
1906
+ 'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
1907
+ 'input_type' => '',
1908
+ 'input_placeholder' => ''
1909
+ ),
1910
+ array(
1911
+ 'id' => self::REASON_BROKE_MY_SITE,
1912
+ 'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
1913
+ 'input_type' => '',
1914
+ 'input_placeholder' => '',
1915
+ 'internal_message' => $contact_support_template
1916
+ ),
1917
+ array(
1918
+ 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
1919
+ 'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
1920
+ 'input_type' => '',
1921
+ 'input_placeholder' => '',
1922
+ 'internal_message' => $contact_support_template
1923
+ )
1924
+ );
1925
+
1926
+ if ( $this->is_paying() ) {
1927
+ $long_term_user_reasons[] = array(
1928
+ 'id' => self::REASON_CANT_PAY_ANYMORE,
1929
+ 'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
1930
+ 'input_type' => 'textfield',
1931
+ 'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
1932
+ );
1933
+ }
1934
+
1935
+ $reason_dont_share_info = array(
1936
+ 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
1937
+ 'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
1938
+ 'input_type' => '',
1939
+ 'input_placeholder' => ''
1940
+ );
1941
+
1942
+ /**
1943
+ * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
1944
+ * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
1945
+ * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
1946
+ * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
1947
+ * button in the opt-in form is shown/hidden).
1948
+ */
1949
+ if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
1950
+ $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
1951
+ }
1952
+
1953
+ $uninstall_reasons = array(
1954
+ 'long-term' => $long_term_user_reasons,
1955
+ 'non-registered-and-non-anonymous-short-term' => array(
1956
+ array(
1957
+ 'id' => self::REASON_DIDNT_WORK,
1958
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
1959
+ 'input_type' => '',
1960
+ 'input_placeholder' => ''
1961
+ ),
1962
+ $reason_dont_share_info,
1963
+ $reason_found_better_plugin
1964
+ ),
1965
+ 'short-term' => array(
1966
+ array(
1967
+ 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
1968
+ 'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
1969
+ 'input_type' => '',
1970
+ 'input_placeholder' => '',
1971
+ 'internal_message' => $contact_support_template
1972
+ ),
1973
+ $reason_found_better_plugin,
1974
+ array(
1975
+ 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
1976
+ 'text' => sprintf( $this->get_text_inline( "The %s is great, but I need specific feature that you don't support", 'reason-great-but-need-specific-feature' ), $module_type ),
1977
+ 'input_type' => 'textarea',
1978
+ 'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
1979
+ ),
1980
+ array(
1981
+ 'id' => self::REASON_NOT_WORKING,
1982
+ 'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
1983
+ 'input_type' => 'textarea',
1984
+ 'input_placeholder' => $this->get_text_inline( "Kindly share what didn't work so we can fix it for future users...", 'placeholder-share-what-didnt-work' )
1985
+ ),
1986
+ array(
1987
+ 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
1988
+ 'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
1989
+ 'input_type' => 'textarea',
1990
+ 'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
1991
+ ),
1992
+ array(
1993
+ 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
1994
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
1995
+ 'input_type' => 'textarea',
1996
+ 'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
1997
+ )
1998
+ )
1999
+ );
2000
+
2001
+ // Randomize the reasons for the current user type.
2002
+ shuffle( $uninstall_reasons[ $user_type ] );
2003
+
2004
+ // Keep the following reasons as the last items in the list.
2005
+ $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
2006
+ $uninstall_reasons[ $user_type ][] = $reason_other;
2007
+
2008
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
2009
+
2010
+ return $uninstall_reasons[ $user_type ];
2011
+ }
2012
+
2013
+ /**
2014
+ * Called after the user has submitted his reason for deactivating the plugin.
2015
+ *
2016
+ * @author Leo Fajardo (@leorw)
2017
+ * @since 1.1.2
2018
+ */
2019
+ function _submit_uninstall_reason_action() {
2020
+ $this->_logger->entrance();
2021
+
2022
+ $this->check_ajax_referer( 'submit_uninstall_reason' );
2023
+
2024
+ $reason_id = fs_request_get( 'reason_id' );
2025
+
2026
+ // Check if the given reason ID is an unsigned integer.
2027
+ if ( ! ctype_digit( $reason_id ) ) {
2028
+ exit;
2029
+ }
2030
+
2031
+ $reason_info = trim( fs_request_get( 'reason_info', '' ) );
2032
+ if ( ! empty( $reason_info ) ) {
2033
+ $reason_info = substr( $reason_info, 0, 128 );
2034
+ }
2035
+
2036
+ $reason = (object) array(
2037
+ 'id' => $reason_id,
2038
+ 'info' => $reason_info,
2039
+ 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
2040
+ );
2041
+
2042
+ $this->_storage->store( 'uninstall_reason', $reason );
2043
+
2044
+ /**
2045
+ * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
2046
+ * not support uninstall hook.
2047
+ *
2048
+ * @author Leo Fajardo (@leorw)
2049
+ * @since 1.2.2
2050
+ */
2051
+ if ( $this->is_theme() ) {
2052
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
2053
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2054
+ }
2055
+
2056
+ $this->_uninstall_plugin_event( false );
2057
+ $this->remove_sdk_reference();
2058
+ }
2059
+
2060
+ // Print '1' for successful operation.
2061
+ echo 1;
2062
+ exit;
2063
+ }
2064
+
2065
+ /**
2066
+ * @author Leo Fajardo (@leorw)
2067
+ * @since 2.0.2
2068
+ */
2069
+ function _delete_theme_update_data_action() {
2070
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2071
+ }
2072
+
2073
+ #endregion
2074
+
2075
+ #----------------------------------------------------------------------------------
2076
+ #region Instance
2077
+ #----------------------------------------------------------------------------------
2078
+
2079
+ /**
2080
+ * Main singleton instance.
2081
+ *
2082
+ * @author Vova Feldman (@svovaf)
2083
+ * @since 1.0.0
2084
+ *
2085
+ * @param number $module_id
2086
+ * @param string|bool $slug
2087
+ * @param bool $is_init Is initiation sequence.
2088
+ *
2089
+ * @return Freemius|false
2090
+ */
2091
+ static function instance( $module_id, $slug = false, $is_init = false ) {
2092
+ if ( empty( $module_id ) ) {
2093
+ return false;
2094
+ }
2095
+
2096
+ /**
2097
+ * Load the essential static data prior to initiating FS_Plugin_Manager since there's an essential MS network migration logic that needs to be executed prior to the initiation.
2098
+ */
2099
+ self::_load_required_static();
2100
+
2101
+ if ( ! is_numeric( $module_id ) ) {
2102
+ if ( ! $is_init && true === $slug ) {
2103
+ $is_init = true;
2104
+ }
2105
+
2106
+ $slug = $module_id;
2107
+
2108
+ $module = FS_Plugin_Manager::instance( $slug )->get();
2109
+
2110
+ if ( is_object( $module ) ) {
2111
+ $module_id = $module->id;
2112
+ }
2113
+ }
2114
+
2115
+ $key = 'm_' . $module_id;
2116
+
2117
+ if ( ! isset( self::$_instances[ $key ] ) ) {
2118
+ self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
2119
+ }
2120
+
2121
+ return self::$_instances[ $key ];
2122
+ }
2123
+
2124
+ /**
2125
+ * @author Vova Feldman (@svovaf)
2126
+ * @since 1.0.6
2127
+ *
2128
+ * @param number $addon_id
2129
+ *
2130
+ * @return bool
2131
+ */
2132
+ private static function has_instance( $addon_id ) {
2133
+ return isset( self::$_instances[ 'm_' . $addon_id ] );
2134
+ }
2135
+
2136
+ /**
2137
+ * @author Leo Fajardo (@leorw)
2138
+ * @since 1.2.2
2139
+ *
2140
+ * @param string|number $id_or_slug
2141
+ *
2142
+ * @return number|false
2143
+ */
2144
+ private static function get_module_id( $id_or_slug ) {
2145
+ if ( is_numeric( $id_or_slug ) ) {
2146
+ return $id_or_slug;
2147
+ }
2148
+
2149
+ foreach ( self::$_instances as $instance ) {
2150
+ if ( $instance->is_plugin() && ( $id_or_slug === $instance->get_slug() ) ) {
2151
+ return $instance->get_id();
2152
+ }
2153
+ }
2154
+
2155
+ return false;
2156
+ }
2157
+
2158
+ /**
2159
+ * @author Vova Feldman (@svovaf)
2160
+ * @since 1.0.6
2161
+ *
2162
+ * @param number $id
2163
+ *
2164
+ * @return false|Freemius
2165
+ */
2166
+ static function get_instance_by_id( $id ) {
2167
+ return isset ( self::$_instances[ 'm_' . $id ] ) ?
2168
+ self::$_instances[ 'm_' . $id ] :
2169
+ false;
2170
+ }
2171
+
2172
+ /**
2173
+ *
2174
+ * @author Vova Feldman (@svovaf)
2175
+ * @since 1.0.1
2176
+ *
2177
+ * @param $plugin_file
2178
+ *
2179
+ * @return false|Freemius
2180
+ */
2181
+ static function get_instance_by_file( $plugin_file ) {
2182
+ $slug = self::find_slug_by_basename( $plugin_file );
2183
+
2184
+ return ( false !== $slug ) ?
2185
+ self::instance( self::get_module_id( $slug ) ) :
2186
+ false;
2187
+ }
2188
+
2189
+ /**
2190
+ * @author Vova Feldman (@svovaf)
2191
+ * @since 1.0.6
2192
+ *
2193
+ * @return false|Freemius
2194
+ */
2195
+ function get_parent_instance() {
2196
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2197
+ }
2198
+
2199
+ /**
2200
+ * @author Vova Feldman (@svovaf)
2201
+ * @since 1.0.6
2202
+ *
2203
+ * @param string|number $id_or_slug
2204
+ *
2205
+ * @return false|Freemius
2206
+ */
2207
+ function get_addon_instance( $id_or_slug ) {
2208
+ $addon_id = self::get_module_id( $id_or_slug );
2209
+
2210
+ return self::instance( $addon_id );
2211
+ }
2212
+
2213
+ #endregion ------------------------------------------------------------------
2214
+
2215
+ /**
2216
+ * @author Vova Feldman (@svovaf)
2217
+ * @since 1.0.6
2218
+ *
2219
+ * @return bool
2220
+ */
2221
+ function is_parent_plugin_installed() {
2222
+ $is_active = self::has_instance( $this->_plugin->parent_plugin_id );
2223
+
2224
+ if ( $is_active ) {
2225
+ return true;
2226
+ }
2227
+
2228
+ /**
2229
+ * Parent module might be a theme. If that's the case, the add-on's FS
2230
+ * instance will be loaded prior to the theme's FS instance, therefore,
2231
+ * we need to check if it's active with a "look ahead".
2232
+ *
2233
+ * @author Vova Feldman
2234
+ * @since 1.2.2.3
2235
+ */
2236
+ global $fs_active_plugins;
2237
+ if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
2238
+ $active_theme = wp_get_theme();
2239
+
2240
+ foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
2241
+ if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
2242
+ if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
2243
+ // Parent module is a theme and it's currently active.
2244
+ return true;
2245
+ }
2246
+ }
2247
+ }
2248
+ }
2249
+
2250
+ return false;
2251
+ }
2252
+
2253
+ /**
2254
+ * Check if add-on parent plugin in activation mode.
2255
+ *
2256
+ * @author Vova Feldman (@svovaf)
2257
+ * @since 1.0.7
2258
+ *
2259
+ * @return bool
2260
+ */
2261
+ function is_parent_in_activation() {
2262
+ $parent_fs = $this->get_parent_instance();
2263
+ if ( ! is_object( $parent_fs ) ) {
2264
+ return false;
2265
+ }
2266
+
2267
+ return ( $parent_fs->is_activation_mode() );
2268
+ }
2269
+
2270
+ /**
2271
+ * Is plugin in activation mode.
2272
+ *
2273
+ * @author Vova Feldman (@svovaf)
2274
+ * @since 1.0.7
2275
+ *
2276
+ * @param bool $and_on
2277
+ *
2278
+ * @return bool
2279
+ */
2280
+ function is_activation_mode( $and_on = true ) {
2281
+ return fs_is_network_admin() ?
2282
+ $this->is_network_activation_mode( $and_on ) :
2283
+ $this->is_site_activation_mode( $and_on );
2284
+ }
2285
+
2286
+ /**
2287
+ * Is plugin in activation mode.
2288
+ *
2289
+ * @author Vova Feldman (@svovaf)
2290
+ * @since 1.0.7
2291
+ *
2292
+ * @param bool $and_on
2293
+ *
2294
+ * @return bool
2295
+ */
2296
+ function is_site_activation_mode( $and_on = true ) {
2297
+ return (
2298
+ ( $this->is_on() || ! $and_on ) &&
2299
+ ( ! $this->is_registered() ||
2300
+ ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
2301
+ ( ! $this->is_enable_anonymous() ||
2302
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
2303
+ );
2304
+ }
2305
+
2306
+ /**
2307
+ * Checks if the SDK in network activation mode.
2308
+ *
2309
+ * @author Leo Fajardo (@leorw)
2310
+ * @since 2.0.0
2311
+ *
2312
+ * @param bool $and_on
2313
+ *
2314
+ * @return bool
2315
+ */
2316
+ private function is_network_activation_mode( $and_on = true ) {
2317
+ if ( ! $this->_is_network_active ) {
2318
+ // Not network activated.
2319
+ return false;
2320
+ }
2321
+
2322
+ if ( $this->is_network_upgrade_mode() ) {
2323
+ // Special flag to enforce network activation mode to decide what to do with the sites that are not yet opted-in nor skipped.
2324
+ return true;
2325
+ }
2326
+
2327
+ if ( ! $this->is_site_activation_mode( $and_on ) ) {
2328
+ // Whether the context is single site or the network, if the plugin is no longer in activation mode then it is not in network activation mode as well.
2329
+ return false;
2330
+ }
2331
+
2332
+ if ( $this->is_network_delegated_connection() ) {
2333
+ // Super-admin delegated the connection to the site admins -> not activation mode.
2334
+ return false;
2335
+ }
2336
+
2337
+ if ( $this->is_network_anonymous() ) {
2338
+ // Super-admin skipped the connection network wide -> not activation mode.
2339
+ return false;
2340
+ }
2341
+
2342
+ if ( $this->is_network_registered() ) {
2343
+ // Super-admin connected at least one site -> not activation mode.
2344
+ return false;
2345
+ }
2346
+
2347
+ return true;
2348
+ }
2349
+
2350
+ /**
2351
+ * Check if current page is the opt-in/pending-activation page.
2352
+ *
2353
+ * @author Vova Feldman (@svovaf)
2354
+ * @since 1.2.1.7
2355
+ *
2356
+ * @return bool
2357
+ */
2358
+ function is_activation_page() {
2359
+ if ( $this->_menu->is_main_settings_page() ) {
2360
+ return true;
2361
+ }
2362
+
2363
+ if ( ! $this->is_activation_mode() ) {
2364
+ return false;
2365
+ }
2366
+
2367
+ // Check if current page is matching the activation page.
2368
+ return $this->is_matching_url( $this->get_activation_url() );
2369
+ }
2370
+
2371
+ /**
2372
+ * Check if URL path's are matching and that all querystring
2373
+ * arguments of the $sub_url exist in the $url with the same values.
2374
+ *
2375
+ * WARNING:
2376
+ * 1. This method doesn't check if the sub/domain are matching.
2377
+ * 2. Ignore case sensitivity.
2378
+ *
2379
+ * @author Vova Feldman (@svovaf)
2380
+ * @since 1.2.1.7
2381
+ *
2382
+ * @param string $sub_url
2383
+ * @param string $url If argument is not set, check if the sub_url matching the current's page URL.
2384
+ *
2385
+ * @return bool
2386
+ */
2387
+ private function is_matching_url( $sub_url, $url = '' ) {
2388
+ if ( empty( $url ) ) {
2389
+ $url = $_SERVER['REQUEST_URI'];
2390
+ }
2391
+
2392
+ $url = strtolower( $url );
2393
+ $sub_url = strtolower( $sub_url );
2394
+
2395
+ if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
2396
+ // Different path - DO NOT OVERRIDE PAGE.
2397
+ return false;
2398
+ }
2399
+
2400
+ $url_params = array();
2401
+ parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
2402
+
2403
+ $sub_url_params = array();
2404
+ parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
2405
+
2406
+ foreach ( $sub_url_params as $key => $val ) {
2407
+ if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
2408
+ // Not matching query string - DO NOT OVERRIDE PAGE.
2409
+ return false;
2410
+ }
2411
+ }
2412
+
2413
+ return true;
2414
+ }
2415
+
2416
+ /**
2417
+ * Get the basenames of all active plugins for specific blog. Including network activated plugins.
2418
+ *
2419
+ * @author Vova Feldman (@svovaf)
2420
+ * @since 2.0.0
2421
+ *
2422
+ * @param int $blog_id
2423
+ *
2424
+ * @return string[]
2425
+ */
2426
+ private static function get_active_plugins_basenames( $blog_id = 0 ) {
2427
+ if ( is_multisite() && $blog_id > 0 ) {
2428
+ $active_basenames = get_blog_option( $blog_id, 'active_plugins' );
2429
+ } else {
2430
+ $active_basenames = get_option( 'active_plugins' );
2431
+ }
2432
+
2433
+ if ( is_multisite() ) {
2434
+ $network_active_basenames = get_site_option( 'active_sitewide_plugins' );
2435
+
2436
+ if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
2437
+ $active_basenames = array_merge( $active_basenames, $network_active_basenames );
2438
+ }
2439
+ }
2440
+
2441
+ return $active_basenames;
2442
+ }
2443
+
2444
+ /**
2445
+ * Get collection of all active plugins. Including network activated plugins.
2446
+ *
2447
+ * @author Vova Feldman (@svovaf)
2448
+ * @since 1.0.9
2449
+ *
2450
+ * @param int $blog_id Since 2.0.0
2451
+ *
2452
+ * @return array[string]array
2453
+ */
2454
+ private static function get_active_plugins( $blog_id = 0 ) {
2455
+ self::require_plugin_essentials();
2456
+
2457
+ $active_plugin = array();
2458
+ $all_plugins = get_plugins();
2459
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
2460
+
2461
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
2462
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
2463
+ }
2464
+
2465
+ return $active_plugin;
2466
+ }
2467
+
2468
+ /**
2469
+ * Get collection of all site active plugins for a specified blog.
2470
+ *
2471
+ * @author Vova Feldman (@svovaf)
2472
+ * @since 2.0.0
2473
+ *
2474
+ * @param int $blog_id
2475
+ *
2476
+ * @return array[string]array
2477
+ */
2478
+ private static function get_site_active_plugins( $blog_id = 0 ) {
2479
+ $active_basenames = ( is_multisite() && $blog_id > 0 ) ?
2480
+ get_blog_option( $blog_id, 'active_plugins' ) :
2481
+ get_option( 'active_plugins' );
2482
+
2483
+ $active = array();
2484
+ foreach ( $active_basenames as $basename ) {
2485
+ $active[ $basename ] = array(
2486
+ 'is_active' => true,
2487
+ 'Version' => '1.0', // Dummy version.
2488
+ 'slug' => self::get_plugin_slug( $basename ),
2489
+ );
2490
+ }
2491
+
2492
+ return $active;
2493
+ }
2494
+
2495
+ /**
2496
+ * Get collection of all plugins with their activation status for a specified blog.
2497
+ *
2498
+ * @author Vova Feldman (@svovaf)
2499
+ * @since 1.1.8
2500
+ *
2501
+ * @param int $blog_id Since 2.0.0
2502
+ *
2503
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
2504
+ */
2505
+ private static function get_all_plugins( $blog_id = 0 ) {
2506
+ self::require_plugin_essentials();
2507
+
2508
+ $all_plugins = get_plugins();
2509
+
2510
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
2511
+
2512
+ foreach ( $all_plugins as $basename => &$data ) {
2513
+ // By default set to inactive (next foreach update the active plugins).
2514
+ $data['is_active'] = false;
2515
+ // Enrich with plugin slug.
2516
+ $data['slug'] = self::get_plugin_slug( $basename );
2517
+ }
2518
+
2519
+ // Flag active plugins.
2520
+ foreach ( $active_plugins_basenames as $basename ) {
2521
+ if ( isset( $all_plugins[ $basename ] ) ) {
2522
+ $all_plugins[ $basename ]['is_active'] = true;
2523
+ }
2524
+ }
2525
+
2526
+ return $all_plugins;
2527
+ }
2528
+
2529
+ /**
2530
+ * Get collection of all plugins and if they are network level activated.
2531
+ *
2532
+ * @author Vova Feldman (@svovaf)
2533
+ * @since 2.0.0
2534
+ *
2535
+ * @return array Key is the plugin basename and the value is an array of the plugin data.
2536
+ */
2537
+ private static function get_network_plugins() {
2538
+ self::require_plugin_essentials();
2539
+
2540
+ $all_plugins = get_plugins();
2541
+
2542
+ $network_active_basenames = is_multisite() ?
2543
+ get_site_option( 'active_sitewide_plugins' ) :
2544
+ array();
2545
+
2546
+ foreach ( $all_plugins as $basename => &$data ) {
2547
+ // By default set to inactive (next foreach update the active plugins).
2548
+ $data['is_active'] = false;
2549
+ // Enrich with plugin slug.
2550
+ $data['slug'] = self::get_plugin_slug( $basename );
2551
+ }
2552
+
2553
+ // Flag active plugins.
2554
+ foreach ( $network_active_basenames as $basename ) {
2555
+ if ( isset( $all_plugins[ $basename ] ) ) {
2556
+ $all_plugins[ $basename ]['is_active'] = true;
2557
+ }
2558
+ }
2559
+
2560
+ return $all_plugins;
2561
+ }
2562
+
2563
+ /**
2564
+ * Cached result of get_site_transient( 'update_plugins' )
2565
+ *
2566
+ * @author Vova Feldman (@svovaf)
2567
+ * @since 1.1.8
2568
+ *
2569
+ * @var object
2570
+ */
2571
+ private static $_plugins_info;
2572
+
2573
+ /**
2574
+ * Helper function to get specified plugin's slug.
2575
+ *
2576
+ * @author Vova Feldman (@svovaf)
2577
+ * @since 1.1.8
2578
+ *
2579
+ * @param $basename
2580
+ *
2581
+ * @return string
2582
+ */
2583
+ private static function get_plugin_slug( $basename ) {
2584
+ if ( ! isset( self::$_plugins_info ) ) {
2585
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
2586
+ }
2587
+
2588
+ $slug = '';
2589
+
2590
+ if ( is_object( self::$_plugins_info ) ) {
2591
+ if ( isset( self::$_plugins_info->no_update ) &&
2592
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
2593
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
2594
+ ) {
2595
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
2596
+ } else if ( isset( self::$_plugins_info->response ) &&
2597
+ isset( self::$_plugins_info->response[ $basename ] ) &&
2598
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
2599
+ ) {
2600
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
2601
+ }
2602
+ }
2603
+
2604
+ if ( empty( $slug ) ) {
2605
+ // Try to find slug from FS data.
2606
+ $slug = self::find_slug_by_basename( $basename );
2607
+ }
2608
+
2609
+ if ( empty( $slug ) ) {
2610
+ // Fallback to plugin's folder name.
2611
+ $slug = dirname( $basename );
2612
+ }
2613
+
2614
+ return $slug;
2615
+ }
2616
+
2617
+ private static $_statics_loaded = false;
2618
+
2619
+ /**
2620
+ * Load static resources.
2621
+ *
2622
+ * @author Vova Feldman (@svovaf)
2623
+ * @since 1.0.1
2624
+ */
2625
+ private static function _load_required_static() {
2626
+ if ( self::$_statics_loaded ) {
2627
+ return;
2628
+ }
2629
+
2630
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
2631
+
2632
+ self::$_static_logger->entrance();
2633
+
2634
+ self::$_accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
2635
+
2636
+ if ( is_multisite() ) {
2637
+ /**
2638
+ * If the id_slug_type_path_map exists on the site level but doesn't exist on the
2639
+ * network level storage, it means that we need to process the storage with migration.
2640
+ *
2641
+ * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, id_slug_type_path_map will be already set in the network level storage.
2642
+ *
2643
+ * @author Vova Feldman (@svovaf)
2644
+ * @since 2.0.0
2645
+ */
2646
+ if ( null === self::$_accounts->get_option( 'id_slug_type_path_map', null, true ) &&
2647
+ null !== self::$_accounts->get_option( 'id_slug_type_path_map', null, false )
2648
+ ) {
2649
+ self::migrate_accounts_to_network();
2650
+
2651
+ // Migrate API options from site level to network level.
2652
+ $api_network_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true, true );
2653
+ $api_network_options->migrate_to_network();
2654
+
2655
+ // Migrate API cache to network level storage.
2656
+ FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME )->migrate_to_network();
2657
+ }
2658
+ }
2659
+
2660
+ self::$_global_admin_notices = FS_Admin_Notices::instance( 'global' );
2661
+
2662
+ if ( ! WP_FS__DEMO_MODE ) {
2663
+ add_action( ( fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu', array(
2664
+ 'Freemius',
2665
+ '_add_debug_section'
2666
+ ) );
2667
+ }
2668
+
2669
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
2670
+
2671
+ self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
2672
+
2673
+ self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
2674
+
2675
+ self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
2676
+
2677
+ if ( 0 == did_action( 'plugins_loaded' ) ) {
2678
+ add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
2679
+ }
2680
+
2681
+ add_action( 'admin_footer', array( 'Freemius', '_enrich_ajax_url' ) );
2682
+
2683
+ self::$_statics_loaded = true;
2684
+ }
2685
+
2686
+ #----------------------------------------------------------------------------------
2687
+ #region Localization
2688
+ #----------------------------------------------------------------------------------
2689
+
2690
+ /**
2691
+ * Load framework's text domain.
2692
+ *
2693
+ * @author Vova Feldman (@svovaf)
2694
+ * @since 1.2.1
2695
+ */
2696
+ static function _load_textdomain() {
2697
+ if ( ! is_admin() ) {
2698
+ return;
2699
+ }
2700
+
2701
+ global $fs_active_plugins;
2702
+
2703
+ // Works both for plugins and themes.
2704
+ load_plugin_textdomain(
2705
+ 'freemius',
2706
+ false,
2707
+ $fs_active_plugins->newest->sdk_path . '/languages/'
2708
+ );
2709
+ }
2710
+
2711
+ #endregion
2712
+
2713
+ #----------------------------------------------------------------------------------
2714
+ #region Debugging
2715
+ #----------------------------------------------------------------------------------
2716
+
2717
+ /**
2718
+ * @author Vova Feldman (@svovaf)
2719
+ * @since 1.0.8
2720
+ */
2721
+ static function _add_debug_section() {
2722
+ if ( ! is_super_admin() ) {
2723
+ // Add debug page only for super-admins.
2724
+ return;
2725
+ }
2726
+
2727
+ self::$_static_logger->entrance();
2728
+
2729
+ $title = sprintf( '%s [v.%s]', fs_text_inline( 'Freemius Debug' ), WP_FS__SDK_VERSION );
2730
+
2731
+ if ( WP_FS__DEV_MODE ) {
2732
+ // Add top-level debug menu item.
2733
+ $hook = FS_Admin_Menu_Manager::add_page(
2734
+ $title,
2735
+ $title,
2736
+ 'manage_options',
2737
+ 'freemius',
2738
+ array( 'Freemius', '_debug_page_render' )
2739
+ );
2740
+ } else {
2741
+ // Add hidden debug page.
2742
+ $hook = FS_Admin_Menu_Manager::add_subpage(
2743
+ null,
2744
+ $title,
2745
+ $title,
2746
+ 'manage_options',
2747
+ 'freemius',
2748
+ array( 'Freemius', '_debug_page_render' )
2749
+ );
2750
+ }
2751
+
2752
+ if ( ! empty( $hook ) ) {
2753
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
2754
+ }
2755
+ }
2756
+
2757
+ /**
2758
+ * @author Vova Feldman (@svovaf)
2759
+ * @since 1.1.7.3
2760
+ */
2761
+ static function _toggle_debug_mode() {
2762
+ $is_on = fs_request_get( 'is_on', false, 'post' );
2763
+
2764
+ if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
2765
+ update_option( 'fs_debug_mode', $is_on );
2766
+
2767
+ // Turn on/off storage logging.
2768
+ FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
2769
+ }
2770
+
2771
+ exit;
2772
+ }
2773
+
2774
+ /**
2775
+ * @author Vova Feldman (@svovaf)
2776
+ * @since 1.2.1.6
2777
+ */
2778
+ static function _get_debug_log() {
2779
+ $logs = FS_Logger::load_db_logs(
2780
+ fs_request_get( 'filters', false, 'post' ),
2781
+ ! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? $_POST['limit'] : 200,
2782
+ ! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? $_POST['offset'] : 0
2783
+ );
2784
+
2785
+ self::shoot_ajax_success( $logs );
2786
+ }
2787
+
2788
+ /**
2789
+ * @author Vova Feldman (@svovaf)
2790
+ * @since 1.2.1.7
2791
+ */
2792
+ static function _get_db_option() {
2793
+ $option_name = fs_request_get( 'option_name' );
2794
+
2795
+ $value = get_option( $option_name );
2796
+
2797
+ $result = array(
2798
+ 'name' => $option_name,
2799
+ );
2800
+
2801
+ if ( false !== $value ) {
2802
+ if ( ! is_string( $value ) ) {
2803
+ $value = json_encode( $value );
2804
+ }
2805
+
2806
+ $result['value'] = $value;
2807
+ }
2808
+
2809
+ self::shoot_ajax_success( $result );
2810
+ }
2811
+
2812
+ /**
2813
+ * @author Vova Feldman (@svovaf)
2814
+ * @since 1.2.1.7
2815
+ */
2816
+ static function _set_db_option() {
2817
+ $option_name = fs_request_get( 'option_name' );
2818
+ $option_value = fs_request_get( 'option_value' );
2819
+
2820
+ if ( ! empty( $option_value ) ) {
2821
+ update_option( $option_name, $option_value );
2822
+ }
2823
+
2824
+ self::shoot_ajax_success();
2825
+ }
2826
+
2827
+ /**
2828
+ * @author Vova Feldman (@svovaf)
2829
+ * @since 1.0.8
2830
+ */
2831
+ static function _debug_page_actions() {
2832
+ self::_clean_admin_content_section();
2833
+
2834
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
2835
+ check_admin_referer( 'restart_freemius' );
2836
+
2837
+ if ( ! is_multisite() ) {
2838
+ // Clear accounts data.
2839
+ self::$_accounts->clear( null, true );
2840
+ } else {
2841
+ $sites = self::get_sites();
2842
+ foreach ( $sites as $site ) {
2843
+ $blog_id = self::get_site_blog_id( $site );
2844
+ self::$_accounts->clear( $blog_id, true );
2845
+ }
2846
+
2847
+ // Clear network level storage.
2848
+ self::$_accounts->clear( true, true );
2849
+ }
2850
+
2851
+ // Clear SDK reference cache.
2852
+ delete_option( 'fs_active_plugins' );
2853
+ } else if ( fs_request_is_action( 'clear_updates_data' ) ) {
2854
+ check_admin_referer( 'clear_updates_data' );
2855
+
2856
+ if ( ! is_multisite() ) {
2857
+ set_site_transient( 'update_plugins', null );
2858
+ set_site_transient( 'update_themes', null );
2859
+ } else {
2860
+ $current_blog_id = get_current_blog_id();
2861
+
2862
+ $sites = self::get_sites();
2863
+ foreach ( $sites as $site ) {
2864
+ switch_to_blog( self::get_site_blog_id( $site ) );
2865
+
2866
+ set_site_transient( 'update_plugins', null );
2867
+ set_site_transient( 'update_themes', null );
2868
+ }
2869
+
2870
+ switch_to_blog( $current_blog_id );
2871
+ }
2872
+ } else if ( fs_request_is_action( 'simulate_trial' ) ) {
2873
+ check_admin_referer( 'simulate_trial' );
2874
+
2875
+ $fs = freemius( fs_request_get( 'module_id' ) );
2876
+
2877
+ // Update SDK install to at least 24 hours before.
2878
+ $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
2879
+ // Unset the trial shown timestamp.
2880
+ unset( $fs->_storage->trial_promotion_shown );
2881
+ } else if ( fs_request_is_action( 'simulate_network_upgrade' ) ) {
2882
+ check_admin_referer( 'simulate_network_upgrade' );
2883
+
2884
+ $fs = freemius( fs_request_get( 'module_id' ) );
2885
+
2886
+ self::set_network_upgrade_mode( $fs->_storage );
2887
+ } else if ( fs_request_is_action( 'delete_install' ) ) {
2888
+ check_admin_referer( 'delete_install' );
2889
+
2890
+ self::_delete_site_by_slug(
2891
+ fs_request_get( 'slug' ),
2892
+ fs_request_get( 'module_type' ),
2893
+ true,
2894
+ fs_request_get( 'blog_id', null )
2895
+ );
2896
+ } else if ( fs_request_is_action( 'delete_user' ) ) {
2897
+ check_admin_referer( 'delete_user' );
2898
+
2899
+ self::delete_user( fs_request_get( 'user_id' ) );
2900
+ } else if ( fs_request_is_action( 'download_logs' ) ) {
2901
+ check_admin_referer( 'download_logs' );
2902
+
2903
+ $download_url = FS_Logger::download_db_logs(
2904
+ fs_request_get( 'filters', false, 'post' )
2905
+ );
2906
+
2907
+ if ( false === $download_url ) {
2908
+ wp_die( 'Oops... there was an error while generating the logs download file. Please try again and if it doesn\'t work contact support@freemius.com.' );
2909
+ }
2910
+
2911
+ fs_redirect( $download_url );
2912
+ }
2913
+ }
2914
+
2915
+ /**
2916
+ * @author Vova Feldman (@svovaf)
2917
+ * @since 1.0.8
2918
+ */
2919
+ static function _debug_page_render() {
2920
+ self::$_static_logger->entrance();
2921
+
2922
+ if ( ! is_multisite() ) {
2923
+ $all_plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
2924
+ $all_themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME );
2925
+ } else {
2926
+ $sites = self::get_sites();
2927
+
2928
+ $all_plugins_installs = array();
2929
+ $all_themes_installs = array();
2930
+
2931
+ foreach ( $sites as $site ) {
2932
+ $blog_id = self::get_site_blog_id( $site );
2933
+
2934
+ $plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
2935
+
2936
+ foreach ( $plugins_installs as $slug => $install ) {
2937
+ if ( ! isset( $all_plugins_installs[ $slug ] ) ) {
2938
+ $all_plugins_installs[ $slug ] = array();
2939
+ }
2940
+
2941
+ $install->blog_id = $blog_id;
2942
+
2943
+ $all_plugins_installs[ $slug ][] = $install;
2944
+ }
2945
+
2946
+ $themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id );
2947
+
2948
+ foreach ( $themes_installs as $slug => $install ) {
2949
+ if ( ! isset( $all_themes_installs[ $slug ] ) ) {
2950
+ $all_themes_installs[ $slug ] = array();
2951
+ }
2952
+
2953
+ $install->blog_id = $blog_id;
2954
+
2955
+ $all_themes_installs[ $slug ][] = $install;
2956
+ }
2957
+ }
2958
+ }
2959
+
2960
+ $licenses_by_module_type = self::get_all_licenses_by_module_type();
2961
+
2962
+ $vars = array(
2963
+ 'plugin_sites' => $all_plugins_installs,
2964
+ 'theme_sites' => $all_themes_installs,
2965
+ 'users' => self::get_all_users(),
2966
+ 'addons' => self::get_all_addons(),
2967
+ 'account_addons' => self::get_all_account_addons(),
2968
+ 'plugin_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_PLUGIN ],
2969
+ 'theme_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_THEME ]
2970
+ );
2971
+
2972
+ fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
2973
+ fs_require_once_template( 'debug.php', $vars );
2974
+ }
2975
+
2976
+ #endregion
2977
+
2978
+ #----------------------------------------------------------------------------------
2979
+ #region Connectivity Issues
2980
+ #----------------------------------------------------------------------------------
2981
+
2982
+ /**
2983
+ * Check if Freemius should be turned on for the current plugin install.
2984
+ *
2985
+ * Note:
2986
+ * $this->_is_on is updated in has_api_connectivity()
2987
+ *
2988
+ * @author Vova Feldman (@svovaf)
2989
+ * @since 1.0.9
2990
+ *
2991
+ * @return bool
2992
+ */
2993
+ function is_on() {
2994
+ self::$_static_logger->entrance();
2995
+
2996
+ if ( isset( $this->_is_on ) ) {
2997
+ return $this->_is_on;
2998
+ }
2999
+
3000
+ // If already installed or pending then sure it's on :)
3001
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
3002
+ $this->_is_on = true;
3003
+
3004
+ return true;
3005
+ }
3006
+
3007
+ return false;
3008
+ }
3009
+
3010
+ /**
3011
+ * @author Vova Feldman (@svovaf)
3012
+ * @since 1.1.7.3
3013
+ *
3014
+ * @param bool $flush_if_no_connectivity
3015
+ *
3016
+ * @return bool
3017
+ */
3018
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
3019
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
3020
+ // Connectivity test was never executed, or cache was cleared.
3021
+ return true;
3022
+ }
3023
+
3024
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
3025
+ if ( WP_FS__IS_HTTP_REQUEST ) {
3026
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
3027
+ // Domain changed.
3028
+ return true;
3029
+ }
3030
+
3031
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
3032
+ // Server IP changed.
3033
+ return true;
3034
+ }
3035
+ }
3036
+ }
3037
+
3038
+ if ( $this->_storage->connectivity_test['is_connected'] &&
3039
+ $this->_storage->connectivity_test['is_active']
3040
+ ) {
3041
+ // API connected and Freemius is active - no need to run connectivity check.
3042
+ return false;
3043
+ }
3044
+
3045
+ if ( $flush_if_no_connectivity ) {
3046
+ /**
3047
+ * If explicitly asked to flush when no connectivity - do it only
3048
+ * if at least 10 sec passed from the last API connectivity test.
3049
+ */
3050
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
3051
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
3052
+ }
3053
+
3054
+ /**
3055
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
3056
+ */
3057
+ $version = $this->get_plugin_version();
3058
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
3059
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
3060
+ return true;
3061
+ }
3062
+
3063
+ return false;
3064
+ }
3065
+
3066
+ /**
3067
+ * @author Vova Feldman (@svovaf)
3068
+ * @since 1.1.7.4
3069
+ *
3070
+ * @param int|null $blog_id Since 2.0.0.
3071
+ * @param bool $is_gdpr_test Since 2.0.2. Perform only the GDPR test.
3072
+ *
3073
+ * @return object|false
3074
+ */
3075
+ private function ping( $blog_id = null, $is_gdpr_test = false ) {
3076
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
3077
+ return false;
3078
+ }
3079
+
3080
+ $version = $this->get_plugin_version();
3081
+
3082
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
3083
+
3084
+ return $this->get_api_plugin_scope()->ping(
3085
+ $this->get_anonymous_id( $blog_id ),
3086
+ array(
3087
+ 'is_update' => json_encode( $is_update ),
3088
+ 'version' => $version,
3089
+ 'sdk' => $this->version,
3090
+ 'is_admin' => json_encode( is_admin() ),
3091
+ 'is_ajax' => json_encode( self::is_ajax() ),
3092
+ 'is_cron' => json_encode( self::is_cron() ),
3093
+ 'is_gdpr_test' => $is_gdpr_test,
3094
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
3095
+ )
3096
+ );
3097
+ }
3098
+
3099
+ /**
3100
+ * Check if there's any connectivity issue to Freemius API.
3101
+ *
3102
+ * @author Vova Feldman (@svovaf)
3103
+ * @since 1.0.9
3104
+ *
3105
+ * @param bool $flush_if_no_connectivity
3106
+ *
3107
+ * @return bool
3108
+ */
3109
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
3110
+ $this->_logger->entrance();
3111
+
3112
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
3113
+ return $this->_has_api_connection;
3114
+ }
3115
+
3116
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
3117
+ isset( $this->_storage->connectivity_test ) &&
3118
+ true === $this->_storage->connectivity_test['is_connected']
3119
+ ) {
3120
+ unset( $this->_storage->connectivity_test );
3121
+ }
3122
+
3123
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
3124
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
3125
+ /**
3126
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
3127
+ *
3128
+ * @since 1.2.1.5 If the user running the premium version then ignore the 'is_active' flag and turn Freemius on to enable license key activation.
3129
+ */
3130
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
3131
+ $this->is_premium() ||
3132
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3133
+
3134
+ return $this->_has_api_connection;
3135
+ }
3136
+
3137
+ $pong = $this->ping();
3138
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3139
+
3140
+ if ( ! $is_connected ) {
3141
+ // API failure.
3142
+ $this->_add_connectivity_issue_message( $pong );
3143
+ }
3144
+
3145
+ if ( $is_connected ) {
3146
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3147
+ }
3148
+
3149
+ $this->store_connectivity_info( $pong, $is_connected );
3150
+
3151
+ return $this->_has_api_connection;
3152
+ }
3153
+
3154
+ /**
3155
+ * @author Vova Feldman (@svovaf)
3156
+ * @since 1.1.7.4
3157
+ *
3158
+ * @param object $pong
3159
+ * @param bool $is_connected
3160
+ */
3161
+ private function store_connectivity_info( $pong, $is_connected ) {
3162
+ $this->_logger->entrance();
3163
+
3164
+ $version = $this->get_plugin_version();
3165
+
3166
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
3167
+ $is_active = false;
3168
+ } else {
3169
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
3170
+ }
3171
+
3172
+ $is_active = $this->apply_filters(
3173
+ 'is_on',
3174
+ $is_active,
3175
+ $this->is_plugin_update(),
3176
+ $version
3177
+ );
3178
+
3179
+ $this->_storage->connectivity_test = array(
3180
+ 'is_connected' => $is_connected,
3181
+ 'host' => $_SERVER['HTTP_HOST'],
3182
+ 'server_ip' => WP_FS__REMOTE_ADDR,
3183
+ 'is_active' => $is_active,
3184
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3185
+ // Last version with connectivity attempt.
3186
+ 'version' => $version,
3187
+ );
3188
+
3189
+ $this->_has_api_connection = $is_connected;
3190
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3191
+ }
3192
+
3193
+ /**
3194
+ * Force turning Freemius on.
3195
+ *
3196
+ * @author Vova Feldman (@svovaf)
3197
+ * @since 1.1.8.1
3198
+ *
3199
+ * @return bool TRUE if successfully turned on.
3200
+ */
3201
+ private function turn_on() {
3202
+ $this->_logger->entrance();
3203
+
3204
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
3205
+ return false;
3206
+ }
3207
+
3208
+ $updated_connectivity = $this->_storage->connectivity_test;
3209
+ $updated_connectivity['is_active'] = true;
3210
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
3211
+ $this->_storage->connectivity_test = $updated_connectivity;
3212
+
3213
+ $this->_is_on = true;
3214
+
3215
+ return true;
3216
+ }
3217
+
3218
+ /**
3219
+ * Anonymous and unique site identifier (Hash).
3220
+ *
3221
+ * @author Vova Feldman (@svovaf)
3222
+ * @since 1.1.0
3223
+ *
3224
+ * @param null|int $blog_id Since 2.0.0
3225
+ *
3226
+ * @return string
3227
+ */
3228
+ function get_anonymous_id( $blog_id = null ) {
3229
+ $unique_id = self::$_accounts->get_option( 'unique_id', null, $blog_id );
3230
+
3231
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
3232
+ $key = fs_strip_url_protocol( get_site_url( $blog_id ) );
3233
+
3234
+ $secure_auth = SECURE_AUTH_KEY;
3235
+ if ( empty( $secure_auth ) || false !== strpos( $secure_auth, ' ' ) ) {
3236
+ // Protect against default auth key.
3237
+ $secure_auth = md5( microtime() );
3238
+ }
3239
+
3240
+ /**
3241
+ * Base the unique identifier on the WP secure authentication key. Which
3242
+ * turns the key into a secret anonymous identifier. This will help us
3243
+ * to avoid duplicate installs generation on the backend upon opt-in.
3244
+ *
3245
+ * @author Vova Feldman (@svovaf)
3246
+ * @since 1.2.3
3247
+ */
3248
+ $unique_id = md5( $key . $secure_auth );
3249
+
3250
+ self::$_accounts->set_option( 'unique_id', $unique_id, true, $blog_id );
3251
+ }
3252
+
3253
+ $this->_logger->departure( $unique_id );
3254
+
3255
+ return $unique_id;
3256
+ }
3257
+
3258
+ /**
3259
+ * @author Vova Feldman (@svovaf)
3260
+ * @since 1.1.7.4
3261
+ *
3262
+ * @return \WP_User
3263
+ */
3264
+ static function _get_current_wp_user() {
3265
+ self::require_pluggable_essentials();
3266
+ self::wp_cookie_constants();
3267
+
3268
+ return wp_get_current_user();
3269
+ }
3270
+
3271
+ /**
3272
+ * Define cookie constants which are required by Freemius::_get_current_wp_user() since
3273
+ * it uses wp_get_current_user() which needs the cookie constants set. When a plugin
3274
+ * is network activated the cookie constants are only configured after the network
3275
+ * plugins activation, therefore, if we don't define those constants WP will throw
3276
+ * PHP warnings/notices.
3277
+ *
3278
+ * @author Vova Feldman (@svovaf)
3279
+ * @since 2.1.1
3280
+ */
3281
+ private static function wp_cookie_constants() {
3282
+ if ( defined( 'LOGGED_IN_COOKIE' ) &&
3283
+ ( defined( 'AUTH_COOKIE' ) || defined( 'SECURE_AUTH_COOKIE' ) )
3284
+ ) {
3285
+ return;
3286
+ }
3287
+
3288
+ /**
3289
+ * Used to guarantee unique hash cookies
3290
+ *
3291
+ * @since 1.5.0
3292
+ */
3293
+ if ( ! defined( 'COOKIEHASH' ) ) {
3294
+ $siteurl = get_site_option( 'siteurl' );
3295
+ if ( $siteurl ) {
3296
+ define( 'COOKIEHASH', md5( $siteurl ) );
3297
+ } else {
3298
+ define( 'COOKIEHASH', '' );
3299
+ }
3300
+ }
3301
+
3302
+ if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
3303
+ define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
3304
+ }
3305
+
3306
+ /**
3307
+ * @since 2.5.0
3308
+ */
3309
+ if ( ! defined( 'AUTH_COOKIE' ) ) {
3310
+ define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
3311
+ }
3312
+
3313
+ /**
3314
+ * @since 2.6.0
3315
+ */
3316
+ if ( ! defined( 'SECURE_AUTH_COOKIE' ) ) {
3317
+ define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
3318
+ }
3319
+ }
3320
+
3321
+ /**
3322
+ * @author Vova Feldman (@svovaf)
3323
+ * @since 2.1.0
3324
+ *
3325
+ * @return int
3326
+ */
3327
+ static function get_current_wp_user_id() {
3328
+ $wp_user = self::_get_current_wp_user();
3329
+
3330
+ return $wp_user->ID;
3331
+ }
3332
+
3333
+ /**
3334
+ * @author Vova Feldman (@svovaf)
3335
+ * @since 1.2.1.7
3336
+ *
3337
+ * @param string $email
3338
+ *
3339
+ * @return bool
3340
+ */
3341
+ static function is_valid_email( $email ) {
3342
+ if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
3343
+ return false;
3344
+ }
3345
+
3346
+ $parts = explode( '@', $email );
3347
+
3348
+ if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
3349
+ return false;
3350
+ }
3351
+
3352
+ $blacklist = array(
3353
+ 'admin.',
3354
+ 'webmaster.',
3355
+ 'localhost.',
3356
+ 'dev.',
3357
+ 'development.',
3358
+ 'test.',
3359
+ 'stage.',
3360
+ 'staging.',
3361
+ );
3362
+
3363
+ // Make sure domain is not one of the blacklisted.
3364
+ foreach ( $blacklist as $invalid ) {
3365
+ if ( 0 === strpos( $parts[1], $invalid ) ) {
3366
+ return false;
3367
+ }
3368
+ }
3369
+
3370
+ // Get the UTF encoded domain name.
3371
+ $domain = idn_to_ascii( $parts[1] ) . '.';
3372
+
3373
+ return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
3374
+ }
3375
+
3376
+ /**
3377
+ * Generate API connectivity issue message.
3378
+ *
3379
+ * @author Vova Feldman (@svovaf)
3380
+ * @since 1.0.9
3381
+ *
3382
+ * @param mixed $api_result
3383
+ * @param bool $is_first_failure
3384
+ */
3385
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
3386
+ if ( ! $this->is_premium() && $this->_enable_anonymous ) {
3387
+ // Don't add message if it's the free version and can run anonymously.
3388
+ return;
3389
+ }
3390
+
3391
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
3392
+ require_once ABSPATH . 'wp-includes/functions.php';
3393
+ }
3394
+
3395
+ $current_user = self::_get_current_wp_user();
3396
+ // $admin_email = get_option( 'admin_email' );
3397
+ $admin_email = $current_user->user_email;
3398
+
3399
+ // Aliases.
3400
+ $deactivate_plugin_title = $this->esc_html_inline( 'That\'s exhausting, please deactivate', 'deactivate-plugin-title' );
3401
+ $deactivate_plugin_desc = $this->esc_html_inline( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'deactivate-plugin-desc' );
3402
+ $install_previous_title = $this->esc_html_inline( 'Let\'s try your previous version', 'install-previous-title' );
3403
+ $install_previous_desc = $this->esc_html_inline( 'Uninstall this version and install the previous one.', 'install-previous-desc' );
3404
+ $fix_issue_title = $this->esc_html_inline( 'Yes - I\'m giving you a chance to fix it', 'fix-issue-title' );
3405
+ $fix_issue_desc = $this->esc_html_inline( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.', 'fix-issue-desc' );
3406
+ /* translators: %s: product title (e.g. "Awesome Plugin" requires an access to...) */
3407
+ $x_requires_access_to_api = $this->esc_html_inline( '%s requires an access to our API.', 'x-requires-access-to-api' );
3408
+ $sysadmin_title = $this->esc_html_inline( 'I\'m a system administrator', 'sysadmin-title' );
3409
+ $happy_to_resolve_issue_asap = $this->esc_html_inline( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.', 'happy-to-resolve-issue-asap' );
3410
+
3411
+ $message = false;
3412
+ if ( is_object( $api_result ) &&
3413
+ isset( $api_result->error ) &&
3414
+ isset( $api_result->error->code )
3415
+ ) {
3416
+ switch ( $api_result->error->code ) {
3417
+ case 'curl_missing':
3418
+ $missing_methods = '';
3419
+ if ( is_array( $api_result->missing_methods ) &&
3420
+ ! empty( $api_result->missing_methods )
3421
+ ) {
3422
+ foreach ( $api_result->missing_methods as $m ) {
3423
+ if ( 'curl_version' === $m ) {
3424
+ continue;
3425
+ }
3426
+
3427
+ if ( ! empty( $missing_methods ) ) {
3428
+ $missing_methods .= ', ';
3429
+ }
3430
+
3431
+ $missing_methods .= sprintf( '<code>%s</code>', $m );
3432
+ }
3433
+
3434
+ if ( ! empty( $missing_methods ) ) {
3435
+ $missing_methods = sprintf(
3436
+ '<br><br><b>%s</b> %s',
3437
+ $this->esc_html_inline( 'Disabled method(s):', 'curl-disabled-methods' ),
3438
+ $missing_methods
3439
+ );
3440
+ }
3441
+ }
3442
+
3443
+ $message = sprintf(
3444
+ $x_requires_access_to_api . ' ' .
3445
+ $this->esc_html_inline( 'We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server.', 'curl-missing-message' ) . ' ' .
3446
+ $missing_methods .
3447
+ ' %s',
3448
+ '<b>' . $this->get_plugin_name() . '</b>',
3449
+ sprintf(
3450
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3451
+ sprintf(
3452
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
3453
+ $this->get_text_inline( 'I don\'t know what is cURL or how to install it, help me!', 'curl-missing-no-clue-title' ),
3454
+ ' - ' . sprintf(
3455
+ $this->get_text_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'curl-missing-no-clue-desc' ),
3456
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3457
+ )
3458
+ ),
3459
+ sprintf(
3460
+ '<b>%s</b> - %s',
3461
+ $sysadmin_title,
3462
+ esc_html( sprintf( $this->get_text_inline( 'Great, please install cURL and enable it in your php.ini file. In addition, search for the \'disable_functions\' directive in your php.ini file and remove any disabled methods starting with \'curl_\'. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the %s and reactivate it back again.', 'curl-missing-sysadmin-desc' ), $this->get_module_label( true ) ) )
3463
+ ),
3464
+ sprintf(
3465
+ '<a href="%s"><b>%s</b></a> - %s',
3466
+ 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 ),
3467
+ $deactivate_plugin_title,
3468
+ $deactivate_plugin_desc
3469
+ )
3470
+ )
3471
+ );
3472
+ break;
3473
+ case 'cloudflare_ddos_protection':
3474
+ $message = sprintf(
3475
+ $x_requires_access_to_api . ' ' .
3476
+ $this->esc_html_inline( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'cloudflare-blocks-connection-message' ) . ' ' .
3477
+ $happy_to_resolve_issue_asap .
3478
+ ' %s',
3479
+ '<b>' . $this->get_plugin_name() . '</b>',
3480
+ sprintf(
3481
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3482
+ sprintf(
3483
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
3484
+ $fix_issue_title,
3485
+ ' - ' . sprintf(
3486
+ $fix_issue_desc,
3487
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3488
+ )
3489
+ ),
3490
+ sprintf(
3491
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
3492
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
3493
+ $install_previous_title,
3494
+ $install_previous_desc
3495
+ ),
3496
+ sprintf(
3497
+ '<a href="%s"><b>%s</b></a> - %s',
3498
+ 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 ),
3499
+ $deactivate_plugin_title,
3500
+ $deactivate_plugin_desc
3501
+ )
3502
+ )
3503
+ );
3504
+ break;
3505
+ case 'squid_cache_block':
3506
+ $message = sprintf(
3507
+ $x_requires_access_to_api . ' ' .
3508
+ $this->esc_html_inline( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'squid-blocks-connection-message' ) .
3509
+ ' %s',
3510
+ '<b>' . $this->get_plugin_name() . '</b>',
3511
+ sprintf(
3512
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3513
+ sprintf(
3514
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a> - %s',
3515
+ $this->esc_html_inline( 'I don\'t know what is Squid or ACL, help me!', 'squid-no-clue-title' ),
3516
+ sprintf(
3517
+ $this->esc_html_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'squid-no-clue-desc' ),
3518
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3519
+ )
3520
+ ),
3521
+ sprintf(
3522
+ '<b>%s</b> - %s',
3523
+ $sysadmin_title,
3524
+ sprintf(
3525
+ $this->esc_html_inline( 'Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again.', 'squid-sysadmin-desc' ),
3526
+ // We use a filter since the plugin might require additional API connectivity.
3527
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
3528
+ 'api.freemius.com',
3529
+ 'wp.freemius.com'
3530
+ ) ) ) . '</b>',
3531
+ $this->_module_type
3532
+ )
3533
+ ),
3534
+ sprintf(
3535
+ '<a href="%s"><b>%s</b></a> - %s',
3536
+ 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 ),
3537
+ $deactivate_plugin_title,
3538
+ $deactivate_plugin_desc
3539
+ )
3540
+ )
3541
+ );
3542
+ break;
3543
+ // default:
3544
+ // $message = $this->get_text_inline( 'connectivity-test-fails-message' );
3545
+ // break;
3546
+ }
3547
+ }
3548
+
3549
+ $message_id = 'failed_connect_api';
3550
+ $type = 'error';
3551
+
3552
+ $connectivity_test_fails_message = $this->esc_html_inline( 'From unknown reason, the API connectivity test failed.', 'connectivity-test-fails-message' );
3553
+
3554
+ if ( false === $message ) {
3555
+ if ( $is_first_failure ) {
3556
+ // First attempt failed.
3557
+ $message = sprintf(
3558
+ $x_requires_access_to_api . ' ' .
3559
+ $connectivity_test_fails_message . ' ' .
3560
+ $this->esc_html_inline( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?', 'connectivity-test-maybe-temporary' ) . '<br><br>' .
3561
+ '%s',
3562
+ '<b>' . $this->get_plugin_name() . '</b>',
3563
+ sprintf(
3564
+ '<div id="fs_firewall_issue_options">%s %s</div>',
3565
+ sprintf(
3566
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
3567
+ $this->get_text_inline( 'Yes - do your thing', 'yes-do-your-thing' )
3568
+ ),
3569
+ sprintf(
3570
+ '<a href="%s" class="button">%s</a>',
3571
+ 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 ),
3572
+ $this->get_text_inline( 'No - just deactivate', 'no-deactivate' )
3573
+ )
3574
+ )
3575
+ );
3576
+
3577
+ $message_id = 'failed_connect_api_first';
3578
+ $type = 'promotion';
3579
+ } else {
3580
+ // Second connectivity attempt failed.
3581
+ $message = sprintf(
3582
+ $x_requires_access_to_api . ' ' .
3583
+ $connectivity_test_fails_message . ' ' .
3584
+ $happy_to_resolve_issue_asap .
3585
+ ' %s',
3586
+ '<b>' . $this->get_plugin_name() . '</b>',
3587
+ sprintf(
3588
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3589
+ sprintf(
3590
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
3591
+ $fix_issue_title,
3592
+ ' - ' . sprintf(
3593
+ $fix_issue_desc,
3594
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3595
+ )
3596
+ ),
3597
+ sprintf(
3598
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
3599
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
3600
+ $install_previous_title,
3601
+ $install_previous_desc
3602
+ ),
3603
+ sprintf(
3604
+ '<a href="%s"><b>%s</b></a> - %s',
3605
+ 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 ),
3606
+ $deactivate_plugin_title,
3607
+ $deactivate_plugin_desc
3608
+ )
3609
+ )
3610
+ );
3611
+ }
3612
+ }
3613
+
3614
+ $this->_admin_notices->add_sticky(
3615
+ $message,
3616
+ $message_id,
3617
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
3618
+ $type
3619
+ );
3620
+ }
3621
+
3622
+ /**
3623
+ * Handle user request to resolve connectivity issue.
3624
+ * This method will send an email to Freemius API technical staff for resolution.
3625
+ * The email will contain server's info and installed plugins (might be caching issue).
3626
+ *
3627
+ * @author Vova Feldman (@svovaf)
3628
+ * @since 1.0.9
3629
+ */
3630
+ function _email_about_firewall_issue() {
3631
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
3632
+
3633
+ $pong = $this->ping();
3634
+
3635
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3636
+
3637
+ if ( $is_connected ) {
3638
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3639
+
3640
+ $this->store_connectivity_info( $pong, $is_connected );
3641
+
3642
+ echo $this->get_after_plugin_activation_redirect_url();
3643
+ exit;
3644
+ }
3645
+
3646
+ $current_user = self::_get_current_wp_user();
3647
+ $admin_email = $current_user->user_email;
3648
+
3649
+ $error_type = fs_request_get( 'error_type', 'general' );
3650
+
3651
+ switch ( $error_type ) {
3652
+ case 'squid':
3653
+ $title = 'Squid ACL Blocking Issue';
3654
+ break;
3655
+ case 'cloudflare':
3656
+ $title = 'CloudFlare Blocking Issue';
3657
+ break;
3658
+ default:
3659
+ $title = 'API Connectivity Issue';
3660
+ break;
3661
+ }
3662
+
3663
+ $custom_email_sections = array();
3664
+
3665
+ // Add 'API Error' custom email section.
3666
+ $custom_email_sections['api_error'] = array(
3667
+ 'title' => 'API Error',
3668
+ 'rows' => array(
3669
+ 'ping' => array(
3670
+ 'API Error',
3671
+ is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
3672
+ ),
3673
+ )
3674
+ );
3675
+
3676
+ // Send email with technical details to resolve API connectivity issues.
3677
+ $this->send_email(
3678
+ 'api@freemius.com', // recipient
3679
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
3680
+ $custom_email_sections,
3681
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
3682
+ );
3683
+
3684
+ $this->_admin_notices->add_sticky(
3685
+ sprintf(
3686
+ $this->get_text_inline( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.', 'fix-request-sent-message' ),
3687
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3688
+ ),
3689
+ 'server_details_sent'
3690
+ );
3691
+
3692
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
3693
+
3694
+ echo "1";
3695
+ exit;
3696
+ }
3697
+
3698
+ /**
3699
+ * Handle connectivity test retry approved by the user.
3700
+ *
3701
+ * @author Vova Feldman (@svovaf)
3702
+ * @since 1.1.7.4
3703
+ */
3704
+ function _retry_connectivity_test() {
3705
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
3706
+
3707
+ $pong = $this->ping();
3708
+
3709
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3710
+
3711
+ if ( $is_connected ) {
3712
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3713
+
3714
+ $this->store_connectivity_info( $pong, $is_connected );
3715
+
3716
+ echo $this->get_after_plugin_activation_redirect_url();
3717
+ } else {
3718
+ // Add connectivity issue message after 2nd failed attempt.
3719
+ $this->_add_connectivity_issue_message( $pong, false );
3720
+
3721
+ echo "1";
3722
+ }
3723
+
3724
+ exit;
3725
+ }
3726
+
3727
+ static function _add_firewall_issues_javascript() {
3728
+ $params = array();
3729
+ fs_require_once_template( 'firewall-issues-js.php', $params );
3730
+ }
3731
+
3732
+ #endregion
3733
+
3734
+ #----------------------------------------------------------------------------------
3735
+ #region Email
3736
+ #----------------------------------------------------------------------------------
3737
+
3738
+ /**
3739
+ * Generates and sends an HTML email with customizable sections.
3740
+ *
3741
+ * @author Leo Fajardo (@leorw)
3742
+ * @since 1.1.2
3743
+ *
3744
+ * @param string $to_address
3745
+ * @param string $subject
3746
+ * @param array $sections
3747
+ * @param array $headers
3748
+ *
3749
+ * @return bool Whether the email contents were sent successfully.
3750
+ */
3751
+ private function send_email(
3752
+ $to_address,
3753
+ $subject,
3754
+ $sections = array(),
3755
+ $headers = array()
3756
+ ) {
3757
+ $default_sections = $this->get_email_sections();
3758
+
3759
+ // Insert new sections or replace the default email sections.
3760
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
3761
+ foreach ( $sections as $section_id => $custom_section ) {
3762
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
3763
+ // If the section does not exist, add it.
3764
+ $default_sections[ $section_id ] = $custom_section;
3765
+ } else {
3766
+ // If the section already exists, override it.
3767
+ $current_section = $default_sections[ $section_id ];
3768
+
3769
+ // Replace the current section's title if a custom section title exists.
3770
+ if ( isset( $custom_section['title'] ) ) {
3771
+ $current_section['title'] = $custom_section['title'];
3772
+ }
3773
+
3774
+ // Insert new rows under the current section or replace the default rows.
3775
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
3776
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
3777
+ $current_section['rows'][ $row_id ] = $row;
3778
+ }
3779
+ }
3780
+
3781
+ $default_sections[ $section_id ] = $current_section;
3782
+ }
3783
+ }
3784
+ }
3785
+
3786
+ $vars = array( 'sections' => $default_sections );
3787
+ $message = fs_get_template( 'email.php', $vars );
3788
+
3789
+ // Set the type of email to HTML.
3790
+ $headers[] = 'Content-type: text/html; charset=UTF-8';
3791
+
3792
+ $header_string = implode( "\r\n", $headers );
3793
+
3794
+ return wp_mail(
3795
+ $to_address,
3796
+ $subject,
3797
+ $message,
3798
+ $header_string
3799
+ );
3800
+ }
3801
+
3802
+ /**
3803
+ * Generates the data for the sections of the email content.
3804
+ *
3805
+ * @author Leo Fajardo (@leorw)
3806
+ * @since 1.1.2
3807
+ *
3808
+ * @return array
3809
+ */
3810
+ private function get_email_sections() {
3811
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
3812
+ $current_user = self::_get_current_wp_user();
3813
+
3814
+ // Retrieve the cURL version information so that we can get the version number below.
3815
+ $curl_version_information = curl_version();
3816
+
3817
+ $active_plugin = self::get_active_plugins();
3818
+
3819
+ // Generate the list of active plugins separated by new line.
3820
+ $active_plugin_string = '';
3821
+ foreach ( $active_plugin as $plugin ) {
3822
+ $active_plugin_string .= sprintf(
3823
+ '<a href="%s">%s</a> [v%s]<br>',
3824
+ $plugin['PluginURI'],
3825
+ $plugin['Name'],
3826
+ $plugin['Version']
3827
+ );
3828
+ }
3829
+
3830
+ $server_ip = WP_FS__REMOTE_ADDR;
3831
+
3832
+ // Add PHP info for deeper investigation.
3833
+ ob_start();
3834
+ phpinfo();
3835
+ $php_info = ob_get_clean();
3836
+
3837
+ $api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
3838
+
3839
+ // Generate the default email sections.
3840
+ $sections = array(
3841
+ 'sdk' => array(
3842
+ 'title' => 'SDK',
3843
+ 'rows' => array(
3844
+ 'fs_version' => array( 'FS Version', $this->version ),
3845
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
3846
+ )
3847
+ ),
3848
+ 'plugin' => array(
3849
+ 'title' => ucfirst( $this->get_module_type() ),
3850
+ 'rows' => array(
3851
+ 'name' => array( 'Name', $this->get_plugin_name() ),
3852
+ 'version' => array( 'Version', $this->get_plugin_version() )
3853
+ )
3854
+ ),
3855
+ 'api' => array(
3856
+ 'title' => 'API Subdomain',
3857
+ 'rows' => array(
3858
+ 'dns' => array(
3859
+ 'DNS_CNAME',
3860
+ function_exists( 'dns_get_record' ) ?
3861
+ var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
3862
+ 'dns_get_record() disabled/blocked'
3863
+ ),
3864
+ 'ip' => array(
3865
+ 'IP',
3866
+ function_exists( 'gethostbyname' ) ?
3867
+ gethostbyname( $api_domain ) :
3868
+ 'gethostbyname() disabled/blocked'
3869
+ ),
3870
+ ),
3871
+ ),
3872
+ 'site' => array(
3873
+ 'title' => 'Site',
3874
+ 'rows' => array(
3875
+ 'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
3876
+ 'address' => array( 'Address', site_url() ),
3877
+ 'host' => array(
3878
+ 'HTTP_HOST',
3879
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
3880
+ ),
3881
+ 'hosting' => array(
3882
+ 'Hosting Company' => fs_request_has( 'hosting_company' ) ?
3883
+ fs_request_get( 'hosting_company' ) :
3884
+ 'Unknown',
3885
+ ),
3886
+ 'server_addr' => array(
3887
+ 'SERVER_ADDR',
3888
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
3889
+ )
3890
+ )
3891
+ ),
3892
+ 'user' => array(
3893
+ 'title' => 'User',
3894
+ 'rows' => array(
3895
+ 'email' => array( 'Email', $current_user->user_email ),
3896
+ 'first' => array( 'First', $current_user->user_firstname ),
3897
+ 'last' => array( 'Last', $current_user->user_lastname )
3898
+ )
3899
+ ),
3900
+ 'plugins' => array(
3901
+ 'title' => 'Plugins',
3902
+ 'rows' => array(
3903
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
3904
+ )
3905
+ ),
3906
+ 'php_info' => array(
3907
+ 'title' => 'PHP Info',
3908
+ 'rows' => array(
3909
+ 'info' => array( $php_info )
3910
+ ),
3911
+ )
3912
+ );
3913
+
3914
+ // Allow the sections to be modified by other code.
3915
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
3916
+
3917
+ return $sections;
3918
+ }
3919
+
3920
+ #endregion
3921
+
3922
+ #----------------------------------------------------------------------------------
3923
+ #region Initialization
3924
+ #----------------------------------------------------------------------------------
3925
+
3926
+ /**
3927
+ * Init plugin's Freemius instance.
3928
+ *
3929
+ * @author Vova Feldman (@svovaf)
3930
+ * @since 1.0.1
3931
+ *
3932
+ * @param number $id
3933
+ * @param string $public_key
3934
+ * @param bool $is_live
3935
+ * @param bool $is_premium
3936
+ */
3937
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
3938
+ $this->_logger->entrance();
3939
+
3940
+ $this->dynamic_init( array(
3941
+ 'id' => $id,
3942
+ 'public_key' => $public_key,
3943
+ 'is_live' => $is_live,
3944
+ 'is_premium' => $is_premium,
3945
+ ) );
3946
+ }
3947
+
3948
+ /**
3949
+ * Dynamic initiator, originally created to support initiation
3950
+ * with parent_id for add-ons.
3951
+ *
3952
+ * @author Vova Feldman (@svovaf)
3953
+ * @since 1.0.6
3954
+ *
3955
+ * @param array $plugin_info
3956
+ *
3957
+ * @throws Freemius_Exception
3958
+ */
3959
+ function dynamic_init( array $plugin_info ) {
3960
+ $this->_logger->entrance();
3961
+
3962
+ $this->parse_settings( $plugin_info );
3963
+
3964
+ if ( ! self::is_ajax() ) {
3965
+ if ( ! $this->is_addon() || $this->is_only_premium() ) {
3966
+ add_action(
3967
+ ( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
3968
+ array( &$this, '_prepare_admin_menu' ),
3969
+ WP_FS__LOWEST_PRIORITY
3970
+ );
3971
+ }
3972
+ }
3973
+
3974
+ if ( $this->should_stop_execution() ) {
3975
+ return;
3976
+ }
3977
+
3978
+ if ( ! $this->is_registered() ) {
3979
+ if ( $this->is_anonymous() ) {
3980
+ // If user skipped, no need to test connectivity.
3981
+ $this->_has_api_connection = true;
3982
+ $this->_is_on = true;
3983
+ } else {
3984
+ if ( ! $this->has_api_connectivity() ) {
3985
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
3986
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
3987
+ ) {
3988
+ if ( ! $this->_enable_anonymous || $this->is_premium() ) {
3989
+ // If anonymous mode is disabled, add firewall admin-notice message.
3990
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
3991
+
3992
+ $ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
3993
+ add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
3994
+ &$this,
3995
+ '_email_about_firewall_issue'
3996
+ ) );
3997
+
3998
+ add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
3999
+ &$this,
4000
+ '_retry_connectivity_test'
4001
+ ) );
4002
+
4003
+ /**
4004
+ * Currently the admin notice manager relies on the module's type and slug. The new AJAX actions manager uses module IDs, hence, consider to replace the if block above with the commented code below after adjusting the admin notices manager to work with module IDs.
4005
+ *
4006
+ * @author Vova Feldman (@svovaf)
4007
+ * @since 2.0.0
4008
+ */
4009
+ /*$this->add_ajax_action( 'resolve_firewall_issues', array(
4010
+ &$this,
4011
+ '_email_about_firewall_issue'
4012
+ ) );
4013
+
4014
+ $this->add_ajax_action( 'retry_connectivity_test', array(
4015
+ &$this,
4016
+ '_retry_connectivity_test'
4017
+ ) );*/
4018
+ }
4019
+ }
4020
+
4021
+ return;
4022
+ } else {
4023
+ $this->_admin_notices->remove_sticky( array(
4024
+ 'failed_connect_api_first',
4025
+ 'failed_connect_api',
4026
+ ) );
4027
+
4028
+ if ( $this->_anonymous_mode ) {
4029
+ // Simulate anonymous mode.
4030
+ $this->_is_anonymous = true;
4031
+ }
4032
+ }
4033
+ }
4034
+ }
4035
+
4036
+ /**
4037
+ * This should be executed even if Freemius is off for the core module,
4038
+ * otherwise, the add-ons dialogbox won't work properly. This is esepcially
4039
+ * relevant when the developer decided to turn FS off for existing users.
4040
+ *
4041
+ * @author Vova Feldman (@svovaf)
4042
+ */
4043
+ if ( $this->is_user_in_admin() &&
4044
+ ! $this->is_addon() &&
4045
+ $this->has_addons() &&
4046
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
4047
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
4048
+ ) {
4049
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
4050
+
4051
+ new FS_Plugin_Info_Dialog( $this );
4052
+ }
4053
+
4054
+ // Check if Freemius is on for the current plugin.
4055
+ // This MUST be executed after all the plugin variables has been loaded.
4056
+ if ( ! $this->is_registered() && ! $this->is_on() ) {
4057
+ return;
4058
+ }
4059
+
4060
+ if ( $this->has_api_connectivity() ) {
4061
+ if ( self::is_cron() ) {
4062
+ $this->hook_callback_to_sync_cron();
4063
+ } else if ( $this->is_user_in_admin() ) {
4064
+ /**
4065
+ * Schedule daily data sync cron if:
4066
+ *
4067
+ * 1. User opted-in (for tracking).
4068
+ * 2. If skipped, but later upgraded (opted-in via upgrade).
4069
+ *
4070
+ * @author Vova Feldman (@svovaf)
4071
+ * @since 1.1.7.3
4072
+ *
4073
+ */
4074
+ if ( $this->is_registered() ) {
4075
+ if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
4076
+ $this->schedule_sync_cron();
4077
+ }
4078
+ }
4079
+
4080
+ /**
4081
+ * Check if requested for manual blocking background sync.
4082
+ */
4083
+ if ( fs_request_has( 'background_sync' ) ) {
4084
+ $this->run_manual_sync();
4085
+ }
4086
+ }
4087
+ }
4088
+
4089
+ if ( $this->is_registered() ) {
4090
+ $this->hook_callback_to_install_sync();
4091
+ }
4092
+
4093
+ if ( $this->is_addon() ) {
4094
+ if ( $this->is_parent_plugin_installed() ) {
4095
+ // Link to parent FS.
4096
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
4097
+
4098
+ // Get parent plugin reference.
4099
+ $this->_parent_plugin = $this->_parent->get_plugin();
4100
+ }
4101
+ }
4102
+
4103
+ if ( $this->is_user_in_admin() ) {
4104
+ if ( $this->is_addon() ) {
4105
+ if ( ! $this->is_parent_plugin_installed() ) {
4106
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
4107
+
4108
+ if ( isset( $plugin_info['parent'] ) ) {
4109
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
4110
+ }
4111
+
4112
+ $this->_admin_notices->add(
4113
+ ( ! empty( $parent_name ) ?
4114
+ sprintf( $this->get_text_x_inline( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
4115
+ sprintf( $this->get_text_x_inline( '%s cannot run without the plugin.', 'addonX cannot run...', 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
4116
+ ),
4117
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
4118
+ 'error'
4119
+ );
4120
+
4121
+ return;
4122
+ } else {
4123
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
4124
+ // If parent plugin activated, automatically install add-on for the user.
4125
+ $this->_activate_addon_account( $this->_parent );
4126
+ } else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
4127
+ // If add-on activated and parent not, automatically install parent for the user.
4128
+ $this->activate_parent_account( $this->_parent );
4129
+ }
4130
+
4131
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
4132
+ if ( $this->is_premium() ) {
4133
+ // Remove add-on download admin-notice.
4134
+ $this->_parent->_admin_notices->remove_sticky( array(
4135
+ 'addon_plan_upgraded_' . $this->_slug,
4136
+ 'no_addon_license_' . $this->_slug,
4137
+ ) );
4138
+ }
4139
+
4140
+ // $this->deactivate_premium_only_addon_without_license();
4141
+ }
4142
+ }
4143
+
4144
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
4145
+
4146
+ // if ( $this->is_registered() ||
4147
+ // $this->is_anonymous() ||
4148
+ // $this->is_pending_activation()
4149
+ // ) {
4150
+ // $this->_init_admin();
4151
+ // }
4152
+ }
4153
+
4154
+ /**
4155
+ * Should be called outside `$this->is_user_in_admin()` scope
4156
+ * because the updater has some logic that needs to be executed
4157
+ * during AJAX calls.
4158
+ *
4159
+ * Currently we need to hook to the `http_request_host_is_external` filter.
4160
+ * In the future, there might be additional logic added.
4161
+ *
4162
+ * @author Vova Feldman
4163
+ * @since 1.2.1.6
4164
+ */
4165
+ if ( $this->is_premium() && $this->has_release_on_freemius() ) {
4166
+ FS_Plugin_Updater::instance( $this );
4167
+ }
4168
+
4169
+ $this->do_action( 'initiated' );
4170
+
4171
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
4172
+ if ( isset( $this->_storage->prev_is_premium ) ) {
4173
+ $this->apply_filters(
4174
+ 'after_code_type_change',
4175
+ // New code type.
4176
+ $this->_plugin->is_premium
4177
+ );
4178
+ } else {
4179
+ // Set for code type for the first time.
4180
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
4181
+ }
4182
+ }
4183
+
4184
+ if ( ! $this->is_addon() ) {
4185
+ if ( $this->is_registered() ) {
4186
+ // Fix for upgrade from versions < 1.0.9.
4187
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
4188
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
4189
+ }
4190
+
4191
+ $this->do_action( 'after_init_plugin_registered' );
4192
+ } else if ( $this->is_anonymous() ) {
4193
+ $this->do_action( 'after_init_plugin_anonymous' );
4194
+ } else if ( $this->is_pending_activation() ) {
4195
+ $this->do_action( 'after_init_plugin_pending_activations' );
4196
+ }
4197
+ } else {
4198
+ if ( $this->is_registered() ) {
4199
+ $this->do_action( 'after_init_addon_registered' );
4200
+ } else if ( $this->is_anonymous() ) {
4201
+ $this->do_action( 'after_init_addon_anonymous' );
4202
+ } else if ( $this->is_pending_activation() ) {
4203
+ $this->do_action( 'after_init_addon_pending_activations' );
4204
+ }
4205
+ }
4206
+ }
4207
+
4208
+ /**
4209
+ * @author Leo Fajardo (@leorw)
4210
+ *
4211
+ * @since 1.2.1.5
4212
+ */
4213
+ function _stop_tracking_callback() {
4214
+ $this->_logger->entrance();
4215
+
4216
+ $this->check_ajax_referer( 'stop_tracking' );
4217
+
4218
+ $result = $this->stop_tracking( fs_is_network_admin() );
4219
+
4220
+ if ( true === $result ) {
4221
+ self::shoot_ajax_success();
4222
+ }
4223
+
4224
+ $this->_logger->api_error( $result );
4225
+
4226
+ self::shoot_ajax_failure(
4227
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
4228
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
4229
+ $result->error->message :
4230
+ var_export( $result, true ) )
4231
+ );
4232
+ }
4233
+
4234
+ /**
4235
+ * @author Leo Fajardo (@leorw)
4236
+ * @since 1.2.1.5
4237
+ */
4238
+ function _allow_tracking_callback() {
4239
+ $this->_logger->entrance();
4240
+
4241
+ $this->check_ajax_referer( 'allow_tracking' );
4242
+
4243
+ $result = $this->allow_tracking( fs_is_network_admin() );
4244
+
4245
+ if ( true === $result ) {
4246
+ self::shoot_ajax_success();
4247
+ }
4248
+
4249
+ $this->_logger->api_error( $result );
4250
+
4251
+ self::shoot_ajax_failure(
4252
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
4253
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
4254
+ $result->error->message :
4255
+ var_export( $result, true ) )
4256
+ );
4257
+ }
4258
+
4259
+ /**
4260
+ * Opt-out from usage tracking.
4261
+ *
4262
+ * Note: This will not delete the account information but will stop all tracking.
4263
+ *
4264
+ * Returns:
4265
+ * 1. FALSE - If the user never opted-in.
4266
+ * 2. TRUE - If successfully opted-out.
4267
+ * 3. object - API result on failure.
4268
+ *
4269
+ * @author Leo Fajardo (@leorw)
4270
+ * @since 1.2.1.5
4271
+ *
4272
+ * @return bool|object
4273
+ */
4274
+ function stop_site_tracking() {
4275
+ $this->_logger->entrance();
4276
+
4277
+ if ( ! $this->is_registered() ) {
4278
+ // User never opted-in.
4279
+ return false;
4280
+ }
4281
+
4282
+ if ( $this->is_tracking_prohibited() ) {
4283
+ // Already disconnected.
4284
+ return true;
4285
+ }
4286
+
4287
+ // Send update to FS.
4288
+ $result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
4289
+ 'is_disconnected' => true
4290
+ ) );
4291
+
4292
+ if ( ! $this->is_api_result_entity( $result ) ||
4293
+ ! isset( $result->is_disconnected ) ||
4294
+ ! $result->is_disconnected
4295
+ ) {
4296
+ $this->_logger->api_error( $result );
4297
+
4298
+ return $result;
4299
+ }
4300
+
4301
+ $this->_site->is_disconnected = $result->is_disconnected;
4302
+ $this->_store_site();
4303
+
4304
+ $this->clear_sync_cron();
4305
+
4306
+ // Successfully disconnected.
4307
+ return true;
4308
+ }
4309
+
4310
+ /**
4311
+ * Opt-out network from usage tracking.
4312
+ *
4313
+ * Note: This will not delete the account information but will stop all tracking.
4314
+ *
4315
+ * Returns:
4316
+ * 1. FALSE - If the user never opted-in.
4317
+ * 2. TRUE - If successfully opted-out.
4318
+ * 3. object - API result on failure.
4319
+ *
4320
+ * @author Leo Fajardo (@leorw)
4321
+ * @since 1.2.1.5
4322
+ *
4323
+ * @return bool|object
4324
+ */
4325
+ function stop_network_tracking() {
4326
+ $this->_logger->entrance();
4327
+
4328
+ if ( ! $this->is_registered() ) {
4329
+ // User never opted-in.
4330
+ return false;
4331
+ }
4332
+
4333
+ $install_id_2_blog_id = array();
4334
+ $installs_map = $this->get_blog_install_map();
4335
+
4336
+ $opt_out_all = true;
4337
+
4338
+ $params = array();
4339
+ foreach ( $installs_map as $blog_id => $install ) {
4340
+ if ( $install->is_tracking_prohibited() ) {
4341
+ // Already opted-out.
4342
+ continue;
4343
+ }
4344
+
4345
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
4346
+ // Opt-out only from non-delegated installs.
4347
+ $opt_out_all = false;
4348
+ continue;
4349
+ }
4350
+
4351
+ $params[] = array( 'id' => $install->id );
4352
+
4353
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
4354
+ }
4355
+
4356
+ if ( empty( $install_id_2_blog_id ) ) {
4357
+ return true;
4358
+ }
4359
+
4360
+ $params[] = array( 'is_disconnected' => true );
4361
+
4362
+ // Send update to FS.
4363
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
4364
+
4365
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
4366
+ $this->_logger->api_error( $result );
4367
+
4368
+ return $result;
4369
+ }
4370
+
4371
+ foreach ( $result->installs as $r_install ) {
4372
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
4373
+ $install = $installs_map[ $blog_id ];
4374
+ $install->is_disconnected = $r_install->is_disconnected;
4375
+ $this->_store_site( true, $blog_id, $install );
4376
+ }
4377
+
4378
+ $this->clear_sync_cron( $opt_out_all );
4379
+
4380
+ // Successfully disconnected.
4381
+ return true;
4382
+ }
4383
+
4384
+ /**
4385
+ * Opt-out from usage tracking.
4386
+ *
4387
+ * Note: This will not delete the account information but will stop all tracking.
4388
+ *
4389
+ * Returns:
4390
+ * 1. FALSE - If the user never opted-in.
4391
+ * 2. TRUE - If successfully opted-out.
4392
+ * 3. object - API result on failure.
4393
+ *
4394
+ * @author Leo Fajardo (@leorw)
4395
+ * @since 1.2.1.5
4396
+ *
4397
+ * @param bool $is_network_action
4398
+ *
4399
+ * @return bool|object
4400
+ */
4401
+ function stop_tracking( $is_network_action = false ) {
4402
+ $this->_logger->entrance();
4403
+
4404
+ return $is_network_action ?
4405
+ $this->stop_network_tracking() :
4406
+ $this->stop_site_tracking();
4407
+ }
4408
+
4409
+ /**
4410
+ * Opt-in back into usage tracking.
4411
+ *
4412
+ * Note: This will only work if the user opted-in previously.
4413
+ *
4414
+ * Returns:
4415
+ * 1. FALSE - If the user never opted-in.
4416
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4417
+ * 3. object - API result on failure.
4418
+ *
4419
+ * @author Leo Fajardo (@leorw)
4420
+ * @since 1.2.1.5
4421
+ *
4422
+ * @return bool|object
4423
+ */
4424
+ function allow_site_tracking() {
4425
+ $this->_logger->entrance();
4426
+
4427
+ if ( ! $this->is_registered() ) {
4428
+ // User never opted-in.
4429
+ return false;
4430
+ }
4431
+
4432
+ if ( $this->is_tracking_allowed() ) {
4433
+ // Tracking already allowed.
4434
+ return true;
4435
+ }
4436
+
4437
+ $result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
4438
+ 'is_disconnected' => false
4439
+ ) );
4440
+
4441
+ if ( ! $this->is_api_result_entity( $result ) ||
4442
+ ! isset( $result->is_disconnected ) ||
4443
+ $result->is_disconnected
4444
+ ) {
4445
+ $this->_logger->api_error( $result );
4446
+
4447
+ return $result;
4448
+ }
4449
+
4450
+ $this->_site->is_disconnected = $result->is_disconnected;
4451
+ $this->_store_site();
4452
+
4453
+ $this->schedule_sync_cron();
4454
+
4455
+ // Successfully reconnected.
4456
+ return true;
4457
+ }
4458
+
4459
+ /**
4460
+ * Opt-in network back into usage tracking.
4461
+ *
4462
+ * Note: This will only work if the user opted-in previously.
4463
+ *
4464
+ * Returns:
4465
+ * 1. FALSE - If the user never opted-in.
4466
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4467
+ * 3. object - API result on failure.
4468
+ *
4469
+ * @author Leo Fajardo (@leorw)
4470
+ * @since 1.2.1.5
4471
+ *
4472
+ * @return bool|object
4473
+ */
4474
+ function allow_network_tracking() {
4475
+ $this->_logger->entrance();
4476
+
4477
+ if ( ! $this->is_registered() ) {
4478
+ // User never opted-in.
4479
+ return false;
4480
+ }
4481
+
4482
+ $install_id_2_blog_id = array();
4483
+ $installs_map = $this->get_blog_install_map();
4484
+
4485
+ $params = array();
4486
+ foreach ( $installs_map as $blog_id => $install ) {
4487
+ if ( $install->is_tracking_allowed() ) {
4488
+ continue;
4489
+ }
4490
+
4491
+ $params[] = array( 'id' => $install->id );
4492
+
4493
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
4494
+ }
4495
+
4496
+ if ( empty( $install_id_2_blog_id ) ) {
4497
+ return true;
4498
+ }
4499
+
4500
+ $params[] = array( 'is_disconnected' => false );
4501
+
4502
+ // Send update to FS.
4503
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
4504
+
4505
+
4506
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
4507
+ $this->_logger->api_error( $result );
4508
+
4509
+ return $result;
4510
+ }
4511
+
4512
+ foreach ( $result->installs as $r_install ) {
4513
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
4514
+ $install = $installs_map[ $blog_id ];
4515
+ $install->is_disconnected = $r_install->is_disconnected;
4516
+ $this->_store_site( true, $blog_id, $install );
4517
+ }
4518
+
4519
+ $this->schedule_sync_cron();
4520
+
4521
+ // Successfully reconnected.
4522
+ return true;
4523
+ }
4524
+
4525
+ /**
4526
+ * Opt-in back into usage tracking.
4527
+ *
4528
+ * Note: This will only work if the user opted-in previously.
4529
+ *
4530
+ * Returns:
4531
+ * 1. FALSE - If the user never opted-in.
4532
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4533
+ * 3. object - API result on failure.
4534
+ *
4535
+ * @author Leo Fajardo (@leorw)
4536
+ * @since 1.2.1.5
4537
+ *
4538
+ * @param bool $is_network_action
4539
+ *
4540
+ * @return bool|object
4541
+ */
4542
+ function allow_tracking( $is_network_action = false ) {
4543
+ $this->_logger->entrance();
4544
+
4545
+ return $is_network_action ?
4546
+ $this->allow_network_tracking() :
4547
+ $this->allow_site_tracking();
4548
+ }
4549
+
4550
+ /**
4551
+ * If user opted-in and later disabled usage-tracking,
4552
+ * re-allow tracking for licensing and updates.
4553
+ *
4554
+ * @author Leo Fajardo (@leorw)
4555
+ * @since 1.2.1.5
4556
+ *
4557
+ * @param bool $is_context_single_site
4558
+ */
4559
+ private function reconnect_locally( $is_context_single_site = false ) {
4560
+ $this->_logger->entrance();
4561
+
4562
+ if ( ! $this->is_registered() ) {
4563
+ return;
4564
+ }
4565
+
4566
+ if ( ! fs_is_network_admin() || $is_context_single_site ) {
4567
+ if ( $this->is_tracking_prohibited() ) {
4568
+ $this->_site->is_disconnected = false;
4569
+ $this->_store_site();
4570
+ }
4571
+ } else {
4572
+ $installs_map = $this->get_blog_install_map();
4573
+ foreach ( $installs_map as $blog_id => $install ) {
4574
+ /**
4575
+ * @var FS_Site $install
4576
+ */
4577
+ if ( $install->is_tracking_prohibited() ) {
4578
+ $install->is_disconnected = false;
4579
+ $this->_store_site( true, $blog_id, $install );
4580
+ }
4581
+ }
4582
+ }
4583
+ }
4584
+
4585
+ /**
4586
+ * Parse plugin's settings (as defined by the plugin dev).
4587
+ *
4588
+ * @author Vova Feldman (@svovaf)
4589
+ * @since 1.1.7.3
4590
+ *
4591
+ * @param array $plugin_info
4592
+ *
4593
+ * @throws \Freemius_Exception
4594
+ */
4595
+ private function parse_settings( &$plugin_info ) {
4596
+ $this->_logger->entrance();
4597
+
4598
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
4599
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
4600
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
4601
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
4602
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
4603
+
4604
+ /**
4605
+ * @author Vova Feldman (@svovaf)
4606
+ * @since 1.1.9 Try to pull secret key from external config.
4607
+ */
4608
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
4609
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
4610
+ }
4611
+
4612
+ if ( isset( $plugin_info['parent'] ) ) {
4613
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
4614
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
4615
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
4616
+ // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
4617
+ }
4618
+
4619
+ if ( false === $id ) {
4620
+ throw new Freemius_Exception( array(
4621
+ 'error' => array(
4622
+ 'type' => 'ParameterNotSet',
4623
+ 'message' => 'Plugin id parameter is not set.',
4624
+ 'code' => 'plugin_id_not_set',
4625
+ 'http' => 500,
4626
+ )
4627
+ ) );
4628
+ }
4629
+ if ( false === $public_key ) {
4630
+ throw new Freemius_Exception( array(
4631
+ 'error' => array(
4632
+ 'type' => 'ParameterNotSet',
4633
+ 'message' => 'Plugin public_key parameter is not set.',
4634
+ 'code' => 'plugin_public_key_not_set',
4635
+ 'http' => 500,
4636
+ )
4637
+ ) );
4638
+ }
4639
+
4640
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
4641
+ $this->_plugin :
4642
+ new FS_Plugin();
4643
+
4644
+ $plugin->update( array(
4645
+ 'id' => $id,
4646
+ 'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
4647
+ 'public_key' => $public_key,
4648
+ 'slug' => $this->_slug,
4649
+ 'parent_plugin_id' => $parent_id,
4650
+ 'version' => $this->get_plugin_version(),
4651
+ 'title' => $this->get_plugin_name(),
4652
+ 'file' => $this->_plugin_basename,
4653
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
4654
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
4655
+ 'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
4656
+ ) );
4657
+
4658
+ if ( $plugin->is_updated() ) {
4659
+ // Update plugin details.
4660
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
4661
+ }
4662
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
4663
+ $this->_plugin->secret_key = $secret_key;
4664
+
4665
+ if ( ! isset( $plugin_info['menu'] ) ) {
4666
+ $plugin_info['menu'] = array();
4667
+
4668
+ if ( ! empty( $this->_storage->sdk_last_version ) &&
4669
+ version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
4670
+ ) {
4671
+ // Backward compatibility to 1.1.2
4672
+ $plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
4673
+ $plugin_info['menu_slug'] :
4674
+ $this->_slug;
4675
+ }
4676
+ }
4677
+
4678
+ $this->_menu = FS_Admin_Menu_Manager::instance(
4679
+ $this->_module_id,
4680
+ $this->_module_type,
4681
+ $this->get_unique_affix()
4682
+ );
4683
+
4684
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
4685
+
4686
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
4687
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
4688
+ $this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
4689
+ $this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
4690
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
4691
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
4692
+ if ( $this->_is_premium_only ) {
4693
+ // If premium only plugin, disable anonymous mode.
4694
+ $this->_enable_anonymous = false;
4695
+ $this->_anonymous_mode = false;
4696
+ } else {
4697
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
4698
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
4699
+ }
4700
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
4701
+
4702
+ if ( ! empty( $plugin_info['trial'] ) ) {
4703
+ $this->_trial_days = $this->get_numeric_option(
4704
+ $plugin_info['trial'],
4705
+ 'days',
4706
+ // Default to 0 - trial without days specification.
4707
+ 0
4708
+ );
4709
+
4710
+ $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
4711
+ }
4712
+ }
4713
+
4714
+ /**
4715
+ * @param string[] $options
4716
+ * @param string $key
4717
+ * @param mixed $default
4718
+ *
4719
+ * @return bool
4720
+ */
4721
+ private function get_option( &$options, $key, $default = false ) {
4722
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
4723
+ }
4724
+
4725
+ private function get_bool_option( &$options, $key, $default = false ) {
4726
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
4727
+ }
4728
+
4729
+ private function get_numeric_option( &$options, $key, $default = false ) {
4730
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
4731
+ }
4732
+
4733
+ /**
4734
+ * Gate keeper.
4735
+ *
4736
+ * @author Vova Feldman (@svovaf)
4737
+ * @since 1.1.7.3
4738
+ *
4739
+ * @return bool
4740
+ */
4741
+ private function should_stop_execution() {
4742
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
4743
+ /**
4744
+ * Don't execute Freemius until plugin was fully loaded at least once,
4745
+ * to give the opportunity for the activation hook to run before pinging
4746
+ * the API for connectivity test. This logic is relevant for the
4747
+ * identification of new plugin install vs. plugin update.
4748
+ *
4749
+ * @author Vova Feldman (@svovaf)
4750
+ * @since 1.1.9
4751
+ */
4752
+ return true;
4753
+ }
4754
+
4755
+ if ( $this->is_activation_mode() ) {
4756
+ if ( ! is_admin() ) {
4757
+ /**
4758
+ * If in activation mode, don't execute Freemius outside of the
4759
+ * admin dashboard.
4760
+ *
4761
+ * @author Vova Feldman (@svovaf)
4762
+ * @since 1.1.7.3
4763
+ */
4764
+ return true;
4765
+ }
4766
+
4767
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
4768
+ /**
4769
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
4770
+ * then don't start Freemius.
4771
+ *
4772
+ * @author Vova Feldman (@svovaf)
4773
+ * @since 1.1.6.3
4774
+ *
4775
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
4776
+ */
4777
+ return true;
4778
+ }
4779
+
4780
+ if ( self::is_cron() ) {
4781
+ /**
4782
+ * If in activation mode, don't execute Freemius during wp crons
4783
+ * (wp crons have HTTP context - called as HTTP request).
4784
+ *
4785
+ * @author Vova Feldman (@svovaf)
4786
+ * @since 1.1.7.3
4787
+ */
4788
+ return true;
4789
+ }
4790
+
4791
+ if ( self::is_ajax() &&
4792
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
4793
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
4794
+ ) {
4795
+ /**
4796
+ * During activation, if running in AJAX mode, unless there's a sticky
4797
+ * connectivity issue notice, don't run Freemius.
4798
+ *
4799
+ * @author Vova Feldman (@svovaf)
4800
+ * @since 1.1.7.3
4801
+ */
4802
+ return true;
4803
+ }
4804
+ }
4805
+
4806
+ return false;
4807
+ }
4808
+
4809
+ /**
4810
+ * Triggered after code type has changed.
4811
+ *
4812
+ * @author Vova Feldman (@svovaf)
4813
+ * @since 1.1.9.1
4814
+ */
4815
+ function _after_code_type_change() {
4816
+ $this->_logger->entrance();
4817
+
4818
+ if ( $this->is_theme() ) {
4819
+ // Expire the cache of the previous tabs since the theme may
4820
+ // have setting updates after code type has changed.
4821
+ $this->_cache->expire( 'tabs' );
4822
+ $this->_cache->expire( 'tabs_stylesheets' );
4823
+ }
4824
+
4825
+ if ( $this->is_registered() ) {
4826
+ if ( ! $this->is_addon() ) {
4827
+ add_action(
4828
+ is_admin() ? 'admin_init' : 'init',
4829
+ array( &$this, '_plugin_code_type_changed' )
4830
+ );
4831
+ }
4832
+
4833
+ if ( $this->is_premium() ) {
4834
+ // Purge cached payments after switching to the premium version.
4835
+ // @todo This logic doesn't handle purging the cache for serviceware module upgrade.
4836
+ $this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
4837
+ }
4838
+ }
4839
+ }
4840
+
4841
+ /**
4842
+ * Handles plugin's code type change (free <--> premium).
4843
+ *
4844
+ * @author Vova Feldman (@svovaf)
4845
+ * @since 1.0.9
4846
+ */
4847
+ function _plugin_code_type_changed() {
4848
+ $this->_logger->entrance();
4849
+
4850
+ if ( $this->is_premium() ) {
4851
+ $this->reconnect_locally();
4852
+
4853
+ // Activated premium code.
4854
+ $this->do_action( 'after_premium_version_activation' );
4855
+
4856
+ // Remove all sticky messages related to download of the premium version.
4857
+ $this->_admin_notices->remove_sticky( array(
4858
+ 'trial_started',
4859
+ 'plan_upgraded',
4860
+ 'plan_changed',
4861
+ 'license_activated',
4862
+ ) );
4863
+
4864
+ $notice = '';
4865
+ if ( ! $this->is_only_premium() ) {
4866
+ $notice = sprintf( $this->get_text_inline( 'Premium %s version was successfully activated.', 'premium-activated-message' ), $this->_module_type );
4867
+ }
4868
+
4869
+ $license_notice = $this->get_license_network_activation_notice();
4870
+ if ( ! empty( $license_notice ) ) {
4871
+ $notice .= ' ' . $license_notice;
4872
+ }
4873
+
4874
+ if ( ! empty( $notice ) ) {
4875
+ $this->_admin_notices->add_sticky(
4876
+ trim( $notice ),
4877
+ 'premium_activated',
4878
+ $this->get_text_x_inline( 'W00t',
4879
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
4880
+ );
4881
+ }
4882
+ } else {
4883
+ // Remove sticky message related to premium code activation.
4884
+ $this->_admin_notices->remove_sticky( 'premium_activated' );
4885
+
4886
+ // Activated free code (after had the premium before).
4887
+ $this->do_action( 'after_free_version_reactivation' );
4888
+
4889
+ if ( $this->is_paying() && ! $this->is_premium() ) {
4890
+ $this->_admin_notices->add_sticky(
4891
+ sprintf(
4892
+ /* translators: %s: License type (e.g. you have a professional license) */
4893
+ $this->get_text_inline( 'You have a %s license.', 'you-have-x-license' ),
4894
+ $this->get_plan_title()
4895
+ ) . $this->get_complete_upgrade_instructions(),
4896
+ 'plan_upgraded',
4897
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
4898
+ );
4899
+ }
4900
+ }
4901
+
4902
+ // Schedule code type changes event.
4903
+ $this->schedule_install_sync();
4904
+
4905
+ /**
4906
+ * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
4907
+ * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
4908
+ * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
4909
+ * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
4910
+ * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
4911
+ * free and premium versions are almost identical (same class or have same functions), a fatal error like
4912
+ * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
4913
+ */
4914
+ $this->unregister_uninstall_hook();
4915
+
4916
+ $this->clear_module_main_file_cache();
4917
+
4918
+ // Update is_premium of latest version.
4919
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
4920
+ }
4921
+
4922
+ #endregion
4923
+
4924
+ #----------------------------------------------------------------------------------
4925
+ #region Add-ons
4926
+ #----------------------------------------------------------------------------------
4927
+
4928
+ /**
4929
+ * Check if add-on installed and activated on site.
4930
+ *
4931
+ * @author Vova Feldman (@svovaf)
4932
+ * @since 1.0.6
4933
+ *
4934
+ * @param string|number $id_or_slug
4935
+ * @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
4936
+ *
4937
+ * @return bool
4938
+ */
4939
+ function is_addon_activated( $id_or_slug, $is_premium = null ) {
4940
+ $this->_logger->entrance();
4941
+
4942
+ $addon_id = self::get_module_id( $id_or_slug );
4943
+ $is_activated = self::has_instance( $addon_id );
4944
+
4945
+ if ( ! $is_activated ) {
4946
+ return false;
4947
+ }
4948
+
4949
+ if ( is_bool( $is_premium ) ) {
4950
+ // Check if the specified code version is activate.
4951
+ $addon = $this->get_addon_instance( $addon_id );
4952
+ $is_activated = ( $is_premium === $addon->is_premium() );
4953
+ }
4954
+
4955
+ return $is_activated;
4956
+ }
4957
+
4958
+ /**
4959
+ * Check if add-on was connected to install
4960
+ *
4961
+ * @author Vova Feldman (@svovaf)
4962
+ * @since 1.1.7
4963
+ *
4964
+ * @param string|number $id_or_slug
4965
+ *
4966
+ * @return bool
4967
+ */
4968
+ function is_addon_connected( $id_or_slug ) {
4969
+ $this->_logger->entrance();
4970
+
4971
+ $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
4972
+
4973
+ $addon_id = self::get_module_id( $id_or_slug );
4974
+ $addon = $this->get_addon( $addon_id );
4975
+ $slug = $addon->slug;
4976
+ if ( ! isset( $sites[ $slug ] ) ) {
4977
+ return false;
4978
+ }
4979
+
4980
+ $site = $sites[ $slug ];
4981
+
4982
+ $plugin = FS_Plugin_Manager::instance( $addon_id )->get();
4983
+
4984
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
4985
+ // The given slug do NOT belong to any of the plugin's add-ons.
4986
+ return false;
4987
+ }
4988
+
4989
+ return ( is_object( $site ) &&
4990
+ is_numeric( $site->id ) &&
4991
+ is_numeric( $site->user_id ) &&
4992
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
4993
+ );
4994
+ }
4995
+
4996
+ /**
4997
+ * Determines if add-on installed.
4998
+ *
4999
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
5000
+ *
5001
+ * @author Vova Feldman (@svovaf)
5002
+ * @since 1.0.6
5003
+ *
5004
+ * @param string|number $id_or_slug
5005
+ *
5006
+ * @return bool
5007
+ */
5008
+ function is_addon_installed( $id_or_slug ) {
5009
+ $this->_logger->entrance();
5010
+
5011
+ $addon_id = self::get_module_id( $id_or_slug );
5012
+
5013
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
5014
+ }
5015
+
5016
+ /**
5017
+ * Get add-on basename.
5018
+ *
5019
+ * @author Vova Feldman (@svovaf)
5020
+ * @since 1.0.6
5021
+ *
5022
+ * @param string|number $id_or_slug
5023
+ *
5024
+ * @return string
5025
+ */
5026
+ function get_addon_basename( $id_or_slug ) {
5027
+ $addon_id = self::get_module_id( $id_or_slug );
5028
+
5029
+ if ( $this->is_addon_activated( $addon_id ) ) {
5030
+ return self::instance( $addon_id )->get_plugin_basename();
5031
+ }
5032
+
5033
+ $addon = $this->get_addon( $addon_id );
5034
+ $premium_basename = "{$addon->slug}-premium/{$addon->slug}.php";
5035
+
5036
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
5037
+ return $premium_basename;
5038
+ }
5039
+
5040
+ $all_plugins = $this->get_all_plugins();
5041
+
5042
+ foreach ( $all_plugins as $basename => &$data ) {
5043
+ if ( $addon->slug === $data['slug'] ||
5044
+ $addon->slug . '-premium' === $data['slug']
5045
+ ) {
5046
+ return $basename;
5047
+ }
5048
+ }
5049
+
5050
+ $free_basename = "{$addon->slug}/{$addon->slug}.php";
5051
+
5052
+ return $free_basename;
5053
+ }
5054
+
5055
+ /**
5056
+ * Get installed add-ons instances.
5057
+ *
5058
+ * @author Vova Feldman (@svovaf)
5059
+ * @since 1.0.6
5060
+ *
5061
+ * @return Freemius[]
5062
+ */
5063
+ function get_installed_addons() {
5064
+ $installed_addons = array();
5065
+ foreach ( self::$_instances as $instance ) {
5066
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
5067
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
5068
+ $installed_addons[] = $instance;
5069
+ }
5070
+ }
5071
+ }
5072
+
5073
+ return $installed_addons;
5074
+ }
5075
+
5076
+ /**
5077
+ * Check if any add-ons of the plugin are installed.
5078
+ *
5079
+ * @author Leo Fajardo (@leorw)
5080
+ * @since 1.1.1
5081
+ *
5082
+ * @return bool
5083
+ */
5084
+ function has_installed_addons() {
5085
+ if ( ! $this->has_addons() ) {
5086
+ return false;
5087
+ }
5088
+
5089
+ foreach ( self::$_instances as $instance ) {
5090
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
5091
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
5092
+ return true;
5093
+ }
5094
+ }
5095
+ }
5096
+
5097
+ return false;
5098
+ }
5099
+
5100
+ /**
5101
+ * Tell Freemius that the current plugin is an add-on.
5102
+ *
5103
+ * @author Vova Feldman (@svovaf)
5104
+ * @since 1.0.6
5105
+ *
5106
+ * @param number $parent_plugin_id The parent plugin ID
5107
+ */
5108
+ function init_addon( $parent_plugin_id ) {
5109
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
5110
+ }
5111
+
5112
+ /**
5113
+ * @author Vova Feldman (@svovaf)
5114
+ * @since 1.0.6
5115
+ *
5116
+ * @return bool
5117
+ */
5118
+ function is_addon() {
5119
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
5120
+ }
5121
+
5122
+ /**
5123
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
5124
+ *
5125
+ * @param bool $is_after_trial_cancel
5126
+ *
5127
+ * @return bool If add-on was deactivated.
5128
+ */
5129
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
5130
+ if ( ! $this->has_free_plan() &&
5131
+ ! $this->has_features_enabled_license() &&
5132
+ ! $this->_has_premium_license()
5133
+ ) {
5134
+ if ( $this->is_registered() ) {
5135
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
5136
+ // if (empty($this->_storage->activation_timestamp) ||
5137
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
5138
+ // ) {
5139
+ /**
5140
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
5141
+ *
5142
+ * Retry syncing the user add-on licenses.
5143
+ */
5144
+ // Sync licenses.
5145
+ $this->_sync_licenses();
5146
+ // }
5147
+
5148
+ // Try to activate premium license.
5149
+ $this->_activate_license( true );
5150
+ }
5151
+
5152
+ if ( ! $this->has_free_plan() &&
5153
+ ! $this->has_features_enabled_license() &&
5154
+ ! $this->_has_premium_license()
5155
+ ) {
5156
+ // @todo Check if deactivate plugins also call the deactivation hook.
5157
+
5158
+ $this->_parent->_admin_notices->add_sticky(
5159
+ sprintf(
5160
+ ( $is_after_trial_cancel ?
5161
+ $this->_parent->get_text_inline(
5162
+ '%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.',
5163
+ 'addon-trial-cancelled-message'
5164
+ ) :
5165
+ $this->_parent->get_text_inline(
5166
+ '%s is a premium only add-on. You have to purchase a license first before activating the plugin.',
5167
+ 'addon-no-license-message'
5168
+ )
5169
+ ),
5170
+ '<b>' . $this->_plugin->title . '</b>'
5171
+ ) . ' ' . sprintf(
5172
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
5173
+ $this->_parent->addon_url( $this->_slug ),
5174
+ esc_attr( sprintf( $this->_parent->get_text_inline( 'More information about %s', 'more-information-about-x' ), $this->_plugin->title ) ),
5175
+ $this->_parent->get_text_inline( 'Purchase License', 'purchase-license' )
5176
+ ),
5177
+ 'no_addon_license_' . $this->_slug,
5178
+ ( $is_after_trial_cancel ? '' : $this->_parent->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' ),
5179
+ ( $is_after_trial_cancel ? 'success' : 'error' )
5180
+ );
5181
+
5182
+ deactivate_plugins( array( $this->_plugin_basename ), true );
5183
+
5184
+ return true;
5185
+ }
5186
+ }
5187
+
5188
+ return false;
5189
+ }
5190
+
5191
+ #endregion
5192
+
5193
+ #----------------------------------------------------------------------------------
5194
+ #region Sandbox
5195
+ #----------------------------------------------------------------------------------
5196
+
5197
+ /**
5198
+ * Set Freemius into sandbox mode for debugging.
5199
+ *
5200
+ * @author Vova Feldman (@svovaf)
5201
+ * @since 1.0.4
5202
+ *
5203
+ * @param string $secret_key
5204
+ */
5205
+ function init_sandbox( $secret_key ) {
5206
+ $this->_plugin->secret_key = $secret_key;
5207
+
5208
+ // Update plugin details.
5209
+ FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
5210
+ }
5211
+
5212
+ /**
5213
+ * Check if running payments in sandbox mode.
5214
+ *
5215
+ * @author Vova Feldman (@svovaf)
5216
+ * @since 1.0.4
5217
+ *
5218
+ * @return bool
5219
+ */
5220
+ function is_payments_sandbox() {
5221
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
5222
+ }
5223
+
5224
+ #endregion
5225
+
5226
+ /**
5227
+ * Check if running test vs. live plugin.
5228
+ *
5229
+ * @author Vova Feldman (@svovaf)
5230
+ * @since 1.0.5
5231
+ *
5232
+ * @return bool
5233
+ */
5234
+ function is_live() {
5235
+ return $this->_plugin->is_live;
5236
+ }
5237
+
5238
+ /**
5239
+ * Check if super-admin skipped connection for all sites in the network.
5240
+ *
5241
+ * @author Vova Feldman (@svovaf)
5242
+ * @since 2.0.0
5243
+ */
5244
+ function is_network_anonymous() {
5245
+ if ( ! $this->_is_network_active ) {
5246
+ return false;
5247
+ }
5248
+
5249
+ $is_anonymous_ms = $this->_storage->get( 'is_anonymous_ms' );
5250
+
5251
+ if ( empty( $is_anonymous_ms ) ) {
5252
+ return false;
5253
+ }
5254
+
5255
+ return $is_anonymous_ms['is'];
5256
+ }
5257
+
5258
+ /**
5259
+ * Check if super-admin opted-in for all sites in the network.
5260
+ *
5261
+ * @author Vova Feldman (@svovaf)
5262
+ * @since 2.0.0
5263
+ */
5264
+ function is_network_connected() {
5265
+ if ( ! $this->_is_network_active ) {
5266
+ return false;
5267
+ }
5268
+
5269
+ return $this->_storage->get( 'is_network_connected' );
5270
+ }
5271
+
5272
+ /**
5273
+ * Check if the user skipped connecting the account with Freemius.
5274
+ *
5275
+ * @author Vova Feldman (@svovaf)
5276
+ * @since 1.0.7
5277
+ *
5278
+ * @return bool
5279
+ */
5280
+ function is_anonymous() {
5281
+ if ( ! isset( $this->_is_anonymous ) ) {
5282
+ if ( $this->is_network_anonymous() ) {
5283
+ $this->_is_anonymous = true;
5284
+ } else {
5285
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
5286
+ // Not skipped.
5287
+ $this->_is_anonymous = false;
5288
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
5289
+ // For back compatibility, since the variable was boolean before.
5290
+ $this->_is_anonymous = $this->_storage->is_anonymous;
5291
+
5292
+ // Upgrade stored data format to 1.1.3 format.
5293
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
5294
+ } else {
5295
+ // Version 1.1.3 and later.
5296
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
5297
+ }
5298
+ }
5299
+ }
5300
+
5301
+ return $this->_is_anonymous;
5302
+ }
5303
+
5304
+ /**
5305
+ * Check if the user skipped the connection of a specified site.
5306
+ *
5307
+ * @author Vova Feldman (@svovaf)
5308
+ * @since 2.0.0
5309
+ *
5310
+ * @param int $blog_id
5311
+ *
5312
+ * @return bool
5313
+ */
5314
+ function is_anonymous_site( $blog_id = 0 ) {
5315
+ if ( $this->is_network_anonymous() ) {
5316
+ return true;
5317
+ }
5318
+
5319
+ $is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
5320
+
5321
+ if ( empty( $is_anonymous ) ) {
5322
+ return false;
5323
+ }
5324
+
5325
+ return $is_anonymous['is'];
5326
+ }
5327
+
5328
+ /**
5329
+ * Check if user connected his account and install pending email activation.
5330
+ *
5331
+ * @author Vova Feldman (@svovaf)
5332
+ * @since 1.0.7
5333
+ *
5334
+ * @return bool
5335
+ */
5336
+ function is_pending_activation() {
5337
+ return $this->_storage->get( 'is_pending_activation', false );
5338
+ }
5339
+
5340
+ /**
5341
+ * Check if plugin must be WordPress.org compliant.
5342
+ *
5343
+ * @since 1.0.7
5344
+ *
5345
+ * @return bool
5346
+ */
5347
+ function is_org_repo_compliant() {
5348
+ return $this->_is_org_compliant;
5349
+ }
5350
+
5351
+ #--------------------------------------------------------------------------------
5352
+ #region WP Cron Common
5353
+ #--------------------------------------------------------------------------------
5354
+
5355
+ /**
5356
+ * @author Vova Feldman (@svovaf)
5357
+ * @since 2.0.0
5358
+ *
5359
+ * @param string $name Cron name.
5360
+ *
5361
+ * @return object
5362
+ */
5363
+ private function get_cron_data( $name ) {
5364
+ $this->_logger->entrance( $name );
5365
+
5366
+ /**
5367
+ * @var object $cron_data
5368
+ */
5369
+ return $this->_storage->get( "{$name}_cron", null );
5370
+ }
5371
+
5372
+ /**
5373
+ * @author Vova Feldman (@svovaf)
5374
+ * @since 2.0.0
5375
+ *
5376
+ * @param string $name Cron name.
5377
+ */
5378
+ private function clear_cron_data( $name ) {
5379
+ $this->_logger->entrance( $name );
5380
+
5381
+ $this->_storage->remove( "{$name}_cron" );
5382
+ }
5383
+
5384
+ /**
5385
+ * @author Vova Feldman (@svovaf)
5386
+ * @since 2.0.0
5387
+ *
5388
+ * @param string $name Cron name.
5389
+ * @param int $cron_blog_id The cron executing blog ID.
5390
+ */
5391
+ private function set_cron_data( $name, $cron_blog_id = 0 ) {
5392
+ $this->_logger->entrance( $name );
5393
+
5394
+ $this->_storage->store( "{$name}_cron", (object) array(
5395
+ 'version' => $this->get_plugin_version(),
5396
+ 'blog_id' => $cron_blog_id,
5397
+ 'sdk_version' => $this->version,
5398
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
5399
+ 'on' => true,
5400
+ ) );
5401
+ }
5402
+
5403
+ /**
5404
+ * Get the cron's executing blog ID.
5405
+ *
5406
+ * @author Vova Feldman (@svovaf)
5407
+ * @since 2.0.0
5408
+ *
5409
+ * @param string $name Cron name.
5410
+ *
5411
+ * @return int
5412
+ */
5413
+ private function get_cron_blog_id( $name ) {
5414
+ $this->_logger->entrance( $name );
5415
+
5416
+ /**
5417
+ * @var object $cron_data
5418
+ */
5419
+ $cron_data = $this->get_cron_data( $name );
5420
+
5421
+ return ( is_object( $cron_data ) && is_numeric( $cron_data->blog_id ) ) ?
5422
+ $cron_data->blog_id :
5423
+ 0;
5424
+ }
5425
+
5426
+ /**
5427
+ * @author Vova Feldman (@svovaf)
5428
+ * @since 2.0.0
5429
+ *
5430
+ * @param string $name Cron name.
5431
+ *
5432
+ * @return bool
5433
+ */
5434
+ private function is_cron_on( $name ) {
5435
+ $this->_logger->entrance( $name );
5436
+
5437
+ /**
5438
+ * @var object $cron_data
5439
+ */
5440
+ $cron_data = $this->get_cron_data( $name );
5441
+
5442
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
5443
+ }
5444
+
5445
+ /**
5446
+ * Unix timestamp for previous cron execution or false if never executed.
5447
+ *
5448
+ * @author Vova Feldman (@svovaf)
5449
+ * @since 2.0.0
5450
+ *
5451
+ * @param string $name Cron name.
5452
+ *
5453
+ * @return int|false
5454
+ */
5455
+ private function cron_last_execution( $name ) {
5456
+ $this->_logger->entrance( $name );
5457
+
5458
+ return $this->_storage->get( "{$name}_timestamp" );
5459
+ }
5460
+
5461
+ /**
5462
+ * Set cron execution time to now.
5463
+ *
5464
+ * @author Vova Feldman (@svovaf)
5465
+ * @since 2.0.0
5466
+ *
5467
+ * @param string $name Cron name.
5468
+ */
5469
+ private function set_cron_execution_timestamp( $name ) {
5470
+ $this->_logger->entrance( $name );
5471
+
5472
+ $this->_storage->store( "{$name}_timestamp", time() );
5473
+ }
5474
+
5475
+ /**
5476
+ * Check if cron was executed in the last $period of seconds.
5477
+ *
5478
+ * @author Vova Feldman (@svovaf)
5479
+ * @since 2.0.0
5480
+ *
5481
+ * @param string $name Cron name.
5482
+ * @param int $period In seconds
5483
+ *
5484
+ * @return bool
5485
+ */
5486
+ private function is_cron_executed( $name, $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
5487
+ $this->_logger->entrance( $name );
5488
+
5489
+ $last_execution = $this->set_cron_execution_timestamp( $name );
5490
+
5491
+ if ( ! is_numeric( $last_execution ) ) {
5492
+ return false;
5493
+ }
5494
+
5495
+ return ( $last_execution > ( WP_FS__SCRIPT_START_TIME - $period ) );
5496
+ }
5497
+
5498
+ /**
5499
+ * WP Cron is executed on a site level. When running in a multisite network environment
5500
+ * with the network integration activated, for optimization reasons, we are consolidating
5501
+ * the installs data sync cron to be executed only from a single site.
5502
+ *
5503
+ * @author Vova Feldman (@svovaf)
5504
+ * @since 2.0.0
5505
+ *
5506
+ * @param int $except_blog_id Target any except the excluded blog ID.
5507
+ *
5508
+ * @return int
5509
+ */
5510
+ private function get_cron_target_blog_id( $except_blog_id = 0 ) {
5511
+ if ( ! is_multisite() ) {
5512
+ return 0;
5513
+ }
5514
+
5515
+ if ( $this->_is_network_active &&
5516
+ is_numeric( $this->_storage->network_install_blog_id ) &&
5517
+ $except_blog_id != $this->_storage->network_install_blog_id &&
5518
+ self::is_site_active( $this->_storage->network_install_blog_id )
5519
+ ) {
5520
+ // Try to run cron from the main network blog.
5521
+ $install = $this->get_install_by_blog_id( $this->_storage->network_install_blog_id );
5522
+
5523
+ if ( is_object( $install ) &&
5524
+ ( $this->is_premium() || $install->is_tracking_allowed() )
5525
+ ) {
5526
+ return $this->_storage->network_install_blog_id;
5527
+ }
5528
+ }
5529
+
5530
+ // Get first opted-in blog ID with active tracking.
5531
+ $installs = $this->get_blog_install_map();
5532
+ foreach ( $installs as $blog_id => $install ) {
5533
+ if ( $except_blog_id != $blog_id &&
5534
+ self::is_site_active( $blog_id ) &&
5535
+ ( $this->is_premium() || $install->is_tracking_allowed() )
5536
+ ) {
5537
+ return $blog_id;
5538
+ }
5539
+ }
5540
+
5541
+ return 0;
5542
+ }
5543
+
5544
+ /**
5545
+ * @author Vova Feldman (@svovaf)
5546
+ * @since 2.0.0
5547
+ *
5548
+ * @param string $name Cron name.
5549
+ * @param string $action_tag Callback action tag.
5550
+ * @param bool $is_network_clear If set to TRUE, clear sync cron even if there are installs that are still connected.
5551
+ */
5552
+ private function clear_cron( $name, $action_tag = '', $is_network_clear = false ) {
5553
+ $this->_logger->entrance( $name );
5554
+
5555
+ if ( ! $this->is_cron_on( $name ) ) {
5556
+ return;
5557
+ }
5558
+
5559
+ $clear_cron = true;
5560
+ if ( ! $is_network_clear && $this->_is_network_active ) {
5561
+ $installs = $this->get_blog_install_map();
5562
+
5563
+ foreach ( $installs as $blog_id => $install ) {
5564
+ /**
5565
+ * @var FS_Site $install
5566
+ */
5567
+ if ( $install->is_tracking_allowed() ) {
5568
+ $clear_cron = false;
5569
+ break;
5570
+ }
5571
+ }
5572
+ }
5573
+
5574
+ if ( ! $clear_cron ) {
5575
+ return;
5576
+ }
5577
+
5578
+ /**
5579
+ * @var object $cron_data
5580
+ */
5581
+ $cron_data = $this->get_cron_data( $name );
5582
+
5583
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
5584
+ $cron_data->blog_id :
5585
+ 0;
5586
+
5587
+ $this->clear_cron_data( $name );
5588
+
5589
+ if ( 0 < $cron_blog_id ) {
5590
+ switch_to_blog( $cron_blog_id );
5591
+ }
5592
+
5593
+ if ( empty( $action_tag ) ) {
5594
+ $action_tag = $name;
5595
+ }
5596
+
5597
+ wp_clear_scheduled_hook( $this->get_action_tag( $action_tag ) );
5598
+
5599
+ if ( 0 < $cron_blog_id ) {
5600
+ restore_current_blog();
5601
+ }
5602
+ }
5603
+
5604
+ /**
5605
+ * Unix timestamp for next cron execution or false if not scheduled.
5606
+ *
5607
+ * @author Vova Feldman (@svovaf)
5608
+ * @since 2.0.0
5609
+ *
5610
+ * @param string $name Cron name.
5611
+ * @param string $action_tag Callback action tag.
5612
+ *
5613
+ * @return int|false
5614
+ */
5615
+ private function get_next_scheduled_cron( $name, $action_tag = '' ) {
5616
+ $this->_logger->entrance( $name );
5617
+
5618
+ if ( ! $this->is_cron_on( $name ) ) {
5619
+ return false;
5620
+ }
5621
+
5622
+ /**
5623
+ * @var object $cron_data
5624
+ */
5625
+ $cron_data = $this->get_cron_data( $name );
5626
+
5627
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
5628
+ $cron_data->blog_id :
5629
+ 0;
5630
+
5631
+ if ( 0 < $cron_blog_id ) {
5632
+ switch_to_blog( $cron_blog_id );
5633
+ }
5634
+
5635
+ if ( empty( $action_tag ) ) {
5636
+ $action_tag = $name;
5637
+ }
5638
+
5639
+ $next_scheduled = wp_next_scheduled( $this->get_action_tag( $action_tag ) );
5640
+
5641
+ if ( 0 < $cron_blog_id ) {
5642
+ restore_current_blog();
5643
+ }
5644
+
5645
+ return $next_scheduled;
5646
+ }
5647
+
5648
+ /**
5649
+ * @author Vova Feldman (@svovaf)
5650
+ * @since 2.0.0
5651
+ *
5652
+ * @param string $name Cron name.
5653
+ * @param string $action_tag Callback action tag.
5654
+ * @param string $recurrence 'single' or 'daily'.
5655
+ * @param int $start_at Defaults to now.
5656
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
5657
+ * @param int $except_blog_id Target any except the excluded blog ID.
5658
+ */
5659
+ private function schedule_cron(
5660
+ $name,
5661
+ $action_tag = '',
5662
+ $recurrence = 'single',
5663
+ $start_at = WP_FS__SCRIPT_START_TIME,
5664
+ $randomize_start = true,
5665
+ $except_blog_id = 0
5666
+ ) {
5667
+ $this->_logger->entrance( $name );
5668
+
5669
+ $this->clear_cron( $name, $action_tag, true );
5670
+
5671
+ $cron_blog_id = $this->get_cron_target_blog_id( $except_blog_id );
5672
+
5673
+ if ( is_multisite() && 0 == $cron_blog_id ) {
5674
+ // Don't schedule cron since couldn't find a target blog.
5675
+ return;
5676
+ }
5677
+
5678
+ if ( 0 < $cron_blog_id ) {
5679
+ switch_to_blog( $cron_blog_id );
5680
+ }
5681
+
5682
+ if ( 'daily' === $recurrence ) {
5683
+ if ( $randomize_start ) {
5684
+ // Schedule first sync with a random 12 hour time range from now.
5685
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
5686
+ }
5687
+
5688
+ // Schedule daily WP cron.
5689
+ wp_schedule_event(
5690
+ $start_at,
5691
+ 'daily',
5692
+ $this->get_action_tag( $action_tag )
5693
+ );
5694
+ } else if ( 'single' === $recurrence ) {
5695
+ // Schedule single cron.
5696
+ wp_schedule_single_event(
5697
+ $start_at,
5698
+ $this->get_action_tag( $action_tag )
5699
+ );
5700
+ }
5701
+
5702
+ $this->set_cron_data( $name, $cron_blog_id );
5703
+
5704
+ if ( 0 < $cron_blog_id ) {
5705
+ restore_current_blog();
5706
+ }
5707
+ }
5708
+
5709
+ /**
5710
+ * Consolidated cron execution for performance optimization. The max number of API requests is based on the number of unique opted-in users.
5711
+ * that doesn't halt page loading.
5712
+ *
5713
+ * @author Vova Feldman (@svovaf)
5714
+ * @since 2.0.0
5715
+ *
5716
+ * @param string $name Cron name.
5717
+ * @param callable $callable The function that should be executed.
5718
+ */
5719
+ private function execute_cron( $name, $callable ) {
5720
+ $this->_logger->entrance( $name );
5721
+
5722
+ // Store the last time data sync was executed.
5723
+ $this->set_cron_execution_timestamp( $name );
5724
+
5725
+ // Check if API is temporary down.
5726
+ if ( FS_Api::is_temporary_down() ) {
5727
+ return;
5728
+ }
5729
+
5730
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
5731
+
5732
+ $users_2_blog_ids = array();
5733
+
5734
+ if ( ! is_multisite() ) {
5735
+ // Add dummy blog.
5736
+ $users_2_blog_ids[0] = array( 0 );
5737
+ } else {
5738
+ $installs = $this->get_blog_install_map();
5739
+ foreach ( $installs as $blog_id => $install ) {
5740
+ if ( $this->is_premium() || $install->is_tracking_allowed() ) {
5741
+ if ( ! isset( $users_2_blog_ids[ $install->user_id ] ) ) {
5742
+ $users_2_blog_ids[ $install->user_id ] = array();
5743
+ }
5744
+
5745
+ $users_2_blog_ids[ $install->user_id ][] = $blog_id;
5746
+ }
5747
+ }
5748
+ }
5749
+
5750
+ foreach ( $users_2_blog_ids as $user_id => $blog_ids ) {
5751
+ if ( 0 < $blog_ids[0] ) {
5752
+ $this->switch_to_blog( $blog_ids[0] );
5753
+ }
5754
+
5755
+ call_user_func_array( $callable, array( $blog_ids ) );
5756
+
5757
+ foreach ( $blog_ids as $blog_id ) {
5758
+ $this->do_action( "after_{$name}_cron", $blog_id );
5759
+ }
5760
+ }
5761
+
5762
+ if ( is_multisite() ) {
5763
+ $this->do_action( "after_{$name}_cron_multisite" );
5764
+ }
5765
+ }
5766
+
5767
+ #endregion
5768
+
5769
+ #----------------------------------------------------------------------------------
5770
+ #region Daily Sync Cron
5771
+ #----------------------------------------------------------------------------------
5772
+
5773
+
5774
+ /**
5775
+ * @author Vova Feldman (@svovaf)
5776
+ * @since 2.0.0
5777
+ *
5778
+ * @return bool
5779
+ */
5780
+ private function is_sync_cron_scheduled() {
5781
+ return $this->is_cron_on( 'sync' );
5782
+ }
5783
+
5784
+ /**
5785
+ * Get the sync cron's executing blog ID.
5786
+ *
5787
+ * @author Vova Feldman (@svovaf)
5788
+ * @since 2.0.0
5789
+ *
5790
+ * @return int
5791
+ */
5792
+ private function get_sync_cron_blog_id() {
5793
+ return $this->get_cron_blog_id( 'sync' );
5794
+ }
5795
+
5796
+ /**
5797
+ * @author Vova Feldman (@svovaf)
5798
+ * @since 1.1.7.3
5799
+ */
5800
+ private function run_manual_sync() {
5801
+ self::require_pluggable_essentials();
5802
+
5803
+ if ( ! $this->is_user_admin() ) {
5804
+ return;
5805
+ }
5806
+
5807
+ // Run manual sync.
5808
+ $this->_sync_cron();
5809
+
5810
+ // Reschedule next cron to run 24 hours from now (performance optimization).
5811
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
5812
+ }
5813
+
5814
+ /**
5815
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
5816
+ * that doesn't halt page loading.
5817
+ *
5818
+ * @author Vova Feldman (@svovaf)
5819
+ * @since 1.1.7.3
5820
+ * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
5821
+ */
5822
+ function _sync_cron() {
5823
+ $this->_logger->entrance();
5824
+
5825
+ $this->execute_cron( 'sync', array( &$this, '_sync_cron_method' ) );
5826
+ }
5827
+
5828
+ /**
5829
+ * The actual data sync cron logic.
5830
+ *
5831
+ * @author Vova Feldman (@svovaf)
5832
+ * @since 2.0.0
5833
+ *
5834
+ * @param int[] $blog_ids
5835
+ */
5836
+ function _sync_cron_method( array $blog_ids ) {
5837
+ if ( $this->is_registered() ) {
5838
+ if ( $this->has_paid_plan() ) {
5839
+ // Initiate background plan sync.
5840
+ $this->_sync_license( true );
5841
+
5842
+ if ( $this->is_paying() ) {
5843
+ // Check for premium plugin updates.
5844
+ $this->check_updates( true );
5845
+ }
5846
+ } else {
5847
+ // Sync install(s) (only if something changed locally).
5848
+ if ( 1 < count( $blog_ids ) ) {
5849
+ $this->sync_installs();
5850
+ } else {
5851
+ $this->sync_install();
5852
+ }
5853
+ }
5854
+ }
5855
+ }
5856
+
5857
+ /**
5858
+ * Check if sync was executed in the last $period of seconds.
5859
+ *
5860
+ * @author Vova Feldman (@svovaf)
5861
+ * @since 1.1.7.3
5862
+ *
5863
+ * @param int $period In seconds
5864
+ *
5865
+ * @return bool
5866
+ */
5867
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
5868
+ return $this->is_cron_executed( 'sync', $period );
5869
+ }
5870
+
5871
+ /**
5872
+ * @author Vova Feldman (@svovaf)
5873
+ * @since 1.1.7.3
5874
+ *
5875
+ * @return bool
5876
+ */
5877
+ private function is_sync_cron_on() {
5878
+ return $this->is_cron_on( 'sync' );
5879
+ }
5880
+
5881
+ /**
5882
+ * @author Vova Feldman (@svovaf)
5883
+ * @since 1.1.7.3
5884
+ *
5885
+ * @param int $start_at Defaults to now.
5886
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
5887
+ * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
5888
+ */
5889
+ private function schedule_sync_cron(
5890
+ $start_at = WP_FS__SCRIPT_START_TIME,
5891
+ $randomize_start = true,
5892
+ $except_blog_id = 0
5893
+ ) {
5894
+ $this->schedule_cron(
5895
+ 'sync',
5896
+ 'data_sync',
5897
+ 'daily',
5898
+ $start_at,
5899
+ $randomize_start,
5900
+ $except_blog_id
5901
+ );
5902
+ }
5903
+
5904
+ /**
5905
+ * Add the actual sync function to the cron job hook.
5906
+ *
5907
+ * @author Vova Feldman (@svovaf)
5908
+ * @since 1.1.7.3
5909
+ */
5910
+ private function hook_callback_to_sync_cron() {
5911
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
5912
+ }
5913
+
5914
+ /**
5915
+ * @author Vova Feldman (@svovaf)
5916
+ * @since 1.1.7.3
5917
+ *
5918
+ * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
5919
+ */
5920
+ private function clear_sync_cron( $is_network_clear = false ) {
5921
+ $this->_logger->entrance();
5922
+
5923
+ $this->clear_cron( 'sync', 'data_sync', $is_network_clear );
5924
+ }
5925
+
5926
+ /**
5927
+ * Unix timestamp for next sync cron execution or false if not scheduled.
5928
+ *
5929
+ * @author Vova Feldman (@svovaf)
5930
+ * @since 1.1.7.3
5931
+ *
5932
+ * @return int|false
5933
+ */
5934
+ function next_sync_cron() {
5935
+ return $this->get_next_scheduled_cron( 'sync', 'data_sync' );
5936
+ }
5937
+
5938
+ /**
5939
+ * Unix timestamp for previous sync cron execution or false if never executed.
5940
+ *
5941
+ * @author Vova Feldman (@svovaf)
5942
+ * @since 1.1.7.3
5943
+ *
5944
+ * @return int|false
5945
+ */
5946
+ function last_sync_cron() {
5947
+ return $this->cron_last_execution( 'sync' );
5948
+ }
5949
+
5950
+ #endregion Daily Sync Cron ------------------------------------------------------------------
5951
+
5952
+ #----------------------------------------------------------------------------------
5953
+ #region Async Install Sync
5954
+ #----------------------------------------------------------------------------------
5955
+
5956
+ /**
5957
+ * @author Vova Feldman (@svovaf)
5958
+ * @since 1.1.7.3
5959
+ *
5960
+ * @return bool
5961
+ */
5962
+ private function is_install_sync_scheduled() {
5963
+ return $this->is_cron_on( 'install_sync' );
5964
+ }
5965
+
5966
+ /**
5967
+ * Get the sync cron's executing blog ID.
5968
+ *
5969
+ * @author Vova Feldman (@svovaf)
5970
+ * @since 2.0.0
5971
+ *
5972
+ * @return int
5973
+ */
5974
+ private function get_install_sync_cron_blog_id() {
5975
+ return $this->get_cron_blog_id( 'install_sync' );
5976
+ }
5977
+
5978
+ /**
5979
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
5980
+ *
5981
+ * @author Vova Feldman (@svovaf)
5982
+ * @since 1.1.7.3
5983
+ *
5984
+ * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
5985
+ */
5986
+ private function schedule_install_sync( $except_blog_id = 0 ) {
5987
+ $this->schedule_cron( 'install_sync', 'install_sync', 'single', 0, false, $except_blog_id );
5988
+ }
5989
+
5990
+ /**
5991
+ * Unix timestamp for previous install sync cron execution or false if never executed.
5992
+ *
5993
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being updated. But for sure the sync event is working.
5994
+ *
5995
+ * @author Vova Feldman (@svovaf)
5996
+ * @since 1.1.7.3
5997
+ *
5998
+ * @return int|false
5999
+ */
6000
+ function last_install_sync() {
6001
+ return $this->cron_last_execution( 'install_sync' );
6002
+ }
6003
+
6004
+ /**
6005
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
6006
+ *
6007
+ * @author Vova Feldman (@svovaf)
6008
+ * @since 1.1.7.3
6009
+ *
6010
+ * @return int|false
6011
+ */
6012
+ function next_install_sync() {
6013
+ return $this->get_next_scheduled_cron( 'install_sync', 'install_sync' );
6014
+ }
6015
+
6016
+ /**
6017
+ * Add the actual install sync function to the cron job hook.
6018
+ *
6019
+ * @author Vova Feldman (@svovaf)
6020
+ * @since 1.1.7.3
6021
+ */
6022
+ private function hook_callback_to_install_sync() {
6023
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
6024
+ }
6025
+
6026
+ /**
6027
+ * @author Vova Feldman (@svovaf)
6028
+ * @since 1.1.7.3
6029
+ *
6030
+ * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
6031
+ */
6032
+ private function clear_install_sync_cron( $is_network_clear = false ) {
6033
+ $this->_logger->entrance();
6034
+
6035
+ $this->clear_cron( 'install_sync', 'install_sync', $is_network_clear );
6036
+ }
6037
+
6038
+ /**
6039
+ * @author Vova Feldman (@svovaf)
6040
+ * @since 1.1.7.3
6041
+ * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
6042
+ */
6043
+ public function _run_sync_install() {
6044
+ $this->_logger->entrance();
6045
+
6046
+ $this->execute_cron( 'sync', array( &$this, '_sync_install_cron_method' ) );
6047
+ }
6048
+
6049
+ /**
6050
+ * The actual install(s) sync cron logic.
6051
+ *
6052
+ * @author Vova Feldman (@svovaf)
6053
+ * @since 2.0.0
6054
+ *
6055
+ * @param int[] $blog_ids
6056
+ */
6057
+ function _sync_install_cron_method( array $blog_ids ) {
6058
+ if ( $this->is_registered() ) {
6059
+ if ( 1 < count( $blog_ids ) ) {
6060
+ $this->sync_installs( array(), true );
6061
+ } else {
6062
+ $this->sync_install( array(), true );
6063
+ }
6064
+ }
6065
+ }
6066
+
6067
+ #endregion Async Install Sync ------------------------------------------------------------------
6068
+
6069
+ /**
6070
+ * Show a notice that activation is currently pending.
6071
+ *
6072
+ * @author Vova Feldman (@svovaf)
6073
+ * @since 1.0.7
6074
+ *
6075
+ * @param bool|string $email
6076
+ * @param bool $is_pending_trial Since 1.2.1.5
6077
+ */
6078
+ function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
6079
+ if ( ! is_string( $email ) ) {
6080
+ $current_user = self::_get_current_wp_user();
6081
+ $email = $current_user->user_email;
6082
+ }
6083
+
6084
+ $this->_admin_notices->add_sticky(
6085
+ sprintf(
6086
+ $this->get_text_inline( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s.', 'pending-activation-message' ),
6087
+ '<b>' . $this->get_plugin_name() . '</b>',
6088
+ '<b>' . $email . '</b>',
6089
+ ( $is_pending_trial ?
6090
+ $this->get_text_inline( 'start the trial', 'start-the-trial' ) :
6091
+ $this->get_text_inline( 'complete the install', 'complete-the-install' ) )
6092
+ ),
6093
+ 'activation_pending',
6094
+ 'Thanks!'
6095
+ );
6096
+ }
6097
+
6098
+ /**
6099
+ * Check if currently in plugin activation.
6100
+ *
6101
+ * @author Vova Feldman (@svovaf)
6102
+ * @since 1.1.4
6103
+ *
6104
+ * @return bool
6105
+ */
6106
+ function is_plugin_activation() {
6107
+ $result = get_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
6108
+
6109
+ return !empty($result);
6110
+ }
6111
+
6112
+ /**
6113
+ *
6114
+ * NOTE: admin_menu action executed before admin_init.
6115
+ *
6116
+ * @author Vova Feldman (@svovaf)
6117
+ * @since 1.0.7
6118
+ */
6119
+ function _admin_init_action() {
6120
+ /**
6121
+ * Automatically redirect to connect/activation page after plugin activation.
6122
+ *
6123
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
6124
+ */
6125
+ if ( $this->is_plugin_activation() ) {
6126
+ delete_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
6127
+
6128
+ if ( isset( $_GET['activate-multi'] ) ) {
6129
+ /**
6130
+ * Don't redirect if activating multiple plugins at once (bulk activation).
6131
+ */
6132
+ } else {
6133
+ $this->_redirect_on_activation_hook();
6134
+ return;
6135
+ }
6136
+ }
6137
+
6138
+ if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
6139
+ check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
6140
+
6141
+ $this->skip_connection( null, fs_is_network_admin() );
6142
+
6143
+ fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
6144
+ }
6145
+
6146
+ if ( $this->is_network_activation_mode() &&
6147
+ fs_request_is_action( $this->get_unique_affix() . '_delegate_activation' )
6148
+ ) {
6149
+ check_admin_referer( $this->get_unique_affix() . '_delegate_activation' );
6150
+
6151
+ $this->delegate_connection();
6152
+
6153
+ fs_redirect( $this->get_after_activation_url( 'after_delegation_url' ) );
6154
+ }
6155
+
6156
+ $this->_add_upgrade_action_link();
6157
+
6158
+ if ( ! $this->is_addon() &&
6159
+ ! ( ! $this->_is_network_active && fs_is_network_admin() ) &&
6160
+ (
6161
+ // Not registered nor anonymous.
6162
+ ( ! $this->is_registered() && ! $this->is_anonymous() ) ||
6163
+ // OR, network level and in network upgrade mode.
6164
+ ( fs_is_network_admin() && $this->_is_network_active && $this->is_network_upgrade_mode() )
6165
+ )
6166
+ ) {
6167
+ if ( ! $this->is_pending_activation() ) {
6168
+ if ( ! $this->_menu->is_main_settings_page() ) {
6169
+ /**
6170
+ * If a user visits any other admin page before activating the premium-only theme with a valid
6171
+ * license, reactivate the previous theme.
6172
+ *
6173
+ * @author Leo Fajardo (@leorw)
6174
+ * @since 1.2.2
6175
+ */
6176
+ if ( $this->is_theme()
6177
+ && $this->is_only_premium()
6178
+ && ! $this->has_settings_menu()
6179
+ && ! isset( $_REQUEST['fs_action'] )
6180
+ && $this->can_activate_previous_theme()
6181
+ ) {
6182
+ $this->activate_previous_theme();
6183
+
6184
+ return;
6185
+ }
6186
+
6187
+ if ( ! fs_is_network_admin() &&
6188
+ $this->is_network_activation_mode() &&
6189
+ ! $this->is_delegated_connection()
6190
+ ) {
6191
+ return;
6192
+ }
6193
+
6194
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
6195
+ // Show notice for new plugin installations.
6196
+ $this->_admin_notices->add(
6197
+ sprintf(
6198
+ $this->get_text_inline( 'You are just one step away - %s', 'you-are-step-away' ),
6199
+ sprintf( '<b><a href="%s">%s</a></b>',
6200
+ $this->get_activation_url( array(), ! $this->is_delegated_connection() ),
6201
+ sprintf( $this->get_text_x_inline( 'Complete "%s" Activation Now',
6202
+ '%s - plugin name. As complete "PluginX" activation now', 'activate-x-now' ), $this->get_plugin_name() )
6203
+ )
6204
+ ),
6205
+ '',
6206
+ 'update-nag'
6207
+ );
6208
+ } else {
6209
+ if ( $this->should_add_sticky_optin_notice() ) {
6210
+ $this->add_sticky_optin_admin_notice();
6211
+ }
6212
+
6213
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
6214
+ // Don't show admin nag if plugin update.
6215
+ wp_enqueue_script( 'wp-pointer' );
6216
+ wp_enqueue_style( 'wp-pointer' );
6217
+
6218
+ $this->_enqueue_connect_essentials();
6219
+
6220
+ add_action( 'admin_print_footer_scripts', array(
6221
+ $this,
6222
+ '_add_connect_pointer_script'
6223
+ ) );
6224
+ }
6225
+ }
6226
+ }
6227
+ }
6228
+
6229
+ if ( $this->is_theme() &&
6230
+ $this->_menu->is_main_settings_page()
6231
+ ) {
6232
+ $this->_show_theme_activation_optin_dialog();
6233
+ }
6234
+ }
6235
+ }
6236
+
6237
+ /**
6238
+ * @author Vova Feldman (@svovaf)
6239
+ * @since 2.0.0
6240
+ *
6241
+ * @return bool
6242
+ */
6243
+ private function should_add_sticky_optin_notice() {
6244
+ if ( fs_is_network_admin() ) {
6245
+ if ( ! $this->_is_network_active ) {
6246
+ return false;
6247
+ }
6248
+
6249
+ if ( ! $this->is_network_activation_mode() ) {
6250
+ return false;
6251
+ }
6252
+
6253
+ return ! isset( $this->_storage->sticky_optin_added_ms );
6254
+ }
6255
+
6256
+ if ( ! $this->is_activation_mode() ) {
6257
+ return false;
6258
+ }
6259
+
6260
+ // If running from a blog admin and delegated the connection.
6261
+ return ! isset( $this->_storage->sticky_optin_added );
6262
+ }
6263
+
6264
+ /**
6265
+ * @author Leo Fajardo (@leorw)
6266
+ * @since 2.0.0
6267
+ */
6268
+ private function add_sticky_optin_admin_notice() {
6269
+ if ( ! $this->_is_network_active || ! fs_is_network_admin() ) {
6270
+ $this->_storage->sticky_optin_added = true;
6271
+ } else {
6272
+ $this->_storage->sticky_optin_added_ms = true;
6273
+ }
6274
+
6275
+ // Show notice for new plugin installations.
6276
+ $this->_admin_notices->add_sticky(
6277
+ sprintf(
6278
+ $this->get_text_inline( 'We made a few tweaks to the %s, %s', 'few-plugin-tweaks' ),
6279
+ $this->_module_type,
6280
+ sprintf( '<b><a href="%s">%s</a></b>',
6281
+ $this->get_activation_url(),
6282
+ sprintf( $this->get_text_inline( 'Opt in to make "%s" Better!', 'optin-x-now' ), $this->get_plugin_name() )
6283
+ )
6284
+ ),
6285
+ 'connect_account',
6286
+ '',
6287
+ 'update-nag'
6288
+ );
6289
+ }
6290
+
6291
+ /**
6292
+ * Enqueue connect requires scripts and styles.
6293
+ *
6294
+ * @author Vova Feldman (@svovaf)
6295
+ * @since 1.1.4
6296
+ */
6297
+ function _enqueue_connect_essentials() {
6298
+ wp_enqueue_script( 'jquery' );
6299
+ wp_enqueue_script( 'json2' );
6300
+
6301
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
6302
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
6303
+
6304
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
6305
+ }
6306
+
6307
+ /**
6308
+ * Add connect / opt-in pointer.
6309
+ *
6310
+ * @author Vova Feldman (@svovaf)
6311
+ * @since 1.1.4
6312
+ */
6313
+ function _add_connect_pointer_script() {
6314
+ $vars = array( 'id' => $this->_module_id );
6315
+ $pointer_content = fs_get_template( 'connect.php', $vars );
6316
+ ?>
6317
+ <script type="text/javascript">// <![CDATA[
6318
+ jQuery(document).ready(function ($) {
6319
+ if ('undefined' !== typeof(jQuery().pointer)) {
6320
+
6321
+ var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
6322
+
6323
+ if (element.length > 0) {
6324
+ var optin = $(element).pointer($.extend(true, {}, {
6325
+ content : <?php echo json_encode( $pointer_content ) ?>,
6326
+ position : {
6327
+ edge : 'left',
6328
+ align: 'center'
6329
+ },
6330
+ buttons : function () {
6331
+ // Don't show pointer buttons.
6332
+ return '';
6333
+ },
6334
+ pointerWidth: 482
6335
+ }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
6336
+
6337
+ <?php
6338
+ echo $this->apply_filters( 'optin_pointer_execute', "
6339
+
6340
+ optin.pointer('open');
6341
+
6342
+ // Tag the opt-in pointer with custom class.
6343
+ $('.wp-pointer #fs_connect')
6344
+ .parents('.wp-pointer.wp-pointer-top')
6345
+ .addClass('fs-opt-in-pointer');
6346
+
6347
+ ", 'element', 'optin' ) ?>
6348
+ }
6349
+ }
6350
+ });
6351
+ // ]]></script>
6352
+ <?php
6353
+ }
6354
+
6355
+ /**
6356
+ * Return current page's URL.
6357
+ *
6358
+ * @author Vova Feldman (@svovaf)
6359
+ * @since 1.0.7
6360
+ *
6361
+ * @return string
6362
+ */
6363
+ function current_page_url() {
6364
+ $url = 'http';
6365
+
6366
+ if ( isset( $_SERVER["HTTPS"] ) ) {
6367
+ if ( $_SERVER["HTTPS"] == "on" ) {
6368
+ $url .= "s";
6369
+ }
6370
+ }
6371
+ $url .= "://";
6372
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
6373
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
6374
+ } else {
6375
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
6376
+ }
6377
+
6378
+ return esc_url( $url );
6379
+ }
6380
+
6381
+ /**
6382
+ * Check if the current page is the plugin's main admin settings page.
6383
+ *
6384
+ * @author Vova Feldman (@svovaf)
6385
+ * @since 1.0.7
6386
+ *
6387
+ * @return bool
6388
+ */
6389
+ function _is_plugin_page() {
6390
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
6391
+ fs_is_plugin_page( $this->_slug );
6392
+ }
6393
+
6394
+ /* Events
6395
+ ------------------------------------------------------------------------------------------------------------------*/
6396
+ /**
6397
+ * Delete site install from Database.
6398
+ *
6399
+ * @author Vova Feldman (@svovaf)
6400
+ * @since 1.0.1
6401
+ *
6402
+ * @param bool $store
6403
+ * @param int|null $blog_id Since 2.0.0
6404
+ *
6405
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
6406
+ */
6407
+ function _delete_site( $store = true, $blog_id = null ) {
6408
+ return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
6409
+ }
6410
+
6411
+ /**
6412
+ * Delete site install from Database.
6413
+ *
6414
+ * @author Vova Feldman (@svovaf)
6415
+ * @since 1.2.2.7
6416
+ *
6417
+ * @param string $slug
6418
+ * @param string $module_type
6419
+ * @param bool $store
6420
+ * @param int|null $blog_id Since 2.0.0
6421
+ *
6422
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
6423
+ */
6424
+ static function _delete_site_by_slug( $slug, $module_type, $store = true, $blog_id = null ) {
6425
+ $sites = self::get_all_sites( $module_type, $blog_id );
6426
+
6427
+ $install_id = false;
6428
+
6429
+ if ( isset( $sites[ $slug ] ) ) {
6430
+ if ( is_object( $sites[ $slug ] ) ) {
6431
+ $install_id = $sites[ $slug ]->id;
6432
+ }
6433
+
6434
+ unset( $sites[ $slug ] );
6435
+
6436
+ self::set_account_option_by_module( $module_type, 'sites', $sites, $store, $blog_id );
6437
+ }
6438
+
6439
+ return $install_id;
6440
+ }
6441
+
6442
+ /**
6443
+ * Delete user.
6444
+ *
6445
+ * @author Vova Feldman (@svovaf)
6446
+ * @since 2.0.0
6447
+ *
6448
+ * @param number $user_id
6449
+ * @param bool $store
6450
+ *
6451
+ * @return false|int The user ID if deleted. Otherwise, FALSE (when install not exist).
6452
+ */
6453
+ private static function delete_user( $user_id, $store = true ) {
6454
+ $users = self::get_all_users();
6455
+
6456
+ if ( ! is_array( $users ) || ! isset( $users[ $user_id ] ) ) {
6457
+ return false;
6458
+ }
6459
+
6460
+ unset( $users[ $user_id ] );
6461
+
6462
+ self::$_accounts->set_option( 'users', $users, $store );
6463
+
6464
+ return $user_id;
6465
+ }
6466
+
6467
+ /**
6468
+ * Delete plugin's plans information.
6469
+ *
6470
+ * @param bool $store Flush to Database if true.
6471
+ * @param bool $keep_associated_plans If set to false, delete all plans, even if a plan is associated with an install.
6472
+ *
6473
+ * @author Vova Feldman (@svovaf)
6474
+ * @since 1.0.9
6475
+ */
6476
+ private function _delete_plans( $store = true, $keep_associated_plans = true ) {
6477
+ $this->_logger->entrance();
6478
+
6479
+ $plans = self::get_all_plans( $this->_module_type );
6480
+
6481
+ $plans_to_keep = array();
6482
+
6483
+ if ( $keep_associated_plans ) {
6484
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
6485
+ foreach ( $plans_ids_to_keep as $plan_id ) {
6486
+ $plan = self::_get_plan_by_id( $plan_id );
6487
+ if ( is_object( $plan ) ) {
6488
+ $plans_to_keep[] = $plan;
6489
+ }
6490
+ }
6491
+ }
6492
+
6493
+ if ( ! empty( $plans_to_keep ) ) {
6494
+ $plans[ $this->_slug ] = $plans_to_keep;
6495
+ } else {
6496
+ unset( $plans[ $this->_slug ] );
6497
+ }
6498
+
6499
+ $this->set_account_option( 'plans', $plans, $store );
6500
+ }
6501
+
6502
+ /**
6503
+ * Delete all plugin licenses.
6504
+ *
6505
+ * @author Vova Feldman (@svovaf)
6506
+ * @since 1.0.9
6507
+ *
6508
+ * @param bool $store
6509
+ */
6510
+ private function _delete_licenses( $store = true ) {
6511
+ $this->_logger->entrance();
6512
+
6513
+ $all_licenses = self::get_all_licenses();
6514
+
6515
+ unset( $all_licenses[ $this->_module_id ] );
6516
+
6517
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
6518
+ }
6519
+
6520
+ /**
6521
+ * Check if Freemius was added on new plugin installation.
6522
+ *
6523
+ * @author Vova Feldman (@svovaf)
6524
+ * @since 1.1.5
6525
+ *
6526
+ * @return bool
6527
+ */
6528
+ function is_plugin_new_install() {
6529
+ return isset( $this->_storage->is_plugin_new_install ) &&
6530
+ $this->_storage->is_plugin_new_install;
6531
+ }
6532
+
6533
+ /**
6534
+ * Check if it's the first plugin release that is running Freemius.
6535
+ *
6536
+ * @author Vova Feldman (@svovaf)
6537
+ * @since 1.2.1.5
6538
+ *
6539
+ * @return bool
6540
+ */
6541
+ function is_first_freemius_powered_version() {
6542
+ return empty( $this->_storage->plugin_last_version );
6543
+ }
6544
+
6545
+ /**
6546
+ * @author Leo Fajardo (@leorw)
6547
+ * @since 1.2.2
6548
+ *
6549
+ * @return bool|string
6550
+ */
6551
+ private function get_previous_theme_slug() {
6552
+ return isset( $this->_storage->previous_theme ) ?
6553
+ $this->_storage->previous_theme :
6554
+ false;
6555
+ }
6556
+
6557
+ /**
6558
+ * @author Leo Fajardo (@leorw)
6559
+ * @since 1.2.2
6560
+ *
6561
+ * @return string
6562
+ */
6563
+ private function can_activate_previous_theme() {
6564
+ $slug = $this->get_previous_theme_slug();
6565
+ if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
6566
+ $theme_instance = wp_get_theme( $slug );
6567
+
6568
+ return $theme_instance->exists();
6569
+ }
6570
+
6571
+ return false;
6572
+ }
6573
+
6574
+ /**
6575
+ * @author Leo Fajardo (@leorw)
6576
+ * @since 1.2.2
6577
+ */
6578
+ private function activate_previous_theme() {
6579
+ switch_theme( $this->get_previous_theme_slug() );
6580
+ unset( $this->_storage->previous_theme );
6581
+
6582
+ global $pagenow;
6583
+ if ( 'themes.php' === $pagenow ) {
6584
+ /**
6585
+ * Refresh the active theme information.
6586
+ *
6587
+ * @author Leo Fajardo (@leorw)
6588
+ * @since 1.2.2
6589
+ */
6590
+ fs_redirect( $this->admin_url( $pagenow ) );
6591
+ }
6592
+ }
6593
+
6594
+ /**
6595
+ * @author Leo Fajardo (@leorw)
6596
+ * @since 1.2.2
6597
+ *
6598
+ * @return string
6599
+ */
6600
+ function get_previous_theme_activation_url() {
6601
+ if ( ! $this->can_activate_previous_theme() ) {
6602
+ return '';
6603
+ }
6604
+
6605
+ /**
6606
+ * Activation URL
6607
+ *
6608
+ * @author Leo Fajardo (@leorw)
6609
+ * @since 1.2.2
6610
+ */
6611
+ return wp_nonce_url(
6612
+ $this->admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
6613
+ 'switch-theme_' . $this->get_previous_theme_slug()
6614
+ );
6615
+ }
6616
+
6617
+ /**
6618
+ * Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
6619
+ * form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
6620
+ * activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
6621
+ * theme doesn't exist, then there will be no close button.
6622
+ *
6623
+ * @author Leo Fajardo (@leorw)
6624
+ * @since 1.2.2
6625
+ *
6626
+ * @param string $slug_or_name Old theme's slug or name.
6627
+ * @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
6628
+ */
6629
+ function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
6630
+ $this->_storage->previous_theme = ( false !== $old_theme ) ?
6631
+ $old_theme->get_stylesheet() :
6632
+ $slug_or_name;
6633
+
6634
+ $this->_activate_plugin_event_hook();
6635
+ }
6636
+
6637
+ /**
6638
+ * Plugin activated hook.
6639
+ *
6640
+ * @author Vova Feldman (@svovaf)
6641
+ * @since 1.0.1
6642
+ *
6643
+ * @uses FS_Api
6644
+ */
6645
+ function _activate_plugin_event_hook() {
6646
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6647
+
6648
+ if ( ! $this->is_user_admin() ) {
6649
+ return;
6650
+ }
6651
+
6652
+ $this->unregister_uninstall_hook();
6653
+
6654
+ // Clear API cache on activation.
6655
+ FS_Api::clear_cache();
6656
+
6657
+ $is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );
6658
+
6659
+ $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
6660
+
6661
+ // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
6662
+ // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
6663
+ $other_version_basename = $is_premium_version_activation ?
6664
+ $this->_free_plugin_basename :
6665
+ $this->premium_plugin_basename();
6666
+
6667
+ if ( ! $this->_is_network_active ) {
6668
+ /**
6669
+ * During the activation, the plugin isn't yet active, therefore,
6670
+ * _is_network_active will be set to false even if it's a network level
6671
+ * activation. So we need to fix that by looking at the is_network_admin() value.
6672
+ *
6673
+ * @author Vova Feldman
6674
+ */
6675
+ $this->_is_network_active = (
6676
+ $this->_is_multisite_integrated &&
6677
+ // Themes are always network activated, but the ACTUAL activation is per site.
6678
+ $this->is_plugin() &&
6679
+ fs_is_network_admin()
6680
+ );
6681
+ }
6682
+
6683
+ /**
6684
+ * If the other module version is activate, deactivate it.
6685
+ *
6686
+ * is_plugin_active() checks if the plugin active on the site or the network level
6687
+ * and deactivate_plugins() deactivates the plugin whether its activated on the site
6688
+ * or network level.
6689
+ *
6690
+ * @author Leo Fajardo (@leorw)
6691
+ * @since 1.2.2
6692
+ */
6693
+ if ( is_plugin_active( $other_version_basename ) ) {
6694
+ deactivate_plugins( $other_version_basename );
6695
+ }
6696
+
6697
+ if ( $this->is_registered() ) {
6698
+ if ( $is_premium_version_activation ) {
6699
+ $this->reconnect_locally();
6700
+ }
6701
+
6702
+
6703
+ // Schedule re-activation event and sync.
6704
+ // $this->sync_install( array(), true );
6705
+ $this->schedule_install_sync();
6706
+
6707
+ // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
6708
+ if ( $is_premium_version_activation ) {
6709
+ $this->_admin_notices->add(
6710
+ sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
6711
+ $this->get_text_x_inline( 'W00t',
6712
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
6713
+ );
6714
+ }
6715
+ } else if ( $this->is_anonymous() ) {
6716
+ if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
6717
+ $plugin_version = $this->_storage->is_anonymous_ms['version'];
6718
+ $network = true;
6719
+ } else {
6720
+ $plugin_version = $this->_storage->is_anonymous['version'];
6721
+ $network = false;
6722
+ }
6723
+
6724
+ /**
6725
+ * Reset "skipped" click cache on the following:
6726
+ * 1. Freemius DEV mode.
6727
+ * 2. WordPress DEBUG mode.
6728
+ * 3. If a plugin and the user skipped the exact same version before.
6729
+ *
6730
+ * @since 1.2.2.7 Ulrich Pogson (@grapplerulrich) asked to not reset the SKIPPED flag if the exact same THEME version was activated before unless the developer is running with WP_DEBUG on, or Freemius debug mode on (WP_FS__DEV_MODE).
6731
+ *
6732
+ * @todo 4. If explicitly asked to retry after every activation.
6733
+ */
6734
+ if ( WP_FS__DEV_MODE ||
6735
+ (
6736
+ ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
6737
+ $this->get_plugin_version() == $plugin_version
6738
+ )
6739
+ ) {
6740
+ $this->reset_anonymous_mode( $network );
6741
+ }
6742
+ }
6743
+
6744
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
6745
+ /**
6746
+ * If no previous version of plugin's version exist, it means that it's either
6747
+ * the first time that the plugin installed on the site, or the plugin was installed
6748
+ * before but didn't have Freemius integrated.
6749
+ *
6750
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
6751
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
6752
+ * only after immediate activation.
6753
+ *
6754
+ * @since 1.1.4
6755
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
6756
+ */
6757
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
6758
+ }
6759
+
6760
+ if ( ! $this->_anonymous_mode &&
6761
+ $this->has_api_connectivity( WP_FS__DEV_MODE ) &&
6762
+ ! $this->_isAutoInstall
6763
+ ) {
6764
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
6765
+ set_transient( "fs_{$this->_module_type}_{$this->_slug}_activated", true, 60 );
6766
+ }
6767
+
6768
+ /**
6769
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
6770
+ * after the plugin was loaded. The logic is located at activate_plugin()
6771
+ * ./wp-admin/includes/plugin.php.
6772
+ *
6773
+ * @author Vova Feldman (@svovaf)
6774
+ * @since 1.1.9
6775
+ */
6776
+ $this->_storage->was_plugin_loaded = true;
6777
+ }
6778
+
6779
+ /**
6780
+ * Delete account.
6781
+ *
6782
+ * @author Vova Feldman (@svovaf)
6783
+ * @since 1.0.3
6784
+ *
6785
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
6786
+ */
6787
+ function delete_account_event( $check_user = true ) {
6788
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6789
+
6790
+ if ( $check_user && ! $this->is_user_admin() ) {
6791
+ return;
6792
+ }
6793
+
6794
+ $this->do_action( 'before_account_delete' );
6795
+
6796
+ // Clear all admin notices.
6797
+ $this->_admin_notices->clear_all_sticky( false );
6798
+
6799
+ $this->_delete_site( false );
6800
+
6801
+ $delete_network_common_data = true;
6802
+
6803
+ if ( $this->_is_network_active ) {
6804
+ $installs = $this->get_blog_install_map();
6805
+
6806
+ // Don't delete common network data unless no other installs left.
6807
+ $delete_network_common_data = empty( $installs );
6808
+ }
6809
+
6810
+ if ( $delete_network_common_data ) {
6811
+ $this->_delete_plans( false );
6812
+
6813
+ $this->_delete_licenses( false );
6814
+
6815
+ // Delete add-ons related to plugin's account.
6816
+ $this->_delete_account_addons( false );
6817
+ }
6818
+
6819
+ // @todo Delete plans and licenses of add-ons.
6820
+
6821
+ self::$_accounts->store();
6822
+
6823
+ /**
6824
+ * IMPORTANT:
6825
+ * Clear crons must be executed before clearing all storage.
6826
+ * Otherwise, the cron will not be cleared.
6827
+ */
6828
+ if ( $delete_network_common_data ) {
6829
+ $this->clear_sync_cron();
6830
+ }
6831
+
6832
+ $this->clear_install_sync_cron();
6833
+
6834
+ // Clear all storage data.
6835
+ $this->_storage->clear_all( true, array(
6836
+ 'connectivity_test',
6837
+ 'is_on',
6838
+ ), false );
6839
+
6840
+ // Send delete event.
6841
+ $this->get_api_site_scope()->call( '/', 'delete' );
6842
+
6843
+ $this->do_action( 'after_account_delete' );
6844
+ }
6845
+
6846
+ /**
6847
+ * Delete network level account.
6848
+ *
6849
+ * @author Vova Feldman (@svovaf)
6850
+ * @since 2.0.0
6851
+ *
6852
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
6853
+ */
6854
+ function delete_network_account_event( $check_user = true ) {
6855
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6856
+
6857
+ if ( $check_user && ! $this->is_user_admin() ) {
6858
+ return;
6859
+ }
6860
+
6861
+ $this->do_action( 'before_network_account_delete' );
6862
+
6863
+ // Clear all admin notices.
6864
+ $this->_admin_notices->clear_all_sticky();
6865
+
6866
+ $this->_delete_plans( false, false );
6867
+
6868
+ $this->_delete_licenses( false );
6869
+
6870
+ // Delete add-ons related to plugin's account.
6871
+ $this->_delete_account_addons( false );
6872
+
6873
+ // @todo Delete plans and licenses of add-ons.
6874
+
6875
+ self::$_accounts->store( true );
6876
+
6877
+ /**
6878
+ * IMPORTANT:
6879
+ * Clear crons must be executed before clearing all storage.
6880
+ * Otherwise, the cron will not be cleared.
6881
+ */
6882
+ $this->clear_sync_cron( true );
6883
+ $this->clear_install_sync_cron( true );
6884
+
6885
+ $sites = self::get_sites();
6886
+
6887
+ $install_ids = array();
6888
+ foreach ( $sites as $site ) {
6889
+ $blog_id = self::get_site_blog_id( $site );
6890
+
6891
+ $install_id = $this->_delete_site( true, $blog_id );
6892
+
6893
+ // Clear all storage data.
6894
+ $this->_storage->clear_all( true, array( 'connectivity_test' ), $blog_id );
6895
+
6896
+ if ( FS_Site::is_valid_id( $install_id ) ) {
6897
+ $install_ids[] = $install_id;
6898
+ }
6899
+
6900
+ switch_to_blog( $blog_id );
6901
+
6902
+ $this->do_action( 'after_account_delete' );
6903
+
6904
+ restore_current_blog();
6905
+ }
6906
+
6907
+ $this->_storage->clear_all( true, array(
6908
+ 'connectivity_test',
6909
+ 'is_on',
6910
+ ), true );
6911
+
6912
+ // Send delete event.
6913
+ if ( ! empty( $install_ids ) ) {
6914
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', $install_ids ), 'delete' );
6915
+ }
6916
+
6917
+ $this->do_action( 'after_network_account_delete' );
6918
+ }
6919
+
6920
+ /**
6921
+ * Plugin deactivation hook.
6922
+ *
6923
+ * @author Vova Feldman (@svovaf)
6924
+ * @since 1.0.1
6925
+ */
6926
+ function _deactivate_plugin_hook() {
6927
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6928
+
6929
+ if ( ! $this->is_user_admin() ) {
6930
+ return;
6931
+ }
6932
+
6933
+ $is_network_deactivation = fs_is_network_admin();
6934
+ $storage_keys_for_removal = array();
6935
+
6936
+ $this->_admin_notices->clear_all_sticky();
6937
+
6938
+ $storage_keys_for_removal[] = 'sticky_optin_added';
6939
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
6940
+ unset( $this->_storage->sticky_optin_added );
6941
+ }
6942
+
6943
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
6944
+ // Remember that plugin was already installed.
6945
+ $this->_storage->is_plugin_new_install = false;
6946
+ }
6947
+
6948
+ // Hook to plugin uninstall.
6949
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
6950
+
6951
+ $this->clear_module_main_file_cache();
6952
+ $this->clear_sync_cron( $this->_is_network_active );
6953
+ $this->clear_install_sync_cron();
6954
+
6955
+ if ( $this->is_registered() ) {
6956
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
6957
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
6958
+ }
6959
+
6960
+ if ( $is_network_deactivation ) {
6961
+ // Send deactivation event.
6962
+ $this->sync_installs( array(
6963
+ 'is_active' => false,
6964
+ ) );
6965
+ } else {
6966
+ // Send deactivation event.
6967
+ $this->sync_install( array(
6968
+ 'is_active' => false,
6969
+ ) );
6970
+ }
6971
+ } else {
6972
+ if ( ! $this->has_api_connectivity() ) {
6973
+ // Reset connectivity test cache.
6974
+ unset( $this->_storage->connectivity_test );
6975
+
6976
+ $storage_keys_for_removal[] = 'connectivity_test';
6977
+ }
6978
+ }
6979
+
6980
+ if ( $is_network_deactivation ) {
6981
+ if ( isset( $this->_storage->sticky_optin_added_ms ) ) {
6982
+ unset( $this->_storage->sticky_optin_added_ms );
6983
+ }
6984
+
6985
+ if ( ! empty( $storage_keys_for_removal ) ) {
6986
+ $sites = self::get_sites();
6987
+
6988
+ foreach ( $sites as $site ) {
6989
+ $blog_id = self::get_site_blog_id( $site );
6990
+
6991
+ foreach ( $storage_keys_for_removal as $key ) {
6992
+ $this->_storage->remove( $key, false, $blog_id );
6993
+ }
6994
+
6995
+ $this->_storage->save( $blog_id );
6996
+ }
6997
+ }
6998
+ }
6999
+
7000
+ // Clear API cache on deactivation.
7001
+ FS_Api::clear_cache();
7002
+
7003
+ $this->remove_sdk_reference();
7004
+ }
7005
+
7006
+ /**
7007
+ * @author Vova Feldman (@svovaf)
7008
+ * @since 1.1.6
7009
+ */
7010
+ private function remove_sdk_reference() {
7011
+ global $fs_active_plugins;
7012
+
7013
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
7014
+ if ( $this->_plugin_basename == $data->plugin_path ) {
7015
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
7016
+ break;
7017
+ }
7018
+ }
7019
+
7020
+ fs_fallback_to_newest_active_sdk();
7021
+ }
7022
+
7023
+ /**
7024
+ * @author Vova Feldman (@svovaf)
7025
+ * @since 1.1.3
7026
+ *
7027
+ * @param bool $is_anonymous
7028
+ * @param bool|int $network_or_blog_id Since 2.0.0
7029
+ */
7030
+ private function set_anonymous_mode( $is_anonymous = true, $network_or_blog_id = 0 ) {
7031
+ // Store information regarding skip to try and opt-in the user
7032
+ // again in the future.
7033
+ $skip_info = array(
7034
+ 'is' => $is_anonymous,
7035
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
7036
+ 'version' => $this->get_plugin_version(),
7037
+ );
7038
+
7039
+ if ( true === $network_or_blog_id ) {
7040
+ $this->_storage->is_anonymous_ms = $skip_info;
7041
+ } else {
7042
+ $this->_storage->store( 'is_anonymous', $skip_info, $network_or_blog_id );
7043
+ }
7044
+
7045
+ $this->network_upgrade_mode_completed();
7046
+
7047
+ // Update anonymous mode cache.
7048
+ $this->_is_anonymous = $is_anonymous;
7049
+ }
7050
+
7051
+ /**
7052
+ * @author Vova Feldman (@svovaf)
7053
+ * @since 2.0.0
7054
+ *
7055
+ * @param int $blog_id Site ID.
7056
+ * @param int $user_id User ID.
7057
+ * @param string $domain Site domain.
7058
+ * @param string $path Site path.
7059
+ * @param int $network_id Network ID. Only relevant on multi-network installations.
7060
+ * @param array $meta Metadata. Used to set initial site options.
7061
+ *
7062
+ * @uses Freemius::is_license_network_active() to check if the context license was network activated by the super-admin.
7063
+ * @uses Freemius::is_network_connected() to check if the super-admin network opted-in.
7064
+ * @uses Freemius::is_network_anonymous() to check if the super-admin network skipped.
7065
+ * @uses Freemius::is_network_delegated_connection() to check if the super-admin network delegated the connection to the site admins.
7066
+ */
7067
+ function _after_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
7068
+ $this->_logger->entrance();
7069
+
7070
+ if ( $this->is_premium() &&
7071
+ $this->is_network_connected() &&
7072
+ is_object( $this->_license ) &&
7073
+ $this->_license->can_activate( FS_Site::is_localhost_by_address( $domain ) ) &&
7074
+ $this->is_license_network_active( $blog_id )
7075
+ ) {
7076
+ /**
7077
+ * Running the premium version, the license was network activated, and the license can also be activated on the current site -> so try to opt-in with the license key.
7078
+ */
7079
+ $current_blog_id = get_current_blog_id();
7080
+ $license = clone $this->_license;
7081
+
7082
+ $this->switch_to_blog( $blog_id );
7083
+
7084
+ // Opt-in with network user.
7085
+ $this->install_with_user(
7086
+ $this->get_network_user(),
7087
+ $license->secret_key,
7088
+ false,
7089
+ false,
7090
+ false
7091
+ );
7092
+
7093
+ if ( is_object( $this->_site ) ) {
7094
+ if ( $this->_site->license_id == $license->id ) {
7095
+ /**
7096
+ * If the license was activated successfully, sync the license data from the remote server.
7097
+ */
7098
+ $this->_license = $license;
7099
+ $this->sync_site_license();
7100
+ }
7101
+ }
7102
+
7103
+ $this->switch_to_blog( $current_blog_id );
7104
+
7105
+ if ( is_object( $this->_site ) ) {
7106
+ // Already connected (with or without a license), so no need to continue.
7107
+ return;
7108
+ }
7109
+ }
7110
+
7111
+ if ( $this->is_network_anonymous() ) {
7112
+ /**
7113
+ * Opt-in was network skipped so automatically skip the opt-in for the new site.
7114
+ */
7115
+ $this->skip_site_connection( $blog_id );
7116
+ } else if ( $this->is_network_delegated_connection() ) {
7117
+ /**
7118
+ * Opt-in was network delegated so automatically delegate the opt-in for the new site's admin.
7119
+ */
7120
+ $this->delegate_site_connection( $blog_id );
7121
+ } else if ( $this->is_network_connected() ) {
7122
+ /**
7123
+ * Opt-in was network activated so automatically opt-in with the network user and new site admin.
7124
+ */
7125
+ $current_blog_id = get_current_blog_id();
7126
+
7127
+ $this->switch_to_blog( $blog_id );
7128
+
7129
+ // Opt-in with network user.
7130
+ $this->install_with_user(
7131
+ $this->get_network_user(),
7132
+ false,
7133
+ false,
7134
+ false,
7135
+ false
7136
+ );
7137
+
7138
+ $this->switch_to_blog( $current_blog_id );
7139
+ } else {
7140
+ /**
7141
+ * If the super-admin mixed different options (connect, skip, delegated):
7142
+ * a) If at least one site connection was delegated, then automatically delegate connection.
7143
+ * b) Otherwise, it means that at least one site was skipped and at least one site was connected. For a simplified UX in the initial release of the multisite network integration, skip the connection for the newly created site. If the super-admin will want to opt-in they can still do that from the network level Account page.
7144
+ */
7145
+ $has_delegated_site = false;
7146
+
7147
+ $sites = self::get_sites();
7148
+ foreach ( $sites as $site ) {
7149
+ $blog_id = self::get_site_blog_id( $site );
7150
+
7151
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
7152
+ $has_delegated_site = true;
7153
+ break;
7154
+ }
7155
+ }
7156
+
7157
+ if ( $has_delegated_site ) {
7158
+ $this->delegate_site_connection( $blog_id );
7159
+ } else {
7160
+ $this->skip_site_connection( $blog_id );
7161
+ }
7162
+ }
7163
+ }
7164
+
7165
+ /**
7166
+ * @author Vova Feldman (@svovaf)
7167
+ * @since 1.1.3
7168
+ *
7169
+ * @param bool|int $network_or_blog_id Since 2.0.0.
7170
+ */
7171
+ private function reset_anonymous_mode( $network_or_blog_id = 0 ) {
7172
+ if ( true === $network_or_blog_id ) {
7173
+ unset( $this->_storage->is_anonymous_ms );
7174
+ } else {
7175
+ $this->_storage->remove( 'is_anonymous', true, $network_or_blog_id );
7176
+ }
7177
+
7178
+ /**
7179
+ * Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
7180
+ * has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
7181
+ * on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
7182
+ *
7183
+ * @author Leo Fajardo (@leorw)
7184
+ * @since 1.2.2
7185
+ */
7186
+ if ( ! $this->_is_network_active ||
7187
+ 0 === $network_or_blog_id ||
7188
+ get_current_blog_id() == $network_or_blog_id ||
7189
+ ( true === $network_or_blog_id && fs_is_network_admin() )
7190
+ ) {
7191
+ unset( $this->_is_anonymous );
7192
+ }
7193
+ }
7194
+
7195
+ /**
7196
+ * Clears the anonymous mode and redirects to the opt-in screen.
7197
+ *
7198
+ * @author Vova Feldman (@svovaf)
7199
+ * @since 1.1.7
7200
+ */
7201
+ function connect_again() {
7202
+ if ( ! $this->is_anonymous() ) {
7203
+ return;
7204
+ }
7205
+
7206
+ $this->reset_anonymous_mode( fs_is_network_admin() );
7207
+
7208
+ fs_redirect( $this->get_activation_url() );
7209
+ }
7210
+
7211
+ /**
7212
+ * Skip account connect, and set anonymous mode.
7213
+ *
7214
+ * @author Vova Feldman (@svovaf)
7215
+ * @since 1.1.1
7216
+ *
7217
+ * @param array|null $sites Since 2.0.0. Specific sites.
7218
+ * @param bool $skip_all_network Since 2.0.0. If true, skip connection for all sites.
7219
+ */
7220
+ function skip_connection( $sites = null, $skip_all_network = false ) {
7221
+ $this->_logger->entrance();
7222
+
7223
+ $this->_admin_notices->remove_sticky( 'connect_account' );
7224
+
7225
+ if ( $skip_all_network ) {
7226
+ $this->set_anonymous_mode( true, true );
7227
+ }
7228
+
7229
+ if ( ! $skip_all_network && empty( $sites ) ) {
7230
+ $this->skip_site_connection();
7231
+ } else {
7232
+ $uids = array();
7233
+
7234
+ if ( $skip_all_network ) {
7235
+ $this->set_anonymous_mode( true, true );
7236
+
7237
+ $sites = self::get_sites();
7238
+ foreach ( $sites as $site ) {
7239
+ $blog_id = self::get_site_blog_id( $site );
7240
+ $this->skip_site_connection( $blog_id, false );
7241
+ $uids[] = $this->get_anonymous_id( $blog_id );
7242
+ }
7243
+ } else if ( ! empty( $sites ) ) {
7244
+ foreach ( $sites as $site ) {
7245
+ $uids[] = $site['uid'];
7246
+ $this->skip_site_connection( $site['blog_id'], false );
7247
+ }
7248
+ }
7249
+
7250
+ // Send anonymous skip event.
7251
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
7252
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
7253
+ 'uids' => $uids,
7254
+ ) );
7255
+ }
7256
+
7257
+ $this->network_upgrade_mode_completed();
7258
+ }
7259
+
7260
+ /**
7261
+ * Skip connection for specific site in the network.
7262
+ *
7263
+ * @author Vova Feldman (@svovaf)
7264
+ * @since 2.0.0
7265
+ *
7266
+ * @param int|null $blog_id
7267
+ * @param bool $send_skip
7268
+ */
7269
+ private function skip_site_connection( $blog_id = null, $send_skip = true ) {
7270
+ $this->_logger->entrance();
7271
+
7272
+ $this->_admin_notices->remove_sticky( 'connect_account', $blog_id );
7273
+
7274
+ $this->set_anonymous_mode( true, $blog_id );
7275
+
7276
+ if ( $send_skip ) {
7277
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
7278
+ 'uids' => array( $this->get_anonymous_id( $blog_id ) ),
7279
+ ) );
7280
+ }
7281
+ }
7282
+
7283
+ /**
7284
+ * Plugin version update hook.
7285
+ *
7286
+ * @author Vova Feldman (@svovaf)
7287
+ * @since 1.0.4
7288
+ */
7289
+ private function update_plugin_version_event() {
7290
+ $this->_logger->entrance();
7291
+
7292
+ if ( ! $this->is_registered() ) {
7293
+ return;
7294
+ }
7295
+
7296
+ $this->schedule_install_sync();
7297
+ // $this->sync_install( array(), true );
7298
+ }
7299
+
7300
+ /**
7301
+ * Generate an MD5 signature of a plugins collection.
7302
+ * This helper methods used to identify changes in a plugins collection.
7303
+ *
7304
+ * @author Vova Feldman (@svovaf)
7305
+ * @since 2.0.0
7306
+ *
7307
+ * @param array [string]array $plugins
7308
+ *
7309
+ * @return string
7310
+ */
7311
+ private function get_plugins_thumbprint( $plugins ) {
7312
+ ksort( $plugins );
7313
+
7314
+ $thumbprint = '';
7315
+ foreach ( $plugins as $basename => $data ) {
7316
+ $thumbprint .= $data['slug'] . ',' .
7317
+ $data['Version'] . ',' .
7318
+ ( $data['is_active'] ? '1' : '0' ) . ';';
7319
+ }
7320
+
7321
+ return md5( $thumbprint );
7322
+ }
7323
+
7324
+ /**
7325
+ * Return a list of modified plugins since the last sync.
7326
+ *
7327
+ * Note:
7328
+ * There's no point to store a plugins counter since even if the number of
7329
+ * plugins didn't change, we still need to check if the versions are all the
7330
+ * same and the activity state is similar.
7331
+ *
7332
+ * @author Vova Feldman (@svovaf)
7333
+ * @since 1.1.8
7334
+ *
7335
+ * @return array|false
7336
+ */
7337
+ private function get_plugins_data_for_api() {
7338
+ // Alias.
7339
+ $site_active_plugins_option_name = 'active_plugins';
7340
+ $network_plugins_option_name = 'all_plugins';
7341
+
7342
+ /**
7343
+ * Collection of all site level active plugins.
7344
+ */
7345
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
7346
+
7347
+ if ( ! is_object( $site_active_plugins_cache ) ) {
7348
+ $site_active_plugins_cache = (object) array(
7349
+ 'timestamp' => '',
7350
+ 'md5' => '',
7351
+ 'plugins' => array(),
7352
+ );
7353
+ }
7354
+
7355
+ $time = time();
7356
+
7357
+ if ( ! empty( $site_active_plugins_cache->timestamp ) &&
7358
+ ( $time - $site_active_plugins_cache->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
7359
+ ) {
7360
+ // Don't send plugin updates if last update was in the past 5 min.
7361
+ return false;
7362
+ }
7363
+
7364
+ // Write timestamp to lock the logic.
7365
+ $site_active_plugins_cache->timestamp = $time;
7366
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
7367
+
7368
+ // Reload options from DB.
7369
+ self::$_accounts->load( true );
7370
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
7371
+
7372
+ if ( $time != $site_active_plugins_cache->timestamp ) {
7373
+ // If timestamp is different, then another thread captured the lock.
7374
+ return false;
7375
+ }
7376
+
7377
+ /**
7378
+ * Collection of all plugins (network level).
7379
+ */
7380
+ $network_plugins_cache = self::$_accounts->get_option( $network_plugins_option_name );
7381
+
7382
+ if ( ! is_object( $network_plugins_cache ) ) {
7383
+ $network_plugins_cache = (object) array(
7384
+ 'timestamp' => '',
7385
+ 'md5' => '',
7386
+ 'plugins' => array(),
7387
+ );
7388
+ }
7389
+
7390
+ // Check if there's a change in plugins.
7391
+ $network_plugins = self::get_network_plugins();
7392
+ $site_active_plugins = self::get_site_active_plugins();
7393
+
7394
+ $network_plugins_thumbprint = $this->get_plugins_thumbprint( $network_plugins );
7395
+ $site_active_plugins_thumbprint = $this->get_plugins_thumbprint( $site_active_plugins );
7396
+
7397
+ // Check if plugins status changed (version or active/inactive).
7398
+ $network_plugins_changed = ( $network_plugins_cache->md5 !== $network_plugins_thumbprint );
7399
+ $site_active_plugins_changed = ( $site_active_plugins_cache->md5 !== $site_active_plugins_thumbprint );
7400
+
7401
+ if ( ! $network_plugins_changed &&
7402
+ ! $site_active_plugins_changed
7403
+ ) {
7404
+ // No changes.
7405
+ return array();
7406
+ }
7407
+
7408
+ $plugins_update_data = array();
7409
+
7410
+ foreach ( $network_plugins_cache->plugins as $basename => $data ) {
7411
+ if ( ! isset( $network_plugins[ $basename ] ) ) {
7412
+ // Plugin uninstalled.
7413
+ $uninstalled_plugin_data = $data;
7414
+ $uninstalled_plugin_data['is_active'] = false;
7415
+ $uninstalled_plugin_data['is_uninstalled'] = true;
7416
+ $plugins_update_data[] = $uninstalled_plugin_data;
7417
+
7418
+ unset( $network_plugins[ $basename ] );
7419
+
7420
+ unset( $network_plugins_cache->plugins[ $basename ] );
7421
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
7422
+
7423
+ continue;
7424
+ }
7425
+
7426
+ $was_active = $data['is_active'] ||
7427
+ ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7428
+ true === $site_active_plugins_cache->plugins[ $basename ]['is_active'] );
7429
+ $is_active = $network_plugins[ $basename ]['is_active'] ||
7430
+ ( isset( $site_active_plugins[ $basename ] ) &&
7431
+ $site_active_plugins[ $basename ]['is_active'] );
7432
+
7433
+ if ( ! isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7434
+ isset( $site_active_plugins[ $basename ] )
7435
+ ) {
7436
+ // Plugin was site level activated.
7437
+ $site_active_plugins_cache->plugins[ $basename ] = $network_plugins[ $basename ];
7438
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
7439
+ } else if ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7440
+ ! isset( $site_active_plugins[ $basename ] )
7441
+ ) {
7442
+ // Plugin was site level deactivated.
7443
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
7444
+ }
7445
+
7446
+ $prev_version = $data['version'];
7447
+ $current_version = $network_plugins[ $basename ]['Version'];
7448
+
7449
+ if ( $was_active !== $is_active || $prev_version !== $current_version ) {
7450
+ // Plugin activated or deactivated, or version changed.
7451
+
7452
+ if ( $was_active !== $is_active ) {
7453
+ if ( $data['is_active'] != $network_plugins[ $basename ]['is_active'] ) {
7454
+ $network_plugins_cache->plugins[ $basename ]['is_active'] = $data['is_active'];
7455
+ }
7456
+ }
7457
+
7458
+ if ( $prev_version !== $current_version ) {
7459
+ $network_plugins_cache->plugins[ $basename ]['Version'] = $current_version;
7460
+ }
7461
+
7462
+ $updated_plugin_data = $data;
7463
+ $updated_plugin_data['is_active'] = $is_active;
7464
+ $updated_plugin_data['version'] = $current_version;
7465
+ $updated_plugin_data['title'] = $network_plugins[ $basename ]['Name'];
7466
+ $plugins_update_data[] = $updated_plugin_data;
7467
+ }
7468
+ }
7469
+
7470
+ // Find new plugins that weren't yet seen before.
7471
+ foreach ( $network_plugins as $basename => $data ) {
7472
+ if ( ! isset( $network_plugins_cache->plugins[ $basename ] ) ) {
7473
+ // New plugin.
7474
+ $new_plugin = array(
7475
+ 'slug' => $data['slug'],
7476
+ 'version' => $data['Version'],
7477
+ 'title' => $data['Name'],
7478
+ 'is_active' => $data['is_active'],
7479
+ 'is_uninstalled' => false,
7480
+ );
7481
+
7482
+ $plugins_update_data[] = $new_plugin;
7483
+ $network_plugins_cache->plugins[ $basename ] = $new_plugin;
7484
+
7485
+ if ( isset( $site_active_plugins[ $basename ] ) ) {
7486
+ $site_active_plugins_cache->plugins[ $basename ] = $new_plugin;
7487
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
7488
+ }
7489
+ }
7490
+ }
7491
+
7492
+ $site_active_plugins_cache->md5 = $site_active_plugins_thumbprint;
7493
+ $site_active_plugins_cache->timestamp = $time;
7494
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
7495
+
7496
+ $network_plugins_cache->md5 = $network_plugins_thumbprint;
7497
+ $network_plugins_cache->timestamp = $time;
7498
+ self::$_accounts->set_option( $network_plugins_option_name, $network_plugins_cache, true );
7499
+
7500
+ return $plugins_update_data;
7501
+ }
7502
+
7503
+ /**
7504
+ * Return a list of modified themes since the last sync.
7505
+ *
7506
+ * Note:
7507
+ * There's no point to store a themes counter since even if the number of
7508
+ * themes didn't change, we still need to check if the versions are all the
7509
+ * same and the activity state is similar.
7510
+ *
7511
+ * @author Vova Feldman (@svovaf)
7512
+ * @since 1.1.8
7513
+ *
7514
+ * @return array|false
7515
+ */
7516
+ private function get_themes_data_for_api() {
7517
+ // Alias.
7518
+ $option_name = 'all_themes';
7519
+
7520
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
7521
+
7522
+ if ( ! is_object( $all_cached_themes ) ) {
7523
+ $all_cached_themes = (object) array(
7524
+ 'timestamp' => '',
7525
+ 'md5' => '',
7526
+ 'themes' => array(),
7527
+ );
7528
+ }
7529
+
7530
+ $time = time();
7531
+
7532
+ if ( ! empty( $all_cached_themes->timestamp ) &&
7533
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
7534
+ ) {
7535
+ // Don't send theme updates if last update was in the past 5 min.
7536
+ return false;
7537
+ }
7538
+
7539
+ // Write timestamp to lock the logic.
7540
+ $all_cached_themes->timestamp = $time;
7541
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
7542
+
7543
+ // Reload options from DB.
7544
+ self::$_accounts->load( true );
7545
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
7546
+
7547
+ if ( $time != $all_cached_themes->timestamp ) {
7548
+ // If timestamp is different, then another thread captured the lock.
7549
+ return false;
7550
+ }
7551
+
7552
+ // Get active theme.
7553
+ $active_theme = wp_get_theme();
7554
+ $active_theme_stylesheet = $active_theme->get_stylesheet();
7555
+
7556
+ // Check if there's a change in themes.
7557
+ $all_themes = wp_get_themes();
7558
+
7559
+ // Check if themes changed.
7560
+ ksort( $all_themes );
7561
+
7562
+ $themes_signature = '';
7563
+ foreach ( $all_themes as $slug => $data ) {
7564
+ $is_active = ( $slug === $active_theme_stylesheet );
7565
+ $themes_signature .= $slug . ',' .
7566
+ $data->version . ',' .
7567
+ ( $is_active ? '1' : '0' ) . ';';
7568
+ }
7569
+
7570
+ // Check if themes status changed (version or active/inactive).
7571
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
7572
+
7573
+ $themes_update_data = array();
7574
+
7575
+ if ( $themes_changed ) {
7576
+ // Change in themes, report changes.
7577
+
7578
+ // Update existing themes info.
7579
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
7580
+ $is_active = ( $slug === $active_theme_stylesheet );
7581
+
7582
+ if ( ! isset( $all_themes[ $slug ] ) ) {
7583
+ // Plugin uninstalled.
7584
+ $uninstalled_theme_data = $data;
7585
+ $uninstalled_theme_data['is_active'] = false;
7586
+ $uninstalled_theme_data['is_uninstalled'] = true;
7587
+ $themes_update_data[] = $uninstalled_theme_data;
7588
+
7589
+ unset( $all_themes[ $slug ] );
7590
+ unset( $all_cached_themes->themes[ $slug ] );
7591
+ } else if ( $data['is_active'] !== $is_active ||
7592
+ $data['version'] !== $all_themes[ $slug ]->version
7593
+ ) {
7594
+ // Plugin activated or deactivated, or version changed.
7595
+
7596
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
7597
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
7598
+
7599
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
7600
+ }
7601
+ }
7602
+
7603
+ // Find new themes that weren't yet seen before.
7604
+ foreach ( $all_themes as $slug => $data ) {
7605
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
7606
+ $is_active = ( $slug === $active_theme_stylesheet );
7607
+
7608
+ // New plugin.
7609
+ $new_plugin = array(
7610
+ 'slug' => $slug,
7611
+ 'version' => $data->version,
7612
+ 'title' => $data->name,
7613
+ 'is_active' => $is_active,
7614
+ 'is_uninstalled' => false,
7615
+ );
7616
+
7617
+ $themes_update_data[] = $new_plugin;
7618
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
7619
+ }
7620
+ }
7621
+
7622
+ $all_cached_themes->md5 = md5( $themes_signature );
7623
+ $all_cached_themes->timestamp = time();
7624
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
7625
+ }
7626
+
7627
+ return $themes_update_data;
7628
+ }
7629
+
7630
+ /**
7631
+ * Get site data for API install request.
7632
+ *
7633
+ * @author Vova Feldman (@svovaf)
7634
+ * @since 1.1.2
7635
+ *
7636
+ * @param string[] string $override
7637
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
7638
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
7639
+ *
7640
+ * @return array
7641
+ */
7642
+ private function get_install_data_for_api(
7643
+ array $override,
7644
+ $include_plugins = true,
7645
+ $include_themes = true
7646
+ ) {
7647
+ /**
7648
+ * @since 1.1.8 Also send plugin updates.
7649
+ */
7650
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
7651
+ $plugins = $this->get_plugins_data_for_api();
7652
+ if ( ! empty( $plugins ) ) {
7653
+ $override['plugins'] = $plugins;
7654
+ }
7655
+ }
7656
+ /**
7657
+ * @since 1.1.8 Also send themes updates.
7658
+ */
7659
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
7660
+ $themes = $this->get_themes_data_for_api();
7661
+ if ( ! empty( $themes ) ) {
7662
+ $override['themes'] = $themes;
7663
+ }
7664
+ }
7665
+
7666
+ return array_merge( array(
7667
+ 'version' => $this->get_plugin_version(),
7668
+ 'is_premium' => $this->is_premium(),
7669
+ 'language' => get_bloginfo( 'language' ),
7670
+ 'charset' => get_bloginfo( 'charset' ),
7671
+ 'platform_version' => get_bloginfo( 'version' ),
7672
+ 'sdk_version' => $this->version,
7673
+ 'programming_language_version' => phpversion(),
7674
+ 'title' => get_bloginfo( 'name' ),
7675
+ 'url' => get_site_url(),
7676
+ // Special params.
7677
+ 'is_active' => true,
7678
+ 'is_disconnected' => $this->is_tracking_prohibited(),
7679
+ 'is_uninstalled' => false,
7680
+ ), $override );
7681
+ }
7682
+
7683
+ /**
7684
+ * Update installs details.
7685
+ *
7686
+ * @todo V1 of multiste network support doesn't support plugin and theme data sending.
7687
+ *
7688
+ * @author Vova Feldman (@svovaf)
7689
+ * @since 2.0.0
7690
+ *
7691
+ * @param string[] string $override
7692
+ * @param bool $only_diff
7693
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
7694
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
7695
+ *
7696
+ * @return array
7697
+ */
7698
+ private function get_installs_data_for_api(
7699
+ array $override,
7700
+ $only_diff = false,
7701
+ $include_plugins = true,
7702
+ $include_themes = true
7703
+ ) {
7704
+ /**
7705
+ * @since 1.1.8 Also send plugin updates.
7706
+ */
7707
+ // if ( $include_plugins && ! isset( $override['plugins'] ) ) {
7708
+ // $plugins = $this->get_plugins_data_for_api();
7709
+ // if ( ! empty( $plugins ) ) {
7710
+ // $override['plugins'] = $plugins;
7711
+ // }
7712
+ // }
7713
+ /**
7714
+ * @since 1.1.8 Also send themes updates.
7715
+ */
7716
+ // if ( $include_themes && ! isset( $override['themes'] ) ) {
7717
+ // $themes = $this->get_themes_data_for_api();
7718
+ // if ( ! empty( $themes ) ) {
7719
+ // $override['themes'] = $themes;
7720
+ // }
7721
+ // }
7722
+
7723
+ // Common properties.
7724
+ $common = array_merge( array(
7725
+ 'version' => $this->get_plugin_version(),
7726
+ 'is_premium' => $this->is_premium(),
7727
+ 'sdk_version' => $this->version,
7728
+ 'programming_language_version' => phpversion(),
7729
+ 'platform_version' => get_bloginfo( 'version' ),
7730
+ ), $override );
7731
+
7732
+
7733
+ $is_common_diff_for_any_site = false;
7734
+ $common_diff_union = array();
7735
+
7736
+ $installs_data = array();
7737
+
7738
+ $sites = self::get_sites();
7739
+
7740
+ foreach ( $sites as $site ) {
7741
+ $blog_id = self::get_site_blog_id( $site );
7742
+
7743
+ $install = $this->get_install_by_blog_id( $blog_id );
7744
+
7745
+ if ( is_object( $install ) ) {
7746
+ if ( $install->user_id != $this->_user->id ) {
7747
+ // Install belongs to a different owner.
7748
+ continue;
7749
+ }
7750
+
7751
+ if ( ! $this->is_premium() && $install->is_tracking_prohibited() ) {
7752
+ // Don't send updates regarding opted-out installs.
7753
+ continue;
7754
+ }
7755
+
7756
+ $install_data = $this->get_site_info( $site );
7757
+
7758
+ $uid = $install_data['uid'];
7759
+
7760
+ unset( $install_data['blog_id'] );
7761
+ unset( $install_data['uid'] );
7762
+
7763
+ $install_data['is_disconnected'] = $install->is_disconnected;
7764
+ $install_data['is_active'] = $this->is_active_for_site( $blog_id );
7765
+ $install_data['is_uninstalled'] = $install->is_uninstalled;
7766
+
7767
+ $common_diff = null;
7768
+ $is_common_diff = false;
7769
+ if ( $only_diff ) {
7770
+ $install_data = $this->get_install_diff_for_api( $install_data, $install, $override );
7771
+ $common_diff = $this->get_install_diff_for_api( $common, $install, $override );
7772
+
7773
+ $is_common_diff = ! empty( $common_diff );
7774
+
7775
+ if ( $is_common_diff ) {
7776
+ foreach ( $common_diff as $k => $v ) {
7777
+ if ( ! isset( $common_diff_union[ $k ] ) ) {
7778
+ $common_diff_union[ $k ] = $v;
7779
+ }
7780
+ }
7781
+ }
7782
+
7783
+ $is_common_diff_for_any_site = $is_common_diff_for_any_site || $is_common_diff;
7784
+ }
7785
+
7786
+ if ( ! empty( $install_data ) || $is_common_diff ) {
7787
+ // Add install ID and site unique ID.
7788
+ $install_data['id'] = $install->id;
7789
+ $install_data['uid'] = $uid;
7790
+
7791
+ $installs_data[] = $install_data;
7792
+ }
7793
+ }
7794
+ }
7795
+
7796
+ restore_current_blog();
7797
+
7798
+ if ( 0 < count( $installs_data ) && ( $is_common_diff_for_any_site || ! $only_diff ) ) {
7799
+ if ( ! $only_diff ) {
7800
+ $installs_data[] = $common;
7801
+ } else if ( ! empty( $common_diff_union ) ) {
7802
+ $installs_data[] = $common_diff_union;
7803
+ }
7804
+ }
7805
+
7806
+ foreach ( $installs_data as &$data ) {
7807
+ $data = (object) $data;
7808
+ }
7809
+
7810
+ return $installs_data;
7811
+ }
7812
+
7813
+ /**
7814
+ * Compare site actual data to the stored install data and return the differences for an API data sync.
7815
+ *
7816
+ * @author Vova Feldman (@svovaf)
7817
+ * @since 2.0.0
7818
+ *
7819
+ * @param array $site
7820
+ * @param FS_Site $install
7821
+ * @param string[] string $override
7822
+ *
7823
+ * @return array
7824
+ */
7825
+ private function get_install_diff_for_api( $site, $install, $override = array() ) {
7826
+ $diff = array();
7827
+ $special = array();
7828
+ $special_override = false;
7829
+
7830
+ foreach ( $site as $p => $v ) {
7831
+ if ( property_exists( $install, $p ) ) {
7832
+ if ( ( is_bool( $install->{$p} ) || ! empty( $install->{$p} ) ) &&
7833
+ $install->{$p} != $v
7834
+ ) {
7835
+ $install->{$p} = $v;
7836
+ $diff[ $p ] = $v;
7837
+ }
7838
+ } else {
7839
+ $special[ $p ] = $v;
7840
+
7841
+ if ( isset( $override[ $p ] ) ||
7842
+ 'plugins' === $p ||
7843
+ 'themes' === $p
7844
+ ) {
7845
+ $special_override = true;
7846
+ }
7847
+ }
7848
+ }
7849
+
7850
+ if ( $special_override || 0 < count( $diff ) ) {
7851
+ // Add special params only if has at least one
7852
+ // standard param, or if explicitly requested to
7853
+ // override a special param or a param which is not exist
7854
+ // in the install object.
7855
+ $diff = array_merge( $diff, $special );
7856
+ }
7857
+
7858
+ return $diff;
7859
+ }
7860
+
7861
+ /**
7862
+ * Update install only if changed.
7863
+ *
7864
+ * @author Vova Feldman (@svovaf)
7865
+ * @since 1.0.9
7866
+ *
7867
+ * @param string[] string $override
7868
+ * @param bool $flush
7869
+ *
7870
+ * @return false|object|string
7871
+ */
7872
+ private function send_install_update( $override = array(), $flush = false ) {
7873
+ $this->_logger->entrance();
7874
+
7875
+ $check_properties = $this->get_install_data_for_api( $override );
7876
+
7877
+ if ( $flush ) {
7878
+ $params = $check_properties;
7879
+ } else {
7880
+ $params = $this->get_install_diff_for_api( $check_properties, $this->_site, $override );
7881
+ }
7882
+
7883
+ if ( 0 < count( $params ) ) {
7884
+ if ( ! is_multisite() ) {
7885
+ // Update last install sync timestamp.
7886
+ $this->set_cron_execution_timestamp( 'install_sync' );
7887
+ }
7888
+
7889
+ $params['uid'] = $this->get_anonymous_id();
7890
+
7891
+ // Send updated values to FS.
7892
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
7893
+
7894
+ if ( $this->is_api_result_entity( $site ) ) {
7895
+ if ( ! is_multisite() ) {
7896
+ // I successfully sent install update, clear scheduled sync if exist.
7897
+ $this->clear_install_sync_cron();
7898
+ }
7899
+ }
7900
+
7901
+ return $site;
7902
+ }
7903
+
7904
+ return false;
7905
+ }
7906
+
7907
+ /**
7908
+ * Update installs only if changed.
7909
+ *
7910
+ * @author Vova Feldman (@svovaf)
7911
+ * @since 2.0.0
7912
+ *
7913
+ * @param string[] string $override
7914
+ * @param bool $flush
7915
+ *
7916
+ * @return false|object|string
7917
+ */
7918
+ private function send_installs_update( $override = array(), $flush = false ) {
7919
+ $this->_logger->entrance();
7920
+
7921
+ $installs_data = $this->get_installs_data_for_api( $override, ! $flush );
7922
+
7923
+ if ( empty( $installs_data ) ) {
7924
+ return false;
7925
+ }
7926
+
7927
+ // Update last install sync timestamp.
7928
+ $this->set_cron_execution_timestamp( 'install_sync' );
7929
+
7930
+ // Send updated values to FS.
7931
+ $result = $this->get_api_user_scope()->call( "/plugins/{$this->_plugin->id}/installs.json", 'put', $installs_data );
7932
+
7933
+ if ( $this->is_api_result_object( $result, 'installs' ) ) {
7934
+ // I successfully sent installs update, clear scheduled sync if exist.
7935
+ $this->clear_install_sync_cron();
7936
+ }
7937
+
7938
+ return $result;
7939
+ }
7940
+
7941
+ /**
7942
+ * Update install only if changed.
7943
+ *
7944
+ * @author Vova Feldman (@svovaf)
7945
+ * @since 1.0.9
7946
+ *
7947
+ * @param string[] string $override
7948
+ * @param bool $flush
7949
+ */
7950
+ private function sync_install( $override = array(), $flush = false ) {
7951
+ $this->_logger->entrance();
7952
+
7953
+ $site = $this->send_install_update( $override, $flush );
7954
+
7955
+ if ( false === $site ) {
7956
+ // No sync required.
7957
+ return;
7958
+ }
7959
+
7960
+ if ( ! $this->is_api_result_entity( $site ) ) {
7961
+ // Failed to sync, don't update locally.
7962
+ return;
7963
+ }
7964
+
7965
+ $this->_site = new FS_Site( $site );
7966
+
7967
+ $this->_store_site( true );
7968
+ }
7969
+
7970
+ /**
7971
+ * Update install only if changed.
7972
+ *
7973
+ * @author Vova Feldman (@svovaf)
7974
+ * @since 1.0.9
7975
+ *
7976
+ * @param string[] string $override
7977
+ * @param bool $flush
7978
+ */
7979
+ private function sync_installs( $override = array(), $flush = false ) {
7980
+ $this->_logger->entrance();
7981
+
7982
+ $result = $this->send_installs_update( $override, $flush );
7983
+
7984
+ if ( false === $result ) {
7985
+ // No sync required.
7986
+ return;
7987
+ }
7988
+
7989
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
7990
+ // Failed to sync, don't update locally.
7991
+ return;
7992
+ }
7993
+
7994
+ $address_to_blog_map = $this->get_address_to_blog_map();
7995
+
7996
+ foreach ( $result->installs as $install ) {
7997
+ $this->_site = new FS_Site( $install );
7998
+
7999
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
8000
+ $blog_id = $address_to_blog_map[ $address ];
8001
+
8002
+ $this->_store_site( true, $blog_id );
8003
+ }
8004
+ }
8005
+
8006
+ /**
8007
+ * Track install's custom event.
8008
+ *
8009
+ * IMPORTANT:
8010
+ * Custom event tracking is currently only supported for specific clients.
8011
+ * If you are not one of them, please don't use this method. If you will,
8012
+ * the API will simply ignore your request based on the plugin ID.
8013
+ *
8014
+ * Need custom tracking for your plugin or theme?
8015
+ * If you are interested in custom event tracking please contact yo@freemius.com
8016
+ * for further details.
8017
+ *
8018
+ * @author Vova Feldman (@svovaf)
8019
+ * @since 1.2.1
8020
+ *
8021
+ * @param string $name Event name.
8022
+ * @param array $properties Associative key/value array with primitive values only
8023
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
8024
+ * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
8025
+ *
8026
+ * @return object|false Event data or FALSE on failure.
8027
+ *
8028
+ * @throws \Freemius_InvalidArgumentException
8029
+ */
8030
+ public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
8031
+ $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
8032
+
8033
+ if ( ! $this->is_registered() ) {
8034
+ return false;
8035
+ }
8036
+
8037
+ $event = array( 'type' => $name );
8038
+
8039
+ if ( is_numeric( $process_at ) && $process_at > time() ) {
8040
+ $event['process_at'] = $process_at;
8041
+ }
8042
+
8043
+ if ( $once ) {
8044
+ $event['once'] = true;
8045
+ }
8046
+
8047
+ if ( ! empty( $properties ) ) {
8048
+ // Verify associative array values are primitive.
8049
+ foreach ( $properties as $k => $v ) {
8050
+ if ( ! is_scalar( $v ) ) {
8051
+ throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
8052
+ }
8053
+ }
8054
+
8055
+ $event['properties'] = $properties;
8056
+ }
8057
+
8058
+ $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
8059
+
8060
+ return $this->is_api_error( $result ) ?
8061
+ false :
8062
+ $result;
8063
+ }
8064
+
8065
+ /**
8066
+ * Track install's custom event only once, but it still triggers the API call.
8067
+ *
8068
+ * IMPORTANT:
8069
+ * Custom event tracking is currently only supported for specific clients.
8070
+ * If you are not one of them, please don't use this method. If you will,
8071
+ * the API will simply ignore your request based on the plugin ID.
8072
+ *
8073
+ * Need custom tracking for your plugin or theme?
8074
+ * If you are interested in custom event tracking please contact yo@freemius.com
8075
+ * for further details.
8076
+ *
8077
+ * @author Vova Feldman (@svovaf)
8078
+ * @since 1.2.1
8079
+ *
8080
+ * @param string $name Event name.
8081
+ * @param array $properties Associative key/value array with primitive values only
8082
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
8083
+ *
8084
+ * @return object|false Event data or FALSE on failure.
8085
+ *
8086
+ * @throws \Freemius_InvalidArgumentException
8087
+ *
8088
+ * @user Freemius::track_event()
8089
+ */
8090
+ public function track_event_once( $name, $properties = array(), $process_at = false ) {
8091
+ return $this->track_event( $name, $properties, $process_at, true );
8092
+ }
8093
+
8094
+ /**
8095
+ * Plugin uninstall hook.
8096
+ *
8097
+ * @author Vova Feldman (@svovaf)
8098
+ * @since 1.0.1
8099
+ *
8100
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
8101
+ */
8102
+ function _uninstall_plugin_event( $check_user = true ) {
8103
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
8104
+
8105
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
8106
+ return;
8107
+ }
8108
+
8109
+ $params = array();
8110
+ $uninstall_reason = null;
8111
+ if ( isset( $this->_storage->uninstall_reason ) ) {
8112
+ $uninstall_reason = $this->_storage->uninstall_reason;
8113
+ $params['reason_id'] = $uninstall_reason->id;
8114
+ $params['reason_info'] = $uninstall_reason->info;
8115
+ }
8116
+
8117
+ if ( ! $this->is_registered() ) {
8118
+ // Send anonymous uninstall event only if user submitted a feedback.
8119
+ if ( isset( $uninstall_reason ) ) {
8120
+ if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
8121
+ $this->opt_in( false, false, false, false, true );
8122
+ } else {
8123
+ $params['uid'] = $this->get_anonymous_id();
8124
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
8125
+ }
8126
+ }
8127
+ } else {
8128
+ $params = array_merge( $params, array(
8129
+ 'is_active' => false,
8130
+ 'is_uninstalled' => true,
8131
+ ) );
8132
+
8133
+ if ( $this->_is_network_active ) {
8134
+ // Send uninstall event.
8135
+ $this->send_installs_update( $params );
8136
+ } else {
8137
+ // Send uninstall event.
8138
+ $this->send_install_update( $params );
8139
+ }
8140
+ }
8141
+
8142
+ // @todo Decide if we want to delete plugin information from db.
8143
+ }
8144
+
8145
+ /**
8146
+ * @author Vova Feldman (@svovaf)
8147
+ * @since 1.1.1
8148
+ *
8149
+ * @return string
8150
+ */
8151
+ function premium_plugin_basename() {
8152
+ return "{$this->_slug}-premium/" . basename( $this->_free_plugin_basename );
8153
+ }
8154
+
8155
+ /**
8156
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
8157
+ *
8158
+ * @author Vova Feldman (@svovaf)
8159
+ * @since 1.0.2
8160
+ */
8161
+ public static function _uninstall_plugin_hook() {
8162
+ self::_load_required_static();
8163
+
8164
+ self::$_static_logger->entrance();
8165
+
8166
+ if ( ! current_user_can( 'activate_plugins' ) ) {
8167
+ return;
8168
+ }
8169
+
8170
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
8171
+
8172
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
8173
+
8174
+ define( 'WP_FS__UNINSTALL_MODE', true );
8175
+
8176
+ $fs = self::get_instance_by_file( $plugin_file );
8177
+
8178
+ if ( is_object( $fs ) ) {
8179
+ self::require_plugin_essentials();
8180
+
8181
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
8182
+ is_plugin_active( $fs->premium_plugin_basename() )
8183
+ ) {
8184
+ // Deleting Free or Premium plugin version while the other version still installed.
8185
+ return;
8186
+ }
8187
+
8188
+ $fs->_uninstall_plugin_event();
8189
+
8190
+ $fs->do_action( 'after_uninstall' );
8191
+ }
8192
+ }
8193
+
8194
+ #----------------------------------------------------------------------------------
8195
+ #region Plugin Information
8196
+ #----------------------------------------------------------------------------------
8197
+
8198
+ /**
8199
+ * Load WordPress core plugin.php essential module.
8200
+ *
8201
+ * @author Vova Feldman (@svovaf)
8202
+ * @since 1.1.1
8203
+ */
8204
+ private static function require_plugin_essentials() {
8205
+ if ( ! function_exists( 'get_plugins' ) ) {
8206
+ self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
8207
+
8208
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
8209
+ }
8210
+ }
8211
+
8212
+ /**
8213
+ * Load WordPress core pluggable.php module.
8214
+ *
8215
+ * @author Vova Feldman (@svovaf)
8216
+ * @since 1.1.2
8217
+ */
8218
+ private static function require_pluggable_essentials() {
8219
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
8220
+ require_once ABSPATH . 'wp-includes/pluggable.php';
8221
+ }
8222
+ }
8223
+
8224
+ /**
8225
+ * Return plugin data.
8226
+ *
8227
+ * @author Vova Feldman (@svovaf)
8228
+ * @since 1.0.1
8229
+ *
8230
+ * @return array
8231
+ */
8232
+ function get_plugin_data() {
8233
+ if ( ! isset( $this->_plugin_data ) ) {
8234
+ self::require_plugin_essentials();
8235
+
8236
+ if ( $this->is_plugin() ) {
8237
+ /**
8238
+ * @author Vova Feldman (@svovaf)
8239
+ * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
8240
+ *
8241
+ * @link https://github.com/Freemius/wordpress-sdk/issues/77
8242
+ */
8243
+ $plugin_data = get_plugin_data(
8244
+ $this->_plugin_main_file_path,
8245
+ false,
8246
+ false
8247
+ );
8248
+ } else {
8249
+ $theme_data = wp_get_theme();
8250
+
8251
+ if ( $this->_plugin_basename !== $theme_data->get_stylesheet() && is_child_theme() ) {
8252
+ $parent_theme = $theme_data->parent();
8253
+
8254
+ if ( ( $parent_theme instanceof WP_Theme ) && $this->_plugin_basename === $parent_theme->get_stylesheet() ) {
8255
+ $theme_data = $parent_theme;
8256
+ }
8257
+ }
8258
+
8259
+ $plugin_data = array(
8260
+ 'Name' => $theme_data->get( 'Name' ),
8261
+ 'Version' => $theme_data->get( 'Version' ),
8262
+ 'Author' => $theme_data->get( 'Author' ),
8263
+ 'Description' => $theme_data->get( 'Description' ),
8264
+ 'PluginURI' => $theme_data->get( 'ThemeURI' ),
8265
+ );
8266
+ }
8267
+
8268
+ $this->_plugin_data = $plugin_data;
8269
+ }
8270
+
8271
+ return $this->_plugin_data;
8272
+ }
8273
+
8274
+ /**
8275
+ * @author Vova Feldman (@svovaf)
8276
+ * @since 1.0.1
8277
+ * @since 1.2.2.5 If slug not set load slug by module ID.
8278
+ *
8279
+ * @return string Plugin slug.
8280
+ */
8281
+ function get_slug() {
8282
+ if ( ! isset( $this->_slug ) ) {
8283
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
8284
+ $this->_slug = $id_slug_type_path_map[ $this->_module_id ]['slug'];
8285
+ }
8286
+
8287
+ return $this->_slug;
8288
+ }
8289
+
8290
+ /**
8291
+ * @author Vova Feldman (@svovaf)
8292
+ * @since 1.2.1.7
8293
+ *
8294
+ * @return string Plugin slug.
8295
+ */
8296
+ function get_target_folder_name() {
8297
+ return $this->_slug . ( $this->can_use_premium_code() ? '-premium' : '' );
8298
+ }
8299
+
8300
+ /**
8301
+ * @author Vova Feldman (@svovaf)
8302
+ * @since 1.0.1
8303
+ *
8304
+ * @return number Plugin ID.
8305
+ */
8306
+ function get_id() {
8307
+ return $this->_plugin->id;
8308
+ }
8309
+
8310
+ /**
8311
+ * @author Vova Feldman (@svovaf)
8312
+ * @since 1.2.1.5
8313
+ *
8314
+ * @return string Freemius SDK version
8315
+ */
8316
+ function get_sdk_version() {
8317
+ return $this->version;
8318
+ }
8319
+
8320
+ /**
8321
+ * @author Vova Feldman (@svovaf)
8322
+ * @since 1.2.1.5
8323
+ *
8324
+ * @return number Parent plugin ID (if parent exist).
8325
+ */
8326
+ function get_parent_id() {
8327
+ return $this->is_addon() ?
8328
+ $this->get_parent_instance()->get_id() :
8329
+ $this->_plugin->id;
8330
+ }
8331
+
8332
+ /**
8333
+ * @author Vova Feldman (@svovaf)
8334
+ * @since 1.0.1
8335
+ *
8336
+ * @return string Plugin public key.
8337
+ */
8338
+ function get_public_key() {
8339
+ return $this->_plugin->public_key;
8340
+ }
8341
+
8342
+ /**
8343
+ * Will be available only on sandbox mode.
8344
+ *
8345
+ * @author Vova Feldman (@svovaf)
8346
+ * @since 1.0.4
8347
+ *
8348
+ * @return mixed Plugin secret key.
8349
+ */
8350
+ function get_secret_key() {
8351
+ return $this->_plugin->secret_key;
8352
+ }
8353
+
8354
+ /**
8355
+ * @author Vova Feldman (@svovaf)
8356
+ * @since 1.1.1
8357
+ *
8358
+ * @return bool
8359
+ */
8360
+ function has_secret_key() {
8361
+ return ! empty( $this->_plugin->secret_key );
8362
+ }
8363
+
8364
+ /**
8365
+ * @author Vova Feldman (@svovaf)
8366
+ * @since 1.0.9
8367
+ *
8368
+ * @return string
8369
+ */
8370
+ function get_plugin_name() {
8371
+ $this->_logger->entrance();
8372
+
8373
+ if ( ! isset( $this->_plugin_name ) ) {
8374
+ $plugin_data = $this->get_plugin_data();
8375
+
8376
+ // Get name.
8377
+ $this->_plugin_name = $plugin_data['Name'];
8378
+
8379
+ // Check if plugin name contains "(Premium)" suffix and remove it.
8380
+ $suffix = ' (premium)';
8381
+ $suffix_len = strlen( $suffix );
8382
+
8383
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
8384
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
8385
+ ) {
8386
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
8387
+ }
8388
+
8389
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
8390
+ }
8391
+
8392
+ return $this->_plugin_name;
8393
+ }
8394
+
8395
+ /**
8396
+ * @author Vova Feldman (@svovaf)
8397
+ * @since 1.0.0
8398
+ *
8399
+ * @return string
8400
+ */
8401
+ function get_plugin_version() {
8402
+ $this->_logger->entrance();
8403
+
8404
+ $plugin_data = $this->get_plugin_data();
8405
+
8406
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
8407
+
8408
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
8409
+ }
8410
+
8411
+ /**
8412
+ * @author Vova Feldman (@svovaf)
8413
+ * @since 1.2.1.7
8414
+ *
8415
+ * @return string
8416
+ */
8417
+ function get_plugin_title() {
8418
+ $this->_logger->entrance();
8419
+
8420
+ $title = $this->_plugin->title;
8421
+
8422
+ return $this->apply_filters( 'plugin_title', $title );
8423
+ }
8424
+
8425
+ /**
8426
+ * @author Vova Feldman (@svovaf)
8427
+ * @since 1.2.2.7
8428
+ *
8429
+ * @param bool $lowercase
8430
+ *
8431
+ * @return string
8432
+ */
8433
+ function get_module_label( $lowercase = false ) {
8434
+ $label = $this->is_addon() ?
8435
+ $this->get_text_inline( 'Add-On', 'addon' ) :
8436
+ ( $this->is_plugin() ?
8437
+ $this->get_text_inline( 'Plugin', 'plugin' ) :
8438
+ $this->get_text_inline( 'Theme', 'theme' ) );
8439
+
8440
+ if ( $lowercase ) {
8441
+ $label = strtolower( $label );
8442
+ }
8443
+
8444
+ return $label;
8445
+ }
8446
+
8447
+ /**
8448
+ * @author Vova Feldman (@svovaf)
8449
+ * @since 1.0.4
8450
+ *
8451
+ * @return string
8452
+ */
8453
+ function get_plugin_basename() {
8454
+ if ( ! isset( $this->_plugin_basename ) ) {
8455
+ if ( $this->is_plugin() ) {
8456
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
8457
+ } else {
8458
+ $this->_plugin_basename = basename( dirname( $this->_plugin_main_file_path ) );
8459
+ }
8460
+ }
8461
+
8462
+ return $this->_plugin_basename;
8463
+ }
8464
+
8465
+ function get_plugin_folder_name() {
8466
+ $this->_logger->entrance();
8467
+
8468
+ $plugin_folder = $this->_plugin_basename;
8469
+
8470
+ while ( '.' !== dirname( $plugin_folder ) ) {
8471
+ $plugin_folder = dirname( $plugin_folder );
8472
+ }
8473
+
8474
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
8475
+
8476
+ return $plugin_folder;
8477
+ }
8478
+
8479
+ #endregion ------------------------------------------------------------------
8480
+
8481
+ /* Account
8482
+ ------------------------------------------------------------------------------------------------------------------*/
8483
+
8484
+ /**
8485
+ * Find plugin's slug by plugin's basename.
8486
+ *
8487
+ * @author Vova Feldman (@svovaf)
8488
+ * @since 1.0.9
8489
+ *
8490
+ * @param string $plugin_base_name
8491
+ *
8492
+ * @return false|string
8493
+ */
8494
+ private static function find_slug_by_basename( $plugin_base_name ) {
8495
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
8496
+
8497
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
8498
+ return false;
8499
+ }
8500
+
8501
+ return $file_slug_map[ $plugin_base_name ];
8502
+ }
8503
+
8504
+ /**
8505
+ * Store the map between the plugin's basename to the slug.
8506
+ *
8507
+ * @author Vova Feldman (@svovaf)
8508
+ * @since 1.0.9
8509
+ */
8510
+ private function store_file_slug_map() {
8511
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
8512
+
8513
+ if ( ! array( $file_slug_map ) ) {
8514
+ $file_slug_map = array();
8515
+ }
8516
+
8517
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
8518
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
8519
+ ) {
8520
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
8521
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
8522
+ }
8523
+ }
8524
+
8525
+ /**
8526
+ * @return array[number]FS_User
8527
+ */
8528
+ static function get_all_users() {
8529
+ $users = self::$_accounts->get_option( 'users', array() );
8530
+
8531
+ if ( ! is_array( $users ) ) {
8532
+ $users = array();
8533
+ }
8534
+
8535
+ return $users;
8536
+ }
8537
+
8538
+ /**
8539
+ * @param string $module_type
8540
+ * @param null|int $blog_id Since 2.0.0
8541
+ *
8542
+ * @return array[string]FS_Site
8543
+ */
8544
+ private static function get_all_sites(
8545
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN,
8546
+ $blog_id = null
8547
+ ) {
8548
+ $sites = self::get_account_option( 'sites', $module_type, $blog_id );
8549
+
8550
+ if ( ! is_array( $sites ) ) {
8551
+ $sites = array();
8552
+ }
8553
+
8554
+ return $sites;
8555
+ }
8556
+
8557
+ /**
8558
+ * @author Leo Fajardo (@leorw)
8559
+ *
8560
+ * @since 1.2.2
8561
+ *
8562
+ * @param string $option_name
8563
+ * @param string $module_type
8564
+ * @param null|int $network_level_or_blog_id Since 2.0.0
8565
+ *
8566
+ * @return mixed
8567
+ */
8568
+ private static function get_account_option( $option_name, $module_type = null, $network_level_or_blog_id = null ) {
8569
+ if ( ! is_null( $module_type ) && WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
8570
+ $option_name = $module_type . '_' . $option_name;
8571
+ }
8572
+
8573
+ return self::$_accounts->get_option( $option_name, array(), $network_level_or_blog_id );
8574
+ }
8575
+
8576
+ /**
8577
+ * @author Leo Fajardo (@leorw)
8578
+ *
8579
+ * @since 1.2.2
8580
+ *
8581
+ * @param string $option_name
8582
+ * @param mixed $option_value
8583
+ * @param bool $store
8584
+ * @param null|int $network_level_or_blog_id Since 2.0.0
8585
+ */
8586
+ private function set_account_option( $option_name, $option_value, $store, $network_level_or_blog_id = null ) {
8587
+ self::set_account_option_by_module(
8588
+ $this->_module_type,
8589
+ $option_name,
8590
+ $option_value,
8591
+ $store,
8592
+ $network_level_or_blog_id
8593
+ );
8594
+ }
8595
+
8596
+ /**
8597
+ * @author Vova Feldman (@svovaf)
8598
+ *
8599
+ * @since 1.2.2.7
8600
+ *
8601
+ * @param string $module_type
8602
+ * @param string $option_name
8603
+ * @param mixed $option_value
8604
+ * @param bool $store
8605
+ * @param null|int $network_level_or_blog_id Since 2.0.0
8606
+ */
8607
+ private static function set_account_option_by_module(
8608
+ $module_type,
8609
+ $option_name,
8610
+ $option_value,
8611
+ $store,
8612
+ $network_level_or_blog_id = null
8613
+ ) {
8614
+ if ( WP_FS__MODULE_TYPE_PLUGIN != $module_type ) {
8615
+ $option_name = $module_type . '_' . $option_name;
8616
+ }
8617
+
8618
+ self::$_accounts->set_option( $option_name, $option_value, $store, $network_level_or_blog_id );
8619
+ }
8620
+
8621
+ /**
8622
+ * @author Vova Feldman (@svovaf)
8623
+ * @since 1.0.6
8624
+ *
8625
+ * @param number|null $module_id
8626
+ *
8627
+ * @return FS_Plugin_License[]
8628
+ */
8629
+ private static function get_all_licenses( $module_id = null ) {
8630
+ $licenses = self::get_account_option( 'all_licenses' );
8631
+
8632
+ if ( ! is_array( $licenses ) ) {
8633
+ $licenses = array();
8634
+ }
8635
+
8636
+ if ( is_null( $module_id ) ) {
8637
+ return $licenses;
8638
+ }
8639
+
8640
+ $licenses = isset( $licenses[ $module_id ] ) ?
8641
+ $licenses[ $module_id ] :
8642
+ array();
8643
+
8644
+ return $licenses;
8645
+ }
8646
+
8647
+ /**
8648
+ * @author Leo Fajardo (@leorw)
8649
+ * @since 2.0.0
8650
+ *
8651
+ * @return array
8652
+ */
8653
+ private static function get_all_licenses_by_module_type() {
8654
+ $licenses = self::get_account_option( 'all_licenses' );
8655
+
8656
+ $licenses_by_module_type = array(
8657
+ WP_FS__MODULE_TYPE_PLUGIN => array(),
8658
+ WP_FS__MODULE_TYPE_THEME => array()
8659
+ );
8660
+
8661
+ if ( ! is_array( $licenses ) ) {
8662
+ return $licenses_by_module_type;
8663
+ }
8664
+
8665
+ foreach ( $licenses as $module_id => $module_licenses ) {
8666
+ $fs = self::get_instance_by_id( $module_id );
8667
+ if ( false === $fs ) {
8668
+ continue;
8669
+ }
8670
+
8671
+ $licenses_by_module_type[ $fs->_module_type ] = array_merge( $licenses_by_module_type[ $fs->_module_type ], $module_licenses );
8672
+ }
8673
+
8674
+ return $licenses_by_module_type;
8675
+ }
8676
+
8677
+ /**
8678
+ * @author Leo Fajardo (@leorw)
8679
+ * @since 2.0.0
8680
+ *
8681
+ * @param number $module_id
8682
+ * @param number|null $user_id
8683
+ *
8684
+ * @return array
8685
+ */
8686
+ private static function get_user_id_license_ids_map( $module_id, $user_id = null ) {
8687
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
8688
+
8689
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
8690
+ $all_modules_user_id_license_ids_map = array();
8691
+ }
8692
+
8693
+ $user_id_license_ids_map = isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ?
8694
+ $all_modules_user_id_license_ids_map[ $module_id ] :
8695
+ array();
8696
+
8697
+ if ( FS_User::is_valid_id( $user_id ) ) {
8698
+ $user_id_license_ids_map = isset( $user_id_license_ids_map[ $user_id ] ) ?
8699
+ $user_id_license_ids_map[ $user_id ] :
8700
+ array();
8701
+ }
8702
+
8703
+ return $user_id_license_ids_map;
8704
+ }
8705
+
8706
+ /**
8707
+ * @author Leo Fajardo (@leorw)
8708
+ * @since 2.0.0
8709
+ *
8710
+ * @param array $new_user_id_license_ids_map
8711
+ * @param number $module_id
8712
+ * @param number|null $user_id
8713
+ */
8714
+ private static function store_user_id_license_ids_map( $new_user_id_license_ids_map, $module_id, $user_id = null ) {
8715
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
8716
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
8717
+ $all_modules_user_id_license_ids_map = array();
8718
+ }
8719
+
8720
+ if ( ! isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ) {
8721
+ $all_modules_user_id_license_ids_map[ $module_id ] = array();
8722
+ }
8723
+
8724
+ if ( FS_User::is_valid_id( $user_id ) ) {
8725
+ $all_modules_user_id_license_ids_map[ $module_id ][ $user_id ] = $new_user_id_license_ids_map;
8726
+ } else {
8727
+ $all_modules_user_id_license_ids_map[ $module_id ] = $new_user_id_license_ids_map;
8728
+ }
8729
+
8730
+ self::$_accounts->set_option( 'user_id_license_ids_map', $all_modules_user_id_license_ids_map, true );
8731
+ }
8732
+
8733
+ /**
8734
+ * Get a collection of the user's linked license IDs.
8735
+ *
8736
+ * @author Vova Feldman (@svovaf)
8737
+ * @since 2.0.0
8738
+ *
8739
+ * @param number $user_id
8740
+ *
8741
+ * @return number[]
8742
+ */
8743
+ private function get_user_linked_license_ids( $user_id ) {
8744
+ return self::get_user_id_license_ids_map( $this->_module_id, $user_id );
8745
+ }
8746
+
8747
+ /**
8748
+ * Override the user's linked license IDs with a new IDs collection.
8749
+ *
8750
+ * @author Vova Feldman (@svovaf)
8751
+ * @since 2.0.0
8752
+ *
8753
+ * @param number $user_id
8754
+ * @param number[] $license_ids
8755
+ */
8756
+ private function set_user_linked_license_ids( $user_id, array $license_ids ) {
8757
+ self::store_user_id_license_ids_map( $license_ids, $this->_module_id, $user_id );
8758
+ }
8759
+
8760
+ /**
8761
+ * Link a specified license ID to a given user.
8762
+ *
8763
+ * @author Vova Feldman (@svovaf)
8764
+ * @since 2.0.0
8765
+ *
8766
+ * @param number $license_id
8767
+ * @param number $user_id
8768
+ */
8769
+ private function link_license_2_user( $license_id, $user_id ) {
8770
+ $license_ids = $this->get_user_linked_license_ids( $user_id );
8771
+
8772
+ if ( in_array( $license_id, $license_ids ) ) {
8773
+ // License already linked.
8774
+ return;
8775
+ }
8776
+
8777
+ $license_ids[] = $license_id;
8778
+
8779
+ $this->set_user_linked_license_ids( $user_id, $license_ids );
8780
+ }
8781
+
8782
+ /**
8783
+ * @param string|bool $module_type
8784
+ *
8785
+ * @return FS_Plugin_Plan[]
8786
+ */
8787
+ private static function get_all_plans( $module_type = false ) {
8788
+ $plans = self::get_account_option( 'plans', $module_type );
8789
+
8790
+ if ( ! is_array( $plans ) ) {
8791
+ $plans = array();
8792
+ }
8793
+
8794
+ return $plans;
8795
+ }
8796
+
8797
+ /**
8798
+ * @author Vova Feldman (@svovaf)
8799
+ * @since 1.0.4
8800
+ *
8801
+ * @return FS_Plugin_Tag[]
8802
+ */
8803
+ private static function get_all_updates() {
8804
+ $updates = self::$_accounts->get_option( 'updates', array() );
8805
+
8806
+ if ( ! is_array( $updates ) ) {
8807
+ $updates = array();
8808
+ }
8809
+
8810
+ return $updates;
8811
+ }
8812
+
8813
+ /**
8814
+ * @author Vova Feldman (@svovaf)
8815
+ * @since 1.0.6
8816
+ *
8817
+ * @return array<number,FS_Plugin[]>|false
8818
+ */
8819
+ private static function get_all_addons() {
8820
+ $addons = self::$_accounts->get_option( 'addons', array() );
8821
+
8822
+ if ( ! is_array( $addons ) ) {
8823
+ $addons = array();
8824
+ }
8825
+
8826
+ return $addons;
8827
+ }
8828
+
8829
+ /**
8830
+ * @author Vova Feldman (@svovaf)
8831
+ * @since 1.0.6
8832
+ *
8833
+ * @return FS_Plugin[]|false
8834
+ */
8835
+ private static function get_all_account_addons() {
8836
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
8837
+
8838
+ if ( ! is_array( $addons ) ) {
8839
+ $addons = array();
8840
+ }
8841
+
8842
+ return $addons;
8843
+ }
8844
+
8845
+ /**
8846
+ * Check if user has connected his account (opted-in).
8847
+ *
8848
+ * Note:
8849
+ * If the user opted-in and opted-out on a later stage,
8850
+ * this will still return true. If you want to check if the
8851
+ * user is currently opted-in, use:
8852
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
8853
+ *
8854
+ * @author Vova Feldman (@svovaf)
8855
+ * @since 1.0.1
8856
+ * @return bool
8857
+ */
8858
+ function is_registered() {
8859
+ return is_object( $this->_user );
8860
+ }
8861
+
8862
+ /**
8863
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
8864
+ *
8865
+ * @author Leo Fajardo (@leorw)
8866
+ * @since 1.2.1.5
8867
+ *
8868
+ * @return bool
8869
+ */
8870
+ function is_tracking_allowed() {
8871
+ return ( is_object( $this->_site ) && $this->_site->is_tracking_allowed() );
8872
+ }
8873
+
8874
+ /**
8875
+ * @author Vova Feldman (@svovaf)
8876
+ * @since 1.0.4
8877
+ *
8878
+ * @return FS_Plugin
8879
+ */
8880
+ function get_plugin() {
8881
+ return $this->_plugin;
8882
+ }
8883
+
8884
+ /**
8885
+ * @author Vova Feldman (@svovaf)
8886
+ * @since 1.0.3
8887
+ *
8888
+ * @return FS_User
8889
+ */
8890
+ function get_user() {
8891
+ return $this->_user;
8892
+ }
8893
+
8894
+ /**
8895
+ * @author Vova Feldman (@svovaf)
8896
+ * @since 1.0.3
8897
+ *
8898
+ * @return FS_Site
8899
+ */
8900
+ function get_site() {
8901
+ return $this->_site;
8902
+ }
8903
+
8904
+ /**
8905
+ * Get plugin add-ons.
8906
+ *
8907
+ * @author Vova Feldman (@svovaf)
8908
+ * @since 1.0.6
8909
+ *
8910
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
8911
+ *
8912
+ * @param bool $flush
8913
+ *
8914
+ * @return FS_Plugin[]|false
8915
+ */
8916
+ function get_addons( $flush = false ) {
8917
+ $this->_logger->entrance();
8918
+
8919
+ if ( ! $this->_has_addons ) {
8920
+ return false;
8921
+ }
8922
+
8923
+ $addons = $this->sync_addons( $flush );
8924
+
8925
+ return ( ! is_array( $addons ) || empty( $addons ) ) ?
8926
+ false :
8927
+ $addons;
8928
+ }
8929
+
8930
+ /**
8931
+ * @author Vova Feldman (@svovaf)
8932
+ * @since 1.0.6
8933
+ *
8934
+ * @return FS_Plugin[]|false
8935
+ */
8936
+ function get_account_addons() {
8937
+ $this->_logger->entrance();
8938
+
8939
+ $addons = self::get_all_account_addons();
8940
+
8941
+ if ( ! is_array( $addons ) ||
8942
+ ! isset( $addons[ $this->_plugin->id ] ) ||
8943
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
8944
+ 0 === count( $addons[ $this->_plugin->id ] )
8945
+ ) {
8946
+ return false;
8947
+ }
8948
+
8949
+ return $addons[ $this->_plugin->id ];
8950
+ }
8951
+
8952
+ /**
8953
+ * Check if user has any
8954
+ *
8955
+ * @author Vova Feldman (@svovaf)
8956
+ * @since 1.1.6
8957
+ *
8958
+ * @return bool
8959
+ */
8960
+ function has_account_addons() {
8961
+ $addons = $this->get_account_addons();
8962
+
8963
+ return is_array( $addons ) && ( 0 < count( $addons ) );
8964
+ }
8965
+
8966
+
8967
+ /**
8968
+ * Get add-on by ID (from local data).
8969
+ *
8970
+ * @author Vova Feldman (@svovaf)
8971
+ * @since 1.0.6
8972
+ *
8973
+ * @param number $id
8974
+ *
8975
+ * @return FS_Plugin|false
8976
+ */
8977
+ function get_addon( $id ) {
8978
+ $this->_logger->entrance();
8979
+
8980
+ $addons = $this->get_addons();
8981
+
8982
+ if ( is_array( $addons ) ) {
8983
+ foreach ( $addons as $addon ) {
8984
+ if ( $id == $addon->id ) {
8985
+ return $addon;
8986
+ }
8987
+ }
8988
+ }
8989
+
8990
+ return false;
8991
+ }
8992
+
8993
+ /**
8994
+ * Get add-on by slug (from local data).
8995
+ *
8996
+ * @author Vova Feldman (@svovaf)
8997
+ * @since 1.0.6
8998
+ *
8999
+ * @param string $slug
9000
+ *
9001
+ * @param bool $flush
9002
+ *
9003
+ * @return FS_Plugin|false
9004
+ */
9005
+ function get_addon_by_slug( $slug, $flush = false ) {
9006
+ $this->_logger->entrance();
9007
+
9008
+ $addons = $this->get_addons( $flush );
9009
+
9010
+ if ( is_array( $addons ) ) {
9011
+ foreach ( $addons as $addon ) {
9012
+ if ( $slug === $addon->slug ) {
9013
+ return $addon;
9014
+ }
9015
+ }
9016
+ }
9017
+
9018
+ return false;
9019
+ }
9020
+
9021
+ /**
9022
+ * @author Vova Feldman (@svovaf)
9023
+ * @since 2.0.0
9024
+ *
9025
+ * @param number $user_id
9026
+ *
9027
+ * @return FS_User
9028
+ */
9029
+ static function _get_user_by_id( $user_id ) {
9030
+ self::$_static_logger->entrance( "user_id = {$user_id}" );
9031
+
9032
+ $users = self::get_all_users();
9033
+
9034
+ if ( is_array( $users ) ) {
9035
+ if ( isset( $users[ $user_id ] ) &&
9036
+ $users[ $user_id ] instanceof FS_User &&
9037
+ $user_id == $users[ $user_id ]->id
9038
+ ) {
9039
+ return $users[ $user_id ];
9040
+ }
9041
+
9042
+ // If user wasn't found by the key, iterate over all the users collection.
9043
+ foreach ( $users as $user ) {
9044
+ /**
9045
+ * @var FS_User $user
9046
+ */
9047
+ if ( $user_id == $user->id ) {
9048
+ return $user;
9049
+ }
9050
+ }
9051
+ }
9052
+
9053
+ return null;
9054
+ }
9055
+
9056
+ /**
9057
+ * Checks if a Freemius user_id is associated with a super-admin.
9058
+ *
9059
+ * @author Vova Feldman (@svovaf)
9060
+ * @since 2.0.0
9061
+ *
9062
+ * @param number $user_id
9063
+ *
9064
+ * @return bool
9065
+ */
9066
+ private static function is_super_admin( $user_id ) {
9067
+ $is_super_admin = false;
9068
+
9069
+ $user = self::_get_user_by_id( $user_id );
9070
+
9071
+ if ( $user instanceof FS_User && ! empty( $user->email ) ) {
9072
+ self::require_pluggable_essentials();
9073
+
9074
+ $wp_user = get_user_by( 'email', $user->email );
9075
+
9076
+ if ( $wp_user instanceof WP_User ) {
9077
+ $super_admins = get_super_admins();
9078
+ $is_super_admin = ( is_array( $super_admins ) && in_array( $wp_user->user_login, $super_admins ) );
9079
+ }
9080
+ }
9081
+
9082
+ return $is_super_admin;
9083
+ }
9084
+
9085
+ #----------------------------------------------------------------------------------
9086
+ #region Plans & Licensing
9087
+ #----------------------------------------------------------------------------------
9088
+
9089
+ /**
9090
+ * Check if running premium plugin code.
9091
+ *
9092
+ * @author Vova Feldman (@svovaf)
9093
+ * @since 1.0.5
9094
+ *
9095
+ * @return bool
9096
+ */
9097
+ function is_premium() {
9098
+ return $this->_plugin->is_premium;
9099
+ }
9100
+
9101
+ /**
9102
+ * Get site's plan ID.
9103
+ *
9104
+ * @author Vova Feldman (@svovaf)
9105
+ * @since 1.0.2
9106
+ *
9107
+ * @return number
9108
+ */
9109
+ function get_plan_id() {
9110
+ return $this->_site->plan_id;
9111
+ }
9112
+
9113
+ /**
9114
+ * Get site's plan title.
9115
+ *
9116
+ * @author Vova Feldman (@svovaf)
9117
+ * @since 1.0.2
9118
+ *
9119
+ * @return string
9120
+ */
9121
+ function get_plan_title() {
9122
+ $plan = $this->get_plan();
9123
+
9124
+ return is_object( $plan ) ? $plan->title : 'PLAN_TITLE';
9125
+ }
9126
+
9127
+ /**
9128
+ * Get site's plan name.
9129
+ *
9130
+ * @author Vova Feldman (@svovaf)
9131
+ * @since 2.0.0
9132
+ *
9133
+ * @return string
9134
+ */
9135
+ function get_plan_name() {
9136
+ $plan = $this->get_plan();
9137
+
9138
+ return is_object( $plan ) ? $plan->name : 'PLAN_NAME';
9139
+ }
9140
+
9141
+ /**
9142
+ * @author Vova Feldman (@svovaf)
9143
+ * @since 1.0.9
9144
+ *
9145
+ * @return FS_Plugin_Plan|false
9146
+ */
9147
+ function get_plan() {
9148
+ if ( ! is_object( $this->_site ) ) {
9149
+ return false;
9150
+ }
9151
+
9152
+ return FS_Plugin_Plan::is_valid_id( $this->_site->plan_id ) ?
9153
+ $this->_get_plan_by_id( $this->_site->plan_id ) :
9154
+ false;
9155
+ }
9156
+
9157
+ /**
9158
+ * @author Vova Feldman (@svovaf)
9159
+ * @since 1.0.3
9160
+ *
9161
+ * @return bool
9162
+ */
9163
+ function is_trial() {
9164
+ $this->_logger->entrance();
9165
+
9166
+ if ( ! $this->is_registered() || ! is_object( $this->_site ) ) {
9167
+ return false;
9168
+ }
9169
+
9170
+ return $this->_site->is_trial();
9171
+ }
9172
+
9173
+ /**
9174
+ * Check if currently in a trial with payment method (credit card or paypal).
9175
+ *
9176
+ * @author Vova Feldman (@svovaf)
9177
+ * @since 1.1.7
9178
+ *
9179
+ * @return bool
9180
+ */
9181
+ function is_paid_trial() {
9182
+ $this->_logger->entrance();
9183
+
9184
+ if ( ! $this->is_trial() ) {
9185
+ return false;
9186
+ }
9187
+
9188
+ return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
9189
+ }
9190
+
9191
+ /**
9192
+ * Check if trial already utilized.
9193
+ *
9194
+ * @since 1.0.9
9195
+ *
9196
+ * @return bool
9197
+ */
9198
+ function is_trial_utilized() {
9199
+ $this->_logger->entrance();
9200
+
9201
+ if ( ! $this->is_registered() ) {
9202
+ return false;
9203
+ }
9204
+
9205
+ return $this->_site->is_trial_utilized();
9206
+ }
9207
+
9208
+ /**
9209
+ * Get trial plan information (if in trial).
9210
+ *
9211
+ * @author Vova Feldman (@svovaf)
9212
+ * @since 1.0.9
9213
+ *
9214
+ * @return bool|FS_Plugin_Plan
9215
+ */
9216
+ function get_trial_plan() {
9217
+ $this->_logger->entrance();
9218
+
9219
+ if ( ! $this->is_trial() ) {
9220
+ return false;
9221
+ }
9222
+
9223
+ // Try to load plan from local cache.
9224
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
9225
+
9226
+ if ( ! is_object( $trial_plan ) ) {
9227
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
9228
+
9229
+ /**
9230
+ * If managed to fetch the plan, add it to the plans collection.
9231
+ */
9232
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
9233
+ if ( ! is_array( $this->_plans ) ) {
9234
+ $this->_plans = array();
9235
+ }
9236
+
9237
+ $this->_plans[] = $trial_plan;
9238
+ $this->_store_plans();
9239
+ }
9240
+ }
9241
+
9242
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
9243
+ return $trial_plan;
9244
+ }
9245
+
9246
+ /**
9247
+ * If for some reason failed to get the trial plan, fallback to a dummy name and title.
9248
+ */
9249
+ $trial_plan = new FS_Plugin_Plan();
9250
+ $trial_plan->id = $this->_site->trial_plan_id;
9251
+ $trial_plan->name = 'pro';
9252
+ $trial_plan->title = 'Pro';
9253
+
9254
+ return $trial_plan;
9255
+ }
9256
+
9257
+ /**
9258
+ * Check if the user has an activate, non-expired license on current plugin's install.
9259
+ *
9260
+ * @since 1.0.9
9261
+ *
9262
+ * @return bool
9263
+ */
9264
+ function is_paying() {
9265
+ $this->_logger->entrance();
9266
+
9267
+ if ( ! $this->is_registered() ) {
9268
+ return false;
9269
+ }
9270
+
9271
+ if ( ! $this->has_paid_plan() ) {
9272
+ return false;
9273
+ }
9274
+
9275
+ return (
9276
+ ! $this->is_trial() &&
9277
+ 'free' !== $this->get_plan_name() &&
9278
+ $this->has_active_valid_license()
9279
+ );
9280
+ }
9281
+
9282
+ /**
9283
+ * @author Vova Feldman (@svovaf)
9284
+ * @since 1.0.4
9285
+ *
9286
+ * @return bool
9287
+ */
9288
+ function is_free_plan() {
9289
+ if ( ! $this->is_registered() ) {
9290
+ return true;
9291
+ }
9292
+
9293
+ if ( ! $this->has_paid_plan() ) {
9294
+ return true;
9295
+ }
9296
+
9297
+ return (
9298
+ 'free' === $this->get_plan_name() ||
9299
+ ! $this->has_features_enabled_license()
9300
+ );
9301
+ }
9302
+
9303
+ /**
9304
+ * @author Vova Feldman (@svovaf)
9305
+ * @since 1.0.5
9306
+ *
9307
+ * @return bool
9308
+ */
9309
+ function _has_premium_license() {
9310
+ $this->_logger->entrance();
9311
+
9312
+ $premium_license = $this->_get_available_premium_license();
9313
+
9314
+ return ( false !== $premium_license );
9315
+ }
9316
+
9317
+ /**
9318
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
9319
+ *
9320
+ * @author Vova Feldman (@svovaf)
9321
+ * @since 1.1.7.3
9322
+ *
9323
+ * @return bool
9324
+ */
9325
+ function has_any_license() {
9326
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
9327
+ }
9328
+
9329
+ /**
9330
+ * @author Vova Feldman (@svovaf)
9331
+ * @since 1.0.5
9332
+ *
9333
+ * @param bool|null $is_localhost
9334
+ *
9335
+ * @return FS_Plugin_License|false
9336
+ */
9337
+ function _get_available_premium_license( $is_localhost = null ) {
9338
+ $this->_logger->entrance();
9339
+
9340
+ $licenses = $this->get_available_premium_licenses( $is_localhost );
9341
+ if ( ! empty( $licenses ) ) {
9342
+ return $licenses[0];
9343
+ }
9344
+
9345
+ return false;
9346
+ }
9347
+
9348
+ /**
9349
+ * @author Vova Feldman (@svovaf)
9350
+ * @since 1.0.5
9351
+ *
9352
+ * @param bool|null $is_localhost
9353
+ *
9354
+ * @return FS_Plugin_License[]
9355
+ */
9356
+ function get_available_premium_licenses( $is_localhost = null ) {
9357
+ $this->_logger->entrance();
9358
+
9359
+ $licenses = array();
9360
+ if ( ! $this->has_paid_plan() ) {
9361
+ return $licenses;
9362
+ }
9363
+
9364
+ if ( is_array( $this->_licenses ) ) {
9365
+ foreach ( $this->_licenses as $license ) {
9366
+ if ( ! $license->can_activate( $is_localhost ) ) {
9367
+ continue;
9368
+ }
9369
+
9370
+ $licenses[] = $license;
9371
+ }
9372
+ }
9373
+
9374
+ return $licenses;
9375
+ }
9376
+
9377
+ /**
9378
+ * Sync local plugin plans with remote server.
9379
+ *
9380
+ * IMPORTANT: If for some reason a site is associated with deleted plan, we'll preserve the plan's information and append it as the last plan. This means that if plan is deleted, the is_plan() method will ALWAYS return true for any given argument (it becomes the most inclusive plan).
9381
+ *
9382
+ * @author Vova Feldman (@svovaf)
9383
+ * @since 1.0.5
9384
+ *
9385
+ * @return FS_Plugin_Plan[]|object
9386
+ */
9387
+ function _sync_plans() {
9388
+ $plans = $this->_fetch_plugin_plans();
9389
+
9390
+ if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
9391
+ $plans_map = array();
9392
+ foreach ( $plans as $plan ) {
9393
+ $plans_map[ $plan->id ] = true;
9394
+ }
9395
+
9396
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
9397
+
9398
+ foreach ( $plans_ids_to_keep as $plan_id ) {
9399
+ if ( isset( $plans_map[ $plan_id ] ) ) {
9400
+ continue;
9401
+ }
9402
+
9403
+ $missing_plan = self::_get_plan_by_id( $plan_id );
9404
+
9405
+ if ( is_object( $missing_plan ) ) {
9406
+ $plans[] = $missing_plan;
9407
+ }
9408
+ }
9409
+
9410
+ $this->_plans = $plans;
9411
+ $this->_store_plans();
9412
+ }
9413
+
9414
+ $this->do_action( 'after_plans_sync', $plans );
9415
+
9416
+ return $this->_plans;
9417
+ }
9418
+
9419
+ /**
9420
+ * Check if specified plan exists locally. If not, fetch it and store it.
9421
+ *
9422
+ * @author Vova Feldman (@svovaf)
9423
+ * @since 2.0.0
9424
+ *
9425
+ * @param number $plan_id
9426
+ *
9427
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
9428
+ */
9429
+ private function sync_plan_if_not_exist( $plan_id ) {
9430
+ $plan = self::_get_plan_by_id( $plan_id );
9431
+
9432
+ if ( is_object( $plan ) ) {
9433
+ // Plan already exists.
9434
+ return $plan;
9435
+ }
9436
+
9437
+ $plan = $this->fetch_plan_by_id( $plan_id );
9438
+
9439
+ if ( $plan instanceof FS_Plugin_Plan ) {
9440
+ $this->_plans[] = $plan;
9441
+ $this->_store_plans();
9442
+
9443
+ return $plan;
9444
+ }
9445
+
9446
+ return $plan;
9447
+ }
9448
+
9449
+ /**
9450
+ * Check if specified license exists locally. If not, fetch it and store it.
9451
+ *
9452
+ * @author Vova Feldman (@svovaf)
9453
+ * @since 2.0.0
9454
+ *
9455
+ * @param number $license_id
9456
+ * @param string $license_key
9457
+ *
9458
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
9459
+ */
9460
+ private function sync_license_if_not_exist( $license_id, $license_key ) {
9461
+ $license = $this->_get_license_by_id( $license_id );
9462
+
9463
+ if ( is_object( $license ) ) {
9464
+ // License already exists.
9465
+ return $license;
9466
+ }
9467
+
9468
+ $license = $this->fetch_license_by_key( $license_id, $license_key );
9469
+
9470
+ if ( $license instanceof FS_Plugin_License ) {
9471
+ $this->_licenses[] = $license;
9472
+ $this->_license = $license;
9473
+ $this->_store_licenses();
9474
+
9475
+ return $license;
9476
+ }
9477
+
9478
+ return $license;
9479
+ }
9480
+
9481
+ /**
9482
+ * Get a collection of unique plan IDs that are associated with any installs in the network.
9483
+ *
9484
+ * @author Leo Fajardo (@leorw)
9485
+ * @since 2.0.0
9486
+ *
9487
+ * @return number[]
9488
+ */
9489
+ private function get_plans_ids_associated_with_installs() {
9490
+ if ( ! $this->_is_network_active ) {
9491
+ if ( ! is_object( $this->_site ) ||
9492
+ ! FS_Plugin_Plan::is_valid_id( $this->_site->plan_id )
9493
+ ) {
9494
+ return array();
9495
+ }
9496
+
9497
+ return array( $this->_site->plan_id );
9498
+ }
9499
+
9500
+ $plan_ids = array();
9501
+ $sites = self::get_sites();
9502
+ foreach ( $sites as $site ) {
9503
+ $blog_id = self::get_site_blog_id( $site );
9504
+ $install = $this->get_install_by_blog_id( $blog_id );
9505
+
9506
+ if ( ! is_object( $install ) ||
9507
+ ! FS_Plugin_Plan::is_valid_id( $install->plan_id )
9508
+ ) {
9509
+ continue;
9510
+ }
9511
+
9512
+ $plan_ids[ $install->plan_id ] = true;
9513
+ }
9514
+
9515
+ return array_keys( $plan_ids );
9516
+ }
9517
+
9518
+ /**
9519
+ * Get a collection of unique license IDs that are associated with any installs in the network.
9520
+ *
9521
+ * @author Leo Fajardo (@leorw)
9522
+ * @since 2.0.0
9523
+ *
9524
+ * @return number[]
9525
+ */
9526
+ private function get_license_ids_associated_with_installs() {
9527
+ if ( ! $this->_is_network_active ) {
9528
+ if ( ! is_object( $this->_site ) ||
9529
+ ! FS_Plugin_License::is_valid_id( $this->_site->license_id )
9530
+ ) {
9531
+ return array();
9532
+ }
9533
+
9534
+ return array( $this->_site->license_id );
9535
+ }
9536
+
9537
+ $license_ids = array();
9538
+ $sites = self::get_sites();
9539
+ foreach ( $sites as $site ) {
9540
+ $blog_id = self::get_site_blog_id( $site );
9541
+ $install = $this->get_install_by_blog_id( $blog_id );
9542
+
9543
+ if ( ! is_object( $install ) ||
9544
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
9545
+ ) {
9546
+ continue;
9547
+ }
9548
+
9549
+ $license_ids[ $install->license_id ] = true;
9550
+ }
9551
+
9552
+ return array_keys( $license_ids );
9553
+ }
9554
+
9555
+ /**
9556
+ * @author Vova Feldman (@svovaf)
9557
+ * @since 1.0.5
9558
+ *
9559
+ * @param number $id
9560
+ *
9561
+ * @return FS_Plugin_Plan|false
9562
+ */
9563
+ function _get_plan_by_id( $id ) {
9564
+ $this->_logger->entrance();
9565
+
9566
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
9567
+ $this->_sync_plans();
9568
+ }
9569
+
9570
+ foreach ( $this->_plans as $plan ) {
9571
+ if ( $id == $plan->id ) {
9572
+ return $plan;
9573
+ }
9574
+ }
9575
+
9576
+ return false;
9577
+ }
9578
+
9579
+ /**
9580
+ * @author Vova Feldman (@svovaf)
9581
+ * @since 1.1.8.1
9582
+ *
9583
+ * @param string $name
9584
+ *
9585
+ * @return FS_Plugin_Plan|false
9586
+ */
9587
+ private function get_plan_by_name( $name ) {
9588
+ $this->_logger->entrance();
9589
+
9590
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
9591
+ $this->_sync_plans();
9592
+ }
9593
+
9594
+ foreach ( $this->_plans as $plan ) {
9595
+ if ( $name == $plan->name ) {
9596
+ return $plan;
9597
+ }
9598
+ }
9599
+
9600
+ return false;
9601
+ }
9602
+
9603
+ /**
9604
+ * Sync local licenses with remote server.
9605
+ *
9606
+ * @author Vova Feldman (@svovaf)
9607
+ * @since 1.0.6
9608
+ *
9609
+ * @param number|bool $site_license_id
9610
+ * @param number|null $blog_id
9611
+ *
9612
+ * @return FS_Plugin_License[]|object
9613
+ */
9614
+ function _sync_licenses( $site_license_id = false, $blog_id = null ) {
9615
+ $this->_logger->entrance();
9616
+
9617
+ $is_network_admin = fs_is_network_admin();
9618
+
9619
+ if ( $is_network_admin && is_null( $blog_id ) ) {
9620
+ $all_licenses = self::get_all_licenses( $this->_module_id );
9621
+ } else {
9622
+ $all_licenses = $this->get_user_licenses( $this->_user->id );
9623
+ }
9624
+
9625
+ $foreign_licenses = array(
9626
+ 'ids' => array(),
9627
+ 'license_keys' => array()
9628
+ );
9629
+
9630
+ $all_licenses_map = array();
9631
+ foreach ( $all_licenses as $license ) {
9632
+ $all_licenses_map[ $license->id ] = true;
9633
+ if ( $license->user_id == $this->_user->id || $license->id == $site_license_id ) {
9634
+ continue;
9635
+ }
9636
+
9637
+ $foreign_licenses['ids'][] = $license->id;
9638
+ $foreign_licenses['license_keys'][] = $license->secret_key;
9639
+ }
9640
+
9641
+ if ( empty( $foreign_licenses['ids'] ) ) {
9642
+ $foreign_licenses = array();
9643
+ }
9644
+
9645
+ $licenses = $this->_fetch_licenses( false, $site_license_id, $foreign_licenses, $blog_id );
9646
+
9647
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
9648
+ $licenses_map = array();
9649
+ foreach ( $licenses as $license ) {
9650
+ $licenses_map[ $license->id ] = true;
9651
+ }
9652
+
9653
+ // $license_ids_to_keep = $this->get_license_ids_associated_with_installs();
9654
+ // foreach ( $license_ids_to_keep as $license_id ) {
9655
+ // if ( isset( $licenses_map[ $license_id ] ) ) {
9656
+ // continue;
9657
+ // }
9658
+ //
9659
+ // $missing_license = self::_get_license_by_id( $license_id, false );
9660
+ // if ( is_object( $missing_license ) ) {
9661
+ // $licenses[] = $missing_license;
9662
+ // $licenses_map[ $missing_license->id ] = true;
9663
+ // }
9664
+ // }
9665
+
9666
+ $user_license_ids = $this->get_user_linked_license_ids( $this->_user->id );
9667
+
9668
+ foreach ( $user_license_ids as $key => $license_id ) {
9669
+ if ( ! isset( $licenses_map[ $license_id ] ) ) {
9670
+ // Remove access to licenses that no longer exist.
9671
+ unset( $user_license_ids[ $key ] );
9672
+ }
9673
+ }
9674
+
9675
+ if ( ! empty( $user_license_ids ) ) {
9676
+ foreach ( $licenses_map as $license_id => $value ) {
9677
+ if ( ! isset( $all_licenses_map[ $license_id ] ) ) {
9678
+ // Associate new licenses with the user who triggered the license syncing.
9679
+ $user_license_ids[] = $license_id;
9680
+ }
9681
+ }
9682
+
9683
+ $user_license_ids = array_unique( $user_license_ids );
9684
+ } else {
9685
+ $user_license_ids = array_keys( $licenses_map );
9686
+ }
9687
+
9688
+ if ( ! $is_network_admin || ! is_null( $blog_id ) ) {
9689
+ $user_licenses = array();
9690
+ foreach ( $licenses as $license ) {
9691
+ if ( ! in_array( $license->id, $user_license_ids ) ) {
9692
+ continue;
9693
+ }
9694
+
9695
+ $user_licenses[] = $license;
9696
+ }
9697
+
9698
+ $this->_licenses = $user_licenses;
9699
+ } else {
9700
+ $this->_licenses = $licenses;
9701
+ }
9702
+
9703
+ $this->set_user_linked_license_ids( $this->_user->id, $user_license_ids );
9704
+
9705
+ $this->_store_licenses( true, $this->_module_id, $licenses );
9706
+ }
9707
+
9708
+ // Update current license.
9709
+ if ( is_object( $this->_license ) ) {
9710
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
9711
+ }
9712
+
9713
+ return $this->_licenses;
9714
+ }
9715
+
9716
+ /**
9717
+ * @author Vova Feldman (@svovaf)
9718
+ * @since 1.0.5
9719
+ *
9720
+ * @param number $id
9721
+ * @param bool $sync_licenses
9722
+ *
9723
+ * @return FS_Plugin_License|false
9724
+ */
9725
+ function _get_license_by_id( $id, $sync_licenses = true ) {
9726
+ $this->_logger->entrance();
9727
+
9728
+ if ( ! FS_Plugin_License::is_valid_id( $id ) ) {
9729
+ return false;
9730
+ }
9731
+
9732
+ /**
9733
+ * When running from the network level admin and opted-in from the network,
9734
+ * check if the license exists in the network user licenses collection.
9735
+ *
9736
+ * @author Vova Feldman (@svovaf)
9737
+ * @since 2.0.0
9738
+ */
9739
+ if ( fs_is_network_admin() &&
9740
+ $this->is_network_registered() &&
9741
+ ( ! is_object( $this->_user ) || $this->_storage->network_user_id != $this->_user->id )
9742
+ ) {
9743
+ $licenses = $this->get_user_licenses( $this->_storage->network_user_id );
9744
+
9745
+ foreach ( $licenses as $license ) {
9746
+ if ( $id == $license->id ) {
9747
+ return $license;
9748
+ }
9749
+ }
9750
+ }
9751
+
9752
+ if ( ! $this->has_any_license() && $sync_licenses ) {
9753
+ $this->_sync_licenses( $id );
9754
+ }
9755
+
9756
+ if ( is_array( $this->_licenses ) ) {
9757
+ foreach ( $this->_licenses as $license ) {
9758
+ if ( $id == $license->id ) {
9759
+ return $license;
9760
+ }
9761
+ }
9762
+ }
9763
+
9764
+ return false;
9765
+ }
9766
+
9767
+ /**
9768
+ * Get license by ID. Unlike _get_license_by_id(), this method only checks the local storage and return any license, whether it's associated with the current context user/install or not.
9769
+ *
9770
+ * @author Vova Feldman (@svovaf)
9771
+ * @since 2.0.0
9772
+ *
9773
+ * @param number $id
9774
+ *
9775
+ * @return FS_Plugin_License
9776
+ */
9777
+ private function get_license_by_id( $id ) {
9778
+ $licenses = self::get_all_licenses( $this->_module_id );
9779
+
9780
+ if ( is_array( $licenses ) && ! empty( $licenses ) ) {
9781
+ foreach ( $licenses as $license ) {
9782
+ if ( $id == $license->id ) {
9783
+ return $license;
9784
+ }
9785
+ }
9786
+ }
9787
+
9788
+ return null;
9789
+ }
9790
+
9791
+ /**
9792
+ * Synchronize the site's context license by fetching the license form the API and updating the local data with it.
9793
+ *
9794
+ * @author Vova Feldman (@svovaf)
9795
+ * @since 2.0.0
9796
+ *
9797
+ * @return \FS_Plugin_License|mixed
9798
+ */
9799
+ private function sync_site_license() {
9800
+ $api = $this->get_api_user_scope();
9801
+
9802
+ $result = $api->get( "/licenses/{$this->_license->id}.json?license_key=" . urlencode( $this->_license->secret_key ), true );
9803
+
9804
+ if ( ! $this->is_api_result_entity( $result ) ) {
9805
+ return $result;
9806
+ }
9807
+
9808
+ $license = $this->_update_site_license( new FS_Plugin_License( $result ) );
9809
+ $this->_store_licenses();
9810
+
9811
+ return $license;
9812
+ }
9813
+
9814
+ /**
9815
+ * Get all user's available licenses for the current module.
9816
+ *
9817
+ * @author Vova Feldman (@svovaf)
9818
+ * @since 2.0.0
9819
+ *
9820
+ * @param number $user_id
9821
+ *
9822
+ * @return FS_Plugin_License[]
9823
+ */
9824
+ private function get_user_licenses( $user_id ) {
9825
+ $all_licenses = self::get_all_licenses( $this->_module_id );
9826
+ if ( empty( $all_licenses ) ) {
9827
+ return array();
9828
+ }
9829
+
9830
+ $user_license_ids = $this->get_user_linked_license_ids( $user_id );
9831
+ if ( empty( $user_license_ids ) ) {
9832
+ return array();
9833
+ }
9834
+
9835
+ $licenses = array();
9836
+ foreach ( $all_licenses as $license ) {
9837
+ if ( in_array( $license->id, $user_license_ids ) ) {
9838
+ $licenses[] = $license;
9839
+ }
9840
+ }
9841
+
9842
+ return $licenses;
9843
+ }
9844
+
9845
+ /**
9846
+ * Checks if the context license is network activated except on the given blog ID.
9847
+ *
9848
+ * @author Vova Feldman (@svovaf)
9849
+ * @since 2.0.0
9850
+ *
9851
+ * @param int $except_blog_id
9852
+ *
9853
+ * @return bool
9854
+ */
9855
+ private function is_license_network_active( $except_blog_id = 0 ) {
9856
+ $this->_logger->entrance();
9857
+
9858
+ if ( ! is_object( $this->_license ) ) {
9859
+ return false;
9860
+ }
9861
+
9862
+ $sites = self::get_sites();
9863
+
9864
+ if ( $this->_license->total_activations() < ( count( $sites ) - 1 ) ) {
9865
+ // There are more sites than the number of activations, so license cannot be network activated.
9866
+ return false;
9867
+ }
9868
+
9869
+ foreach ( $sites as $site ) {
9870
+ $blog_id = self::get_site_blog_id( $site );
9871
+
9872
+ if ( $except_blog_id == $blog_id ) {
9873
+ // Skip excluded blog.
9874
+ continue;
9875
+ }
9876
+
9877
+ $install = $this->get_install_by_blog_id( $blog_id );
9878
+
9879
+ if ( is_object( $install ) && $install->license_id != $this->_license->id ) {
9880
+ return false;
9881
+ }
9882
+ }
9883
+
9884
+ return true;
9885
+ }
9886
+
9887
+ /**
9888
+ * Checks if license can be activated on all the network sites (opted-in or skipped) that are not yet associated with a license. If possible, try to make the activation, if not return false.
9889
+ *
9890
+ * Notice: On success, this method will also update the license activations counters (without updating the license in the storage).
9891
+ *
9892
+ * @author Vova Feldman (@svovaf)
9893
+ * @since 2.0.0
9894
+ *
9895
+ * @param \FS_User $user
9896
+ * @param \FS_Plugin_License $license
9897
+ *
9898
+ * @return bool
9899
+ */
9900
+ private function try_activate_license_on_network( FS_User $user, FS_Plugin_License $license ) {
9901
+ $this->_logger->entrance();
9902
+
9903
+ $result = $this->can_activate_license_on_network( $license );
9904
+
9905
+ if ( false === $result ) {
9906
+ return false;
9907
+ }
9908
+
9909
+ $installs_without_license = $result['installs'];
9910
+ if ( ! empty( $installs_without_license ) ) {
9911
+ $this->activate_license_on_many_installs( $user, $license->secret_key, $installs_without_license );
9912
+ }
9913
+
9914
+ $disconnected_site_ids = $result['sites'];
9915
+ if ( ! empty( $disconnected_site_ids ) ) {
9916
+ $this->activate_license_on_many_sites( $user, $license->secret_key, $disconnected_site_ids );
9917
+ }
9918
+
9919
+ $this->link_license_2_user( $license->id, $user->id );
9920
+
9921
+ // Sync license after activations.
9922
+ $license->activated += $result['production_count'];
9923
+ $license->activated_local += $result['localhost_count'];
9924
+
9925
+ // $this->_store_licenses()
9926
+
9927
+ return true;
9928
+ }
9929
+
9930
+ /**
9931
+ * Checks if the given license can be activated on the whole network.
9932
+ *
9933
+ * @author Vova Feldman (@svovaf)
9934
+ * @since 2.0.0
9935
+ *
9936
+ * @param \FS_Plugin_License $license
9937
+ *
9938
+ * @return false|array {
9939
+ * @type array[int]FS_Site $installs Blog ID to install map.
9940
+ * @type int[] $sites Non-connected blog IDs.
9941
+ * @type int $production_count Production sites count.
9942
+ * @type int $localhost_count Production sites count.
9943
+ * }
9944
+ */
9945
+ private function can_activate_license_on_network( FS_Plugin_License $license ) {
9946
+ $sites = self::get_sites();
9947
+
9948
+ $production_count = 0;
9949
+ $localhost_count = 0;
9950
+
9951
+ $installs_without_license = array();
9952
+ $disconnected_site_ids = array();
9953
+
9954
+ foreach ( $sites as $site ) {
9955
+ $blog_id = self::get_site_blog_id( $site );
9956
+ $install = $this->get_install_by_blog_id( $blog_id );
9957
+
9958
+ if ( is_object( $install ) ) {
9959
+ if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
9960
+ // License already activated on the install.
9961
+ continue;
9962
+ }
9963
+
9964
+ $url = $install->url;
9965
+
9966
+ $installs_without_license[ $blog_id ] = $install;
9967
+ } else {
9968
+ $url = is_object( $site ) ?
9969
+ $site->siteurl :
9970
+ get_site_url( $blog_id );
9971
+
9972
+ $disconnected_site_ids[] = $blog_id;
9973
+ }
9974
+
9975
+ if ( FS_Site::is_localhost_by_address( $url ) ) {
9976
+ $localhost_count ++;
9977
+ } else {
9978
+ $production_count ++;
9979
+ }
9980
+ }
9981
+
9982
+ if ( ! $license->can_activate_bulk( $production_count, $localhost_count ) ) {
9983
+ return false;
9984
+ }
9985
+
9986
+ return array(
9987
+ 'installs' => $installs_without_license,
9988
+ 'sites' => $disconnected_site_ids,
9989
+ 'production_count' => $production_count,
9990
+ 'localhost_count' => $localhost_count,
9991
+ );
9992
+ }
9993
+
9994
+ /**
9995
+ * Activate a given license on a collection of installs.
9996
+ *
9997
+ * @author Vova Feldman (@svovaf)
9998
+ * @since 2.0.0
9999
+ *
10000
+ * @param \FS_User $user
10001
+ * @param string $license_key
10002
+ * @param array $blog_2_install_map {
10003
+ * @key int Blog ID.
10004
+ * @value FS_Site Blog's associated install.
10005
+ * }
10006
+ *
10007
+ * @return mixed|true
10008
+ */
10009
+ private function activate_license_on_many_installs(
10010
+ FS_User $user,
10011
+ $license_key,
10012
+ array $blog_2_install_map
10013
+ ) {
10014
+ $params = array(
10015
+ array( 'license_key' => $this->apply_filters( 'license_key', $license_key ) )
10016
+ );
10017
+
10018
+ $install_2_blog_map = array();
10019
+ foreach ( $blog_2_install_map as $blog_id => $install ) {
10020
+ $params[] = array( 'id' => $install->id );
10021
+
10022
+ $install_2_blog_map[ $install->id ] = $blog_id;
10023
+ }
10024
+
10025
+ $result = $this->get_api_user_scope_by_user( $user )->call(
10026
+ "plugins/{$this->_plugin->id}/installs.json",
10027
+ 'PUT',
10028
+ $params
10029
+ );
10030
+
10031
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
10032
+ return $result;
10033
+ }
10034
+
10035
+ foreach ( $result->installs as $r_install ) {
10036
+ $install = new FS_Site( $r_install );
10037
+ $install->is_disconnected = false;
10038
+
10039
+ // Update install.
10040
+ $this->_store_site(
10041
+ true,
10042
+ $install_2_blog_map[ $r_install->id ],
10043
+ $install
10044
+ );
10045
+ }
10046
+
10047
+ return true;
10048
+ }
10049
+
10050
+ /**
10051
+ * Activate a given license on a collection of blogs/sites that are not yet opted-in.
10052
+ *
10053
+ * @author Vova Feldman (@svovaf)
10054
+ * @since 2.0.0
10055
+ *
10056
+ * @param \FS_User $user
10057
+ * @param string $license_key
10058
+ * @param int[] $site_ids
10059
+ *
10060
+ * @return true|mixed True if successful, otherwise, the API result.
10061
+ */
10062
+ private function activate_license_on_many_sites(
10063
+ FS_User $user,
10064
+ $license_key,
10065
+ array $site_ids
10066
+ ) {
10067
+ $sites = array();
10068
+ foreach ( $site_ids as $site_id ) {
10069
+ $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
10070
+ }
10071
+
10072
+ // Install the plugin.
10073
+ $result = $this->create_installs_with_user(
10074
+ $user,
10075
+ $license_key,
10076
+ false,
10077
+ $sites,
10078
+ false,
10079
+ true
10080
+ );
10081
+
10082
+ if ( ! $this->is_api_result_entity( $result ) &&
10083
+ ! $this->is_api_result_object( $result, 'installs' )
10084
+ ) {
10085
+ return $result;
10086
+ }
10087
+
10088
+ $installs = array();
10089
+ foreach ( $result->installs as $install ) {
10090
+ $installs[] = new FS_Site( $install );
10091
+ }
10092
+
10093
+ // Map site addresses to their blog IDs.
10094
+ $address_to_blog_map = $this->get_address_to_blog_map();
10095
+
10096
+ $first_blog_id = null;
10097
+
10098
+ foreach ( $installs as $install ) {
10099
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
10100
+ $blog_id = $address_to_blog_map[ $address ];
10101
+
10102
+ $this->_store_site( true, $blog_id, $install );
10103
+
10104
+ $this->reset_anonymous_mode( $blog_id );
10105
+
10106
+ if ( is_null( $first_blog_id ) ) {
10107
+ $first_blog_id = $blog_id;
10108
+ }
10109
+ }
10110
+
10111
+ if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
10112
+ $this->_storage->network_install_blog_id = $first_blog_id;
10113
+ }
10114
+
10115
+ return true;
10116
+ }
10117
+
10118
+ /**
10119
+ * Sync site's license with user licenses.
10120
+ *
10121
+ * @author Vova Feldman (@svovaf)
10122
+ * @since 1.0.6
10123
+ *
10124
+ * @param FS_Plugin_License|null $new_license
10125
+ *
10126
+ * @return FS_Plugin_License|null
10127
+ */
10128
+ function _update_site_license( $new_license ) {
10129
+ $this->_logger->entrance();
10130
+
10131
+ $this->_license = $new_license;
10132
+
10133
+ if ( ! is_object( $new_license ) ) {
10134
+ $this->_site->license_id = null;
10135
+ $this->_sync_site_subscription( null );
10136
+
10137
+ return $this->_license;
10138
+ }
10139
+
10140
+ $this->_site->license_id = $this->_license->id;
10141
+
10142
+ if ( ! is_array( $this->_licenses ) ) {
10143
+ $this->_licenses = array();
10144
+ }
10145
+
10146
+ $is_license_found = false;
10147
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
10148
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
10149
+ $this->_licenses[ $i ] = $new_license;
10150
+
10151
+ $is_license_found = true;
10152
+ break;
10153
+ }
10154
+ }
10155
+
10156
+ // If new license just append.
10157
+ if ( ! $is_license_found ) {
10158
+ $this->_licenses[] = $new_license;
10159
+ }
10160
+
10161
+ $this->_sync_site_subscription( $new_license );
10162
+
10163
+ return $this->_license;
10164
+ }
10165
+
10166
+ /**
10167
+ * Sync site's subscription.
10168
+ *
10169
+ * @author Vova Feldman (@svovaf)
10170
+ * @since 1.0.9
10171
+ *
10172
+ * @param FS_Plugin_License|null $license
10173
+ *
10174
+ * @return bool|\FS_Subscription
10175
+ */
10176
+ private function _sync_site_subscription( $license ) {
10177
+ if ( ! is_object( $license ) ) {
10178
+ $this->delete_unused_subscriptions();
10179
+
10180
+ return false;
10181
+ }
10182
+
10183
+ // Load subscription details if not lifetime.
10184
+ $subscription = $license->is_lifetime() ?
10185
+ false :
10186
+ $this->_fetch_site_license_subscription();
10187
+
10188
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
10189
+ $this->store_subscription( $subscription );
10190
+ } else {
10191
+ $this->delete_unused_subscriptions();
10192
+ }
10193
+
10194
+ return $subscription;
10195
+ }
10196
+
10197
+ /**
10198
+ * @author Vova Feldman (@svovaf)
10199
+ * @since 1.0.6
10200
+ *
10201
+ * @return bool|\FS_Plugin_License
10202
+ */
10203
+ function _get_license() {
10204
+ if ( ! fs_is_network_admin() || is_object( $this->_license ) ) {
10205
+ return $this->_license;
10206
+ }
10207
+
10208
+ return $this->_get_available_premium_license();
10209
+ }
10210
+
10211
+ /**
10212
+ * @param number $license_id
10213
+ *
10214
+ * @return null|\FS_Subscription
10215
+ */
10216
+ function _get_subscription( $license_id ) {
10217
+ if ( ! isset( $this->_storage->subscriptions ) ||
10218
+ empty( $this->_storage->subscriptions )
10219
+ ) {
10220
+ return null;
10221
+ }
10222
+
10223
+ foreach ( $this->_storage->subscriptions as $subscription ) {
10224
+ if ( $subscription->license_id == $license_id ) {
10225
+ return $subscription;
10226
+ }
10227
+ }
10228
+
10229
+ return null;
10230
+ }
10231
+
10232
+ /**
10233
+ * @author Leo Fajardo (@leorw)
10234
+ * @since 2.0.0
10235
+ *
10236
+ * @param FS_Subscription $subscription
10237
+ */
10238
+ function store_subscription( FS_Subscription $subscription ) {
10239
+ if ( ! isset( $this->_storage->subscriptions ) ) {
10240
+ $this->_storage->subscriptions = array();
10241
+ }
10242
+
10243
+ if ( empty( $this->_storage->subscriptions ) || ! is_multisite() ) {
10244
+ $this->_storage->subscriptions = array( $subscription );
10245
+
10246
+ return;
10247
+ }
10248
+
10249
+ $subscriptions = $this->_storage->subscriptions;
10250
+
10251
+ $updated_subscription = false;
10252
+ foreach ( $subscriptions as $key => $existing_subscription ) {
10253
+ if ( $existing_subscription->id == $subscription->id ) {
10254
+ $subscriptions[ $key ] = $subscription;
10255
+ $updated_subscription = true;
10256
+ break;
10257
+ }
10258
+ }
10259
+
10260
+ if ( ! $updated_subscription ) {
10261
+ $subscriptions[] = $subscription;
10262
+ }
10263
+
10264
+ $this->_storage->subscriptions = $subscriptions;
10265
+ }
10266
+
10267
+ /**
10268
+ * @author Leo Fajardo (@leorw)
10269
+ * @since 2.0.0
10270
+ */
10271
+ function delete_unused_subscriptions() {
10272
+ if ( ! isset( $this->_storage->subscriptions ) ||
10273
+ empty( $this->_storage->subscriptions ) ||
10274
+ // Clean up only if there are already at least 3 subscriptions.
10275
+ ( count( $this->_storage->subscriptions ) < 3 )
10276
+ ) {
10277
+ return;
10278
+ }
10279
+
10280
+ if ( ! is_multisite() ) {
10281
+ // If not multisite, there should only be 1 subscription, so just clear the array.
10282
+ $this->_storage->subscriptions = array();
10283
+
10284
+ return;
10285
+ }
10286
+
10287
+ $subscriptions_to_keep_by_license_id_map = array();
10288
+ $sites = self::get_sites();
10289
+ foreach ( $sites as $site ) {
10290
+ $blog_id = self::get_site_blog_id( $site );
10291
+ $install = $this->get_install_by_blog_id( $blog_id );
10292
+
10293
+ if ( ! is_object( $install ) ||
10294
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
10295
+ ) {
10296
+ continue;
10297
+ }
10298
+
10299
+ $subscriptions_to_keep_by_license_id_map[ $install->license_id ] = true;
10300
+ }
10301
+
10302
+ if ( empty( $subscriptions_to_keep_by_license_id_map ) ) {
10303
+ $this->_storage->subscriptions = array();
10304
+
10305
+ return;
10306
+ }
10307
+
10308
+ foreach ( $this->_storage->subscriptions as $key => $subscription ) {
10309
+ if ( ! isset( $subscriptions_to_keep_by_license_id_map[ $subscription->license_id ] ) ) {
10310
+ unset( $this->_storage->subscriptions[ $key ] );
10311
+ }
10312
+ }
10313
+ }
10314
+
10315
+ /**
10316
+ * @author Vova Feldman (@svovaf)
10317
+ * @since 1.0.2
10318
+ *
10319
+ * @param string $plan Plan name
10320
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
10321
+ *
10322
+ * @return bool
10323
+ */
10324
+ function is_plan( $plan, $exact = false ) {
10325
+ $this->_logger->entrance();
10326
+
10327
+ if ( ! $this->is_registered() ) {
10328
+ return false;
10329
+ }
10330
+
10331
+ $plan = strtolower( $plan );
10332
+
10333
+ $current_plan_name = $this->get_plan_name();
10334
+
10335
+ if ( $current_plan_name === $plan ) {
10336
+ // Exact plan.
10337
+ return true;
10338
+ } else if ( $exact ) {
10339
+ // Required exact, but plans are different.
10340
+ return false;
10341
+ }
10342
+
10343
+ $current_plan_order = - 1;
10344
+ $required_plan_order = - 1;
10345
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
10346
+ if ( $plan === $this->_plans[ $i ]->name ) {
10347
+ $required_plan_order = $i;
10348
+ } else if ( $current_plan_name === $this->_plans[ $i ]->name ) {
10349
+ $current_plan_order = $i;
10350
+ }
10351
+ }
10352
+
10353
+ return ( $current_plan_order > $required_plan_order );
10354
+ }
10355
+
10356
+ /**
10357
+ * Check if module has only one plan.
10358
+ *
10359
+ * @author Vova Feldman (@svovaf)
10360
+ * @since 1.2.1.7
10361
+ *
10362
+ * @return bool
10363
+ */
10364
+ function is_single_plan() {
10365
+ $this->_logger->entrance();
10366
+
10367
+ if ( ! $this->is_registered() ||
10368
+ ! is_array( $this->_plans ) ||
10369
+ 0 === count( $this->_plans )
10370
+ ) {
10371
+ return true;
10372
+ }
10373
+
10374
+ return ( 1 === count( $this->_plans ) );
10375
+ }
10376
+
10377
+ /**
10378
+ * Check if plan based on trial. If not in trial mode, should return false.
10379
+ *
10380
+ * @since 1.0.9
10381
+ *
10382
+ * @param string $plan Plan name
10383
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
10384
+ *
10385
+ * @return bool
10386
+ */
10387
+ function is_trial_plan( $plan, $exact = false ) {
10388
+ $this->_logger->entrance();
10389
+
10390
+ if ( ! $this->is_registered() ) {
10391
+ return false;
10392
+ }
10393
+
10394
+ if ( ! $this->is_trial() ) {
10395
+ return false;
10396
+ }
10397
+
10398
+ $trial_plan = $this->get_trial_plan();
10399
+
10400
+ if ( $trial_plan->name === $plan ) {
10401
+ // Exact plan.
10402
+ return true;
10403
+ } else if ( $exact ) {
10404
+ // Required exact, but plans are different.
10405
+ return false;
10406
+ }
10407
+
10408
+ $current_plan_order = - 1;
10409
+ $required_plan_order = - 1;
10410
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
10411
+ if ( $plan === $this->_plans[ $i ]->name ) {
10412
+ $required_plan_order = $i;
10413
+ } else if ( $trial_plan->name === $this->_plans[ $i ]->name ) {
10414
+ $current_plan_order = $i;
10415
+ }
10416
+ }
10417
+
10418
+ return ( $current_plan_order > $required_plan_order );
10419
+ }
10420
+
10421
+ /**
10422
+ * Check if plugin has any paid plans.
10423
+ *
10424
+ * @author Vova Feldman (@svovaf)
10425
+ * @since 1.0.7
10426
+ *
10427
+ * @return bool
10428
+ */
10429
+ function has_paid_plan() {
10430
+ return $this->_has_paid_plans ||
10431
+ FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
10432
+ }
10433
+
10434
+ /**
10435
+ * Check if plugin has any plan with a trail.
10436
+ *
10437
+ * @author Vova Feldman (@svovaf)
10438
+ * @since 1.0.9
10439
+ *
10440
+ * @return bool
10441
+ */
10442
+ function has_trial_plan() {
10443
+ /**
10444
+ * @author Vova Feldman(@svovaf)
10445
+ * @since 1.2.1.5
10446
+ *
10447
+ * Allow setting a trial from the SDK without calling the API.
10448
+ * But, if the user did opt-in, continue using the real data from the API.
10449
+ */
10450
+ if ( $this->_trial_days >= 0 ) {
10451
+ return true;
10452
+ }
10453
+
10454
+ return $this->_storage->get( 'has_trial_plan', false );
10455
+ }
10456
+
10457
+ /**
10458
+ * Check if plugin has any free plan, or is it premium only.
10459
+ *
10460
+ * Note: If no plans configured, assume plugin is free.
10461
+ *
10462
+ * @author Vova Feldman (@svovaf)
10463
+ * @since 1.0.7
10464
+ *
10465
+ * @return bool
10466
+ */
10467
+ function has_free_plan() {
10468
+ return ! $this->is_only_premium();
10469
+ }
10470
+
10471
+ /**
10472
+ * Displays a license activation dialog box when the user clicks on the "Activate License"
10473
+ * or "Change License" link on the plugins
10474
+ * page.
10475
+ *
10476
+ * @author Leo Fajardo (@leorw)
10477
+ * @since 1.1.9
10478
+ */
10479
+ function _add_license_activation_dialog_box() {
10480
+ $vars = array(
10481
+ 'id' => $this->_module_id,
10482
+ );
10483
+
10484
+ fs_require_template( 'forms/license-activation.php', $vars );
10485
+ fs_require_template( 'forms/resend-key.php', $vars );
10486
+ }
10487
+
10488
+ /**
10489
+ * @author Leo Fajardo (@leorw)
10490
+ * @since 2.0.2
10491
+ */
10492
+ function _add_premium_version_upgrade_selection_dialog_box() {
10493
+ $modules_update = get_site_transient( $this->is_theme() ? 'update_themes' : 'update_plugins' );
10494
+ if ( ! isset( $modules_update->response[ $this->_plugin_basename ] ) ) {
10495
+ return;
10496
+ }
10497
+
10498
+ $vars = array(
10499
+ 'id' => $this->_module_id,
10500
+ 'new_version' => is_object( $modules_update->response[ $this->_plugin_basename ] ) ?
10501
+ $modules_update->response[ $this->_plugin_basename ]->new_version :
10502
+ $modules_update->response[ $this->_plugin_basename ]['new_version']
10503
+ );
10504
+
10505
+ fs_require_template( 'forms/premium-versions-upgrade-metadata.php', $vars );
10506
+ fs_require_once_template( 'forms/premium-versions-upgrade-handler.php', $vars );
10507
+ }
10508
+
10509
+ /**
10510
+ * Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
10511
+ * page.
10512
+ *
10513
+ * @author Leo Fajardo (@leorw)
10514
+ * @since 1.2.1.5
10515
+ */
10516
+ function _add_optout_dialog() {
10517
+ if ( $this->is_theme() ) {
10518
+ $vars = null;
10519
+ fs_require_once_template( '/js/jquery.content-change.php', $vars );
10520
+ }
10521
+
10522
+ $vars = array( 'id' => $this->_module_id );
10523
+ fs_require_template( 'forms/optout.php', $vars );
10524
+ }
10525
+
10526
+ /**
10527
+ * Prepare page to include all required UI and logic for the license activation dialog.
10528
+ *
10529
+ * @author Vova Feldman (@svovaf)
10530
+ * @since 1.2.0
10531
+ */
10532
+ function _add_license_activation() {
10533
+ if ( ! $this->is_user_admin() ) {
10534
+ // Only admins can activate a license.
10535
+ return;
10536
+ }
10537
+
10538
+ if ( ! $this->has_paid_plan() ) {
10539
+ // Module doesn't have any paid plans.
10540
+ return;
10541
+ }
10542
+
10543
+ if ( ! $this->is_premium() ) {
10544
+ // Only add license activation logic to the premium version.
10545
+ return;
10546
+ }
10547
+
10548
+ // Add license activation link and AJAX request handler.
10549
+ if ( self::is_plugins_page() ) {
10550
+ /**
10551
+ * @since 1.2.0 Add license action link only on plugins page.
10552
+ */
10553
+ $this->_add_license_action_link();
10554
+ }
10555
+
10556
+ // Add license activation AJAX callback.
10557
+ $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
10558
+
10559
+ // Add resend license AJAX callback.
10560
+ $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
10561
+ }
10562
+
10563
+ /**
10564
+ * @author Leo Fajardo (@leorw)
10565
+ * @since 2.0.2
10566
+ */
10567
+ function _add_premium_version_upgrade_selection() {
10568
+ if ( ! $this->is_user_admin() ) {
10569
+ return;
10570
+ }
10571
+
10572
+ if ( ! $this->is_premium() || $this->has_active_valid_license() ) {
10573
+ // This is relevant only to the free versions and premium versions without an active license.
10574
+ return;
10575
+ }
10576
+
10577
+ if ( self::is_updates_page() || ( $this->is_plugin() && self::is_plugins_page() ) ) {
10578
+ $this->_add_premium_version_upgrade_selection_action();
10579
+ }
10580
+ }
10581
+
10582
+ /**
10583
+ * @author Leo Fajardo (@leorw)
10584
+ *
10585
+ * @since 1.1.9
10586
+ * @since 2.0.0 When a super-admin that hasn't connected before is network activating a license and excluding some of the sites for the license activation, go over the unselected sites in the network and if a site is not connected, skipped, nor delegated, if it's a freemium product then just skip the connection for the site, if it's a premium only product, delegate the connection and license activation to the site admin (Vova Feldman @svovaf).
10587
+ */
10588
+ function _activate_license_ajax_action() {
10589
+ $this->_logger->entrance();
10590
+
10591
+ $this->check_ajax_referer( 'activate_license' );
10592
+
10593
+ $license_key = trim( fs_request_get( 'license_key' ) );
10594
+
10595
+ if ( empty( $license_key ) ) {
10596
+ exit;
10597
+ }
10598
+
10599
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
10600
+ $fs = ( $plugin_id == $this->_module_id ) ?
10601
+ $this :
10602
+ $this->get_addon_instance( $plugin_id );
10603
+
10604
+ $error = false;
10605
+ $next_page = false;
10606
+
10607
+ $sites = fs_is_network_admin() ?
10608
+ fs_request_get( 'sites', array(), 'post' ) :
10609
+ array();
10610
+
10611
+ $blog_id = fs_request_get( 'blog_id' );
10612
+ $has_valid_blog_id = is_numeric( $blog_id );
10613
+
10614
+ if ( $fs->is_registered() ) {
10615
+ if ( fs_is_network_admin() && ! $has_valid_blog_id ) {
10616
+ // If no specific blog ID was provided, activate the license for all sites in the network.
10617
+ $blog_2_install_map = array();
10618
+ $site_ids = array();
10619
+
10620
+ foreach ( $sites as $site ) {
10621
+ if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
10622
+ continue;
10623
+ }
10624
+
10625
+ $install = $this->get_install_by_blog_id( $site['blog_id'] );
10626
+
10627
+ if ( is_object( $install ) ) {
10628
+ $blog_2_install_map[ $site['blog_id'] ] = $install;
10629
+ } else {
10630
+ $site_ids[] = $site['blog_id'];
10631
+ }
10632
+ }
10633
+
10634
+ $user = $this->get_current_or_network_user();
10635
+
10636
+ if ( ! empty( $blog_2_install_map ) ) {
10637
+ $result = $this->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
10638
+
10639
+ if ( true !== $result ) {
10640
+ $error = FS_Api::is_api_error_object( $result ) ?
10641
+ $result->error->message :
10642
+ var_export( $result, true );
10643
+ }
10644
+ }
10645
+
10646
+ if ( empty( $error ) && ! empty( $site_ids ) ) {
10647
+ $result = $this->activate_license_on_many_sites( $user, $license_key, $site_ids );
10648
+
10649
+ if ( true !== $result ) {
10650
+ $error = FS_Api::is_api_error_object( $result ) ?
10651
+ $result->error->message :
10652
+ var_export( $result, true );
10653
+ }
10654
+ }
10655
+ } else {
10656
+ if ( $has_valid_blog_id ) {
10657
+ /**
10658
+ * If a specific blog ID was provided, activate the license only for the install that is
10659
+ * associated with the given blog ID.
10660
+ *
10661
+ * @author Leo Fajardo (@leorw)
10662
+ */
10663
+ $this->switch_to_blog( $blog_id );
10664
+ }
10665
+
10666
+ $api = $fs->get_api_site_scope();
10667
+
10668
+ $params = array(
10669
+ 'license_key' => $fs->apply_filters( 'license_key', $license_key )
10670
+ );
10671
+
10672
+ $install = $api->call( '/', 'put', $params );
10673
+
10674
+ if ( FS_Api::is_api_error( $install ) ) {
10675
+ $error = FS_Api::is_api_error_object( $install ) ?
10676
+ $install->error->message :
10677
+ var_export( $install->error, true );
10678
+ } else {
10679
+ $fs->reconnect_locally( $has_valid_blog_id );
10680
+ }
10681
+ }
10682
+
10683
+ if ( empty( $error ) ) {
10684
+ $this->network_upgrade_mode_completed();
10685
+
10686
+ $fs->_sync_license( true, $has_valid_blog_id );
10687
+
10688
+ $next_page = $fs->is_addon() ?
10689
+ $fs->get_parent_instance()->get_account_url() :
10690
+ $fs->get_account_url();
10691
+ }
10692
+ } else {
10693
+ $next_page = $fs->opt_in(
10694
+ false,
10695
+ false,
10696
+ false,
10697
+ $license_key,
10698
+ false,
10699
+ false,
10700
+ false,
10701
+ fs_request_get_bool( 'is_marketing_allowed', null ),
10702
+ $sites
10703
+ );
10704
+
10705
+ if ( isset( $next_page->error ) ) {
10706
+ $error = $next_page->error;
10707
+ } else {
10708
+ if ( fs_is_network_admin() ) {
10709
+ /**
10710
+ * Get the list of sites that were just opted-in (and license activated).
10711
+ * This is an optimization for the next part below saving some DB queries.
10712
+ */
10713
+ $connected_sites = array();
10714
+ foreach ( $sites as $site ) {
10715
+ if ( isset( $site['blog_id'] ) && is_numeric( $site['blog_id'] ) ) {
10716
+ $connected_sites[ $site['blog_id'] ] = true;
10717
+ }
10718
+ }
10719
+
10720
+ $all_sites = self::get_sites();
10721
+ $pending_sites = array();
10722
+
10723
+ /**
10724
+ * Check if there are any sites that are not connected, skipped, nor delegated. For every site that falls into that category, if the product is freemium, skip the connection. If the product is premium only, delegate the connection to the site administrator.
10725
+ *
10726
+ * @author Vova Feldman (@svovaf)
10727
+ */
10728
+ foreach ( $all_sites as $site ) {
10729
+ $blog_id = self::get_site_blog_id( $site );
10730
+
10731
+ if ( isset( $connected_sites[ $blog_id ] ) ) {
10732
+ // Site was just connected.
10733
+ continue;
10734
+ }
10735
+
10736
+ if ( $this->is_installed_on_site( $blog_id ) ) {
10737
+ // Site was already connected before.
10738
+ continue;
10739
+ }
10740
+
10741
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
10742
+ // Site's connection was delegated.
10743
+ continue;
10744
+ }
10745
+
10746
+ if ( $this->is_anonymous_site( $blog_id ) ) {
10747
+ // Site connection was already skipped.
10748
+ continue;
10749
+ }
10750
+
10751
+ $pending_sites[] = self::get_site_info( $site );
10752
+ }
10753
+
10754
+ if ( ! empty( $pending_sites ) ) {
10755
+ if ( $this->is_freemium() ) {
10756
+ $this->skip_connection( $pending_sites );
10757
+ } else {
10758
+ $this->delegate_connection( $pending_sites );
10759
+ }
10760
+ }
10761
+ }
10762
+ }
10763
+ }
10764
+
10765
+ $result = array(
10766
+ 'success' => ( false === $error )
10767
+ );
10768
+
10769
+ if ( false !== $error ) {
10770
+ $result['error'] = $error;
10771
+ } else {
10772
+ $result['next_page'] = $next_page;
10773
+ }
10774
+
10775
+ echo json_encode( $result );
10776
+
10777
+ exit;
10778
+ }
10779
+
10780
+ /**
10781
+ * @author Leo Fajardo (@leorw)
10782
+ * @since 1.2.3.1
10783
+ */
10784
+ function _network_activate_ajax_action() {
10785
+ $this->_logger->entrance();
10786
+
10787
+ $this->check_ajax_referer( 'network_activate' );
10788
+
10789
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
10790
+ $fs = ( $plugin_id == $this->_module_id ) ?
10791
+ $this :
10792
+ $this->get_addon_instance( $plugin_id );
10793
+
10794
+ $error = false;
10795
+
10796
+ $sites = fs_request_get( 'sites', array(), 'post' );
10797
+ if ( is_array( $sites ) && ! empty( $sites ) ) {
10798
+ $sites_by_action = array(
10799
+ 'allow' => array(),
10800
+ 'delegate' => array(),
10801
+ 'skip' => array()
10802
+ );
10803
+
10804
+ foreach ( $sites as $site ) {
10805
+ $sites_by_action[ $site['action'] ][] = $site;
10806
+ }
10807
+
10808
+ $total_sites = count( $sites );
10809
+ $total_sites_to_delegate = count( $sites_by_action['delegate'] );
10810
+
10811
+ $next_page = '';
10812
+ if ( $total_sites === $total_sites_to_delegate &&
10813
+ ! $this->is_network_upgrade_mode()
10814
+ ) {
10815
+ $this->delegate_connection();
10816
+ } else {
10817
+ if ( ! empty( $sites_by_action['delegate'] ) ) {
10818
+ $this->delegate_connection( $sites_by_action['delegate'] );
10819
+ }
10820
+
10821
+ if ( ! empty( $sites_by_action['skip'] ) ) {
10822
+ $this->skip_connection( $sites_by_action['skip'] );
10823
+ }
10824
+
10825
+ if ( ! empty( $sites_by_action['allow'] ) ) {
10826
+ if ( ! $fs->is_registered() || ! $this->_is_network_active ) {
10827
+ $next_page = $fs->opt_in(
10828
+ false,
10829
+ false,
10830
+ false,
10831
+ false,
10832
+ false,
10833
+ false,
10834
+ false,
10835
+ fs_request_get_bool( 'is_marketing_allowed', null ),
10836
+ $sites_by_action['allow']
10837
+ );
10838
+ } else {
10839
+ $next_page = $fs->install_with_user(
10840
+ $this->get_network_user(),
10841
+ false,
10842
+ false,
10843
+ false,
10844
+ true,
10845
+ $sites_by_action['allow']
10846
+ );
10847
+ }
10848
+
10849
+ if ( is_object( $next_page ) && isset( $next_page->error ) ) {
10850
+ $error = $next_page->error;
10851
+ }
10852
+ }
10853
+ }
10854
+
10855
+ if ( empty( $next_page ) ) {
10856
+ $next_page = $this->get_after_activation_url( 'after_network_activation_url' );
10857
+ }
10858
+ } else {
10859
+ $error = $this->get_text_inline( 'Invalid site details collection.', 'invalid_site_details_collection' );
10860
+ }
10861
+
10862
+ $result = array(
10863
+ 'success' => ( false === $error )
10864
+ );
10865
+
10866
+ if ( false !== $error ) {
10867
+ $result['error'] = $error;
10868
+ } else {
10869
+ $result['next_page'] = $next_page;
10870
+ }
10871
+
10872
+ echo json_encode( $result );
10873
+
10874
+ exit;
10875
+ }
10876
+
10877
+ /**
10878
+ * Billing update AJAX callback.
10879
+ *
10880
+ * @author Vova Feldman (@svovaf)
10881
+ * @since 1.2.1.5
10882
+ */
10883
+ function _update_billing_ajax_action() {
10884
+ $this->_logger->entrance();
10885
+
10886
+ $this->check_ajax_referer( 'update_billing' );
10887
+
10888
+ if ( ! $this->is_user_admin() ) {
10889
+ // Only for admins.
10890
+ self::shoot_ajax_failure();
10891
+ }
10892
+
10893
+ $billing = fs_request_get( 'billing' );
10894
+
10895
+ $api = $this->get_api_user_scope();
10896
+ $result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
10897
+ 'plugin_id' => $this->get_parent_id(),
10898
+ ) ) );
10899
+
10900
+ if ( ! $this->is_api_result_entity( $result ) ) {
10901
+ self::shoot_ajax_failure();
10902
+ }
10903
+
10904
+ // Purge cached billing.
10905
+ $this->get_api_user_scope()->purge_cache( 'billing.json' );
10906
+
10907
+ self::shoot_ajax_success();
10908
+ }
10909
+
10910
+ /**
10911
+ * Trial start for anonymous users (AJAX callback).
10912
+ *
10913
+ * @author Vova Feldman (@svovaf)
10914
+ * @since 1.2.1.5
10915
+ */
10916
+ function _start_trial_ajax_action() {
10917
+ $this->_logger->entrance();
10918
+
10919
+ $this->check_ajax_referer( 'start_trial' );
10920
+
10921
+ if ( ! $this->is_user_admin() ) {
10922
+ // Only for admins.
10923
+ self::shoot_ajax_failure();
10924
+ }
10925
+
10926
+ $trial_data = fs_request_get( 'trial' );
10927
+
10928
+ $next_page = $this->opt_in(
10929
+ false,
10930
+ false,
10931
+ false,
10932
+ false,
10933
+ false,
10934
+ $trial_data['plan_id']
10935
+ );
10936
+
10937
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
10938
+ self::shoot_ajax_failure(
10939
+ isset( $next_page->error ) ?
10940
+ $next_page->error->message :
10941
+ var_export( $next_page, true )
10942
+ );
10943
+ }
10944
+
10945
+ $this->shoot_ajax_success( array(
10946
+ 'next_page' => $next_page,
10947
+ ) );
10948
+ }
10949
+
10950
+ /**
10951
+ * @author Leo Fajardo (@leorw)
10952
+ * @since 1.2.0
10953
+ */
10954
+ function _resend_license_key_ajax_action() {
10955
+ $this->_logger->entrance();
10956
+
10957
+ $this->check_ajax_referer( 'resend_license_key' );
10958
+
10959
+ $email_address = sanitize_email( trim( fs_request_get( 'email', '', 'post' ) ) );
10960
+
10961
+ if ( empty( $email_address ) ) {
10962
+ exit;
10963
+ }
10964
+
10965
+ $error = false;
10966
+
10967
+ $api = $this->get_api_plugin_scope();
10968
+ $result = $api->call( '/licenses/resend.json', 'post',
10969
+ array(
10970
+ 'email' => $email_address,
10971
+ 'url' => home_url(),
10972
+ )
10973
+ );
10974
+
10975
+ if ( is_object( $result ) && isset( $result->error ) ) {
10976
+ $error = $result->error;
10977
+
10978
+ if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
10979
+ $error = $this->get_text_inline( "We couldn't find your email address in the system, are you sure it's the right address?", 'email-not-found' );
10980
+ } else if ( 'no_license' === $error->code ) {
10981
+ $error = $this->get_text_inline( "We can't see any active licenses associated with that email address, are you sure it's the right address?", 'no-active-licenses' );
10982
+ } else {
10983
+ $error = $error->message;
10984
+ }
10985
+ }
10986
+
10987
+ $licenses = array(
10988
+ 'success' => ( false === $error )
10989
+ );
10990
+
10991
+ if ( false !== $error ) {
10992
+ $licenses['error'] = sprintf( '%s... %s', $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ), strtolower( $error ) );
10993
+ }
10994
+
10995
+ echo json_encode( $licenses );
10996
+
10997
+ exit;
10998
+ }
10999
+
11000
+ /**
11001
+ * @author Vova Feldman (@svovaf)
11002
+ * @since 1.2.1.8
11003
+ *
11004
+ * @var string
11005
+ */
11006
+ private static $_pagenow;
11007
+
11008
+ /**
11009
+ * Get current page or the referer if executing a WP AJAX request.
11010
+ *
11011
+ * @author Vova Feldman (@svovaf)
11012
+ * @since 1.2.1.8
11013
+ *
11014
+ * @return string
11015
+ */
11016
+ static function get_current_page() {
11017
+ if ( ! isset( self::$_pagenow ) ) {
11018
+ global $pagenow;
11019
+
11020
+ self::$_pagenow = $pagenow;
11021
+
11022
+ if ( self::is_ajax() &&
11023
+ 'admin-ajax.php' === $pagenow
11024
+ ) {
11025
+ $referer = fs_get_raw_referer();
11026
+
11027
+ if ( is_string( $referer ) ) {
11028
+ $parts = explode( '?', $referer );
11029
+
11030
+ self::$_pagenow = basename( $parts[0] );
11031
+ }
11032
+ }
11033
+ }
11034
+
11035
+ return self::$_pagenow;
11036
+ }
11037
+
11038
+ /**
11039
+ * Helper method to check if user in the plugins page.
11040
+ *
11041
+ * @author Vova Feldman (@svovaf)
11042
+ * @since 1.2.1.5
11043
+ *
11044
+ * @return bool
11045
+ */
11046
+ static function is_plugins_page() {
11047
+ return ( 'plugins.php' === self::get_current_page() );
11048
+ }
11049
+
11050
+ /**
11051
+ * @author Leo Fajardo (@leorw)
11052
+ * @since 2.0.2
11053
+ *
11054
+ * @return bool
11055
+ */
11056
+ static function is_updates_page() {
11057
+ return ( 'update-core.php' === self::get_current_page() );
11058
+ }
11059
+
11060
+ /**
11061
+ * Helper method to check if user in the themes page.
11062
+ *
11063
+ * @author Vova Feldman (@svovaf)
11064
+ * @since 1.2.2.6
11065
+ *
11066
+ * @return bool
11067
+ */
11068
+ static function is_themes_page() {
11069
+ return ( 'themes.php' === self::get_current_page() );
11070
+ }
11071
+
11072
+ #----------------------------------------------------------------------------------
11073
+ #region Affiliation
11074
+ #----------------------------------------------------------------------------------
11075
+
11076
+ /**
11077
+ * @author Leo Fajardo (@leorw)
11078
+ * @since 1.2.3
11079
+ *
11080
+ * @return bool
11081
+ */
11082
+ function has_affiliate_program() {
11083
+ if ( ! is_object( $this->_plugin ) ) {
11084
+ return false;
11085
+ }
11086
+
11087
+ return $this->_plugin->has_affiliate_program();
11088
+ }
11089
+
11090
+ /**
11091
+ * @author Leo Fajardo (@leorw)
11092
+ * @since 1.2.4
11093
+ */
11094
+ private function fetch_affiliate_terms() {
11095
+ if ( ! is_object( $this->plugin_affiliate_terms ) ) {
11096
+ $plugins_api = $this->get_api_plugin_scope();
11097
+ $affiliate_terms = $plugins_api->get( '/aff.json?type=affiliation', false );
11098
+
11099
+ if ( ! $this->is_api_result_entity( $affiliate_terms ) ) {
11100
+ return;
11101
+ }
11102
+
11103
+ $this->plugin_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
11104
+ }
11105
+ }
11106
+
11107
+ /**
11108
+ * @author Leo Fajardo (@leorw)
11109
+ * @since 1.2.4
11110
+ */
11111
+ private function fetch_affiliate_and_custom_terms() {
11112
+ if ( ! empty( $this->_storage->affiliate_application_data ) ) {
11113
+ $application_data = $this->_storage->affiliate_application_data;
11114
+ $flush = ( ! isset( $application_data['status'] ) || 'pending' === $application_data['status'] );
11115
+
11116
+ $users_api = $this->get_api_user_scope();
11117
+ $result = $users_api->get( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json", $flush );
11118
+ if ( $this->is_api_result_object( $result, 'affiliates' ) ) {
11119
+ if ( ! empty( $result->affiliates ) ) {
11120
+ $affiliate = new FS_Affiliate( $result->affiliates[0] );
11121
+
11122
+ if ( ! isset( $application_data['status'] ) || $application_data['status'] !== $affiliate->status ) {
11123
+ $application_data['status'] = $affiliate->status;
11124
+ $this->_storage->affiliate_application_data = $application_data;
11125
+ }
11126
+
11127
+ if ( $affiliate->is_using_custom_terms ) {
11128
+ $affiliate_terms = $users_api->get( "/plugins/{$this->_plugin->id}/affiliates/{$affiliate->id}/aff/{$affiliate->custom_affiliate_terms_id}.json", $flush );
11129
+ if ( $this->is_api_result_entity( $affiliate_terms ) ) {
11130
+ $this->custom_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
11131
+ }
11132
+ }
11133
+
11134
+ $this->affiliate = $affiliate;
11135
+ }
11136
+ }
11137
+ }
11138
+ }
11139
+
11140
+ /**
11141
+ * @author Leo Fajardo (@leorw)
11142
+ * @since 1.2.3
11143
+ */
11144
+ private function fetch_affiliate_and_terms() {
11145
+ $this->_logger->entrance();
11146
+
11147
+ $this->fetch_affiliate_terms();
11148
+ $this->fetch_affiliate_and_custom_terms();
11149
+ }
11150
+
11151
+ /**
11152
+ * @author Leo Fajardo (@leorw)
11153
+ * @since 1.2.3
11154
+ *
11155
+ * @return FS_Affiliate
11156
+ */
11157
+ function get_affiliate() {
11158
+ return $this->affiliate;
11159
+ }
11160
+
11161
+
11162
+ /**
11163
+ * @author Leo Fajardo (@leorw)
11164
+ * @since 1.2.3
11165
+ *
11166
+ * @return FS_AffiliateTerms
11167
+ */
11168
+ function get_affiliate_terms() {
11169
+ return is_object( $this->custom_affiliate_terms ) ?
11170
+ $this->custom_affiliate_terms :
11171
+ $this->plugin_affiliate_terms;
11172
+ }
11173
+
11174
+ /**
11175
+ * @author Leo Fajardo (@leorw)
11176
+ * @since 1.2.3
11177
+ */
11178
+ function _submit_affiliate_application() {
11179
+ $this->_logger->entrance();
11180
+
11181
+ $this->check_ajax_referer( 'submit_affiliate_application' );
11182
+
11183
+ if ( ! $this->is_user_admin() ) {
11184
+ // Only for admins.
11185
+ self::shoot_ajax_failure();
11186
+ }
11187
+
11188
+ $affiliate = fs_request_get( 'affiliate' );
11189
+
11190
+ if ( empty( $affiliate['promotion_methods'] ) ) {
11191
+ unset( $affiliate['promotion_methods'] );
11192
+ }
11193
+
11194
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
11195
+ $affiliate['additional_domains'] = array_unique( $affiliate['additional_domains'] );
11196
+ }
11197
+
11198
+ if ( ! $this->is_registered() ) {
11199
+ // Opt in but don't track usage.
11200
+ $next_page = $this->opt_in(
11201
+ false,
11202
+ false,
11203
+ false,
11204
+ false,
11205
+ false,
11206
+ false,
11207
+ true
11208
+ );
11209
+
11210
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
11211
+ self::shoot_ajax_failure(
11212
+ isset( $next_page->error ) ?
11213
+ $next_page->error->message :
11214
+ var_export( $next_page, true )
11215
+ );
11216
+ } else if ( $this->is_pending_activation() ) {
11217
+ self::shoot_ajax_failure( $this->get_text_inline( 'Account is pending activation.', 'account-is-pending-activation' ) );
11218
+ }
11219
+ }
11220
+
11221
+ $this->fetch_affiliate_terms();
11222
+
11223
+ $api = $this->get_api_user_scope();
11224
+ $result = $api->call(
11225
+ ( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json" ),
11226
+ 'post',
11227
+ $affiliate
11228
+ );
11229
+
11230
+ if ( $this->is_api_error( $result ) ) {
11231
+ self::shoot_ajax_failure(
11232
+ isset( $result->error ) ?
11233
+ $result->error->message :
11234
+ var_export( $result, true )
11235
+ );
11236
+ } else {
11237
+ if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
11238
+ $this->_admin_notices->remove_sticky( 'affiliate_program' );
11239
+ }
11240
+
11241
+ $affiliate_application_data = array(
11242
+ 'status' => 'pending',
11243
+ 'stats_description' => $affiliate['stats_description'],
11244
+ 'promotion_method_description' => $affiliate['promotion_method_description'],
11245
+ );
11246
+
11247
+ if ( ! empty( $affiliate['promotion_methods'] ) ) {
11248
+ $affiliate_application_data['promotion_methods'] = $affiliate['promotion_methods'];
11249
+ }
11250
+
11251
+ if ( ! empty( $affiliate['domain'] ) ) {
11252
+ $affiliate_application_data['domain'] = $affiliate['domain'];
11253
+ }
11254
+
11255
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
11256
+ $affiliate_application_data['additional_domains'] = $affiliate['additional_domains'];
11257
+ }
11258
+
11259
+ $this->_storage->affiliate_application_data = $affiliate_application_data;
11260
+ }
11261
+
11262
+ // Purge cached affiliate.
11263
+ $api->purge_cache( 'affiliate.json' );
11264
+
11265
+ self::shoot_ajax_success( $result );
11266
+ }
11267
+
11268
+ /**
11269
+ * @author Leo Fajardo (@leorw)
11270
+ * @since 1.2.3
11271
+ *
11272
+ * @return array|null
11273
+ */
11274
+ function get_affiliate_application_data() {
11275
+ if ( empty( $this->_storage->affiliate_application_data ) ) {
11276
+ return null;
11277
+ }
11278
+
11279
+ return $this->_storage->affiliate_application_data;
11280
+ }
11281
+
11282
+ #endregion Affiliation ------------------------------------------------------------
11283
+
11284
+ #----------------------------------------------------------------------------------
11285
+ #region URL Generators
11286
+ #----------------------------------------------------------------------------------
11287
+
11288
+ /**
11289
+ * Alias to pricing_url().
11290
+ *
11291
+ * @author Vova Feldman (@svovaf)
11292
+ * @since 1.0.2
11293
+ *
11294
+ * @uses pricing_url()
11295
+ *
11296
+ * @param string $period Billing cycle
11297
+ * @param bool $is_trial
11298
+ *
11299
+ * @return string
11300
+ */
11301
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
11302
+ return $this->pricing_url( $period, $is_trial );
11303
+ }
11304
+
11305
+ /**
11306
+ * @author Vova Feldman (@svovaf)
11307
+ * @since 1.0.9
11308
+ *
11309
+ * @uses get_upgrade_url()
11310
+ *
11311
+ * @return string
11312
+ */
11313
+ function get_trial_url() {
11314
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
11315
+ }
11316
+
11317
+ /**
11318
+ * Plugin's pricing URL.
11319
+ *
11320
+ * @author Vova Feldman (@svovaf)
11321
+ * @since 1.0.4
11322
+ *
11323
+ * @param string $billing_cycle Billing cycle
11324
+ *
11325
+ * @param bool $is_trial
11326
+ *
11327
+ * @return string
11328
+ */
11329
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
11330
+ $this->_logger->entrance();
11331
+
11332
+ $params = array(
11333
+ 'billing_cycle' => $billing_cycle
11334
+ );
11335
+
11336
+ if ( $is_trial ) {
11337
+ $params['trial'] = 'true';
11338
+ }
11339
+
11340
+ if ( $this->is_addon() ) {
11341
+ return $this->_parent->addon_url( $this->_slug );
11342
+ }
11343
+
11344
+ return $this->_get_admin_page_url( 'pricing', $params );
11345
+ }
11346
+
11347
+ /**
11348
+ * Checkout page URL.
11349
+ *
11350
+ * @author Vova Feldman (@svovaf)
11351
+ * @since 1.0.6
11352
+ *
11353
+ * @param string $billing_cycle Billing cycle
11354
+ * @param bool $is_trial
11355
+ * @param array $extra (optional) Extra parameters, override other query params.
11356
+ *
11357
+ * @return string
11358
+ */
11359
+ function checkout_url(
11360
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
11361
+ $is_trial = false,
11362
+ $extra = array()
11363
+ ) {
11364
+ $this->_logger->entrance();
11365
+
11366
+ $params = array(
11367
+ 'checkout' => 'true',
11368
+ 'billing_cycle' => $billing_cycle,
11369
+ );
11370
+
11371
+ if ( $is_trial ) {
11372
+ $params['trial'] = 'true';
11373
+ }
11374
+
11375
+ /**
11376
+ * Params in extra override other params.
11377
+ */
11378
+ $params = array_merge( $params, $extra );
11379
+
11380
+ return $this->_get_admin_page_url( 'pricing', $params );
11381
+ }
11382
+
11383
+ /**
11384
+ * Add-on checkout URL.
11385
+ *
11386
+ * @author Vova Feldman (@svovaf)
11387
+ * @since 1.1.7
11388
+ *
11389
+ * @param number $addon_id
11390
+ * @param number $pricing_id
11391
+ * @param string $billing_cycle
11392
+ * @param bool $is_trial
11393
+ *
11394
+ * @return string
11395
+ */
11396
+ function addon_checkout_url(
11397
+ $addon_id,
11398
+ $pricing_id,
11399
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
11400
+ $is_trial = false
11401
+ ) {
11402
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
11403
+ 'plugin_id' => $addon_id,
11404
+ 'pricing_id' => $pricing_id,
11405
+ ) );
11406
+ }
11407
+
11408
+ #endregion
11409
+
11410
+ #endregion ------------------------------------------------------------------
11411
+
11412
+ /**
11413
+ * Check if plugin has any add-ons.
11414
+ *
11415
+ * @author Vova Feldman (@svovaf)
11416
+ * @since 1.0.5
11417
+ *
11418
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
11419
+ *
11420
+ * @return bool
11421
+ */
11422
+ function has_addons() {
11423
+ $this->_logger->entrance();
11424
+
11425
+ return $this->_has_addons;
11426
+ }
11427
+
11428
+ /**
11429
+ * Check if plugin can work in anonymous mode.
11430
+ *
11431
+ * @author Vova Feldman (@svovaf)
11432
+ * @since 1.0.9
11433
+ *
11434
+ * @return bool
11435
+ *
11436
+ * @deprecated Please use is_enable_anonymous() instead.
11437
+ */
11438
+ function enable_anonymous() {
11439
+ return $this->_enable_anonymous;
11440
+ }
11441
+
11442
+ /**
11443
+ * Check if plugin can work in anonymous mode.
11444
+ *
11445
+ * @author Vova Feldman (@svovaf)
11446
+ * @since 1.1.9
11447
+ *
11448
+ * @return bool
11449
+ */
11450
+ function is_enable_anonymous() {
11451
+ return $this->_enable_anonymous;
11452
+ }
11453
+
11454
+ /**
11455
+ * Check if plugin is premium only (no free plans).
11456
+ *
11457
+ * @author Vova Feldman (@svovaf)
11458
+ * @since 1.1.9
11459
+ *
11460
+ * @return bool
11461
+ */
11462
+ function is_only_premium() {
11463
+ return $this->_is_premium_only;
11464
+ }
11465
+
11466
+ /**
11467
+ * Checks if the plugin's type is "plugin". The other type is "theme".
11468
+ *
11469
+ * @author Leo Fajardo (@leorw)
11470
+ * @since 1.2.2
11471
+ *
11472
+ * @return bool
11473
+ */
11474
+ function is_plugin() {
11475
+ return ( WP_FS__MODULE_TYPE_PLUGIN === $this->_module_type );
11476
+ }
11477
+
11478
+ /**
11479
+ * @author Leo Fajardo (@leorw)
11480
+ * @since 1.2.2
11481
+ *
11482
+ * @return string
11483
+ */
11484
+ function get_module_type() {
11485
+ if ( ! isset( $this->_module_type ) ) {
11486
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
11487
+ $this->_module_type = $id_slug_type_path_map[ $this->_module_id ]['type'];
11488
+ }
11489
+
11490
+ return $this->_module_type;
11491
+ }
11492
+
11493
+ /**
11494
+ * @author Leo Fajardo (@leorw)
11495
+ * @since 1.2.2
11496
+ *
11497
+ * @return string
11498
+ */
11499
+ function get_plugin_main_file_path() {
11500
+ return $this->_plugin_main_file_path;
11501
+ }
11502
+
11503
+ /**
11504
+ * Check if module has a premium code version.
11505
+ *
11506
+ * Serviceware module might be freemium without any
11507
+ * premium code version, where the paid features
11508
+ * are all part of the service.
11509
+ *
11510
+ * @author Vova Feldman (@svovaf)
11511
+ * @since 1.2.1.6
11512
+ *
11513
+ * @return bool
11514
+ */
11515
+ function has_premium_version() {
11516
+ return $this->_has_premium_version;
11517
+ }
11518
+
11519
+ /**
11520
+ * Check if feature supported with current site's plan.
11521
+ *
11522
+ * @author Vova Feldman (@svovaf)
11523
+ * @since 1.0.1
11524
+ *
11525
+ * @todo IMPLEMENT
11526
+ *
11527
+ * @param number $feature_id
11528
+ *
11529
+ * @throws Exception
11530
+ */
11531
+ function is_feature_supported( $feature_id ) {
11532
+ throw new Exception( 'not implemented' );
11533
+ }
11534
+
11535
+ /**
11536
+ * @author Vova Feldman (@svovaf)
11537
+ * @since 1.0.1
11538
+ *
11539
+ * @return bool Is running in SSL/HTTPS
11540
+ */
11541
+ function is_ssl() {
11542
+ return WP_FS__IS_HTTPS;
11543
+ }
11544
+
11545
+ /**
11546
+ * @author Vova Feldman (@svovaf)
11547
+ * @since 1.0.9
11548
+ *
11549
+ * @return bool Is running in AJAX call.
11550
+ *
11551
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
11552
+ */
11553
+ static function is_ajax() {
11554
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
11555
+ }
11556
+
11557
+ /**
11558
+ * Check if it's an AJAX call targeted for the current module.
11559
+ *
11560
+ * @author Vova Feldman (@svovaf)
11561
+ * @since 1.2.0
11562
+ *
11563
+ * @param array|string $actions Collection of AJAX actions.
11564
+ *
11565
+ * @return bool
11566
+ */
11567
+ function is_ajax_action( $actions ) {
11568
+ // Verify it's an ajax call.
11569
+ if ( ! self::is_ajax() ) {
11570
+ return false;
11571
+ }
11572
+
11573
+ // Verify the call is relevant for the plugin.
11574
+ if ( $this->_module_id != fs_request_get( 'module_id' ) ) {
11575
+ return false;
11576
+ }
11577
+
11578
+ // Verify it's one of the specified actions.
11579
+ if ( is_string( $actions ) ) {
11580
+ $actions = explode( ',', $actions );
11581
+ }
11582
+
11583
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
11584
+ $ajax_action = fs_request_get( 'action' );
11585
+
11586
+ foreach ( $actions as $action ) {
11587
+ if ( $ajax_action === $this->get_action_tag( $action ) ) {
11588
+ return true;
11589
+ }
11590
+ }
11591
+ }
11592
+
11593
+ return false;
11594
+ }
11595
+
11596
+ /**
11597
+ * Check if it's an AJAX call targeted for current request.
11598
+ *
11599
+ * @author Vova Feldman (@svovaf)
11600
+ * @since 1.2.0
11601
+ *
11602
+ * @param array|string $actions Collection of AJAX actions.
11603
+ * @param number|null $module_id
11604
+ *
11605
+ * @return bool
11606
+ */
11607
+ static function is_ajax_action_static( $actions, $module_id = null ) {
11608
+ // Verify it's an ajax call.
11609
+ if ( ! self::is_ajax() ) {
11610
+ return false;
11611
+ }
11612
+
11613
+
11614
+ if ( ! empty( $module_id ) ) {
11615
+ // Verify the call is relevant for the plugin.
11616
+ if ( $module_id != fs_request_get( 'module_id' ) ) {
11617
+ return false;
11618
+ }
11619
+ }
11620
+
11621
+ // Verify it's one of the specified actions.
11622
+ if ( is_string( $actions ) ) {
11623
+ $actions = explode( ',', $actions );
11624
+ }
11625
+
11626
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
11627
+ $ajax_action = fs_request_get( 'action' );
11628
+
11629
+ foreach ( $actions as $action ) {
11630
+ if ( $ajax_action === self::get_ajax_action_static( $action, $module_id ) ) {
11631
+ return true;
11632
+ }
11633
+ }
11634
+ }
11635
+
11636
+ return false;
11637
+ }
11638
+
11639
+ /**
11640
+ * @author Vova Feldman (@svovaf)
11641
+ * @since 1.1.7
11642
+ *
11643
+ * @return bool
11644
+ */
11645
+ static function is_cron() {
11646
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
11647
+ }
11648
+
11649
+ /**
11650
+ * Check if a real user is visiting the admin dashboard.
11651
+ *
11652
+ * @author Vova Feldman (@svovaf)
11653
+ * @since 1.1.7
11654
+ *
11655
+ * @return bool
11656
+ */
11657
+ function is_user_in_admin() {
11658
+ return is_admin() && ! self::is_ajax() && ! self::is_cron();
11659
+ }
11660
+
11661
+ /**
11662
+ * Check if a real user is in the customizer view.
11663
+ *
11664
+ * @author Vova Feldman (@svovaf)
11665
+ * @since 1.2.2.7
11666
+ *
11667
+ * @return bool
11668
+ */
11669
+ static function is_customizer() {
11670
+ return is_customize_preview();
11671
+ }
11672
+
11673
+ /**
11674
+ * Check if running in HTTPS and if site's plan matching the specified plan.
11675
+ *
11676
+ * @param string $plan
11677
+ * @param bool $exact
11678
+ *
11679
+ * @return bool
11680
+ */
11681
+ function is_ssl_and_plan( $plan, $exact = false ) {
11682
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
11683
+ }
11684
+
11685
+ /**
11686
+ * Construct plugin's settings page URL.
11687
+ *
11688
+ * @author Vova Feldman (@svovaf)
11689
+ * @since 1.0.4
11690
+ *
11691
+ * @param string $page
11692
+ * @param array $params
11693
+ * @param bool|null $network
11694
+ *
11695
+ * @return string
11696
+ */
11697
+ function _get_admin_page_url( $page = '', $params = array(), $network = null ) {
11698
+ if ( is_null( $network ) ) {
11699
+ $network = (
11700
+ $this->_is_network_active &&
11701
+ ( fs_is_network_admin() || ! $this->is_delegated_connection() )
11702
+ );
11703
+ }
11704
+
11705
+ if ( 0 < count( $params ) ) {
11706
+ foreach ( $params as $k => $v ) {
11707
+ $params[ $k ] = urlencode( $v );
11708
+ }
11709
+ }
11710
+
11711
+ $page_param = $this->_menu->get_slug( $page );
11712
+
11713
+ if ( empty( $page ) &&
11714
+ $this->is_theme() &&
11715
+ // Show the opt-in as an overlay for free wp.org themes or themes without any settings page.
11716
+ ( $this->is_free_wp_org_theme() || ! $this->has_settings_menu() )
11717
+ ) {
11718
+ $params[ $this->get_unique_affix() . '_show_optin' ] = 'true';
11719
+
11720
+ return add_query_arg(
11721
+ $params,
11722
+ $this->admin_url( 'themes.php', 'admin', $network )
11723
+ );
11724
+ }
11725
+
11726
+ if ( ! $this->has_settings_menu() ) {
11727
+ if ( ! empty( $page ) ) {
11728
+ // Module doesn't have a setting page, but since the request is for
11729
+ // a specific Freemius page, use the admin.php path.
11730
+ return add_query_arg( array_merge( $params, array(
11731
+ 'page' => $page_param,
11732
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11733
+ } else {
11734
+ if ( $this->is_activation_mode() ) {
11735
+ /**
11736
+ * @author Vova Feldman
11737
+ * @since 1.2.1.6
11738
+ *
11739
+ * If plugin doesn't have a settings page, create one for the opt-in screen.
11740
+ */
11741
+ return add_query_arg( array_merge( $params, array(
11742
+ 'page' => $this->_slug,
11743
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11744
+ } else {
11745
+ // Plugin without a settings page.
11746
+ return add_query_arg(
11747
+ $params,
11748
+ $this->admin_url( 'plugins.php', 'admin', $network )
11749
+ );
11750
+ }
11751
+ }
11752
+ }
11753
+
11754
+ // Module has a submenu settings page.
11755
+ if ( ! $this->_menu->is_top_level() ) {
11756
+ $parent_slug = $this->_menu->get_parent_slug();
11757
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
11758
+ $parent_slug :
11759
+ 'admin.php';
11760
+
11761
+ return add_query_arg( array_merge( $params, array(
11762
+ 'page' => $page_param,
11763
+ ) ), $this->admin_url( $menu_file, 'admin', $network ) );
11764
+ }
11765
+
11766
+ // Module has a top level CPT settings page.
11767
+ if ( $this->_menu->is_cpt() ) {
11768
+ if ( empty( $page ) && $this->is_activation_mode() ) {
11769
+ return add_query_arg( array_merge( $params, array(
11770
+ 'page' => $page_param
11771
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11772
+ } else {
11773
+ if ( ! empty( $page ) ) {
11774
+ $params['page'] = $page_param;
11775
+ }
11776
+
11777
+ return add_query_arg(
11778
+ $params,
11779
+ $this->admin_url( $this->_menu->get_raw_slug(), 'admin', $network )
11780
+ );
11781
+ }
11782
+ }
11783
+
11784
+ // Module has a custom top level settings page.
11785
+ return add_query_arg( array_merge( $params, array(
11786
+ 'page' => $page_param,
11787
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11788
+ }
11789
+
11790
+ #--------------------------------------------------------------------------------
11791
+ #region Multisite
11792
+ #--------------------------------------------------------------------------------
11793
+
11794
+ /**
11795
+ * @author Leo Fajardo (@leorw)
11796
+ * @since 2.0.0
11797
+ *
11798
+ * @return bool
11799
+ */
11800
+ function is_network_active() {
11801
+ return $this->_is_network_active;
11802
+ }
11803
+
11804
+ /**
11805
+ * Delegate activation for the given sites in the network (or all sites if `null`) to site admins.
11806
+ *
11807
+ * @author Leo Fajardo (@leorw)
11808
+ * @since 2.0.0
11809
+ *
11810
+ * @param array|null $sites
11811
+ */
11812
+ private function delegate_connection( $sites = null ) {
11813
+ $this->_logger->entrance();
11814
+
11815
+ $this->_admin_notices->remove_sticky( 'connect_account' );
11816
+
11817
+ if ( is_null( $sites ) ) {
11818
+ // All sites delegation.
11819
+ $this->_storage->store( 'is_delegated_connection', true, true, true );
11820
+ } else {
11821
+ // Specified sites delegation.
11822
+ foreach ( $sites as $site ) {
11823
+ $this->delegate_site_connection( $site['blog_id'] );
11824
+ }
11825
+ }
11826
+
11827
+ $this->network_upgrade_mode_completed();
11828
+ }
11829
+
11830
+ /**
11831
+ * Delegate specific network site conncetion to the site admin.
11832
+ *
11833
+ * @author Vova Feldman (@svovaf)
11834
+ * @since 2.0.0
11835
+ *
11836
+ * @param int $blog_id
11837
+ */
11838
+ private function delegate_site_connection( $blog_id ) {
11839
+ $this->_storage->store( 'is_delegated_connection', true, $blog_id, true );
11840
+ }
11841
+
11842
+ /**
11843
+ * Check if super-admin delegated the connection of ALL sites to the site admins.
11844
+ *
11845
+ * @author Vova Feldman (@svovaf)
11846
+ * @since 2.0.0
11847
+ *
11848
+ * @return bool
11849
+ */
11850
+ function is_network_delegated_connection() {
11851
+ if ( ! $this->_is_network_active ) {
11852
+ return false;
11853
+ }
11854
+
11855
+ return $this->_storage->get( 'is_delegated_connection', false, true );
11856
+ }
11857
+
11858
+ /**
11859
+ * @author Leo Fajardo (@leorw)
11860
+ * @since 2.0.0
11861
+ *
11862
+ * @param int $blog_id
11863
+ *
11864
+ * @return bool
11865
+ */
11866
+ function is_site_delegated_connection( $blog_id = 0 ) {
11867
+ if ( ! $this->_is_network_active ) {
11868
+ return false;
11869
+ }
11870
+
11871
+ if ( 0 == $blog_id ) {
11872
+ $blog_id = get_current_blog_id();
11873
+ }
11874
+
11875
+ return $this->_storage->get( 'is_delegated_connection', false, $blog_id );
11876
+ }
11877
+
11878
+ /**
11879
+ * Check if delegated the connection. When running within the the network admin,
11880
+ * and haven't specified the blog ID, checks if network level delegated. If running
11881
+ * within a site admin or specified a blog ID, check if delegated the connection for
11882
+ * the current context site.
11883
+ *
11884
+ * If executed outside the the admin, check if delegated the connection
11885
+ * for the current context site OR the whole network.
11886
+ *
11887
+ * @author Vova Feldman (@svovaf)
11888
+ * @since 2.0.0
11889
+ *
11890
+ * @param int $blog_id If set, checks if network delegated or blog specific delegated.
11891
+ *
11892
+ * @return bool
11893
+ */
11894
+ function is_delegated_connection( $blog_id = 0 ) {
11895
+ if ( ! $this->_is_network_active ) {
11896
+ return false;
11897
+ }
11898
+
11899
+ if ( fs_is_network_admin() && 0 == $blog_id ) {
11900
+ return $this->is_network_delegated_connection();
11901
+ }
11902
+
11903
+ return (
11904
+ $this->is_network_delegated_connection() ||
11905
+ $this->is_site_delegated_connection( $blog_id )
11906
+ );
11907
+ }
11908
+
11909
+ /**
11910
+ * Check if the current module is active for the site.
11911
+ *
11912
+ * @author Vova Feldman (@svovaf)
11913
+ * @since 2.0.0
11914
+ *
11915
+ * @param int $blog_id
11916
+ *
11917
+ * @return bool
11918
+ */
11919
+ function is_active_for_site( $blog_id ) {
11920
+ if ( ! is_multisite() ) {
11921
+ // Not a multisite and this code is executed, means that the plugin is active.
11922
+ return true;
11923
+ }
11924
+
11925
+ if ( $this->is_theme() ) {
11926
+ // All themes are site level activated.
11927
+ return true;
11928
+ }
11929
+
11930
+ if ( $this->_is_network_active ) {
11931
+ // Plugin was network activated so it's active.
11932
+ return true;
11933
+ }
11934
+
11935
+ return in_array( $this->_plugin_basename, (array) get_blog_option( $blog_id, 'active_plugins', array() ) );
11936
+ }
11937
+
11938
+ /**
11939
+ * @author Leo Fajardo (@leorw)
11940
+ * @since 2.0.0
11941
+ *
11942
+ * @return array Active & public sites collection.
11943
+ */
11944
+ static function get_sites() {
11945
+ /**
11946
+ * For consistency with get_blog_list() which only return active public sites.
11947
+ *
11948
+ * @author Vova Feldman (@svovaf)
11949
+ */
11950
+ $args = array(
11951
+ 'public' => 1,
11952
+ 'archived' => 0,
11953
+ 'mature' => 0,
11954
+ 'spam' => 0,
11955
+ 'deleted' => 0,
11956
+ );
11957
+
11958
+ if ( function_exists( 'get_sites' ) ) {
11959
+ // For WP 4.6 and above.
11960
+ return get_sites( $args );
11961
+ } else if ( function_exists( 'wp_get_sites' ) ) {
11962
+ // For WP 3.7 to WP 4.5.
11963
+ return wp_get_sites( $args );
11964
+ } else {
11965
+ // For WP 3.6 and below.
11966
+ return get_blog_list( 0, 'all' );
11967
+ }
11968
+ }
11969
+
11970
+ /**
11971
+ * Checks if a given blog is active.
11972
+ *
11973
+ * @author Vova Feldman (@svovaf)
11974
+ * @since 2.0.0
11975
+ *
11976
+ * @param $blog_id
11977
+ *
11978
+ * @return bool
11979
+ */
11980
+ private static function is_site_active( $blog_id ) {
11981
+ global $wpdb;
11982
+
11983
+ $blog_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d", $blog_id ) );
11984
+
11985
+ if ( ! is_object( $blog_info ) ) {
11986
+ return false;
11987
+ }
11988
+
11989
+ return (
11990
+ true == $blog_info->public &&
11991
+ false == $blog_info->archived &&
11992
+ false == $blog_info->mature &&
11993
+ false == $blog_info->spam &&
11994
+ false == $blog_info->deleted
11995
+ );
11996
+ }
11997
+
11998
+ /**
11999
+ * Get a mapping between the site addresses to their blog IDs.
12000
+ *
12001
+ * @author Vova Feldman (@svovaf)
12002
+ * @since 2.0.0
12003
+ *
12004
+ * @return array {
12005
+ * @key string Site address without protocol with a trailing slash.
12006
+ * @value int Site's blog ID.
12007
+ * }
12008
+ */
12009
+ private function get_address_to_blog_map() {
12010
+ $sites = self::get_sites();
12011
+
12012
+ // Map site addresses to their blog IDs.
12013
+ $address_to_blog_map = array();
12014
+ foreach ( $sites as $site ) {
12015
+ $blog_id = self::get_site_blog_id( $site );
12016
+ $address = trailingslashit( fs_strip_url_protocol( get_site_url( $blog_id ) ) );
12017
+ $address_to_blog_map[ $address ] = $blog_id;
12018
+ }
12019
+
12020
+ return $address_to_blog_map;
12021
+ }
12022
+
12023
+ /**
12024
+ * Get a mapping between the site addresses to their blog IDs.
12025
+ *
12026
+ * @author Vova Feldman (@svovaf)
12027
+ * @since 2.0.0
12028
+ *
12029
+ * @return array {
12030
+ * @key int Site's blog ID.
12031
+ * @value FS_Site Associated install.
12032
+ * }
12033
+ */
12034
+ function get_blog_install_map() {
12035
+ $sites = self::get_sites();
12036
+
12037
+ // Map site blog ID to its install.
12038
+ $install_map = array();
12039
+
12040
+ foreach ( $sites as $site ) {
12041
+ $blog_id = self::get_site_blog_id( $site );
12042
+ $install = $this->get_install_by_blog_id( $blog_id );
12043
+
12044
+ if ( is_object( $install ) ) {
12045
+ $install_map[ $blog_id ] = $install;
12046
+ }
12047
+ }
12048
+
12049
+ return $install_map;
12050
+ }
12051
+
12052
+ /**
12053
+ * Gets a map of modul