// Define $thiscloud } if ($thiscloud["cloudnum"] == 1) { // If Webdav $url = isset($_GET["url"]) ? $_GET["url"] : $thiscloud["url"]; // rawurlencode(); if (isset($_GET["file"])) { // If Webdav File $prop = davPROP($url, $thiscloud["username"], mcrypt_ecb(MCRYPT_3DES, MCRYPTKEY, $thiscloud["password"], MCRYPT_DECRYPT)); $status = $prop["info"]["http_code"]; if ($status < 400) { $xml = xmlstr_to_array(strstr($prop["result"], '<?xml')); $xml = $xml['d:response']; $fname = $xml["d:propstat"]["d:prop"]["d:displayname"]; $type = $xml["d:propstat"]["d:prop"]["d:getcontenttype"]; $get = davGET($url, $thiscloud["username"], mcrypt_ecb(MCRYPT_3DES, MCRYPTKEY, $thiscloud["password"], MCRYPT_DECRYPT)); header("Content-disposition: attachment; filename={$fname}"); header("Content-type: {$type}"); echo $get; exit; } else { apologize("Error {$status} - An unexpected error occurred."); } } else { // If Webdav Folder $prop = davPROP($url, $thiscloud["username"], mcrypt_ecb(MCRYPT_3DES, MCRYPTKEY, $thiscloud["password"], MCRYPT_DECRYPT)); $status = $prop["info"]["http_code"]; if ($status < 400) { if (strpos($prop["result"], '<?xml') !== false) { $xml = xmlstr_to_array(strstr($prop["result"], '<?xml')); $xml = $xml['d:response'];
function sync($davlink, $drivelink, $service) { $davarray = parsedavfolder($davlink); $drivearray = parsedrivefolder($drivelink, $service); function f1($a, $b) { // Same in Dav return strcmp($a['name'], $b['name']); } $same = array_values(array_uintersect($davarray, $drivearray, "f1")); function f2($a, $b) { // Same in Drive return strcmp($a['name'], $b['name']); } $sameindrive = array_values(array_uintersect($drivearray, $davarray, "f2")); function f3($a, $b) { // Sort by name return strcmp($a['name'], $b['name']); } usort($same, "f3"); function f4($a, $b) { // Sort by name return strcmp($a['name'], $b['name']); } usort($sameindrive, "f4"); // For Same Filename for ($i = 0; $i < count($same); $i++) { if ($same[$i]['folder'] == "t") { sync($same[$i]["href"], $sameindrive[$i]["id"], $service); echo $same[$i]["name"] . " is same folder\n"; } elseif ($same[$i]["modified"] > $sameindrive[$i]["modified"]) { echo $same[$i]["name"] . " is same file\n"; $file = davGET($same[$i]["url"], DAVUSERNAME, DAVPASS); if (md5($file) != $sameindrive[$i]["md5"]) { // todo: Update file in Drive } else { // todo: update modtime in Drive } } } // For Dav file not in Drive function f5($a, $b) { return strcmp($a['name'], $b['name']); } $davfilesnotindrive = array_udiff($davarray, $drivearray, "f5"); foreach ($davfilesnotindrive as $keydav) { if ($keydav["folder"] == "t") { echo $keydav["name"] . "is dav folder not in drive\n"; // todo: check for moves, renames, both and then: // Insert folder into Drive, // write function to recursively insert contents(folders/files) into drive } else { echo $keydav["name"] . "is dav file not in drive\n"; // todo: check for moves, renames, both and then Insert new file into Drive } } // For Drive file not in Dav function f6($a, $b) { return strcmp($a['name'], $b['name']); } $drivefilesnotindav = array_udiff($drivearray, $davarray, "f6"); foreach ($drivefilesnotindav as $keydrive) { if ($keydrive["folder"] == "t") { echo $keydrive["name"] . "is drive folder not in dav\n"; // todo: check for moves, renames, both and then delete from Drive } else { echo $keydrive["name"] . "is drive file not in dav\n"; // todo: check for moves, renames, both and then delete from Drive } } }