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()); // @todo: parameterize these dimensions // This saves the photo a second time, which is unfortunate but difficult to avoid. $result = $photo->set_thumbnail($filename, 200, 140) ->set_resize($filename, 640, 480) ->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(sprintf(_("Add Photo to %s"), $parent->title)); $group->input("name")->label(true); $group->input("title")->label(true); $group->textarea("description")->label(true)->rules("length[0, 255"); $group->upload("file")->label(true)->rules("allow[jpg,png,gif,tiff]"); $group->hidden("type")->value("photo"); $group->submit(_("Upload")); $form->add_rules_from(ORM::factory("item")); return $form; } }