<?php
/*
Plugin Name: WT Geotargeting
Plugin URI: http://web-technology.biz/cms-wordpress/plugin-wt-geotargeting
Description: Набор инструментов для настройки геотаргетинга.
Version: 1.7.1
Author: Кусты Роман, АИТ "WebTechnology"
Author URI: http://web-technology.biz
*/

define('WT_GT_PRO_PLUGIN_FILE', __FILE__);
define('WT_GT_PRO_PLUGIN_DIR', dirname(WT_GT_PRO_PLUGIN_FILE));
define('WT_GT_PRO_PLUGIN_BASENAME', plugin_basename(WT_GT_PRO_PLUGIN_FILE));

require_once(WT_GT_PRO_PLUGIN_DIR . '/vendor/autoload.php');
include(WT_GT_PRO_PLUGIN_DIR . '/includes/IpGeoBase.php');	// Класс для работы с IpGeoBase
include(WT_GT_PRO_PLUGIN_DIR . '/includes/DaData.php');	// Класс для работы с DaData

include(WT_GT_PRO_PLUGIN_DIR . '/includes/WtKit.php');      // Статический класс и набор инструментов
include(WT_GT_PRO_PLUGIN_DIR . '/includes/wt_data_files.php');

require(WT_GT_PRO_PLUGIN_DIR . '/includes/wt_gt_admin_behavior.php');

include(WT_GT_PRO_PLUGIN_DIR . '/includes/WtInitialization.php'); // Настройка библиотек
include(WT_GT_PRO_PLUGIN_DIR . '/includes/WtGeolocation.php');		// Оболочка для работы с Web-сервисами

class WtGeoTargeting
{
    public $modules = array(
    );

    function __construct(){
        add_action('plugins_loaded', array($this, 'pluginsLoaded'));
        add_action('init', array($this, 'initial'));
    }

    static function activation(){
    }

    static function deactivation(){}

    public function uninstall(){}

    function pluginsLoaded(){
        if (defined('ABSPATH') && is_admin()) $this->initialAdmin();

        $this->activationModules();

        new WtInitialization();
    }

    function initial(){
    }

    public function initialAdmin(){
        require(WT_GT_PRO_PLUGIN_DIR . '/includes/wt_gt_admin.php');

        $wt_gt_pro_admin = new WtGtAdmin();
        $wt_gt_pro_admin->geotargeting = $this;
    }

    public function activationModules(){
        foreach ($this->modules as $key => $module){
            require(WT_GT_PRO_PLUGIN_DIR . '/modules/' . $key . '/' . $key . '.php');
            new $key();
        }
    }

    public function registerScripts(){
    }

    public function registerAdminScripts(){
    }
}

new WtGeoTargeting();
register_activation_hook(WT_GT_PRO_PLUGIN_FILE, array('WtGeoTargeting', 'activation'));
register_deactivation_hook(WT_GT_PRO_PLUGIN_FILE, array('WtGeoTargeting', 'deactivation'));
register_uninstall_hook(WT_GT_PRO_PLUGIN_FILE, array('WtGeoTargeting', 'uninstall'));