admin
2 months ago
custom_post
2 months ago
admin_notices.php
2 months ago
conditions.php
2 months ago
custom_post.php
2 months ago
error_notices.php
2 months ago
functions.php
2 months ago
ico.png
2 months ago
information_notices.php
2 months ago
libraries.php
2 months ago
plugin-variation.php
2 months ago
settings_fields.php
2 months ago
updater.php
2 months ago
widget.php
2 months ago
updater.php
1415 lines
| 1 | <?php |
| 2 | if ( ! class_exists( 'BeRocket_updater' ) ) { |
| 3 | define( "BeRocket_update_path", 'https://api.berocket.com/' ); |
| 4 | define( "BeRocket_cdn_path", 'https://apicdn.berocket.com/' ); |
| 5 | define( "BeRocket_main_path", 'https://berocket.com/' ); |
| 6 | define( "BeRocket_updater_log", true ); |
| 7 | include_once( plugin_dir_path( __FILE__ ) . 'error_notices.php' ); |
| 8 | |
| 9 | class BeRocket_updater { |
| 10 | public static $plugin_info = array(); |
| 11 | public static $slugs = array(); |
| 12 | public static $free_slugs = array(); |
| 13 | public static $key = ''; |
| 14 | public static $error_log = array(); |
| 15 | public static $debug_mode = false; |
| 16 | |
| 17 | public static function init() { |
| 18 | add_action( 'admin_init', array(__CLASS__, 'admin_init') ); |
| 19 | $options = get_option( 'BeRocket_account_option' ); |
| 20 | if( ! is_array($options) ) { |
| 21 | $options = array(); |
| 22 | } |
| 23 | self::$debug_mode = ! empty( $options[ 'debug_mode' ] ); |
| 24 | } |
| 25 | |
| 26 | public static function admin_init() { |
| 27 | add_filter('woocommerce_addons_sections', array(__CLASS__, 'woocommerce_addons_sections')); |
| 28 | add_filter( 'is_berocket_settings_page', array( __CLASS__, 'is_settings_page' ) ); |
| 29 | if( isset($_GET['page']) && isset($_GET['section']) && $_GET['page'] == 'wc-addons' && ( $_GET['section'] == 'berocket' || ! empty($_GET['search']) ) ) { |
| 30 | add_action('admin_footer', array(__CLASS__, 'woocommerce_addons_berocket')); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public static function run() { |
| 35 | $options = self::get_options(); |
| 36 | self::$debug_mode = ! empty( $options[ 'debug_mode' ] ); |
| 37 | self::$key = ( empty( $options[ 'account_key' ] ) ? '' : $options[ 'account_key' ] ); |
| 38 | |
| 39 | add_action( 'admin_head', array( __CLASS__, 'scripts' ) ); |
| 40 | add_action( 'admin_menu', array( __CLASS__, 'main_menu_item' ), 1 ); |
| 41 | add_action( 'admin_menu', array( __CLASS__, 'account_page' ), 500 ); |
| 42 | add_action( 'network_admin_menu', array( __CLASS__, 'network_account_page' ) ); |
| 43 | add_action( 'admin_init', array( __CLASS__, 'account_option_register' ) ); |
| 44 | add_filter( 'pre_set_site_transient_update_plugins', array( __CLASS__, 'update_check_set' ) ); |
| 45 | add_filter( 'plugins_api_result', array( __CLASS__, 'plugin_api_data' ), 10, 3 ); |
| 46 | add_action( "wp_ajax_br_test_key", array( __CLASS__, 'test_key' ) ); |
| 47 | add_action( "wp_ajax_br_test_keys", array( __CLASS__, 'test_keys' ) ); |
| 48 | add_filter( 'http_request_host_is_external', array( __CLASS__, 'allow_berocket_host' ), 10, 3 ); |
| 49 | |
| 50 | if ( BeRocket_updater_log ) { |
| 51 | add_action( 'admin_footer', array( __CLASS__, 'error_log' ) ); |
| 52 | add_action( 'wp_footer', array( __CLASS__, 'error_log' ) ); |
| 53 | } |
| 54 | |
| 55 | $plugin = array(); |
| 56 | $plugin = apply_filters( 'BeRocket_updater_add_plugin', $plugin ); |
| 57 | |
| 58 | if ( ! isset( $options[ 'plugin_key' ] ) || ! is_array( $options[ 'plugin_key' ] ) ) { |
| 59 | $options[ 'plugin_key' ] = array(); |
| 60 | } |
| 61 | $update = false; |
| 62 | foreach ( $plugin as $plug_id => $plug ) { |
| 63 | if( ! empty($plug[ 'slug' ]) ) { |
| 64 | self::$slugs[ $plug[ 'id' ] ] = $plug[ 'slug' ]; |
| 65 | } |
| 66 | if( ! empty($plug[ 'free_slug' ]) ) { |
| 67 | self::$free_slugs[ $plug[ 'id' ] ] = $plug[ 'free_slug' ]; |
| 68 | } |
| 69 | if ( isset( $options[ 'plugin_key' ][ $plug[ 'id' ] ] ) && $options[ 'plugin_key' ][ $plug[ 'id' ] ] != '' ) { |
| 70 | $plugin[ $plug_id ][ 'key' ] = $options[ 'plugin_key' ][ $plug[ 'id' ] ]; |
| 71 | } elseif ( isset( $plugin[ $plug_id ][ 'key' ] ) && $plugin[ $plug_id ][ 'key' ] != '' ) { |
| 72 | $options[ 'plugin_key' ][ $plug[ 'id' ] ] = $plugin[ $plug_id ][ 'key' ]; |
| 73 | $update = true; |
| 74 | } |
| 75 | } |
| 76 | if ( is_multisite() ) { |
| 77 | $options_ms = BeRocket_Framework::get_global_option(true); |
| 78 | if( ! empty($options_ms) && is_array($options_ms) && isset($options_ms['plugin_key']) && is_array($options_ms['plugin_key']) ) { |
| 79 | foreach ( $plugin as $plug_id => $plug ) { |
| 80 | if ( isset( $options_ms[ 'plugin_key' ][ $plug[ 'id' ] ] ) && $options_ms[ 'plugin_key' ][ $plug[ 'id' ] ] != '' ) { |
| 81 | $plugin[ $plug_id ][ 'key' ] = $options_ms[ 'plugin_key' ][ $plug[ 'id' ] ]; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | self::$plugin_info = $plugin; |
| 87 | |
| 88 | if ( $update ) { |
| 89 | self::set_options( $options ); |
| 90 | } |
| 91 | |
| 92 | add_filter( 'berocket_display_additional_notices', array( |
| 93 | __CLASS__, |
| 94 | 'berocket_display_additional_notices' |
| 95 | ) ); |
| 96 | |
| 97 | if( ! is_network_admin() ) { |
| 98 | add_filter( 'custom_menu_order', array( __CLASS__, 'wp_menu_order' ) ); |
| 99 | } |
| 100 | |
| 101 | //ADMIN NOTICE CHECK |
| 102 | add_filter( 'berocket_admin_notice_is_display_notice', array( __CLASS__, 'admin_notice_is_display_notice' ), 10, 3 ); |
| 103 | add_filter( 'berocket_admin_notice_is_display_notice_priority', array( __CLASS__, 'admin_notice_is_display_notice' ), 10, 3 ); |
| 104 | foreach ( self::$plugin_info as $plugin ) { |
| 105 | $plugin_file = $plugin['plugin']; |
| 106 | add_action( "after_plugin_row_{$plugin_file}", array( __CLASS__, 'update_message'), 10, 1 ); |
| 107 | } |
| 108 | |
| 109 | add_filter( 'plugins_api_result', array( __CLASS__, 'plugin_api_data' ), 10, 3 ); |
| 110 | } |
| 111 | |
| 112 | public static function error_log() { |
| 113 | if ( self::$debug_mode ) { |
| 114 | $plugins_list = self::$plugin_info; |
| 115 | if( is_array($plugins_list) && count($plugins_list) > 0 ) { |
| 116 | foreach($plugins_list as &$plugin) { |
| 117 | if( ! empty($plugin['key']) ) { |
| 118 | $plugin['key'] = self::hide_key($plugin['key']); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | self::$error_log = apply_filters( 'BeRocket_updater_error_log', self::$error_log ); |
| 123 | self::$error_log[ 'real_memory_usage' ] = memory_get_peak_usage( true ); |
| 124 | self::$error_log[ 'script_memory_usage' ] = memory_get_peak_usage( false ); |
| 125 | self::$error_log[ 'plugins' ] = $plugins_list; |
| 126 | self::$error_log[ 'memory_limit' ] = ini_get( 'memory_limit' ); |
| 127 | self::$error_log[ 'WP_DEBUG' ] = 'WP_DEBUG:' . ( defined( 'WP_DEBUG' ) ? ( WP_DEBUG ? 'true' : 'false' ) : 'false' ) . '; WP_DEBUG_DISPLAY:' . ( defined( 'WP_DEBUG_DISPLAY' ) ? ( WP_DEBUG_DISPLAY ? 'true' : 'false' ) : 'false' ); |
| 128 | $error_log = unserialize(preg_replace('/R:\d+/', 's:18:"RECURSION DETECTED"', serialize(self::$error_log))); |
| 129 | ?> |
| 130 | <script> |
| 131 | console.log(<?php echo json_encode( $error_log ); ?>); |
| 132 | </script> |
| 133 | <?php |
| 134 | } |
| 135 | if( ! empty($_GET['BRvercheck']) ) { |
| 136 | $plugin_versions = array(); |
| 137 | foreach(self::$plugin_info as $plugin_i) { |
| 138 | $plugin_versions[$plugin_i['plugin_name']] = array('name' => $plugin_i['name'], 'version' => $plugin_i['version']); |
| 139 | } |
| 140 | ?> |
| 141 | <script> |
| 142 | console.log(<?php echo json_encode( $plugin_versions ); ?>); |
| 143 | </script> |
| 144 | <?php |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | public static function wp_menu_order( $menu_ord ) { |
| 149 | global $submenu; |
| 150 | |
| 151 | if( empty($submenu[ 'berocket_account' ]) || ! is_array($submenu[ 'berocket_account' ]) || count($submenu[ 'berocket_account' ]) == 0 ) { |
| 152 | return $menu_ord; |
| 153 | } |
| 154 | $new_order_temp = array(); |
| 155 | $new_sub_order = array(); |
| 156 | $new_order_sort = array(); |
| 157 | |
| 158 | $compatibility_hack = apply_filters('BeRocket_updater_menu_order_custom_post', array()); |
| 159 | |
| 160 | $BeRocket_item = false; |
| 161 | $account_keys_item = false; |
| 162 | foreach ( $submenu[ 'berocket_account' ] as $item ) { |
| 163 | if ( $item[ 0 ] == 'BeRocket' ) { |
| 164 | $BeRocket_item = $item; |
| 165 | continue; |
| 166 | } elseif ( $item[ 0 ] == __('Setting & Keys', 'BeRocket_domain') ) { |
| 167 | $account_keys_item = $item; |
| 168 | continue; |
| 169 | } |
| 170 | if ( ! empty($compatibility_hack[ str_replace( "edit.php?post_type=", "", $item[ 2 ] ) ]) ) { |
| 171 | $item_0 = "<span class='berocket_admin_menu_custom_post_submenu"; |
| 172 | if ( $item[ 0 ] == 'Upgrade' ) { |
| 173 | $item_0 .= " berocket_admin_menu_custom_post_submenu_upgrade"; |
| 174 | $item[ 0 ] .= " ⚡"; |
| 175 | } |
| 176 | $item[ 0 ] = $item_0 . "'>" . $item[ 0 ] . "</span>"; |
| 177 | $new_sub_order[ $compatibility_hack[ str_replace( "edit.php?post_type=", "", $item[ 2 ] ) ] ][] = $item; |
| 178 | } else { |
| 179 | $new_order_temp[] = $item; |
| 180 | $new_order_sort[] = $item[ 0 ]; |
| 181 | } |
| 182 | } |
| 183 | $new_sub_order = apply_filters('BeRocket_updater_menu_order_sub_order', $new_sub_order); |
| 184 | |
| 185 | array_multisort( $new_order_sort, $new_order_temp ); |
| 186 | |
| 187 | $new_order = array(); |
| 188 | if( $BeRocket_item !== false ) { |
| 189 | $new_order[] = $BeRocket_item; |
| 190 | } |
| 191 | foreach ( $new_order_temp as $item ) { |
| 192 | $new_order[] = $item; |
| 193 | |
| 194 | if ( ! empty( $new_sub_order[ $item[ 2 ] ] ) ) { |
| 195 | foreach ( $new_sub_order[ $item[ 2 ] ] as $sub_item ) { |
| 196 | $new_order[] = $sub_item; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | if( $account_keys_item !== false ) { |
| 201 | $new_order[] = $account_keys_item; |
| 202 | } |
| 203 | |
| 204 | $submenu[ 'berocket_account' ] = $new_order; |
| 205 | |
| 206 | return $menu_ord; |
| 207 | } |
| 208 | |
| 209 | public static function add_to_debug( $data, $plugin, $keys = false ) { |
| 210 | if ( self::$debug_mode ) { |
| 211 | if ( $keys === false ) { |
| 212 | self::$error_log[ $plugin ][] = $data; |
| 213 | } elseif ( is_array( $keys ) ) { |
| 214 | if ( count( $keys ) > 0 ) { |
| 215 | $data_set = self::$error_log[ $plugin ]; |
| 216 | $last_key = array_pop( $keys ); |
| 217 | |
| 218 | foreach ( $keys as $key ) { |
| 219 | if ( ! is_array( $data_set[ $key ] ) ) { |
| 220 | $data_set[ $key ] = array(); |
| 221 | } |
| 222 | |
| 223 | $new_set = &$data_set[ $key ]; |
| 224 | unset( $data_set ); |
| 225 | |
| 226 | $data_set = &$new_set; |
| 227 | unset( $new_set ); |
| 228 | } |
| 229 | |
| 230 | if ( empty( $last_key ) ) { |
| 231 | $data_set[] = $data; |
| 232 | } else { |
| 233 | $data_set[ $last_key ] = $data; |
| 234 | } |
| 235 | } else { |
| 236 | self::$error_log[ $plugin ][] = $data; |
| 237 | } |
| 238 | } else { |
| 239 | self::$error_log[ $plugin ][ $keys ] = $data; |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | public static function berocket_display_additional_notices( $notices ) { |
| 245 | if ( ! empty( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'berocket_account' ) { |
| 246 | return $notices; |
| 247 | } |
| 248 | |
| 249 | $not_activated_notices = array(); |
| 250 | foreach ( self::$plugin_info as $plugin ) { |
| 251 | $check_plugin_activation = self::check_plugin_activation($plugin[ 'id' ]); |
| 252 | $is_active = ( ! empty($check_plugin_activation) && is_array($check_plugin_activation) && ! empty($check_plugin_activation['status']) ); |
| 253 | if ( ! $is_active ) { |
| 254 | $version_capability = br_get_value_from_array($plugin, array('version_capability'), 15); |
| 255 | if ( $version_capability > 5 && ! in_array($version_capability, array(15, 3, 17)) ) { |
| 256 | $meta_data = '?utm_source=paid_plugin&utm_medium=notice&utm_campaign='.$plugin['plugin_name']; |
| 257 | $not_activated_notices[] = array( |
| 258 | 'start' => 0, |
| 259 | 'end' => 0, |
| 260 | 'type' => 'error', |
| 261 | 'name' => $plugin[ 'name' ], |
| 262 | 'html' => '<p style="margin-right: 225px;">' . |
| 263 | __('Please', 'BeRocket_domain'). ' ' . |
| 264 | __('activate plugin', 'BeRocket_domain') . ' ' . $plugin[ 'name' ] . ' ' . |
| 265 | __('with help of plugin/account key from', 'BeRocket_domain'). ' ' |
| 266 | . '<a href="' . BeRocket_main_path . 'my-account' . $meta_data . '" target="_blank">' . |
| 267 | __('BeRocket account', 'BeRocket_domain') . '</a>. ' |
| 268 | . __('You can activate plugin in', 'BeRocket_domain') . |
| 269 | '</p>' |
| 270 | . '<a class="button notice-action-link not_berocket_button" href="' . |
| 271 | ( is_network_admin() ? admin_url( 'network/admin.php?page=berocket_account' ) : admin_url( 'admin.php?page=berocket_account' ) ) . '">' . |
| 272 | __('BeRocket Account settings', 'BeRocket_domain') . '</a> |
| 273 | ', |
| 274 | 'righthtml' => '', |
| 275 | 'rightwidth' => 0, |
| 276 | 'nothankswidth' => 0, |
| 277 | 'contentwidth' => 1600, |
| 278 | 'subscribe' => false, |
| 279 | 'priority' => 10, |
| 280 | 'height' => 70, |
| 281 | 'repeat' => false, |
| 282 | 'repeatcount' => 1, |
| 283 | 'image' => array( |
| 284 | 'local' => '', |
| 285 | 'width' => 0, |
| 286 | 'height' => 0, |
| 287 | 'scale' => 1, |
| 288 | ) |
| 289 | ); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | $notices = array_merge( $notices, $not_activated_notices ); |
| 295 | |
| 296 | return $notices; |
| 297 | } |
| 298 | |
| 299 | public static function get_plugin_count() { |
| 300 | $count = count( self::$plugin_info ); |
| 301 | |
| 302 | return $count; |
| 303 | } |
| 304 | |
| 305 | public static function allow_berocket_host( $allow, $host, $url ) { |
| 306 | if ( $host == 'berocket.com' ) { |
| 307 | $allow = true; |
| 308 | } |
| 309 | |
| 310 | return $allow; |
| 311 | } |
| 312 | |
| 313 | public static function test_keys() { |
| 314 | $wp_nonce = (empty($_GET['wp_nonce']) ? (empty($_POST['wp_nonce']) ? '' : $_POST['wp_nonce']) : $_GET['wp_nonce']); |
| 315 | if ( ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $wp_nonce, 'br_test_keys' ) ) { |
| 316 | echo __( 'Do not have access for this feature', 'BeRocket_domain' ); |
| 317 | wp_die(); |
| 318 | } |
| 319 | $result = array(); |
| 320 | if( ! empty($_POST['keys']) && is_array($_POST['keys']) ) { |
| 321 | $options = self::get_options(); |
| 322 | $check_keys = array(); |
| 323 | foreach($_POST['keys'] as $key) { |
| 324 | if( ! empty($key['key']) ) { |
| 325 | $key_id = intval($key['id']); |
| 326 | if( strpos($key['key'], '********************') === FALSE ) { |
| 327 | $check_keys[] = array( |
| 328 | 'id' => $key_id, |
| 329 | 'key' => sanitize_text_field($key['key']) |
| 330 | ); |
| 331 | } else { |
| 332 | if( $key_id == 0 ) { |
| 333 | if( ! empty($options['account_key']) ) { |
| 334 | $check_keys[] = array( |
| 335 | 'id' => $key_id, |
| 336 | 'key' => sanitize_text_field($options['account_key']) |
| 337 | ); |
| 338 | } |
| 339 | } else { |
| 340 | if( ! empty($options['plugin_key'][$key_id]) ) { |
| 341 | $check_keys[] = array( |
| 342 | 'id' => $key_id, |
| 343 | 'key' => sanitize_text_field($options['plugin_key'][$key_id]) |
| 344 | ); |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | if( count($check_keys) > 0 ) { |
| 351 | $check_plugin_activation = self::check_plugin_activation(false, array('keys' => $check_keys)); |
| 352 | $check_plugin_activation_plugins = $check_plugin_activation['plugins']; |
| 353 | $result = array(); |
| 354 | if( is_array($check_plugin_activation_plugins) ) { |
| 355 | foreach($check_plugin_activation_plugins as $plugin_id => $plugin_data) { |
| 356 | $result[$plugin_id] = ( ! empty($plugin_data) && is_array($plugin_data) && ! empty($plugin_data['status']) ); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | $out = json_encode( $result ); |
| 362 | echo $out; |
| 363 | wp_die(); |
| 364 | } |
| 365 | public static function test_key() { |
| 366 | $wp_nonce = (empty($_GET['wp_nonce']) ? (empty($_POST['wp_nonce']) ? '' : $_POST['wp_nonce']) : $_GET['wp_nonce']); |
| 367 | if ( ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $wp_nonce, 'br_test_key' ) ) { |
| 368 | echo __( 'Do not have access for this feature', 'BeRocket_domain' ); |
| 369 | wp_die(); |
| 370 | } |
| 371 | if ( ! isset( $_POST[ 'key' ] ) || ! isset( $_POST[ 'id' ] ) ) { |
| 372 | $data = array( |
| 373 | 'key_exist' => 0, |
| 374 | 'status' => 'Failed', |
| 375 | 'error' => 'Incorrect query for this function(ID and Key must be sended)' |
| 376 | ); |
| 377 | |
| 378 | $out = json_encode( $data ); |
| 379 | } elseif( strlen($_POST[ 'key' ]) < 35 || strlen($_POST[ 'key' ]) > 45 ) { |
| 380 | $data = array( |
| 381 | 'key_exist' => 0, |
| 382 | 'status' => 'Failed', |
| 383 | 'error' => 'Incorrect query for this function(Incorrect key length)' |
| 384 | ); |
| 385 | |
| 386 | $out = json_encode( $data ); |
| 387 | } else { |
| 388 | $key = sanitize_text_field( $_POST[ 'key' ] ); |
| 389 | $id = sanitize_text_field( $_POST[ 'id' ] ); |
| 390 | $fast = ! empty($_POST[ 'fast' ]); |
| 391 | $site_url = get_site_url(); |
| 392 | $plugins = self::$plugin_info; |
| 393 | if( strpos($key, '**') !== false ) { |
| 394 | if ($id == 0 ) { |
| 395 | $key = self::$key; |
| 396 | } elseif( is_array($plugins) && count($plugins) > 0 ) { |
| 397 | foreach($plugins as $plugin_info) { |
| 398 | if($plugin_info['id'] == $id) { |
| 399 | $key = $plugin_info['key']; |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | |
| 406 | if ( is_array( $plugins ) ) { |
| 407 | $plugins = array_keys( $plugins ); |
| 408 | $plugins = implode( ',', $plugins ); |
| 409 | } else { |
| 410 | $plugins = ''; |
| 411 | } |
| 412 | |
| 413 | $response = wp_remote_post( BeRocket_update_path . 'v1/account_updater', array( |
| 414 | 'body' => array( |
| 415 | 'key' => $key, |
| 416 | 'id' => $id, |
| 417 | 'url' => $site_url, |
| 418 | 'plugins' => $plugins |
| 419 | ), |
| 420 | 'method' => 'POST', |
| 421 | 'timeout' => 30, |
| 422 | 'redirection' => 5, |
| 423 | 'blocking' => true, |
| 424 | 'sslverify' => false |
| 425 | ) ); |
| 426 | |
| 427 | $options = self::get_options(); |
| 428 | if ( ! is_wp_error( $response ) ) { |
| 429 | $out = wp_remote_retrieve_body( $response ); |
| 430 | $current_plugin = false; |
| 431 | $out = json_decode( $out, true ); |
| 432 | |
| 433 | if ( ! is_array( $out ) ) { |
| 434 | $out = array(); |
| 435 | } |
| 436 | |
| 437 | $out[ 'upgrade' ] = array(); |
| 438 | |
| 439 | if( ! $fast ) { |
| 440 | if ( $id != 0 ) { |
| 441 | foreach ( self::$plugin_info as $plugin ) { |
| 442 | if ( $plugin[ 'id' ] == $id ) { |
| 443 | $current_plugin = $plugin; |
| 444 | break; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | if ( $current_plugin !== false ) { |
| 449 | if ( empty( $out[ 'error' ] ) ) { |
| 450 | $options[ 'plugin_key' ][ $id ] = $key; |
| 451 | |
| 452 | if ( isset( $out[ 'versions' ][ $id ] ) && version_compare( $current_plugin[ 'version' ], $out[ 'versions' ][ $id ], '<' ) ) { |
| 453 | $upgrade_button = '<a href="' . wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $current_plugin[ 'plugin' ], 'upgrade-plugin_' . $current_plugin[ 'plugin' ] ) . '" class="button tiny-button">Upgrade plugin</a>'; |
| 454 | $out[ 'upgrade' ][] = array( 'id' => $id, 'upgrade' => $upgrade_button ); |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | } else { |
| 459 | foreach ( self::$plugin_info as $plugin ) { |
| 460 | if ( isset( $out[ 'versions' ][ $plugin[ 'id' ] ] ) && version_compare( $plugin[ 'version' ], $out[ 'versions' ][ $plugin[ 'id' ] ], '<' ) ) { |
| 461 | $upgrade_button = '<a href="' . wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $plugin[ 'plugin' ], 'upgrade-plugin_' . $plugin[ 'plugin' ] ) . '" class="button tiny-button">Upgrade plugin</a>'; |
| 462 | $out[ 'upgrade' ][] = array( |
| 463 | 'id' => $plugin[ 'id' ], |
| 464 | 'upgrade' => $upgrade_button |
| 465 | ); |
| 466 | } |
| 467 | } |
| 468 | $options[ 'account_key' ] = $key; |
| 469 | } |
| 470 | } |
| 471 | $out = json_encode( $out ); |
| 472 | } else { |
| 473 | $data = array( |
| 474 | 'key_exist' => 0, |
| 475 | 'status' => 'Failed', |
| 476 | 'error' => $response->get_error_message() |
| 477 | ); |
| 478 | |
| 479 | $out = json_encode( $data ); |
| 480 | } |
| 481 | if( ! $fast ) { |
| 482 | self::set_options( $options ); |
| 483 | } |
| 484 | } |
| 485 | echo $out; |
| 486 | wp_die(); |
| 487 | } |
| 488 | |
| 489 | public static function scripts() { |
| 490 | ?> |
| 491 | <script> |
| 492 | function BeRocket_key_check(key, show_correct, product_id, async_func, fast) { |
| 493 | if (typeof( product_id ) == 'undefined' || product_id == null) { |
| 494 | product_id = 0; |
| 495 | } |
| 496 | if (typeof( async_func ) == 'undefined' || async_func == null) { |
| 497 | async_func = false; |
| 498 | } |
| 499 | if (typeof( fast ) == 'undefined' || fast == null) { |
| 500 | fast = 0; |
| 501 | } |
| 502 | var async = false; |
| 503 | if( async_func !== false ) { |
| 504 | async = true; |
| 505 | } |
| 506 | data = {action: 'br_test_key', key: key, id: product_id, fast:fast, wp_nonce: "<?php echo wp_create_nonce('br_test_key'); ?>"}; |
| 507 | is_submit = false; |
| 508 | jQuery.ajax({ |
| 509 | url: ajaxurl, |
| 510 | data: data, |
| 511 | type: 'POST', |
| 512 | success: function (data) { |
| 513 | jQuery('.berocket_test_result').html(data); |
| 514 | if (data.key_exist == 1) { |
| 515 | if (show_correct) { |
| 516 | html = '<h3>' + data.status + '</h3>'; |
| 517 | jQuery('.berocket_test_result').html(html); |
| 518 | data.upgrade.forEach(function (el, i, arr) { |
| 519 | jQuery('.berocket_product_key_' + el.id + '_status').html(el.upgrade); |
| 520 | }); |
| 521 | } |
| 522 | is_submit = true; |
| 523 | } else { |
| 524 | if (show_correct) { |
| 525 | html = '<h3>' + data.status + '</h3>'; |
| 526 | html += '<p><b>Error message:</b>' + data.error + '</p>'; |
| 527 | jQuery('.berocket_test_result').html(html); |
| 528 | } |
| 529 | } |
| 530 | jQuery('.berocket_product_key_' + product_id + '_status').text(data.status); |
| 531 | if( ! data.key_exist ) { |
| 532 | jQuery('#berocket_product_key_' + product_id).val(''); |
| 533 | } |
| 534 | if( typeof(async_func) == 'function' ) { |
| 535 | async_func(is_submit); |
| 536 | } |
| 537 | }, |
| 538 | dataType: 'json', |
| 539 | async: async |
| 540 | }); |
| 541 | return is_submit; |
| 542 | } |
| 543 | jQuery(document).on('click', '.berocket_test_account_product', function (event) { |
| 544 | event.preventDefault(); |
| 545 | if (jQuery(this).data('product')) { |
| 546 | key = jQuery(jQuery(this).data('product')).val(); |
| 547 | } else { |
| 548 | key = jQuery('#berocket_product_key').val(); |
| 549 | } |
| 550 | BeRocket_key_check(key, true, jQuery(this).data('id')); |
| 551 | }); |
| 552 | </script> |
| 553 | <style> |
| 554 | .toplevel_page_berocket_account .dashicons-before img { |
| 555 | max-width: 16px; |
| 556 | } |
| 557 | </style> |
| 558 | <?php |
| 559 | } |
| 560 | |
| 561 | public static function network_account_page() { |
| 562 | add_menu_page( __('BeRocket Account Settings', 'BeRocket_domain'), __('BeRocket Account', 'BeRocket_domain'), 'manage_berocket', 'berocket_account', array( |
| 563 | __CLASS__, |
| 564 | 'account_form_network' |
| 565 | ), plugin_dir_url( __FILE__ ) . 'ico.png', '55.55' ); |
| 566 | } |
| 567 | |
| 568 | public static function main_menu_item() { |
| 569 | add_menu_page( 'BeRocket Account', 'BeRocket', 'manage_berocket', 'berocket_account', array( |
| 570 | __CLASS__, |
| 571 | 'account_form' |
| 572 | ), plugin_dir_url( __FILE__ ) . 'ico.png', '55.55' ); |
| 573 | } |
| 574 | |
| 575 | public static function account_page() { |
| 576 | add_submenu_page( 'berocket_account', __('BeRocket Account Settings', 'BeRocket_domain'), __('Setting & Keys', 'BeRocket_domain'), 'manage_berocket_account', 'berocket_account', array( |
| 577 | __CLASS__, |
| 578 | 'account_form' |
| 579 | ) ); |
| 580 | } |
| 581 | |
| 582 | public static function account_option_register() { |
| 583 | register_setting( 'BeRocket_account_option_settings', 'BeRocket_account_option', array('sanitize_callback' => array(__CLASS__, 'reset_update_plugin_data')) ); |
| 584 | } |
| 585 | |
| 586 | public static function reset_update_plugin_data($options) { |
| 587 | $options = self::restore_keys($options); |
| 588 | self::update_check_set(''); |
| 589 | delete_site_transient( 'update_plugins' ); |
| 590 | delete_transient('berocket_plugin_paid_info'); |
| 591 | return $options; |
| 592 | } |
| 593 | |
| 594 | public static function account_form() { |
| 595 | wp_enqueue_style( 'berocket_framework_admin_style' ); |
| 596 | ?> |
| 597 | <div class="wrap"> |
| 598 | <form method="post" action="options.php" class="account_key_send br_framework_settings"> |
| 599 | <?php |
| 600 | $options = BeRocket_Framework::get_global_option(); |
| 601 | self::inside_form( $options ); |
| 602 | ?> |
| 603 | </form> |
| 604 | <?php do_action('BeRocket_framework_updater_account_form_after', self::$plugin_info); ?> |
| 605 | </div> |
| 606 | <?php |
| 607 | } |
| 608 | |
| 609 | public static function account_form_network() { |
| 610 | ?> |
| 611 | <div class="wrap"> |
| 612 | <form method="post" action="edit.php?page=berocket_account" class="account_key_send br_framework_settings"> |
| 613 | <?php |
| 614 | if ( isset( $_POST[ 'BeRocket_account_option' ] ) ) { |
| 615 | $previous_options = BeRocket_Framework::get_global_option(true); |
| 616 | $option = berocket_sanitize_array( $_POST[ 'BeRocket_account_option' ], array('BeRocket_account_option'), $previous_options ); |
| 617 | BeRocket_Framework::save_global_option($option, true); |
| 618 | self::update_check_set(''); |
| 619 | delete_site_transient( 'update_plugins' ); |
| 620 | delete_transient('berocket_plugin_paid_info'); |
| 621 | } |
| 622 | |
| 623 | $options = BeRocket_Framework::get_global_option(true); |
| 624 | self::inside_form( $options ); |
| 625 | ?> |
| 626 | </form> |
| 627 | </div> |
| 628 | <?php |
| 629 | } |
| 630 | |
| 631 | public static function inside_form( $options ) { |
| 632 | settings_fields( 'BeRocket_account_option_settings' ); |
| 633 | if ( isset( $options[ 'plugin_key' ] ) && is_array( $options[ 'plugin_key' ] ) ) { |
| 634 | $plugins_key = $options[ 'plugin_key' ]; |
| 635 | } else { |
| 636 | $plugins_key = array(); |
| 637 | } |
| 638 | $has_free = false; |
| 639 | foreach(self::$plugin_info as $plugin) { |
| 640 | if( $plugin['version_capability'] < 10 ) { |
| 641 | $has_free = true; |
| 642 | } |
| 643 | } |
| 644 | if( $has_free ) { |
| 645 | if ( time() > 1637841600 and time() < 1637841600+302400 ) { |
| 646 | echo " |
| 647 | <div class='berocket-above-settings-banner' style='background: #1a1a1a; padding: 0;'> |
| 648 | <a href='https://berocket.com/products?utm_source=free_plugin&utm_medium=settings&utm_campaign=account_keys&utm_content=top' target='_blank' |
| 649 | style='background: transparent; width: auto; border: 0 none; box-shadow: none; padding: 0; margin: 0;'> |
| 650 | <img alt='BeRocket Products' src='https://berocket.ams3.cdn.digitaloceanspaces.com/g/bf21-1202x280.jpg' style='display: block;'> |
| 651 | </a> |
| 652 | </div>"; |
| 653 | } else if ( time() > 1637841600+302400 and time() < 1637841600+302400+518400 ) { |
| 654 | echo " |
| 655 | <div class='berocket-above-settings-banner berocket-cm21-settings-wrapper' style='background: #07002e; padding: 0;'> |
| 656 | <a href='https://berocket.com/products?utm_source=free_plugin&utm_medium=settings&utm_campaign=account_keys&utm_content=top' target='_blank' > |
| 657 | <img alt='BeRocket Products' src='https://berocket.ams3.cdn.digitaloceanspaces.com/g/cm21.jpg'> |
| 658 | <div class='berocket-cm21-settings'> |
| 659 | <div class='berocket-cm21-settings-header'> |
| 660 | <p>Don't lose another 5% of the discount. Purchase now!</p> |
| 661 | </div> |
| 662 | <p style='top: 30%; left: 6%; '><span>Monday: <span style='padding-left: 20px; font-size: 1.25em; font-weight: bold;'>-30%</span></span></p> |
| 663 | <p style='top: 32%; left: 55%;'><span>Tuesday: <span style='padding-left: 15px; font-size: 1.2em; font-weight: bold;'>-25%</span></span></p> |
| 664 | <p style='top: 48%; left: 10%;'><span>Wednesday: <span style='padding-left: 5px; font-size: 1.15em'>-20%</span></span></p> |
| 665 | <p style='top: 50%; left: 59%;'><span>Thursday: <span style='padding-left: 10px; font-size: 1.1em'>-15%</span></span></p> |
| 666 | <p style='top: 66%; left: 16%;'><span>Friday: <span style='padding-left: 20px; font-size: 0.9em'>-10%</span></span></p> |
| 667 | <p style='top: 68%; left: 63%;'><span>Saturday: <span style='padding-left: 15px; font-size: 0.9em'>-5%</span></span></p> |
| 668 | </div> |
| 669 | <div class='berocket-cm21-settings-mobiles-title' style='display: none;'>Up to 30% off sitewide!</div> |
| 670 | </a> |
| 671 | </div>"; |
| 672 | } |
| 673 | } |
| 674 | ?> |
| 675 | <h2><?php _e('BeRocket Account Settings', 'BeRocket_domain'); ?></h2> |
| 676 | <div> |
| 677 | <table> |
| 678 | <tr<?php if(empty( $options[ 'account_key' ] )) { echo ' style="display:none!important;"';}?>> |
| 679 | <td><h3><?php _e('Account key', 'BeRocket_domain'); ?></h3></td> |
| 680 | <td><input type="text" id="berocket_account_key" name="BeRocket_account_option[account_key]" |
| 681 | size="50" |
| 682 | value="<?php echo( empty( $options[ 'account_key' ] ) ? '' : self::hide_key($options[ 'account_key' ]) ) ?>"> |
| 683 | </td> |
| 684 | <td><input class="berocket_test_account button tiny-button" type="button" value="Test"></td> |
| 685 | <td class="berocket_product_key_0_status"></td> |
| 686 | </tr> |
| 687 | <?php |
| 688 | foreach ( self::$plugin_info as $plugin ) { |
| 689 | echo '<tr class="berocket_updater_plugin_key" data-id="', $plugin[ 'id' ], '">'; |
| 690 | echo '<td><h4>'; |
| 691 | if ( isset( $plugin[ 'name' ] ) ) { |
| 692 | echo $plugin[ 'name' ]; |
| 693 | } else { |
| 694 | echo $plugin[ 'slug' ]; |
| 695 | } |
| 696 | echo '</h4></td>'; |
| 697 | echo '<td><input class="berocket_test_account_product_key" id="berocket_product_key_', $plugin[ 'id' ], '" size="50" name="BeRocket_account_option[plugin_key][', $plugin[ 'id' ], ']" type="text" value="', ( empty( $options[ 'plugin_key' ][ $plugin[ 'id' ] ] ) ? '' : self::hide_key($options[ 'plugin_key' ][ $plugin[ 'id' ] ]) ), '"></td>'; |
| 698 | echo '<td><input class="berocket_test_account_product save_checked button tiny-button" data-id="', $plugin[ 'id' ], '" data-product="#berocket_product_key_', $plugin[ 'id' ], '" type="button" value="Test"></td>'; |
| 699 | echo '<td class="berocket_product_key_status berocket_product_key_', $plugin[ 'id' ], '_status"></td>'; |
| 700 | echo '</tr>'; |
| 701 | unset( $plugins_key[ $plugin[ 'id' ] ] ); |
| 702 | } |
| 703 | foreach ( $plugins_key as $key_id => $key_val ) { |
| 704 | echo '<input name="BeRocket_account_option[plugin_key][', $key_id, ']" type="hidden" value="', $key_val, '">'; |
| 705 | } |
| 706 | ?> |
| 707 | </table> |
| 708 | </div> |
| 709 | <div class="berocket_test_result"></div> |
| 710 | <h2><?php _e('Troubleshooting & Tools', 'BeRocket_domain'); ?></h2> |
| 711 | <div> |
| 712 | <table> |
| 713 | <tr> |
| 714 | <td><h3><?php _e('DEBUG MODE', 'BeRocket_domain'); ?></h3></td> |
| 715 | <td colspan=3><label><input type="checkbox" name="BeRocket_account_option[debug_mode]" |
| 716 | value="1"<?php if ( ! empty( $options[ 'debug_mode' ] ) ) |
| 717 | echo ' checked' ?>><?php _e('Enable debug mode', 'BeRocket_domain'); ?></label></td> |
| 718 | </tr> |
| 719 | <tr> |
| 720 | <td><h3><?php _e('Products per page', 'BeRocket_domain'); ?></h3></td> |
| 721 | <td colspan=3><input type="number" name="BeRocket_account_option[framework_products_per_page]" value="<?php echo (empty($options['framework_products_per_page']) ? '' : $options['framework_products_per_page']); ?>" placeholder="<?php _e('From WooCommerce', 'BeRocket_domain'); ?>"></td> |
| 722 | </tr> |
| 723 | <tr> |
| 724 | <td><h3><?php _e('Admin bar status', 'BeRocket_domain'); ?></h3></td> |
| 725 | <td colspan=3><select name="BeRocket_account_option[disable_admin_bar_panel]"> |
| 726 | <option value="enable"<?php |
| 727 | if( ! empty($options['disable_admin_bar_panel']) && $options['disable_admin_bar_panel'] == 'enable' ) echo ' selected'; |
| 728 | ?>><?php _e('Enable', 'BeRocket_domain') ?></option> |
| 729 | <option value="disable"<?php |
| 730 | if( ! empty($options['disable_admin_bar_panel']) && $options['disable_admin_bar_panel'] == 'disable' ) echo ' selected'; |
| 731 | ?>><?php _e('Disable', 'BeRocket_domain') ?></option> |
| 732 | </select><?php _e('Enable panel in WordPress Admin Bar', 'BeRocket_domain'); ?></td> |
| 733 | </tr> |
| 734 | <tr> |
| 735 | <td><h3><?php _e('Disable Font Awesome', 'BeRocket_domain'); ?></h3></td> |
| 736 | <td colspan=3><label><input type="checkbox" name="BeRocket_account_option[fontawesome_frontend_disable]" |
| 737 | value="1"<?php if ( ! empty( $options[ 'fontawesome_frontend_disable' ] ) ) |
| 738 | echo ' checked' ?>><?php _e('Don\'t load CSS files for Font Awesome on the site\'s front end. Use it only if you don\'t use Font Awesome icons in widgets or have Font Awesome in your theme.', 'BeRocket_domain'); ?></label></td> |
| 739 | </tr> |
| 740 | <tr> |
| 741 | <td><h3><?php _e('Font Awesome Version', 'BeRocket_domain'); ?></h3></td> |
| 742 | <td colspan=3><select name="BeRocket_account_option[fontawesome_frontend_version]"> |
| 743 | <option value=""<?php |
| 744 | if( empty($options['fontawesome_frontend_version']) ) echo ' selected'; |
| 745 | ?>><?php _e('Enable', 'BeRocket_domain') ?></option> |
| 746 | <option value="fontawesome5"<?php |
| 747 | if( ! empty($options['fontawesome_frontend_version']) && $options['fontawesome_frontend_version'] == 'fontawesome5' ) echo ' selected'; |
| 748 | ?>><?php _e('Font Awesome 5', 'BeRocket_domain') ?></option> |
| 749 | </select></td> |
| 750 | </tr> |
| 751 | </table> |
| 752 | </div> |
| 753 | <button type="submit" class="button"><?php _e('Save Changes', 'BeRocket_domain'); ?></button> |
| 754 | |
| 755 | <div class="berocket_debug_errors"> |
| 756 | <h3><?php _e('Errors', 'BeRocket_domain'); ?></h3> |
| 757 | <div> |
| 758 | <?php _e('Select plugin', 'BeRocket_domain'); ?> |
| 759 | <select class="berocket_select_plugin_for_error"> |
| 760 | <?php |
| 761 | foreach ( self::$plugin_info as $plugin ) { |
| 762 | echo '<option value="' . $plugin[ 'id' ] . '">' . $plugin[ 'name' ] . '</option>'; |
| 763 | } |
| 764 | ?> |
| 765 | </select> |
| 766 | <button type="button" class="button tiny-button berocket_get_plugin_for_error" data-nonce="<?php echo wp_create_nonce('berocket_error_notices_get'); ?>">Get errors</button> |
| 767 | <div class="berocket_html_plugin_for_error"></div> |
| 768 | </div> |
| 769 | </div> |
| 770 | <script> |
| 771 | jQuery('.berocket_get_plugin_for_error').click(function () { |
| 772 | var plugin_id = jQuery('.berocket_select_plugin_for_error').val(); |
| 773 | var nonce = jQuery(this).data("nonce"); |
| 774 | jQuery.post(ajaxurl, {action: 'berocket_error_notices_get', plugin_id: plugin_id, wp_nonce: nonce}, function (data) { |
| 775 | jQuery('.berocket_html_plugin_for_error').html(data); |
| 776 | }); |
| 777 | }); |
| 778 | jQuery('.berocket_test_account').click(function (event) { |
| 779 | event.preventDefault(); |
| 780 | key = jQuery('#berocket_account_key').val(); |
| 781 | BeRocket_key_check(key, true); |
| 782 | }); |
| 783 | jQuery(document).on('change', '.berocket_test_account_product_key', function() { |
| 784 | jQuery(this).parents('.berocket_updater_plugin_key').find('.berocket_test_account_product').removeClass('save_checked'); |
| 785 | }); |
| 786 | var berocket_key_checked = 0; |
| 787 | var berocket_key_count = 1; |
| 788 | function next_berocket_key_check(result) { |
| 789 | berocket_key_checked = berocket_key_count - jQuery('.berocket_test_account_product:not(.save_checked), #berocket_account_key:not(.save_checked)').length; |
| 790 | var button = jQuery('.account_key_send .button[type="submit"]'); |
| 791 | var element = jQuery('.berocket_test_account_product:not(.save_checked)').first(); |
| 792 | if( element.length ) { |
| 793 | button.html('Checking keys '+berocket_key_checked+' / '+berocket_key_count+' <i class="fa fa-refresh fa-spin"></i>'); |
| 794 | |
| 795 | if (element.data('product')) { |
| 796 | key_element = jQuery(element.data('product')); |
| 797 | } else { |
| 798 | key_element = jQuery('#berocket_product_key'); |
| 799 | } |
| 800 | key = key_element.val(); |
| 801 | element.addClass('save_checked'); |
| 802 | var is_correct = BeRocket_key_check(key, false, element.data('id'), next_berocket_key_check, 1); |
| 803 | } else { |
| 804 | button.html('Saving keys <i class="fa fa-refresh fa-spin"></i>'); |
| 805 | jQuery('.account_key_send').trigger('submit'); |
| 806 | } |
| 807 | } |
| 808 | var br_key_checked_before_send = 0; |
| 809 | jQuery(document).on('submit', '.account_key_send', function (event) { |
| 810 | if( br_key_checked_before_send < 2 ) { |
| 811 | event.preventDefault(); |
| 812 | } |
| 813 | if( br_key_checked_before_send < 1 ) { |
| 814 | br_key_checked_before_send = 1; |
| 815 | jQuery('.account_key_send .button[type="submit"]').html('Checking keys <i class="fa fa-refresh fa-spin"></i>'); |
| 816 | if( ! jQuery('#berocket_account_key').val() ) { |
| 817 | jQuery('#berocket_account_key').addClass('save_checked'); |
| 818 | } |
| 819 | var keys = []; |
| 820 | var account_key = jQuery('#berocket_account_key').val(); |
| 821 | if( account_key ) { |
| 822 | keys.push({id:'0', key:account_key}); |
| 823 | } |
| 824 | jQuery('.berocket_updater_plugin_key').each(function() { |
| 825 | var plugin_key = jQuery(this).find('.berocket_test_account_product_key').val(); |
| 826 | if( plugin_key ) { |
| 827 | keys.push({id: jQuery(this).data('id'), key: plugin_key}); |
| 828 | } |
| 829 | }); |
| 830 | data = {action: 'br_test_keys', keys: keys, wp_nonce: "<?php echo wp_create_nonce('br_test_keys'); ?>"}; |
| 831 | jQuery.ajax({ |
| 832 | url: ajaxurl, |
| 833 | data: data, |
| 834 | type: 'POST', |
| 835 | success: function (data) { |
| 836 | jQuery.each(data, function(plugin_id) { |
| 837 | if( this == true ) { |
| 838 | jQuery('.berocket_product_key_' + plugin_id + '_status').html('Success'); |
| 839 | } else { |
| 840 | jQuery('.berocket_product_key_' + plugin_id + '_status').html('Failed'); |
| 841 | if( plugin_id == 0 ) { |
| 842 | jQuery('#berocket_account_key').val(''); |
| 843 | } else { |
| 844 | jQuery('#berocket_product_key_' + plugin_id).val(''); |
| 845 | } |
| 846 | } |
| 847 | }); |
| 848 | br_key_checked_before_send = 2; |
| 849 | jQuery('.account_key_send .button[type="submit"]').html('Saving keys <i class="fa fa-refresh fa-spin"></i>'); |
| 850 | jQuery('.account_key_send').trigger('submit'); |
| 851 | }, |
| 852 | dataType: 'json' |
| 853 | }); |
| 854 | } |
| 855 | }); |
| 856 | </script> |
| 857 | <style>.notice:not(.berocket_admin_notice){display:none!important;}</style> |
| 858 | <?php |
| 859 | } |
| 860 | |
| 861 | public static function check_plugin_activation($plugin_test_id = false, $data_send = false) { |
| 862 | $options = self::get_options(); |
| 863 | $active = false; |
| 864 | if( ! empty($options) && is_array($options) && ! empty($options['plugin_key']) && is_array($options['plugin_key']) ) { |
| 865 | $disable_cache = false; |
| 866 | if( $data_send === false ) { |
| 867 | $data_send = array( |
| 868 | 'keys' => array() |
| 869 | ); |
| 870 | if( ! empty($options['account_key']) ) { |
| 871 | $data_send['keys'][] = array( |
| 872 | 'id' => '0', |
| 873 | 'key' => $options['account_key'] |
| 874 | ); |
| 875 | } |
| 876 | foreach(self::$plugin_info as $plugin_data) { |
| 877 | if( ! empty($plugin_data['key']) ) { |
| 878 | $data_send['keys'][] = array( |
| 879 | 'id' => $plugin_data['id'], |
| 880 | 'key' => $plugin_data['key'] |
| 881 | ); |
| 882 | } |
| 883 | } |
| 884 | $keys_hash = md5(print_r($data_send, true)).'v2'; |
| 885 | $plugin_activation = get_transient( 'br_plugin_activation' ); |
| 886 | } else { |
| 887 | $keys_hash = ''; |
| 888 | $disable_cache = true; |
| 889 | } |
| 890 | if( empty($plugin_activation) || ! is_array($plugin_activation) |
| 891 | || empty($plugin_activation['hash']) || $plugin_activation['hash'] != $keys_hash ) { |
| 892 | $plugin_activation = array( |
| 893 | 'hash' => $keys_hash, |
| 894 | 'plugins' => array() |
| 895 | ); |
| 896 | if( count($data_send['keys']) > 0 ) { |
| 897 | $url = BeRocket_update_path . 'v1/check_plugin_key/'; |
| 898 | $response = wp_remote_post( $url, array( |
| 899 | 'body' => $data_send, |
| 900 | 'method' => 'POST', |
| 901 | 'timeout' => 30, |
| 902 | 'redirection' => 5, |
| 903 | 'blocking' => true, |
| 904 | 'sslverify' => false |
| 905 | ) ); |
| 906 | if ( ! is_wp_error( $response ) ) { |
| 907 | $out = wp_remote_retrieve_body( $response ); |
| 908 | if ( ! empty( $out ) ) { |
| 909 | $out = json_decode( @ $out ); |
| 910 | if( is_array($out) ) { |
| 911 | foreach($out as $key_status) { |
| 912 | if( isset($key_status->id) && $key_status->id == 0 ) { |
| 913 | if( ! empty($key_status->products) && is_array($key_status->products) ) { |
| 914 | $plugin_activation['plugins'][0] = true; |
| 915 | foreach($key_status->products as $product_id) { |
| 916 | $plugin_activation['plugins'][intval($product_id)] = array( |
| 917 | 'status' => true, |
| 918 | 'license' => 'paid' |
| 919 | ); |
| 920 | } |
| 921 | } else { |
| 922 | $plugin_activation['plugins'][0] = false; |
| 923 | } |
| 924 | } elseif( ! empty($key_status->id) ) { |
| 925 | $plugin_activation['plugins'][intval($key_status->id)] = array( |
| 926 | 'status' => ! empty($key_status->status), |
| 927 | 'license' => ( empty($key_status->license) ? 'paid' : $key_status->license ) |
| 928 | ); |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | if( ! $disable_cache ) { |
| 936 | set_transient( 'br_plugin_activation', $plugin_activation, 604800 ); |
| 937 | } |
| 938 | } |
| 939 | if( $plugin_test_id === false ) { |
| 940 | $active = $plugin_activation; |
| 941 | } else { |
| 942 | if (! empty($plugin_activation['plugins']) && is_array($plugin_activation['plugins']) && isset($plugin_activation['plugins'][$plugin_test_id])) { |
| 943 | $active = $plugin_activation['plugins'][$plugin_test_id]; |
| 944 | } |
| 945 | } |
| 946 | } |
| 947 | return $active; |
| 948 | } |
| 949 | |
| 950 | public static function update_check_set( $value ) { |
| 951 | $no_update_paid = array(); |
| 952 | |
| 953 | foreach ( self::$plugin_info as $plugin ) { |
| 954 | $check_plugin_activation = self::check_plugin_activation($plugin[ 'id' ]); |
| 955 | $is_active = ( ! empty($check_plugin_activation) && is_array($check_plugin_activation) && ! empty($check_plugin_activation['status']) ); |
| 956 | $license_key_name = ( is_array($check_plugin_activation) && ! empty($check_plugin_activation['license']) ? $check_plugin_activation['license'] : 'paid' ); |
| 957 | $plugin_data = BeRocket_Framework::get_product_data_berocket($plugin[ 'id' ]); |
| 958 | $plugin_licenses = apply_filters('brfr_plugin_get_licenses_current_id_' . $plugin[ 'id' ], array('free')); |
| 959 | if ( ! empty( self::$key ) && strlen( self::$key ) == 40 ) { |
| 960 | $key = self::$key; |
| 961 | } |
| 962 | if ( ! empty( $plugin[ 'key' ] ) && strlen( $plugin[ 'key' ] ) == 40 ) { |
| 963 | $key = $plugin[ 'key' ]; |
| 964 | } |
| 965 | |
| 966 | $responsed = false; |
| 967 | if ( $is_active && ! empty($plugin_data) && is_array($plugin_data) && is_array($plugin) && isset($plugin_data['version']) |
| 968 | && ( version_compare( (string)$plugin[ 'version' ], (string)$plugin_data['version'], '<' ) || ! in_array($license_key_name, $plugin_licenses) ) && ! empty($value) ) { |
| 969 | $value->checked[ $plugin[ 'plugin' ] ] = $plugin_data['version']; |
| 970 | $val = array( |
| 971 | 'id' => 'br_' . $plugin[ 'id' ], |
| 972 | 'new_version' => $plugin_data['version'] . '(' . $license_key_name . ')', |
| 973 | 'package' => BeRocket_update_path . 'v1/update_product/' . $plugin[ 'id' ] . '/' . $key, |
| 974 | 'url' => BeRocket_cdn_path . 'product/' . $plugin[ 'slug' ], |
| 975 | 'plugin' => $plugin[ 'plugin' ], |
| 976 | 'slug' => $plugin[ 'slug' ] |
| 977 | ); |
| 978 | if( ! empty($plugin['free_slug']) ) { |
| 979 | if( ! empty($value->response[ $plugin[ 'plugin' ] ]) ) { |
| 980 | $api = $value->response[ $plugin[ 'plugin' ] ]; |
| 981 | } else { |
| 982 | include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
| 983 | $api = get_transient( 'br_plugin_api_' . $plugin['free_slug'] ); |
| 984 | if( empty($api) ) { |
| 985 | $api = plugins_api( 'plugin_information', array( |
| 986 | 'slug' => wp_unslash( $plugin['free_slug'] ), |
| 987 | 'is_ssl' => is_ssl(), |
| 988 | 'fields' => array( |
| 989 | 'banners' => true, |
| 990 | 'reviews' => false, |
| 991 | 'downloaded' => false, |
| 992 | 'active_installs' => true, |
| 993 | 'icons' => true |
| 994 | ) |
| 995 | ) ); |
| 996 | set_transient( 'br_plugin_api_' . $plugin['free_slug'], $api, 604800 ); |
| 997 | } |
| 998 | } |
| 999 | $api = (array)$api; |
| 1000 | $val = array_merge($api, $val); |
| 1001 | } |
| 1002 | if( isset($val['upgrade_notice']) && ! is_string($val['upgrade_notice']) ) { |
| 1003 | $val['upgrade_notice'] = ''; |
| 1004 | } |
| 1005 | $val = (object)$val; |
| 1006 | $value->response[ $plugin[ 'plugin' ] ] = $val; |
| 1007 | |
| 1008 | $responsed = true; |
| 1009 | } |
| 1010 | if( ! $responsed && isset($plugin[ 'version_capability' ]) && $plugin[ 'version_capability' ] >= 10 ) { |
| 1011 | $val = (object) array( |
| 1012 | 'id' => 'br_' . $plugin[ 'id' ], |
| 1013 | 'new_version' => $plugin[ 'version' ], |
| 1014 | 'package' => BeRocket_update_path . 'v1/update_product/' . $plugin[ 'id' ] . '/' . ( empty($key) ? 'none' : $key ), |
| 1015 | 'url' => BeRocket_cdn_path . 'product/' . $plugin[ 'slug' ], |
| 1016 | 'plugin' => $plugin[ 'plugin' ], |
| 1017 | 'slug' => $plugin[ 'slug' ] |
| 1018 | ); |
| 1019 | $no_update_paid[$plugin[ 'plugin' ]] = $val; |
| 1020 | } |
| 1021 | } |
| 1022 | if ( ! empty($value) && isset( $value->no_update ) && is_array( $value->no_update ) ) { |
| 1023 | $value->no_update = array_merge($value->no_update, $no_update_paid); |
| 1024 | foreach ( $value->no_update as $key => $val ) { |
| 1025 | if ( isset( $val->slug ) && in_array( $val->slug, self::$slugs ) ) { |
| 1026 | if( ! array_key_exists($key, $no_update_paid) ) { |
| 1027 | unset( $value->no_update[ $key ] ); |
| 1028 | } |
| 1029 | } |
| 1030 | if ( isset( $val->slug ) && in_array( $val->slug, self::$free_slugs ) ) { |
| 1031 | if( ! array_key_exists($key, $no_update_paid) ) { |
| 1032 | unset( $value->no_update[ $key ] ); |
| 1033 | } |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | if ( ! empty($value) && isset( $value->response ) && is_array( $value->response ) ) { |
| 1038 | foreach ( $value->response as $key => $val ) { |
| 1039 | if( array_key_exists($key, $no_update_paid) ) { |
| 1040 | unset( $value->response[ $key ] ); |
| 1041 | } |
| 1042 | } |
| 1043 | } |
| 1044 | return $value; |
| 1045 | } |
| 1046 | |
| 1047 | public static function get_options() { |
| 1048 | if ( ! function_exists( 'is_plugin_active_for_network' ) ) { |
| 1049 | require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 1050 | } |
| 1051 | |
| 1052 | $multisite = (is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ); |
| 1053 | $options = BeRocket_Framework::get_global_option($multisite); |
| 1054 | |
| 1055 | if( empty($options) || ! is_array($options) ) { |
| 1056 | $options = array(); |
| 1057 | } |
| 1058 | |
| 1059 | return $options; |
| 1060 | } |
| 1061 | |
| 1062 | public static function set_options( $options ) { |
| 1063 | if ( ! function_exists( 'is_plugin_active_for_network' ) ) { |
| 1064 | require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 1065 | } |
| 1066 | |
| 1067 | $options = self::restore_keys($options); |
| 1068 | $multisite = ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ); |
| 1069 | BeRocket_Framework::save_global_option($options, $multisite); |
| 1070 | if ( $multisite ) { |
| 1071 | delete_site_transient('br_plugin_activation'); |
| 1072 | } else { |
| 1073 | delete_transient('br_plugin_activation'); |
| 1074 | } |
| 1075 | delete_transient('berocket_plugin_paid_info'); |
| 1076 | self::update_check_set(''); |
| 1077 | delete_site_transient( 'update_plugins' ); |
| 1078 | } |
| 1079 | public static function admin_notice_is_display_notice($display_notice, $item, $search_data) { |
| 1080 | if( ! $display_notice ) { |
| 1081 | return $display_notice; |
| 1082 | } |
| 1083 | if( ! empty($item['conditions']) && is_array($item['conditions']) |
| 1084 | && isset($item['conditions']['plugin_version_capability']) && isset($item['conditions']['plugin_id']) ) { |
| 1085 | $from = min($item['conditions']['plugin_version_capability']); |
| 1086 | $to = max($item['conditions']['plugin_version_capability']); |
| 1087 | $plugin_exist = false; |
| 1088 | foreach ( self::$plugin_info as $plugin ) { |
| 1089 | if ( $plugin[ 'id' ] == $item['conditions']['plugin_id'] ) { |
| 1090 | $display_notice = ($plugin['version_capability'] >= $from && $plugin['version_capability'] < $to); |
| 1091 | $plugin_exist = true; |
| 1092 | break; |
| 1093 | } |
| 1094 | } |
| 1095 | if( ! $plugin_exist ) { |
| 1096 | $display_notice = false; |
| 1097 | } |
| 1098 | } |
| 1099 | return $display_notice; |
| 1100 | } |
| 1101 | |
| 1102 | public static function woocommerce_addons_sections($sections) { |
| 1103 | $sections[] = (object)array( |
| 1104 | 'slug' => 'berocket', |
| 1105 | 'label' => 'BeRocket' |
| 1106 | ); |
| 1107 | return $sections; |
| 1108 | } |
| 1109 | public static function woocommerce_addons_berocket() { |
| 1110 | $addons = array(); |
| 1111 | $products = BeRocket_Framework::get_product_data_berocket(); |
| 1112 | if( ! empty($products) && is_array($products) ) { |
| 1113 | foreach($products as $product) { |
| 1114 | $addons[] = (object)array( |
| 1115 | 'title' => $product->name, |
| 1116 | 'image' => $product->mini_image, |
| 1117 | 'excerpt' => $product->about, |
| 1118 | 'link' => $product->plugin_url, |
| 1119 | 'price' => '$'.$product->price, |
| 1120 | 'hash' => '', |
| 1121 | 'slug' => $product->slug |
| 1122 | ); |
| 1123 | } |
| 1124 | } |
| 1125 | if(! empty($_GET['search']) ) { |
| 1126 | $correct_addon = array(); |
| 1127 | $search = isset( $_GET['search'] ) ? sanitize_text_field( wp_unslash( $_GET['search'] ) ) : ''; |
| 1128 | foreach($addons as $addon) { |
| 1129 | if( stripos($addon->title, $search) !== FALSE || stripos($addon->excerpt, $search) !== FALSE ) { |
| 1130 | $correct_addon[] = $addon; |
| 1131 | } |
| 1132 | } |
| 1133 | $addons = $correct_addon; |
| 1134 | } |
| 1135 | ?> |
| 1136 | <ul class="berocket_section_wc_addons" style="display: none;"> |
| 1137 | <?php foreach ( $addons as $addon ) : ?> |
| 1138 | <li class="product"> |
| 1139 | <a href="<?php echo esc_attr( $addon->link ); ?>"> |
| 1140 | <?php if ( ! empty( $addon->image ) ) : ?> |
| 1141 | <span class="product-img-wrap"><img src="<?php echo esc_url( $addon->image ); ?>"/></span> |
| 1142 | <?php else : ?> |
| 1143 | <h2><?php echo esc_html( $addon->title ); ?></h2> |
| 1144 | <?php endif; ?> |
| 1145 | <span class="price"><?php echo wp_kses_post( $addon->price ); ?></span> |
| 1146 | <p><?php echo wp_kses_post( $addon->excerpt ); ?></p> |
| 1147 | </a> |
| 1148 | </li> |
| 1149 | <?php endforeach; ?> |
| 1150 | </ul> |
| 1151 | <ul class="berocket_section_wc_addons_new" style="display: none;"> |
| 1152 | <?php |
| 1153 | $class_names = array( 'product' ); |
| 1154 | $product_details_classes = 'product-details'; |
| 1155 | foreach( $addons as $addon ) { |
| 1156 | ?> |
| 1157 | <li class="<?php echo esc_attr( implode( ' ', $class_names ) ); ?>"> |
| 1158 | <div class="<?php echo esc_attr( $product_details_classes ); ?>"> |
| 1159 | <div class="product-text-container"> |
| 1160 | <a href="<?php echo esc_url( self::link_marketplace($addon->link) ); ?>"> |
| 1161 | <h2><?php echo esc_html( $addon->title ); ?></h2> |
| 1162 | </a> |
| 1163 | <div class="product-developed-by"> |
| 1164 | <?php |
| 1165 | $vendor_url = self::link_marketplace('https://berocket.com'); |
| 1166 | |
| 1167 | printf( |
| 1168 | /* translators: %s vendor link */ |
| 1169 | esc_html__( 'Developed by %s', 'woocommerce' ), |
| 1170 | sprintf( |
| 1171 | '<a class="product-vendor-link" href="%1$s" target="_blank">%2$s</a>', |
| 1172 | esc_url_raw( $vendor_url ), |
| 1173 | esc_html( 'BeRocket' ) |
| 1174 | ) |
| 1175 | ); |
| 1176 | ?> |
| 1177 | </div> |
| 1178 | <p><?php echo wp_kses_post( $addon->excerpt ); ?></p> |
| 1179 | </div> |
| 1180 | <?php if ( ! empty( $addon->image ) ) : ?> |
| 1181 | <span class="product-img-wrap"> |
| 1182 | <?php /* Show an icon if it exists */ ?> |
| 1183 | <img src="<?php echo esc_url( $addon->image ); ?>" /> |
| 1184 | </span> |
| 1185 | <?php endif; ?> |
| 1186 | </div> |
| 1187 | <div class="product-footer"> |
| 1188 | <div class="product-price-and-reviews-container"> |
| 1189 | <div class="product-price-block"> |
| 1190 | <?php if ( $addon->price == 0 || $addon->price == '$0' ) : ?> |
| 1191 | <span class="price"><?php esc_html_e( 'Free', 'woocommerce' ); ?></span> |
| 1192 | <?php else : ?> |
| 1193 | <span class="price"> |
| 1194 | <?php |
| 1195 | echo wp_kses( |
| 1196 | $addon->price, |
| 1197 | array( |
| 1198 | 'span' => array( |
| 1199 | 'class' => array(), |
| 1200 | ), |
| 1201 | 'bdi' => array(), |
| 1202 | ) |
| 1203 | ); |
| 1204 | ?> |
| 1205 | </span> |
| 1206 | <span class="price-suffix"><?php esc_html_e( 'one time', 'woocommerce' ); ?></span> |
| 1207 | <?php endif; ?> |
| 1208 | </div> |
| 1209 | <?php if ( ! empty( $mapped->reviews_count ) && ! empty( $mapped->rating ) ) : ?> |
| 1210 | <?php /* Show rating and the number of reviews */ ?> |
| 1211 | <div class="product-reviews-block"> |
| 1212 | <?php for ( $index = 1; $index <= 5; ++$index ) : ?> |
| 1213 | <?php $rating_star_class = 'product-rating-star product-rating-star__' . self::get_star_class( $mapped->rating, $index ); ?> |
| 1214 | <div class="<?php echo esc_attr( $rating_star_class ); ?>"></div> |
| 1215 | <?php endfor; ?> |
| 1216 | <span class="product-reviews-count">(<?php echo (int) $mapped->reviews_count; ?>)</span> |
| 1217 | </div> |
| 1218 | <?php endif; ?> |
| 1219 | </div> |
| 1220 | <a class="button" href="<?php echo esc_url( self::link_marketplace($addon->link) ); ?>"> |
| 1221 | <?php esc_html_e( 'View details', 'woocommerce' ); ?> |
| 1222 | </a> |
| 1223 | </div> |
| 1224 | </li> |
| 1225 | <?php |
| 1226 | } |
| 1227 | ?> |
| 1228 | </ul> |
| 1229 | <script> |
| 1230 | if( jQuery('.berocket_section_wc_addons').length && jQuery('.wc_addons_wrap .search-form').length ) { |
| 1231 | jQuery('.berocket_section_wc_addons').addClass('products').show(); |
| 1232 | jQuery('.wc_addons_wrap .search-form').after(jQuery('.berocket_section_wc_addons')); |
| 1233 | } |
| 1234 | if( jQuery('.berocket_section_wc_addons_new').length && jQuery('.marketplace-content-wrapper').length ) { |
| 1235 | jQuery('.berocket_section_wc_addons_new').show(); |
| 1236 | if( jQuery('.marketplace-content-wrapper .products').length > 0 ) { |
| 1237 | jQuery('.marketplace-content-wrapper .products').prepend(jQuery('.berocket_section_wc_addons_new .product')); |
| 1238 | } else { |
| 1239 | jQuery('.berocket_section_wc_addons_new').addClass('products'); |
| 1240 | jQuery('.marketplace-content-wrapper').prepend(jQuery('.berocket_section_wc_addons_new')); |
| 1241 | } |
| 1242 | } |
| 1243 | </script> |
| 1244 | <?php |
| 1245 | } |
| 1246 | public static function link_marketplace($link) { |
| 1247 | $link = add_query_arg( array( |
| 1248 | 'utm_source' => 'free_plugin', |
| 1249 | 'utm_medium' => 'marketplace', |
| 1250 | 'utm_campaign' => 'marketplace', |
| 1251 | ), $link ); |
| 1252 | return $link; |
| 1253 | } |
| 1254 | public static function hide_key($key) { |
| 1255 | if( ! empty($key) ) { |
| 1256 | $part = (int)(strlen($key) / 3); |
| 1257 | $replace = strlen($key) - $part; |
| 1258 | $key = substr($key, $replace); |
| 1259 | for($i = 0; $i < $replace; $i++) { |
| 1260 | $key = '*'.$key; |
| 1261 | } |
| 1262 | } |
| 1263 | return $key; |
| 1264 | } |
| 1265 | public static function restore_keys($options) { |
| 1266 | $options_old = self::get_options(); |
| 1267 | if( ! empty($options['account_key']) && strpos($options['account_key'], '**') !== false && ! empty($options_old['account_key']) ) { |
| 1268 | $options['account_key'] = $options_old['account_key']; |
| 1269 | } |
| 1270 | if( ! empty($options['plugin_key']) && is_array($options['plugin_key']) ) { |
| 1271 | foreach($options['plugin_key'] as $plugin_id => $plugin_key) { |
| 1272 | if( ! empty($plugin_key) && strpos($plugin_key, '**') !== false && ! empty($options_old['plugin_key']) && ! empty($options_old['plugin_key'][$plugin_id]) ) { |
| 1273 | $options['plugin_key'][$plugin_id] = $options_old['plugin_key'][$plugin_id]; |
| 1274 | } |
| 1275 | } |
| 1276 | } |
| 1277 | return $options; |
| 1278 | } |
| 1279 | public static function get_plugin_data($plugin_id) { |
| 1280 | $data = array(); |
| 1281 | if( is_array(self::$plugin_info) ) { |
| 1282 | foreach(self::$plugin_info as $plugin) { |
| 1283 | if( $plugin['id'] == $plugin_id ) { |
| 1284 | return $plugin; |
| 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | return $data; |
| 1289 | } |
| 1290 | public static function update_message($plugin_file) { |
| 1291 | $plugin_data = false; |
| 1292 | foreach ( self::$plugin_info as $plugin ) { |
| 1293 | if( $plugin_file == $plugin['plugin'] ) { |
| 1294 | $version_capability = br_get_value_from_array($plugin, array('version_capability'), 15); |
| 1295 | if ( $version_capability > 5 && ! in_array($version_capability, array(15, 3, 17)) ) { |
| 1296 | $plugin_data = $plugin; |
| 1297 | } |
| 1298 | break; |
| 1299 | } |
| 1300 | } |
| 1301 | if( $plugin_data !== false ) { |
| 1302 | $wp_list_table = _get_list_table( |
| 1303 | 'WP_Plugins_List_Table', |
| 1304 | array( |
| 1305 | 'screen' => get_current_screen(), |
| 1306 | ) |
| 1307 | ); |
| 1308 | $check_plugin_activation = self::check_plugin_activation($plugin_data['id']); |
| 1309 | $is_active = ( ! empty($check_plugin_activation) && is_array($check_plugin_activation) && ! empty($check_plugin_activation['status']) ); |
| 1310 | if( ! $is_active ) { |
| 1311 | $plugin_data = BeRocket_Framework::get_product_data_berocket($plugin[ 'id' ]); |
| 1312 | if ( ! empty($plugin_data) && is_array($plugin_data) && version_compare($plugin_data['version'], $plugin[ 'version' ], '>') ) { |
| 1313 | echo '<tr class="active plugin-update-tr"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice inline notice-warning notice-alt"><p>'; |
| 1314 | printf( |
| 1315 | __( 'There is a new version %1$s of %2$s available. But <a href="%3$s">Activation required to update</a>.' ), |
| 1316 | $plugin_data['version'], |
| 1317 | $plugin_data['name'], |
| 1318 | ( is_network_admin() ? admin_url( 'network/admin.php?page=berocket_account' ) : admin_url( 'admin.php?page=berocket_account' ) ) |
| 1319 | ); |
| 1320 | echo '</p></div></td></tr>'; |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | public static function plugin_api_data($res, $action, $args) { |
| 1327 | if ( property_exists($args, 'slug') && $plugin_id = array_search( $args->slug, self::$slugs ) ) { |
| 1328 | if ( $transient_res = get_transient( 'brplugin_info_' . $plugin_id ) ) { |
| 1329 | return $transient_res; |
| 1330 | } else { |
| 1331 | if ( $plugin = self::get_plugin_data( $plugin_id ) and |
| 1332 | ! empty( $plugin['version_capability'] ) and |
| 1333 | $plugin['version_capability'] >= 10 |
| 1334 | ) { |
| 1335 | $live_plugin_data = BeRocket_Framework::get_product_data_berocket( $plugin['id'] ); |
| 1336 | |
| 1337 | if ( ! empty( self::$key ) && strlen( self::$key ) == 40 ) { |
| 1338 | $key = self::$key; |
| 1339 | } |
| 1340 | if ( ! empty( $plugin['key'] ) && strlen( $plugin['key'] ) == 40 ) { |
| 1341 | $key = $plugin['key']; |
| 1342 | } |
| 1343 | |
| 1344 | $res->name = $plugin['full_name']; |
| 1345 | $res->slug = $plugin['slug']; |
| 1346 | $res->version = $live_plugin_data['version']; |
| 1347 | $res->author = '<a href="https://berocket.com/">BeRocket</a>'; |
| 1348 | $res->author_profile = 'https://berocket.com/'; |
| 1349 | $res->support_url = 'https://berocket.com/support/'; |
| 1350 | $res->support_threads = 0; |
| 1351 | $res->support_threads_resolved = 0; |
| 1352 | $res->commercial_support_url = 'https://berocket.com/support/'; |
| 1353 | $res->download_link = BeRocket_update_path . 'v1/update_product/' . $plugin['id'] . '/' . ( empty( $key ) ? 'none' : $key ); |
| 1354 | $res->ratings = array(); |
| 1355 | $res->external = true; |
| 1356 | $res->contributors = array(); |
| 1357 | $res->donate_link = ''; |
| 1358 | $res->sections['changelog'] = ''; |
| 1359 | |
| 1360 | $url = $live_plugin_data['plugin_url'] . '?preview=in_plugin_info'; |
| 1361 | |
| 1362 | if ( $plugin_contents_raw = file_get_contents( $url ) and |
| 1363 | $plugin_contents = json_decode( $plugin_contents_raw ) and |
| 1364 | ! empty( $plugin_contents->changelog ) |
| 1365 | ) { |
| 1366 | $k = 1; |
| 1367 | $plugin_contents->changelog->version = array_reverse( $plugin_contents->changelog->version, true ); |
| 1368 | foreach ( $plugin_contents->changelog->version as $version_key => $version ) { |
| 1369 | $res->sections['changelog'] .= '<h4>' . $version . '</h4>'; |
| 1370 | $res->sections['changelog'] .= '<ul>'; |
| 1371 | if ( ! empty( $plugin_contents->changelog->enhancements[ $version_key ] ) ) { |
| 1372 | $enhancements = preg_split( "/\r\n|\n|\r/", $plugin_contents->changelog->enhancements[ $version_key ] ); |
| 1373 | foreach ( $enhancements as $enhancement ) { |
| 1374 | $res->sections['changelog'] .= '<li><strong>Enhancement:</strong> ' . $enhancement . '</li>'; |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | if ( ! empty( $plugin_contents->changelog->fixes[ $version_key ] ) ) { |
| 1379 | $fixes = preg_split( "/\r\n|\n|\r/", $plugin_contents->changelog->fixes[ $version_key ] ); |
| 1380 | foreach ( $fixes as $fix ) { |
| 1381 | $res->sections['changelog'] .= '<li><strong>Bugfix:</strong> ' . $fix . '</li>'; |
| 1382 | } |
| 1383 | } |
| 1384 | $res->sections['changelog'] .= '</ul>'; |
| 1385 | if ( ++ $k > 2 ) { |
| 1386 | $res->sections['changelog'] .= '<p></p>'; |
| 1387 | $res->sections['changelog'] .= '<a target="_blank" href="' . $live_plugin_data['plugin_url'] . '">For a complete list of updates and changes, please visit the plugin’s page.</a>'; |
| 1388 | $res->sections['changelog'] .= '<p></p>'; |
| 1389 | break; |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | $res->version = $plugin_contents->tech_detail->plugin_version; |
| 1394 | $res->last_updated = date( 'Y-m-d g:ia e', strtotime( $plugin_contents->tech_detail->last_update ) ); |
| 1395 | } |
| 1396 | |
| 1397 | set_transient( 'brplugin_info_' . $plugin_id, $res, 7200 ); |
| 1398 | } |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | return $res; |
| 1403 | } |
| 1404 | public static function is_settings_page($is_page) { |
| 1405 | if ( ! empty( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'berocket_account' ) { |
| 1406 | return true; |
| 1407 | } |
| 1408 | return $is_page; |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | BeRocket_updater::init(); |
| 1413 | add_action( 'init', array( 'BeRocket_updater', 'run' ), 1 ); |
| 1414 | } |
| 1415 |