subtype = "tool"; // Set its owner to the current user $tool->owner_guid = $_SESSION['user']->getGUID(); // For now, set its access to public (we'll add an access dropdown shortly) $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/add.php"); } // Now let's add tags. We can pass an array directly to the object property! Easy. if (is_array($tagarray)) { $tool->tags = $tagarray; } // Also setting tool-related fields $tool->url = $url; $tool->subjects = $subjects; $tool->guidelines = serialize(keParseGuidelines($guidelines)); $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)) { // Save it $original = saveImageFile($tool->getGUID() . '.original', $image, $tool->getOwner()); // Write original file name into objects metadata $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); // Save it $resized = saveImageFile("small_" . $tool->getGUID() . ".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); // Save it $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(elgg_echo('koolielu:error_supported_image_formats')); } } // Success message /*translation:Tool added*/ system_message(elgg_echo("koolielu:message_tool_added")); // add to river add_to_river('river/object/tool/create','create',$_SESSION['user']->guid,$tool->guid); // 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()); } ?>