license.php
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
$license=$this->get_license();
if(isset($_POST['remove_license'])){
$license_key = (isset($_POST['license_key'])&& !empty($_POST['license_key']))? $_POST['license_key']: $license['license'];
if($license_key!=''){
global $wp_version;
$args = array(
'slug' => $this->slug,
'key'=>$license_key,
'url' =>home_url(),
'email' =>get_bloginfo('admin_email')
);
$request = wp_remote_post($this->remote_path, array('body' => array('action' => 'remove','request' => serialize($args)),'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')));
if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
if($request['body'])
{
$result = json_decode($request['body']);
if($result->status=='success'){
$license['status'] = false;
$license['date'] = time();
$license['license'] = "";
}
update_option($this->LicenseName,$license);
?>
<div class="<?php if($result->status=='success') echo 'updated';else echo 'error';?>"><p><strong><?php echo $result->message;?></strong></p></div>
<?php
}
}
}else{
?>
<div class="error"><p><strong>No license key to remove</strong></p></div>
<?php
}
}
if(isset($_POST['add_license']) && isset($_POST['license_key']) && !empty($_POST['license_key'])){
global $wp_version;
$args = array(
'slug' => $this->slug,
'key'=>$_POST['license_key'],
'url' =>home_url(),
'email' =>get_bloginfo('admin_email')
);
//var_dump($args);
$request = wp_remote_post($this->remote_path, array('body' => array('action' => 'active','request' => serialize($args)),'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')));
if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
if($request['body'])
{
$result = json_decode($request['body']);
if($result->status=='success'){
$license['status'] = true;
$license['date'] = time();
}else $license['status'] = false;
$license['license'] = $_POST['license_key'];
update_option($this->LicenseName,$license);
?>
<div class="<?php if($result->status=='success') echo 'updated';else echo 'error';?>"><p><strong><?php echo $result->message;?></strong></p></div>
<?php
}
//var_dump($request['body']);
}
}
if(isset($_POST['re_add_license'])){
global $wp_version;
$args = array(
'slug' => $this->slug,
'key'=>$license['license'],
'url' =>home_url(),
'email' =>get_bloginfo('admin_email')
);
$request = wp_remote_post($this->remote_path, array('body' => array('action' => 'active','request' => serialize($args)),'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')));
if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
if($request['body'])
{
$result = json_decode($request['body']);
if($result->status=='success'){
$license['status'] = true;
$license['date'] = time();
}else $license['status'] = false;
update_option($this->LicenseName,$license);
?>
<div class="<?php if($result->status=='success') echo 'updated';else echo 'error';?>"><p><strong><?php echo $result->message;?></strong></p></div>
<?php
}
}
}
$status = (!empty($license['status']))?$license['status']:false;
$key = (!empty($license['license']))?$license['license']:'';
if($status && ($key!='' || !empty($key))){
$k = strrpos($key,"-");
if($k)
for($i=0;$i<strlen($key);$i++){
if($i<$k) $key[$i] = "*";
}
}
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br></div>
<h2><?php _e('License',self::LANG);?></h2>
<p>Please enter your license key to enable plugin update via wordpress admin. You can <a href="http://files.megadrupal.com/how-to-get-purchase-code.png">follow this steps</a> to get your license key</p>
<form action="" method="post">
<table class="form-table" id="modern-admin-icons-table">
<tbody>
<tr valign="top">
<th scope="row"><label for="license_key"><?php _e('License Key',self::LANG);?></label></th>
<td>
<?php if($status!=false):?>
<div><?php echo $key;?></div>
<?php else:?>
<input type="text" class="regular-text" id="license_key" value="<?php echo $key;?>" name="license_key">
<?php endif;?>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="status"><?php _e('Status',self::LANG);?></label></th>
<td>
<?php if($license['status']==true) echo "<b style='color: #008000'>OK</b>"; else echo "<b style='color: red'>FALSE</b>"?>
</td>
</tr>
<tr valign="top">
<th scope="row"></th>
<td>
<button type="submit" name="<?php if($status!=false) echo "re_add_license"; else echo "add_license";?>">
<?php if($status!=false):?>
<?php _e('Re-Active',self::LANG);?>
<?php else:?>
<?php _e('Active',self::LANG);?>
<?php endif;?>
</button>
<button type="submit" name="remove_license"><?php _e('Remove',self::LANG);?></button>
</td>
</tr>
</tbody>
</table>
</form>
</div>