25 $handle = opendir($dir);
26 while ((
$file = readdir($handle)) !==
false) {
27 if (in_array(
$file, [
'.',
'..'])) {
30 if (is_dir($dir .
$file)) {
31 $total_size =
get_dir_size($dir . $file .
"/", $total_size);
33 $total_size += filesize($dir . $file);
79 if (!file_exists($directory)) {
83 if (!is_dir($directory)) {
88 if (!$handle = opendir($directory)) {
93 while ((
$file = readdir($handle)) !==
false) {
94 if (in_array(
$file, [
'.',
'..'])) {
98 $path =
"$directory/$file";
112 return rmdir($directory);
124 $params = [
'mime_type' => $mime_type];
168 $ext = pathinfo($original_filename, PATHINFO_EXTENSION);
170 return (
new \
Elgg\Filesystem\MimeTypeDetector())->fixDetectionErrors($mime_type, $ext);
188 switch ($mime_type) {
189 case "application/msword":
190 case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
191 case "application/pdf":
194 case "application/ogg":
198 if (preg_match(
'~^(audio|image|video)/~', $mime_type, $m)) {
201 if (0 === strpos($mime_type,
'text/') ||
false !== strpos($mime_type,
'opendocument')) {
268 'guid' => $entity->guid,
282 $response =
_elgg_services()->iconService->handleServeIconRequest();
297 $original_attributes =
$entity->getOriginalAttributes();
298 if (!array_key_exists(
'access_id', $original_attributes)) {
306 foreach ($sizes as
$size) {
308 if (
$icon->exists()) {
309 $icon->setModifiedTime();
332 $original_attributes =
$entity->getOriginalAttributes();
333 if (empty($original_attributes[
'owner_guid'])) {
337 $previous_owner_guid = $original_attributes[
'owner_guid'];
338 $new_owner_guid =
$entity->owner_guid;
342 foreach ($sizes as
$size => $opts) {
344 if ($new_icon->owner_guid ==
$entity->guid) {
349 if ($new_icon->owner_guid != $new_owner_guid) {
354 $old_icon = new \ElggIcon();
355 $old_icon->owner_guid = $previous_owner_guid;
356 $old_icon->setFilename($new_icon->getFilename());
357 if (!$old_icon->exists()) {
362 if ($new_icon->exists()) {
366 elgg_log(
"Entity $entity->guid has been transferred to a new owner but an icon was " 367 .
"left behind under {$old_icon->getFilenameOnFilestore()}. " 368 .
"Old icon has been deleted",
'NOTICE');
372 $old_icon->transfer($new_icon->owner_guid, $new_icon->getFilename());
373 elgg_log(
"Entity $entity->guid has been transferred to a new owner. " 374 .
"Icon was moved from {$old_icon->getFilenameOnFilestore()} to {$new_icon->getFilenameOnFilestore()}.",
'NOTICE');
414 $events->registerHandler(
'init',
'system',
'_elgg_filestore_init', 100);
_elgg_filestore_serve_icon_handler()
Handler for /serve-icon resources /serve-icon/<entity_guid>/<size>
if(!array_key_exists($filename, $text_files)) $file
$params
Saves global plugin settings.
This class represents a physical file (by default in the system temp directory).
elgg_get_icon_sizes($entity_type=null, $entity_subtype=null, $type= 'icon')
Returns a configuration array of icon sizes.
elgg_get_download_url(\ElggFile $file, $use_cookie=true, $expires= '+2 hours')
Returns file's download URL.
elgg_get_embed_url(\ElggEntity $entity, $size)
Returns a URL suitable for embedding entity's icon in a text editor.
get_dir_size($dir, $total_size=0)
Get the size of the specified directory.
_elgg_filestore_parse_simpletype($hook, $type, $simple_type, $params)
Parse a file category of file from a MIME type.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
elgg_get_uploaded_files($input_name)
Returns an array of uploaded file objects regardless of upload status/errors.
elgg_get_inline_url(\ElggFile $file, $use_cookie=false, $expires= '')
Returns file's URL for inline display Suitable for displaying cacheable resources, such as user avatars.
elgg_get_uploaded_file($input_name, $check_for_validity=true)
Returns a single valid uploaded file object.
Base class for events and hooks.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
elgg_get_temp_file()
Returns a ElggTempFile which can handle writing/reading of data to a temporary file location...
elgg_generate_url($name, array $parameters=[])
Generate a URL for named route.
getDownloadURL($use_cookie=true, $expires= '+2 hours')
Returns file's download URL.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
_elgg_filestore_move_icons($event, $type, $entity)
Listen to entity ownership changes and update icon ownership by moving icons to their new owner's dir...
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
getInlineURL($use_cookie=false, $expires= '')
Returns file's URL for inline display Suitable for displaying cacheable resources, such as user avatars.
_elgg_filestore_detect_mimetype($hook, $type, $mime_type, $params)
Fix MIME type detection for Microsoft zipped formats.
elgg_save_resized_image($source, $destination=null, array $params=[])
Crops and resizes an image.
_elgg_services()
Get the global service provider.
delete_directory($directory)
Delete a directory and all its contents.
_elgg_filestore_init()
Register file-related handlers on "init, system" event.
_elgg_filestore_test($hook, $type, $value)
Unit tests for files.
elgg_get_file_simple_type($mime_type)
Returns the category of a file from its MIME type.
_elgg_filestore_touch_icons($event, $type, $entity)
Reset icon URLs if access_id has changed.