| 1 |
<?php |
| 2 |
|
| 3 |
if ( !class_exists( 'MeowCommon_Licenser' ) ) { |
| 4 |
|
| 5 |
class MeowCommon_Licenser { |
| 6 |
public $license = null; |
| 7 |
public $prefix; // prefix used for actions, filters (mfrh) |
| 8 |
public $mainfile; // plugin main file (media-file-renamer.php) |
| 9 |
public $domain; // domain used for translation (media-file-renamer) |
| 10 |
public $item; // name of the Pro plugin (Media File Renamer Pro) |
| 11 |
public $version; // version of the plugin (Media File Renamer Pro) |
| 12 |
|
| 13 |
public function __construct( $prefix, $mainfile, $domain, $item, $version ) { |
| 14 |
$this->prefix = $prefix; |
| 15 |
$this->mainfile = $mainfile; |
| 16 |
$this->domain = $domain; |
| 17 |
$this->item = $item; |
| 18 |
$this->version = $version; |
| 19 |
|
| 20 |
if ( $this->is_registered() ) { |
| 21 |
add_filter( $this->prefix . '_meowapps_is_registered', array( $this, 'is_registered' ), 10 ); |
| 22 |
} |
| 23 |
|
| 24 |
if ( MeowCommon_Helpers::is_rest() ) { |
| 25 |
new MeowCommon_Classes_Rest_License( $this ); |
| 26 |
} |
| 27 |
else if ( is_admin() ) { |
| 28 |
$license_key = $this->license && isset( $this->license['key'] ) ? $this->license['key'] : ""; |
| 29 |
new MeowCommon_Classes_Updater( |
| 30 |
( get_option( 'force_sslverify', false ) ? 'https' : 'http' ) . '://store.meowapps.com', $this->mainfile, |
| 31 |
array( |
| 32 |
'version' => $this->version, |
| 33 |
'license' => $license_key, |
| 34 |
'item_name' => $this->item, |
| 35 |
'wp_override' => true, |
| 36 |
'author' => 'Jordy Meow', |
| 37 |
'url' => strtolower( home_url() ), |
| 38 |
'beta' => false |
| 39 |
) |
| 40 |
); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
function retry_validation() { |
| 45 |
if ( isset( $_POST[$this->prefix . '_pro_serial'] ) ) { |
| 46 |
$serial = sanitize_text_field( $_POST[$this->prefix . '_pro_serial'] ); |
| 47 |
$this->validate_pro( $serial ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
function is_registered( $force = false ) { |
| 52 |
if ( !$force && !empty( $this->license ) ) |
| 53 |
return empty( $this->license['issue'] ); |
| 54 |
$this->license = get_option( $this->prefix . '_license', "" ); |
| 55 |
if ( empty( $this->license ) || !empty( $this->license['issue'] ) ) |
| 56 |
return false; |
| 57 |
if ( $this->license['expires'] == "lifetime" ) |
| 58 |
return true; |
| 59 |
$datediff = strtotime( $this->license['expires'] ) - time(); |
| 60 |
$days = floor( $datediff / ( 60 * 60 * 24 ) ); |
| 61 |
if ( $days < 0 ) |
| 62 |
$this->validate_pro( $this->license['key'] ); |
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
function validate_pro( $subscr_id ) { |
| 67 |
$prefix = $this->prefix; |
| 68 |
delete_option( $prefix . '_license', "" ); |
| 69 |
if ( empty( $subscr_id ) ) |
| 70 |
return false; |
| 71 |
$url = ( get_option( 'force_sslverify', false ) ? 'https' : 'http' ) . |
| 72 |
'://store.meowapps.com/?edd_action=activate_license' . |
| 73 |
'&item_name=' . urlencode( $this->item ) . |
| 74 |
'&license=' . $subscr_id . '&url=' . strtolower( home_url() ) . '&cache=' . bin2hex( openssl_random_pseudo_bytes( 4 ) ); |
| 75 |
$response = wp_remote_get( $url, array( |
| 76 |
'user-agent' => "MeowApps", |
| 77 |
'sslverify' => get_option( 'force_sslverify', false ), |
| 78 |
'timeout' => 45, |
| 79 |
'method' => 'GET' |
| 80 |
) |
| 81 |
); |
| 82 |
$body = is_array( $response ) ? $response['body'] : null; |
| 83 |
$post = @json_decode( $body ); |
| 84 |
$status = null; |
| 85 |
$license = null; |
| 86 |
$expires = null; |
| 87 |
$logs = null; |
| 88 |
if ( !$post || ( property_exists( $post, 'code' ) ) ) { |
| 89 |
$status = 'error'; |
| 90 |
// $status = __( "There was an error while validating the serial.<br />Please contact <a target='_blank' href='https://meowapps.com/contact/'>Meow Apps</a> and mention the following log: <br /><ul>", $this->domain ); |
| 91 |
$logs = "<li>Server IP: <b>" . gethostbyname( $_SERVER['SERVER_NAME'] ) . "</b></li>"; |
| 92 |
$logs .= "<li>Google GET: "; |
| 93 |
$r = wp_remote_get( 'http://google.com' ); |
| 94 |
$logs .= is_wp_error( $r ) ? print_r( $r, true ) : 'OK'; |
| 95 |
$logs .= "</li><li>MeowApps GET: "; |
| 96 |
$r = wp_remote_get( 'http://meowapps.com' ); |
| 97 |
$logs .= is_wp_error( $r ) ? print_r( $r, true ) : 'OK'; |
| 98 |
$logs .= "</li><li>MeowApps STORE:<br /><br />"; |
| 99 |
$logs .= "REQUEST: $url<br /><br />"; |
| 100 |
$logs .= "RESPONSE: "; |
| 101 |
$logs .= print_r( $response, true ); |
| 102 |
$logs .= "</li></ul>"; |
| 103 |
error_log( print_r( $response, true ) ); |
| 104 |
} |
| 105 |
else if ( $post->license !== "valid" ) { |
| 106 |
$status = $post->error ; |
| 107 |
} |
| 108 |
else { |
| 109 |
$license = $post->license; |
| 110 |
$expires = $post->expires; |
| 111 |
delete_option( '_site_transient_update_plugins' ); |
| 112 |
} |
| 113 |
update_option( $prefix . '_license', array( |
| 114 |
'key' => $subscr_id, |
| 115 |
'issue' => $status, |
| 116 |
'logs' => $logs, |
| 117 |
'expires' => $expires, |
| 118 |
'license' => $license ) ); |
| 119 |
return $this->is_registered( true ); |
| 120 |
} |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
?> |
| 127 |
|