type = "photo"; $photo->title = $title; $photo->description = $description; $photo->name = $name; $photo->owner_id = $owner_id; $photo->width = $image_info[0]; $photo->height = $image_info[1]; $photo->mime_type = empty($image_info['mime']) ? "application/unknown" : $image_info['mime']; // Randomize the name if there's a conflict while (ORM::Factory("item") ->where("parent_id", $parent_id) ->where("name", $photo->name) ->find()->id) { // @todo Improve this. Random numbers are not user friendly $photo->name = rand() . "." . $pi["extension"]; } // This saves the photo $parent = ORM::factory("item", $parent_id); if (!$parent->loaded) { throw new Exception("@todo INVALID_PARENT_ID"); } $photo->add_to_parent($parent); copy($filename, $photo->file_path()); // This saves the photo a second time, which is unfortunate but difficult to avoid. $thumbnail_size = module::get_var("core", "thumbnail_size"); $resize_size = module::get_var("core", "resize_size"); $result = $photo->set_thumbnail($filename, $thumbnail_size, $thumbnail_size) ->set_resize($filename, $resize_size, $resize_size) ->save(); module::event("photo_created", $photo); return $result; } static function get_add_form($parent) { $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "gAddPhotoForm", "enctype" => "multipart/form-data")); $group = $form->group("add_photo")->label(sprintf(_("Add Photo to %s"), $parent->title)); $group->input("name")->label(_("Name")); $group->input("title")->label(_("Title")); $group->textarea("description")->label(_("Description"))->rules("length[0, 255"); $group->upload("file")->label(_("File"))->rules("allow[jpg,png,gif,tiff]"); $group->hidden("type")->value("photo"); $group->submit(_("Upload")); $form->add_rules_from(ORM::factory("item")); return $form; } }