summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-13 20:56:49 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-13 20:56:49 +0200
commit5b3388c7c4c37492627700c38b385f31a397fb91 (patch)
tree8bac096896f14f5468da359ee80678956cab6563 /lib
parent206f83941b26b16f89e695ae84b998e9cf11132a (diff)
parentc149b57d3b4020c65d33966d5dc8395b8b821fc9 (diff)
downloadnextcloud-server-5b3388c7c4c37492627700c38b385f31a397fb91.tar.gz
nextcloud-server-5b3388c7c4c37492627700c38b385f31a397fb91.zip
Merge branch 'master' into appframework-master
Diffstat (limited to 'lib')
-rw-r--r--lib/app.php22
-rw-r--r--lib/archive.php3
-rw-r--r--lib/base.php32
-rw-r--r--lib/cache/file.php11
-rw-r--r--lib/cache/fileglobal.php20
-rw-r--r--lib/connector/sabre/objecttree.php8
-rw-r--r--lib/db.php12
-rw-r--r--lib/files/cache/scanner.php28
-rw-r--r--lib/files/storage/common.php21
-rw-r--r--lib/files/storage/mappedlocal.php18
-rw-r--r--lib/files/view.php99
-rw-r--r--lib/helper.php100
-rw-r--r--lib/image.php306
-rw-r--r--lib/installer.php10
-rw-r--r--lib/l10n/ach.php8
-rw-r--r--lib/l10n/es.php24
-rw-r--r--lib/l10n/es_AR.php22
-rw-r--r--lib/l10n/es_MX.php8
-rw-r--r--lib/l10n/fr.php26
-rw-r--r--lib/l10n/it.php1
-rw-r--r--lib/l10n/ja_JP.php14
-rw-r--r--lib/l10n/nn_NO.php10
-rw-r--r--lib/l10n/nqo.php8
-rw-r--r--lib/l10n/pl.php22
-rw-r--r--lib/l10n/pt_BR.php8
-rw-r--r--lib/l10n/pt_PT.php8
-rw-r--r--lib/l10n/sq.php8
-rw-r--r--lib/migration/content.php3
-rw-r--r--lib/ocs/activity.php28
-rw-r--r--lib/ocsclient.php49
-rwxr-xr-xlib/preview.php627
-rw-r--r--lib/preview/image.php36
-rw-r--r--lib/preview/movies.php47
-rw-r--r--lib/preview/mp3.php48
-rw-r--r--lib/preview/office-cl.php134
-rw-r--r--lib/preview/office-fallback.php142
-rw-r--r--lib/preview/office.php22
-rw-r--r--lib/preview/pdf.php40
-rw-r--r--lib/preview/provider.php19
-rw-r--r--lib/preview/svg.php46
-rw-r--r--lib/preview/txt.php73
-rw-r--r--lib/preview/unknown.php27
-rw-r--r--lib/public/preview.php34
-rw-r--r--lib/public/share.php11
-rw-r--r--lib/public/template.php19
-rw-r--r--lib/setup.php2
-rw-r--r--lib/setup/mysql.php2
-rw-r--r--lib/setup/oci.php2
-rw-r--r--lib/setup/postgresql.php2
-rw-r--r--lib/template/functions.php16
-rw-r--r--lib/templatelayout.php4
-rw-r--r--lib/user.php2
-rwxr-xr-xlib/util.php514
53 files changed, 2190 insertions, 616 deletions
diff --git a/lib/app.php b/lib/app.php
index 8f5dd1d685e..d98af2dc296 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -73,11 +73,11 @@ class OC_App{
if (!defined('DEBUG') || !DEBUG) {
if (is_null($types)
- && empty(OC_Util::$core_scripts)
- && empty(OC_Util::$core_styles)) {
- OC_Util::$core_scripts = OC_Util::$scripts;
+ && empty(OC_Util::$coreScripts)
+ && empty(OC_Util::$coreStyles)) {
+ OC_Util::$coreScripts = OC_Util::$scripts;
OC_Util::$scripts = array();
- OC_Util::$core_styles = OC_Util::$styles;
+ OC_Util::$coreStyles = OC_Util::$styles;
OC_Util::$styles = array();
}
}
@@ -667,14 +667,16 @@ class OC_App{
}
$dh = opendir( $apps_dir['path'] );
- while (($file = readdir($dh)) !== false) {
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
- if ($file[0] != '.' and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php')) {
+ if ($file[0] != '.' and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php')) {
- $apps[] = $file;
+ $apps[] = $file;
- }
+ }
+ }
}
}
@@ -868,10 +870,10 @@ class OC_App{
/**
- * Compares the app version with the owncloud version to see if the app
+ * Compares the app version with the owncloud version to see if the app
* requires a newer version than the currently active one
* @param array $owncloudVersions array with 3 entries: major minor bugfix
- * @param string $appRequired the required version from the xml
+ * @param string $appRequired the required version from the xml
* major.minor.bugfix
* @return boolean true if compatible, otherwise false
*/
diff --git a/lib/archive.php b/lib/archive.php
index 364cd5a74a1..85bfae57295 100644
--- a/lib/archive.php
+++ b/lib/archive.php
@@ -119,7 +119,8 @@ abstract class OC_Archive{
* @return bool
*/
function addRecursive($path, $source) {
- if($dh=opendir($source)) {
+ $dh = opendir($source);
+ if(is_resource($dh)) {
$this->addFolder($path);
while (($file = readdir($dh)) !== false) {
if($file=='.' or $file=='..') {
diff --git a/lib/base.php b/lib/base.php
index 5e99838a41c..76779f66d16 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -425,7 +425,7 @@ class OC {
}
self::initPaths();
- OC_Util::issetlocaleworking();
+ OC_Util::isSetLocaleWorking();
// set debug mode if an xdebug session is active
if (!defined('DEBUG') || !DEBUG) {
@@ -500,6 +500,7 @@ class OC {
self::registerCacheHooks();
self::registerFilesystemHooks();
+ self::registerPreviewHooks();
self::registerShareHooks();
self::registerLogRotate();
@@ -536,7 +537,7 @@ class OC {
}
// write error into log if locale can't be set
- if (OC_Util::issetlocaleworking() == false) {
+ if (OC_Util::isSetLocaleWorking() == false) {
OC_Log::write('core',
'setting locale to en_US.UTF-8/en_US.UTF8 failed. Support is probably not installed on your system',
OC_Log::ERROR);
@@ -588,6 +589,14 @@ class OC {
}
/**
+ * register hooks for previews
+ */
+ public static function registerPreviewHooks() {
+ OC_Hook::connect('OC_Filesystem', 'post_write', 'OC\Preview', 'post_write');
+ OC_Hook::connect('OC_Filesystem', 'delete', 'OC\Preview', 'post_delete');
+ }
+
+ /**
* register hooks for sharing
*/
public static function registerShareHooks() {
@@ -767,7 +776,7 @@ class OC {
if (in_array($_COOKIE['oc_token'], $tokens, true)) {
// replace successfully used token with a new one
OC_Preferences::deleteKey($_COOKIE['oc_username'], 'login_token', $_COOKIE['oc_token']);
- $token = OC_Util::generate_random_bytes(32);
+ $token = OC_Util::generateRandomBytes(32);
OC_Preferences::setValue($_COOKIE['oc_username'], 'login_token', $token, time());
OC_User::setMagicInCookie($_COOKIE['oc_username'], $token);
// login
@@ -807,7 +816,7 @@ class OC {
if (defined("DEBUG") && DEBUG) {
OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG);
}
- $token = OC_Util::generate_random_bytes(32);
+ $token = OC_Util::generateRandomBytes(32);
OC_Preferences::setValue($userid, 'login_token', $token, time());
OC_User::setMagicInCookie($userid, $token);
} else {
@@ -825,16 +834,11 @@ class OC {
) {
return false;
}
- // don't redo authentication if user is already logged in
- // otherwise session would be invalidated in OC_User::login with
- // session_regenerate_id at every page load
- if (!OC_User::isLoggedIn()) {
- OC_App::loadApps(array('authentication'));
- if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
- //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG);
- OC_User::unsetMagicInCookie();
- $_SERVER['HTTP_REQUESTTOKEN'] = OC_Util::callRegister();
- }
+ OC_App::loadApps(array('authentication'));
+ if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
+ //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG);
+ OC_User::unsetMagicInCookie();
+ $_SERVER['HTTP_REQUESTTOKEN'] = OC_Util::callRegister();
}
return true;
}
diff --git a/lib/cache/file.php b/lib/cache/file.php
index 9fee6034a71..361138e4736 100644
--- a/lib/cache/file.php
+++ b/lib/cache/file.php
@@ -80,9 +80,11 @@ class OC_Cache_File{
$storage = $this->getStorage();
if($storage and $storage->is_dir('/')) {
$dh=$storage->opendir('/');
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
- $storage->unlink('/'.$file);
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
+ $storage->unlink('/'.$file);
+ }
}
}
}
@@ -94,6 +96,9 @@ class OC_Cache_File{
if($storage and $storage->is_dir('/')) {
$now = time();
$dh=$storage->opendir('/');
+ if(!is_resource($dh)) {
+ return null;
+ }
while (($file = readdir($dh)) !== false) {
if($file!='.' and $file!='..') {
$mtime = $storage->filemtime('/'.$file);
diff --git a/lib/cache/fileglobal.php b/lib/cache/fileglobal.php
index 2fbd8ca3edb..c0bd8e45f39 100644
--- a/lib/cache/fileglobal.php
+++ b/lib/cache/fileglobal.php
@@ -69,9 +69,11 @@ class OC_Cache_FileGlobal{
$prefix = $this->fixKey($prefix);
if($cache_dir and is_dir($cache_dir)) {
$dh=opendir($cache_dir);
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
- unlink($cache_dir.$file);
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)) {
+ unlink($cache_dir.$file);
+ }
}
}
}
@@ -88,11 +90,13 @@ class OC_Cache_FileGlobal{
$cache_dir = self::getCacheDir();
if($cache_dir and is_dir($cache_dir)) {
$dh=opendir($cache_dir);
- while (($file = readdir($dh)) !== false) {
- if($file!='.' and $file!='..') {
- $mtime = filemtime($cache_dir.$file);
- if ($mtime < $now) {
- unlink($cache_dir.$file);
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if($file!='.' and $file!='..') {
+ $mtime = filemtime($cache_dir.$file);
+ if ($mtime < $now) {
+ unlink($cache_dir.$file);
+ }
}
}
}
diff --git a/lib/connector/sabre/objecttree.php b/lib/connector/sabre/objecttree.php
index b298813a202..acff45ed5e2 100644
--- a/lib/connector/sabre/objecttree.php
+++ b/lib/connector/sabre/objecttree.php
@@ -88,11 +88,13 @@ class ObjectTree extends \Sabre_DAV_ObjectTree {
} else {
Filesystem::mkdir($destination);
$dh = Filesystem::opendir($source);
- while (($subnode = readdir($dh)) !== false) {
+ if(is_resource($dh)) {
+ while (($subnode = readdir($dh)) !== false) {
- if ($subnode == '.' || $subnode == '..') continue;
- $this->copy($source . '/' . $subnode, $destination . '/' . $subnode);
+ if ($subnode == '.' || $subnode == '..') continue;
+ $this->copy($source . '/' . $subnode, $destination . '/' . $subnode);
+ }
}
}
diff --git a/lib/db.php b/lib/db.php
index ebd012c72f8..f090f474243 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -330,18 +330,6 @@ class OC_DB {
}
/**
- * @brief Disconnect
- *
- * This is good bye, good bye, yeah!
- */
- public static function disconnect() {
- // Cut connection if required
- if(self::$connection) {
- self::$connection->close();
- }
- }
-
- /**
* @brief saves database schema to xml file
* @param string $file name of file
* @param int $mode
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 87fa7c1365a..9d180820e9d 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -159,20 +159,22 @@ class Scanner extends BasicEmitter {
$newChildren = array();
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
- while (($file = readdir($dh)) !== false) {
- $child = ($path) ? $path . '/' . $file : $file;
- if (!Filesystem::isIgnoredDir($file)) {
- $newChildren[] = $file;
- $data = $this->scanFile($child, $reuse, true);
- if ($data) {
- if ($data['size'] === -1) {
- if ($recursive === self::SCAN_RECURSIVE) {
- $childQueue[] = $child;
- } else {
- $size = -1;
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ $child = ($path) ? $path . '/' . $file : $file;
+ if (!Filesystem::isIgnoredDir($file)) {
+ $newChildren[] = $file;
+ $data = $this->scanFile($child, $reuse, true);
+ if ($data) {
+ if ($data['size'] === -1) {
+ if ($recursive === self::SCAN_RECURSIVE) {
+ $childQueue[] = $child;
+ } else {
+ $size = -1;
+ }
+ } else if ($size !== -1) {
+ $size += $data['size'];
}
- } else if ($size !== -1) {
- $size += $data['size'];
}
}
}
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php
index 01560f34fde..a5b79f0e967 100644
--- a/lib/files/storage/common.php
+++ b/lib/files/storage/common.php
@@ -142,13 +142,15 @@ abstract class Common implements \OC\Files\Storage\Storage {
return false;
} else {
$directoryHandle = $this->opendir($directory);
- while (($contents = readdir($directoryHandle)) !== false) {
- if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
- $path = $directory . '/' . $contents;
- if ($this->is_dir($path)) {
- $this->deleteAll($path);
- } else {
- $this->unlink($path);
+ if(is_resource($directoryHandle)) {
+ while (($contents = readdir($directoryHandle)) !== false) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
+ $path = $directory . '/' . $contents;
+ if ($this->is_dir($path)) {
+ $this->deleteAll($path);
+ } else {
+ $this->unlink($path);
+ }
}
}
}
@@ -224,7 +226,8 @@ abstract class Common implements \OC\Files\Storage\Storage {
}
private function addLocalFolder($path, $target) {
- if ($dh = $this->opendir($path)) {
+ $dh = $this->opendir($path);
+ if(is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file !== '.' and $file !== '..') {
if ($this->is_dir($path . '/' . $file)) {
@@ -242,7 +245,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
protected function searchInDir($query, $dir = '') {
$files = array();
$dh = $this->opendir($dir);
- if ($dh) {
+ if (is_resource($dh)) {
while (($item = readdir($dh)) !== false) {
if ($item == '.' || $item == '..') continue;
if (strstr(strtolower($item), strtolower($query)) !== false) {
diff --git a/lib/files/storage/mappedlocal.php b/lib/files/storage/mappedlocal.php
index fbf1b4ebf96..ba5ac4191c5 100644
--- a/lib/files/storage/mappedlocal.php
+++ b/lib/files/storage/mappedlocal.php
@@ -65,16 +65,18 @@ class MappedLocal extends \OC\Files\Storage\Common{
$logicalPath = $this->mapper->physicalToLogic($physicalPath);
$dh = opendir($physicalPath);
- while (($file = readdir($dh)) !== false) {
- if ($file === '.' or $file === '..') {
- continue;
- }
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if ($file === '.' or $file === '..') {
+ continue;
+ }
- $logicalFilePath = $this->mapper->physicalToLogic($physicalPath.'/'.$file);
+ $logicalFilePath = $this->mapper->physicalToLogic($physicalPath.'/'.$file);
- $file= $this->mapper->stripRootFolder($logicalFilePath, $logicalPath);
- $file = $this->stripLeading($file);
- $files[]= $file;
+ $file= $this->mapper->stripRootFolder($logicalFilePath, $logicalPath);
+ $file = $this->stripLeading($file);
+ $files[]= $file;
+ }
}
\OC\Files\Stream\Dir::register('local-win32'.$path, $files);
diff --git a/lib/files/view.php b/lib/files/view.php
index 8aee12bf6fe..6d58bcd9918 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -268,18 +268,18 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
and Filesystem::isValidPath($path)
- and !Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
$exists = $this->file_exists($path);
$run = true;
- if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path)) {
+ if ($this->shouldEmitHooks($path)) {
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_create,
array(
- Filesystem::signal_param_path => $path,
+ Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run
)
);
@@ -288,7 +288,7 @@ class View {
Filesystem::CLASSNAME,
Filesystem::signal_write,
array(
- Filesystem::signal_param_path => $path,
+ Filesystem::signal_param_path => $this->getHookPath($path),
Filesystem::signal_param_run => &$run
)
);
@@ -301,18 +301,18 @@ class View {
list ($count, $result) = \OC_Helper::streamCopy($data, $target);
fclose($target);
fclose($data);
- if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path) && $result !== false) {
+ if ($this->shouldEmitHooks($path) && $result !== false) {
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_create,
- array(Filesystem::signal_param_path => $path)
+ array(Filesystem::signal_param_path => $this->getHookPath($path))
);
}
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_write,
- array(Filesystem::signal_param_path => $path)
+ array(Filesystem::signal_param_path => $this->getHookPath($path))
);
}
\OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
@@ -333,7 +333,7 @@ class View {
}
public function deleteAll($directory, $empty = false) {
- return $this->basicOperation('deleteAll', $directory, array('delete'), $empty);
+ return $this->rmdir($directory);
}
public function rename($path1, $path2) {
@@ -354,21 +354,21 @@ class View {
return false;
}
$run = true;
- if ($this->fakeRoot == Filesystem::getRoot() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) {
+ if ($this->shouldEmitHooks() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) {
// if it was a rename from a part file to a regular file it was a write and not a rename operation
\OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::signal_write,
array(
- Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
- } elseif ($this->fakeRoot == Filesystem::getRoot()) {
+ } elseif ($this->shouldEmitHooks()) {
\OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::signal_rename,
array(
- Filesystem::signal_param_oldpath => $path1,
- Filesystem::signal_param_newpath => $path2,
+ Filesystem::signal_param_oldpath => $this->getHookPath($path1),
+ Filesystem::signal_param_newpath => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
@@ -408,22 +408,22 @@ class View {
}
}
}
- if ($this->fakeRoot == Filesystem::getRoot() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
+ if ($this->shouldEmitHooks() && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
// if it was a rename from a part file to a regular file it was a write and not a rename operation
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_write,
array(
- Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_path => $this->getHookPath($path2),
)
);
- } elseif ($this->fakeRoot == Filesystem::getRoot() && $result !== false) {
+ } elseif ($this->shouldEmitHooks() && $result !== false) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_rename,
array(
- Filesystem::signal_param_oldpath => $path1,
- Filesystem::signal_param_newpath => $path2
+ Filesystem::signal_param_oldpath => $this->getHookPath($path1),
+ Filesystem::signal_param_newpath => $this->getHookPath($path2)
)
);
}
@@ -455,13 +455,13 @@ class View {
}
$run = true;
$exists = $this->file_exists($path2);
- if ($this->fakeRoot == Filesystem::getRoot()) {
+ if ($this->shouldEmitHooks()) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_copy,
array(
- Filesystem::signal_param_oldpath => $path1,
- Filesystem::signal_param_newpath => $path2,
+ Filesystem::signal_param_oldpath => $this->getHookPath($path1),
+ Filesystem::signal_param_newpath => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
@@ -470,7 +470,7 @@ class View {
Filesystem::CLASSNAME,
Filesystem::signal_create,
array(
- Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
@@ -480,7 +480,7 @@ class View {
Filesystem::CLASSNAME,
Filesystem::signal_write,
array(
- Filesystem::signal_param_path => $path2,
+ Filesystem::signal_param_path => $this->getHookPath($path2),
Filesystem::signal_param_run => &$run
)
);
@@ -500,9 +500,11 @@ class View {
} else {
if ($this->is_dir($path1) && ($dh = $this->opendir($path1))) {
$result = $this->mkdir($path2);
- while (($file = readdir($dh)) !== false) {
- if (!Filesystem::isIgnoredDir($file)) {
- $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file);
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if (!Filesystem::isIgnoredDir($file)) {
+ $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file);
+ }
}
}
} else {
@@ -511,26 +513,26 @@ class View {
list($count, $result) = \OC_Helper::streamCopy($source, $target);
}
}
- if ($this->fakeRoot == Filesystem::getRoot() && $result !== false) {
+ if ($this->shouldEmitHooks() && $result !== false) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_copy,
array(
- Filesystem::signal_param_oldpath => $path1,
- Filesystem::signal_param_newpath => $path2
+ Filesystem::signal_param_oldpath => $this->getHookPath($path1),
+ Filesystem::signal_param_newpath => $this->getHookPath($path2)
)
);
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_create,
- array(Filesystem::signal_param_path => $path2)
+ array(Filesystem::signal_param_path => $this->getHookPath($path2))
);
}
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_write,
- array(Filesystem::signal_param_path => $path2)
+ array(Filesystem::signal_param_path => $this->getHookPath($path2))
);
}
return $result;
@@ -621,11 +623,11 @@ class View {
if ($path == null) {
return false;
}
- if (Filesystem::$loaded && $this->fakeRoot == Filesystem::getRoot()) {
+ if ($this->shouldEmitHooks($path)) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_read,
- array(Filesystem::signal_param_path => $path)
+ array(Filesystem::signal_param_path => $this->getHookPath($path))
);
}
list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
@@ -659,7 +661,7 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam)
and Filesystem::isValidPath($path)
- and !Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
if ($path == null) {
@@ -675,7 +677,7 @@ class View {
$result = $storage->$operation($internalPath);
}
$result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
- if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && $result !== false) {
+ if ($this->shouldEmitHooks($path) && $result !== false) {
if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open
$this->runHooks($hooks, $path, true);
}
@@ -686,10 +688,35 @@ class View {
return null;
}
+ /**
+ * get the path relative to the default root for hook usage
+ *
+ * @param string $path
+ * @return string
+ */
+ private function getHookPath($path) {
+ if (!Filesystem::getView()) {
+ return $path;
+ }
+ return Filesystem::getView()->getRelativePath($this->getAbsolutePath($path));
+ }
+
+ private function shouldEmitHooks($path = '') {
+ if ($path && Cache\Scanner::isPartialFile($path)) {
+ return false;
+ }
+ if (!Filesystem::$loaded) {
+ return false;
+ }
+ $defaultRoot = Filesystem::getRoot();
+ return (strlen($this->fakeRoot) >= strlen($defaultRoot)) && (substr($this->fakeRoot, 0, strlen($defaultRoot)) === $defaultRoot);
+ }
+
private function runHooks($hooks, $path, $post = false) {
+ $path = $this->getHookPath($path);
$prefix = ($post) ? 'post_' : '';
$run = true;
- if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path)) {
+ if ($this->shouldEmitHooks($path)) {
foreach ($hooks as $hook) {
if ($hook != 'read') {
\OC_Hook::emit(
diff --git a/lib/helper.php b/lib/helper.php
index cfb29028ee3..66e7acb407a 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -185,7 +185,38 @@ class OC_Helper {
* Returns the path to the image of this file type.
*/
public static function mimetypeIcon($mimetype) {
- $alias = array('application/xml' => 'code/xml');
+ $alias = array(
+ 'application/xml' => 'code/xml',
+ 'application/msword' => 'x-office/document',
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'x-office/document',
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'x-office/document',
+ 'application/vnd.ms-word.document.macroEnabled.12' => 'x-office/document',
+ 'application/vnd.ms-word.template.macroEnabled.12' => 'x-office/document',
+ 'application/vnd.oasis.opendocument.text' => 'x-office/document',
+ 'application/vnd.oasis.opendocument.text-template' => 'x-office/document',
+ 'application/vnd.oasis.opendocument.text-web' => 'x-office/document',
+ 'application/vnd.oasis.opendocument.text-master' => 'x-office/document',
+ 'application/vnd.ms-powerpoint' => 'x-office/presentation',
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'x-office/presentation',
+ 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'x-office/presentation',
+ 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'x-office/presentation',
+ 'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'x-office/presentation',
+ 'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'x-office/presentation',
+ 'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'x-office/presentation',
+ 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'x-office/presentation',
+ 'application/vnd.oasis.opendocument.presentation' => 'x-office/presentation',
+ 'application/vnd.oasis.opendocument.presentation-template' => 'x-office/presentation',
+ 'application/vnd.ms-excel' => 'x-office/spreadsheet',
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'x-office/spreadsheet',
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'x-office/spreadsheet',
+ 'application/vnd.ms-excel.sheet.macroEnabled.12' => 'x-office/spreadsheet',
+ 'application/vnd.ms-excel.template.macroEnabled.12' => 'x-office/spreadsheet',
+ 'application/vnd.ms-excel.addin.macroEnabled.12' => 'x-office/spreadsheet',
+ 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'x-office/spreadsheet',
+ 'application/vnd.oasis.opendocument.spreadsheet' => 'x-office/spreadsheet',
+ 'application/vnd.oasis.opendocument.spreadsheet-template' => 'x-office/spreadsheet',
+ );
+
if (isset($alias[$mimetype])) {
$mimetype = $alias[$mimetype];
}
@@ -201,6 +232,14 @@ class OC_Helper {
self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/folder.png';
return OC::$WEBROOT . '/core/img/filetypes/folder.png';
}
+ if ($mimetype === 'dir-shared') {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/folder-shared.png';
+ return OC::$WEBROOT . '/core/img/filetypes/folder-shared.png';
+ }
+ if ($mimetype === 'dir-external') {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT . '/core/img/filetypes/folder-external.png';
+ return OC::$WEBROOT . '/core/img/filetypes/folder-external.png';
+ }
// Icon exists?
if (file_exists(OC::$SERVERROOT . '/core/img/filetypes/' . $icon . '.png')) {
@@ -220,6 +259,21 @@ class OC_Helper {
}
/**
+ * @brief get path to preview of file
+ * @param string $path path
+ * @return string the url
+ *
+ * Returns the path to the preview of the file.
+ */
+ public static function previewIcon($path) {
+ return self::linkToRoute( 'core_ajax_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path) ));
+ }
+
+ public static function publicPreviewIcon( $path, $token ) {
+ return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path), 't' => $token));
+ }
+
+ /**
* @brief Make a human file size
* @param int $bytes file size in bytes
* @return string a human readable file size
@@ -228,7 +282,6 @@ class OC_Helper {
*/
public static function humanFileSize($bytes) {
if ($bytes < 0) {
- $l = OC_L10N::get('lib');
return "?";
}
if ($bytes < 1024) {
@@ -242,10 +295,17 @@ class OC_Helper {
if ($bytes < 1024) {
return "$bytes MB";
}
+ $bytes = round($bytes / 1024, 1);
+ if ($bytes < 1024) {
+ return "$bytes GB";
+ }
+ $bytes = round($bytes / 1024, 1);
+ if ($bytes < 1024) {
+ return "$bytes TB";
+ }
- // Wow, heavy duty for owncloud
$bytes = round($bytes / 1024, 1);
- return "$bytes GB";
+ return "$bytes PB";
}
/**
@@ -295,17 +355,19 @@ class OC_Helper {
if (!is_dir($path))
return chmod($path, $filemode);
$dh = opendir($path);
- while (($file = readdir($dh)) !== false) {
- if ($file != '.' && $file != '..') {
- $fullpath = $path . '/' . $file;
- if (is_link($fullpath))
- return false;
- elseif (!is_dir($fullpath) && !@chmod($fullpath, $filemode))
- return false; elseif (!self::chmodr($fullpath, $filemode))
- return false;
+ if(is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if ($file != '.' && $file != '..') {
+ $fullpath = $path . '/' . $file;
+ if (is_link($fullpath))
+ return false;
+ elseif (!is_dir($fullpath) && !@chmod($fullpath, $filemode))
+ return false; elseif (!self::chmodr($fullpath, $filemode))
+ return false;
+ }
}
+ closedir($dh);
}
- closedir($dh);
if (@chmod($path, $filemode))
return true;
else
@@ -603,9 +665,11 @@ class OC_Helper {
// if oc-noclean is empty delete it
$isTmpDirNoCleanEmpty = true;
$tmpDirNoClean = opendir($tmpDirNoCleanName);
- while (false !== ($file = readdir($tmpDirNoClean))) {
- if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
- $isTmpDirNoCleanEmpty = false;
+ if(is_resource($tmpDirNoClean)) {
+ while (false !== ($file = readdir($tmpDirNoClean))) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+ $isTmpDirNoCleanEmpty = false;
+ }
}
}
if ($isTmpDirNoCleanEmpty) {
@@ -648,7 +712,7 @@ class OC_Helper {
$newpath = $path . '/' . $filename;
if ($view->file_exists($newpath)) {
if (preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) {
- //Replace the last "(number)" with "(number+1)"
+ //Replace the last "(number)" with "(number+1)"
$last_match = count($matches[0]) - 1;
$counter = $matches[1][$last_match][0] + 1;
$offset = $matches[0][$last_match][1];
@@ -659,7 +723,7 @@ class OC_Helper {
}
do {
if ($offset) {
- //Replace the last "(number)" with "(number+1)"
+ //Replace the last "(number)" with "(number+1)"
$newname = substr_replace($name, '(' . $counter . ')', $offset, $match_length);
} else {
$newname = $name . ' (' . $counter . ')';
diff --git a/lib/image.php b/lib/image.php
index 4bc38e20e56..7761a3c7737 100644
--- a/lib/image.php
+++ b/lib/image.php
@@ -25,24 +25,27 @@
*/
class OC_Image {
protected $resource = false; // tmp resource.
- protected $imagetype = IMAGETYPE_PNG; // Default to png if file type isn't evident.
- protected $bit_depth = 24;
- protected $filepath = null;
+ protected $imageType = IMAGETYPE_PNG; // Default to png if file type isn't evident.
+ protected $mimeType = "image/png"; // Default to png
+ protected $bitDepth = 24;
+ protected $filePath = null;
+
+ private $fileInfo;
/**
* @brief Get mime type for an image file.
* @param $filepath The path to a local image file.
* @returns string The mime type if the it could be determined, otherwise an empty string.
*/
- static public function getMimeTypeForFile($filepath) {
+ static public function getMimeTypeForFile($filePath) {
// exif_imagetype throws "read error!" if file is less than 12 byte
- if (filesize($filepath) > 11) {
- $imagetype = exif_imagetype($filepath);
+ if (filesize($filePath) > 11) {
+ $imageType = exif_imagetype($filePath);
}
else {
- $imagetype = false;
+ $imageType = false;
}
- return $imagetype ? image_type_to_mime_type($imagetype) : '';
+ return $imageType ? image_type_to_mime_type($imageType) : '';
}
/**
@@ -50,14 +53,19 @@ class OC_Image {
* @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function.
* @returns bool False on error
*/
- public function __construct($imageref = null) {
+ public function __construct($imageRef = null) {
//OC_Log::write('core',__METHOD__.'(): start', OC_Log::DEBUG);
if(!extension_loaded('gd') || !function_exists('gd_info')) {
OC_Log::write('core', __METHOD__.'(): GD module not installed', OC_Log::ERROR);
return false;
}
- if(!is_null($imageref)) {
- $this->load($imageref);
+
+ if (\OC_Util::fileInfoLoaded()) {
+ $this->fileInfo = new finfo(FILEINFO_MIME_TYPE);
+ }
+
+ if(!is_null($imageRef)) {
+ $this->load($imageRef);
}
}
@@ -74,7 +82,7 @@ class OC_Image {
* @returns int
*/
public function mimeType() {
- return $this->valid() ? image_type_to_mime_type($this->imagetype) : '';
+ return $this->valid() ? $this->mimeType : '';
}
/**
@@ -157,30 +165,30 @@ class OC_Image {
* @returns bool
*/
- public function save($filepath=null) {
- if($filepath === null && $this->filepath === null) {
+ public function save($filePath=null) {
+ if($filePath === null && $this->filePath === null) {
OC_Log::write('core', __METHOD__.'(): called with no path.', OC_Log::ERROR);
return false;
- } elseif($filepath === null && $this->filepath !== null) {
- $filepath = $this->filepath;
+ } elseif($filePath === null && $this->filePath !== null) {
+ $filePath = $this->filePath;
}
- return $this->_output($filepath);
+ return $this->_output($filePath);
}
/**
* @brief Outputs/saves the image.
*/
- private function _output($filepath=null) {
- if($filepath) {
- if (!file_exists(dirname($filepath)))
- mkdir(dirname($filepath), 0777, true);
- if(!is_writable(dirname($filepath))) {
+ private function _output($filePath=null) {
+ if($filePath) {
+ if (!file_exists(dirname($filePath)))
+ mkdir(dirname($filePath), 0777, true);
+ if(!is_writable(dirname($filePath))) {
OC_Log::write('core',
- __METHOD__.'(): Directory \''.dirname($filepath).'\' is not writable.',
+ __METHOD__.'(): Directory \''.dirname($filePath).'\' is not writable.',
OC_Log::ERROR);
return false;
- } elseif(is_writable(dirname($filepath)) && file_exists($filepath) && !is_writable($filepath)) {
- OC_Log::write('core', __METHOD__.'(): File \''.$filepath.'\' is not writable.', OC_Log::ERROR);
+ } elseif(is_writable(dirname($filePath)) && file_exists($filePath) && !is_writable($filePath)) {
+ OC_Log::write('core', __METHOD__.'(): File \''.$filePath.'\' is not writable.', OC_Log::ERROR);
return false;
}
}
@@ -188,30 +196,30 @@ class OC_Image {
return false;
}
- $retval = false;
- switch($this->imagetype) {
+ $retVal = false;
+ switch($this->imageType) {
case IMAGETYPE_GIF:
- $retval = imagegif($this->resource, $filepath);
+ $retVal = imagegif($this->resource, $filePath);
break;
case IMAGETYPE_JPEG:
- $retval = imagejpeg($this->resource, $filepath);
+ $retVal = imagejpeg($this->resource, $filePath);
break;
case IMAGETYPE_PNG:
- $retval = imagepng($this->resource, $filepath);
+ $retVal = imagepng($this->resource, $filePath);
break;
case IMAGETYPE_XBM:
- $retval = imagexbm($this->resource, $filepath);
+ $retVal = imagexbm($this->resource, $filePath);
break;
case IMAGETYPE_WBMP:
- $retval = imagewbmp($this->resource, $filepath);
+ $retVal = imagewbmp($this->resource, $filePath);
break;
case IMAGETYPE_BMP:
- $retval = imagebmp($this->resource, $filepath, $this->bit_depth);
+ $retVal = imagebmp($this->resource, $filePath, $this->bitDepth);
break;
default:
- $retval = imagepng($this->resource, $filepath);
+ $retVal = imagepng($this->resource, $filePath);
}
- return $retval;
+ return $retVal;
}
/**
@@ -233,7 +241,21 @@ class OC_Image {
*/
function data() {
ob_start();
- $res = imagepng($this->resource);
+ switch ($this->mimeType) {
+ case "image/png":
+ $res = imagepng($this->resource);
+ break;
+ case "image/jpeg":
+ $res = imagejpeg($this->resource);
+ break;
+ case "image/gif":
+ $res = imagegif($this->resource);
+ break;
+ default:
+ $res = imagepng($this->resource);
+ OC_Log::write('core', 'OC_Image->data. Couldn\'t guess mimetype, defaulting to png', OC_Log::INFO);
+ break;
+ }
if (!$res) {
OC_Log::write('core', 'OC_Image->data. Error getting image data.', OC_Log::ERROR);
}
@@ -261,11 +283,11 @@ class OC_Image {
OC_Log::write('core', 'OC_Image->fixOrientation() No image loaded.', OC_Log::DEBUG);
return -1;
}
- if(is_null($this->filepath) || !is_readable($this->filepath)) {
+ if(is_null($this->filePath) || !is_readable($this->filePath)) {
OC_Log::write('core', 'OC_Image->fixOrientation() No readable file path set.', OC_Log::DEBUG);
return -1;
}
- $exif = @exif_read_data($this->filepath, 'IFD0');
+ $exif = @exif_read_data($this->filePath, 'IFD0');
if(!$exif) {
return -1;
}
@@ -351,19 +373,19 @@ class OC_Image {
* @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function or a file resource (file handle ).
* @returns An image resource or false on error
*/
- public function load($imageref) {
- if(is_resource($imageref)) {
- if(get_resource_type($imageref) == 'gd') {
- $this->resource = $imageref;
+ public function load($imageRef) {
+ if(is_resource($imageRef)) {
+ if(get_resource_type($imageRef) == 'gd') {
+ $this->resource = $imageRef;
return $this->resource;
- } elseif(in_array(get_resource_type($imageref), array('file', 'stream'))) {
- return $this->loadFromFileHandle($imageref);
+ } elseif(in_array(get_resource_type($imageRef), array('file', 'stream'))) {
+ return $this->loadFromFileHandle($imageRef);
}
- } elseif($this->loadFromFile($imageref) !== false) {
+ } elseif($this->loadFromFile($imageRef) !== false) {
return $this->resource;
- } elseif($this->loadFromBase64($imageref) !== false) {
+ } elseif($this->loadFromBase64($imageRef) !== false) {
return $this->resource;
- } elseif($this->loadFromData($imageref) !== false) {
+ } elseif($this->loadFromData($imageRef) !== false) {
return $this->resource;
} else {
OC_Log::write('core', __METHOD__.'(): couldn\'t load anything. Giving up!', OC_Log::DEBUG);
@@ -390,62 +412,62 @@ class OC_Image {
* @param $imageref The path to a local file.
* @returns An image resource or false on error
*/
- public function loadFromFile($imagepath=false) {
+ public function loadFromFile($imagePath=false) {
// exif_imagetype throws "read error!" if file is less than 12 byte
- if(!@is_file($imagepath) || !file_exists($imagepath) || filesize($imagepath) < 12 || !is_readable($imagepath)) {
+ if(!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) {
// Debug output disabled because this method is tried before loadFromBase64?
- OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.$imagepath, OC_Log::DEBUG);
+ OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.$imagePath, OC_Log::DEBUG);
return false;
}
- $itype = exif_imagetype($imagepath);
- switch($itype) {
+ $iType = exif_imagetype($imagePath);
+ switch ($iType) {
case IMAGETYPE_GIF:
if (imagetypes() & IMG_GIF) {
- $this->resource = imagecreatefromgif($imagepath);
+ $this->resource = imagecreatefromgif($imagePath);
} else {
OC_Log::write('core',
- 'OC_Image->loadFromFile, GIF images not supported: '.$imagepath,
+ 'OC_Image->loadFromFile, GIF images not supported: '.$imagePath,
OC_Log::DEBUG);
}
break;
case IMAGETYPE_JPEG:
if (imagetypes() & IMG_JPG) {
- $this->resource = imagecreatefromjpeg($imagepath);
+ $this->resource = imagecreatefromjpeg($imagePath);
} else {
OC_Log::write('core',
- 'OC_Image->loadFromFile, JPG images not supported: '.$imagepath,
+ 'OC_Image->loadFromFile, JPG images not supported: '.$imagePath,
OC_Log::DEBUG);
}
break;
case IMAGETYPE_PNG:
if (imagetypes() & IMG_PNG) {
- $this->resource = imagecreatefrompng($imagepath);
+ $this->resource = imagecreatefrompng($imagePath);
} else {
OC_Log::write('core',
- 'OC_Image->loadFromFile, PNG images not supported: '.$imagepath,
+ 'OC_Image->loadFromFile, PNG images not supported: '.$imagePath,
OC_Log::DEBUG);
}
break;
case IMAGETYPE_XBM:
if (imagetypes() & IMG_XPM) {
- $this->resource = imagecreatefromxbm($imagepath);
+ $this->resource = imagecreatefromxbm($imagePath);
} else {
OC_Log::write('core',
- 'OC_Image->loadFromFile, XBM/XPM images not supported: '.$imagepath,
+ 'OC_Image->loadFromFile, XBM/XPM images not supported: '.$imagePath,
OC_Log::DEBUG);
}
break;
case IMAGETYPE_WBMP:
if (imagetypes() & IMG_WBMP) {
- $this->resource = imagecreatefromwbmp($imagepath);
+ $this->resource = imagecreatefromwbmp($imagePath);
} else {
OC_Log::write('core',
- 'OC_Image->loadFromFile, WBMP images not supported: '.$imagepath,
+ 'OC_Image->loadFromFile, WBMP images not supported: '.$imagePath,
OC_Log::DEBUG);
}
break;
case IMAGETYPE_BMP:
- $this->resource = $this->imagecreatefrombmp($imagepath);
+ $this->resource = $this->imagecreatefrombmp($imagePath);
break;
/*
case IMAGETYPE_TIFF_II: // (intel byte order)
@@ -474,14 +496,15 @@ class OC_Image {
default:
// this is mostly file created from encrypted file
- $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagepath)));
- $itype = IMAGETYPE_PNG;
+ $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
+ $iType = IMAGETYPE_PNG;
OC_Log::write('core', 'OC_Image->loadFromFile, Default', OC_Log::DEBUG);
break;
}
if($this->valid()) {
- $this->imagetype = $itype;
- $this->filepath = $imagepath;
+ $this->imageType = $iType;
+ $this->mimeType = image_type_to_mime_type($iType);
+ $this->filePath = $imagePath;
}
return $this->resource;
}
@@ -496,6 +519,14 @@ class OC_Image {
return false;
}
$this->resource = @imagecreatefromstring($str);
+ if ($this->fileInfo) {
+ $this->mimeType = $this->fileInfo->buffer($str);
+ }
+ if(is_resource($this->resource)) {
+ imagealphablending($this->resource, false);
+ imagesavealpha($this->resource, true);
+ }
+
if(!$this->resource) {
OC_Log::write('core', 'OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG);
return false;
@@ -515,6 +546,9 @@ class OC_Image {
$data = base64_decode($str);
if($data) { // try to load from string data
$this->resource = @imagecreatefromstring($data);
+ if ($this->fileInfo) {
+ $this->mimeType = $this->fileInfo->buffer($data);
+ }
if(!$this->resource) {
OC_Log::write('core', 'OC_Image->loadFromBase64, couldn\'t load', OC_Log::DEBUG);
return false;
@@ -534,16 +568,16 @@ class OC_Image {
* </p>
* @return resource an image resource identifier on success, <b>FALSE</b> on errors.
*/
- private function imagecreatefrombmp($filename) {
- if (!($fh = fopen($filename, 'rb'))) {
- trigger_error('imagecreatefrombmp: Can not open ' . $filename, E_USER_WARNING);
+ private function imagecreatefrombmp($fileName) {
+ if (!($fh = fopen($fileName, 'rb'))) {
+ trigger_error('imagecreatefrombmp: Can not open ' . $fileName, E_USER_WARNING);
return false;
}
// read file header
$meta = unpack('vtype/Vfilesize/Vreserved/Voffset', fread($fh, 14));
// check for bitmap
if ($meta['type'] != 19778) {
- trigger_error('imagecreatefrombmp: ' . $filename . ' is not a bitmap!', E_USER_WARNING);
+ trigger_error('imagecreatefrombmp: ' . $fileName . ' is not a bitmap!', E_USER_WARNING);
return false;
}
// read image header
@@ -554,7 +588,7 @@ class OC_Image {
}
// set bytes and padding
$meta['bytes'] = $meta['bits'] / 8;
- $this->bit_depth = $meta['bits']; //remember the bit depth for the imagebmp call
+ $this->bitDepth = $meta['bits']; //remember the bit depth for the imagebmp call
$meta['decal'] = 4 - (4 * (($meta['width'] * $meta['bytes'] / 4)- floor($meta['width'] * $meta['bytes'] / 4)));
if ($meta['decal'] == 4) {
$meta['decal'] = 0;
@@ -590,7 +624,7 @@ class OC_Image {
$p = 0;
$vide = chr(0);
$y = $meta['height'] - 1;
- $error = 'imagecreatefrombmp: ' . $filename . ' has not enough data!';
+ $error = 'imagecreatefrombmp: ' . $fileName . ' has not enough data!';
// loop through the image data beginning with the lower left corner
while ($y >= 0) {
$x = 0;
@@ -653,7 +687,7 @@ class OC_Image {
break;
default:
trigger_error('imagecreatefrombmp: '
- . $filename . ' has ' . $meta['bits'] . ' bits and this is not supported!',
+ . $fileName . ' has ' . $meta['bits'] . ' bits and this is not supported!',
E_USER_WARNING);
return false;
}
@@ -673,24 +707,24 @@ class OC_Image {
* @param $maxsize The maximum size of either the width or height.
* @returns bool
*/
- public function resize($maxsize) {
+ public function resize($maxSize) {
if(!$this->valid()) {
OC_Log::write('core', __METHOD__.'(): No image loaded', OC_Log::ERROR);
return false;
}
- $width_orig=imageSX($this->resource);
- $height_orig=imageSY($this->resource);
- $ratio_orig = $width_orig/$height_orig;
+ $widthOrig=imageSX($this->resource);
+ $heightOrig=imageSY($this->resource);
+ $ratioOrig = $widthOrig/$heightOrig;
- if ($ratio_orig > 1) {
- $new_height = round($maxsize/$ratio_orig);
- $new_width = $maxsize;
+ if ($ratioOrig > 1) {
+ $newHeight = round($maxSize/$ratioOrig);
+ $newWidth = $maxSize;
} else {
- $new_width = round($maxsize*$ratio_orig);
- $new_height = $maxsize;
+ $newWidth = round($maxSize*$ratioOrig);
+ $newHeight = $maxSize;
}
- $this->preciseResize(round($new_width), round($new_height));
+ $this->preciseResize(round($newWidth), round($newHeight));
return true;
}
@@ -699,8 +733,8 @@ class OC_Image {
OC_Log::write('core', __METHOD__.'(): No image loaded', OC_Log::ERROR);
return false;
}
- $width_orig=imageSX($this->resource);
- $height_orig=imageSY($this->resource);
+ $widthOrig=imageSX($this->resource);
+ $heightOrig=imageSY($this->resource);
$process = imagecreatetruecolor($width, $height);
if ($process == false) {
@@ -710,13 +744,13 @@ class OC_Image {
}
// preserve transparency
- if($this->imagetype == IMAGETYPE_GIF or $this->imagetype == IMAGETYPE_PNG) {
+ if($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) {
imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127));
imagealphablending($process, false);
imagesavealpha($process, true);
}
- imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
+ imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
if ($process == false) {
OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$width.'x'.$height, OC_Log::ERROR);
imagedestroy($process);
@@ -737,19 +771,19 @@ class OC_Image {
OC_Log::write('core', 'OC_Image->centerCrop, No image loaded', OC_Log::ERROR);
return false;
}
- $width_orig=imageSX($this->resource);
- $height_orig=imageSY($this->resource);
- if($width_orig === $height_orig and $size==0) {
+ $widthOrig=imageSX($this->resource);
+ $heightOrig=imageSY($this->resource);
+ if($widthOrig === $heightOrig and $size==0) {
return true;
}
- $ratio_orig = $width_orig/$height_orig;
- $width = $height = min($width_orig, $height_orig);
+ $ratioOrig = $widthOrig/$heightOrig;
+ $width = $height = min($widthOrig, $heightOrig);
- if ($ratio_orig > 1) {
- $x = ($width_orig/2) - ($width/2);
+ if ($ratioOrig > 1) {
+ $x = ($widthOrig/2) - ($width/2);
$y = 0;
} else {
- $y = ($height_orig/2) - ($height/2);
+ $y = ($heightOrig/2) - ($height/2);
$x = 0;
}
if($size>0) {
@@ -767,7 +801,7 @@ class OC_Image {
}
// preserve transparency
- if($this->imagetype == IMAGETYPE_GIF or $this->imagetype == IMAGETYPE_PNG) {
+ if($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) {
imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127));
imagealphablending($process, false);
imagesavealpha($process, true);
@@ -827,9 +861,9 @@ class OC_Image {
OC_Log::write('core', __METHOD__.'(): No image loaded', OC_Log::ERROR);
return false;
}
- $width_orig=imageSX($this->resource);
- $height_orig=imageSY($this->resource);
- $ratio = $width_orig/$height_orig;
+ $widthOrig=imageSX($this->resource);
+ $heightOrig=imageSY($this->resource);
+ $ratio = $widthOrig/$heightOrig;
$newWidth = min($maxWidth, $ratio*$maxHeight);
$newHeight = min($maxHeight, $maxWidth/$ratio);
@@ -863,7 +897,7 @@ if ( ! function_exists( 'imagebmp') ) {
* @param int $compression [optional]
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
*/
- function imagebmp($im, $filename='', $bit=24, $compression=0) {
+ function imagebmp($im, $fileName='', $bit=24, $compression=0) {
if (!in_array($bit, array(1, 4, 8, 16, 24, 32))) {
$bit = 24;
}
@@ -874,14 +908,14 @@ if ( ! function_exists( 'imagebmp') ) {
imagetruecolortopalette($im, true, $bits);
$width = imagesx($im);
$height = imagesy($im);
- $colors_num = imagecolorstotal($im);
- $rgb_quad = '';
+ $colorsNum = imagecolorstotal($im);
+ $rgbQuad = '';
if ($bit <= 8) {
- for ($i = 0; $i < $colors_num; $i++) {
+ for ($i = 0; $i < $colorsNum; $i++) {
$colors = imagecolorsforindex($im, $i);
- $rgb_quad .= chr($colors['blue']) . chr($colors['green']) . chr($colors['red']) . "\0";
+ $rgbQuad .= chr($colors['blue']) . chr($colors['green']) . chr($colors['red']) . "\0";
}
- $bmp_data = '';
+ $bmpData = '';
if ($compression == 0 || $bit < 8) {
$compression = 0;
$extra = '';
@@ -899,35 +933,35 @@ if ( ! function_exists( 'imagebmp') ) {
$bin |= $index << $k;
$i++;
}
- $bmp_data .= chr($bin);
+ $bmpData .= chr($bin);
}
- $bmp_data .= $extra;
+ $bmpData .= $extra;
}
}
// RLE8
else if ($compression == 1 && $bit == 8) {
for ($j = $height - 1; $j >= 0; $j--) {
- $last_index = "\0";
- $same_num = 0;
+ $lastIndex = "\0";
+ $sameNum = 0;
for ($i = 0; $i <= $width; $i++) {
$index = imagecolorat($im, $i, $j);
- if ($index !== $last_index || $same_num > 255) {
- if ($same_num != 0) {
- $bmp_data .= chr($same_num) . chr($last_index);
+ if ($index !== $lastIndex || $sameNum > 255) {
+ if ($sameNum != 0) {
+ $bmpData .= chr($same_num) . chr($lastIndex);
}
- $last_index = $index;
- $same_num = 1;
+ $lastIndex = $index;
+ $sameNum = 1;
}
else {
- $same_num++;
+ $sameNum++;
}
}
- $bmp_data .= "\0\0";
+ $bmpData .= "\0\0";
}
- $bmp_data .= "\0\1";
+ $bmpData .= "\0\1";
}
- $size_quad = strlen($rgb_quad);
- $size_data = strlen($bmp_data);
+ $sizeQuad = strlen($rgbQuad);
+ $sizeData = strlen($bmpData);
}
else {
$extra = '';
@@ -935,7 +969,7 @@ if ( ! function_exists( 'imagebmp') ) {
if ($padding % 4 != 0) {
$extra = str_repeat("\0", $padding);
}
- $bmp_data = '';
+ $bmpData = '';
for ($j = $height - 1; $j >= 0; $j--) {
for ($i = 0; $i < $width; $i++) {
$index = imagecolorat($im, $i, $j);
@@ -945,27 +979,27 @@ if ( ! function_exists( 'imagebmp') ) {
$bin |= ($colors['red'] >> 3) << 10;
$bin |= ($colors['green'] >> 3) << 5;
$bin |= $colors['blue'] >> 3;
- $bmp_data .= pack("v", $bin);
+ $bmpData .= pack("v", $bin);
}
else {
- $bmp_data .= pack("c*", $colors['blue'], $colors['green'], $colors['red']);
+ $bmpData .= pack("c*", $colors['blue'], $colors['green'], $colors['red']);
}
}
- $bmp_data .= $extra;
+ $bmpData .= $extra;
}
- $size_quad = 0;
- $size_data = strlen($bmp_data);
- $colors_num = 0;
- }
- $file_header = 'BM' . pack('V3', 54 + $size_quad + $size_data, 0, 54 + $size_quad);
- $info_header = pack('V3v2V*', 0x28, $width, $height, 1, $bit, $compression, $size_data, 0, 0, $colors_num, 0);
- if ($filename != '') {
- $fp = fopen($filename, 'wb');
- fwrite($fp, $file_header . $info_header . $rgb_quad . $bmp_data);
+ $sizeQuad = 0;
+ $sizeData = strlen($bmpData);
+ $colorsNum = 0;
+ }
+ $fileHeader = 'BM' . pack('V3', 54 + $sizeQuad + $sizeData, 0, 54 + $sizeQuad);
+ $infoHeader = pack('V3v2V*', 0x28, $width, $height, 1, $bit, $compression, $sizeData, 0, 0, $colorsNum, 0);
+ if ($fileName != '') {
+ $fp = fopen($fileName, 'wb');
+ fwrite($fp, $fileHeader . $infoHeader . $rgbQuad . $bmpData);
fclose($fp);
return true;
}
- echo $file_header . $info_header. $rgb_quad . $bmp_data;
+ echo $fileHeader . $infoHeader. $rgbQuad . $bmpData;
return true;
}
}
@@ -977,8 +1011,8 @@ if ( ! function_exists( 'exif_imagetype' ) ) {
* @param string $filename
* @return string|boolean
*/
- function exif_imagetype ( $filename ) {
- if ( ( $info = getimagesize( $filename ) ) !== false ) {
+ function exif_imagetype ( $fileName ) {
+ if ( ( $info = getimagesize( $fileName ) ) !== false ) {
return $info[2];
}
return false;
diff --git a/lib/installer.php b/lib/installer.php
index b9684eaeea0..607e6da7265 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -107,10 +107,12 @@ class OC_Installer{
if(!is_file($extractDir.'/appinfo/info.xml')) {
//try to find it in a subdir
$dh=opendir($extractDir);
- while (($folder = readdir($dh)) !== false) {
- if($folder[0]!='.' and is_dir($extractDir.'/'.$folder)) {
- if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')) {
- $extractDir.='/'.$folder;
+ if(is_resource($dh)) {
+ while (($folder = readdir($dh)) !== false) {
+ if($folder[0]!='.' and is_dir($extractDir.'/'.$folder)) {
+ if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')) {
+ $extractDir.='/'.$folder;
+ }
}
}
}
diff --git a/lib/l10n/ach.php b/lib/l10n/ach.php
new file mode 100644
index 00000000000..406ff5f5a26
--- /dev/null
+++ b/lib/l10n/ach.php
@@ -0,0 +1,8 @@
+<?php
+$TRANSLATIONS = array(
+"_%n minute ago_::_%n minutes ago_" => array("",""),
+"_%n hour ago_::_%n hours ago_" => array("",""),
+"_%n day go_::_%n days ago_" => array("",""),
+"_%n month ago_::_%n months ago_" => array("","")
+);
+$PLURAL_FORMS = "nplurals=2; plural=(n > 1);";
diff --git a/lib/l10n/es.php b/lib/l10n/es.php
index 14bbf6f6a13..047d5d955bb 100644
--- a/lib/l10n/es.php
+++ b/lib/l10n/es.php
@@ -1,5 +1,7 @@
<?php
$TRANSLATIONS = array(
+"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "La aplicación \"%s\" no puede ser instalada porque no es compatible con esta versión de ownCloud",
+"No app name specified" => "No se ha especificado nombre de la aplicación",
"Help" => "Ayuda",
"Personal" => "Personal",
"Settings" => "Ajustes",
@@ -13,6 +15,18 @@ $TRANSLATIONS = array(
"Back to Files" => "Volver a Archivos",
"Selected files too large to generate zip file." => "Los archivos seleccionados son demasiado grandes para generar el archivo zip.",
"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Descargue los archivos en trozos más pequeños, por separado o solicítelos amablemente su administrador.",
+"No source specified when installing app" => "No se ha especificado origen cuando se ha instalado la aplicación",
+"No href specified when installing app from http" => "No href especificado cuando se ha instalado la aplicación",
+"No path specified when installing app from local file" => "Sin path especificado cuando se ha instalado la aplicación desde el fichero local",
+"Archives of type %s are not supported" => "Ficheros de tipo %s no son soportados",
+"Failed to open archive when installing app" => "Fallo de apertura de fichero mientras se instala la aplicación",
+"App does not provide an info.xml file" => "La aplicación no suministra un fichero info.xml",
+"App can't be installed because of not allowed code in the App" => "La aplicación no puede ser instalada por tener código no autorizado en la aplicación",
+"App can't be installed because it is not compatible with this version of ownCloud" => "La aplicación no se puede instalar porque no es compatible con esta versión de ownCloud",
+"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "La aplicación no se puede instalar porque contiene la etiqueta\n<shipped>\ntrue\n</shipped>\nque no está permitida para aplicaciones no distribuidas",
+"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "La aplicación no puede ser instalada por que la versión en info.xml/version no es la misma que la establecida en la app store",
+"App directory already exists" => "El directorio de la aplicación ya existe",
+"Can't create app folder. Please fix permissions. %s" => "No se puede crear la carpeta de la aplicación. Corrija los permisos. %s",
"Application is not enabled" => "La aplicación no está habilitada",
"Authentication error" => "Error de autenticación",
"Token expired. Please reload page." => "Token expirado. Por favor, recarga la página.",
@@ -21,7 +35,7 @@ $TRANSLATIONS = array(
"Images" => "Imágenes",
"%s enter the database username." => "%s ingresar el usuario de la base de datos.",
"%s enter the database name." => "%s ingresar el nombre de la base de datos",
-"%s you may not use dots in the database name" => "%s no se puede utilizar puntos en el nombre de la base de datos",
+"%s you may not use dots in the database name" => "%s puede utilizar puntos en el nombre de la base de datos",
"MS SQL username and/or password not valid: %s" => "Usuario y/o contraseña de MS SQL no válidos: %s",
"You need to enter either an existing account or the administrator." => "Tiene que ingresar una cuenta existente o la del administrador.",
"MySQL username and/or password not valid" => "Usuario y/o contraseña de MySQL no válidos",
@@ -40,13 +54,13 @@ $TRANSLATIONS = array(
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Su servidor web aún no está configurado adecuadamente para permitir sincronización de archivos ya que la interfaz WebDAV parece no estar funcionando.",
"Please double check the <a href='%s'>installation guides</a>." => "Por favor, vuelva a comprobar las <a href='%s'>guías de instalación</a>.",
"seconds ago" => "hace segundos",
-"_%n minute ago_::_%n minutes ago_" => array("",""),
-"_%n hour ago_::_%n hours ago_" => array("",""),
+"_%n minute ago_::_%n minutes ago_" => array("Hace %n minuto","Hace %n minutos"),
+"_%n hour ago_::_%n hours ago_" => array("Hace %n hora","Hace %n horas"),
"today" => "hoy",
"yesterday" => "ayer",
-"_%n day go_::_%n days ago_" => array("",""),
+"_%n day go_::_%n days ago_" => array("Hace %n día","Hace %n días"),
"last month" => "mes pasado",
-"_%n month ago_::_%n months ago_" => array("",""),
+"_%n month ago_::_%n months ago_" => array("Hace %n mes","Hace %n meses"),
"last year" => "año pasado",
"years ago" => "hace años",
"Caused by:" => "Causado por:",
diff --git a/lib/l10n/es_AR.php b/lib/l10n/es_AR.php
index 26f1e4ecd5e..f637eb403ed 100644
--- a/lib/l10n/es_AR.php
+++ b/lib/l10n/es_AR.php
@@ -1,5 +1,7 @@
<?php
$TRANSLATIONS = array(
+"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "La app \"%s\" no puede ser instalada porque no es compatible con esta versión de ownCloud",
+"No app name specified" => "No fue especificado el nombre de la app",
"Help" => "Ayuda",
"Personal" => "Personal",
"Settings" => "Configuración",
@@ -13,6 +15,18 @@ $TRANSLATIONS = array(
"Back to Files" => "Volver a Archivos",
"Selected files too large to generate zip file." => "Los archivos seleccionados son demasiado grandes para generar el archivo zip.",
"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Descargá los archivos en partes más chicas, de forma separada, o pedíselos al administrador",
+"No source specified when installing app" => "No se especificó el origen al instalar la app",
+"No href specified when installing app from http" => "No se especificó href al instalar la app",
+"No path specified when installing app from local file" => "No se especificó PATH al instalar la app desde el archivo local",
+"Archives of type %s are not supported" => "No hay soporte para archivos de tipo %s",
+"Failed to open archive when installing app" => "Error al abrir archivo mientras se instalaba la app",
+"App does not provide an info.xml file" => "La app no suministra un archivo info.xml",
+"App can't be installed because of not allowed code in the App" => "No puede ser instalada la app por tener código no autorizado",
+"App can't be installed because it is not compatible with this version of ownCloud" => "No se puede instalar la app porque no es compatible con esta versión de ownCloud",
+"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "La app no se puede instalar porque contiene la etiqueta <shipped>true</shipped> que no está permitida para apps no distribuidas",
+"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "La app no puede ser instalada porque la versión en info.xml/version no es la misma que la establecida en el app store",
+"App directory already exists" => "El directorio de la app ya existe",
+"Can't create app folder. Please fix permissions. %s" => "No se puede crear el directorio para la app. Corregí los permisos. %s",
"Application is not enabled" => "La aplicación no está habilitada",
"Authentication error" => "Error al autenticar",
"Token expired. Please reload page." => "Token expirado. Por favor, recargá la página.",
@@ -40,13 +54,13 @@ $TRANSLATIONS = array(
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Tu servidor web no está configurado todavía para permitir sincronización de archivos porque la interfaz WebDAV parece no funcionar.",
"Please double check the <a href='%s'>installation guides</a>." => "Por favor, comprobá nuevamente la <a href='%s'>guía de instalación</a>.",
"seconds ago" => "segundos atrás",
-"_%n minute ago_::_%n minutes ago_" => array("",""),
-"_%n hour ago_::_%n hours ago_" => array("",""),
+"_%n minute ago_::_%n minutes ago_" => array("Hace %n minuto","Hace %n minutos"),
+"_%n hour ago_::_%n hours ago_" => array("Hace %n hora","Hace %n horas"),
"today" => "hoy",
"yesterday" => "ayer",
-"_%n day go_::_%n days ago_" => array("",""),
+"_%n day go_::_%n days ago_" => array("Hace %n día","Hace %n días"),
"last month" => "el mes pasado",
-"_%n month ago_::_%n months ago_" => array("",""),
+"_%n month ago_::_%n months ago_" => array("Hace %n mes","Hace %n meses"),
"last year" => "el año pasado",
"years ago" => "años atrás",
"Caused by:" => "Provocado por:",
diff --git a/lib/l10n/es_MX.php b/lib/l10n/es_MX.php
new file mode 100644
index 00000000000..15f78e0bce6
--- /dev/null
+++ b/lib/l10n/es_MX.php
@@ -0,0 +1,8 @@
+<?php
+$TRANSLATIONS = array(
+"_%n minute ago_::_%n minutes ago_" => array("",""),
+"_%n hour ago_::_%n hours ago_" => array("",""),
+"_%n day go_::_%n days ago_" => array("",""),
+"_%n month ago_::_%n months ago_" => array("","")
+);
+$PLURAL_FORMS = "nplurals=2; plural=(n != 1);";
diff --git a/lib/l10n/fr.php b/lib/l10n/fr.php
index cfcca28d5f8..da3ec4ce372 100644
--- a/lib/l10n/fr.php
+++ b/lib/l10n/fr.php
@@ -1,15 +1,32 @@
<?php
$TRANSLATIONS = array(
+"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "L'application \"%s\" ne peut être installée car elle n'est pas compatible avec cette version de ownCloud.",
+"No app name specified" => "Aucun nom d'application spécifié",
"Help" => "Aide",
"Personal" => "Personnel",
"Settings" => "Paramètres",
"Users" => "Utilisateurs",
"Admin" => "Administration",
+"Failed to upgrade \"%s\"." => "Echec de la mise à niveau \"%s\".",
"web services under your control" => "services web sous votre contrôle",
+"cannot open \"%s\"" => "impossible d'ouvrir \"%s\"",
"ZIP download is turned off." => "Téléchargement ZIP désactivé.",
"Files need to be downloaded one by one." => "Les fichiers nécessitent d'être téléchargés un par un.",
"Back to Files" => "Retour aux Fichiers",
"Selected files too large to generate zip file." => "Les fichiers sélectionnés sont trop volumineux pour être compressés.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Télécharger les fichiers en parties plus petites, séparément ou demander avec bienveillance à votre administrateur.",
+"No source specified when installing app" => "Aucune source spécifiée pour installer l'application",
+"No href specified when installing app from http" => "Aucun href spécifié pour installer l'application par http",
+"No path specified when installing app from local file" => "Aucun chemin spécifié pour installer l'application depuis un fichier local",
+"Archives of type %s are not supported" => "Les archives de type %s ne sont pas supportées",
+"Failed to open archive when installing app" => "Échec de l'ouverture de l'archive lors de l'installation de l'application",
+"App does not provide an info.xml file" => "L'application ne fournit pas de fichier info.xml",
+"App can't be installed because of not allowed code in the App" => "L'application ne peut être installée car elle contient du code non-autorisé",
+"App can't be installed because it is not compatible with this version of ownCloud" => "L'application ne peut être installée car elle n'est pas compatible avec cette version de ownCloud",
+"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "L'application ne peut être installée car elle contient la balise <shipped>true</shipped> qui n'est pas autorisée pour les applications non-diffusées",
+"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "L'application ne peut être installée car la version de info.xml/version n'est identique à celle indiquée sur l'app store",
+"App directory already exists" => "Le dossier de l'application existe déjà",
+"Can't create app folder. Please fix permissions. %s" => "Impossible de créer le dossier de l'application. Corrigez les droits d'accès. %s",
"Application is not enabled" => "L'application n'est pas activée",
"Authentication error" => "Erreur d'authentification",
"Token expired. Please reload page." => "La session a expiré. Veuillez recharger la page.",
@@ -37,15 +54,16 @@ $TRANSLATIONS = array(
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Votre serveur web, n'est pas correctement configuré pour permettre la synchronisation des fichiers, car l'interface WebDav ne fonctionne pas comme il faut.",
"Please double check the <a href='%s'>installation guides</a>." => "Veuillez vous référer au <a href='%s'>guide d'installation</a>.",
"seconds ago" => "il y a quelques secondes",
-"_%n minute ago_::_%n minutes ago_" => array("",""),
-"_%n hour ago_::_%n hours ago_" => array("",""),
+"_%n minute ago_::_%n minutes ago_" => array("","il y a %n minutes"),
+"_%n hour ago_::_%n hours ago_" => array("","Il y a %n heures"),
"today" => "aujourd'hui",
"yesterday" => "hier",
-"_%n day go_::_%n days ago_" => array("",""),
+"_%n day go_::_%n days ago_" => array("","il y a %n jours"),
"last month" => "le mois dernier",
-"_%n month ago_::_%n months ago_" => array("",""),
+"_%n month ago_::_%n months ago_" => array("","Il y a %n mois"),
"last year" => "l'année dernière",
"years ago" => "il y a plusieurs années",
+"Caused by:" => "Causé par :",
"Could not find category \"%s\"" => "Impossible de trouver la catégorie \"%s\""
);
$PLURAL_FORMS = "nplurals=2; plural=(n > 1);";
diff --git a/lib/l10n/it.php b/lib/l10n/it.php
index a35027eb962..c3a040048ec 100644
--- a/lib/l10n/it.php
+++ b/lib/l10n/it.php
@@ -23,6 +23,7 @@ $TRANSLATIONS = array(
"App does not provide an info.xml file" => "L'applicazione non fornisce un file info.xml",
"App can't be installed because of not allowed code in the App" => "L'applicazione non può essere installata a causa di codice non consentito al suo interno",
"App can't be installed because it is not compatible with this version of ownCloud" => "L'applicazione non può essere installata poiché non è compatibile con questa versione di ownCloud",
+"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "L'applicazione non può essere installata poiché contiene il tag <shipped>true<shipped> che non è permesso alle applicazioni non shipped",
"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "L'applicazione non può essere installata poiché la versione in info.xml/version non è la stessa riportata dall'app store",
"App directory already exists" => "La cartella dell'applicazione esiste già",
"Can't create app folder. Please fix permissions. %s" => "Impossibile creare la cartella dell'applicazione. Correggi i permessi. %s",
diff --git a/lib/l10n/ja_JP.php b/lib/l10n/ja_JP.php
index 902170524b9..2d37001ca19 100644
--- a/lib/l10n/ja_JP.php
+++ b/lib/l10n/ja_JP.php
@@ -1,5 +1,7 @@
<?php
$TRANSLATIONS = array(
+"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => " \"%s\" アプリは、このバージョンのownCloudと互換性がない為、インストールできません。",
+"No app name specified" => "アプリ名が未指定",
"Help" => "ヘルプ",
"Personal" => "個人",
"Settings" => "設定",
@@ -13,6 +15,18 @@ $TRANSLATIONS = array(
"Back to Files" => "ファイルに戻る",
"Selected files too large to generate zip file." => "選択したファイルはZIPファイルの生成には大きすぎます。",
"Download the files in smaller chunks, seperately or kindly ask your administrator." => "ファイルは、小さいファイルに分割されてダウンロードされます。もしくは、管理者にお尋ねください。",
+"No source specified when installing app" => "アプリインストール時のソースが未指定",
+"No href specified when installing app from http" => "アプリインストール時のhttpの URL が未指定",
+"No path specified when installing app from local file" => "アプリインストール時のローカルファイルのパスが未指定",
+"Archives of type %s are not supported" => "\"%s\"タイプのアーカイブ形式は未サポート",
+"Failed to open archive when installing app" => "アプリをインストール中にアーカイブファイルを開けませんでした。",
+"App does not provide an info.xml file" => "アプリにinfo.xmlファイルが入っていません",
+"App can't be installed because of not allowed code in the App" => "アプリで許可されないコードが入っているのが原因でアプリがインストールできません",
+"App can't be installed because it is not compatible with this version of ownCloud" => "アプリは、このバージョンのownCloudと互換性がない為、インストールできません。",
+"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "非shippedアプリには許可されない<shipped>true</shipped>タグが含まれているためにアプリをインストール出来ません。",
+"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "info.xml/versionのバージョンがアプリストアのバージョンと合っていない為、アプリはインストールされません",
+"App directory already exists" => "アプリディレクトリは既に存在します",
+"Can't create app folder. Please fix permissions. %s" => "アプリフォルダを作成出来ませんでした。%s のパーミッションを修正してください。",
"Application is not enabled" => "アプリケーションは無効です",
"Authentication error" => "認証エラー",
"Token expired. Please reload page." => "トークンが無効になりました。ページを再読込してください。",
diff --git a/lib/l10n/nn_NO.php b/lib/l10n/nn_NO.php
index 28b4f7b7d94..d5da8c64415 100644
--- a/lib/l10n/nn_NO.php
+++ b/lib/l10n/nn_NO.php
@@ -10,15 +10,15 @@ $TRANSLATIONS = array(
"Files" => "Filer",
"Text" => "Tekst",
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Tenaren din er ikkje enno rett innstilt til å tilby filsynkronisering sidan WebDAV-grensesnittet ser ut til å vera øydelagt.",
-"Please double check the <a href='%s'>installation guides</a>." => "Ver vennleg og dobbeltsjekk <a href='%s'>installasjonsrettleiinga</a>.",
+"Please double check the <a href='%s'>installation guides</a>." => "Ver venleg og dobbeltsjekk <a href='%s'>installasjonsrettleiinga</a>.",
"seconds ago" => "sekund sidan",
-"_%n minute ago_::_%n minutes ago_" => array("",""),
-"_%n hour ago_::_%n hours ago_" => array("",""),
+"_%n minute ago_::_%n minutes ago_" => array("","%n minutt sidan"),
+"_%n hour ago_::_%n hours ago_" => array("","%n timar sidan"),
"today" => "i dag",
"yesterday" => "i går",
-"_%n day go_::_%n days ago_" => array("",""),
+"_%n day go_::_%n days ago_" => array("","%n dagar sidan"),
"last month" => "førre månad",
-"_%n month ago_::_%n months ago_" => array("",""),
+"_%n month ago_::_%n months ago_" => array("","%n månadar sidan"),
"last year" => "i fjor",
"years ago" => "år sidan"
);
diff --git a/lib/l10n/nqo.php b/lib/l10n/nqo.php
new file mode 100644
index 00000000000..e7b09649a24
--- /dev/null
+++ b/lib/l10n/nqo.php
@@ -0,0 +1,8 @@
+<?php
+$TRANSLATIONS = array(
+"_%n minute ago_::_%n minutes ago_" => array(""),
+"_%n hour ago_::_%n hours ago_" => array(""),
+"_%n day go_::_%n days ago_" => array(""),
+"_%n month ago_::_%n months ago_" => array("")
+);
+$PLURAL_FORMS = "nplurals=1; plural=0;";
diff --git a/lib/l10n/pl.php b/lib/l10n/pl.php
index 984043aa0be..4acd735d692 100644
--- a/lib/l10n/pl.php
+++ b/lib/l10n/pl.php
@@ -1,5 +1,7 @@
<?php
$TRANSLATIONS = array(
+"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "Aplikacja \"%s\" nie może zostać zainstalowana, ponieważ nie jest zgodna z tą wersją ownCloud.",
+"No app name specified" => "Nie określono nazwy aplikacji",
"Help" => "Pomoc",
"Personal" => "Osobiste",
"Settings" => "Ustawienia",
@@ -13,6 +15,18 @@ $TRANSLATIONS = array(
"Back to Files" => "Wróć do plików",
"Selected files too large to generate zip file." => "Wybrane pliki są zbyt duże, aby wygenerować plik zip.",
"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Pobierz pliki w mniejszy kawałkach, oddzielnie lub poproś administratora o zwiększenie limitu.",
+"No source specified when installing app" => "Nie określono źródła podczas instalacji aplikacji",
+"No href specified when installing app from http" => "Nie określono linku skąd aplikacja ma być zainstalowana",
+"No path specified when installing app from local file" => "Nie określono lokalnego pliku z którego miała być instalowana aplikacja",
+"Archives of type %s are not supported" => "Typ archiwum %s nie jest obsługiwany",
+"Failed to open archive when installing app" => "Nie udało się otworzyć archiwum podczas instalacji aplikacji",
+"App does not provide an info.xml file" => "Aplikacja nie posiada pliku info.xml",
+"App can't be installed because of not allowed code in the App" => "Aplikacja nie może być zainstalowany ponieważ nie dopuszcza kod w aplikacji",
+"App can't be installed because it is not compatible with this version of ownCloud" => "Aplikacja nie może zostać zainstalowana ponieważ jest niekompatybilna z tą wersja ownCloud",
+"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "Aplikacja nie może być zainstalowana ponieważ true tag nie jest <shipped>true</shipped> , co nie jest dozwolone dla aplikacji nie wysłanych",
+"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "Nie można zainstalować aplikacji, ponieważ w wersji info.xml/version nie jest taka sama, jak wersja z app store",
+"App directory already exists" => "Katalog aplikacji już isnieje",
+"Can't create app folder. Please fix permissions. %s" => "Nie mogę utworzyć katalogu aplikacji. Proszę popraw uprawnienia. %s",
"Application is not enabled" => "Aplikacja nie jest włączona",
"Authentication error" => "Błąd uwierzytelniania",
"Token expired. Please reload page." => "Token wygasł. Proszę ponownie załadować stronę.",
@@ -40,13 +54,13 @@ $TRANSLATIONS = array(
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Serwer internetowy nie jest jeszcze poprawnie skonfigurowany, aby umożliwić synchronizację plików, ponieważ interfejs WebDAV wydaje się być uszkodzony.",
"Please double check the <a href='%s'>installation guides</a>." => "Sprawdź ponownie <a href='%s'>przewodniki instalacji</a>.",
"seconds ago" => "sekund temu",
-"_%n minute ago_::_%n minutes ago_" => array("","",""),
-"_%n hour ago_::_%n hours ago_" => array("","",""),
+"_%n minute ago_::_%n minutes ago_" => array("%n minute temu","%n minut temu","%n minut temu"),
+"_%n hour ago_::_%n hours ago_" => array("%n godzinę temu","%n godzin temu","%n godzin temu"),
"today" => "dziś",
"yesterday" => "wczoraj",
-"_%n day go_::_%n days ago_" => array("","",""),
+"_%n day go_::_%n days ago_" => array("%n dzień temu","%n dni temu","%n dni temu"),
"last month" => "w zeszłym miesiącu",
-"_%n month ago_::_%n months ago_" => array("","",""),
+"_%n month ago_::_%n months ago_" => array("%n miesiąc temu","%n miesięcy temu","%n miesięcy temu"),
"last year" => "w zeszłym roku",
"years ago" => "lat temu",
"Caused by:" => "Spowodowane przez:",
diff --git a/lib/l10n/pt_BR.php b/lib/l10n/pt_BR.php
index a2379ca4883..72bc1f36a1e 100644
--- a/lib/l10n/pt_BR.php
+++ b/lib/l10n/pt_BR.php
@@ -54,13 +54,13 @@ $TRANSLATIONS = array(
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Seu servidor web não está configurado corretamente para permitir sincronização de arquivos porque a interface WebDAV parece estar quebrada.",
"Please double check the <a href='%s'>installation guides</a>." => "Por favor, confira os <a href='%s'>guias de instalação</a>.",
"seconds ago" => "segundos atrás",
-"_%n minute ago_::_%n minutes ago_" => array("",""),
-"_%n hour ago_::_%n hours ago_" => array("",""),
+"_%n minute ago_::_%n minutes ago_" => array("","ha %n minutos"),
+"_%n hour ago_::_%n hours ago_" => array("","ha %n horas"),
"today" => "hoje",
"yesterday" => "ontem",
-"_%n day go_::_%n days ago_" => array("",""),
+"_%n day go_::_%n days ago_" => array("","ha %n dias"),
"last month" => "último mês",
-"_%n month ago_::_%n months ago_" => array("",""),
+"_%n month ago_::_%n months ago_" => array("","ha %n meses"),
"last year" => "último ano",
"years ago" => "anos atrás",
"Caused by:" => "Causados ​​por:",
diff --git a/lib/l10n/pt_PT.php b/lib/l10n/pt_PT.php
index c8a2f78cbf5..bf540012249 100644
--- a/lib/l10n/pt_PT.php
+++ b/lib/l10n/pt_PT.php
@@ -40,13 +40,13 @@ $TRANSLATIONS = array(
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "O seu servidor web não está configurado correctamente para autorizar sincronização de ficheiros, pois o interface WebDAV parece estar com problemas.",
"Please double check the <a href='%s'>installation guides</a>." => "Por favor verifique <a href='%s'>installation guides</a>.",
"seconds ago" => "Minutos atrás",
-"_%n minute ago_::_%n minutes ago_" => array("",""),
-"_%n hour ago_::_%n hours ago_" => array("",""),
+"_%n minute ago_::_%n minutes ago_" => array("","%n minutos atrás"),
+"_%n hour ago_::_%n hours ago_" => array("","%n horas atrás"),
"today" => "hoje",
"yesterday" => "ontem",
-"_%n day go_::_%n days ago_" => array("",""),
+"_%n day go_::_%n days ago_" => array("","%n dias atrás"),
"last month" => "ultímo mês",
-"_%n month ago_::_%n months ago_" => array("",""),
+"_%n month ago_::_%n months ago_" => array("","%n meses atrás"),
"last year" => "ano passado",
"years ago" => "anos atrás",
"Caused by:" => "Causado por:",
diff --git a/lib/l10n/sq.php b/lib/l10n/sq.php
index c2447b7ea23..edaa1df2b86 100644
--- a/lib/l10n/sq.php
+++ b/lib/l10n/sq.php
@@ -36,13 +36,13 @@ $TRANSLATIONS = array(
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Serveri web i juaji nuk është konfiguruar akoma për të lejuar sinkronizimin e skedarëve sepse ndërfaqja WebDAV mund të jetë e dëmtuar.",
"Please double check the <a href='%s'>installation guides</a>." => "Ju lutemi kontrolloni mirë <a href='%s'>shoqëruesin e instalimit</a>.",
"seconds ago" => "sekonda më parë",
-"_%n minute ago_::_%n minutes ago_" => array("",""),
-"_%n hour ago_::_%n hours ago_" => array("",""),
+"_%n minute ago_::_%n minutes ago_" => array("","%n minuta më parë"),
+"_%n hour ago_::_%n hours ago_" => array("","%n orë më parë"),
"today" => "sot",
"yesterday" => "dje",
-"_%n day go_::_%n days ago_" => array("",""),
+"_%n day go_::_%n days ago_" => array("","%n ditë më parë"),
"last month" => "muajin e shkuar",
-"_%n month ago_::_%n months ago_" => array("",""),
+"_%n month ago_::_%n months ago_" => array("","%n muaj më parë"),
"last year" => "vitin e shkuar",
"years ago" => "vite më parë",
"Could not find category \"%s\"" => "Kategoria \"%s\" nuk u gjet"
diff --git a/lib/migration/content.php b/lib/migration/content.php
index 2d8268a1d74..4413d722731 100644
--- a/lib/migration/content.php
+++ b/lib/migration/content.php
@@ -191,7 +191,8 @@ class OC_Migration_Content{
if( !file_exists( $dir ) ) {
return false;
}
- if ($dirhandle = opendir($dir)) {
+ $dirhandle = opendir($dir);
+ if(is_resource($dirhandle)) {
while (false !== ( $file = readdir($dirhandle))) {
if (( $file != '.' ) && ( $file != '..' )) {
diff --git a/lib/ocs/activity.php b/lib/ocs/activity.php
deleted file mode 100644
index c30e21018d3..00000000000
--- a/lib/ocs/activity.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-/**
-* ownCloud
-*
-* @author Frank Karlitschek
-* @copyright 2012 Frank Karlitschek frank@owncloud.org
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-class OC_OCS_Activity {
-
- public static function activityGet($parameters){
- // TODO
- }
-}
diff --git a/lib/ocsclient.php b/lib/ocsclient.php
index bd0302a2a81..58636f806be 100644
--- a/lib/ocsclient.php
+++ b/lib/ocsclient.php
@@ -40,16 +40,6 @@ class OC_OCSClient{
return($url);
}
- /**
- * @brief Get the url of the OCS KB server.
- * @returns string of the KB server
- * This function returns the url of the OCS knowledge base server. It´s
- * possible to set it in the config file or it will fallback to the default
- */
- private static function getKBURL() {
- $url = OC_Config::getValue('knowledgebaseurl', 'http://api.apps.owncloud.com/v1');
- return($url);
- }
/**
* @brief Get the content of an OCS url call.
@@ -214,44 +204,5 @@ class OC_OCSClient{
}
- /**
- * @brief Get all the knowledgebase entries from the OCS server
- * @returns array with q and a data
- *
- * This function returns a list of all the knowledgebase entries from the OCS server
- */
- public static function getKnownledgebaseEntries($page, $pagesize, $search='') {
- $kbe = array('totalitems' => 0);
- if(OC_Config::getValue('knowledgebaseenabled', true)) {
- $p = (int) $page;
- $s = (int) $pagesize;
- $searchcmd = '';
- if ($search) {
- $searchcmd = '&search='.urlencode($search);
- }
- $url = OC_OCSClient::getKBURL().'/knowledgebase/data?type=150&page='. $p .'&pagesize='. $s . $searchcmd;
- $xml = OC_OCSClient::getOCSresponse($url);
- $data = @simplexml_load_string($xml);
- if($data===false) {
- OC_Log::write('core', 'Unable to parse knowledgebase content', OC_Log::FATAL);
- return null;
- }
- $tmp = $data->data->content;
- for($i = 0; $i < count($tmp); $i++) {
- $kbe[] = array(
- 'id' => $tmp[$i]->id,
- 'name' => $tmp[$i]->name,
- 'description' => $tmp[$i]->description,
- 'answer' => $tmp[$i]->answer,
- 'preview1' => $tmp[$i]->smallpreviewpic1,
- 'detailpage' => $tmp[$i]->detailpage
- );
- }
- $kbe['totalitems'] = $data->meta->totalitems;
- }
- return $kbe;
- }
-
-
}
diff --git a/lib/preview.php b/lib/preview.php
new file mode 100755
index 00000000000..b40ba191fba
--- /dev/null
+++ b/lib/preview.php
@@ -0,0 +1,627 @@
+<?php
+/**
+ * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ *
+ * Thumbnails:
+ * structure of filename:
+ * /data/user/thumbnails/pathhash/x-y.png
+ *
+ */
+namespace OC;
+
+require_once 'preview/image.php';
+require_once 'preview/movies.php';
+require_once 'preview/mp3.php';
+require_once 'preview/pdf.php';
+require_once 'preview/svg.php';
+require_once 'preview/txt.php';
+require_once 'preview/unknown.php';
+require_once 'preview/office.php';
+
+class Preview {
+ //the thumbnail folder
+ const THUMBNAILS_FOLDER = 'thumbnails';
+
+ //config
+ private $maxScaleFactor;
+ private $configMaxX;
+ private $configMaxY;
+
+ //fileview object
+ private $fileView = null;
+ private $userView = null;
+
+ //vars
+ private $file;
+ private $maxX;
+ private $maxY;
+ private $scalingup;
+
+ //preview images object
+ private $preview;
+
+ //preview providers
+ static private $providers = array();
+ static private $registeredProviders = array();
+
+ /**
+ * @brief check if thumbnail or bigger version of thumbnail of file is cached
+ * @param string $user userid - if no user is given, OC_User::getUser will be used
+ * @param string $root path of root
+ * @param string $file The path to the file where you want a thumbnail from
+ * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
+ * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
+ * @param bool $scalingUp Disable/Enable upscaling of previews
+ * @return mixed (bool / string)
+ * false if thumbnail does not exist
+ * path to thumbnail if thumbnail exists
+ */
+ public function __construct($user='', $root='/', $file='', $maxX=1, $maxY=1, $scalingUp=true) {
+ //set config
+ $this->configMaxX = \OC_Config::getValue('preview_max_x', null);
+ $this->configMaxY = \OC_Config::getValue('preview_max_y', null);
+ $this->maxScaleFactor = \OC_Config::getValue('preview_max_scale_factor', 2);
+
+ //save parameters
+ $this->setFile($file);
+ $this->setMaxX($maxX);
+ $this->setMaxY($maxY);
+ $this->setScalingUp($scalingUp);
+
+ //init fileviews
+ if($user === ''){
+ $user = \OC_User::getUser();
+ }
+ $this->fileView = new \OC\Files\View('/' . $user . '/' . $root);
+ $this->userView = new \OC\Files\View('/' . $user);
+
+ $this->preview = null;
+
+ //check if there are preview backends
+ if(empty(self::$providers)) {
+ self::initProviders();
+ }
+
+ if(empty(self::$providers)) {
+ \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR);
+ throw new \Exception('No preview providers');
+ }
+ }
+
+ /**
+ * @brief returns the path of the file you want a thumbnail from
+ * @return string
+ */
+ public function getFile() {
+ return $this->file;
+ }
+
+ /**
+ * @brief returns the max width of the preview
+ * @return integer
+ */
+ public function getMaxX() {
+ return $this->maxX;
+ }
+
+ /**
+ * @brief returns the max height of the preview
+ * @return integer
+ */
+ public function getMaxY() {
+ return $this->maxY;
+ }
+
+ /**
+ * @brief returns whether or not scalingup is enabled
+ * @return bool
+ */
+ public function getScalingUp() {
+ return $this->scalingup;
+ }
+
+ /**
+ * @brief returns the name of the thumbnailfolder
+ * @return string
+ */
+ public function getThumbnailsFolder() {
+ return self::THUMBNAILS_FOLDER;
+ }
+
+ /**
+ * @brief returns the max scale factor
+ * @return integer
+ */
+ public function getMaxScaleFactor() {
+ return $this->maxScaleFactor;
+ }
+
+ /**
+ * @brief returns the max width set in ownCloud's config
+ * @return integer
+ */
+ public function getConfigMaxX() {
+ return $this->configMaxX;
+ }
+
+ /**
+ * @brief returns the max height set in ownCloud's config
+ * @return integer
+ */
+ public function getConfigMaxY() {
+ return $this->configMaxY;
+ }
+
+ /**
+ * @brief set the path of the file you want a thumbnail from
+ * @param string $file
+ * @return $this
+ */
+ public function setFile($file) {
+ $this->file = $file;
+ return $this;
+ }
+
+ /**
+ * @brief set the the max width of the preview
+ * @param int $maxX
+ * @return $this
+ */
+ public function setMaxX($maxX=1) {
+ if($maxX <= 0) {
+ throw new \Exception('Cannot set width of 0 or smaller!');
+ }
+ $configMaxX = $this->getConfigMaxX();
+ if(!is_null($configMaxX)) {
+ if($maxX > $configMaxX) {
+ \OC_Log::write('core', 'maxX reduced from ' . $maxX . ' to ' . $configMaxX, \OC_Log::DEBUG);
+ $maxX = $configMaxX;
+ }
+ }
+ $this->maxX = $maxX;
+ return $this;
+ }
+
+ /**
+ * @brief set the the max height of the preview
+ * @param int $maxY
+ * @return $this
+ */
+ public function setMaxY($maxY=1) {
+ if($maxY <= 0) {
+ throw new \Exception('Cannot set height of 0 or smaller!');
+ }
+ $configMaxY = $this->getConfigMaxY();
+ if(!is_null($configMaxY)) {
+ if($maxY > $configMaxY) {
+ \OC_Log::write('core', 'maxX reduced from ' . $maxY . ' to ' . $configMaxY, \OC_Log::DEBUG);
+ $maxY = $configMaxY;
+ }
+ }
+ $this->maxY = $maxY;
+ return $this;
+ }
+
+ /**
+ * @brief set whether or not scalingup is enabled
+ * @param bool $scalingUp
+ * @return $this
+ */
+ public function setScalingup($scalingUp) {
+ if($this->getMaxScaleFactor() === 1) {
+ $scalingUp = false;
+ }
+ $this->scalingup = $scalingUp;
+ return $this;
+ }
+
+ /**
+ * @brief check if all parameters are valid
+ * @return bool
+ */
+ public function isFileValid() {
+ $file = $this->getFile();
+ if($file === '') {
+ \OC_Log::write('core', 'No filename passed', \OC_Log::DEBUG);
+ return false;
+ }
+
+ if(!$this->fileView->file_exists($file)) {
+ \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::DEBUG);
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @brief deletes previews of a file with specific x and y
+ * @return bool
+ */
+ public function deletePreview() {
+ $file = $this->getFile();
+
+ $fileInfo = $this->fileView->getFileInfo($file);
+ $fileId = $fileInfo['fileid'];
+
+ $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png';
+ $this->userView->unlink($previewPath);
+ return !$this->userView->file_exists($previewPath);
+ }
+
+ /**
+ * @brief deletes all previews of a file
+ * @return bool
+ */
+ public function deleteAllPreviews() {
+ $file = $this->getFile();
+
+ $fileInfo = $this->fileView->getFileInfo($file);
+ $fileId = $fileInfo['fileid'];
+
+ $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
+ $this->userView->deleteAll($previewPath);
+ $this->userView->rmdir($previewPath);
+ return !$this->userView->is_dir($previewPath);
+ }
+
+ /**
+ * @brief check if thumbnail or bigger version of thumbnail of file is cached
+ * @return mixed (bool / string)
+ * false if thumbnail does not exist
+ * path to thumbnail if thumbnail exists
+ */
+ private function isCached() {
+ $file = $this->getFile();
+ $maxX = $this->getMaxX();
+ $maxY = $this->getMaxY();
+ $scalingUp = $this->getScalingUp();
+ $maxScaleFactor = $this->getMaxScaleFactor();
+
+ $fileInfo = $this->fileView->getFileInfo($file);
+ $fileId = $fileInfo['fileid'];
+
+ if(is_null($fileId)) {
+ return false;
+ }
+
+ $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
+ if(!$this->userView->is_dir($previewPath)) {
+ return false;
+ }
+
+ //does a preview with the wanted height and width already exist?
+ if($this->userView->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) {
+ return $previewPath . $maxX . '-' . $maxY . '.png';
+ }
+
+ $wantedAspectRatio = (float) ($maxX / $maxY);
+
+ //array for usable cached thumbnails
+ $possibleThumbnails = array();
+
+ $allThumbnails = $this->userView->getDirectoryContent($previewPath);
+ foreach($allThumbnails as $thumbnail) {
+ $name = rtrim($thumbnail['name'], '.png');
+ $size = explode('-', $name);
+ $x = (int) $size[0];
+ $y = (int) $size[1];
+
+ $aspectRatio = (float) ($x / $y);
+ if($aspectRatio !== $wantedAspectRatio) {
+ continue;
+ }
+
+ if($x < $maxX || $y < $maxY) {
+ if($scalingUp) {
+ $scalefactor = $maxX / $x;
+ if($scalefactor > $maxScaleFactor) {
+ continue;
+ }
+ }else{
+ continue;
+ }
+ }
+ $possibleThumbnails[$x] = $thumbnail['path'];
+ }
+
+ if(count($possibleThumbnails) === 0) {
+ return false;
+ }
+
+ if(count($possibleThumbnails) === 1) {
+ return current($possibleThumbnails);
+ }
+
+ ksort($possibleThumbnails);
+
+ if(key(reset($possibleThumbnails)) > $maxX) {
+ return current(reset($possibleThumbnails));
+ }
+
+ if(key(end($possibleThumbnails)) < $maxX) {
+ return current(end($possibleThumbnails));
+ }
+
+ foreach($possibleThumbnails as $width => $path) {
+ if($width < $maxX) {
+ continue;
+ }else{
+ return $path;
+ }
+ }
+ }
+
+ /**
+ * @brief return a preview of a file
+ * @return \OC_Image
+ */
+ public function getPreview() {
+ if(!is_null($this->preview) && $this->preview->valid()){
+ return $this->preview;
+ }
+
+ $this->preview = null;
+ $file = $this->getFile();
+ $maxX = $this->getMaxX();
+ $maxY = $this->getMaxY();
+ $scalingUp = $this->getScalingUp();
+
+ $fileInfo = $this->fileView->getFileInfo($file);
+ $fileId = $fileInfo['fileid'];
+
+ $cached = $this->isCached();
+
+ if($cached) {
+ $image = new \OC_Image($this->userView->file_get_contents($cached, 'r'));
+ $this->preview = $image->valid() ? $image : null;
+ $this->resizeAndCrop();
+ }
+
+ if(is_null($this->preview)) {
+ $mimetype = $this->fileView->getMimeType($file);
+ $preview = null;
+
+ foreach(self::$providers as $supportedMimetype => $provider) {
+ if(!preg_match($supportedMimetype, $mimetype)) {
+ continue;
+ }
+
+ \OC_Log::write('core', 'Generating preview for "' . $file . '" with "' . get_class($provider) . '"', \OC_Log::DEBUG);
+
+ $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileView);
+
+ if(!($preview instanceof \OC_Image)) {
+ continue;
+ }
+
+ $this->preview = $preview;
+ $this->resizeAndCrop();
+
+ $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
+ $cachePath = $previewPath . $maxX . '-' . $maxY . '.png';
+
+ if($this->userView->is_dir($this->getThumbnailsFolder() . '/') === false) {
+ $this->userView->mkdir($this->getThumbnailsFolder() . '/');
+ }
+
+ if($this->userView->is_dir($previewPath) === false) {
+ $this->userView->mkdir($previewPath);
+ }
+
+ $this->userView->file_put_contents($cachePath, $preview->data());
+
+ break;
+ }
+ }
+
+ if(is_null($this->preview)) {
+ $this->preview = new \OC_Image();
+ }
+
+ return $this->preview;
+ }
+
+ /**
+ * @brief show preview
+ * @return void
+ */
+ public function showPreview() {
+ \OCP\Response::enableCaching(3600 * 24); // 24 hours
+ if(is_null($this->preview)) {
+ $this->getPreview();
+ }
+ $this->preview->show();
+ return;
+ }
+
+ /**
+ * @brief show preview
+ * @return void
+ */
+ public function show() {
+ $this->showPreview();
+ return;
+ }
+
+ /**
+ * @brief resize, crop and fix orientation
+ * @return void
+ */
+ private function resizeAndCrop() {
+ $image = $this->preview;
+ $x = $this->getMaxX();
+ $y = $this->getMaxY();
+ $scalingUp = $this->getScalingUp();
+ $maxscalefactor = $this->getMaxScaleFactor();
+
+ if(!($image instanceof \OC_Image)) {
+ \OC_Log::write('core', '$this->preview is not an instance of OC_Image', \OC_Log::DEBUG);
+ return;
+ }
+
+ $image->fixOrientation();
+
+ $realx = (int) $image->width();
+ $realy = (int) $image->height();
+
+ if($x === $realx && $y === $realy) {
+ $this->preview = $image;
+ return;
+ }
+
+ $factorX = $x / $realx;
+ $factorY = $y / $realy;
+
+ if($factorX >= $factorY) {
+ $factor = $factorX;
+ }else{
+ $factor = $factorY;
+ }
+
+ if($scalingUp === false) {
+ if($factor > 1) {
+ $factor = 1;
+ }
+ }
+
+ if(!is_null($maxscalefactor)) {
+ if($factor > $maxscalefactor) {
+ \OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $maxscalefactor, \OC_Log::DEBUG);
+ $factor = $maxscalefactor;
+ }
+ }
+
+ $newXsize = (int) ($realx * $factor);
+ $newYsize = (int) ($realy * $factor);
+
+ $image->preciseResize($newXsize, $newYsize);
+
+ if($newXsize === $x && $newYsize === $y) {
+ $this->preview = $image;
+ return;
+ }
+
+ if($newXsize >= $x && $newYsize >= $y) {
+ $cropX = floor(abs($x - $newXsize) * 0.5);
+ //don't crop previews on the Y axis, this sucks if it's a document.
+ //$cropY = floor(abs($y - $newYsize) * 0.5);
+ $cropY = 0;
+
+ $image->crop($cropX, $cropY, $x, $y);
+
+ $this->preview = $image;
+ return;
+ }
+
+ if($newXsize < $x || $newYsize < $y) {
+ if($newXsize > $x) {
+ $cropX = floor(($newXsize - $x) * 0.5);
+ $image->crop($cropX, 0, $x, $newYsize);
+ }
+
+ if($newYsize > $y) {
+ $cropY = floor(($newYsize - $y) * 0.5);
+ $image->crop(0, $cropY, $newXsize, $y);
+ }
+
+ $newXsize = (int) $image->width();
+ $newYsize = (int) $image->height();
+
+ //create transparent background layer
+ $backgroundlayer = imagecreatetruecolor($x, $y);
+ $white = imagecolorallocate($backgroundlayer, 255, 255, 255);
+ imagefill($backgroundlayer, 0, 0, $white);
+
+ $image = $image->resource();
+
+ $mergeX = floor(abs($x - $newXsize) * 0.5);
+ $mergeY = floor(abs($y - $newYsize) * 0.5);
+
+ imagecopy($backgroundlayer, $image, $mergeX, $mergeY, 0, 0, $newXsize, $newYsize);
+
+ //$black = imagecolorallocate(0,0,0);
+ //imagecolortransparent($transparentlayer, $black);
+
+ $image = new \OC_Image($backgroundlayer);
+
+ $this->preview = $image;
+ return;
+ }
+ }
+
+ /**
+ * @brief register a new preview provider to be used
+ * @param string $provider class name of a Preview_Provider
+ * @param array $options
+ * @return void
+ */
+ public static function registerProvider($class, $options=array()) {
+ self::$registeredProviders[]=array('class'=>$class, 'options'=>$options);
+ }
+
+ /**
+ * @brief create instances of all the registered preview providers
+ * @return void
+ */
+ private static function initProviders() {
+ if(!\OC_Config::getValue('enable_previews', true)) {
+ $provider = new Preview\Unknown(array());
+ self::$providers = array($provider->getMimeType() => $provider);
+ return;
+ }
+
+ if(count(self::$providers)>0) {
+ return;
+ }
+
+ foreach(self::$registeredProviders as $provider) {
+ $class=$provider['class'];
+ $options=$provider['options'];
+
+ $object = new $class($options);
+
+ self::$providers[$object->getMimeType()] = $object;
+ }
+
+ $keys = array_map('strlen', array_keys(self::$providers));
+ array_multisort($keys, SORT_DESC, self::$providers);
+ }
+
+ public static function post_write($args) {
+ self::post_delete($args);
+ }
+
+ public static function post_delete($args) {
+ $path = $args['path'];
+ if(substr($path, 0, 1) === '/') {
+ $path = substr($path, 1);
+ }
+ $preview = new Preview(\OC_User::getUser(), 'files/', $path);
+ $preview->deleteAllPreviews();
+ }
+
+ public static function isMimeSupported($mimetype) {
+ if(!\OC_Config::getValue('enable_previews', true)) {
+ return false;
+ }
+
+ //check if there are preview backends
+ if(empty(self::$providers)) {
+ self::initProviders();
+ }
+
+ //remove last element because it has the mimetype *
+ $providers = array_slice(self::$providers, 0, -1);
+ foreach($providers as $supportedMimetype => $provider) {
+ if(preg_match($supportedMimetype, $mimetype)) {
+ return true;
+ }
+ }
+ return false;
+ }
+} \ No newline at end of file
diff --git a/lib/preview/image.php b/lib/preview/image.php
new file mode 100644
index 00000000000..9aec967282d
--- /dev/null
+++ b/lib/preview/image.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+class Image extends Provider {
+
+ public function getMimeType() {
+ return '/image\/.*/';
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ //get fileinfo
+ $fileInfo = $fileview->getFileInfo($path);
+ if(!$fileInfo) {
+ return false;
+ }
+
+ //check if file is encrypted
+ if($fileInfo['encrypted'] === true) {
+ $image = new \OC_Image(stream_get_contents($fileview->fopen($path, 'r')));
+ }else{
+ $image = new \OC_Image();
+ $image->loadFromFile($fileview->getLocalFile($path));
+ }
+
+ return $image->valid() ? $image : false;
+ }
+}
+
+\OC\Preview::registerProvider('OC\Preview\Image'); \ No newline at end of file
diff --git a/lib/preview/movies.php b/lib/preview/movies.php
new file mode 100644
index 00000000000..c318137ff0e
--- /dev/null
+++ b/lib/preview/movies.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+$isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions')));
+$whichAVCONV = shell_exec('which avconv');
+$isAVCONVAvailable = !empty($whichAVCONV);
+
+if($isShellExecEnabled && $isAVCONVAvailable) {
+
+ class Movie extends Provider {
+
+ public function getMimeType() {
+ return '/video\/.*/';
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ $absPath = \OC_Helper::tmpFile();
+ $tmpPath = \OC_Helper::tmpFile();
+
+ $handle = $fileview->fopen($path, 'rb');
+
+ $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576
+ file_put_contents($absPath, $firstmb);
+
+ //$cmd = 'ffmpeg -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmpPath;
+ $cmd = 'avconv -an -y -ss 1 -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 ' . escapeshellarg($tmpPath);
+
+ shell_exec($cmd);
+
+ $image = new \OC_Image($tmpPath);
+
+ unlink($absPath);
+ unlink($tmpPath);
+
+ return $image->valid() ? $image : false;
+ }
+ }
+
+ \OC\Preview::registerProvider('OC\Preview\Movie');
+} \ No newline at end of file
diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php
new file mode 100644
index 00000000000..1eed566315c
--- /dev/null
+++ b/lib/preview/mp3.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+class MP3 extends Provider {
+
+ public function getMimeType() {
+ return '/audio\/mpeg/';
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ require_once('getid3/getid3.php');
+
+ $getID3 = new \getID3();
+
+ $tmpPath = $fileview->toTmpFile($path);
+
+ $tags = $getID3->analyze($tmpPath);
+ \getid3_lib::CopyTagsToComments($tags);
+ if(isset($tags['id3v2']['APIC'][0]['data'])) {
+ $picture = @$tags['id3v2']['APIC'][0]['data'];
+ unlink($tmpPath);
+ $image = new \OC_Image($picture);
+ return $image->valid() ? $image : $this->getNoCoverThumbnail();
+ }
+
+ return $this->getNoCoverThumbnail();
+ }
+
+ private function getNoCoverThumbnail() {
+ $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png';
+
+ if(!file_exists($icon)) {
+ return false;
+ }
+
+ $image = new \OC_Image($icon);
+ return $image->valid() ? $image : false;
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\MP3'); \ No newline at end of file
diff --git a/lib/preview/office-cl.php b/lib/preview/office-cl.php
new file mode 100644
index 00000000000..112909d6523
--- /dev/null
+++ b/lib/preview/office-cl.php
@@ -0,0 +1,134 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+//we need imagick to convert
+class Office extends Provider {
+
+ private $cmd;
+
+ public function getMimeType() {
+ return null;
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ $this->initCmd();
+ if(is_null($this->cmd)) {
+ return false;
+ }
+
+ $absPath = $fileview->toTmpFile($path);
+
+ $tmpDir = get_temp_dir();
+
+ $defaultParameters = ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ';
+ $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
+
+ $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
+ $export = 'export HOME=/' . $tmpDir;
+
+ shell_exec($export . "\n" . $exec);
+
+ //create imagick object from pdf
+ try{
+ $pdf = new \imagick($absPath . '.pdf' . '[0]');
+ $pdf->setImageFormat('jpg');
+ } catch (\Exception $e) {
+ unlink($absPath);
+ unlink($absPath . '.pdf');
+ \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
+ return false;
+ }
+
+ $image = new \OC_Image($pdf);
+
+ unlink($absPath);
+ unlink($absPath . '.pdf');
+
+ return $image->valid() ? $image : false;
+ }
+
+ private function initCmd() {
+ $cmd = '';
+
+ if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) {
+ $cmd = \OC_Config::getValue('preview_libreoffice_path', null);
+ }
+
+ $whichLibreOffice = shell_exec('which libreoffice');
+ if($cmd === '' && !empty($whichLibreOffice)) {
+ $cmd = 'libreoffice';
+ }
+
+ $whichOpenOffice = shell_exec('which openoffice');
+ if($cmd === '' && !empty($whichOpenOffice)) {
+ $cmd = 'openoffice';
+ }
+
+ if($cmd === '') {
+ $cmd = null;
+ }
+
+ $this->cmd = $cmd;
+ }
+}
+
+//.doc, .dot
+class MSOfficeDoc extends Office {
+
+ public function getMimeType() {
+ return '/application\/msword/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\MSOfficeDoc');
+
+//.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m)
+class MSOffice2003 extends Office {
+
+ public function getMimeType() {
+ return '/application\/vnd.ms-.*/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\MSOffice2003');
+
+//.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
+class MSOffice2007 extends Office {
+
+ public function getMimeType() {
+ return '/application\/vnd.openxmlformats-officedocument.*/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\MSOffice2007');
+
+//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
+class OpenDocument extends Office {
+
+ public function getMimeType() {
+ return '/application\/vnd.oasis.opendocument.*/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\OpenDocument');
+
+//.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
+class StarOffice extends Office {
+
+ public function getMimeType() {
+ return '/application\/vnd.sun.xml.*/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\StarOffice'); \ No newline at end of file
diff --git a/lib/preview/office-fallback.php b/lib/preview/office-fallback.php
new file mode 100644
index 00000000000..e69ab0ab8cb
--- /dev/null
+++ b/lib/preview/office-fallback.php
@@ -0,0 +1,142 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+/* //There is no (good) php-only solution for converting 2003 word documents to pdfs / pngs ...
+class DOC extends Provider {
+
+ public function getMimeType() {
+ return '/application\/msword/';
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ require_once('');
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\DOC');
+*/
+
+class DOCX extends Provider {
+
+ public function getMimeType() {
+ return '/application\/vnd.openxmlformats-officedocument.wordprocessingml.document/';
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ require_once('phpdocx/classes/TransformDoc.inc');
+
+ $tmpDoc = $fileview->toTmpFile($path);
+
+ $transformdoc = new \TransformDoc();
+ $transformdoc->setStrFile($tmpDoc);
+ $transformdoc->generatePDF($tmpDoc);
+
+ $pdf = new \imagick($tmpDoc . '[0]');
+ $pdf->setImageFormat('jpg');
+
+ unlink($tmpDoc);
+
+ $image = new \OC_Image($pdf);
+
+ return $image->valid() ? $image : false;
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\DOCX');
+
+class MSOfficeExcel extends Provider {
+
+ public function getMimeType() {
+ return null;
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ require_once('PHPExcel/Classes/PHPExcel.php');
+ require_once('PHPExcel/Classes/PHPExcel/IOFactory.php');
+
+ $absPath = $fileview->toTmpFile($path);
+ $tmpPath = \OC_Helper::tmpFile();
+
+ $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF;
+ $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf';
+
+ \PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
+
+ $phpexcel = new \PHPExcel($absPath);
+ $excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF');
+ $excel->save($tmpPath);
+
+ $pdf = new \imagick($tmpPath . '[0]');
+ $pdf->setImageFormat('jpg');
+
+ unlink($absPath);
+ unlink($tmpPath);
+
+ $image = new \OC_Image($pdf);
+
+ return $image->valid() ? $image : false;
+ }
+
+}
+
+class XLS extends MSOfficeExcel {
+
+ public function getMimeType() {
+ return '/application\/vnd.ms-excel/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\XLS');
+
+class XLSX extends MSOfficeExcel {
+
+ public function getMimeType() {
+ return '/application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\XLSX');
+
+/* //There is no (good) php-only solution for converting powerpoint documents to pdfs / pngs ...
+class MSOfficePowerPoint extends Provider {
+
+ public function getMimeType() {
+ return null;
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ return false;
+ }
+
+}
+
+class PPT extends MSOfficePowerPoint {
+
+ public function getMimeType() {
+ return '/application\/vnd.ms-powerpoint/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\PPT');
+
+class PPTX extends MSOfficePowerPoint {
+
+ public function getMimeType() {
+ return '/application\/vnd.openxmlformats-officedocument.presentationml.presentation/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\PPTX');
+*/ \ No newline at end of file
diff --git a/lib/preview/office.php b/lib/preview/office.php
new file mode 100644
index 00000000000..5287bbd6ac1
--- /dev/null
+++ b/lib/preview/office.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+//both, libreoffice backend and php fallback, need imagick
+if (extension_loaded('imagick')) {
+ $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions')));
+ $whichLibreOffice = shell_exec('which libreoffice');
+ $isLibreOfficeAvailable = !empty($whichLibreOffice);
+ $whichOpenOffice = shell_exec('which libreoffice');
+ $isOpenOfficeAvailable = !empty($whichOpenOffice);
+ //let's see if there is libreoffice or openoffice on this machine
+ if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) {
+ require_once('office-cl.php');
+ }else{
+ //in case there isn't, use our fallback
+ require_once('office-fallback.php');
+ }
+} \ No newline at end of file
diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php
new file mode 100644
index 00000000000..cc974b68818
--- /dev/null
+++ b/lib/preview/pdf.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+if (extension_loaded('imagick')) {
+
+ class PDF extends Provider {
+
+ public function getMimeType() {
+ return '/application\/pdf/';
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ $tmpPath = $fileview->toTmpFile($path);
+
+ //create imagick object from pdf
+ try{
+ $pdf = new \imagick($tmpPath . '[0]');
+ $pdf->setImageFormat('jpg');
+ } catch (\Exception $e) {
+ \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
+ return false;
+ }
+
+ unlink($tmpPath);
+
+ //new image object
+ $image = new \OC_Image($pdf);
+ //check if image object is valid
+ return $image->valid() ? $image : false;
+ }
+ }
+
+ \OC\Preview::registerProvider('OC\Preview\PDF');
+}
diff --git a/lib/preview/provider.php b/lib/preview/provider.php
new file mode 100644
index 00000000000..e4a730bafc8
--- /dev/null
+++ b/lib/preview/provider.php
@@ -0,0 +1,19 @@
+<?php
+namespace OC\Preview;
+
+abstract class Provider {
+ private $options;
+
+ public function __construct($options) {
+ $this->options=$options;
+ }
+
+ abstract public function getMimeType();
+
+ /**
+ * search for $query
+ * @param string $query
+ * @return
+ */
+ abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview);
+}
diff --git a/lib/preview/svg.php b/lib/preview/svg.php
new file mode 100644
index 00000000000..b49e51720fa
--- /dev/null
+++ b/lib/preview/svg.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+if (extension_loaded('imagick')) {
+
+ class SVG extends Provider {
+
+ public function getMimeType() {
+ return '/image\/svg\+xml/';
+ }
+
+ public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) {
+ try{
+ $svg = new \Imagick();
+ $svg->setBackgroundColor(new \ImagickPixel('transparent'));
+
+ $content = stream_get_contents($fileview->fopen($path, 'r'));
+ if(substr($content, 0, 5) !== '<?xml') {
+ $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
+ }
+
+ $svg->readImageBlob($content);
+ $svg->setImageFormat('png32');
+ } catch (\Exception $e) {
+ \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
+ return false;
+ }
+
+
+ //new image object
+ $image = new \OC_Image();
+ $image->loadFromData($svg);
+ //check if image object is valid
+ return $image->valid() ? $image : false;
+ }
+ }
+
+ \OC\Preview::registerProvider('OC\Preview\SVG');
+
+} \ No newline at end of file
diff --git a/lib/preview/txt.php b/lib/preview/txt.php
new file mode 100644
index 00000000000..a487330691e
--- /dev/null
+++ b/lib/preview/txt.php
@@ -0,0 +1,73 @@
+<?php
+/**
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+class TXT extends Provider {
+
+ public function getMimeType() {
+ return '/text\/.*/';
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ $content = $fileview->fopen($path, 'r');
+ $content = stream_get_contents($content);
+
+ //don't create previews of empty text files
+ if(trim($content) === '') {
+ return false;
+ }
+
+ $lines = preg_split("/\r\n|\n|\r/", $content);
+
+ $fontSize = 5; //5px
+ $lineSize = ceil($fontSize * 1.25);
+
+ $image = imagecreate($maxX, $maxY);
+ imagecolorallocate($image, 255, 255, 255);
+ $textColor = imagecolorallocate($image, 0, 0, 0);
+
+ foreach($lines as $index => $line) {
+ $index = $index + 1;
+
+ $x = (int) 1;
+ $y = (int) ($index * $lineSize) - $fontSize;
+
+ imagestring($image, 1, $x, $y, $line, $textColor);
+
+ if(($index * $lineSize) >= $maxY) {
+ break;
+ }
+ }
+
+ $image = new \OC_Image($image);
+
+ return $image->valid() ? $image : false;
+ }
+}
+
+\OC\Preview::registerProvider('OC\Preview\TXT');
+
+class PHP extends TXT {
+
+ public function getMimeType() {
+ return '/application\/x-php/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\PHP');
+
+class JavaScript extends TXT {
+
+ public function getMimeType() {
+ return '/application\/javascript/';
+ }
+
+}
+
+\OC\Preview::registerProvider('OC\Preview\JavaScript'); \ No newline at end of file
diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php
new file mode 100644
index 00000000000..9e6cd68d401
--- /dev/null
+++ b/lib/preview/unknown.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+class Unknown extends Provider {
+
+ public function getMimeType() {
+ return '/.*/';
+ }
+
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+ $mimetype = $fileview->getMimeType($path);
+
+ $path = \OC_Helper::mimetypeIcon($mimetype);
+ $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT));
+
+ return new \OC_Image($path);
+ }
+}
+
+\OC\Preview::registerProvider('OC\Preview\Unknown'); \ No newline at end of file
diff --git a/lib/public/preview.php b/lib/public/preview.php
new file mode 100644
index 00000000000..7588347eccb
--- /dev/null
+++ b/lib/public/preview.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org
+ * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OCP;
+
+/**
+ * This class provides functions to render and show thumbnails and previews of files
+ */
+class Preview {
+
+ /**
+ * @brief return a preview of a file
+ * @param $file The path to the file where you want a thumbnail from
+ * @param $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
+ * @param $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
+ * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly
+ * @return image
+ */
+ public static function show($file,$maxX=100,$maxY=75,$scaleup=false) {
+ return(\OC\Preview::show($file,$maxX,$maxY,$scaleup));
+ }
+
+
+
+ public static function isMimeSupported($mimetype='*') {
+ return \OC\Preview::isMimeSupported($mimetype);
+ }
+
+}
diff --git a/lib/public/share.php b/lib/public/share.php
index b38208bc67f..9ab956d84b9 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -140,8 +140,13 @@ class Share {
$source = -1;
$cache = false;
- $view = new \OC\Files\View('/' . $user . '/files/');
- $meta = $view->getFileInfo(\OC\Files\Filesystem::normalizePath($path));
+ $view = new \OC\Files\View('/' . $user . '/files');
+ if ($view->file_exists($path)) {
+ $meta = $view->getFileInfo($path);
+ } else {
+ // if the file doesn't exists yet we start with the parent folder
+ $meta = $view->getFileInfo(dirname($path));
+ }
if($meta !== false) {
$source = $meta['fileid'];
@@ -463,7 +468,7 @@ class Share {
if (isset($oldToken)) {
$token = $oldToken;
} else {
- $token = \OC_Util::generate_random_bytes(self::TOKEN_LENGTH);
+ $token = \OC_Util::generateRandomBytes(self::TOKEN_LENGTH);
}
$result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions,
null, $token);
diff --git a/lib/public/template.php b/lib/public/template.php
index ab1089c332d..3b1a4ed4906 100644
--- a/lib/public/template.php
+++ b/lib/public/template.php
@@ -54,6 +54,25 @@ function mimetype_icon( $mimetype ) {
return(\mimetype_icon( $mimetype ));
}
+/**
+ * @brief make preview_icon available as a simple function
+ * Returns the path to the preview of the image.
+ * @param $path path of file
+ * @returns link to the preview
+ */
+function preview_icon( $path ) {
+ return(\preview_icon( $path ));
+}
+
+/**
+ * @brief make publicpreview_icon available as a simple function
+ * Returns the path to the preview of the image.
+ * @param $path path of file
+ * @returns link to the preview
+ */
+function publicPreview_icon ( $path, $token ) {
+ return(\publicPreview_icon( $path, $token ));
+}
/**
* @brief make OC_Helper::humanFileSize available as a simple function
diff --git a/lib/setup.php b/lib/setup.php
index 05a49890976..6bf3c88370f 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -61,7 +61,7 @@ class OC_Setup {
}
//generate a random salt that is used to salt the local user passwords
- $salt = OC_Util::generate_random_bytes(30);
+ $salt = OC_Util::generateRandomBytes(30);
OC_Config::setValue('passwordsalt', $salt);
//write the config file
diff --git a/lib/setup/mysql.php b/lib/setup/mysql.php
index 0cf04fde5a1..d97b6d2602f 100644
--- a/lib/setup/mysql.php
+++ b/lib/setup/mysql.php
@@ -23,7 +23,7 @@ class MySQL extends AbstractDatabase {
$this->dbuser=substr('oc_'.$username, 0, 16);
if($this->dbuser!=$oldUser) {
//hash the password so we don't need to store the admin config in the config file
- $this->dbpassword=\OC_Util::generate_random_bytes(30);
+ $this->dbpassword=\OC_Util::generateRandomBytes(30);
$this->createDBUser($connection);
diff --git a/lib/setup/oci.php b/lib/setup/oci.php
index 86b53de45a4..326d7a00531 100644
--- a/lib/setup/oci.php
+++ b/lib/setup/oci.php
@@ -65,7 +65,7 @@ class OCI extends AbstractDatabase {
//add prefix to the oracle user name to prevent collisions
$this->dbuser='oc_'.$username;
//create a new password so we don't need to store the admin config in the config file
- $this->dbpassword=\OC_Util::generate_random_bytes(30);
+ $this->dbpassword=\OC_Util::generateRandomBytes(30);
//oracle passwords are treated as identifiers:
// must start with aphanumeric char
diff --git a/lib/setup/postgresql.php b/lib/setup/postgresql.php
index 49fcbf0326e..89d328ada19 100644
--- a/lib/setup/postgresql.php
+++ b/lib/setup/postgresql.php
@@ -33,7 +33,7 @@ class PostgreSQL extends AbstractDatabase {
//add prefix to the postgresql user name to prevent collisions
$this->dbuser='oc_'.$username;
//create a new password so we don't need to store the admin config in the config file
- $this->dbpassword=\OC_Util::generate_random_bytes(30);
+ $this->dbpassword=\OC_Util::generateRandomBytes(30);
$this->createDBUser($connection);
diff --git a/lib/template/functions.php b/lib/template/functions.php
index 717e197c1cb..501f8081bff 100644
--- a/lib/template/functions.php
+++ b/lib/template/functions.php
@@ -59,6 +59,22 @@ function mimetype_icon( $mimetype ) {
}
/**
+ * @brief make preview_icon available as a simple function
+ * Returns the path to the preview of the image.
+ * @param $path path of file
+ * @returns link to the preview
+ *
+ * For further information have a look at OC_Helper::previewIcon
+ */
+function preview_icon( $path ) {
+ return OC_Helper::previewIcon( $path );
+}
+
+function publicPreview_icon ( $path, $token ) {
+ return OC_Helper::publicPreviewIcon( $path, $token );
+}
+
+/**
* @brief make OC_Helper::humanFileSize available as a simple function
* @param int $bytes size in bytes
* @return string size as string
diff --git a/lib/templatelayout.php b/lib/templatelayout.php
index 0024c9d4960..0b868a39e49 100644
--- a/lib/templatelayout.php
+++ b/lib/templatelayout.php
@@ -58,7 +58,7 @@ class OC_TemplateLayout extends OC_Template {
if (OC_Config::getValue('installed', false) && $renderas!='error') {
$this->append( 'jsfiles', OC_Helper::linkToRoute('js_config') . $versionParameter);
}
- if (!empty(OC_Util::$core_scripts)) {
+ if (!empty(OC_Util::$coreScripts)) {
$this->append( 'jsfiles', OC_Helper::linkToRemoteBase('core.js', false) . $versionParameter);
}
foreach($jsfiles as $info) {
@@ -71,7 +71,7 @@ class OC_TemplateLayout extends OC_Template {
// Add the css files
$cssfiles = self::findStylesheetFiles(OC_Util::$styles);
$this->assign('cssfiles', array());
- if (!empty(OC_Util::$core_styles)) {
+ if (!empty(OC_Util::$coreStyles)) {
$this->append( 'cssfiles', OC_Helper::linkToRemoteBase('core.css', false) . $versionParameter);
}
foreach($cssfiles as $info) {
diff --git a/lib/user.php b/lib/user.php
index 93c7c9d4cd5..0f6f40aec9a 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -353,7 +353,7 @@ class OC_User {
* generates a password
*/
public static function generatePassword() {
- return OC_Util::generate_random_bytes(30);
+ return OC_Util::generateRandomBytes(30);
}
/**
diff --git a/lib/util.php b/lib/util.php
index e03667b0794..41f5f1d16be 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -11,12 +11,18 @@ class OC_Util {
public static $headers=array();
private static $rootMounted=false;
private static $fsSetup=false;
- public static $core_styles=array();
- public static $core_scripts=array();
+ public static $coreStyles=array();
+ public static $coreScripts=array();
- // Can be set up
- public static function setupFS( $user = '' ) {// configure the initial filesystem based on the configuration
- if(self::$fsSetup) {//setting up the filesystem twice can only lead to trouble
+ /**
+ * @brief Can be set up
+ * @param string $user
+ * @return boolean
+ * @description configure the initial filesystem based on the configuration
+ */
+ public static function setupFS( $user = '' ) {
+ //setting up the filesystem twice can only lead to trouble
+ if(self::$fsSetup) {
return false;
}
@@ -37,15 +43,16 @@ class OC_Util {
self::$fsSetup=true;
}
- $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
+ $configDataDirectory = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
//first set up the local "root" storage
\OC\Files\Filesystem::initMounts();
if(!self::$rootMounted) {
- \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir'=>$CONFIG_DATADIRECTORY), '/');
- self::$rootMounted=true;
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir'=>$configDataDirectory), '/');
+ self::$rootMounted = true;
}
- if( $user != "" ) { //if we aren't logged in, there is no use to set up the filesystem
+ //if we aren't logged in, there is no use to set up the filesystem
+ if( $user != "" ) {
$quota = self::getUserQuota($user);
if ($quota !== \OC\Files\SPACE_UNLIMITED) {
\OC\Files\Filesystem::addStorageWrapper(function($mountPoint, $storage) use ($quota, $user) {
@@ -56,19 +63,19 @@ class OC_Util {
}
});
}
- $user_dir = '/'.$user.'/files';
- $user_root = OC_User::getHome($user);
- $userdirectory = $user_root . '/files';
- if( !is_dir( $userdirectory )) {
- mkdir( $userdirectory, 0755, true );
+ $userDir = '/'.$user.'/files';
+ $userRoot = OC_User::getHome($user);
+ $userDirectory = $userRoot . '/files';
+ if( !is_dir( $userDirectory )) {
+ mkdir( $userDirectory, 0755, true );
}
//jail the user into his "home" directory
- \OC\Files\Filesystem::init($user, $user_dir);
+ \OC\Files\Filesystem::init($user, $userDir);
$fileOperationProxy = new OC_FileProxy_FileOperations();
OC_FileProxy::register($fileOperationProxy);
- OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
+ OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
}
return true;
}
@@ -85,24 +92,27 @@ class OC_Util {
}
}
+ /**
+ * @return void
+ */
public static function tearDownFS() {
\OC\Files\Filesystem::tearDown();
self::$fsSetup=false;
- self::$rootMounted=false;
+ self::$rootMounted=false;
}
/**
- * get the current installed version of ownCloud
+ * @brief get the current installed version of ownCloud
* @return array
*/
public static function getVersion() {
// hint: We only can count up. Reset minor/patchlevel when
// updating major/minor version number.
- return array(5, 80, 05);
+ return array(5, 80, 07);
}
/**
- * get the current installed version string of ownCloud
+ * @brief get the current installed version string of ownCloud
* @return string
*/
public static function getVersionString() {
@@ -110,7 +120,7 @@ class OC_Util {
}
/**
- * get the current installed edition of ownCloud. There is the community
+ * @description get the current installed edition of ownCloud. There is the community
* edition that just returns an empty string and the enterprise edition
* that returns "Enterprise".
* @return string
@@ -120,103 +130,117 @@ class OC_Util {
}
/**
- * add a javascript file
+ * @brief add a javascript file
*
- * @param appid $application
- * @param filename $file
+ * @param string $application
+ * @param filename $file
+ * @return void
*/
public static function addScript( $application, $file = null ) {
- if( is_null( $file )) {
+ if ( is_null( $file )) {
$file = $application;
$application = "";
}
- if( !empty( $application )) {
+ if ( !empty( $application )) {
self::$scripts[] = "$application/js/$file";
- }else{
+ } else {
self::$scripts[] = "js/$file";
}
}
/**
- * add a css file
+ * @brief add a css file
*
- * @param appid $application
- * @param filename $file
+ * @param string $application
+ * @param filename $file
+ * @return void
*/
public static function addStyle( $application, $file = null ) {
- if( is_null( $file )) {
+ if ( is_null( $file )) {
$file = $application;
$application = "";
}
- if( !empty( $application )) {
+ if ( !empty( $application )) {
self::$styles[] = "$application/css/$file";
- }else{
+ } else {
self::$styles[] = "css/$file";
}
}
/**
* @brief Add a custom element to the header
- * @param string tag tag name of the element
+ * @param string $tag tag name of the element
* @param array $attributes array of attributes for the element
* @param string $text the text content for the element
+ * @return void
*/
public static function addHeader( $tag, $attributes, $text='') {
- self::$headers[] = array('tag'=>$tag, 'attributes'=>$attributes, 'text'=>$text);
+ self::$headers[] = array(
+ 'tag'=>$tag,
+ 'attributes'=>$attributes,
+ 'text'=>$text
+ );
}
/**
- * formats a timestamp in the "right" way
+ * @brief formats a timestamp in the "right" way
*
- * @param int timestamp $timestamp
- * @param bool dateOnly option to omit time from the result
+ * @param int $timestamp
+ * @param bool $dateOnly option to omit time from the result
+ * @return string timestamp
+ * @description adjust to clients timezone if we know it
*/
public static function formatDate( $timestamp, $dateOnly=false) {
- if(\OC::$session->exists('timezone')) {//adjust to clients timezone if we know it
+ if(\OC::$session->exists('timezone')) {
$systemTimeZone = intval(date('O'));
- $systemTimeZone=(round($systemTimeZone/100, 0)*60)+($systemTimeZone%100);
- $clientTimeZone=\OC::$session->get('timezone')*60;
- $offset=$clientTimeZone-$systemTimeZone;
- $timestamp=$timestamp+$offset*60;
+ $systemTimeZone = (round($systemTimeZone/100, 0)*60) + ($systemTimeZone%100);
+ $clientTimeZone = \OC::$session->get('timezone')*60;
+ $offset = $clientTimeZone - $systemTimeZone;
+ $timestamp = $timestamp + $offset*60;
}
- $l=OC_L10N::get('lib');
+ $l = OC_L10N::get('lib');
return $l->l($dateOnly ? 'date' : 'datetime', $timestamp);
}
/**
- * check if the current server configuration is suitable for ownCloud
+ * @brief check if the current server configuration is suitable for ownCloud
* @return array arrays with error messages and hints
*/
public static function checkServer() {
// Assume that if checkServer() succeeded before in this session, then all is fine.
- if(\OC::$session->exists('checkServer_suceeded') && \OC::$session->get('checkServer_suceeded'))
+ if(\OC::$session->exists('checkServer_suceeded') && \OC::$session->get('checkServer_suceeded')) {
return array();
+ }
- $errors=array();
+ $errors = array();
$defaults = new \OC_Defaults();
- $web_server_restart= false;
+ $webServerRestart = false;
//check for database drivers
if(!(is_callable('sqlite_open') or class_exists('SQLite3'))
and !is_callable('mysql_connect')
and !is_callable('pg_connect')
and !is_callable('oci_connect')) {
- $errors[]=array('error'=>'No database drivers (sqlite, mysql, or postgresql) installed.',
- 'hint'=>'');//TODO: sane hint
- $web_server_restart= true;
+ $errors[] = array(
+ 'error'=>'No database drivers (sqlite, mysql, or postgresql) installed.',
+ 'hint'=>'' //TODO: sane hint
+ );
+ $webServerRestart = true;
}
- //common hint for all file permissons error messages
+ //common hint for all file permissions error messages
$permissionsHint = 'Permissions can usually be fixed by '
- .'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the root directory</a>.';
+ .'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html'
+ .'#set-the-directory-permissions" target="_blank">giving the webserver write access to the root directory</a>.';
// Check if config folder is writable.
if(!is_writable(OC::$SERVERROOT."/config/") or !is_readable(OC::$SERVERROOT."/config/")) {
$errors[] = array(
'error' => "Can't write into config directory",
'hint' => 'This can usually be fixed by '
- .'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the config directory</a>.'
+ .'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html'
+ .'#set-the-directory-permissions" target="_blank">giving the webserver write access to the config directory</a>.'
);
}
@@ -228,7 +252,8 @@ class OC_Util {
$errors[] = array(
'error' => "Can't write into apps directory",
'hint' => 'This can usually be fixed by '
- .'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the apps directory</a> '
+ .'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html'
+ .'#set-the-directory-permissions" target="_blank">giving the webserver write access to the apps directory</a> '
.'or disabling the appstore in the config file.'
);
}
@@ -243,94 +268,131 @@ class OC_Util {
$errors[] = array(
'error' => "Can't create data directory (".$CONFIG_DATADIRECTORY.")",
'hint' => 'This can usually be fixed by '
- .'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the root directory</a>.'
+ .'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html'
+ .'#set-the-directory-permissions" target="_blank">giving the webserver write access to the root directory</a>.'
);
}
} else if(!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
- $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') not writable by ownCloud',
- 'hint'=>$permissionsHint);
+ $errors[] = array(
+ 'error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') not writable by ownCloud',
+ 'hint'=>$permissionsHint
+ );
} else {
$errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
}
+
+ $moduleHint = "Please ask your server administrator to install the module.";
// check if all required php modules are present
if(!class_exists('ZipArchive')) {
- $errors[]=array('error'=>'PHP module zip not installed.',
- 'hint'=>'Please ask your server administrator to install the module.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP module zip not installed.',
+ 'hint'=>$moduleHint
+ );
+ $webServerRestart = true;
}
if(!class_exists('DOMDocument')) {
- $errors[] = array('error' => 'PHP module dom not installed.',
- 'hint' => 'Please ask your server administrator to install the module.');
- $web_server_restart =true;
+ $errors[] = array(
+ 'error' => 'PHP module dom not installed.',
+ 'hint' => $moduleHint
+ );
+ $webServerRestart =true;
}
if(!function_exists('xml_parser_create')) {
- $errors[] = array('error' => 'PHP module libxml not installed.',
- 'hint' => 'Please ask your server administrator to install the module.');
- $web_server_restart =true;
+ $errors[] = array(
+ 'error' => 'PHP module libxml not installed.',
+ 'hint' => $moduleHint
+ );
+ $webServerRestart = true;
}
if(!function_exists('mb_detect_encoding')) {
- $errors[]=array('error'=>'PHP module mb multibyte not installed.',
- 'hint'=>'Please ask your server administrator to install the module.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP module mb multibyte not installed.',
+ 'hint'=>$moduleHint
+ );
+ $webServerRestart = true;
}
if(!function_exists('ctype_digit')) {
- $errors[]=array('error'=>'PHP module ctype is not installed.',
- 'hint'=>'Please ask your server administrator to install the module.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP module ctype is not installed.',
+ 'hint'=>$moduleHint
+ );
+ $webServerRestart = true;
}
if(!function_exists('json_encode')) {
- $errors[]=array('error'=>'PHP module JSON is not installed.',
- 'hint'=>'Please ask your server administrator to install the module.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP module JSON is not installed.',
+ 'hint'=>$moduleHint
+ );
+ $webServerRestart = true;
}
if(!extension_loaded('gd') || !function_exists('gd_info')) {
- $errors[]=array('error'=>'PHP module GD is not installed.',
- 'hint'=>'Please ask your server administrator to install the module.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP module GD is not installed.',
+ 'hint'=>$moduleHint
+ );
+ $webServerRestart = true;
}
if(!function_exists('gzencode')) {
- $errors[]=array('error'=>'PHP module zlib is not installed.',
- 'hint'=>'Please ask your server administrator to install the module.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP module zlib is not installed.',
+ 'hint'=>$moduleHint
+ );
+ $webServerRestart = true;
}
if(!function_exists('iconv')) {
- $errors[]=array('error'=>'PHP module iconv is not installed.',
- 'hint'=>'Please ask your server administrator to install the module.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP module iconv is not installed.',
+ 'hint'=>$moduleHint
+ );
+ $webServerRestart = true;
}
if(!function_exists('simplexml_load_string')) {
- $errors[]=array('error'=>'PHP module SimpleXML is not installed.',
- 'hint'=>'Please ask your server administrator to install the module.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP module SimpleXML is not installed.',
+ 'hint'=>$moduleHint
+ );
+ $webServerRestart = true;
}
- if(floatval(phpversion())<5.3) {
- $errors[]=array('error'=>'PHP 5.3 is required.',
+ if(floatval(phpversion()) < 5.3) {
+ $errors[] = array(
+ 'error'=>'PHP 5.3 is required.',
'hint'=>'Please ask your server administrator to update PHP to version 5.3 or higher.'
- .' PHP 5.2 is no longer supported by ownCloud and the PHP community.');
- $web_server_restart=true;
+ .' PHP 5.2 is no longer supported by ownCloud and the PHP community.'
+ );
+ $webServerRestart = true;
}
if(!defined('PDO::ATTR_DRIVER_NAME')) {
- $errors[]=array('error'=>'PHP PDO module is not installed.',
- 'hint'=>'Please ask your server administrator to install the module.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP PDO module is not installed.',
+ 'hint'=>$moduleHint
+ );
+ $webServerRestart = true;
}
if (((strtolower(@ini_get('safe_mode')) == 'on')
|| (strtolower(@ini_get('safe_mode')) == 'yes')
|| (strtolower(@ini_get('safe_mode')) == 'true')
|| (ini_get("safe_mode") == 1 ))) {
- $errors[]=array('error'=>'PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.',
- 'hint'=>'PHP Safe Mode is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.',
+ 'hint'=>'PHP Safe Mode is a deprecated and mostly useless setting that should be disabled. '
+ .'Please ask your server administrator to disable it in php.ini or in your webserver config.'
+ );
+ $webServerRestart = true;
}
if (get_magic_quotes_gpc() == 1 ) {
- $errors[]=array('error'=>'Magic Quotes is enabled. ownCloud requires that it is disabled to work properly.',
- 'hint'=>'Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
- $web_server_restart=true;
+ $errors[] = array(
+ 'error'=>'Magic Quotes is enabled. ownCloud requires that it is disabled to work properly.',
+ 'hint'=>'Magic Quotes is a deprecated and mostly useless setting that should be disabled. '
+ .'Please ask your server administrator to disable it in php.ini or in your webserver config.'
+ );
+ $webServerRestart = true;
}
- if($web_server_restart) {
- $errors[]=array('error'=>'PHP modules have been installed, but they are still listed as missing?',
- 'hint'=>'Please ask your server administrator to restart the web server.');
+ if($webServerRestart) {
+ $errors[] = array(
+ 'error'=>'PHP modules have been installed, but they are still listed as missing?',
+ 'hint'=>'Please ask your server administrator to restart the web server.'
+ );
}
// Cache the result of this function
@@ -357,30 +419,36 @@ class OC_Util {
}
/**
- * Check for correct file permissions of data directory
- * @return array arrays with error messages and hints
- */
+ * @brief Check for correct file permissions of data directory
+ * @paran string $dataDirectory
+ * @return array arrays with error messages and hints
+ */
public static function checkDataDirectoryPermissions($dataDirectory) {
$errors = array();
- if (stristr(PHP_OS, 'WIN')) {
+ if (self::runningOnWindows()) {
//TODO: permissions checks for windows hosts
} else {
$permissionsModHint = 'Please change the permissions to 0770 so that the directory'
.' cannot be listed by other users.';
- $prems = substr(decoct(@fileperms($dataDirectory)), -3);
- if (substr($prems, -1) != '0') {
+ $perms = substr(decoct(@fileperms($dataDirectory)), -3);
+ if (substr($perms, -1) != '0') {
OC_Helper::chmodr($dataDirectory, 0770);
clearstatcache();
- $prems = substr(decoct(@fileperms($dataDirectory)), -3);
- if (substr($prems, 2, 1) != '0') {
- $errors[] = array('error' => 'Data directory ('.$dataDirectory.') is readable for other users',
- 'hint' => $permissionsModHint);
+ $perms = substr(decoct(@fileperms($dataDirectory)), -3);
+ if (substr($perms, 2, 1) != '0') {
+ $errors[] = array(
+ 'error' => 'Data directory ('.$dataDirectory.') is readable for other users',
+ 'hint' => $permissionsModHint
+ );
}
}
}
return $errors;
}
+ /**
+ * @return void
+ */
public static function displayLoginPage($errors = array()) {
$parameters = array();
foreach( $errors as $key => $value ) {
@@ -394,8 +462,8 @@ class OC_Util {
$parameters['user_autofocus'] = true;
}
if (isset($_REQUEST['redirect_url'])) {
- $redirect_url = $_REQUEST['redirect_url'];
- $parameters['redirect_url'] = urlencode($redirect_url);
+ $redirectUrl = $_REQUEST['redirect_url'];
+ $parameters['redirect_url'] = urlencode($redirectUrl);
}
$parameters['alt_login'] = OC_App::getAlternativeLogIns();
@@ -404,7 +472,8 @@ class OC_Util {
/**
- * Check if the app is enabled, redirects to home if not
+ * @brief Check if the app is enabled, redirects to home if not
+ * @return void
*/
public static function checkAppEnabled($app) {
if( !OC_App::isEnabled($app)) {
@@ -416,18 +485,21 @@ class OC_Util {
/**
* Check if the user is logged in, redirects to home if not. With
* redirect URL parameter to the request URI.
+ * @return void
*/
public static function checkLoggedIn() {
// Check if we are a user
if( !OC_User::isLoggedIn()) {
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php',
- array('redirect_url' => OC_Request::requestUri())));
+ array('redirectUrl' => OC_Request::requestUri())
+ ));
exit();
}
}
/**
- * Check if the user is a admin, redirects to home if not
+ * @brief Check if the user is a admin, redirects to home if not
+ * @return void
*/
public static function checkAdminUser() {
if( !OC_User::isAdminUser(OC_User::getUser())) {
@@ -437,7 +509,7 @@ class OC_Util {
}
/**
- * Check if the user is a subadmin, redirects to home if not
+ * @brief Check if the user is a subadmin, redirects to home if not
* @return array $groups where the current user is subadmin
*/
public static function checkSubAdminUser() {
@@ -449,7 +521,8 @@ class OC_Util {
}
/**
- * Redirect to the user default page
+ * @brief Redirect to the user default page
+ * @return void
*/
public static function redirectToDefaultPage() {
if(isset($_REQUEST['redirect_url'])) {
@@ -457,13 +530,11 @@ class OC_Util {
}
else if (isset(OC::$REQUESTEDAPP) && !empty(OC::$REQUESTEDAPP)) {
$location = OC_Helper::linkToAbsolute( OC::$REQUESTEDAPP, 'index.php' );
- }
- else {
- $defaultpage = OC_Appconfig::getValue('core', 'defaultpage');
- if ($defaultpage) {
- $location = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/'.$defaultpage);
- }
- else {
+ } else {
+ $defaultPage = OC_Appconfig::getValue('core', 'defaultpage');
+ if ($defaultPage) {
+ $location = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/'.$defaultPage);
+ } else {
$location = OC_Helper::linkToAbsolute( 'files', 'index.php' );
}
}
@@ -472,28 +543,28 @@ class OC_Util {
exit();
}
- /**
- * get an id unique for this instance
- * @return string
- */
- public static function getInstanceId() {
- $id = OC_Config::getValue('instanceid', null);
- if(is_null($id)) {
- // We need to guarantee at least one letter in instanceid so it can be used as the session_name
- $id = 'oc' . OC_Util::generate_random_bytes(10);
- OC_Config::setValue('instanceid', $id);
- }
- return $id;
- }
+ /**
+ * @brief get an id unique for this instance
+ * @return string
+ */
+ public static function getInstanceId() {
+ $id = OC_Config::getValue('instanceid', null);
+ if(is_null($id)) {
+ // We need to guarantee at least one letter in instanceid so it can be used as the session_name
+ $id = 'oc' . self::generateRandomBytes(10);
+ OC_Config::setValue('instanceid', $id);
+ }
+ return $id;
+ }
/**
* @brief Static lifespan (in seconds) when a request token expires.
* @see OC_Util::callRegister()
* @see OC_Util::isCallRegistered()
* @description
- * Also required for the client side to compute the piont in time when to
+ * Also required for the client side to compute the point in time when to
* request a fresh token. The client will do so when nearly 97% of the
- * timespan coded here has expired.
+ * time span coded here has expired.
*/
public static $callLifespan = 3600; // 3600 secs = 1 hour
@@ -513,7 +584,7 @@ class OC_Util {
// Check if a token exists
if(!\OC::$session->exists('requesttoken')) {
// No valid token found, generate a new one.
- $requestToken = self::generate_random_bytes(20);
+ $requestToken = self::generateRandomBytes(20);
\OC::$session->set('requesttoken', $requestToken);
} else {
// Valid token already exists, send it
@@ -534,11 +605,11 @@ class OC_Util {
}
if(isset($_GET['requesttoken'])) {
- $token=$_GET['requesttoken'];
+ $token = $_GET['requesttoken'];
} elseif(isset($_POST['requesttoken'])) {
- $token=$_POST['requesttoken'];
+ $token = $_POST['requesttoken'];
} elseif(isset($_SERVER['HTTP_REQUESTTOKEN'])) {
- $token=$_SERVER['HTTP_REQUESTTOKEN'];
+ $token = $_SERVER['HTTP_REQUESTTOKEN'];
} else {
//no token found.
return false;
@@ -556,11 +627,12 @@ class OC_Util {
/**
* @brief Check an ajax get/post call if the request token is valid. exit if not.
- * Todo: Write howto
+ * @todo Write howto
+ * @return void
*/
public static function callCheck() {
if(!OC_Util::isCallRegistered()) {
- exit;
+ exit();
}
}
@@ -570,14 +642,15 @@ class OC_Util {
* This function is used to sanitize HTML and should be applied on any
* string or array of strings before displaying it on a web page.
*
- * @param string or array of strings
+ * @param string|array of strings
* @return array with sanitized strings or a single sanitized string, depends on the input parameter.
*/
public static function sanitizeHTML( &$value ) {
if (is_array($value)) {
array_walk_recursive($value, 'OC_Util::sanitizeHTML');
} else {
- $value = htmlentities((string)$value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4
+ //Specify encoding for PHP<5.4
+ $value = htmlentities((string)$value, ENT_QUOTES, 'UTF-8');
}
return $value;
}
@@ -599,48 +672,52 @@ class OC_Util {
}
/**
- * Check if the htaccess file is working by creating a test file in the data directory and trying to access via http
+ * @brief Check if the htaccess file is working
+ * @return bool
+ * @description Check if the htaccess file is working by creating a test
+ * file in the data directory and trying to access via http
*/
- public static function ishtaccessworking() {
+ public static function isHtAccessWorking() {
// testdata
- $filename='/htaccesstest.txt';
- $testcontent='testcontent';
+ $fileName = '/htaccesstest.txt';
+ $testContent = 'testcontent';
// creating a test file
- $testfile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$filename;
+ $testFile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$fileName;
- if(file_exists($testfile)) {// already running this test, possible recursive call
+ if(file_exists($testFile)) {// already running this test, possible recursive call
return false;
}
- $fp = @fopen($testfile, 'w');
- @fwrite($fp, $testcontent);
+ $fp = @fopen($testFile, 'w');
+ @fwrite($fp, $testContent);
@fclose($fp);
// accessing the file via http
- $url = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/data'.$filename);
+ $url = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/data'.$fileName);
$fp = @fopen($url, 'r');
$content=@fread($fp, 2048);
@fclose($fp);
// cleanup
- @unlink($testfile);
+ @unlink($testFile);
// does it work ?
- if($content==$testcontent) {
- return(false);
- }else{
- return(true);
+ if($content==$testContent) {
+ return false;
+ } else {
+ return true;
}
}
/**
- * we test if webDAV is working properly
- *
+ * @brief test if webDAV is working properly
+ * @return bool
+ * @description
* The basic assumption is that if the server returns 401/Not Authenticated for an unauthenticated PROPFIND
* the web server it self is setup properly.
*
- * Why not an authenticated PROFIND and other verbs?
+ * Why not an authenticated PROPFIND and other verbs?
* - We don't have the password available
* - We have no idea about other auth methods implemented (e.g. OAuth with Bearer header)
*
@@ -654,7 +731,7 @@ class OC_Util {
);
// save the old timeout so that we can restore it later
- $old_timeout=ini_get("default_socket_timeout");
+ $oldTimeout = ini_get("default_socket_timeout");
// use a 5 sec timeout for the check. Should be enough for local requests.
ini_set("default_socket_timeout", 5);
@@ -668,24 +745,25 @@ class OC_Util {
try {
// test PROPFIND
$client->propfind('', array('{DAV:}resourcetype'));
- } catch(\Sabre_DAV_Exception_NotAuthenticated $e) {
+ } catch (\Sabre_DAV_Exception_NotAuthenticated $e) {
$return = true;
- } catch(\Exception $e) {
+ } catch (\Exception $e) {
OC_Log::write('core', 'isWebDAVWorking: NO - Reason: '.$e->getMessage(). ' ('.get_class($e).')', OC_Log::WARN);
$return = false;
}
// restore the original timeout
- ini_set("default_socket_timeout", $old_timeout);
+ ini_set("default_socket_timeout", $oldTimeout);
return $return;
}
/**
- * Check if the setlocal call doesn't work. This can happen if the right
+ * Check if the setlocal call does not work. This can happen if the right
* local packages are not available on the server.
+ * @return bool
*/
- public static function issetlocaleworking() {
+ public static function isSetLocaleWorking() {
// setlocale test is pointless on Windows
if (OC_Util::runningOnWindows() ) {
return true;
@@ -699,7 +777,7 @@ class OC_Util {
}
/**
- * Check if the PHP module fileinfo is loaded.
+ * @brief Check if the PHP module fileinfo is loaded.
* @return bool
*/
public static function fileInfoLoaded() {
@@ -707,7 +785,8 @@ class OC_Util {
}
/**
- * Check if the ownCloud server can connect to the internet
+ * @brief Check if the ownCloud server can connect to the internet
+ * @return bool
*/
public static function isInternetConnectionWorking() {
// in case there is no internet connection on purpose return false
@@ -720,30 +799,29 @@ class OC_Util {
if ($connected) {
fclose($connected);
return true;
- }else{
-
+ } else {
// second try in case one server is down
$connected = @fsockopen("apps.owncloud.com", 80);
if ($connected) {
fclose($connected);
return true;
- }else{
+ } else {
return false;
}
-
}
-
}
/**
- * Check if the connection to the internet is disabled on purpose
+ * @brief Check if the connection to the internet is disabled on purpose
+ * @return bool
*/
public static function isInternetConnectionEnabled(){
return \OC_Config::getValue("has_internet_connection", true);
}
/**
- * clear all levels of output buffering
+ * @brief clear all levels of output buffering
+ * @return void
*/
public static function obEnd(){
while (ob_get_level()) {
@@ -753,47 +831,47 @@ class OC_Util {
/**
- * @brief Generates a cryptographical secure pseudorandom string
- * @param Int with the length of the random string
+ * @brief Generates a cryptographic secure pseudo-random string
+ * @param Int $length of the random string
* @return String
- * Please also update secureRNG_available if you change something here
+ * Please also update secureRNGAvailable if you change something here
*/
- public static function generate_random_bytes($length = 30) {
-
+ public static function generateRandomBytes($length = 30) {
// Try to use openssl_random_pseudo_bytes
- if(function_exists('openssl_random_pseudo_bytes')) {
- $pseudo_byte = bin2hex(openssl_random_pseudo_bytes($length, $strong));
+ if (function_exists('openssl_random_pseudo_bytes')) {
+ $pseudoByte = bin2hex(openssl_random_pseudo_bytes($length, $strong));
if($strong == true) {
- return substr($pseudo_byte, 0, $length); // Truncate it to match the length
+ return substr($pseudoByte, 0, $length); // Truncate it to match the length
}
}
// Try to use /dev/urandom
- $fp = @file_get_contents('/dev/urandom', false, null, 0, $length);
- if ($fp !== false) {
- $string = substr(bin2hex($fp), 0, $length);
- return $string;
+ if (!self::runningOnWindows()) {
+ $fp = @file_get_contents('/dev/urandom', false, null, 0, $length);
+ if ($fp !== false) {
+ $string = substr(bin2hex($fp), 0, $length);
+ return $string;
+ }
}
// Fallback to mt_rand()
$characters = '0123456789';
$characters .= 'abcdefghijklmnopqrstuvwxyz';
$charactersLength = strlen($characters)-1;
- $pseudo_byte = "";
+ $pseudoByte = "";
// Select some random characters
for ($i = 0; $i < $length; $i++) {
- $pseudo_byte .= $characters[mt_rand(0, $charactersLength)];
+ $pseudoByte .= $characters[mt_rand(0, $charactersLength)];
}
- return $pseudo_byte;
+ return $pseudoByte;
}
/**
* @brief Checks if a secure random number generator is available
* @return bool
*/
- public static function secureRNG_available() {
-
+ public static function secureRNGAvailable() {
// Check openssl_random_pseudo_bytes
if(function_exists('openssl_random_pseudo_bytes')) {
openssl_random_pseudo_bytes(1, $strong);
@@ -803,9 +881,11 @@ class OC_Util {
}
// Check /dev/urandom
- $fp = @file_get_contents('/dev/urandom', false, null, 0, 1);
- if ($fp !== false) {
- return true;
+ if (!self::runningOnWindows()) {
+ $fp = @file_get_contents('/dev/urandom', false, null, 0, 1);
+ if ($fp !== false) {
+ return true;
+ }
}
return false;
@@ -818,11 +898,8 @@ class OC_Util {
* 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')) {
-
+ if (function_exists('curl_init')) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADER, 0);
@@ -833,10 +910,10 @@ class OC_Util {
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler");
- if(OC_Config::getValue('proxy', '')<>'') {
+ if(OC_Config::getValue('proxy', '') != '') {
curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy'));
}
- if(OC_Config::getValue('proxyuserpwd', '')<>'') {
+ if(OC_Config::getValue('proxyuserpwd', '') != '') {
curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd'));
}
$data = curl_exec($curl);
@@ -845,7 +922,7 @@ class OC_Util {
} else {
$contextArray = null;
- if(OC_Config::getValue('proxy', '')<>'') {
+ if(OC_Config::getValue('proxy', '') != '') {
$contextArray = array(
'http' => array(
'timeout' => 10,
@@ -860,11 +937,10 @@ class OC_Util {
);
}
-
$ctx = stream_context_create(
$contextArray
);
- $data=@file_get_contents($url, 0, $ctx);
+ $data = @file_get_contents($url, 0, $ctx);
}
return $data;
@@ -877,7 +953,6 @@ class OC_Util {
return (substr(PHP_OS, 0, 3) === "WIN");
}
-
/**
* Handles the case that there may not be a theme, then check if a "default"
* theme exists and take that one
@@ -887,20 +962,19 @@ class OC_Util {
$theme = OC_Config::getValue("theme", '');
if($theme === '') {
-
if(is_dir(OC::$SERVERROOT . '/themes/default')) {
$theme = 'default';
}
-
}
return $theme;
}
/**
- * Clear the opcode cache if one exists
+ * @brief Clear the opcode cache if one exists
* This is necessary for writing to the config file
- * in case the opcode cache doesn't revalidate files
+ * in case the opcode cache does not re-validate files
+ * @return void
*/
public static function clearOpcodeCache() {
// APC
@@ -939,8 +1013,10 @@ class OC_Util {
return $value;
}
- public static function basename($file)
- {
+ /**
+ * @return string
+ */
+ public static function basename($file) {
$file = rtrim($file, '/');
$t = explode('/', $file);
return array_pop($t);