<?php
/**
 * Plugin Name:       Reactify
 * Plugin URI:        https://wordpress.org/plugins/reactify/
 * Description:       Reactify helps to make your content come alive using interactive emoji reactions. Users will be able to click on the emojis they would like to express their feelings, and each emoji will display a count number that indicates its popularity. This system is simple to use and fun!
Through smooth animations and a host of emojis , users can quickly express Laughter, Love, Surprise, or Excitement. The one click-reactions with numbers make everything more engaging and interactive, making users feel like they are a part of something fun and exciting.
 * Version:           1.0.6
 * Requires at least: 5.2
 * Requires PHP:      7.2
 * Author:            WP Plugify
 * Author URI:        https://wpplugify.com/
 * License:           GPL v3 or later
 * License URI:       https://www.gnu.org/licenses/gpl-3.0.htmlreadme.txt
 * Text Domain:       reactify
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

define( 'REACTIFY_BLOCK_VERSION', '1.0.6' );
define( 'REACTIFY_BLOCK_PATH', plugin_dir_path( __FILE__ ) );
define( 'REACTIFY_BLOCK_INCLUDES_PATH', REACTIFY_BLOCK_PATH . 'includes' );
define( 'REACTIFY_BLOCK_INCLUDES_URL', plugin_dir_url( __FILE__ ) . 'includes' );

// Function to create up database when the plugin is installed

if ( ! function_exists( 'reactify_activate' ) ) :

    function reactify_activate() {

        global $wpdb;

        $table_name = $wpdb->prefix . 'reactify';
        $charset_collate = $wpdb->get_charset_collate();

        $sql = "CREATE TABLE IF NOT EXISTS $table_name (
            id mediumint(9) NOT NULL AUTO_INCREMENT,
            post_id mediumint(9) NOT NULL,
            user_id mediumint(9) DEFAULT 0 NOT NULL,
            cookie_value varchar(64) DEFAULT '' NOT NULL,
            emoji_type varchar(20) NOT NULL,
            reaction_time datetime NOT NULL,
            PRIMARY KEY  (id),
            UNIQUE KEY post_user_reaction (post_id, user_id, cookie_value)
        ) $charset_collate;";

        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
        dbDelta( $sql );
    }

endif;

register_activation_hook( __FILE__, 'reactify_activate' );

// Function to clean up database when the plugin is uninstalled

if ( ! function_exists( 'reactify_uninstall' ) ) :

    function reactify_uninstall() {

        global $wpdb;

        $table_name = $wpdb->prefix . 'reactify';
        // Drop the table
        $wpdb->query(  "DROP TABLE IF EXISTS $table_name;" );
    }

endif;

register_uninstall_hook( __FILE__, 'reactify_uninstall' );

$reactify_includes = ['/config', '/admin/reactify-admin', '/fields/fieldmanager', '/fields/text', '/fields/checkbox', '/fields/select', '/metabox', '/view/front-reaction'];

foreach ( $reactify_includes as $wpp_file ) {
    require_once REACTIFY_BLOCK_INCLUDES_PATH . $wpp_file . '.php';
}
