<?php
/*
Plugin Name: Webapp Generator
Plugin URI: https://www.rtl-theme.com/webapp-generator-wordpress-plugin/
Description: With Webapp Generator Plugin you can make a full version mobile application of your website.
Version: 6.0.4
Author: HashtagDevelop
Author URI: https://www.rtl-theme.com/user-profile/hashtagdevelop/
Domain Path: /languages/
License:
*/


register_activation_hook( __FILE__, function(){
    include dirname(__FILE__).'/hr-databases.php';
    $database=new hr_databases();
    $database->create_table();
    $database->create_intro();
    $database->create_inistalled_app();
    $database->create_tabs();
    $database->create_notification_table();
});
register_uninstall_hook(__FILE__, 'hashtagdevelop_plugin_uninstall');
register_deactivation_hook(__FILE__, 'hashtagdevelop_plugin_deactivate');

function hashtagdevelop_plugin_uninstall() {
     include dirname(__FILE__).'/hr-databases.php';
     $database = new hr_databases();
     $database->uninstall();
}

function hashtagdevelop_plugin_deactivate() {
     include dirname(__FILE__).'/hr-databases.php';
     $database = new hr_databases();
     $database->uninstall();
}
add_action('init',function(){

    if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/hd-webapp.php")) {
        copy(dirname(__FILE__).'/hd-webapp.php', $_SERVER['DOCUMENT_ROOT'] . "/hd-webapp.php");
    }

    load_plugin_textdomain('hashtagdevelop-webapp-generator', FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
    include dirname(__FILE__).'/includes/hd_web_app_generator.php';
    include dirname(__FILE__) . '/options/hd_webapp_functions.php';
    include dirname(__FILE__).'/includes/jdf.php';
    include dirname(__FILE__).'/includes/views/services/class-webapp-generator-table.php';
    include dirname(__FILE__).'/includes/views/services/class-webapp-installed-apps.php';
    include dirname(__FILE__).'/includes/views/services/class-webapp-notification-list.php';
    include dirname(__FILE__).'/includes/app-generator-form-handler.php';

});
add_action('wp_footer', 'wq_footer_method');
add_action ( 'wp_head', 'add_pwa_header' );
add_action( 'wp_footer', 'add_pwa_footer' );
add_action( 'wp_footer', 'add_pwa_ios' );
function custom_upload_mimes($mimes) {
     $mimes['json'] = 'application/json';
     $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}
add_filter('upload_mimes', 'custom_upload_mimes', 1, 1);

add_filter( 'wp_check_filetype_and_ext', 'wc_correct_filetypes', 10, 5 );

function wc_correct_filetypes( $data, $file, $filename, $mimes, $real_mime ) {
    if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) {
        return $data;
    }
    $wp_file_type = wp_check_filetype( $filename, $mimes );
    if ( 'json' === $wp_file_type['ext'] ) {
        $data['ext']  = 'application/json';
        $data['type'] = 'text/plain';
    }
    if ($wp_file_type['type'] == 'image/svg+xml') {
        $data['type'] = 'image/svg+xml';
    }
    return $data;
}
function enqueue_scripts() {
    wp_localize_script( 'scripts', 'jsAlert', array(
        'json' =>  __( "Error: You must choice json file for firebase push notification", 'hashtagdevelop-webapp-generator' ),
        'png' =>  __( "Error: You must choice png image", 'hashtagdevelop-webapp-generator' ),
        'gif' =>  __( "Error: You must choice gif image", 'hashtagdevelop-webapp-generator' ),
    ) );
}
add_action( 'admin_enqueue_scripts', 'enqueue_scripts' );
