PluginProbe
TrustedSite / trunk
TrustedSite vtrunk
1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 trunk 1.0 1.0.1 1.0.2 1.0.3
trustedsite / lib / Trustedsite.php

Trustedsite.php in TrustedSite trunk, at lib/Trustedsite.php

320 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') OR exit;
3
4 class Trustedsite {
5 public static function activate() {
6 update_option('trustedsite_active', 1);
7
8 if(Trustedsite::get_sitemap_active() == true) {
9 update_option('trustedsite_robots_enable', 1);
10 } else {
11 update_option('trustedsite_robots_enable', 0);
12 }
13
14 Trustedsite::ping_event('activate');
15 }
16
17 public static function scripts($hook) {
18 if (strpos($hook, "trustedsite-settings") !== false) {
19 wp_enqueue_style('trustedsite-settings-fa', plugins_url('../css/font-awesome.min.css',__FILE__));
20 wp_enqueue_style('trustedsite-settings-css', plugins_url('../css/settings.css',__FILE__));
21 wp_enqueue_script('trustedsite-trustedsite-js', plugins_url('../js/trustedsite.js',__FILE__));
22 }
23 }
24
25 public static function get_api_response() {
26 $endpoint_host = "https://cdn.trustedsite.com";
27 $arrHost = parse_url(home_url('', $scheme = 'http'));
28 $host = $arrHost['host'];
29
30 $api_url = $endpoint_host . "/api/v2/site-lookup.json?host=" . urlencode($host) . "&cache=" . get_the_date('i');
31 $response = wp_remote_get($api_url);
32
33 return $response;
34 }
35
36 public static function get_site_id() {
37 $existing_site_id = get_option('trustedsite_site_id');
38 if (!empty($existing_site_id)) {
39 return $existing_site_id;
40 }
41
42 $response = Trustedsite::get_api_response();
43
44 if (is_array($response) && !is_wp_error($response)) {
45 $rjson = json_decode($response['body'], true);
46 $site_id = $rjson['site_id'];
47 update_option('trustedsite_site_id', $site_id);
48 return $site_id;
49 }
50
51 return false;
52 }
53
54 public static function get_sitemap_active() {
55 $response = Trustedsite::get_api_response();
56
57 if (is_array($response) && !is_wp_error($response)) {
58 $rjson = json_decode($response['body'], true);
59 if ($rjson['success'] == 0) return false;
60 $sitemap = $rjson['sitemap'];
61 $status = $sitemap['status'];
62 if ($status == 'active') return true;
63 return false;
64 }
65
66 return false;
67 }
68
69 public static function ping_event($name) {
70 $id = get_option('trustedsite_id');
71 if ( ! $id ) {
72 $id = wp_generate_uuid4();
73 update_option('trustedsite_id', $id);
74 }
75 $response = wp_remote_post('https://www.trustedsite.com/rpc/wordpress', [
76 'timeout' => 5,
77 'body' => [
78 'do' => 'event',
79 'id' => $id,
80 'name' => $name,
81 'site_url' => site_url(),
82 'home_url' => home_url(),
83 'email' => get_option('admin_email'),
84 'version' => TRUSTEDSITE_VERSION
85 ],
86 ]);
87 }
88
89 public static function ping_siteurl_change() {
90 Trustedsite::ping_event('siteurl_change');
91 }
92
93 public static function ping_admin_email_change() {
94 Trustedsite::ping_event('admin_email_change');
95 }
96
97 public static function install() {
98 add_shortcode('mcafeesecure', 'Trustedsite::mfes_engagement_trustmark_shortcode');
99 add_shortcode('trustedsite', 'Trustedsite::ts_engagement_trustmark_shortcode');
100 add_shortcode('trustedsite_form', 'Trustedsite::ts_form_engagement_trustmark_shortcode');
101 add_shortcode('trustedsite_checkout', 'Trustedsite::ts_checkout_engagement_trustmark_shortcode');
102 add_shortcode('trustedsite_login', 'Trustedsite::ts_login_engagement_trustmark_shortcode');
103 add_shortcode('mcafeesecure_sip', 'Trustedsite::mfes_sip_trustmark_shortcode');
104 add_shortcode('trustedsite_sip', 'Trustedsite::ts_sip_shortcode');
105 add_shortcode('trustedsite_sip_legacy', 'Trustedsite::ts_sip_legacy_shortcode');
106 add_shortcode('trustedsite_banner', 'Trustedsite::ts_banner_shortcode');
107 add_shortcode('trustedsite_testimonial', 'Trustedsite::ts_testimonial_shortcode');
108 add_shortcode('mcafeesecure_hide', 'Trustedsite::hide_floating_trustmark_shortcode');
109 add_shortcode('trustedsite_hide', 'Trustedsite::hide_floating_trustmark_shortcode');
110
111 add_action('admin_menu', 'Trustedsite::admin_menus');
112 add_action('admin_enqueue_scripts', 'Trustedsite::scripts');
113 add_action('update_option_siteurl', 'Trustedsite::ping_siteurl_change');
114 add_action('update_option_admin_email', 'Trustedsite::ping_admin_email_change');
115
116 add_filter('plugin_action_links_trustedsite/trustedsite.php', 'Trustedsite::add_plugin_settings_link');
117
118 if (get_option('mcafeesecure_active') === false) {
119 add_action('do_robots', 'Trustedsite::robots');
120 add_action('wp_footer', 'Trustedsite::inject_code');
121 if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
122 Trustedsite::install_woocommerce();
123 }
124 }
125
126 if (!get_option('trustedsite_install_ping_done')) {
127 Trustedsite::ping_event('install');
128 update_option('trustedsite_install_ping_done', 1);
129 }
130 }
131
132 public static function robots() {
133 if (get_option('trustedsite_robots_enable') == 1) {
134 $site_id = Trustedsite::get_site_id();
135 if(!empty($site_id)){
136 echo "\nSitemap: https://cdn.ywxi.net/sitemap/".$site_id."/1.xml\n";
137 }
138 }
139 }
140
141 public static function inject_sip_modal($order_id) {
142 $order = wc_get_order($order_id);
143 $email = $order->get_billing_email();
144 $first_name = $order->get_billing_first_name();
145 $last_name = $order->get_billing_last_name();
146 $country_code = $order->get_billing_country();
147 $state_code = $order->get_billing_state();
148
149 echo <<<EOT
150 <script type="text/javascript">
151 (function() {
152 var sipScript = document.createElement('script');
153 sipScript.setAttribute("class","trustedsite-track-conversion");
154 sipScript.setAttribute("type","text/javascript");
155 sipScript.setAttribute("data-type","purchase");
156 sipScript.setAttribute("data-orderid", "$order_id");
157 sipScript.setAttribute("data-email", "$email");
158 sipScript.setAttribute("data-firstname", "$first_name");
159 sipScript.setAttribute("data-lastname", "$last_name");
160 sipScript.setAttribute("data-country", "$country_code");
161 sipScript.setAttribute("data-state", "$state_code");
162 sipScript.setAttribute("src", "https://cdn.ywxi.net/js/conversion.js");
163 document.getElementsByTagName("head")[0].appendChild(sipScript);
164 })();
165 </script>
166 EOT;
167 }
168
169 public static function install_woocommerce() {
170 add_action('woocommerce_thankyou', 'Trustedsite::inject_sip_modal');
171 }
172
173 public static function deactivate() {
174 delete_option("trustedsite_active");
175
176 Trustedsite::ping_event('deactivate');
177 }
178
179 public static function uninstall() {
180 delete_option("trustedsite_active");
181 delete_option("trustedsite_data");
182 delete_option("trustedsite_site_id");
183 delete_option("trustedsite_robots_enable");
184 delete_option("trustedsite_install_ping_done");
185
186 Trustedsite::ping_event('uninstall');
187 }
188
189 public static function mfes_engagement_trustmark_shortcode($atts = array()) {
190 $a = shortcode_atts(array(
191 'width' => 90,
192 ), $atts);
193
194 $width = intval($a['width']);
195 return "<div class='mfes-trustmark' data-type='102' data-width=" . $width . " data-ext='svg'></div>";
196 }
197
198 public static function ts_engagement_trustmark_shortcode($atts = array()) {
199 $a = shortcode_atts(array(
200 'width' => 90,
201 ), $atts);
202
203 $width = intval($a['width']);
204 return "<div class='trustedsite-trustmark' data-type='202' data-width=" . $width . " data-ext='svg'></div>";
205 }
206
207 public static function ts_form_engagement_trustmark_shortcode($atts = array()) {
208 $a = shortcode_atts(array(
209 'width' => 90,
210 ), $atts);
211
212 $width = intval($a['width']);
213 return "<div class='trustedsite-trustmark' data-type='211' data-width=" . $width . " data-ext='svg'></div>";
214 }
215
216 public static function ts_checkout_engagement_trustmark_shortcode($atts = array()) {
217 $a = shortcode_atts(array(
218 'width' => 90,
219 ), $atts);
220
221 $width = intval($a['width']);
222 return "<div class='trustedsite-trustmark' data-type='212' data-width=" . $width . " data-ext='svg'></div>";
223 }
224
225 public static function ts_login_engagement_trustmark_shortcode($atts = array()) {
226 $a = shortcode_atts(array(
227 'width' => 90,
228 ), $atts);
229
230 $width = intval($a['width']);
231 return "<div class='trustedsite-trustmark' data-type='213' data-width=" . $width . " data-ext='svg'></div>";
232 }
233
234 public static function mfes_sip_trustmark_shortcode($atts = array()) {
235 $a = shortcode_atts(array(
236 'width' => 90,
237 ), $atts);
238
239 $width = intval($a['width']);
240 return "<div class='mfes-trustmark' data-type='103' data-width=" . $width . " data-ext='svg'></div>";
241 }
242
243 public static function ts_sip_legacy_shortcode($atts = array()) {
244 $a = shortcode_atts(array(
245 'width' => 90,
246 ), $atts);
247
248 $width = intval($a['width']);
249 return"<div class='trustedsite-trustmark' data-type='203' data-width=" . $width . " data-ext='svg'></div>";
250 }
251
252 public static function ts_sip_shortcode($atts = array()) {
253 $a = shortcode_atts(array(
254 'width' => 90,
255 ), $atts);
256
257 $width = intval($a['width']);
258 return"<div class='trustedsite-trustmark' data-type='204' data-width=" . $width . " data-ext='svg'></div>";
259 }
260
261 public static function ts_banner_shortcode($atts = array()) {
262 $a = shortcode_atts(array(
263 'width' => '0',
264 ), $atts);
265
266 $width = intval($a['width']);
267 return"<div class='trustedsite-trustmark' data-type='1001' data-width=" . $width . "></div>";
268 }
269
270 public static function ts_testimonial_shortcode($atts = array()) {
271 $a = shortcode_atts(array(
272 'width' => '0',
273 'height' => '0',
274 ), $atts);
275
276
277 $width = intval($a['width']);
278 $height = intval($a['height']);
279 return"<div class='trustedsite-trustmark' data-type='1002' data-width=" . $width . " data-height=" . $height . "></div>";
280 }
281
282 public static function hide_floating_trustmark_shortcode($atts = array()) {
283 return "<div class='trustedsite-tm-float-disable'></div>";
284 }
285
286 public static function admin_menus() {
287
288 add_options_page(
289 'TrustedSite',
290 'TrustedSite',
291 'activate_plugins',
292 'trustedsite-settings',
293 'Trustedsite::settings_page');
294
295 }
296
297 public static function add_plugin_settings_link($links) {
298 array_unshift( $links, '<a href="options-general.php?page=trustedsite-settings">Settings</a>' );
299 return $links;
300 }
301
302 public static function settings_page() {
303 require WP_PLUGIN_DIR . '/trustedsite/lib/settings_page.php';
304 }
305
306 public static function inject_code() {
307 echo <<<EOT
308 <script type="text/javascript">
309 (function() {
310 var sa = document.createElement('script'); sa.type = 'text/javascript'; sa.async = true;
311 sa.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.ywxi.net/js/1.js';
312 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(sa, s);
313 })();
314 </script>
315 EOT;
316 }
317 }
318
319 ?>
320