assets
3 weeks ago
builder
3 weeks ago
templates
3 weeks ago
views
3 weeks ago
addon-functions.php
3 weeks ago
admin-functions.php
3 weeks ago
enqueu-script.php
3 weeks ago
index.php
3 weeks ago
addon-functions.php
215 lines
| 1 | <?php |
| 2 | |
| 3 | if (! defined('ABSPATH')) { |
| 4 | exit; // Exit if accessed directly |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Deactivate addon. |
| 9 | * |
| 10 | * @since 1.0.0 |
| 11 | */ |
| 12 | function cff_deactivate_addon() |
| 13 | { |
| 14 | |
| 15 | // Run a security check. |
| 16 | check_ajax_referer('cff-admin', 'nonce'); |
| 17 | |
| 18 | // Check for permissions. |
| 19 | if (! current_user_can('deactivate_plugins')) { |
| 20 | wp_send_json_error(); |
| 21 | } |
| 22 | |
| 23 | $type = 'addon'; |
| 24 | if (! empty($_POST['type'])) { |
| 25 | $type = sanitize_key(wp_unslash($_POST['type'])); |
| 26 | } |
| 27 | |
| 28 | if (isset($_POST['plugin'])) { |
| 29 | deactivate_plugins(wp_unslash($_POST['plugin'])); |
| 30 | |
| 31 | if ('plugin' === $type) { |
| 32 | wp_send_json_success(esc_html__('Plugin deactivated.', 'custom-facebook-feed')); |
| 33 | } else { |
| 34 | wp_send_json_success(esc_html__('Addon deactivated.', 'custom-facebook-feed')); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | wp_send_json_error(esc_html__('Could not deactivate the addon. Please deactivate from the Plugins page.', 'custom-facebook-feed')); |
| 39 | } |
| 40 | add_action('wp_ajax_cff_deactivate_addon', 'cff_deactivate_addon'); |
| 41 | |
| 42 | /** |
| 43 | * Activate addon. |
| 44 | * |
| 45 | * @since 1.0.0 |
| 46 | */ |
| 47 | function cff_activate_addon() |
| 48 | { |
| 49 | |
| 50 | // Run a security check. |
| 51 | check_ajax_referer('cff-admin', 'nonce'); |
| 52 | |
| 53 | // Check for permissions. |
| 54 | if (! current_user_can('activate_plugins')) { |
| 55 | wp_send_json_error(); |
| 56 | } |
| 57 | |
| 58 | if (isset($_POST['plugin'])) { |
| 59 | $type = 'addon'; |
| 60 | if (! empty($_POST['type'])) { |
| 61 | $type = sanitize_key(wp_unslash($_POST['type'])); |
| 62 | } |
| 63 | |
| 64 | $activate = activate_plugins($_POST['plugin']); |
| 65 | |
| 66 | if (! is_wp_error($activate)) { |
| 67 | if ('plugin' === $type) { |
| 68 | wp_send_json_success(esc_html__('Plugin activated.', 'custom-facebook-feed')); |
| 69 | } else { |
| 70 | wp_send_json_success(esc_html__('Addon activated.', 'custom-facebook-feed')); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | wp_send_json_error(esc_html__('Could not activate addon. Please activate from the Plugins page.', 'custom-facebook-feed')); |
| 76 | } |
| 77 | add_action('wp_ajax_cff_activate_addon', 'cff_activate_addon'); |
| 78 | |
| 79 | /** |
| 80 | * Install addon. |
| 81 | * |
| 82 | * @since 1.0.0 |
| 83 | */ |
| 84 | function cff_install_addon() |
| 85 | { |
| 86 | |
| 87 | // Run a security check. |
| 88 | check_ajax_referer('cff-admin', 'nonce'); |
| 89 | |
| 90 | // Check for permissions. |
| 91 | if (! current_user_can('install_plugins')) { |
| 92 | wp_send_json_error(); |
| 93 | } |
| 94 | |
| 95 | $error = esc_html__('Could not install addon. Please download from smashballoon.com and install manually.', 'custom-facebook-feed'); |
| 96 | |
| 97 | if (empty($_POST['plugin'])) { |
| 98 | wp_send_json_error($error); |
| 99 | } |
| 100 | |
| 101 | // Set the current screen to avoid undefined notices. |
| 102 | set_current_screen('cff-about'); |
| 103 | |
| 104 | // Prepare variables. |
| 105 | $url = esc_url_raw( |
| 106 | add_query_arg( |
| 107 | array( |
| 108 | 'page' => 'cff-about', |
| 109 | ), |
| 110 | admin_url('admin.php') |
| 111 | ) |
| 112 | ); |
| 113 | |
| 114 | $creds = request_filesystem_credentials($url, '', false, false, null); |
| 115 | |
| 116 | // Check for file system permissions. |
| 117 | if (false === $creds) { |
| 118 | wp_send_json_error($error); |
| 119 | } |
| 120 | |
| 121 | if (! WP_Filesystem($creds)) { |
| 122 | wp_send_json_error($error); |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * We do not need any extra credentials if we have gotten this far, so let's install the plugin. |
| 127 | */ |
| 128 | |
| 129 | // require_once CFF_PLUGIN_DIR . 'admin/class-install-skin.php'; |
| 130 | |
| 131 | // Do not allow WordPress to search/download translations, as this will break JS output. |
| 132 | remove_action('upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20); |
| 133 | |
| 134 | // Create the plugin upgrader with our custom skin. |
| 135 | $installer = new CustomFacebookFeed\Helpers\PluginSilentUpgrader(new CustomFacebookFeed\Admin\CFF_Install_Skin()); |
| 136 | |
| 137 | // Error check. |
| 138 | if (! method_exists($installer, 'install') || empty($_POST['plugin'])) { |
| 139 | wp_send_json_error($error); |
| 140 | } |
| 141 | |
| 142 | $installer->install( $_POST['plugin'] ); // phpcs:ignore |
| 143 | |
| 144 | // Flush the cache and return the newly installed plugin basename. |
| 145 | wp_cache_flush(); |
| 146 | |
| 147 | $plugin_basename = $installer->plugin_info(); |
| 148 | |
| 149 | if ($plugin_basename) { |
| 150 | $type = 'addon'; |
| 151 | if (! empty($_POST['type'])) { |
| 152 | $type = sanitize_key($_POST['type']); |
| 153 | } |
| 154 | |
| 155 | // Activate the plugin silently. |
| 156 | $activated = activate_plugin($plugin_basename); |
| 157 | |
| 158 | if (! is_wp_error($activated)) { |
| 159 | wp_send_json_success( |
| 160 | array( |
| 161 | 'msg' => 'plugin' === $type ? esc_html__('Plugin installed & activated.', 'custom-facebook-feed') : esc_html__('Addon installed & activated.', 'custom-facebook-feed'), |
| 162 | 'is_activated' => true, |
| 163 | 'basename' => $plugin_basename, |
| 164 | ) |
| 165 | ); |
| 166 | } else { |
| 167 | wp_send_json_success( |
| 168 | array( |
| 169 | 'msg' => 'plugin' === $type ? esc_html__('Plugin installed.', 'custom-facebook-feed') : esc_html__('Addon installed.', 'custom-facebook-feed'), |
| 170 | 'is_activated' => false, |
| 171 | 'basename' => $plugin_basename, |
| 172 | ) |
| 173 | ); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | wp_send_json_error($error); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | add_action('wp_ajax_cff_install_addon', 'cff_install_addon'); |
| 182 | |
| 183 | |
| 184 | /** |
| 185 | * Smash Balloon Encrypt or decrypt |
| 186 | * |
| 187 | * @param string @action |
| 188 | * @param string @string |
| 189 | * |
| 190 | * @return string $output |
| 191 | */ |
| 192 | function sb_encrypt_decrypt($action, $string) |
| 193 | { |
| 194 | $output = false; |
| 195 | |
| 196 | $encrypt_method = "AES-256-CBC"; |
| 197 | $secret_key = 'SMA$H.BA[[OON#23121'; |
| 198 | $secret_iv = '1231394873342102221'; |
| 199 | |
| 200 | // hash |
| 201 | $key = hash('sha256', $secret_key); |
| 202 | |
| 203 | // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning |
| 204 | $iv = substr(hash('sha256', $secret_iv), 0, 16); |
| 205 | |
| 206 | if ($action == 'encrypt') { |
| 207 | $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); |
| 208 | $output = base64_encode($output); |
| 209 | } elseif ($action == 'decrypt') { |
| 210 | $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); |
| 211 | } |
| 212 | |
| 213 | return $output; |
| 214 | } |
| 215 |