19 $handle = @opendir($dir);
20 while ($file = @readdir($handle)) {
21 if (in_array($file, array(
'.',
'..'))) {
24 if (is_dir($dir . $file)) {
25 $total_size =
get_dir_size($dir . $file .
"/", $total_size);
27 $total_size += filesize($dir . $file);
54 return file_get_contents(
elgg_extract(
'tmp_name', $file));
72 $square =
false, $upscale =
false) {
84 $maxheight, $square, 0, 0, 0, 0, $upscale);
112 if ($imgsizearray ==
false) {
116 $width = $imgsizearray[0];
117 $height = $imgsizearray[1];
119 $accepted_formats = array(
120 'image/jpeg' =>
'jpeg',
121 'image/pjpeg' =>
'jpeg',
122 'image/png' =>
'png',
123 'image/x-png' =>
'png',
128 $load_function =
"imagecreatefrom" . $accepted_formats[$imgsizearray[
'mime']];
129 if (!is_callable($load_function)) {
135 'maxwidth' => $maxwidth,
136 'maxheight' => $maxheight,
138 'upscale' => $upscale,
150 $original_image = call_user_func($load_function,
$input_name);
151 if (!$original_image) {
156 $new_image = imagecreatetruecolor(
$params[
'newwidth'],
$params[
'newheight']);
162 imagefilledrectangle(
164 imagecolorallocate($new_image, 255, 255, 255)
167 $rtn_code = imagecopyresampled( $new_image,
183 imagejpeg($new_image, null, 90);
184 $jpeg = ob_get_clean();
186 imagedestroy($new_image);
187 imagedestroy($original_image);
237 $selection_width =
$x2 -
$x1;
238 $selection_height =
$y2 -
$y1;
241 $selection_width = $width;
242 $selection_height = $height;
250 if ($crop ==
true && $selection_width != $selection_height) {
255 $new_width = $new_height = min($maxwidth, $maxheight);
258 $selection_width = $selection_height = min($selection_width, $selection_height);
268 $widthoffset = floor(($width - $selection_width) / 2);
269 $heightoffset = floor(($height - $selection_height) / 2);
273 $new_width = $maxwidth;
274 $new_height = $maxheight;
277 if (($selection_height / (
float)$new_height) > ($selection_width / (
float)$new_width)) {
278 $new_width = floor($new_height * $selection_width / (
float)$selection_height);
280 $new_height = floor($new_width * $selection_height / (
float)$selection_width);
293 if (!$upscale && ($selection_height < $new_height || $selection_width < $new_width)) {
296 $new_height = $selection_height;
297 $new_width = $selection_width;
299 if ($selection_height < $new_height && $selection_width < $new_width) {
300 $new_height = $selection_height;
301 $new_width = $selection_width;
307 'newwidth' => $new_width,
308 'newheight' => $new_height,
309 'selectionwidth' => $selection_width,
310 'selectionheight' => $selection_height,
311 'xoffset' => $widthoffset,
312 'yoffset' => $heightoffset,
327 if (!$file || !$file->canEdit()) {
331 $thumbnail = $file->thumbnail;
332 $smallthumb = $file->smallthumb;
333 $largethumb = $file->largethumb;
335 $delfile = new \ElggFile();
336 $delfile->owner_guid = $file->owner_guid;
337 $delfile->setFilename($thumbnail);
341 $delfile = new \ElggFile();
342 $delfile->owner_guid = $file->owner_guid;
343 $delfile->setFilename($smallthumb);
347 $delfile = new \ElggFile();
348 $delfile->owner_guid = $file->owner_guid;
349 $delfile->setFilename($largethumb);
353 return $file->delete();
365 if (!$handle = opendir($directory)) {
370 while (($file = readdir($handle)) !==
false) {
371 if (in_array($file, array(
'.',
'..'))) {
375 $path =
"$directory/$file";
389 return rmdir($directory);
408 $dir = new \Elgg\EntityDirLocator(
$entity->guid);
410 if (file_exists($file_path)) {
440 $DEFAULT_FILE_STORE = $filestore;
454 $params = array(
'mime_type' => $mime_type);
469 if (isset($CONFIG->dataroot)) {
498 $info = pathinfo($original_filename);
501 $office_formats = array(
'docx',
'xlsx',
'pptx');
502 if ($mime_type ==
"application/zip" && in_array($info[
'extension'], $office_formats)) {
503 switch ($info[
'extension']) {
505 $mime_type =
"application/vnd.openxmlformats-officedocument.wordprocessingml.document";
508 $mime_type =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
511 $mime_type =
"application/vnd.openxmlformats-officedocument.presentationml.presentation";
517 if ($mime_type ==
"application/vnd.ms-office" && $info[
'extension'] ==
"ppt") {
518 $mime_type =
"application/vnd.ms-powerpoint";
539 switch ($mime_type) {
540 case "application/msword":
541 case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
542 case "application/pdf":
545 case "application/ogg":
549 if (preg_match(
'~^(audio|image|video)/~', $mime_type,
$m)) {
552 if (0 === strpos($mime_type,
'text/') ||
false !== strpos($mime_type,
'opendocument')) {
572 $value[] =
"{$CONFIG->path}engine/tests/ElggCoreFilestoreTest.php";
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$DEFAULT_FILE_STORE
Variable holding the default datastore.
get_dir_size($dir, $total_size=0)
Get the size of the specified directory.
if(!$autoload_available) _elgg_services()
_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_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $x1
get_image_resize_parameters($width, $height, $options)
Calculate the parameters for resizing an image.
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...
get_uploaded_file($input_name)
Get the contents of an uploaded file.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
elgg global
Pointer to the global context.
file_delete($guid)
Delete an file.
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
_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.
_elgg_filestore_init()
Initialize the file library.
_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_entity($guid)
Loads and returns an entity object from a guid.