getSubtype() == "tool" && $tool->canEdit()) { // Cache to the session $_SESSION['tooltitle'] = $title; $_SESSION['toolurl'] = $url; $_SESSION['toolbody'] = $body; $_SESSION['toolshortdescription'] = $short_description; $_SESSION['toolsubjects'] = $subjects; $_SESSION['tooltags'] = $tags; $_SESSION['toolguidelines'] = $guidelines; // Convert string of tags into a preformatted array $tagarray = string_to_tag_array($tags); // Make sure the title / description aren't blank if (empty($title) || empty($body) || empty($url) || empty($short_description)) { /*translation:Please fill all required fields.*/ register_error(elgg_echo("koolielu:error_blank")); forward("mod/tools/edit.php?tool=" . $guid); // Otherwise, save the tool } else { // Get owning user $owner = get_entity($tool->getOwner()); // Only addable by trusted users, public by default $tool->access_id = 2; // public // Set its title and description appropriately $tool->title = $title; $tool->description = $body; // Before we can set metadata, we need to save the tool if (!$tool->save()) { /*translation:Error occured, object could not be saved.*/ register_error(elgg_echo("koolielu:error_not_saved")); forward("mod/tools/edit.php?tool=" . $guid); } // Now let's add tags. We can pass an array directly to the object property! Easy. $tool->clearMetadata('tags'); if (is_array($tagarray)) { $tool->tags = $tagarray; } // Setting our own data now $tool->clearMetadata('subjects'); $tool->subjects = $subjects; $tool->clearMetadata('url'); $tool->url = $url; $tool->clearMetadata('guidelines'); $tool->guidelines = serialize(keParseGuidelines($guidelines)); $tool->clearMetadata('shortdescription'); $tool->shortdescription = $short_description; // Deal with image if ((isset($_FILES['toolimage'])) && (substr_count($_FILES['toolimage']['type'],'image/'))) { $supported_formats = getSupportedImageFormats(); $image = get_uploaded_file('toolimage'); // See if we even support the format first if (in_array(exif_imagetype($_FILES['toolimage']['tmp_name']),$supported_formats)) { // Delete all associated files, and then save new ones deleteKeObjectImages($tool->getGUID(), $tool->getOwner()); $original = saveImageFile($tool->guid . ".original", $image, $tool->getOwner()); // Write original file name into objects metadata $tool->clearMetadata('original_file_name'); $tool->original_file_name = $_FILES['toolimage']['name']; if (!$original) { /*translation:Original image could not be saved.*/ register_error(elgg_echo('koolielu:error_original_image_not_saved')); } $resized_image = get_resized_image_from_uploaded_file('toolimage', 100, 100, false); $resized = saveImageFile("small_" . $tool->guid . ".jpg", $resized_image, $tool->getOwner()); if (!$resized) { /*translation:Resized image could not be saved.*/ register_error(elgg_echo('koolielu:error_resized_image_not_saved')); } $resized_listing_image = get_resized_image_from_uploaded_file('toolimage', 40, 40, false); $resized_listing = saveImageFile("listing_" . $tool->getGUID() . ".jpg", $resized_listing_image, $tool->getOwner()); if (!$resized_listing) { /*translation:Resized image could not be saved.*/ register_error(elgg_echo('koolielu:error_resized_image_not_saved')); } } else { /*translation:Image format not supported. Supported formats are: .jpg, .png, .jpeg and .gif.*/ register_error('koolielu:error_supported_image_formats'); } } // Success message /*translation:Tool modified.*/ system_message(elgg_echo("koolielu:message_tool_modified")); // Remove the tool cache unset($_SESSION['tooltitle']); unset($_SESSION['toolurl']); unset($_SESSION['toolbody']); unset($_SESSION['toolshortdescription']); unset($_SESSION['toolsubjects']); unset($_SESSION['tooltags']); unset($_SESSION['toolguidelines']); // Forward to the main tools page forward($tool->getURL()); } } ?>