21 $handle = @opendir($dir);
22 while (
$file = @readdir($handle)) {
23 if (in_array(
$file, array(
'.',
'..'))) {
26 if (is_dir($dir .
$file)) {
27 $total_size =
get_dir_size($dir . $file .
"/", $total_size);
29 $total_size += filesize($dir . $file);
49 $input = array_shift($inputs);
53 return file_get_contents(
$input->getPathname());
101 $square =
false, $upscale =
false) {
115 if (
$file->getError() !== 0) {
144 $square =
false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0, $upscale =
false) {
154 $tmp_filename = tempnam(sys_get_temp_dir(),
'icon_resize');
164 'upscale' => $upscale,
167 $image_bytes =
false;
169 $image_bytes = file_get_contents($tmp_filename);
172 unlink($tmp_filename);
207 'selectionheight' => $params[
'y2'] - $params[
'y1'],
208 'xoffset' => $params[
'x1'],
209 'yoffset' => $params[
'y1'],
212 elgg_log($ex->getMessage(),
'ERROR');
230 $thumbnail =
$file->thumbnail;
231 $smallthumb =
$file->smallthumb;
232 $largethumb =
$file->largethumb;
234 $delfile = new \ElggFile();
235 $delfile->owner_guid =
$file->owner_guid;
236 $delfile->setFilename($thumbnail);
240 $delfile = new \ElggFile();
241 $delfile->owner_guid =
$file->owner_guid;
242 $delfile->setFilename($smallthumb);
246 $delfile = new \ElggFile();
247 $delfile->owner_guid =
$file->owner_guid;
248 $delfile->setFilename($largethumb);
252 return $file->delete();
264 if (!$handle = opendir($directory)) {
269 while ((
$file = readdir($handle)) !==
false) {
270 if (in_array(
$file, array(
'.',
'..'))) {
274 $path =
"$directory/$file";
288 return rmdir($directory);
307 $dir = new \Elgg\EntityDirLocator(
$entity->guid);
309 if (file_exists($file_path)) {
326 return $GLOBALS[
'DEFAULT_FILE_STORE'];
340 $GLOBALS[
'DEFAULT_FILE_STORE'] = $filestore;
353 $params = array(
'mime_type' => $mime_type);
367 if (isset($CONFIG->dataroot)) {
368 $GLOBALS[
'DEFAULT_FILE_STORE'] = new \ElggDiskFilestore($CONFIG->dataroot);
415 $ext = pathinfo($original_filename, PATHINFO_EXTENSION);
417 return (
new \
Elgg\Filesystem\MimeTypeDetector())->fixDetectionErrors($mime_type, $ext);
435 switch ($mime_type) {
436 case "application/msword":
437 case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
438 case "application/pdf":
441 case "application/ogg":
445 if (preg_match(
'~^(audio|image|video)/~', $mime_type,
$m)) {
448 if (0 === strpos($mime_type,
'text/') ||
false !== strpos($mime_type,
'opendocument')) {
468 $value[] =
"{$CONFIG->path}engine/tests/ElggCoreFilestoreTest.php";
484 $file_svc->setFile($file);
485 $file_svc->setExpires($expires);
486 $file_svc->setDisposition(
'attachment');
487 $file_svc->bindSession($use_cookie);
488 return $file_svc->getURL();
504 $file_svc->setFile($file);
506 $file_svc->setExpires($expires);
508 $file_svc->setDisposition(
'inline');
509 $file_svc->bindSession($use_cookie);
510 return $file_svc->getURL();
538 $response =
_elgg_services()->iconService->handleServeIconRequest();
553 $original_attributes =
$entity->getOriginalAttributes();
554 if (!array_key_exists(
'access_id', $original_attributes)) {
562 foreach ($sizes as
$size) {
564 if (
$icon->exists()) {
565 $icon->setModifiedTime();
588 $original_attributes =
$entity->getOriginalAttributes();
589 if (empty($original_attributes[
'owner_guid'])) {
593 $previous_owner_guid = $original_attributes[
'owner_guid'];
594 $new_owner_guid =
$entity->owner_guid;
598 foreach ($sizes as
$size => $opts) {
600 if ($new_icon->owner_guid ==
$entity->guid) {
605 if ($new_icon->owner_guid != $new_owner_guid) {
610 $old_icon = new \ElggIcon();
611 $old_icon->owner_guid = $previous_owner_guid;
612 $old_icon->setFilename($new_icon->getFilename());
613 if (!$old_icon->exists()) {
618 if ($new_icon->exists()) {
622 elgg_log(
"Entity $entity->guid has been transferred to a new owner but an icon was " 623 .
"left behind under {$old_icon->getFilenameOnFilestore()}. " 624 .
"Old icon has been deleted",
'NOTICE');
628 $old_icon->transfer($new_icon->owner_guid, $new_icon->getFilename());
629 elgg_log(
"Entity $entity->guid has been transferred to a new owner. " 630 .
"Icon was moved from {$old_icon->getFilenameOnFilestore()} to {$new_icon->getFilenameOnFilestore()}.",
'NOTICE');
645 $events->registerHandler(
'boot',
'system',
'_elgg_filestore_boot', 100);
646 $events->registerHandler(
'init',
'system',
'_elgg_filestore_init', 100);
_elgg_filestore_boot()
Bootstraps the default filestore at "boot, system" event.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
_elgg_filestore_serve_icon_handler()
Handler for /serve-icon resources /serve-icon/<entity_guid>/<size>
if(!array_key_exists($filename, $text_files)) $file
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $input
$DEFAULT_FILE_STORE
Variable holding the default datastore.
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.
$guid
Removes an admin notice.
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.
get_default_filestore()
Return the default filestore.
get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square=false, $x1=0, $y1=0, $x2=0, $y2=0, $upscale=false)
Gets the jpeg contents of the resized version of an already uploaded image (Returns false if the file...
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.
get_uploaded_file($input_name)
Get the contents of an uploaded file.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
elgg global
Pointer to the global context.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
file_delete($guid)
Delete an file.
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)
elgg_log($message, $level= 'NOTICE')
Display or log a message.
elgg_save_resized_image($source, $destination=null, array $params=array())
Crops and resizes an image.
_elgg_filestore_detect_mimetype($hook, $type, $mime_type, $params)
Fix MIME type detection for Microsoft zipped formats.
get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square=false, $upscale=false)
Gets the jpeg contents of the resized version of an uploaded image (Returns false if the uploaded fil...
delete_directory($directory)
Delete a directory and all its contents.
set_default_filestore(\ElggFilestore $filestore)
Set the default filestore for the system.
foreach($resources as $id=> $href) if(!empty($resources_html)) $files
_elgg_filestore_init()
Register file-related handlers on "init, system" event.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
_elgg_filestore_test($hook, $type, $value)
Unit tests for files.
_elgg_clear_entity_files($entity)
Removes all entity files.
elgg_get_file_simple_type($mime_type)
Returns the category of a file from its MIME type.
get_image_resize_parameters($width, $height, array $params=[])
Calculate the parameters for resizing an image.
get_entity($guid)
Loads and returns an entity object from a guid.
_elgg_filestore_touch_icons($event, $type, $entity)
Reset icon URLs if access_id has changed.