/** * Create the watermark image filename * * @param string $text * @param ElggUser $owner * @return string */ function tp_get_watermark_filename($text, $owner) { $base = elgg_strtolower($text); $base = preg_replace("/[^\\w-]+/", "-", $base); $base = trim($base, '-'); $filename = tp_get_img_dir(); $filename .= elgg_strtolower($owner->username . "_" . $base . "_stamp"); return $filename; }
/** * Saves uploaded file to ElggFile with given attributes * * @param array $attributes New file attributes and metadata * @apara string $prefix Filestore prefix * @return \Upload */ public function save(array $attributes = array(), $prefix = self::DEFAULT_FILESTORE_PREFIX) { $this->error_code = $this->error; $this->error = $this->getError(); $this->filesize = $this->size; $this->path = $this->tmp_name; $this->mimetype = $this->detectMimeType(); $this->simpletype = $this->parseSimpleType(); if (!$this->isSuccessful()) { return $this; } $prefix = trim($prefix, '/'); if (!$prefix) { $prefix = self::DEFAULT_FILESTORE_PREFIX; } $id = elgg_strtolower(time() . $this->name); $filename = implode('/', array($prefix, $id)); $type = elgg_extract('type', $attributes, 'object'); $subtype = elgg_extract('subtype', $attributes, 'file'); $class = get_subtype_class($type, $subtype); if (!$class) { $class = '\\ElggFile'; } try { $filehandler = new $class(); foreach ($attributes as $key => $value) { $filehandler->{$key} = $value; } $filehandler->setFilename($filename); $filehandler->title = $this->name; $filehandler->originalfilename = $this->name; $filehandler->filesize = $this->size; $filehandler->mimetype = $this->mimetype; $filehandler->simpletype = $this->simpletype; $filehandler->open("write"); $filehandler->close(); if ($this->simpletype == 'image') { $img = new \hypeJunction\Files\Image($this->tmp_name); $img->save($filehandler->getFilenameOnFilestore(), hypeApps()->config->getSrcCompressionOpts()); } else { move_uploaded_file($this->tmp_name, $filehandler->getFilenameOnFilestore()); } if ($filehandler->save()) { $this->guid = $filehandler->getGUID(); $this->file = $filehandler; } } catch (\Exception $ex) { elgg_log($ex->getMessage(), 'ERROR'); $this->error = elgg_echo('upload:error:unknown'); } return $this; }
function copyGroup($guid, $name, $parentGroupGuid = null, array $options = null) { $inheritMembers = $_POST['inheritMembers']; $inheritFiles = $_POST['inheritFiles']; $inheritForums = $_POST['inheritForums']; $inheritSubGroups = $_POST['subGroups']; if ($options) { $inheritMembers = $options['inheritMembers']; $inheritFiles = $options['inheritFiles']; $inheritForums = $options['inheritForums']; $inheritSubGroups = $options['inheritSubGroups']; } $groupOptions = array('inheritMembers' => $inheritMembers, 'inheritFiles' => $inheritFiles, 'inheritForums' => $inheritForums, 'inheritSubGroups' => $inheritSubGroups); //check if a sub-group when parentGroupGuid is null if (!isset($parentGroupGuid)) { $parentGroup = elgg_get_entities_from_relationship(array("relationship" => "au_subgroup_of", "relationship_guid" => $guid)); $parentGroupGuid = $parentGroup[0]->guid; } //get group $oldGroup = get_entity($guid); //get user $user = get_user($oldGroup->owner_guid); //create new group $newGroup = clone $oldGroup; $newGroup->name = $name; $newGroup->save(); //get all categories associated with the group and associate them with the copied group $groupCats = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjcategory', 'order_by' => 'e.last_action desc', 'limit' => 40, 'full_view' => false, 'container_guid' => $guid)); foreach ($groupCats as $groupCat) { $newGroupCat = clone $groupCat; $newGroupCat->container_guid = $newGroup->guid; $newGroupCat->save(); } if ($inheritFiles) { //clone files belonging to the old group add add them to their new categories $groupFiles = elgg_get_entities(array('type' => 'object', 'subtype' => 'file', 'order_by' => 'e.last_action desc', 'limit' => 500, 'full_view' => false, 'container_guid' => $guid)); foreach ($groupFiles as $groupFile) { $newGroupFile = clone $groupFile; $newGroupFile->container_guid = $newGroup->guid; $newGroupFile->access_id = $newGroup->group_acl; $date = new DateTime(); $newTimeStamp = $date->getTimestamp(); $newGroupFile->time_created = $newTimeStamp; $newGroupFile->time_updated = $newTimeStamp; $newGroupFile->last_action = $newTimeStamp; $newGroupFile->save(); //copy file over on disk $prefix = "file/"; $filestorename = elgg_strtolower(time() . $newGroupFile->originalfilename); $sourceDest = $newGroupFile->getFilenameOnFilestore(); $newGroupFile->setFilename($prefix . $filestorename); $newGroupFile->open("write"); $newGroupFile->close(); if (!copy($sourceDest, $newGroupFile->getFilenameOnFilestore())) { error_log("couldn't copy"); } //if file is tagged in a category, need to update to reflect copied groups category if ($newGroupFile->universal_categories) { $categories = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjcategory', 'order_by' => 'e.last_action desc', 'limit' => 40, 'full_view' => false, 'container_guid' => $newGroup->guid)); $copyCategories = elgg_get_entities_from_relationship(array('relationship' => HYPECATEGORIES_RELATIONSHIP, 'relationship_guid' => $groupFile->guid, 'inverse_relationship' => false, 'limit' => 150)); foreach ($categories as $category) { foreach ($copyCategories as $c) { if ($category->title == $c->title) { add_entity_relationship($newGroupFile->guid, HYPECATEGORIES_RELATIONSHIP, $category->guid); } } } } //$newGroupFile->save(); } //get all folders associated with the group and associate them with the new copied group $groupFolders = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 120, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => 0)); foreach ($groupFolders as $groupFolder) { $newGroupFolder = clone $groupFolder; $newGroupFolder->container_guid = $newGroup->guid; $newGroupFolder->access_id = $newGroup->group_acl; $newGroupFolder->save(); //get files associated with folder $files = elgg_get_entities(array('type' => 'object', 'subtype' => 'file', 'order_by' => 'e.last_action desc', 'limit' => 500, 'full_view' => false, 'container_guid' => $newGroup->guid)); $oldFolderFiles = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $groupFolder->guid, 'inverse_relationship' => false, 'limit' => 100)); foreach ($oldFolderFiles as $f) { foreach ($files as $file) { if ($file->title == $f->title) { add_entity_relationship($newGroupFolder->guid, 'folder_of', $file->guid); } } } //get sub folders $subFolders = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $groupFolder->guid)); foreach ($subFolders as $subFolder) { $newSubFolder = clone $subFolder; $newSubFolder->container_guid = $newGroup->guid; $newSubFolder->access_id = $newGroup->group_acl; $newSubFolder->parent_guid = $newGroupFolder->guid; $newSubFolder->save(); $oldSubFolderFiles = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder->guid, 'inverse_relationship' => false, 'limit' => 60)); foreach ($oldSubFolderFiles as $f) { foreach ($files as $file) { if ($file->title == $f->title) { add_entity_relationship($newSubFolder->guid, 'folder_of', $file->guid); } } } //get sub sub folders $subFolders2 = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $subFolder->guid)); foreach ($subFolders2 as $subFolder2) { $newSubFolder2 = clone $subFolder2; $newSubFolder2->container_guid = $newGroup->guid; $newSubFolder2->access_id = $newGroup->group_acl; $newSubFolder2->parent_guid = $newSubFolder->guid; $newSubFolder2->save(); $oldSubFolder2Files = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder2->guid, 'inverse_relationship' => false, 'limit' => 60)); foreach ($oldSubFolder2Files as $f) { foreach ($files as $file) { if ($file->title == $f->title) { add_entity_relationship($newSubFolder2->guid, 'folder_of', $file->guid); } } } //get sub sub folders $subFolders3 = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $subFolder2->guid)); foreach ($subFolders3 as $subFolder3) { $newSubFolder3 = clone $subFolder3; $newSubFolder3->container_guid = $newGroup->guid; $newSubFolder3->access_id = $newGroup->group_acl; $newSubFolder3->parent_guid = $newSubFolder2->guid; $newSubFolder3->save(); $oldSubFolder3Files = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder3->guid, 'inverse_relationship' => false, 'limit' => 60)); foreach ($oldSubFolder3Files as $f) { foreach ($files as $file) { if ($file->title == $f->title) { add_entity_relationship($newSubFolder3->guid, 'folder_of', $file->guid); } } } //get sub sub folders $subFolders4 = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $subFolder3->guid)); foreach ($subFolders4 as $subFolder4) { $newSubFolder4 = clone $subFolder4; $newSubFolder4->container_guid = $newGroup->guid; $newSubFolder4->access_id = $newGroup->group_acl; $newSubFolder4->parent_guid = $newSubFolder3->guid; $newSubFolder4->save(); $oldSubFolder4Files = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder4->guid, 'inverse_relationship' => false, 'limit' => 60)); foreach ($oldSubFolder4Files as $f) { foreach ($files as $file) { if ($file->title == $f->title) { add_entity_relationship($newSubFolder4->guid, 'folder_of', $file->guid); } } } //get sub sub sub folders $subFolders5 = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'folder', 'order_by' => 'e.last_action desc', 'limit' => 60, 'full_view' => false, 'container_guid' => $guid, 'metadata_name' => 'parent_guid', 'metadata_value' => $subFolder4->guid)); foreach ($subFolders5 as $subFolder5) { $newSubFolder5 = clone $subFolder5; $newSubFolder5->container_guid = $newGroup->guid; $newSubFolder5->access_id = $newGroup->group_acl; $newSubFolder5->parent_guid = $newSubFolder5->guid; $newSubFolder5->save(); $oldSubFolder5Files = elgg_get_entities_from_relationship(array('relationship' => 'folder_of', 'relationship_guid' => $subFolder5->guid, 'inverse_relationship' => false, 'limit' => 60)); foreach ($oldSubFolder5Files as $f) { foreach ($files as $file) { if ($file->title == $f->title) { add_entity_relationship($newSubFolder5->guid, 'folder_of', $file->guid); } } } } //end 6th level folders } //end 5th level folders } //end 4th level folders } //end 3rd level folders } //end 2nd folders } //end group folders } //copy over forums if ($inheritForums) { $groupForums = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjforum', 'order_by' => 'e.last_action asc', 'limit' => 100, 'full_view' => false, 'container_guid' => $guid)); $i1 = 0; foreach ($groupForums as $groupForum) { $newGroupForum = clone $groupForum; $newGroupForum->container_guid = $newGroup->getGUID(); $newGroupForum->access_id = $newGroup->group_acl; $newGroupForum->last_action = time(); $newGroupForum->save(); $subForums = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjforum', 'order_by' => 'e.last_action asc', 'limit' => 150, 'full_view' => false, 'container_guid' => $groupForum->guid)); $i2 = 0; foreach ($subForums as $subForum) { $newSubForum = clone $subForum; $newSubForum->container_guid = $newGroupForum->getGUID(); $newSubForum->access_id = $newGroupForum->access_id; $newSubForum->last_action = time(); $newSubForum->save(); $subForums2 = elgg_get_entities(array('type' => 'object', 'subtype' => 'hjforum', 'order_by' => 'e.last_action asc', 'limit' => 150, 'full_view' => false, 'container_guid' => $subForum->guid)); $i3 = 0; foreach ($subForums2 as $subForum2) { $newSubForum2 = clone $subForum2; $newSubForum2->container_guid = $newSubForum->getGUID(); $newSubForum2->access_id = $newSubForum->access_id; $newSubForum2->save(); $time = time() + $i3; update_entity_last_action($newSubForum2->guid, $time); $i3++; } $time = time() + $i2; update_entity_last_action($newSubForum->guid, $time); $i2++; } $time = time() + $i1; update_entity_last_action($newGroupForum->guid, $time); $i1++; } } $newGroup->join($user); //get admins from old group and add them to the new one $oldAdmins = elgg_get_entities_from_relationship(array("relationship" => "group_admin", "relationship_guid" => $oldGroup->getGUID(), "inverse_relationship" => true)); foreach ($oldAdmins as $admin) { $newGroup->join($admin); add_entity_relationship($admin->getGUID(), "group_admin", $newGroup->getGUID()); } //get members from old group and add them to new group if specified by user if ($inheritMembers) { //get collection of old members $oldMembers = elgg_get_entities_from_relationship(array("relationship" => "member", "relationship_guid" => $oldGroup->getGUID(), "inverse_relationship" => true, 'limit' => 200)); foreach ($oldMembers as $oldMember) { $newGroup->join($oldMember); } } if ($inheritSubGroups) { $subGroups = elgg_get_entities_from_relationship(array("relationship" => "au_subgroup_of", "relationship_guid" => $guid, "inverse_relationship" => true, 'limit' => false)); foreach ($subGroups as $subGroup) { copyGroup($subGroup->guid, "Copy of " . $subGroup->name, $newGroup->guid, $groupOptions); } } if ($parentGroupGuid) { add_entity_relationship($newGroup->guid, 'au_subgroup_of', $parentGroupGuid); } add_to_river('river/group/create', 'create', $user->guid, $newGroup->guid, $newGroup->access_id); $newGroup->save(); return $newGroup->getURL(); }
} global $CONFIG; add_submenu_item(elgg_echo($label), $CONFIG->wwwroot . "pg/search/?tag=" . urlencode($tag) . "&subtype=" . $object_subtype . "&object=" . urlencode($object_type) . "&tagtype=" . urlencode($md_type) . "&owner_guid=" . urlencode($owner_guid)); } } } add_submenu_item(elgg_echo('all'), $CONFIG->wwwroot . "pg/search/?tag=" . urlencode($tag) . "&owner_guid=" . urlencode($owner_guid)); } if (empty($objecttype) && empty($subtype)) { $title = sprintf(elgg_echo('searchtitle'), $tag); } else { if (empty($objecttype)) { $objecttype = 'object'; } $itemtitle = 'item:' . $objecttype; if (!empty($subtype)) { $itemtitle .= ':' . $subtype; } $itemtitle = elgg_echo($itemtitle); $title = sprintf(elgg_echo('advancedsearchtitle'), $itemtitle, $tag); } if (!empty($tag)) { $body = ""; $body .= elgg_view_title($title); // elgg_view_title(sprintf(elgg_echo('searchtitle'),$tag)); $body .= trigger_plugin_hook('search', '', $tag, ""); $body .= elgg_view('search/startblurb', array('tag' => $tag)); $body .= list_entities_from_metadata($md_type, elgg_strtolower($tag), $objecttype, $subtype, $owner_guid_array, 10, false, false); $body = elgg_view_layout('two_column_left_sidebar', '', $body); } page_draw($title, $body);
$list_class = (array) elgg_extract('class', $vars, []); unset($vars['class']); $list_class[] = 'elgg-input-checkboxes'; $list_class[] = "elgg-{$vars['align']}"; $id = elgg_extract('id', $vars, ''); unset($vars['id']); if (is_array($vars['value'])) { $values = array_map('elgg_strtolower', $vars['value']); } else { $values = array(elgg_strtolower($vars['value'])); } $input_vars = $vars; $input_vars['default'] = false; if ($vars['name']) { $input_vars['name'] = "{$vars['name']}[]"; } unset($input_vars['align']); unset($input_vars['options']); // include a default value so if nothing is checked 0 will be passed. if ($vars['name'] && $vars['default'] !== false) { echo elgg_view('input/hidden', ['name' => $vars['name'], 'value' => $default]); } $checkboxes = ''; foreach ($vars['options'] as $label => $value) { $input_vars['checked'] = in_array(elgg_strtolower($value), $values); $input_vars['value'] = $value; $input_vars['label'] = $label; $input = elgg_view('input/checkbox', $input_vars); $checkboxes .= "<li>{$input}</li>"; } echo elgg_format_element('ul', ['class' => $list_class, 'id' => $id], $checkboxes);
/** * Return a string with highlighted matched queries and relevant context * Determins context based upon occurance and distance of words with each other. * * @param string $haystack * @param string $query * @param int $min_match_context = 30 * @param int $max_length = 300 * @return string */ function search_get_highlighted_relevant_substrings($haystack, $query, $min_match_context = 30, $max_length = 300) { global $CONFIG; $haystack = strip_tags($haystack); $haystack_length = elgg_strlen($haystack); $haystack_lc = elgg_strtolower($haystack); $words = search_remove_ignored_words($query, 'array'); // if haystack < $max_length return the entire haystack w/formatting immediately if ($haystack_length <= $max_length) { $return = search_highlight_words($words, $haystack); return $return; } // get the starting positions and lengths for all matching words $starts = array(); $lengths = array(); foreach ($words as $word) { $word = elgg_strtolower($word); $count = elgg_substr_count($haystack_lc, $word); $word_len = elgg_strlen($word); // find the start positions for the words if ($count > 1) { $offset = 0; while (FALSE !== ($pos = elgg_strpos($haystack_lc, $word, $offset))) { $start = $pos - $min_match_context > 0 ? $pos - $min_match_context : 0; $starts[] = $start; $stop = $pos + $word_len + $min_match_context; $lengths[] = $stop - $start; $offset += $pos + $word_len; } } else { $pos = elgg_strpos($haystack_lc, $word); $start = $pos - $min_match_context > 0 ? $pos - $min_match_context : 0; $starts[] = $start; $stop = $pos + $word_len + $min_match_context; $lengths[] = $stop - $start; } } $offsets = search_consolidate_substrings($starts, $lengths); // figure out if we can adjust the offsets and lengths // in order to return more context $total_length = array_sum($offsets); $add_length = 0; if ($total_length < $max_length) { $add_length = floor(($max_length - $total_length) / count($offsets) / 2); $starts = array(); $lengths = array(); foreach ($offsets as $offset => $length) { $start = $offset - $add_length > 0 ? $offset - $add_length : 0; $length = $length + $add_length; $starts[] = $start; $lengths[] = $length; } $offsets = search_consolidate_substrings($starts, $lengths); } // sort by order of string size descending (which is roughly // the proximity of matched terms) so we can keep the // substrings with terms closest together and discard // the others as needed to fit within $max_length. arsort($offsets); $return_strs = array(); $total_length = 0; foreach ($offsets as $start => $length) { $string = trim(elgg_substr($haystack, $start, $length)); // continue past if adding this substring exceeds max length if ($total_length + $length > $max_length) { continue; } $total_length += $length; $return_strs[$start] = $string; } // put the strings in order of occurence ksort($return_strs); // add ...s where needed $return = implode('...', $return_strs); if (!array_key_exists(0, $return_strs)) { $return = "...{$return}"; } // add to end of string if last substring doesn't hit the end. $starts = array_keys($return_strs); $last_pos = $starts[count($starts) - 1]; if ($last_pos + elgg_strlen($return_strs[$last_pos]) < $haystack_length) { $return .= '...'; } $return = search_highlight_words($words, $return); return $return; }
// TODO: ask the user for another group container instead $container = get_entity($container_guid); if (!$container) { $container_guid = elgg_get_logged_in_user_guid(); } // create new file object $file = new ElggFile(); $file->title = $title; $file->access_id = $access_id; $file->description = $description; $file->container_guid = $container_guid; $file->tags = $tags; $file->setMimeType("application/vnd.oasis.opendocument.text"); $file->simpletype = "document"; // same naming pattern as in file/actions/file/upload.php $filestorename = "file/" . elgg_strtolower(time() . $_FILES['upload']['name']); $file->setFilename($filestorename); // Open the file to guarantee the directory exists $file->open("write"); $file->close(); // now put file into destination move_uploaded_file($_FILES['upload']['tmp_name'], $file->getFilenameOnFilestore()); // create lock $lock_guid = odt_editor_locking_create_lock($file, $user_guid); $file->save(); // log success system_message(elgg_echo("file:saved")); add_to_river('river/object/file/create', 'create', $user_guid, $file->guid); // reply to client $reply = array("file_guid" => $file->guid, "document_url" => elgg_get_site_url() . "file/download/{$file->uid}", "file_name" => $file->getFilename(), "lock_guid" => $lock_guid); print json_encode($reply);
/** * Unzip an uploaded zip file * * @param array $file the $_FILES information * @param int $container_guid the container to put the files/folders under * @param int $parent_guid the parrent folder * * @return bool */ function file_tools_unzip($file, $container_guid, $parent_guid = 0) { $extracted = false; if (!empty($file) && !empty($container_guid)) { $allowed_extensions = file_tools_allowed_extensions(); $zipfile = elgg_extract("tmp_name", $file); $container_entity = get_entity($container_guid); $access_id = get_input("access_id", false); if ($access_id === false) { if (!empty($parent_guid) && ($parent_folder = get_entity($parent_guid)) && elgg_instanceof($parent_folder, "object", FILE_TOOLS_SUBTYPE)) { $access_id = $parent_folder->access_id; } else { if (elgg_instanceof($container_entity, "group")) { $access_id = $container_entity->group_acl; } else { $access_id = get_default_access($container_entity); } } } // open the zip file $zip = zip_open($zipfile); while ($zip_entry = zip_read($zip)) { // open the zip entry zip_entry_open($zip, $zip_entry); // set some variables $zip_entry_name = zip_entry_name($zip_entry); $filename = basename($zip_entry_name); // check for folder structure if (strlen($zip_entry_name) != strlen($filename)) { // there is a folder structure, check it and create missing items file_tools_create_folders($zip_entry, $container_guid, $parent_guid); } // extract the folder structure from the zip entry $folder_array = explode("/", $zip_entry_name); $parent = $parent_guid; foreach ($folder_array as $folder) { $folder = utf8_encode($folder); if ($entity = file_tools_check_foldertitle_exists($folder, $container_guid, $parent)) { $parent = $entity->getGUID(); } else { if ($folder == end($folder_array)) { $prefix = "file/"; $extension_array = explode('.', $folder); $file_extension = end($extension_array); if (in_array(strtolower($file_extension), $allowed_extensions)) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); // create the file $filehandler = new ElggFile(); $filehandler->setFilename($prefix . $folder); $filehandler->title = $folder; $filehandler->originalfilename = $folder; $filehandler->owner_guid = elgg_get_logged_in_user_guid(); $filehandler->container_guid = $container_guid; $filehandler->access_id = $access_id; $filehandler->open("write"); $filehandler->write($buf); $filehandler->close(); $mime_type = $filehandler->detectMimeType($filehandler->getFilenameOnFilestore()); // hack for Microsoft zipped formats $info = pathinfo($folder); $office_formats = array("docx", "xlsx", "pptx"); if ($mime_type == "application/zip" && in_array($info["extension"], $office_formats)) { switch ($info["extension"]) { case "docx": $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; case "xlsx": $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; case "pptx": $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; break; } } // check for bad ppt detection if ($mime_type == "application/vnd.ms-office" && $info["extension"] == "ppt") { $mime_type = "application/vnd.ms-powerpoint"; } $simple_type = file_get_simple_type($mime_type); $filehandler->setMimeType($mime_type); $filehandler->simpletype = $simple_type; if ($simple_type == "image") { $filestorename = elgg_strtolower(time() . $folder); $thumb = new ElggFile(); $thumb->owner_guid = elgg_get_logged_in_user_guid(); $thumbnail = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 60, 60, true); if ($thumbnail) { $thumb->setFilename($prefix . "thumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); $filehandler->thumbnail = $prefix . "thumb" . $filestorename; unset($thumbnail); } $thumbsmall = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 153, 153, true); if ($thumbsmall) { $thumb->setFilename($prefix . "smallthumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbsmall); $thumb->close(); $filehandler->smallthumb = $prefix . "smallthumb" . $filestorename; unset($thumbsmall); } $thumblarge = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 600, 600, false); if ($thumblarge) { $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->open("write"); $thumb->write($thumblarge); $thumb->close(); $filehandler->largethumb = $prefix . "largethumb" . $filestorename; unset($thumblarge); } unset($thumb); } set_input('folder_guid', $parent); $filehandler->save(); $extracted = true; if (!empty($parent)) { add_entity_relationship($parent, FILE_TOOLS_RELATIONSHIP, $filehandler->getGUID()); } } } } } zip_entry_close($zip_entry); } zip_close($zip); } return $extracted; }
/** * Writes contents of the uploaded file to an instance of ElggFile * * @note Note that this function moves the file and populates properties, * but does not call ElggFile::save(). * * @note This method will automatically assign a filename on filestore based * on the upload time and filename. By default, the file will be written * to /file directory on owner's filestore. You can change this directory, * by setting 'filestore_prefix' property of the ElggFile instance before * calling this method. * * @param UploadedFile $upload Uploaded file object * @return bool */ public function acceptUploadedFile(UploadedFile $upload) { if (!$upload->isValid()) { return false; } $old_filestorename = ''; if ($this->exists()) { $old_filestorename = $this->getFilenameOnFilestore(); } $originalfilename = $upload->getClientOriginalName(); $this->originalfilename = $originalfilename; if (empty($this->title)) { $this->title = htmlspecialchars($this->originalfilename, ENT_QUOTES, 'UTF-8'); } $this->upload_time = time(); $prefix = $this->filestore_prefix ?: 'file'; $prefix = trim($prefix, '/'); $filename = elgg_strtolower("{$prefix}/{$this->upload_time}{$this->originalfilename}"); $this->setFilename($filename); $this->filestore_prefix = $prefix; $hook_params = ['file' => $this, 'upload' => $upload]; $uploaded = _elgg_services()->hooks->trigger('upload', 'file', $hook_params); if ($uploaded !== true && $uploaded !== false) { $filestorename = $this->getFilenameOnFilestore(); try { $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME)); } catch (FileException $ex) { _elgg_services()->logger->error($ex->getMessage()); $uploaded = false; } } if ($uploaded) { if ($old_filestorename && $old_filestorename != $this->getFilenameOnFilestore()) { // remove old file unlink($old_filestorename); } $mime_type = $this->detectMimeType(null, $upload->getClientMimeType()); $this->setMimeType($mime_type); $this->simpletype = elgg_get_file_simple_type($mime_type); _elgg_services()->events->triggerAfter('upload', 'file', $this); return true; } return false; }
/** * Send a message to specified recipients * * @param int $sender_guid GUID of the sender entity * @param array $recipient_guids An array of recipient GUIDs * @param str $subject Subject of the message * @param str $message Body of the message * @param str $message_type Type of the message * @param array $params Additional parameters, e.g. 'message_hash', 'attachments' * @return boolean */ function hj_inbox_send_message($sender_guid, $recipient_guids, $subject = '', $message = '', $message_type = '', array $params = array()) { $ia = elgg_set_ignore_access(); if (!is_array($recipient_guids)) { $recipient_guids = array($recipient_guids); } if (isset($params['message_hash'])) { $message_hash = elgg_extract('message_hash', $params); } if (isset($params['attachments'])) { $attachments = elgg_extract('attachments', $params); } $user_guids = $recipient_guids; $user_guids[] = $sender_guid; sort($user_guids); if (!$message_hash) { $title = strtolower($subject); $title = trim(str_replace('re:', '', $title)); $message_hash = sha1(implode(':', $user_guids) . $title); } $acl_hash = sha1(implode(':', $user_guids)); $dbprefix = elgg_get_config('dbprefix'); $query = "SELECT * FROM {$dbprefix}access_collections WHERE name = '{$acl_hash}'"; $collection = get_data_row($query); //error_log(print_r($collection, true)); $acl_id = $collection->id; if (!$acl_id) { $site = elgg_get_site_entity(); $acl_id = create_access_collection($acl_hash, $site->guid); update_access_collection($acl_id, $user_guids); } //error_log($acl_id); $message_sent = new ElggObject(); $message_sent->subtype = "messages"; $message_sent->owner_guid = $sender_guid; $message_sent->container_guid = $sender_guid; $message_sent->access_id = ACCESS_PRIVATE; $message_sent->title = $subject; $message_sent->description = $message; $message_sent->toId = $recipient_guids; // the users receiving the message $message_sent->fromId = $sender_guid; // the user sending the message $message_sent->readYet = 1; // this is a toggle between 0 / 1 (1 = read) $message_sent->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag $message_sent->hiddenTo = 0; // this is used when a user deletes a message in their inbox $message_sent->msg = 1; $message_sent->msgType = $message_type; $message_sent->msgHash = $message_hash; $message_sent->save(); if ($attachments) { $count = count($attachments['name']); for ($i = 0; $i < $count; $i++) { if ($attachments['error'][$i] || !$attachments['name'][$i]) { continue; } $name = $attachments['name'][$i]; $file = new ElggFile(); $file->container_guid = $message_sent->guid; $file->title = $name; $file->access_id = (int) $acl_id; $prefix = "file/"; $filestorename = elgg_strtolower(time() . $name); $file->setFilename($prefix . $filestorename); $file->open("write"); $file->close(); move_uploaded_file($attachments['tmp_name'][$i], $file->getFilenameOnFilestore()); $saved = $file->save(); if ($saved) { $mime_type = ElggFile::detectMimeType($attachments['tmp_name'][$i], $attachments['type'][$i]); $info = pathinfo($name); $office_formats = array('docx', 'xlsx', 'pptx'); if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) { switch ($info['extension']) { case 'docx': $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; case 'xlsx': $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; case 'pptx': $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; break; } } // check for bad ppt detection if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") { $mime_type = "application/vnd.ms-powerpoint"; } $file->msgHash = $message_hash; $file->toId = $recipient_guids; $file->fromId = $sender_guid; $file->setMimeType($mime_type); $file->originalfilename = $name; if (elgg_is_active_plugin('file')) { $file->simpletype = file_get_simple_type($mime_type); } $file->save(); $guid = $file->getGUID(); $uploaded_attachments[] = $guid; $attachment_urls .= '<div class="inbox-attachment">' . elgg_view('output/url', array('href' => "messages/download/{$guid}", 'text' => $file->title, 'is_trusted' => true)) . '</div>'; if ($file->simpletype == "image") { $file->icontime = time(); $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true); if ($thumbnail) { $thumb = new ElggFile(); $thumb->setMimeType($attachments['type'][$i]); $thumb->setFilename($prefix . "thumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); $file->thumbnail = $prefix . "thumb" . $filestorename; unset($thumbnail); } $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true); if ($thumbsmall) { $thumb->setFilename($prefix . "smallthumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbsmall); $thumb->close(); $file->smallthumb = $prefix . "smallthumb" . $filestorename; unset($thumbsmall); } $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false); if ($thumblarge) { $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->open("write"); $thumb->write($thumblarge); $thumb->close(); $file->largethumb = $prefix . "largethumb" . $filestorename; unset($thumblarge); } } } } } $success = $error = 0; foreach ($recipient_guids as $recipient_guid) { $message_to = new ElggObject(); $message_to->subtype = "messages"; $message_to->owner_guid = $recipient_guid; $message_to->container_guid = $recipient_guid; $message_to->access_id = ACCESS_PRIVATE; $message_to->title = $subject; $message_to->description = $message; $message_to->toId = $recipient_guids; // the users receiving the message $message_to->fromId = $sender_guid; // the user sending the message $message_to->readYet = 0; // this is a toggle between 0 / 1 (1 = read) $message_to->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag $message_to->hiddenTo = 0; // this is used when a user deletes a message in their inbox $message_to->msg = 1; $message_to->msgType = $message_type; $message_to->msgHash = $message_hash; if ($message_to->save()) { $success++; // Make attachments if ($uploaded_attachments) { foreach ($uploaded_attachments as $attachment_guid) { make_attachment($message_to->guid, $attachment_guid); } } // Send out notifications skipping 'site' notification handler if ($recipient_guid != $sender_guid) { $methods = (array) get_user_notification_settings($recipient_guid); unset($methods['site']); if (count($methods)) { $recipient = get_user($recipient_guid); $sender = get_user($sender_guid); $notification_subject = elgg_echo('messages:email:subject'); $notification_message = strip_tags($message); if ($uploaded_attachments) { $notification_message .= elgg_view_module('inbox-attachments', elgg_echo('messages:attachments'), $attachment_urls); } $notification_body = elgg_echo('messages:email:body', array($sender->name, $notification_message, elgg_get_site_url() . "messages/inbox/{$recipient->username}?message_type={$message_type}", $sender->name, elgg_get_site_url() . "messages/thread/{$message_hash}")); notify_user($recipient_guid, $sender_guid, $notification_subject, $notification_body, null, $methods); } } } else { $error++; } } if ($success > 0) { // Make attachments if ($uploaded_attachments) { foreach ($uploaded_attachments as $attachment_guid) { make_attachment($message_sent->guid, $attachment_guid); } } $return = true; } else { $message_sent->delete(); $return = false; } elgg_set_ignore_access($ia); return $return; }
*/ $additional_class = elgg_extract('class', $vars); $align = elgg_extract('align', $vars, 'vertical'); $class = "elgg-input-radio elgg-{$align}"; if ($additional_class) { $class = " {$additional_class}"; unset($vars['class']); } if (isset($vars['align'])) { unset($vars['align']); } $options = $vars['options']; unset($vars['options']); $value = $vars['value']; unset($vars['value']); if ($options && count($options) > 0) { echo "<ul class=\"{$class}\">"; foreach ($options as $label => $option) { $vars['checked'] = elgg_strtolower($option) == elgg_strtolower($value); $vars['value'] = $option; $attributes = elgg_format_attributes($vars); // handle indexed array where label is not specified // @deprecated 1.8 Remove in 1.9 if (is_integer($label)) { elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/radio', 1.8); $label = $option; } echo "<li><label><input type=\"radio\" {$attributes} />{$label}</label></li>"; } echo '</ul>'; }
/** * Save uploaded files * * @param string $input_name Form input name * @param array $attributes File attributes * @return ElggFile[] */ protected function saveUploadedFiles($input_name, array $attributes = []) { $files = []; $uploaded_files = $this->getUploadedFiles($input_name); $subtype = elgg_extract('subtype', $attributes, 'file', false); unset($attributes['subtype']); $class = get_subtype_class('object', $subtype); if (!$class || !class_exists($class) || !is_subclass_of($class, ElggFile::class)) { $class = ElggFile::class; } foreach ($uploaded_files as $upload) { if (!$upload->isValid()) { $error = new \stdClass(); $error->error = elgg_get_friendly_upload_error($upload->getError()); $files[] = $error; continue; } $file = new $class(); $file->subtype = $subtype; foreach ($attributes as $key => $value) { $file->{$key} = $value; } $old_filestorename = ''; if ($file->exists()) { $old_filestorename = $file->getFilenameOnFilestore(); } $originalfilename = $upload->getClientOriginalName(); $file->originalfilename = $originalfilename; if (empty($file->title)) { $file->title = htmlspecialchars($file->originalfilename, ENT_QUOTES, 'UTF-8'); } $file->upload_time = time(); $prefix = $file->filestore_prefix ?: 'file'; $prefix = trim($prefix, '/'); $filename = elgg_strtolower("{$prefix}/{$file->upload_time}{$file->originalfilename}"); $file->setFilename($filename); $file->filestore_prefix = $prefix; $hook_params = ['file' => $file, 'upload' => $upload]; $uploaded = _elgg_services()->hooks->trigger('upload', 'file', $hook_params); if ($uploaded !== true && $uploaded !== false) { $filestorename = $file->getFilenameOnFilestore(); try { $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME)); } catch (FileException $ex) { elgg_log($ex->getMessage(), 'ERROR'); $uploaded = false; } } if (!$uploaded) { $error = new \stdClass(); $error->error = elgg_echo('dropzone:file_not_entity'); $files[] = $error; continue; } if ($old_filestorename && $old_filestorename != $file->getFilenameOnFilestore()) { // remove old file unlink($old_filestorename); } $mime_type = $file->detectMimeType(null, $upload->getClientMimeType()); $file->setMimeType($mime_type); $file->simpletype = elgg_get_file_simple_type($mime_type); _elgg_services()->events->triggerAfter('upload', 'file', $file); if (!$file->save() || !$file->exists()) { $file->delete(); $error = new \stdClass(); $error->error = elgg_echo('dropzone:file_not_entity'); $files[] = $error; continue; } if ($file->saveIconFromElggFile($file)) { $file->thumbnail = $file->getIcon('small')->getFilename(); $file->smallthumb = $file->getIcon('medium')->getFilename(); $file->largethumb = $file->getIcon('large')->getFilename(); } $success = new \stdClass(); $success->file = $file; $files[] = $success; } return $files; }
function hj_framework_handle_multifile_upload($user_guid) { if (!empty($_FILES)) { $access = elgg_get_ignore_access(); elgg_set_ignore_access(true); $file = $_FILES['Filedata']; $filehandler = new hjFile(); $filehandler->owner_guid = (int) $user_guid; $filehandler->container_guid = (int) $user_guid; $filehandler->access_id = ACCESS_DEFAULT; $filehandler->data_pattern = hj_framework_get_data_pattern('object', 'hjfile'); $filehandler->title = $file['name']; $filehandler->description = ''; $prefix = "hjfile/"; $filestorename = elgg_strtolower($file['name']); $mime = hj_framework_get_mime_type($file['name']); $filehandler->setFilename($prefix . $filestorename); $filehandler->setMimeType($mime); $filehandler->originalfilename = $file['name']; $filehandler->simpletype = hj_framework_get_simple_type($mime); $filehandler->filesize = round($file['size'] / (1024 * 1024), 2) . "Mb"; $filehandler->open("write"); $filehandler->close(); move_uploaded_file($file['tmp_name'], $filehandler->getFilenameOnFilestore()); $file_guid = $filehandler->save(); hj_framework_set_entity_priority($filehandler); elgg_trigger_plugin_hook('hj:framework:file:process', 'object', array('entity' => $filehandler)); if ($file_guid) { $meta_value = $filehandler->getGUID(); } else { $meta_value = $filehandler->getFilenameOnFilestore(); } if ($file_guid && $filehandler->simpletype == "image") { $thumb_sizes = hj_framework_get_thumb_sizes(); foreach ($thumb_sizes as $thumb_type => $thumb_size) { $thumbnail = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $thumb_size['w'], $thumb_size['h'], $thumb_size['square'], 0, 0, 0, 0, true); if ($thumbnail) { $thumb = new ElggFile(); $thumb->setMimeType($file['type']); $thumb->owner_guid = $user_guid; $thumb->setFilename("{$prefix}{$filehandler->getGUID()}{$thumb_type}.jpg"); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); $thumb_meta = "{$thumb_type}thumb"; $filehandler->{$thumb_meta} = $thumb->getFilename(); unset($thumbnail); } } } $response = array('status' => 'OK', 'value' => $meta_value); } else { $response = array('status' => 'FAIL'); } echo json_encode($response); elgg_set_ignore_access($access); return; }
if ($mem_required > $mem_avail) { array_push($not_uploaded, $sent_file['name']); array_push($error_msgs, elgg_echo('tidypics:image_pixels')); trigger_error('Tidypics warning: image memory size too large for resizing so rejecting', E_USER_WARNING); continue; } } else if ($image_lib == 'ImageMagickPHP') { // haven't been able to determine a limit like there is for GD } */ $mime = "image/jpeg"; //not sure how to get this from the file if we aren't posting it //this will save to users folder in /image/ and organize by photo album $prefix = "image/" . $container_guid . "/"; $file = new ElggFile(); $filestorename = elgg_strtolower(time() . $name); $file->setFilename($prefix . $filestorename . ".jpg"); //that's all flickr stores so I think this is safe $file->setMimeType($mime); $file->originalfilename = $name; $file->subtype = "image"; $file->simpletype = "image"; $file->access_id = $access_id; if ($container_guid) { $file->container_guid = $container_guid; } // get the file from flickr and save it locally $filename = $file->getFilenameOnFilestore(); $destination = fopen($filename, "w"); $source = fopen($photo["url"], "r"); while ($a = fread($source, 1024)) {
/** * Create new entities from file uploads * * @param string $input Name of the file input * @return void */ protected static function entityFactory($input) { if (!isset(self::$config['filestore_prefix'])) { $prefix = "file/"; } $uploads = self::$uploads[$input]; $handled_uploads = array(); $entities = array(); foreach ($uploads as $key => $upload) { if ($upload->error) { $handled_uploads[] = $upload; continue; } $filehandler = new ElggFile(); if (is_array(self::$attributes)) { foreach (self::$attributes as $key => $value) { $filehandler->{$key} = $value; } } $filestorename = elgg_strtolower(time() . $upload->name); $filehandler->setFilename($prefix . $filestorename); $filehandler->title = $upload->name; $filehandler->originalfilename = $upload->name; $filehandler->filesize = $upload->size; $filehandler->mimetype = $upload->mimetype; $filehandler->simpletype = $upload->simpletype; $filehandler->open("write"); $filehandler->close(); move_uploaded_file($upload->path, $filehandler->getFilenameOnFilestore()); if ($filehandler->save()) { $upload->guid = $filehandler->getGUID(); $upload->file = $filehandler; if ($filehandler->simpletype == "image") { IconHandler::makeIcons($filehandler); } $entities[] = $filehandler; } else { $upload->error = elgg_echo('upload:error:unknown'); } $handled_uploads[] = $upload; } self::$uploads[$input] = $handled_uploads; self::$files[$input] = $entities; }
/** * Process uploaded files * * @param string $name Name of the HTML file input * @param string $subtype Object subtype to be assigned to newly created objects * @param type $guid GUID of an existing object * @param type $container_guid GUID of the container entity * @return array An associative array of original file names and guids (or false) of created object */ function process_file_upload($name, $subtype = hjAlbumImage::SUBTYPE, $guid = null, $container_guid = null) { // Normalize the $_FILES array if (is_array($_FILES[$name]['name'])) { $files = prepare_files_global($_FILES); $files = $files[$name]; } else { $files = $_FILES[$name]; $files = array($files); } foreach ($files as $file) { if (!is_array($file) || $file['error']) { continue; } $filehandler = new ElggFile($guid); $prefix = 'hjfile/'; if ($guid) { $filename = $filehandler->getFilenameOnFilestore(); if (file_exists($filename)) { unlink($filename); } $filestorename = $filehandler->getFilename(); $filestorename = elgg_substr($filestorename, elgg_strlen($prefix)); } else { $filehandler->subtype = $subtype; $filehandler->container_guid = $container_guid; $filestorename = elgg_strtolower(time() . $file['name']); } $filehandler->setFilename($prefix . $filestorename); $filehandler->title = $file['name']; $mime_type = ElggFile::detectMimeType($file['tmp_name'], $file['type']); // hack for Microsoft zipped formats $info = pathinfo($file['name']); $office_formats = array('docx', 'xlsx', 'pptx'); if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) { switch ($info['extension']) { case 'docx': $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; case 'xlsx': $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; case 'pptx': $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; break; } } // check for bad ppt detection if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") { $mime_type = "application/vnd.ms-powerpoint"; } $filehandler->setMimeType($mime_type); $filehandler->originalfilename = $file['name']; $filehandler->simpletype = get_simple_type($mime_type); $filehandler->filesize = $file['size']; $filehandler->open("write"); $filehandler->close(); move_uploaded_file($file['tmp_name'], $filehandler->getFilenameOnFilestore()); if ($filehandler->save()) { // Generate icons for images if ($filehandler->simpletype == "image") { generate_entity_icons($filehandler); // the settings tell us not to keep the original image file, so downsizing to master if (elgg_get_plugin_setting('remove_original_files', 'hypeGallery')) { $icon_sizes = elgg_get_config('icon_sizes'); $values = $icon_sizes['master']; $master = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $values['w'], $values['h'], $values['square'], 0, 0, 0, 0, $values['upscale']); $filehandler->open('write'); $filehandler->write($master); $filehandler->close(); } } $return[$file['name']] = $filehandler->getGUID(); } else { $return[$file['name']] = false; } } return $return; }
/** * Unzip an uploaded zip file * * @param array $file the $_FILES information * @param int $container_guid the container to put the files/folders under * @param int $parent_guid the parrent folder * * @return bool */ function file_tools_unzip($file, $container_guid, $parent_guid = 0) { $container_guid = (int) $container_guid; $parent_guid = (int) $parent_guid; if (empty($file) || empty($container_guid)) { return false; } $container_entity = get_entity($container_guid); if (empty($container_entity)) { return false; } $extracted = false; $allowed_extensions = file_tools_allowed_extensions(); $zipfile = elgg_extract('tmp_name', $file); $access_id = get_input('access_id', false); if ($access_id === false) { $parent_folder = get_entity($parent_guid); if (elgg_instanceof($parent_folder, 'object', FILE_TOOLS_SUBTYPE)) { $access_id = $parent_folder->access_id; } else { if ($container_entity instanceof ElggGroup) { $access_id = $container_entity->group_acl; } else { $access_id = get_default_access($container_entity); } } } // open the zip file $zip = zip_open($zipfile); while ($zip_entry = zip_read($zip)) { // open the zip entry zip_entry_open($zip, $zip_entry); // set some variables $zip_entry_name = zip_entry_name($zip_entry); $filename = basename($zip_entry_name); // check for folder structure if (strlen($zip_entry_name) != strlen($filename)) { // there is a folder structure, check it and create missing items file_tools_create_folders($zip_entry, $container_guid, $parent_guid); } // extract the folder structure from the zip entry $folder_array = explode('/', $zip_entry_name); $parent = $parent_guid; foreach ($folder_array as $folder) { $folder = utf8_encode($folder); $entity = file_tools_check_foldertitle_exists($folder, $container_guid, $parent); if (!empty($entity)) { $parent = $entity->getGUID(); } else { if ($folder !== end($folder_array)) { continue; } $prefix = 'file/'; $extension_array = explode('.', $folder); $file_extension = end($extension_array); if (!in_array(strtolower($file_extension), $allowed_extensions)) { continue; } $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); $filestorename = elgg_strtolower(time() . $folder); // create the file $filehandler = new ElggFile(); $filehandler->setFilename($prefix . $filestorename); $filehandler->title = $folder; $filehandler->originalfilename = $folder; $filehandler->owner_guid = elgg_get_logged_in_user_guid(); $filehandler->container_guid = $container_guid; $filehandler->access_id = $access_id; if (!$filehandler->save()) { continue; } $filehandler->open('write'); $filehandler->write($buf); $filehandler->close(); $mime_type = $filehandler->detectMimeType($filehandler->getFilenameOnFilestore()); // hack for Microsoft zipped formats $info = pathinfo($folder); $office_formats = ['docx', 'xlsx', 'pptx']; if ($mime_type == 'application/zip' && in_array($info['extension'], $office_formats)) { switch ($info['extension']) { case 'docx': $mime_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; break; case 'xlsx': $mime_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; break; case 'pptx': $mime_type = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; break; } } // check for bad ppt detection if ($mime_type == 'application/vnd.ms-office' && $info['extension'] == 'ppt') { $mime_type = 'application/vnd.ms-powerpoint'; } $simple_type = file_get_simple_type($mime_type); $filehandler->setMimeType($mime_type); $filehandler->simpletype = $simple_type; if ($simple_type == 'image') { if ($filehandler->saveIconFromElggFile($filehandler)) { $filehandler->thumbnail = $filehandler->getIcon('small')->getFilename(); $filehandler->smallthumb = $filehandler->getIcon('medium')->getFilename(); $filehandler->largethumb = $filehandler->getIcon('large')->getFilename(); } } set_input('folder_guid', $parent); $filehandler->save(); $extracted = true; if (!empty($parent)) { add_entity_relationship($parent, FILE_TOOLS_RELATIONSHIP, $filehandler->getGUID()); } } } zip_entry_close($zip_entry); } zip_close($zip); return $extracted; }
function file_tools_unzip($file, $container_guid, $parent_guid = 0) { $extracted = false; if (!empty($file) && !empty($container_guid)) { $allowed_extensions = file_tools_allowed_extensions(); $zipfile = elgg_extract("tmp_name", $file); $container_entity = get_entity($container_guid); $access_id = get_input("access_id", false); if ($access_id === false) { if (!empty($parent_guid) && ($parent_folder = get_entity($parent_guid)) && elgg_instanceof($parent_folder, "object", FILE_TOOLS_SUBTYPE)) { $access_id = $parent_folder->access_id; } else { if (elgg_instanceof($container_entity, "group")) { $access_id = $container_entity->group_acl; } else { $access_id = get_default_access($container_entity); } } } // open the zip file $zip = zip_open($zipfile); while ($zip_entry = zip_read($zip)) { // open the zip entry zip_entry_open($zip, $zip_entry); // set some variables $zip_entry_name = zip_entry_name($zip_entry); $filename = basename($zip_entry_name); // check for folder structure if (strlen($zip_entry_name) != strlen($filename)) { // there is a folder structure, check it and create missing items file_tools_create_folders($zip_entry, $container_guid, $parent_guid); } // extract the folder structure from the zip entry $folder_array = explode("/", $zip_entry_name); $parent = $parent_guid; foreach ($folder_array as $folder) { $folder = sanitize_string(utf8_encode($folder)); if ($entity = file_tools_check_foldertitle_exists($folder, $container_guid, $parent)) { $parent = $entity->getGUID(); } else { if ($folder == end($folder_array)) { $prefix = "file/"; $extension_array = explode('.', $folder); $file_extension = end($extension_array); $file_size = zip_entry_filesize($zip_entry); if (in_array(strtolower($file_extension), $allowed_extensions)) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); // create the file $filehandler = new ElggFile(); $filehandler->setFilename($prefix . $folder); $filehandler->title = $folder; $filehandler->originalfilename = $folder; $filehandler->owner_guid = elgg_get_logged_in_user_guid(); $filehandler->container_guid = $container_guid; $filehandler->access_id = $access_id; $filehandler->open("write"); $filehandler->write($buf); $filehandler->close(); $mime_type = mime_content_type($filehandler->getFilenameOnFilestore()); $simple_type = explode("/", $mime_type); $filehandler->setMimeType($mime_type); $filehandler->simpletype = $simple_type[0]; if ($simple_type[0] == "image") { $filestorename = elgg_strtolower(time() . $folder); $thumbnail = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 60, 60, true); if ($thumbnail) { $thumb = new ElggFile(); $thumb->setMimeType($mime_type); $thumb->setFilename($prefix . "thumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); $filehandler->thumbnail = $prefix . "thumb" . $filestorename; unset($thumbnail); } $thumbsmall = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 153, 153, true); if ($thumbsmall) { $thumb->setFilename($prefix . "smallthumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbsmall); $thumb->close(); $filehandler->smallthumb = $prefix . "smallthumb" . $filestorename; unset($thumbsmall); } $thumblarge = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 600, 600, false); if ($thumblarge) { $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->open("write"); $thumb->write($thumblarge); $thumb->close(); $filehandler->largethumb = $prefix . "largethumb" . $filestorename; unset($thumblarge); } } set_input('folder_guid', $parent); $filehandler->save(); $extracted = true; if (!empty($parent)) { add_entity_relationship($parent, FILE_TOOLS_RELATIONSHIP, $filehandler->getGUID()); } } } } } zip_entry_close($zip_entry); } zip_close($zip); } return $extracted; }
/** * * upload attachments for a project * @param ElggEntity * */ function projects_upload_attachments($attachments, $project) { $count = count($attachments['name']); for ($i = 0; $i < $count; $i++) { if ($attachments['error'][$i] || !$attachments['name'][$i]) { continue; } $name = $attachments['name'][$i]; $file = new ElggFile(); $file->container_guid = $project->guid; $file->title = $name; $file->access_id = (int) $project->access_id; $prefix = "file/"; $filestorename = elgg_strtolower(time() . $name); $file->setFilename($prefix . $filestorename); $file->open("write"); $file->close(); move_uploaded_file($attachments['tmp_name'][$i], $file->getFilenameOnFilestore()); $saved = $file->save(); if ($saved) { $mime_type = ElggFile::detectMimeType($attachments['tmp_name'][$i], $attachments['type'][$i]); $info = pathinfo($name); $office_formats = array('docx', 'xlsx', 'pptx'); if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) { switch ($info['extension']) { case 'docx': $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; case 'xlsx': $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; case 'pptx': $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; break; } } // check for bad ppt detection if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") { $mime_type = "application/vnd.ms-powerpoint"; } //add_metastring("projectId"); //$file->projectId = $project_guid; $file->setMimeType($mime_type); $file->originalfilename = $name; if (elgg_is_active_plugin('file')) { $file->simpletype = file_get_simple_type($mime_type); } $saved = $file->save(); if ($saved) { $file->addRelationship($project->guid, 'attachment'); } } } }
/** * Get the URL for this entity's icon * * Plugins can register for the 'entity:icon:url', <type> plugin hook * to customize the icon for an entity. * * @param mixed $params A string defining the size of the icon (e.g. tiny, small, medium, large) * or an array of parameters including 'size' * @return string The URL * @since 1.8.0 */ public function getIconURL($params = array()) { if (is_array($params)) { $size = elgg_extract('size', $params, 'medium'); } else { $size = is_string($params) ? $params : 'medium'; $params = array(); } $size = elgg_strtolower($size); if (isset($this->icon_override[$size])) { elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8); return $this->icon_override[$size]; } $params['entity'] = $this; $params['size'] = $size; $type = $this->getType(); $url = _elgg_services()->hooks->trigger('entity:icon:url', $type, $params, null); if ($url == null) { $url = "_graphics/icons/default/{$size}.png"; } return elgg_normalize_url($url); }
/** * Set the internal filenames */ protected function setOriginalFilename($originalName) { $prefix = "image/" . $this->container_guid . "/"; $filestorename = elgg_strtolower(time() . $originalName); $this->setFilename($prefix . $filestorename); $this->originalfilename = $originalName; }
} else { if ($_FILES["upload"]["error"] !== 0) { register_error(elgg_echo("file:uploadfailed")); continue; } // if no title on new upload, grab filename if (empty($title)) { $title = htmlspecialchars($_FILES["upload"]["name"], ENT_QUOTES, "UTF-8"); } $file = new FilePluginFile(); $file->subtype = "file"; $file->access_id = $access_id; $file->container_guid = $container_guid; $file->title = $title; $file->originalfilename = $_FILES["upload"]["name"]; $filestorename = elgg_strtolower(time() . $_FILES["upload"]["name"]); $file->setFilename($prefix . $filestorename); $mime_type = file_tools_get_mimetype($_FILES["upload"]["tmp_name"], $_FILES["upload"]["type"]); $file->setMimeType($mime_type); $file->simpletype = file_get_simple_type($mime_type); $guid = $file->save(); // Open the file to guarantee the directory exists $file->open("write"); $file->close(); move_uploaded_file($_FILES["upload"]["tmp_name"], $file->getFilenameOnFilestore()); if ($guid && $file->simpletype == "image") { file_tools_generate_thumbs($file); $file->icontime = time(); $file->save(); } add_to_river('river/object/file/create', 'create', elgg_get_logged_in_user_guid(), $file->guid);
/** * Get the URL for this entity's icon * * Plugins can register for the 'entity:icon:url', <type> plugin hook * to customize the icon for an entity. * * @param string $size Size of the icon: tiny, small, medium, large * * @return string The URL * @since 1.8.0 */ public function getIconURL($size = 'medium') { $size = elgg_strtolower($size); if (isset($this->icon_override[$size])) { elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8); return $this->icon_override[$size]; } $url = "_graphics/icons/default/{$size}.png"; $url = elgg_normalize_url($url); $type = $this->getType(); $params = array('entity' => $this, 'size' => $size); $url = elgg_trigger_plugin_hook('entity:icon:url', $type, $params, $url); return elgg_normalize_url($url); }
// and to get access to guid if adding a new video $video->save(); // we have a video upload, so process it if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { $prefix = "video/{$video->getGUID()}/"; // if previous video, delete it if ($new_video == false) { $videoname = $video->getFilenameOnFilestore(); if (file_exists($videoname)) { unlink($videoname); } // use same videoname on the disk - ensures thumbnails are overwritten $videostorename = $video->getFilename(); $videostorename = elgg_substr($videostorename, elgg_strlen($prefix)); } else { $videostorename = elgg_strtolower($_FILES['upload']['name']); } $video->setFilename($prefix . $videostorename); $mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']); $video->setMimeType($mime_type); $video->originalvideoname = $_FILES['upload']['name']; $video->simpletype = 'video'; // Open the video to guarantee the directory exists $video->open("write"); $video->close(); move_uploaded_file($_FILES['upload']['tmp_name'], $video->getFilenameOnFilestore()); // Change the directory mode chmod($video->getFileDirectory(), 0775); $guid = $video->save(); } // video saved so clear sticky form
/** * Get the URL for this entity's icon * * Plugins can register for the 'entity:icon:url', <type> plugin hook * to customize the icon for an entity. * * @param mixed $params A string defining the size of the icon (e.g. tiny, small, medium, large) * or an array of parameters including 'size' * @return string The URL * @since 1.8.0 */ public function getIconURL($params = array()) { if (is_array($params)) { $size = elgg_extract('size', $params, 'medium'); } else { $size = is_string($params) ? $params : 'medium'; $params = array(); } $size = elgg_strtolower($size); $params['entity'] = $this; $params['size'] = $size; $type = $this->getType(); $url = _elgg_services()->hooks->trigger('entity:icon:url', $type, $params, null); if ($url == null) { $url = elgg_get_simplecache_url("icons/default/{$size}.png"); } return elgg_normalize_url($url); }
/** * Write a file resource into a file object * If no $file is provided, a new object of subtype 'file' will be created * * @param string $path Full path to file * @param ElggFile $file Optional file object to write to * @return ElggFile|false */ public function createFromResource($path, ElggFile $file = null) { $contents = @file_get_contents($path); if (empty($contents)) { return; } if (!isset($file)) { $file = new ElggFile(); $file->subtype = 'file'; $file->owner_guid = elgg_get_logged_in_user_guid(); } if (!$file instanceof ElggFile || !$file->owner_guid) { // files need an owner to load a filestore return false; } if ($file->guid && $file->exists()) { // remove file written to the filestore previously unlink($file->getFilenameOnFilestore()); } if (filter_var($path, FILTER_VALIDATE_URL)) { $path = parse_url($path, PHP_URL_PATH); } $originalfilename = pathinfo($path, PATHINFO_BASENAME); $basename = elgg_strtolower(time() . $originalfilename); $directory = $this->getDirectory($file); $filename = $this->getFilename($file, $basename); $file->setFilename("{$directory}/{$filename}"); $file->open('write'); $file->write($contents); $file->close(); $file->mimetype = $file->detectMimeType(); $file->simpletype = 'image'; $file->originalfilename = $originalfilename; if (!isset($file->title)) { $file->title = $file->originalfilename; } if (!$this->isImage($file) || !$file->exists() || !$file->save()) { // written file is not an image or write failed $file->delete(); return false; } return $file; }
/** * When given a title, returns a version suitable for inclusion in a URL * * @param string $title The title * * @return string The optimised title * @since 1.7.2 */ function elgg_get_friendly_title($title) { // return a URL friendly title to short circuit normal title formatting $params = array('title' => $title); $result = elgg_trigger_plugin_hook('format', 'friendly:title', $params, NULL); if ($result) { return $result; } // @todo not using this because of locale concerns //$title = iconv('UTF-8', 'ASCII//TRANSLIT', $title); // @todo this uses a utf8 character class. can use if // we want to support utf8 in the url. //$title = preg_replace('/[^\p{L}\- ]/u', '', $title); // use A-Za-z0-9_ instead of \w because \w is locale sensitive $title = preg_replace("/[^A-Za-z0-9_\\- ]/", "", $title); $title = str_replace(" ", "-", $title); $title = str_replace("--", "-", $title); $title = trim($title); $title = elgg_strtolower($title); return $title; }
} $id = elgg_extract('id', $vars, ''); unset($vars['id']); $list_class = (array) elgg_extract('class', $vars, []); $list_class[] = 'elgg-input-radios '; $list_class[] = 'list-unstyled'; $list_class[] = "elgg-{$vars['align']}"; unset($vars['class']); unset($vars['align']); $vars['class'] = 'elgg-input-radio'; if (is_array($vars['value'])) { $vars['value'] = array_map('elgg_strtolower', $vars['value']); } else { $vars['value'] = array(elgg_strtolower($vars['value'])); } $value = $vars['value']; unset($vars['value']); $radios = ''; foreach ($options as $label => $option) { $vars['checked'] = in_array(elgg_strtolower($option), $value); $vars['value'] = $option; // handle indexed array where label is not specified // @deprecated 1.8 Remove in 1.9 if (is_integer($label)) { elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/radio', 1.8); $label = $option; } $radio = elgg_format_element('input', $vars); $radios .= "<li><label>{$radio}{$label}</label></li>"; } echo elgg_format_element('ul', ['class' => $list_class, 'id' => $id], $radios);
function create_file($container_guid, $title, $desc, $access_id, $guid, $tags, $new_file) { // register_error("Creating file: " . $container_guid . ", vars: " . print_r(array($title, $desc, $access_id, $guid, $tags, $new_file), true)); if ($new_file) { // must have a file if a new file upload if (empty($_FILES['upload']['name'])) { // cache information in session $_SESSION['uploadtitle'] = $title; $_SESSION['uploaddesc'] = $desc; $_SESSION['uploadtags'] = $tags; $_SESSION['uploadaccessid'] = $access_id; register_error(elgg_echo('file:nofile') . "no file new"); forward($_SERVER['HTTP_REFERER']); } $file = new FilePluginFile(); $file->subtype = "file"; // if no title on new upload, grab filename if (empty($title)) { $title = $_FILES['upload']['name']; } } else { // load original file object $file = get_entity($guid); if (!$file) { register_error(elgg_echo('file:cannotload') . 'can"t load existing'); forward($_SERVER['HTTP_REFERER']); } // user must be able to edit file if (!$file->canEdit()) { register_error(elgg_echo('file:noaccess') . 'no access to existing'); forward($_SERVER['HTTP_REFERER']); } } $file->title = $title; $file->description = $desc; $file->access_id = $access_id; $file->container_guid = $container_guid; $tags = explode(",", $tags); $file->tags = $tags; // we have a file upload, so process it if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { $prefix = "file/"; // if previous file, delete it if ($new_file == false) { $filename = $file->getFilenameOnFilestore(); if (file_exists($filename)) { unlink($filename); } // use same filename on the disk - ensures thumbnails are overwritten $filestorename = $file->getFilename(); $filestorename = elgg_substr($filestorename, elgg_strlen($prefix)); } else { $filestorename = elgg_strtolower(time() . $_FILES['upload']['name']); } $file->setFilename($prefix . $filestorename); $file->setMimeType($_FILES['upload']['type']); $file->originalfilename = $_FILES['upload']['name']; $file->simpletype = get_general_file_type($_FILES['upload']['type']); $file->open("write"); $file->write(get_uploaded_file('upload')); $file->close(); $guid = $file->save(); // if image, we need to create thumbnails (this should be moved into a function) if ($guid && $file->simpletype == "image") { $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true); if ($thumbnail) { $thumb = new ElggFile(); $thumb->setMimeType($_FILES['upload']['type']); $thumb->setFilename($prefix . "thumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); $file->thumbnail = $prefix . "thumb" . $filestorename; unset($thumbnail); } $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true); if ($thumbsmall) { $thumb->setFilename($prefix . "smallthumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbsmall); $thumb->close(); $file->smallthumb = $prefix . "smallthumb" . $filestorename; unset($thumbsmall); } $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false); if ($thumblarge) { $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->open("write"); $thumb->write($thumblarge); $thumb->close(); $file->largethumb = $prefix . "largethumb" . $filestorename; unset($thumblarge); } } } else { // not saving a file but still need to save the entity to push attributes to database $file->save(); } return array($file, $guid); }
/** * @param $title * @param $description * @param $username * @param $access * @param $tags * @return array * @throws InvalidParameterException * @internal param $guid * @internal param $size */ function file_save_post($title, $description, $username, $access, $tags) { $return = array(); if (!$username) { $user = elgg_get_logged_in_user_entity(); } else { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } } $loginUser = elgg_get_logged_in_user_entity(); $container_guid = $loginUser->guid; if ($access == 'ACCESS_FRIENDS') { $access_id = -2; } elseif ($access == 'ACCESS_PRIVATE') { $access_id = 0; } elseif ($access == 'ACCESS_LOGGED_IN') { $access_id = 1; } elseif ($access == 'ACCESS_PUBLIC') { $access_id = 2; } else { $access_id = -2; } $file = $_FILES["upload"]; if (empty($file)) { $response['status'] = 1; $response['result'] = elgg_echo("file:blank"); return $response; } $new_file = true; if ($new_file) { $file = new ElggFile(); $file->subtype = "file"; // if no title on new upload, grab filename if (empty($title)) { $title = htmlspecialchars($_FILES['upload']['name'], ENT_QUOTES, 'UTF-8'); } } $file->title = $title; $file->description = $description; $file->access_id = $access_id; $file->container_guid = $container_guid; $file->tags = string_to_tag_array($tags); // we have a file upload, so process it if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { $prefix = "file/"; $filestorename = elgg_strtolower(time() . $_FILES['upload']['name']); $file->setFilename($prefix . $filestorename); $file->originalfilename = $_FILES['upload']['name']; $mime_type = $file->detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']); $file->setMimeType($mime_type); $file->simpletype = elgg_get_file_simple_type($mime_type); // Open the file to guarantee the directory exists $file->open("write"); $file->close(); move_uploaded_file($_FILES['upload']['tmp_name'], $file->getFilenameOnFilestore()); $fileSaved = $file->save(); // if image, we need to create thumbnails (this should be moved into a function) if ($fileSaved && $file->simpletype == "image") { $file->icontime = time(); $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true); if ($thumbnail) { $thumb = new ElggFile(); $thumb->setMimeType($_FILES['upload']['type']); $thumb->setFilename($prefix . "thumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); $file->thumbnail = $prefix . "thumb" . $filestorename; unset($thumbnail); } $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true); if ($thumbsmall) { $thumb->setFilename($prefix . "smallthumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbsmall); $thumb->close(); $file->smallthumb = $prefix . "smallthumb" . $filestorename; unset($thumbsmall); } $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false); if ($thumblarge) { $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->open("write"); $thumb->write($thumblarge); $thumb->close(); $file->largethumb = $prefix . "largethumb" . $filestorename; unset($thumblarge); } } elseif ($file->icontime) { // if it is not an image, we do not need thumbnails unset($file->icontime); $thumb = new ElggFile(); $thumb->setFilename($prefix . "thumb" . $filestorename); $thumb->delete(); unset($file->thumbnail); $thumb->setFilename($prefix . "smallthumb" . $filestorename); $thumb->delete(); unset($file->smallthumb); $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->delete(); unset($file->largethumb); } } else { // not saving a file but still need to save the entity to push attributes to database $fileSaved = $file->save(); } // handle results differently for new files and file updates if ($new_file) { if ($fileSaved) { elgg_create_river_item(array('view' => 'river/object/file/create', 'action_type' => 'create', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $file->guid)); $return['guid'] = $file->guid; $return['message'] = 'success'; } else { // failed to save file object - nothing we can do about this $return['guid'] = 0; $return['message'] = elgg_echo("file:uploadfailed"); } } else { $return['guid'] = 0; $return['message'] = elgg_echo("file:uploadfailed"); } return $return; }