4 * Copyright (C) 2010, 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 2010 Free Software Foundation, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
29 /* Photo sharing plugin */
31 if (!defined('STATUSNET')) {
35 class GNUsocialPhotosPlugin extends Plugin
38 function onAutoload($cls)
40 $dir = dirname(__FILE__);
45 include_once $dir . '/lib/photolib.php';
46 include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
48 case 'PhotouploadAction':
49 include_once $dir . '/lib/photolib.php';
50 include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
56 include_once $dir . '/classes/gnusocialphoto.php';
57 include_once $dir . '/classes/gnusocialphotoalbum.php';
61 function onCheckSchema()
63 $schema = Schema::get();
64 $schema->ensureTable('GNUsocialPhoto',
65 array(new ColumnDef('notice_id', 'int(11)', null, false),
66 new ColumnDef('album_id', 'int(11)', null, false),
67 new ColumnDef('uri', 'varchar(512)', null, false),
68 new ColumnDef('thumb_uri', 'varchar(512)', null, false)));
69 $schema->ensureTable('GNUsocialPhotoAlbum',
70 array(new ColumnDef('album_id', 'int(11)', null, false, 'PRI', null, null, true),
71 new ColumnDef('profile_id', 'int(11)', null, false),
72 new ColumnDef('album_name', 'varchar(256)', null, false)));
76 function onRouterInitialized($m)
78 $m->connect(':nickname/photos', array('action' => 'photos'));
79 $m->connect('main/uploadphoto', array('action' => 'photoupload'));
80 common_log(LOG_INFO, "init'd!");
84 function onStartActivityDefaultObjectType(&$notice, &$xs, &$type)
86 $photo = GNUsocialPhoto::staticGet('notice_id', $notice->id);
88 $type = ActivityObject::PHOTO;
92 function onStartActivityObjects(&$notice, &$xs, &$objects)
94 $photo = GNUsocialPhoto::staticGet('notice_id', $notice->id);
96 $object = new ActivityObject();
97 $object->thumbnail = $photo->thumb_uri;
98 $object->largerImage = $photo->uri;
99 $object->type = ActivityObject::PHOTO;
101 $object->id = $notice->id;
102 $objects[0] = $object;
106 function onStartHandleFeedEntry($activity)
108 if ($activity->verb == ActivityVerb::POST) {
109 $oprofile = Ostatus_profile::ensureActorProfile($activity);
110 foreach ($activity->objects as $object) {
111 if ($object->type == ActivityObject::PHOTO) {
112 $uri = $object->largerImage;
113 $thumb_uri = $object->thumbnail;
114 $profile_id = $oprofile->profile_id;
115 $source = 'unknown'; // TODO: put something better here.
117 $uri = filter_var($uri, FILTER_SANITIZE_URL);
118 $thumb_uri = filter_var($thumb_uri, FILTER_SANITIZE_URL);
119 $uri = filter_var($uri, FILTER_VALIDATE_URL);
120 $thumb_uri = filter_var($thumb_uri, FILTER_VALIDATE_URL);
121 if (!empty($uri) && !empty($thumb_uri)) {
122 GNUsocialPhoto::saveNew($profile_id, $thumb_uri, $uri, $source);
132 function onStartShowNoticeItem($action)
134 $photo = GNUsocialPhoto::staticGet('notice_id', $action->notice->id);
136 $action->out->elementStart('div', 'entry-title');
137 $action->showAuthor();
138 $action->out->elementStart('a', array('href' => $photo->uri));
139 $action->out->element('img', array('src' => $photo->thumb_uri));
140 $action->out->elementEnd('a');
141 $action->out->elementEnd('div');
142 $action->showNoticeInfo();
143 $action->showNoticeOptions();