Skip to content

Commit 77559af

Browse files
committed
GitHub processing script setup, clone added
Detect if SSL capabilities are available and if not, inform user what they need to do. On cloning, establish local and remote paths and if our root is in the local list, establish the target, zipURL and zipFile path & name Get the zip file over file_get_contents if possible, otherwise cURL. Then unpack the zip into our local folder. The first entry will be the folder inside of the zip, so we get the $dirName of that only to use, this is removed from subsequent file paths When done, remove the zip file and refresh the file manager to show the files
1 parent 20f6e83 commit 77559af

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

lib/github.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
include("headers.php");
3+
include("settings.php");
4+
5+
// SSL check, as everything is over https
6+
$wrappers = stream_get_wrappers();
7+
$sslAvail = true;
8+
if (!extension_loaded('openssl') || !in_array('https', $wrappers)) {
9+
$sslAvail = false;
10+
echo "<script>top.ICEcoder.message('Sorry, you don\'t appear to have OpenSSL loaded on your PHP instance, so https is not available. This is required for GitHub data transfer, please amend php.ini settings, restart your server and try again');top.ICEcoder.showHide('hide',top.get('loadingMask'));</script>";
11+
die();
12+
}
13+
14+
// If we have an action to perform
15+
if (!$demoMode && isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] && isset($_GET['action']) && $sslAvail) {
16+
17+
// =====
18+
// CLONE
19+
// =====
20+
if ($_GET['action']=="clone") {
21+
22+
$iceGithubLocalPaths = $ICEcoder["githubLocalPaths"];
23+
$iceGithubRemotePaths = $ICEcoder["githubRemotePaths"];
24+
$pathPos = array_search($iceRoot,$iceGithubLocalPaths);
25+
if ($pathPos !== false) {
26+
27+
// USE: https://github.com/mattpass/ICEcoder/zipball/master
28+
// Store the plugin zip to the tmp dir
29+
$target = $docRoot.$iceGithubLocalPaths[$pathPos]."/";
30+
$zipURL = $iceGithubRemotePaths[$pathPos].'/zipball/master';
31+
$zipFile = "../tmp/".basename($zipURL);
32+
33+
if (ini_get('allow_url_fopen')) {
34+
$fileData = file_get_contents($zipURL, false, $context);
35+
} elseif (function_exists('curl_init')) {
36+
$client = curl_init($zipURL);
37+
curl_setopt($client, CURLOPT_SSL_VERIFYPEER, false);
38+
curl_setopt($client, CURLOPT_RETURNTRANSFER, 1); //fixed this line
39+
$fileData = curl_exec($client);
40+
}
41+
file_put_contents($zipFile, $fileData);
42+
43+
// Now unpack the zip
44+
$zip = new ZipArchive;
45+
$zip->open($zipFile);
46+
47+
// Create all files & dirs, in 1kb chunks
48+
for($i=0; $i<$zip->numFiles; $i++) {
49+
50+
$name = $zip->getNameIndex($i);
51+
if ($i==0) {
52+
$dirName = $name;
53+
} else {
54+
$name = str_replace($dirName,"",$name);
55+
// Determine output filename
56+
$file = $target.$name;
57+
58+
// Create the directories if necessary
59+
$dir = dirname($file);
60+
if (!is_dir($dir)) mkdir($dir, 0777, true);
61+
62+
// Read from zip and write to disk
63+
$fpr = $zip->getStream($name);
64+
if (!is_dir($file)) {
65+
$fpw = fopen($file, 'w');
66+
while ($data = fread($fpr, 1024)) {
67+
fwrite($fpw, $data);
68+
}
69+
fclose($fpw);
70+
}
71+
fclose($fpr);
72+
}
73+
}
74+
$zip->close();
75+
76+
// Remove the tmp zip file
77+
unlink($zipFile);
78+
79+
// Refresh the file manager
80+
echo "<script>top.ICEcoder.refreshFileManager();</script>";
81+
82+
}
83+
84+
}
85+
86+
}
87+
?>

0 commit comments

Comments
 (0)