]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialPhoto/GNUsocialPhotoPlugin.php
Merge remote-tracking branch 'statusnet/master'
[quix0rs-gnu-social.git] / plugins / GNUsocialPhoto / GNUsocialPhotoPlugin.php
1 <?php
2 /**
3  * GNU Social
4  * Copyright (C) 2011, Free Software Foundation, Inc.
5  *
6  * PHP version 5
7  *
8  * LICENCE:
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Widget
23  * @package   GNU Social
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
27  */
28
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 class GNUsocialPhotoPlugin extends MicroAppPlugin
34 {
35
36     function onCheckSchema()
37     {
38         $schema = Schema::get();
39
40         $schema->ensureTable('photo', Photo::schemaDef());
41
42         return true;
43     }
44
45     function onAutoload($cls)
46     {
47         $dir = dirname(__FILE__);
48         switch($cls)
49         {
50         case 'Photo':
51             include_once $dir . '/Photo.php';
52             break;
53         case 'NewPhotoForm':
54             include_once $dir . '/newphotoform.php';
55             break;
56         case 'NewphotoAction':
57             include_once $dir . '/newphoto.php';
58             break;
59         default:
60             break;
61         }
62         return true;
63     }
64
65     function onRouterInitialized($m)
66     {
67         $m->connect('main/photo/new', array('action' => 'newphoto'));
68         $m->connect('main/photo/:id', array('action' => 'showphoto'));
69         return true;
70     }
71
72     function entryForm($out)
73     {
74         return new NewPhotoForm($out);
75     }
76
77     function appTitle()
78     {
79         return _('Photo');
80     }
81
82     function tag()
83     {
84         return 'Photo';
85     }
86
87     function types()
88     {
89         return array(Photo::OBJECT_TYPE);
90     }
91
92     function saveNoticeFromActivity($activity, $actor, $options=array())
93     {
94
95         if(count($activity->objects) != 1) {
96             throw new Exception('Too many activity objects.');
97         }
98
99         $photoObj = $activity->objects[0];
100
101         if ($photoObj->type != Photo::OBJECT_TYPE) {
102             throw new Exception('Wrong type for object.');
103         }
104
105         $photo_uri = $photoObj->largerImage;
106         $thumb_uri = $photo_uri;
107         if(!empty($photoObj->thumbnail)){
108             $thumb_uri = $photoObj->thumbnail;
109         }
110
111         $description = $photoObj->description;
112         $title = $photoObj->title;
113         
114         $options['object_type'] = Photo::OBJECT_TYPE;
115
116         Photo::saveNew($actor, $photo_uri, $thumb_uri, $title, $description, $options);
117    
118     }
119
120     function activityObjectFromNotice($notice)
121     {
122
123         $photo = Photo::getByNotice($notice);
124         
125         $object = new ActivityObject();
126         $object->id = $notice->uri;
127         $object->type = Photo::OBJECT_TYPE;
128         $object->title = $photo->title;
129         $object->summary = $notice->content;
130         $object->link = $notice->bestUrl();
131
132         $object->largerImage = $photo->photo_uri;
133         $object->thumbnail = $photo->thumb_uri;
134         $object->description = $photo->description;
135         
136         return $object;
137         
138     }
139
140     function showNotice($notice, $out)
141     {
142         $photo = Photo::getByNotice($notice);
143         if ($photo) {
144             if($photo->title){
145                 // TODO: ugly. feel like we should have a more abstract way
146                 // of choosing the h-level.
147                 $out->element('h3', array(), $title);
148             }
149             $out->element('img', array('src' => $photo->photo_uri,
150                 'width' => '100%'));
151             // TODO: add description
152         }
153     }
154
155     function deleteRelated($notice)
156     {
157         $photo = Photo::getByNotice($notice);
158         if ($photo) {
159             $photo->delete();
160         }
161     }
162 }