diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-11-18 14:07:52 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-11-18 14:07:52 +0100 |
commit | a922eb756eeb5a301772361c22b0d7f40b1f1cb0 (patch) | |
tree | ae27f291902989b5fe5c044499a9fb8c16a1cb4d /lib | |
parent | 3358bface5c20aeb4ad41dc1edffb895bc24af71 (diff) | |
parent | ea80a8b9e3adb4fb091d0d5c80280de683b7b1a3 (diff) | |
download | nextcloud-server-a922eb756eeb5a301772361c22b0d7f40b1f1cb0.tar.gz nextcloud-server-a922eb756eeb5a301772361c22b0d7f40b1f1cb0.zip |
merge master into filesystem
Diffstat (limited to 'lib')
-rw-r--r-- | lib/files.php | 75 | ||||
-rw-r--r-- | lib/helper.php | 31 | ||||
-rw-r--r-- | lib/l10n/ca.php | 6 | ||||
-rw-r--r-- | lib/l10n/de.php | 6 | ||||
-rw-r--r-- | lib/l10n/de_DE.php | 6 | ||||
-rw-r--r-- | lib/l10n/el.php | 7 | ||||
-rw-r--r-- | lib/l10n/es.php | 6 | ||||
-rw-r--r-- | lib/l10n/it.php | 6 | ||||
-rw-r--r-- | lib/l10n/nl.php | 3 | ||||
-rw-r--r-- | lib/l10n/pt_PT.php | 6 | ||||
-rw-r--r-- | lib/ocsclient.php | 13 | ||||
-rwxr-xr-x | lib/util.php | 39 |
12 files changed, 162 insertions, 42 deletions
diff --git a/lib/files.php b/lib/files.php index 3abc8c4aaf2..323d7ddb7e8 100644 --- a/lib/files.php +++ b/lib/files.php @@ -44,8 +44,13 @@ class OC_Files { * @param boolean $only_header ; boolean to only send header of the request */ public static function get($dir, $files, $only_header = false) { - if (strpos($files, ';')) { - $files = explode(';', $files); + $xsendfile = false; + if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || + isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { + $xsendfile = true; + } + if(strpos($files, ';')) { + $files=explode(';', $files); } if (is_array($files)) { @@ -53,8 +58,12 @@ class OC_Files { $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); - $filename = OC_Helper::tmpFile('.zip'); - if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) { + if ($xsendfile) { + $filename = OC_Helper::tmpFileNoClean('.zip'); + }else{ + $filename = OC_Helper::tmpFile('.zip'); + } + if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) { exit("cannot open <$filename>\n"); } foreach ($files as $file) { @@ -74,8 +83,12 @@ class OC_Files { $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); - $filename = OC_Helper::tmpFile('.zip'); - if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) { + if ($xsendfile) { + $filename = OC_Helper::tmpFileNoClean('.zip'); + }else{ + $filename = OC_Helper::tmpFile('.zip'); + } + if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) { exit("cannot open <$filename>\n"); } $file = $dir . '/' . $files; @@ -95,8 +108,13 @@ class OC_Files { ini_set('zlib.output_compression', 'off'); header('Content-Type: application/zip'); header('Content-Length: ' . filesize($filename)); - } else { - header('Content-Type: ' . \OC\Files\Filesystem::getMimeType($filename)); + self::addSendfileHeader($filename); + }else{ + header('Content-Type: '.\OC\Files\Filesystem::getMimeType($filename)); + list($storage, ) = \OC\Files\Filesystem::resolvePath($filename); + if ($storage instanceof \OC\File\Storage\Local) { + self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename)); + } } } elseif ($zip or !\OC\Files\Filesystem::file_exists($filename)) { header("HTTP/1.0 404 Not Found"); @@ -121,8 +139,10 @@ class OC_Files { flush(); } } - unlink($filename); - } else { + if (!$xsendfile) { + unlink($filename); + } + }else{ \OC\Files\Filesystem::readfile($filename); } foreach (self::$tmpFiles as $tmpFile) { @@ -132,19 +152,28 @@ class OC_Files { } } - public static function zipAddDir($dir, $zip, $internalDir = '') { - $dirname = basename($dir); - $zip->addEmptyDir($internalDir . $dirname); - $internalDir .= $dirname .= '/'; - $files = \OC\Files\Filesystem::getDirectoryContent($dir); - foreach ($files as $file) { - $filename = $file['name']; - $file = $dir . '/' . $filename; - if (\OC\Files\Filesystem::is_file($file)) { - $tmpFile = \OC\Files\Filesystem::toTmpFile($file); - OC_Files::$tmpFiles[] = $tmpFile; - $zip->addFile($tmpFile, $internalDir . $filename); - } elseif (\OC\Files\Filesystem::is_dir($file)) { + private static function addSendfileHeader($filename) { + if (isset($_SERVER['MOD_X_SENDFILE_ENABLED'])) { + header("X-Sendfile: " . $filename); + } + if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { + header("X-Accel-Redirect: " . $filename); + } + } + + public static function zipAddDir($dir, $zip, $internalDir='') { + $dirname=basename($dir); + $zip->addEmptyDir($internalDir.$dirname); + $internalDir.=$dirname.='/'; + $files=OC_Files::getDirectoryContent($dir); + foreach($files as $file) { + $filename=$file['name']; + $file=$dir.'/'.$filename; + if(\OC\Files\Filesystem::is_file($file)) { + $tmpFile=\OC\Files\Filesystem::toTmpFile($file); + OC_Files::$tmpFiles[]=$tmpFile; + $zip->addFile($tmpFile, $internalDir.$filename); + }elseif(\OC\Files\Filesystem::is_dir($file)) { self::zipAddDir($file, $zip, $internalDir); } } diff --git a/lib/helper.php b/lib/helper.php index a7fa7be8738..2b63778024d 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -525,6 +525,27 @@ class OC_Helper { } /** + * create a temporary file with an unique filename. It will not be deleted + * automatically + * @param string $postfix + * @return string + * + */ + public static function tmpFileNoClean($postfix='') { + $tmpDirNoClean=get_temp_dir().'/oc-noclean/'; + if (!file_exists($tmpDirNoClean) || !is_dir($tmpDirNoClean)) { + if (file_exists($tmpDirNoClean)) { + unlink($tmpDirNoClean); + } + mkdir($tmpDirNoClean); + } + $file=$tmpDirNoClean.md5(time().rand()).$postfix; + $fh=fopen($file,'w'); + fclose($fh); + return $file; + } + + /** * create a temporary folder with an unique filename * @return string * @@ -560,6 +581,16 @@ class OC_Helper { } /** + * remove all files created by self::tmpFileNoClean + */ + public static function cleanTmpNoClean() { + $tmpDirNoCleanFile=get_temp_dir().'/oc-noclean/'; + if(file_exists($tmpDirNoCleanFile)) { + self::rmdirr($tmpDirNoCleanFile); + } + } + + /** * Adds a suffix to the name in case the file exists * * @param $path diff --git a/lib/l10n/ca.php b/lib/l10n/ca.php index 34ce1c4fe74..b3321ef82e1 100644 --- a/lib/l10n/ca.php +++ b/lib/l10n/ca.php @@ -18,13 +18,17 @@ "seconds ago" => "segons enrere", "1 minute ago" => "fa 1 minut", "%d minutes ago" => "fa %d minuts", +"1 hour ago" => "fa 1 hora", +"%d hours ago" => "fa %d hores", "today" => "avui", "yesterday" => "ahir", "%d days ago" => "fa %d dies", "last month" => "el mes passat", +"%d months ago" => "fa %d mesos", "last year" => "l'any passat", "years ago" => "fa anys", "%s is available. Get <a href=\"%s\">more information</a>" => "%s està disponible. Obtén <a href=\"%s\">més informació</a>", "up to date" => "actualitzat", -"updates check is disabled" => "la comprovació d'actualitzacions està desactivada" +"updates check is disabled" => "la comprovació d'actualitzacions està desactivada", +"Could not find category \"%s\"" => "No s'ha trobat la categoria \"%s\"" ); diff --git a/lib/l10n/de.php b/lib/l10n/de.php index 9398abd7b73..7724d8c684f 100644 --- a/lib/l10n/de.php +++ b/lib/l10n/de.php @@ -18,13 +18,17 @@ "seconds ago" => "Gerade eben", "1 minute ago" => "Vor einer Minute", "%d minutes ago" => "Vor %d Minuten", +"1 hour ago" => "Vor einer Stunde", +"%d hours ago" => "Vor %d Stunden", "today" => "Heute", "yesterday" => "Gestern", "%d days ago" => "Vor %d Tag(en)", "last month" => "Letzten Monat", +"%d months ago" => "Vor %d Monaten", "last year" => "Letztes Jahr", "years ago" => "Vor wenigen Jahren", "%s is available. Get <a href=\"%s\">more information</a>" => "%s ist verfügbar. <a href=\"%s\">Weitere Informationen</a>", "up to date" => "aktuell", -"updates check is disabled" => "Die Update-Überprüfung ist ausgeschaltet" +"updates check is disabled" => "Die Update-Überprüfung ist ausgeschaltet", +"Could not find category \"%s\"" => "Die Kategorie \"%s\" konnte nicht gefunden werden." ); diff --git a/lib/l10n/de_DE.php b/lib/l10n/de_DE.php index c2ff42d8570..95596a7a33a 100644 --- a/lib/l10n/de_DE.php +++ b/lib/l10n/de_DE.php @@ -18,13 +18,17 @@ "seconds ago" => "Gerade eben", "1 minute ago" => "Vor einer Minute", "%d minutes ago" => "Vor %d Minuten", +"1 hour ago" => "Vor einer Stunde", +"%d hours ago" => "Vor %d Stunden", "today" => "Heute", "yesterday" => "Gestern", "%d days ago" => "Vor %d Tag(en)", "last month" => "Letzten Monat", +"%d months ago" => "Vor %d Monaten", "last year" => "Letztes Jahr", "years ago" => "Vor wenigen Jahren", "%s is available. Get <a href=\"%s\">more information</a>" => "%s ist verfügbar. <a href=\"%s\">Weitere Informationen</a>", "up to date" => "aktuell", -"updates check is disabled" => "Die Update-Überprüfung ist ausgeschaltet" +"updates check is disabled" => "Die Update-Überprüfung ist ausgeschaltet", +"Could not find category \"%s\"" => "Die Kategorie \"%s\" konnte nicht gefunden werden." ); diff --git a/lib/l10n/el.php b/lib/l10n/el.php index 71650ae24ae..315b995ecc9 100644 --- a/lib/l10n/el.php +++ b/lib/l10n/el.php @@ -14,16 +14,21 @@ "Token expired. Please reload page." => "Το αναγνωριστικό έληξε. Παρακαλώ φορτώστε ξανά την σελίδα.", "Files" => "Αρχεία", "Text" => "Κείμενο", +"Images" => "Εικόνες", "seconds ago" => "δευτερόλεπτα πριν", "1 minute ago" => "1 λεπτό πριν", "%d minutes ago" => "%d λεπτά πριν", +"1 hour ago" => "1 ώρα πριν", +"%d hours ago" => "%d ώρες πριν", "today" => "σήμερα", "yesterday" => "χθές", "%d days ago" => "%d ημέρες πριν", "last month" => "τον προηγούμενο μήνα", +"%d months ago" => "%d μήνες πριν", "last year" => "τον προηγούμενο χρόνο", "years ago" => "χρόνια πριν", "%s is available. Get <a href=\"%s\">more information</a>" => "%s είναι διαθέσιμα. Δείτε <a href=\"%s\">περισσότερες πληροφορίες</a>", "up to date" => "ενημερωμένο", -"updates check is disabled" => "ο έλεγχος ενημερώσεων είναι απενεργοποιημένος" +"updates check is disabled" => "ο έλεγχος ενημερώσεων είναι απενεργοποιημένος", +"Could not find category \"%s\"" => "Αδυναμία εύρεσης κατηγορίας \"%s\"" ); diff --git a/lib/l10n/es.php b/lib/l10n/es.php index 0019ba02b7f..f843c42dfd3 100644 --- a/lib/l10n/es.php +++ b/lib/l10n/es.php @@ -18,13 +18,17 @@ "seconds ago" => "hace segundos", "1 minute ago" => "hace 1 minuto", "%d minutes ago" => "hace %d minutos", +"1 hour ago" => "Hace 1 hora", +"%d hours ago" => "Hace %d horas", "today" => "hoy", "yesterday" => "ayer", "%d days ago" => "hace %d días", "last month" => "este mes", +"%d months ago" => "Hace %d meses", "last year" => "este año", "years ago" => "hace años", "%s is available. Get <a href=\"%s\">more information</a>" => "%s está disponible. Obtén <a href=\"%s\">más información</a>", "up to date" => "actualizado", -"updates check is disabled" => "comprobar actualizaciones está desactivado" +"updates check is disabled" => "comprobar actualizaciones está desactivado", +"Could not find category \"%s\"" => "No puede encontrar la categoria \"%s\"" ); diff --git a/lib/l10n/it.php b/lib/l10n/it.php index 89e2b05a22f..c0fb0babfb3 100644 --- a/lib/l10n/it.php +++ b/lib/l10n/it.php @@ -18,13 +18,17 @@ "seconds ago" => "secondi fa", "1 minute ago" => "1 minuto fa", "%d minutes ago" => "%d minuti fa", +"1 hour ago" => "1 ora fa", +"%d hours ago" => "%d ore fa", "today" => "oggi", "yesterday" => "ieri", "%d days ago" => "%d giorni fa", "last month" => "il mese scorso", +"%d months ago" => "%d mesi fa", "last year" => "l'anno scorso", "years ago" => "anni fa", "%s is available. Get <a href=\"%s\">more information</a>" => "%s è disponibile. Ottieni <a href=\"%s\">ulteriori informazioni</a>", "up to date" => "aggiornato", -"updates check is disabled" => "il controllo degli aggiornamenti è disabilitato" +"updates check is disabled" => "il controllo degli aggiornamenti è disabilitato", +"Could not find category \"%s\"" => "Impossibile trovare la categoria \"%s\"" ); diff --git a/lib/l10n/nl.php b/lib/l10n/nl.php index cddfd8f97e0..087cf23a627 100644 --- a/lib/l10n/nl.php +++ b/lib/l10n/nl.php @@ -29,5 +29,6 @@ "years ago" => "jaar geleden", "%s is available. Get <a href=\"%s\">more information</a>" => "%s is beschikbaar. Verkrijg <a href=\"%s\">meer informatie</a>", "up to date" => "bijgewerkt", -"updates check is disabled" => "Meest recente versie controle is uitgeschakeld" +"updates check is disabled" => "Meest recente versie controle is uitgeschakeld", +"Could not find category \"%s\"" => "Kon categorie \"%s\" niet vinden" ); diff --git a/lib/l10n/pt_PT.php b/lib/l10n/pt_PT.php index a54cb57578a..84867c4c37c 100644 --- a/lib/l10n/pt_PT.php +++ b/lib/l10n/pt_PT.php @@ -18,13 +18,17 @@ "seconds ago" => "há alguns segundos", "1 minute ago" => "há 1 minuto", "%d minutes ago" => "há %d minutos", +"1 hour ago" => "Há 1 horas", +"%d hours ago" => "Há %d horas", "today" => "hoje", "yesterday" => "ontem", "%d days ago" => "há %d dias", "last month" => "mês passado", +"%d months ago" => "Há %d meses atrás", "last year" => "ano passado", "years ago" => "há anos", "%s is available. Get <a href=\"%s\">more information</a>" => "%s está disponível. Obtenha <a href=\"%s\">mais informação</a>", "up to date" => "actualizado", -"updates check is disabled" => "a verificação de actualizações está desligada" +"updates check is disabled" => "a verificação de actualizações está desligada", +"Could not find category \"%s\"" => "Não foi encontrado a categoria \"%s\"" ); diff --git a/lib/ocsclient.php b/lib/ocsclient.php index b6b5ad8f0a9..e730b159afd 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -55,20 +55,11 @@ class OC_OCSClient{ * This function calls an OCS server and returns the response. It also sets a sane timeout */ private static function getOCSresponse($url) { - // set a sensible timeout of 10 sec to stay responsive even if the server is down. - $ctx = stream_context_create( - array( - 'http' => array( - 'timeout' => 10 - ) - ) - ); - $data=@file_get_contents($url, 0, $ctx); + $data = \OC_Util::getUrlContent($url); return($data); } - - /** + /** * @brief Get all the categories from the OCS server * @returns array with category ids * @note returns NULL if config value appstoreenabled is set to false diff --git a/lib/util.php b/lib/util.php index 9b29bfe9d5c..16dcfc73d7d 100755 --- a/lib/util.php +++ b/lib/util.php @@ -679,4 +679,43 @@ class OC_Util { return false; } + + /** + * @Brief Get file content via curl. + * @param string $url Url to get content + * @return string of the response or false on error + * This function get the content of a page via curl, if curl is enabled. + * If not, file_get_element is used. + */ + + public static function getUrlContent($url){ + + if (function_exists('curl_init')) { + + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_HEADER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_USERAGENT, "ownCloud Server Crawler"); + $data = curl_exec($curl); + curl_close($curl); + + } else { + + $ctx = stream_context_create( + array( + 'http' => array( + 'timeout' => 10 + ) + ) + ); + $data=@file_get_contents($url, 0, $ctx); + + } + + return $data; + } + } |