PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 2.8.17 All 260 releases
wpfunnels / vendor / posthog / posthog-php / send.php

send.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.1, at vendor/posthog/posthog-php/send.php

106 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once __DIR__ . '/vendor/autoload.php';
4
5 /**
6 * require client
7 */
8
9 use PostHog\PostHog;
10
11 /**
12 * Args
13 */
14
15 $args = parse($argv);
16
17 /**
18 * Make sure both are set
19 */
20
21 if (!isset($args["apiKey"])) die("--apiKey must be given");
22 if (!isset($args["file"])) die("--file must be given");
23
24 $file = $args["file"];
25 if ($file[0] != '/') $file = __DIR__ . "/" . $file;
26
27 /**
28 * Rename the file so we don't write the same calls
29 * multiple times
30 */
31
32 $dir = dirname($file);
33 $old = $file;
34 $file = $dir . '/posthog-' . rand() . '.log';
35
36 if(!file_exists($old)) {
37 print("file: $old does not exist");
38 exit(0);
39 }
40
41 if (!rename($old, $file)) {
42 print("error renaming from $old to $file\n");
43 exit(1);
44 }
45
46 /**
47 * File contents.
48 */
49
50 $contents = file_get_contents($file);
51 $lines = explode("\n", $contents);
52
53 /**
54 * Initialize the client.
55 */
56
57 PostHog::init($args["apiKey"], array(
58 "debug" => true,
59 "error_handler" => function($code, $msg){
60 print("$code: $msg\n");
61 exit(1);
62 }
63 ));
64
65 /**
66 * Payloads
67 */
68
69 $total = 0;
70 $successful = 0;
71 foreach ($lines as $line) {
72 if (!trim($line)) continue;
73 $payload = json_decode($line, true);
74 $type = $payload["type"];
75 $ret = call_user_func_array(array("PostHog\\PostHog", "raw"), array($payload));
76 if ($ret) $successful++;
77 $total++;
78 if ($total % 100 === 0) PostHog::flush();
79 }
80
81 PostHog::flush();
82 unlink($file);
83
84 /**
85 * Sent
86 */
87
88 print("sent $successful from $total requests successfully");
89 exit(0);
90
91 /**
92 * Parse arguments
93 */
94
95 function parse($argv){
96 $ret = array();
97
98 for ($i = 0; $i < count($argv); ++$i) {
99 $arg = $argv[$i];
100 if ('--' != substr($arg, 0, 2)) continue;
101 $ret[substr($arg, 2, strlen($arg))] = trim($argv[++$i]);
102 }
103
104 return $ret;
105 }
106