Created
August 18, 2015 19:34
-
-
Save 01-Scripts/a80f896f684778c5234f to your computer and use it in GitHub Desktop.
Add Post Deploy-Hook as HTTP POST Notification for deployhq.com deploys.
Put the following file in the root directory of your project or adjust the path in line 24.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?PHP | |
$publicKey = "-----BEGIN PUBLIC KEY----- | |
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXJcP2N6NtcN26Q8nVaidXOA0w | |
RxWK2HQTblIaQdGRDjqTvhrSlFuV5N4jz7w/w8uskP20G7ZQ+CkHwIXrWk76KZJn | |
pdoOHPO6AqRmEFgV5Q6Y1CR77mvnT9O21hTnfzfyyiAdQC2oO8M9/jeLRPTAqmkG | |
xdQa8iepUz4BwrrHmwIDAQAB | |
-----END PUBLIC KEY-----"; | |
// Verify integrity of Payload | |
$result = openssl_verify($_POST['payload'], base64_decode($_POST['signature']), $publicKey); | |
if($result && $_SERVER['CONTENT_TYPE'] == "application/x-www-form-urlencoded"){ | |
$json = stripslashes($_POST['payload']); | |
$payload = json_decode($json); | |
if($payload->status == "completed"){ | |
// Get changed files: | |
$SID = $payload->servers[0]->identifier; | |
$ChangedFiles = $payload->files->$SID->changed; | |
// Minify changed files: | |
if(is_array($ChangedFiles)) | |
minify($ChangedFiles); | |
} | |
} | |
/* | |
* JS and CSS Minifier | |
* version: 1.0 (2013-08-26) | |
* | |
* This document is licensed as free software under the terms of the | |
* MIT License: http://www.opensource.org/licenses/mit-license.php | |
* | |
* Toni Almeida wrote this plugin, which proclaims: | |
* "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK." | |
* | |
* This plugin uses online webservices from javascript-minifier.com and cssminifier.com | |
* This services are property of Andy Chilton, http://chilts.org/ | |
* | |
* Copyrighted 2013 by Toni Almeida, promatik. | |
* | |
* Edited 2015 by Michael Lorer, 01-Scripts.de | |
*/ | |
function minify($arr, $addpath="") { | |
foreach ($arr as $file) { | |
$file = $addpath.$file; | |
switch(FileExtension($file)){ | |
case "css": | |
$url = "http://cssminifier.com/raw"; | |
break; | |
case "js": | |
$url = "http://javascript-minifier.com/raw"; | |
break; | |
default: | |
$url = ""; | |
} | |
if(empty($url)) continue; | |
$handler = fopen($file, 'r+'); | |
if(!$handler) continue; | |
$content = file_get_contents($file); | |
ftruncate($handler, 0); | |
fwrite($handler, getMinified($url, $content)); | |
fclose($handler); | |
echo "File <a href='" . $file . "'>" . $file . "</a> done!<br />"; | |
} | |
} | |
function getMinified($url, $content) { | |
$postdata = array('http' => array( | |
'method' => 'POST', | |
'header' => 'Content-type: application/x-www-form-urlencoded', | |
'content' => http_build_query( array('input' => $content) ) ) ); | |
return file_get_contents($url, false, stream_context_create($postdata)); | |
} | |
function FileExtension($filestring){ | |
if(empty($filestring)) return ""; | |
$pathinfo = pathinfo($filestring); | |
return strtolower($pathinfo['extension']); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment