예제 #1
0
function har_shortcode($params)
{
    wp_enqueue_script('requirejs');
    wp_enqueue_script('dragdrop');
    $options = get_option('harviewer_options');
    har_log($options);
    $values = shortcode_atts(array('path' => '', 'height' => $options['height'], 'resizer' => $options['resizer'], 'expand' => $options['expand'], 'loader' => $options['loader']), $params);
    // Body of the HAR tag is an IFRAME
    $body = '';
    if ($values['path'] != '') {
        return get_preview_body($values);
    }
    return $body;
}
예제 #2
0
function ProcessTest($id)
{
    global $tempDir;
    global $name;
    global $count;
    global $total;
    $ok = false;
    $testPath = './' . GetTestPath($id);
    $restored = false;
    if (!is_dir($testPath)) {
        // try restoring the test several times in case there are network issues
        $attempt = 0;
        do {
            $attempt++;
            har_log("{$id} - restoring test ({$attempt})");
            RestoreTest($id);
            if (is_dir($testPath)) {
                $restored = true;
            } else {
                sleep(1);
            }
        } while (!$restored && $attempt < 120);
    }
    if (is_dir($testPath)) {
        har_log("{$id} - generating HAR");
        $har = GenerateHAR($id, $testPath, ['bodies' => 1, 'run' => 'median', 'cached' => 0]);
        if (isset($har) && strlen($har)) {
            gz_file_put_contents("{$tempDir}/{$id}.har", $har);
            unset($har);
            $file = "{$tempDir}/{$id}.har.gz";
            if (is_file($file)) {
                $file = realpath($file);
                $remoteFile = "{$name}/{$id}.har.gz";
                $bucket = 'httparchive';
                har_log("{$id} - Uploading to {$remoteFile}");
                if (gsUpload($file, $bucket, $remoteFile)) {
                    $ok = true;
                } else {
                    har_log("{$id} - error uploading HAR");
                }
                unlink($file);
            } else {
                har_log("{$id} - error saving HAR");
            }
        } else {
            har_log("{$id} - error generating HAR");
        }
        // clean up the test if we restored it
        if ($restored) {
            delTree($testPath, true);
        }
    } else {
        har_log("{$id} - error restoring test");
    }
    return $ok;
}