2010-01-04 01:03:33 +00:00
|
|
|
<?
|
|
|
|
include("Gallery3.php");
|
|
|
|
|
2010-01-31 04:39:11 +00:00
|
|
|
$SITE_URL = "http://example.com/gallery3/index.php/rest";
|
2010-01-04 01:03:33 +00:00
|
|
|
$USER = "admin";
|
|
|
|
$PASSWORD = "admin";
|
|
|
|
|
|
|
|
if (file_exists("local_config.php")) {
|
|
|
|
include("local_config.php");
|
|
|
|
}
|
|
|
|
|
2010-01-08 19:16:25 +00:00
|
|
|
alert("Connect to $SITE_URL");
|
2010-01-26 08:15:35 +00:00
|
|
|
$auth = Gallery3::login($SITE_URL, $USER, $PASSWORD);
|
|
|
|
$root = Gallery3::factory("$SITE_URL/item/1", $auth);
|
|
|
|
$tags = Gallery3::factory("$SITE_URL/tags", $auth);
|
2010-06-20 16:54:22 +00:00
|
|
|
$comments = Gallery3::factory("$SITE_URL/comments", $auth);
|
2010-01-05 05:49:40 +00:00
|
|
|
|
2010-01-26 08:15:35 +00:00
|
|
|
$tag = Gallery3::factory()
|
|
|
|
->set("name", "My Tag")
|
|
|
|
->create($tags->url, $auth);
|
|
|
|
alert("Created tag: <b>{$tag->url}</b>");
|
|
|
|
|
|
|
|
$album = Gallery3::factory()
|
|
|
|
->set("type", "album")
|
|
|
|
->set("name", "Sample Album")
|
|
|
|
->set("title", "This is my Sample Album")
|
|
|
|
->create($root->url, $auth);
|
2010-01-28 05:46:00 +00:00
|
|
|
alert("Created album: <b>{$album->url} {$album->data->entity->title}</b>");
|
2010-01-26 08:15:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
alert("Modify the album");
|
|
|
|
$album
|
|
|
|
->set("title", "This is the new title")
|
2010-01-04 01:03:33 +00:00
|
|
|
->save();
|
2010-01-28 05:46:00 +00:00
|
|
|
alert("New title: <b>{$album->data->entity->title}</b>");
|
2010-01-26 08:15:35 +00:00
|
|
|
|
2010-04-04 18:58:05 +00:00
|
|
|
for ($i = 0; $i < 2; $i++) {
|
|
|
|
$photo = Gallery3::factory()
|
|
|
|
->set("type", "photo")
|
|
|
|
->set("name", "Sample Photo.png")
|
|
|
|
->set("title", "Sample Photo")
|
2010-08-08 08:13:32 +00:00
|
|
|
->set_file("test1.png")
|
2010-04-04 18:58:05 +00:00
|
|
|
->create($album->url, $auth);
|
|
|
|
alert("Uploaded photo: <b>{$photo->url}</b>");
|
|
|
|
}
|
|
|
|
$album->load();
|
2010-01-26 08:15:35 +00:00
|
|
|
alert("Album members: <b>" . join(", ", $album->data->members) . "</b>");
|
|
|
|
|
2010-08-08 08:13:32 +00:00
|
|
|
|
|
|
|
alert("Replace the data file");
|
|
|
|
$photo->set_file("test2.png")
|
|
|
|
->save();
|
|
|
|
|
|
|
|
|
2010-06-20 16:54:22 +00:00
|
|
|
$comment = Gallery3::factory()
|
|
|
|
->set("item", $album->data->members[0])
|
|
|
|
->set("type", "comment")
|
|
|
|
->set("text", "This is a random comment-- whee!")
|
|
|
|
->create($comments->url, $auth);
|
|
|
|
alert("Comment: <b>{$comment->url}</b>");
|
|
|
|
|
2010-04-04 18:58:05 +00:00
|
|
|
alert("Reorder the album");
|
|
|
|
$album
|
|
|
|
->set_members(array($album->data->members[1], $album->data->members[0]))
|
|
|
|
->set("sort_column", "weight")
|
|
|
|
->save();
|
|
|
|
alert("New order: <b>" . join(", ", $album->data->members) . "</b>");
|
2010-01-05 21:42:45 +00:00
|
|
|
|
2010-01-08 19:16:25 +00:00
|
|
|
alert("Search for the photo");
|
2010-01-26 08:15:35 +00:00
|
|
|
$photos = Gallery3::factory($root->url, $auth)
|
|
|
|
->set("name", "Sample")
|
|
|
|
->load();
|
|
|
|
alert("Found: {$photos->data->members[0]}");
|
|
|
|
|
2010-01-08 19:16:25 +00:00
|
|
|
|
2010-01-08 23:30:54 +00:00
|
|
|
alert("Grab a random photo");
|
2010-06-03 05:14:13 +00:00
|
|
|
$photos = Gallery3::factory("{$root->url}?random=true", $auth)
|
2010-01-26 08:15:35 +00:00
|
|
|
->load();
|
|
|
|
alert("Found: {$photos->data->members[0]}");
|
2010-01-08 23:30:54 +00:00
|
|
|
|
2010-01-04 01:03:33 +00:00
|
|
|
|
2010-01-26 08:15:35 +00:00
|
|
|
alert("Tag the album (using the album's relationships: {$album->data->relationships->tags->url})");
|
|
|
|
$tag_relationship1 = Gallery3::factory()
|
|
|
|
->set("tag", $tag->url)
|
|
|
|
->set("item", $root->url)
|
|
|
|
->create($album->data->relationships->tags->url, $auth);
|
|
|
|
alert("Tag: {$tag_relationship1->url}");
|
|
|
|
|
|
|
|
|
|
|
|
alert("Tag the photo (using the tag's relationships: {$tag->data->relationships->items->url})");
|
|
|
|
$tag_relationship2 = Gallery3::factory()
|
|
|
|
->set("tag", $tag->url)
|
|
|
|
->set("item", $photo->url)
|
|
|
|
->create($tag->data->relationships->items->url, $auth);
|
|
|
|
alert("Tag: {$tag_relationship2->url}");
|
2010-01-05 05:49:40 +00:00
|
|
|
|
2010-01-08 19:16:25 +00:00
|
|
|
alert("Un-tag the photo");
|
2010-01-26 08:15:35 +00:00
|
|
|
$tag_relationship2->delete();
|
|
|
|
$tag->load();
|
|
|
|
alert("1 remaining tag: <b>{$tag->data->relationships->items->members[0]}</b>");
|
2010-01-05 21:42:45 +00:00
|
|
|
|
2010-01-26 08:15:35 +00:00
|
|
|
alert("Delete the album and tag");
|
2010-01-04 01:03:33 +00:00
|
|
|
$album->delete();
|
2010-01-05 21:42:45 +00:00
|
|
|
$tag->delete();
|
|
|
|
|
2010-01-08 19:16:25 +00:00
|
|
|
alert("Done!");
|
|
|
|
|
|
|
|
function alert($msg) {
|
2010-06-20 16:54:22 +00:00
|
|
|
print "$msg <br/>\n";
|
2010-01-08 19:16:25 +00:00
|
|
|
flush();
|
|
|
|
}
|
2010-01-04 01:03:33 +00:00
|
|
|
?>
|