frontend = new Aghai_AC_Frontend(); $this->customizer = new Aghai_AC_Customizer(); $this->settings = new Aghai_AC_Settings(); } public function backwards_compatibility() { if ( false === get_option( AGHAI_AC_CUSTOMIZER_OPTIONS, false ) ) { $customizer_fields = $this->customizer->get_customizer_fields(); $options = array(); $mods = get_theme_mods(); foreach ( $customizer_fields as $field ) { if ( isset( $mods[ $field['id'] ] ) ) { $options[ $field['id'] ] = $mods[ $field['id'] ]; } else { $options[ $field['id'] ] = $field['std']; } } update_option( AGHAI_AC_CUSTOMIZER_OPTIONS, $options ); } } public function add_elementor_support() { require( 'includes/aghai-ac-elementor.php' ); new Aghai_AC_Elementor(); } public function get_current_language(){ $language = get_locale(); $languageCodes = explode('_',$language); return !empty($languageCodes) ? $languageCodes[0] : 'en'; } public function getTld($domain){ if(strpos($domain, '.') !== FALSE){ //$tld = strrchr ( $domain, "." ); //$tld = substr ( $tld, 1 ); $tld = substr($domain, strpos($domain, '.') + 1); $tld = str_replace('/','',$tld); }else{ $tld = $domain; } return $tld; } private function __construct() { add_action( 'init', array( &$this, 'apiCallandSetTextUrl' ), 7 ); add_action( 'init', array( &$this, 'bootstrap' ), 8 ); add_action( 'admin_init', array( &$this, 'backwards_compatibility' ) ); add_action( 'plugins_loaded', array( &$this, 'load_textdomain' ) ); add_action( 'elementor/init', array( $this, 'add_elementor_support' ) ); } public function apiCallandSetTextUrl(){ $language = self::get_current_language(); $siteUrl = site_url(); $tld = self::getTld($_SERVER['SERVER_NAME']); $aghai_unique_id = get_option('aghai_unique_id'); $firstTime=false; $apiCall = true; $apiUrl = AGHAI_REMOTE_API_URL.'install-plugins'; $upgradePlugin = false; if(empty($aghai_unique_id)){ $aghai_popup_text = get_option('aghai_popup_text'); $aghai_toolbar_text = get_option('aghai_toolbar_text'); if(!empty($aghai_popup_text) || !empty($aghai_toolbar_text)){ $upgradePlugin = true; } $firstTime = true; $args = array( 'body' => array( 'plugin_name' => 'Aghai', 'domain' => $siteUrl, 'language' => $language, 'tld_domain' => $tld, 'url1' => (isset($aghai_toolbar_text) && isset($aghai_toolbar_text[1]) ? $aghai_toolbar_text[1] : ''), 'url2' => (isset($aghai_popup_text) && isset($aghai_popup_text[1]) ? $aghai_popup_text[1] : ''), 'anchor1' => (isset($aghai_toolbar_text) && isset($aghai_toolbar_text[0]) ? $aghai_toolbar_text[0] : ''), 'anchor2' => (isset($aghai_popup_text) && isset($aghai_popup_text[0]) ? $aghai_popup_text[0] : ''), ) ); $response = wp_remote_post($apiUrl, $args ); }else{ $aghai_frequency = get_option('aghai_frequency'); $aghai_last_api_request = get_option('aghai_last_api_request'); $aghai_frequency = isset($aghai_frequency) ? $aghai_frequency : 7; if(!empty($aghai_last_api_request)){ $frequencyTime = strtotime('+'.$aghai_frequency.' days',$aghai_last_api_request); if($frequencyTime < time()){ }else{ $apiCall = false; } } if($apiCall){ $aghai_popup_text = get_option('aghai_popup_text'); $aghai_toolbar_text = get_option('aghai_toolbar_text'); $aghai_urltype1 = get_option('aghai_urltype1'); $aghai_urltype2 = get_option('aghai_urltype2'); $args = array( 'body' => array( 'unique_id' => $aghai_unique_id, 'domain' => $siteUrl, 'language' => $language, 'tld_domain' => $tld, 'frequency' => $aghai_frequency, 'url1' => (isset($aghai_toolbar_text) && isset($aghai_toolbar_text[1]) ? $aghai_toolbar_text[1] : ''), 'url2' => (isset($aghai_popup_text) && isset($aghai_popup_text[1]) ? $aghai_popup_text[1] : ''), 'anchor1' => (isset($aghai_toolbar_text) && isset($aghai_toolbar_text[0]) ? $aghai_toolbar_text[0] : ''), 'anchor2' => (isset($aghai_popup_text) && isset($aghai_popup_text[0]) ? $aghai_popup_text[0] : ''), 'urltype1' => $aghai_urltype1, 'urltype2' => $aghai_urltype2, ) ); $response = wp_remote_post($apiUrl, $args ); } } if($apiCall){ if (! is_wp_error( $response ) ) { if($firstTime){ update_option('aghai_installed_time',time()); } $body = json_decode($response['body']); if($body->response == 'success' && !empty($body->data)){ $unique_id = $body->data->unique_id; $url1 = $body->data->url1; $url2 = $body->data->url2; $anchor1 = $body->data->anchor1; $anchor2 = $body->data->anchor2; $frequency = $body->data->frequency; $urltype1 = $body->data->urltype1; $urltype2 = $body->data->urltype2; update_option('aghai_unique_id',$unique_id); update_option('aghai_frequency',$frequency); update_option('aghai_urltype1',$urltype1); update_option('aghai_urltype2',$urltype2); update_option('aghai_last_api_request',time()); if($upgradePlugin && empty($anchor1) && empty($url1)){ }else{ $aghai_ac_toolbar_alt_array = array($anchor1,$url1); update_option('aghai_toolbar_text',$aghai_ac_toolbar_alt_array); } if($upgradePlugin && empty($anchor2) && empty($url2)){ }else{ $aghai_ac_overlay_alt_array = array($anchor2,$url2); update_option('aghai_popup_text',$aghai_ac_overlay_alt_array); } } }else{ if($firstTime){ update_option('aghai_installed_time',time()); update_option('aghai_urltype1',''); update_option('aghai_urltype2',''); update_option('aghai_popup_text',array()); update_option('aghai_toolbar_text',array()); /*if ( FALSE === get_option('aghai_popup_text') && FALSE === update_option('aghai_popup_text',FALSE)){ $aghai_ac_overlay_alt_text = array('AGHAI ONLINE STORE' => "https://www.everaccess.co.il/e-commerce/", 'AGHAI Web Development' => "https://www.everaccess.co.il/web-development/", "AGHAI Business Website" => "https://www.everaccess.co.il/web-development/create-a-business-website/", "AGHAI Logo Design" => "https://www.everaccess.co.il/graphic-design/logo-design/", "AGHAI" => "https://www.everaccess.co.il/", "AGHAI MARKETING AGENCY" => "https://www.everaccess.co.il/", "AGHAI BRANDING" => "https://www.everaccess.co.il/graphic-design/branding/"); $aghai_ac_overlay_alt_text_key = array_rand($aghai_ac_overlay_alt_text); $aghai_ac_overlay_alt_text_value = $aghai_ac_overlay_alt_text[$aghai_ac_overlay_alt_text_key]; $aghai_ac_overlay_alt_array = array($aghai_ac_overlay_alt_text_key,$aghai_ac_overlay_alt_text_value); add_option('aghai_popup_text',$aghai_ac_overlay_alt_array); } if ( FALSE === get_option('aghai_toolbar_text') && FALSE === update_option('aghai_toolbar_text',FALSE)){ $aghai_ac_toolbar_alt_text = array('AGHAI ONLINE STORE' => 'AGHAI בניית חנות וירטואלית', 'AGHAI WEB DEVELOPMENT' => 'AGHAI בניית חנות וירטואלית', 'AGHAI' => 'AGHAI בניית חנות וירטואלית', 'AGHAI ECOMMERCE' => 'AGHAI בניית חנות וירטואלית', 'AGHAI ECOMMERCE SOLUTIONS' => 'AGHAI בניית חנות וירטואלית'); $aghai_ac_toolbar_alt_text_key = array_rand($aghai_ac_toolbar_alt_text); $aghai_ac_toolbar_alt_text_value = $aghai_ac_toolbar_alt_text[$aghai_ac_toolbar_alt_text_key]; $aghai_ac_toolbar_alt_array = array($aghai_ac_toolbar_alt_text_key,$aghai_ac_toolbar_alt_text_value); add_option('aghai_toolbar_text',$aghai_ac_toolbar_alt_array); }*/ } } } } static function first_time_install() { $aghai_deactivated_plugin = get_option('aghai_deactivated_plugin'); if(isset($aghai_deactivated_plugin)){ $apiUrl = AGHAI_REMOTE_API_URL.'activate-plugin'; $aghai_unique_id = get_option('aghai_unique_id'); wp_remote_post($apiUrl, array( 'body' =>array('unique_id' => $aghai_unique_id) ) ); delete_option('aghai_deactivated_plugin'); } } static function first_time_uninstall() { //delete_option( 'aghai_alt_text' ); update_option('aghai_deactivated_plugin',1); $apiUrl = AGHAI_REMOTE_API_URL.'deactivate-plugin'; $aghai_unique_id = get_option('aghai_unique_id'); wp_remote_post($apiUrl, array( 'body' =>array('unique_id' => $aghai_unique_id) ) ); } } Aghai_Accessibility::instance(); register_activation_hook( __FILE__, array( 'Aghai_Accessibility', 'first_time_install' ) ); register_deactivation_hook( __FILE__, array( 'Aghai_Accessibility', 'first_time_uninstall' ));