PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.77
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.77
9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 8.5.4 All 221 releases
wpvr / vendor / posthog / posthog-php / send.php

send.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.77, 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