Browse Source

Use Robo to extract zip archive

microsub
J. King 5 years ago
parent
commit
b3566f8d48
  1. 79
      RoboFile.php
  2. 1
      vendor-bin/robo/composer.json
  3. 59
      vendor-bin/robo/composer.lock

79
RoboFile.php

@ -208,49 +208,46 @@ class RoboFile extends \Robo\Tasks {
// compile the stylesheet
$t->taskExec($postcss)->arg($scss)->option("-o", $css);
// download highlight.js
if (extension_loaded("zip")) {
$t->addCode(function() use ($tmp, $themeout) {
$languages = ["php", "bash", "shell", "xml", "nginx", "apache"];
$post = http_build_query((function($langs) {
$out = [];
foreach($langs as $l) {
$out[$l.".js"] = "on";
}
return $out;
})($languages));
$conn = @fopen("https://highlightjs.org/download/", "r");
if ($conn === false) {
throw new Exception("Unable to download Highlight.js");
$t->addCode(function() use ($tmp, $themeout) {
$languages = ["php", "bash", "shell", "xml", "nginx", "apache"];
$post = http_build_query((function($langs) {
$out = [];
foreach($langs as $l) {
$out[$l.".js"] = "on";
}
foreach (stream_get_meta_data($conn)['wrapper_data'] as $field) {
if (preg_match("/^Set-Cookie: csrftoken=([^;]+)/i", $field, $cookie)) {
break;
}
return $out;
})($languages));
$conn = @fopen("https://highlightjs.org/download/", "r");
if ($conn === false) {
throw new Exception("Unable to download Highlight.js");
}
foreach (stream_get_meta_data($conn)['wrapper_data'] as $field) {
if (preg_match("/^Set-Cookie: csrftoken=([^;]+)/i", $field, $cookie)) {
break;
}
$token = stream_get_contents($conn);
preg_match("/<input type='hidden' name='csrfmiddlewaretoken' value='([^']*)'/", $token, $token);
$post = "csrfmiddlewaretoken={$token[1]}&$post";
$hljs = @file_get_contents("https://highlightjs.org/download/", false, stream_context_create(['http' => [
'method' => "POST",
'content' => $post,
'header' => [
"Referer: https://highlightjs.org/download/",
"Cookie: csrftoken={$cookie[1]}",
"Content-Type: application/x-www-form-urlencoded",
],
]]));
if ($hljs === false) {
throw new Exception("Unable to download Highlight.js");
} else {
file_put_contents($tmp."highlightjs.zip", $hljs);
}
$z = new \ZipArchive;
$z->open($tmp."highlightjs.zip");
$z->extractTo($themeout, "highlight.pack.js");
}, "downloadHighlightjs");
} else {
$this->say("Zip extension not installed; not updating hightlight.js");
}
}
$token = stream_get_contents($conn);
preg_match("/<input type='hidden' name='csrfmiddlewaretoken' value='([^']*)'/", $token, $token);
$post = "csrfmiddlewaretoken={$token[1]}&$post";
$hljs = @file_get_contents("https://highlightjs.org/download/", false, stream_context_create(['http' => [
'method' => "POST",
'content' => $post,
'header' => [
"Referer: https://highlightjs.org/download/",
"Cookie: csrftoken={$cookie[1]}",
"Content-Type: application/x-www-form-urlencoded",
],
]]));
if ($hljs === false) {
throw new Exception("Unable to download Highlight.js");
} else {
file_put_contents($tmp."highlightjs.zip", $hljs);
}
$this->taskExtract($tmp."highlightjs.zip")->to($tmp."hljs")->run();
$this->taskFilesystemStack()->copy($tmp."hljs/highlight.pack.js", $themeout."/highlight.pack.js")->run();
}, "downloadHighlightjs");
// copy JavaScript files from the Daux theme
# TODO
// execute the collection
return $t->run();
}

1
vendor-bin/robo/composer.json

@ -5,6 +5,5 @@
"symfony/process": "^3.0"
},
"require-dev": {
"splitbrain/php-archive": "^1.1"
}
}

59
vendor-bin/robo/composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0f7d93d4c470b72b0f6f0bc0317d603f",
"content-hash": "d95cf402fed434140db8ae87c3c8bf32",
"packages": [
{
"name": "consolidation/annotated-command",
@ -1734,62 +1734,7 @@
"time": "2019-04-06T14:04:46+00:00"
}
],
"packages-dev": [
{
"name": "splitbrain/php-archive",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/splitbrain/php-archive.git",
"reference": "10d89013572ba1f4d4ad7fcb74860242f4c3860b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/splitbrain/php-archive/zipball/10d89013572ba1f4d4ad7fcb74860242f4c3860b",
"reference": "10d89013572ba1f4d4ad7fcb74860242f4c3860b",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"require-dev": {
"ext-bz2": "*",
"ext-zip": "*",
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^4.8"
},
"suggest": {
"ext-iconv": "Used for proper filename encode handling",
"ext-mbstring": "Can be used alternatively for handling filename encoding"
},
"type": "library",
"autoload": {
"psr-4": {
"splitbrain\\PHPArchive\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Andreas Gohr",
"email": "andi@splitbrain.org"
}
],
"description": "Pure-PHP implementation to read and write TAR and ZIP archives",
"keywords": [
"archive",
"extract",
"tar",
"unpack",
"unzip",
"zip"
],
"time": "2018-09-09T12:13:53+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],

Loading…
Cancel
Save