$settings[$setting] = $value;
}
}
+
+ // core#4791 - Set cache dir to prevent files being generated in font dir
+ $cacheDir = self::getCacheDir($settings);
+ if ($cacheDir !== "") {
+ $settings['font_cache'] = $cacheDir;
+ }
$options->set($settings);
return $options;
}
+ /**
+ * Get location of cache folder.
+ *
+ * @param array $settings
+ * @return string
+ */
+ private static function getCacheDir(array $settings): string {
+ // Use subfolder of custom font dir if it is writable
+ if (isset($settings['font_dir']) && is_writable($settings['font_dir'])) {
+ $cacheDir = $settings['font_dir'] . DIRECTORY_SEPARATOR . 'font_cache';
+ }
+ else {
+ $cacheDir = Civi::paths()->getPath('[civicrm.files]/upload/font_cache');
+ }
+ // Try to create dir if it doesn't exist or return empty string
+ if ((!is_dir($cacheDir)) && (!mkdir($cacheDir))) {
+ $cacheDir = "";
+ }
+ return $cacheDir;
+ }
+
}