Elgg  Version master
filestore.php
Go to the documentation of this file.
1 <?php
8 use Symfony\Component\HttpFoundation\File\UploadedFile;
9 
38 function elgg_save_resized_image(string $source, ?string $destination = null, array $params = []): bool {
39  return _elgg_services()->imageService->resize($source, $destination, $params);
40 }
41 
51 function elgg_delete_directory(string $directory, bool $leave_base_directory = false): bool {
52  $directory = Paths::sanitize($directory);
53  if (!file_exists($directory)) {
54  return true;
55  }
56 
57  if (!is_dir($directory)) {
58  return false;
59  }
60 
61  $dh = new \DirectoryIterator($directory);
62  /* @var $file_info \DirectoryIterator */
63  foreach ($dh as $file_info) {
64  if ($file_info->isDot()) {
65  continue;
66  }
67 
68  if ($file_info->isDir()) {
69  // recurse down through directory
70  if (!elgg_delete_directory($directory . $file_info->getFilename())) {
71  return false;
72  }
73  } elseif ($file_info->isFile()) {
74  unlink($file_info->getPathname());
75  }
76  }
77 
78  if ($leave_base_directory) {
79  return true;
80  }
81 
82  // remove empty directory
83  return rmdir($directory);
84 }
85 
97 function elgg_get_download_url(\ElggFile $file, bool $use_cookie = true, string $expires = '+2 hours'): ?string {
98  return $file->getDownloadURL($use_cookie, $expires);
99 }
100 
113 function elgg_get_inline_url(\ElggFile $file, bool $use_cookie = false, string $expires = ''): ?string {
114  return $file->getInlineURL($use_cookie, $expires);
115 }
116 
130 function elgg_get_embed_url(\ElggEntity $entity, string $size): string {
131  return elgg_generate_url('serve-icon', [
132  'guid' => $entity->guid,
133  'size' => $size,
134  ]);
135 }
136 
144 function elgg_get_uploaded_files(string $input_name): array {
145  return _elgg_services()->uploads->getFiles($input_name);
146 }
147 
156 function elgg_get_uploaded_file(string $input_name, bool $check_for_validity = true): ?UploadedFile {
157  return _elgg_services()->uploads->getFile($input_name, $check_for_validity);
158 }
159 
167  return new ElggTempFile();
168 }
$entity
Definition: reset.php:8
$params
Saves global plugin settings.
Definition: save.php:13
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
$source
This class represents a physical file (by default in the system temp directory).
Find Elgg and project paths.
Definition: Paths.php:8
$input_name
Definition: crop.php:24
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
Definition: item.php:48
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
elgg_delete_directory(string $directory, bool $leave_base_directory=false)
Delete a directory and all its contents.
Definition: filestore.php:51
elgg_save_resized_image(string $source, ?string $destination=null, array $params=[])
Crops and resizes an image.
Definition: filestore.php:38
elgg_get_uploaded_file(string $input_name, bool $check_for_validity=true)
Returns a single valid uploaded file object.
Definition: filestore.php:156
elgg_get_embed_url(\ElggEntity $entity, string $size)
Returns a URL suitable for embedding entity's icon in a text editor.
Definition: filestore.php:130
elgg_get_inline_url(\ElggFile $file, bool $use_cookie=false, string $expires='')
Returns file's URL for inline display Suitable for displaying cacheable resources,...
Definition: filestore.php:113
elgg_get_uploaded_files(string $input_name)
Returns an array of uploaded file objects regardless of upload status/errors.
Definition: filestore.php:144
elgg_get_download_url(\ElggFile $file, bool $use_cookie=true, string $expires='+2 hours')
Returns file's download URL.
Definition: filestore.php:97
elgg_get_temp_file()
Returns a ElggTempFile which can handle writing/reading of data to a temporary file location.
Definition: filestore.php:166
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
$size
Definition: thumb.php:23
$expires