From 77559afe600d03a002364fbb39cc3918c3e0e92f Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Tue, 3 Jun 2014 09:30:55 +0100 Subject: [PATCH] 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 --- lib/github.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 lib/github.php diff --git a/lib/github.php b/lib/github.php new file mode 100644 index 0000000..1769829 --- /dev/null +++ b/lib/github.php @@ -0,0 +1,87 @@ +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'));"; + die(); +} + +// If we have an action to perform +if (!$demoMode && isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] && isset($_GET['action']) && $sslAvail) { + + // ===== + // CLONE + // ===== + if ($_GET['action']=="clone") { + + $iceGithubLocalPaths = $ICEcoder["githubLocalPaths"]; + $iceGithubRemotePaths = $ICEcoder["githubRemotePaths"]; + $pathPos = array_search($iceRoot,$iceGithubLocalPaths); + if ($pathPos !== false) { + + // USE: https://github.com/mattpass/ICEcoder/zipball/master + // Store the plugin zip to the tmp dir + $target = $docRoot.$iceGithubLocalPaths[$pathPos]."/"; + $zipURL = $iceGithubRemotePaths[$pathPos].'/zipball/master'; + $zipFile = "../tmp/".basename($zipURL); + + if (ini_get('allow_url_fopen')) { + $fileData = file_get_contents($zipURL, false, $context); + } elseif (function_exists('curl_init')) { + $client = curl_init($zipURL); + curl_setopt($client, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($client, CURLOPT_RETURNTRANSFER, 1); //fixed this line + $fileData = curl_exec($client); + } + file_put_contents($zipFile, $fileData); + + // Now unpack the zip + $zip = new ZipArchive; + $zip->open($zipFile); + + // Create all files & dirs, in 1kb chunks + for($i=0; $i<$zip->numFiles; $i++) { + + $name = $zip->getNameIndex($i); + if ($i==0) { + $dirName = $name; + } else { + $name = str_replace($dirName,"",$name); + // Determine output filename + $file = $target.$name; + + // Create the directories if necessary + $dir = dirname($file); + if (!is_dir($dir)) mkdir($dir, 0777, true); + + // Read from zip and write to disk + $fpr = $zip->getStream($name); + if (!is_dir($file)) { + $fpw = fopen($file, 'w'); + while ($data = fread($fpr, 1024)) { + fwrite($fpw, $data); + } + fclose($fpw); + } + fclose($fpr); + } + } + $zip->close(); + + // Remove the tmp zip file + unlink($zipFile); + + // Refresh the file manager + echo ""; + + } + + } + +} +?> \ No newline at end of file