]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialPhoto/GNUsocialPhotoPlugin.php
Merge remote-tracking branch 'upstream/master' into social-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     var $oldSaveNew = true;
37
38     function onCheckSchema()
39     {
40         $schema = Schema::get();
41
42         $schema->ensureTable('photo', Photo::schemaDef());
43
44         return true;
45     }
46
47     function onRouterInitialized(URLMapper $m)
48     {
49         $m->connect('main/photo/new', array('action' => 'newphoto'));
50         $m->connect('main/photo/:id', array('action' => 'showphoto'));
51         return true;
52     }
53
54     function entryForm($out)
55     {
56         return new NewPhotoForm($out);
57     }
58
59     function appTitle()
60     {
61         return _('Photo');
62     }
63
64     function tag()
65     {
66         return 'Photo';
67     }
68
69     function types()
70     {
71         return array(Photo::OBJECT_TYPE);
72     }
73
74     function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
75     {
76
77         if(count($activity->objects) != 1) {
78             throw new Exception('Too many activity objects.');
79         }
80
81         $photoObj = $activity->objects[0];
82
83         if ($photoObj->type != Photo::OBJECT_TYPE) {
84             throw new Exception('Wrong type for object.');
85         }
86
87         $photo_uri = $photoObj->largerImage;
88         $thumb_uri = $photo_uri;
89         if(!empty($photoObj->thumbnail)){
90             $thumb_uri = $photoObj->thumbnail;
91         }
92
93         $description = $photoObj->description;
94         $title = $photoObj->title;
95         
96         $options['object_type'] = Photo::OBJECT_TYPE;
97
98         Photo::saveNew($actor, $photo_uri, $thumb_uri, $title, $description, $options);
99    
100     }
101
102     function activityObjectFromNotice(Notice $notice)
103     {
104
105         $photo = Photo::getByNotice($notice);
106         
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();
113
114         $object->largerImage = $photo->photo_uri;
115         $object->thumbnail = $photo->thumb_uri;
116         $object->description = $photo->description;
117         
118         return $object;
119         
120     }
121
122     function showNoticeContent(Notice $notice, HTMLOutputter $out)
123     {
124         $photo = Photo::getByNotice($notice);
125         if ($photo) {
126             if($photo->title){
127                 // TODO: ugly. feel like we should have a more abstract way
128                 // of choosing the h-level.
129                 $out->element('h3', array(), $title);
130             }
131             $out->element('img', array('src' => $photo->photo_uri,
132                 'width' => '100%'));
133             // TODO: add description
134         }
135     }
136
137     function deleteRelated(Notice $notice)
138     {
139         $photo = Photo::getByNotice($notice);
140         if ($photo) {
141             $photo->delete();
142         }
143     }
144 }