/** * Save the contents of the avatar field when the general settings form is submitted. * * @param string $key The name of the field that was submitted. * @param ETForm $form The form object. * @param array $preferences An array of preferences to write to the database. * @return string */ public function saveAvatar($key, $form, &$preferences) { if (empty($_FILES[$key]["tmp_name"])) { return; } $uploader = ET::uploader(); try { // Validate and get the uploaded file from this field. $file = $uploader->getUploadedFile($key); // Save it as an image, cropping it to the configured avatar size. $avatar = $uploader->saveAsImage($file, PATH_UPLOADS . "/avatars/" . ET::$session->userId, C("esoTalk.avatars.width"), C("esoTalk.avatars.height"), "crop"); // Update the member's avatarFormat field to the avatar file's extension. ET::memberModel()->updateById(ET::$session->userId, array("avatarFormat" => pathinfo($avatar, PATHINFO_EXTENSION))); } catch (Exception $e) { // If something went wrong up there, add the error message to the form. $form->error($key, $e->getMessage()); } }