Example #1
0
 private static function _set_meta($data, $id)
 {
     $sourcefile = $id . ".meta";
     if (file_exists($sourcefile)) {
         $data = sys_build_meta(file_get_contents($sourcefile), $data);
     }
     $drop = array("filedata", "folder", "created", "lastmodified", "handler", "mfolder", "dsize", "id");
     $data = sys_build_meta_str($data, array_diff(array_keys($data), $drop));
     if ($data == "") {
         @unlink($sourcefile);
     } else {
         file_put_contents($sourcefile, $data, LOCK_EX);
     }
 }
Example #2
0
 static function update($path, $data, $where, $vars, $mfolder)
 {
     if (empty($vars["id"])) {
         return "";
     }
     if (!empty($data["filedata"])) {
         $source = $data["filedata"];
     } else {
         $source = $vars["id"];
     }
     if (!empty($vars["folder_source"])) {
         return self::_move_file($vars["id"], $vars["folder_source"], $path, $mfolder);
     }
     $drop = array("filedata", "folder", "lastmodified", "handler", "mfolder", "dsize");
     $meta = sys_build_meta_str($data, array_diff(array_keys($data), $drop));
     $content = "<?xml version='1.0' encoding='UTF-8'?>" . "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:docs='http://schemas.google.com/docs/2007'>" . "<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/docs/2007#document'/>" . "<title>" . q(modify::basename($source)) . "</title>" . "<docs:description>" . q($meta) . "</docs:description></entry>";
     if (file_exists($source) and sys_strbegins($source, SIMPLE_CACHE . "/upload/")) {
         $url = "https://docs.google.com/feeds/upload/create-session/default/private/full/" . $vars["id"] . "?convert=false";
         $header = "X-Upload-Content-Type: application/octet-stream\r\n";
         $context = self::_get_context_action($mfolder, "PUT", $content, $header);
         $http_response_header = array();
         $response = file_get_contents($url, false, $context);
         preg_match("/Location: (.+)/m", implode("\n", $http_response_header), $match);
         if (!strpos($http_response_header[0], "200") or empty($match[1])) {
             return "{t}Error{/t} [update] " . implode("\n", $http_response_header) . "\n" . $response;
         }
         $header = "PUT " . $match[1] . " HTTP/1.0\r\n";
         $header .= "Host: docs.google.com\r\n";
         $header .= "Content-Length: " . filesize($source) . "\r\n\r\n";
         $errorNumber = 0;
         $errorString = "";
         $fp = fsockopen("ssl://docs.google.com", "443", $errorNumber, $errorString, 5);
         $fin = fopen($source, "rb");
         if (is_resource($fp) and is_resource($fin)) {
             fwrite($fp, $header);
             while (!feof($fin)) {
                 fwrite($fp, fread($fin, 8192));
             }
             $resp = "";
             while (!feof($fp)) {
                 $resp .= fread($fp, 8192);
             }
             fclose($fp);
             fclose($fin);
             if (!sys_strbegins($resp, "HTTP/1.0 200")) {
                 return "{t}Error{/t} [update2] " . $resp;
             }
         } else {
             return "{t}Error{/t} [update3] " . $errorString . " " . $errorNumber;
         }
     } else {
         $url = "https://docs.google.com/feeds/default/private/full/" . $vars["id"] . "?convert=false";
         $context = self::_get_context_action($mfolder, "PUT", $content);
         $http_response_header = array();
         $response = file_get_contents($url, false, $context);
         if (!strpos($http_response_header[0], "200")) {
             return "{t}Error{/t} [update4] " . $http_response_header . "\n" . $response;
         }
     }
     sys_cache_remove("gdocs_xml_" . md5(serialize(sys_credentials($mfolder)) . $path));
     return "";
 }
Example #3
0
 private static function _set_meta($data, $id, $mfolder, $ntlm)
 {
     $w = new Java("jcifs.smb.SmbFile", "smb://" . $id, $ntlm);
     $lastmodified = $w->getLastModified() / 1000;
     $sourcefile = sys_cache_get_file("cifs", $id . $lastmodified, "--" . modify::basename($id . ".meta"), true);
     if (file_exists($sourcefile)) {
         $data = sys_build_meta(file_get_contents($sourcefile), $data);
     }
     $drop = array("filedata", "folder", "created", "lastmodified", "handler", "mfolder", "dsize", "id");
     $data = sys_build_meta_str($data, array_diff(array_keys($data), $drop));
     if ($data == "") {
         $w = new Java("jcifs.smb.SmbFile", "smb://" . $id . ".meta", $ntlm);
         if ($w->exists()) {
             $w->delete();
         }
     } else {
         file_put_contents($sourcefile, $data, LOCK_EX);
         $in = new Java("java.io.FileInputStream", modify::realfilename($sourcefile, false));
         $w = new Java("jcifs.smb.SmbFile", "smb://" . $id . ".meta", $ntlm);
         $w->load($in);
     }
 }