<?php
if (!defined('ABSPATH')) {
    exit;
}

class SchematicCompatability {

    private $mppCompatible = false;
    private $mppInstalled = false;
    private $error = false;
    protected $minVersionPHP = '5.5.9';

    public function __construct() {
        if (defined('MAGIC_PAGE_VERSION')) {
            $this->mppInstalled = true;

            if (MAGIC_PAGE_VERSION < '5.3') {
                add_action('admin_notices', array($this, 'noticeMpp'));
            } else {
                $this->mppCompatible = true;
            }
        }

        if (!$this->mppCompatible && $this->mppInstalled) {
            $this->error = true;
        }

        if (version_compare(phpversion(), $this->minVersionPHP, '<=')) {
            add_action('admin_notices', array($this, 'phpOld'));
            $this->error = true;
        }
    }

    public function getMppInstalled() {
        return $this->mppInstalled;
    }

    public function getMppCompatible() {
        return $this->mppCompatible;
    }

    public function getError() {
        return $this->error;
    }

    public function phpOld() {
        ?>
        <div class="notice notice-success is-dismissible">
            <p>WP Schema Plugin Notice: You're using too old version of PHP <?php phpversion(); ?>. 
                Please use at least <?php echo($this->minVersionPHP); ?>
            </p>
        </div>
        <?php
    }

    public function noticeMpp() {
        ?>
        <div class="notice notice-success is-dismissible">
            <p>WP Schema Plugin Notice: If you are using Magic Page Plugin you must use no less than version 5.3 </p>
        </div>
        <?php
    }

}
