4 * Copyright (C) 2011, Free Software Foundation, Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Ian Denhardt <ian@zenhack.net>
25 * @copyright 2011 Free Software Foundation, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
29 if (!defined('STATUSNET')) {
33 class GNUsocialPhotoPlugin extends MicroAppPlugin
36 var $oldSaveNew = true;
38 function onCheckSchema()
40 $schema = Schema::get();
42 $schema->ensureTable('photo', Photo::schemaDef());
47 function onRouterInitialized($m)
49 $m->connect('main/photo/new', array('action' => 'newphoto'));
50 $m->connect('main/photo/:id', array('action' => 'showphoto'));
54 function entryForm($out)
56 return new NewPhotoForm($out);
71 return array(Photo::OBJECT_TYPE);
74 function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
77 if(count($activity->objects) != 1) {
78 throw new Exception('Too many activity objects.');
81 $photoObj = $activity->objects[0];
83 if ($photoObj->type != Photo::OBJECT_TYPE) {
84 throw new Exception('Wrong type for object.');
87 $photo_uri = $photoObj->largerImage;
88 $thumb_uri = $photo_uri;
89 if(!empty($photoObj->thumbnail)){
90 $thumb_uri = $photoObj->thumbnail;
93 $description = $photoObj->description;
94 $title = $photoObj->title;
96 $options['object_type'] = Photo::OBJECT_TYPE;
98 Photo::saveNew($actor, $photo_uri, $thumb_uri, $title, $description, $options);
102 function activityObjectFromNotice(Notice $notice)
105 $photo = Photo::getByNotice($notice);
107 $object = new ActivityObject();
108 $object->id = $notice->uri;
109 $object->type = Photo::OBJECT_TYPE;
110 $object->title = $photo->title;
111 $object->summary = $notice->content;
112 $object->link = $notice->getUrl();
114 $object->largerImage = $photo->photo_uri;
115 $object->thumbnail = $photo->thumb_uri;
116 $object->description = $photo->description;
122 function showNoticeContent(Notice $notice, HTMLOutputter $out)
124 $photo = Photo::getByNotice($notice);
127 // TODO: ugly. feel like we should have a more abstract way
128 // of choosing the h-level.
129 $out->element('h3', array(), $title);
131 $out->element('img', array('src' => $photo->photo_uri,
133 // TODO: add description
137 function deleteRelated(Notice $notice)
139 $photo = Photo::getByNotice($notice);