+
+ /**
+ * Fetch the avatar base path
+ *
+ * @return string
+ */
+ private static function basePath(): string
+ {
+ $basepath = DI::config()->get('system', 'avatar_cache_path');
+ if (empty($basepath)) {
+ $basepath = DI::basePath() . self::BASE_PATH;
+ }
+ $basepath = rtrim($basepath, '/') . '/';
+
+ if (!file_exists($basepath)) {
+ // We only automatically create the folder when it is in the web root
+ if (strpos($basepath, DI::basePath()) !== 0) {
+ Logger::warning('Base directory does not exist', ['directory' => $basepath]);
+ return '';
+ }
+ if (!mkdir($basepath, 0775)) {
+ Logger::warning('Base directory could not be created', ['directory' => $basepath]);
+ return '';
+ }
+ }
+
+ return $basepath;
+ }
+
+ /**
+ * Fetch the avatar base url
+ *
+ * @return string
+ */
+ private static function baseUrl(): string
+ {
+ $baseurl = DI::config()->get('system', 'avatar_cache_url');
+ if (!empty($baseurl)) {
+ return rtrim($baseurl, '/') . '/';
+ }
+
+ return DI::baseUrl() . self::BASE_PATH;
+ }