diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-11-22 17:14:15 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-11-22 17:14:15 +0100 |
commit | 26e9e68a39da4e22ec438296304dfa7bfd41ec0f (patch) | |
tree | e4d4b39240d3901371f934b70a567c31156c98eb /lib | |
parent | 9adff4f7f52df660ec066b896161e46abe7a9d5a (diff) | |
parent | 3b904647b0b5d13a0ca4a779d4ea603b526c98a4 (diff) | |
download | nextcloud-server-26e9e68a39da4e22ec438296304dfa7bfd41ec0f.tar.gz nextcloud-server-26e9e68a39da4e22ec438296304dfa7bfd41ec0f.zip |
Merge branch 'master' into fix-5388-master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/avatar.php | 8 | ||||
-rw-r--r-- | lib/private/avatarmanager.php | 26 | ||||
-rw-r--r-- | lib/private/image.php | 31 | ||||
-rw-r--r-- | lib/private/preview/movies.php | 10 | ||||
-rw-r--r-- | lib/private/server.php | 12 | ||||
-rw-r--r-- | lib/private/user.php | 14 | ||||
-rw-r--r-- | lib/public/iavatar.php | 38 | ||||
-rw-r--r-- | lib/public/iavatarmanager.php | 23 | ||||
-rw-r--r-- | lib/public/iservercontainer.php | 6 |
9 files changed, 145 insertions, 23 deletions
diff --git a/lib/private/avatar.php b/lib/private/avatar.php index 720740569df..814a9b22bed 100644 --- a/lib/private/avatar.php +++ b/lib/private/avatar.php @@ -10,7 +10,7 @@ * This class gets and sets users avatars. */ -class OC_Avatar { +class OC_Avatar implements \OCP\IAvatar { private $view; @@ -24,7 +24,7 @@ class OC_Avatar { /** * @brief get the users avatar - * @param $size integer size in px of the avatar, defaults to 64 + * @param $size integer size in px of the avatar, avatars are square, defaults to 64 * @return boolean|\OC_Image containing the avatar or false if there's no image */ public function get ($size = 64) { @@ -54,7 +54,9 @@ class OC_Avatar { $img = new OC_Image($data); $type = substr($img->mimeType(), -3); - if ($type === 'peg') { $type = 'jpg'; } + if ($type === 'peg') { + $type = 'jpg'; + } if ($type !== 'jpg' && $type !== 'png') { $l = \OC_L10N::get('lib'); throw new \Exception($l->t("Unknown filetype")); diff --git a/lib/private/avatarmanager.php b/lib/private/avatarmanager.php new file mode 100644 index 00000000000..3ca46868ea6 --- /dev/null +++ b/lib/private/avatarmanager.php @@ -0,0 +1,26 @@ +<?php +/** + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC; + +use OCP\IAvatarManager; + +/* + * This class implements methods to access Avatar functionality + */ +class AvatarManager implements IAvatarManager { + + /** + * @brief return a user specific instance of \OCP\IAvatar + * @see \OCP\IAvatar + * @param $user string the ownCloud user id + * @return \OCP\IAvatar + */ + function getAvatar($user) { + return new \OC_Avatar($user); + } +} diff --git a/lib/private/image.php b/lib/private/image.php index 7761a3c7737..b5ae1165f8e 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -414,60 +414,61 @@ class OC_Image { */ 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)) { + $absPath = \OC\Files\Filesystem::getLocalFile($imagePath); + if(!@is_file($absPath) || !file_exists($absPath) || filesize($absPath) < 12 || !is_readable($absPath)) { // 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: '.$absPath, OC_Log::DEBUG); return false; } - $iType = exif_imagetype($imagePath); + $iType = exif_imagetype($absPath); switch ($iType) { case IMAGETYPE_GIF: if (imagetypes() & IMG_GIF) { - $this->resource = imagecreatefromgif($imagePath); + $this->resource = imagecreatefromgif($absPath); } else { OC_Log::write('core', - 'OC_Image->loadFromFile, GIF images not supported: '.$imagePath, + 'OC_Image->loadFromFile, GIF images not supported: '.$absPath, OC_Log::DEBUG); } break; case IMAGETYPE_JPEG: if (imagetypes() & IMG_JPG) { - $this->resource = imagecreatefromjpeg($imagePath); + $this->resource = imagecreatefromjpeg($absPath); } else { OC_Log::write('core', - 'OC_Image->loadFromFile, JPG images not supported: '.$imagePath, + 'OC_Image->loadFromFile, JPG images not supported: '.$absPath, OC_Log::DEBUG); } break; case IMAGETYPE_PNG: if (imagetypes() & IMG_PNG) { - $this->resource = imagecreatefrompng($imagePath); + $this->resource = imagecreatefrompng($absPath); } else { OC_Log::write('core', - 'OC_Image->loadFromFile, PNG images not supported: '.$imagePath, + 'OC_Image->loadFromFile, PNG images not supported: '.$absPath, OC_Log::DEBUG); } break; case IMAGETYPE_XBM: if (imagetypes() & IMG_XPM) { - $this->resource = imagecreatefromxbm($imagePath); + $this->resource = imagecreatefromxbm($absPath); } else { OC_Log::write('core', - 'OC_Image->loadFromFile, XBM/XPM images not supported: '.$imagePath, + 'OC_Image->loadFromFile, XBM/XPM images not supported: '.$absPath, OC_Log::DEBUG); } break; case IMAGETYPE_WBMP: if (imagetypes() & IMG_WBMP) { - $this->resource = imagecreatefromwbmp($imagePath); + $this->resource = imagecreatefromwbmp($absPath); } else { OC_Log::write('core', - 'OC_Image->loadFromFile, WBMP images not supported: '.$imagePath, + 'OC_Image->loadFromFile, WBMP images not supported: '.$absPath, OC_Log::DEBUG); } break; case IMAGETYPE_BMP: - $this->resource = $this->imagecreatefrombmp($imagePath); + $this->resource = $this->imagecreatefrombmp($absPath); break; /* case IMAGETYPE_TIFF_II: // (intel byte order) @@ -496,7 +497,7 @@ 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))); + $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents($imagePath)); $iType = IMAGETYPE_PNG; OC_Log::write('core', 'OC_Image->loadFromFile, Default', OC_Log::DEBUG); break; diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php index 28f130f7506..ac771deb413 100644 --- a/lib/private/preview/movies.php +++ b/lib/private/preview/movies.php @@ -46,17 +46,19 @@ if (!\OC_Util::runningOnWindows()) { $handle = $fileview->fopen($path, 'rb'); - $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576 + // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB. + // in some cases 1MB was no enough to generate thumbnail + $firstmb = stream_get_contents($handle, 5242880); file_put_contents($absPath, $firstmb); if (self::$avconvBinary) { - $cmd = self::$avconvBinary . ' -an -y -ss 1'. + $cmd = self::$avconvBinary . ' -an -y -ss 5'. ' -i ' . escapeshellarg($absPath) . - ' -f mjpeg -vframes 1 ' . escapeshellarg($tmpPath) . + ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1'; } else { - $cmd = self::$ffmpegBinary . ' -y -ss 1' . + $cmd = self::$ffmpegBinary . ' -y -ss 5' . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . diff --git a/lib/private/server.php b/lib/private/server.php index 65899f3007e..77c3732a9ca 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -131,6 +131,9 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('ActivityManager', function($c) { return new ActivityManager(); }); + $this->registerService('AvatarManager', function($c) { + return new AvatarManager(); + }); } /** @@ -171,6 +174,15 @@ class Server extends SimpleContainer implements IServerContainer { } /** + * Returns the avatar manager, used for avatar functionality + * + * @return \OCP\IAvatarManager + */ + function getAvatarManager() { + return $this->query('AvatarManager'); + } + + /** * Returns the root folder of ownCloud's data directory * * @return \OCP\Files\Folder diff --git a/lib/private/user.php b/lib/private/user.php index f15fdf1dbbc..5bd36006750 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -54,6 +54,9 @@ class OC_User { private static $_setupedBackends = array(); + // bool, stores if a user want to access a resource anonymously, e.g if he opens a public link + private static $incognitoMode = false; + /** * @brief registers backend * @param string $backend name of the backend @@ -320,6 +323,15 @@ class OC_User { } /** + * @brief set incognito mode, e.g. if a user wants to open a public link + * @param bool $status + */ + public static function setIncognitoMode($status) { + self::$incognitoMode = $status; + + } + + /** * Supplies an attribute to the logout hyperlink. The default behaviour * is to return an href with '?logout=true' appended. However, it can * supply any attribute(s) which are valid for <a>. @@ -354,7 +366,7 @@ class OC_User { */ public static function getUser() { $uid = OC::$session ? OC::$session->get('user_id') : null; - if (!is_null($uid)) { + if (!is_null($uid) && self::$incognitoMode === false) { return $uid; } else { return false; diff --git a/lib/public/iavatar.php b/lib/public/iavatar.php new file mode 100644 index 00000000000..2cbec0d45c3 --- /dev/null +++ b/lib/public/iavatar.php @@ -0,0 +1,38 @@ +<?php +/** + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +/** + * This class provides avatar functionality + */ + +interface IAvatar { + + /** + * @brief get the users avatar + * @param $size integer size in px of the avatar, avatars are square, defaults to 64 + * @return boolean|\OC_Image containing the avatar or false if there's no image + */ + function get($size = 64); + + /** + * @brief sets the users avatar + * @param $data mixed imagedata or path to set a new avatar + * @throws Exception if the provided file is not a jpg or png image + * @throws Exception if the provided image is not valid + * @throws \OCP\NotSquareException if the image is not square + * @return void + */ + function set($data); + + /** + * @brief remove the users avatar + * @return void + */ + function remove(); +} diff --git a/lib/public/iavatarmanager.php b/lib/public/iavatarmanager.php new file mode 100644 index 00000000000..9b185ae0467 --- /dev/null +++ b/lib/public/iavatarmanager.php @@ -0,0 +1,23 @@ +<?php +/** + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +/** + * This class provides avatar functionality + */ + +interface IAvatarManager { + + /** + * @brief return a user specific instance of \OCP\IAvatar + * @see \OCP\IAvatar + * @param $user string the ownCloud user id + * @return \OCP\IAvatar + */ + function getAvatar($user); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 14822817a47..36296a59850 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -154,4 +154,10 @@ interface IServerContainer { */ function getDatabaseConnection(); + /** + * @brief Returns an avatar manager, used for avatar functionality + * @return \OCP\IAvatarManager + */ + function getAvatarManager(); + } |