-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudcheck.php
208 lines (176 loc) · 7.25 KB
/
cloudcheck.php
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* Plugin Name: Cloudcheck Integration
* Plugin URI: https://wordpress.org/plugins/cloudcheck_integration/
* Description: Integration with cloudcheck service for electronic identification verification. Only for New Zealand and Australia
* Version: 1.0.0
* Author: Roundkick.Studio, eurohlam
* Author URI: https://roundkick.studio
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* License: GPLv2 or later
Cloudcheck Integration is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
Cloudcheck Integration is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Cloudcheck Integration. If not, see http://www.gnu.org/licenses/gpl-2.0.txt.
*/
if (!defined('ABSPATH')) exit;
include_once 'class-cloudcheck-integration.php';
include_once 'cloudcheck-shortcodes.php';
define('CLOUDCHECK_INT_VERSION', '1.0.0');
if (!class_exists('WP_Cloudcheck_Int')) {
class WP_Cloudcheck_Int {
/**
* Plugin's options
*/
private $options_group = 'cloudcheck_int';
private $url_option = 'cloudcheck_url';
private $accessKey_option = 'cloudcheck_access_key';
private $secret_option = 'cloudcheck_secret';
private $db_table_name = 'cc_message_log';
private $pdf_folder_name = 'cloudcheck_int';
static function activate() {
global $wpdb;
$table_name = $wpdb->prefix . 'cc_message_log';
$sql = "CREATE TABLE IF NOT EXISTS ".$table_name." (
id int(11) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
endpoint varchar(20) NOT NULL,
request longtext CHARACTER SET utf8 NOT NULL,
response longtext CHARACTER SET utf8 NOT NULL,
filepath varchar(50),
PRIMARY KEY (id)
) DEFAULT CHARSET=utf8;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
$dir_path = wp_upload_dir()['basedir'] . '/cloudcheck_int';
if(!file_exists($dir_path)) wp_mkdir_p($dir_path);
}
static function deactivate() {
//nothing so far
}
static function uninstall() {
global $wpdb;
delete_option( 'cloudcheck_url' );
delete_option( 'cloudcheck_access_key' );
delete_option( 'cloudcheck_secret' );
$table_name = $wpdb->prefix . 'cc_message_log';
$sql = "DROP TABLE IF EXISTS $table_name";
$wpdb->query( $sql );
}
function __construct() {
add_action('admin_menu', array( $this, 'cloudcheck_menu'));
add_action('wp_ajax_cloudcheck_send_request', array( $this,'cloudcheck_send_request'));
add_action('wp_ajax_cloudcheck_send_email', array( $this,'send_pdf_by_email'));
add_action('init', 'cloudcheck_shortcodes_init');
}
/**
* Send request to cloudcheck
*/
function cloudcheck_send_request() {
global $wpdb;
$accessKey = get_option($this->accessKey_option);
$secret = get_option($this->secret_option);
$url = get_option($this->url_option);
$request = stripcslashes($_POST['request']);
$path = $_POST['path'];
if (!empty($accessKey) && !empty($secret) && !empty($url) && !empty($path)) {
$cloudcheckInt = new Cloudcheck_Integration();
$cloudcheckRequest = $cloudcheckInt->prepare_cloudcheck_parameters($accessKey, $secret, $path, $request);
$result = $cloudcheckInt->send_request($url . $path, $cloudcheckRequest);
$wpdb->insert(
$wpdb->prefix . $this->db_table_name,
array(
'time' => current_time( 'mysql' ),
'endpoint' => $path,
'request' => json_encode($cloudcheckRequest),
'response' => $result,
)
);
echo $result;
} else {
error_log('Cloudcheck Integration plugin error: empty one or several required parameters - accessKey, secret, url or path. Please check settings of Cloudcheck Integration plugin');
echo '{"Cloudcheck Integration plugin error": "empty one or several required parameters - accessKey, secret, url or path"}';
}
wp_die();
}
function send_pdf_by_email() {
$subject = 'Electronic Verification Identification Report';
$body = 'Please refer to the attached PDF for more details';
$headers = array('Content-Type: text/html; charset=UTF-8');
$filepath = $_POST['filepath'];
$emailList = $_POST['emaillist'];
wp_mail( $emailList, $subject, $body, $headers, $filepath );
echo '{ "result" : "success" }';
wp_die();
}
function cloudcheck_settings() {
register_setting( $this->options_group, $this->url_option );
register_setting( $this->options_group, $this->accessKey_option );
register_setting( $this->options_group, $this->secret_option );
}
function cloudcheck_menu() {
add_action('admin_init', array( $this,'cloudcheck_settings'));
add_options_page('Cloudcheck Integration', 'Cloudcheck Integration', 'manage_options', 'cloudcheck-int', array( $this,'cloudcheck_options_page'));
}
/**
* Admin options page
*/
function cloudcheck_options_page() {
?>
<div class="wrap">
<h2>Cloudcheck Integration</h2>
<p>Cloudcheck is an electronic identification verification (EV) tool that allows you to verify the identity of your customer using biometric checks, Australian and New Zealand data sources and global watchlists in one easy step. More details about
<a href="https://www.verifidentity.com/cloudcheck/">Cloudcheck</a></p>
<p>Version: <?php echo CLOUDCHECK_INT_VERSION ?></p>
<div>
<form method="post" action="options.php">
<?php
settings_fields($this->options_group);
do_settings_sections($this->options_group);
?>
<table class="form-table">
<tr valign="top">
<th scope="row">Cloudcheck URL</th>
<td>
<input type="url" class="regular-text" name="cloudcheck_url" value="<?php echo get_option($this->url_option) ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">Cloudcheck Access Key</th>
<td>
<input type="text" class="regular-text" name="cloudcheck_access_key" value="<?php echo get_option($this->accessKey_option) ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">Cloudcheck Secret Key</th>
<td>
<input type="text" class="regular-text" name="cloudcheck_secret" value="<?php echo get_option($this->secret_option) ?>" />
</td>
</tr>
</table>
<input type="hidden" name="page_options" value="cloudcheck_url,cloudcheck_access_key,cloudcheck_secret" />
<p class="submit">
<input class="button-primary" type="submit" value="Save Changes" />
</p>
</form>
</div>
</div>
<?php
}
} //end class WP_Cloudcheck_Int
}
if (class_exists('WP_Cloudcheck_Int')) {
// Installation and uninstallation hooks
register_activation_hook(__FILE__, array('WP_Cloudcheck_Int', 'activate'));
register_deactivation_hook(__FILE__, array('WP_Cloudcheck_Int', 'deactivate'));
register_uninstall_hook(__FILE__, array('WP_Cloudcheck_Int', 'uninstall'));
// instantiate the plugin class
$wp_plugin = new WP_Cloudcheck_Int();
}
?>