]> git.mxchange.org Git - friendica.git/blobdiff - src/Contact/Avatar.php
Blanks replaced
[friendica.git] / src / Contact / Avatar.php
index 8aa72bf9ba247ba1200aa065313d0eb717e40a84..38208a043efe94799dd2c0edda5adf49c98fcf30 100644 (file)
@@ -39,6 +39,8 @@ use Friendica\Util\Strings;
  */
 class Avatar
 {
+       const BASE_PATH = '/avatar/';
+
        /**
         * Returns a field array with locally cached avatar pictures
         *
@@ -105,11 +107,11 @@ class Avatar
                        return '';
                }
 
-               $path = '/avatar/' . $filename . $size . '.' . $image->getExt();
+               $path = self::BASE_PATH . $filename . $size . '.' . $image->getExt();
 
                $filepath = DI::basePath() . $path;
 
-               $dirpath = DI::basePath() . '/avatar/';
+               $dirpath = DI::basePath() . self::BASE_PATH;
 
                DI::profiler()->startRecording('file');
 
@@ -121,20 +123,34 @@ class Avatar
                // Check directory permissions of all parts of the path
                foreach (explode('/', dirname($filename)) as $part) {
                        $dirpath .= $part . '/';
+
                        if (!file_exists($dirpath)) {
-                               mkdir($dirpath, $dir_perm);
-                       } elseif (fileperms($dirpath) & 0777 != $dir_perm) {
-                               chmod($dirpath, $dir_perm);
+                               if (!mkdir($dirpath, $dir_perm)) {
+                                       Logger::warning('Directory could not be created', ['directory' => $dirpath]);
+                               }
+                       } elseif ((($old_perm = fileperms($dirpath) & 0777) != $dir_perm) && !chmod($dirpath, $dir_perm)) {
+                               Logger::notice('Directory permissions could not be changed', ['directory' => $dirpath, 'old' => $old_perm, 'new' => $dir_perm]);
                        }
 
-                       if (filegroup($dirpath) != $group) {
-                               chgrp($dirpath, $group);
+                       if ((($old_group = filegroup($dirpath)) != $group) && !chgrp($dirpath, $group)) {
+                               Logger::notice('Directory group could not be changed', ['directory' => $dirpath, 'old' => $old_group, 'new' => $group]);
                        }
                }
 
-               file_put_contents($filepath, $image->asString());
-               chmod($filepath, $file_perm);
-               chgrp($filepath, $group);
+               if (!file_put_contents($filepath, $image->asString())) {
+                       Logger::warning('File could not be created', ['file' => $filepath]);
+               }
+
+               $old_perm  = fileperms($filepath) & 0666;
+               $old_group = filegroup($filepath);
+
+               if (($old_perm != $file_perm) && !chmod($filepath, $file_perm)) {
+                       Logger::notice('File permissions could not be changed', ['file' => $filepath, 'old' => $old_perm, 'new' => $file_perm]);
+               }
+
+               if (($old_group != $group) && !chgrp($filepath, $group)) {
+                       Logger::notice('File group could not be changed', ['file' => $filepath, 'old' => $old_group, 'new' => $group]);
+               }
 
                DI::profiler()->stopRecording();
 
@@ -169,13 +185,13 @@ class Avatar
                        return '';
                }
 
-               $path = Strings::normaliseLink(DI::baseUrl() . '/avatar');
+               $path = Strings::normaliseLink(DI::baseUrl() . self::BASE_PATH);
 
                if (Network::getUrlMatch($path, $avatar) != $path) {
                        return '';
                }
 
-               $filename = str_replace($path, DI::basePath(). '/avatar/', Strings::normaliseLink($avatar));
+               $filename = str_replace($path, DI::basePath(). self::BASE_PATH, Strings::normaliseLink($avatar));
 
                DI::profiler()->startRecording('file');
                $exists = file_exists($filename);