class-aw-license.php 1.64 KB
<?php

class awlicense_class{

    public $awlic;
    public $server;
    public $api_key;
    private $wp_option  = 'ActiveWoo';
    private $product_id = 'ActiveWoo';
    public $err;

    public function __construct($awlic=false , $server , $api_key){
        $this->lic      =   $awlic;
        $this->server   =   $server;
        $this->api_key  =   $api_key;
    }

    /**
     * check for current product if licensed
     * @return boolean
     */
    public function is_licensed(){
        $awlic = get_option($this->wp_option);
        if(!empty( $awlic )){
            return true;
        }
        return false;
    }

    /**
     * send query to server and try to active lisence
     * @return boolean
     */
    public function active(){
        $url = AW_LICENSE_KEY_URL . '/?secret_key=' . AW_LICENSE_KEY_REQ . '&slm_action=slm_activate&license_key=' . $awlicense_key . '&registered_domain=' . get_bloginfo('siteurl').'&item_reference='.$this->product_id;
        $response = wp_remote_get($url, array('timeout' => 20, 'sslverify' => false));

        if(is_array($response)){
            $json = $response['body']; // use the content
            $json = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', utf8_encode($json));
            $awlicense_data = json_decode($json);
        }

        if($awlicense_data->result == 'success'){
            update_option( $this->wp_option, $this->lic );
            return true;
        }else{
            $this->err = $awlicense_data->message;
            return false;
        }
    }

    /**
     * send query to server and try to deactive lisence
     * @return boolean
     */
    public function deactive(){

    }

}