]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialPhoto/GNUsocialPhotoPlugin.php
plugins onAutoload now only overloads if necessary (extlibs etc.)
[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 onRouterInitialized($m)
46     {
47         $m->connect('main/photo/new', array('action' => 'newphoto'));
48         $m->connect('main/photo/:id', array('action' => 'showphoto'));
49         return true;
50     }
51
52     function entryForm($out)
53     {
54         return new NewPhotoForm($out);
55     }
56
57     function appTitle()
58     {
59         return _('Photo');
60     }
61
62     function tag()
63     {
64         return 'Photo';
65     }
66
67     function types()
68     {
69         return array(Photo::OBJECT_TYPE);
70     }
71
72     function saveNoticeFromActivity($activity, $actor, $options=array())
73     {
74
75         if(count($activity->objects) != 1) {
76             throw new Exception('Too many activity objects.');
77         }
78
79         $photoObj = $activity->objects[0];
80
81         if ($photoObj->type != Photo::OBJECT_TYPE) {
82             throw new Exception('Wrong type for object.');
83         }
84
85         $photo_uri = $photoObj->largerImage;
86         $thumb_uri = $photo_uri;
87         if(!empty($photoObj->thumbnail)){
88             $thumb_uri = $photoObj->thumbnail;
89         }
90
91         $description = $photoObj->description;
92         $title = $photoObj->title;
93         
94         $options['object_type'] = Photo::OBJECT_TYPE;
95
96         Photo::saveNew($actor, $photo_uri, $thumb_uri, $title, $description, $options);
97    
98     }
99
100     function activityObjectFromNotice($notice)
101     {
102
103         $photo = Photo::getByNotice($notice);
104         
105         $object = new ActivityObject();
106         $object->id = $notice->uri;
107         $object->type = Photo::OBJECT_TYPE;
108         $object->title = $photo->title;
109         $object->summary = $notice->content;
110         $object->link = $notice->bestUrl();
111
112         $object->largerImage = $photo->photo_uri;
113         $object->thumbnail = $photo->thumb_uri;
114         $object->description = $photo->description;
115         
116         return $object;
117         
118     }
119
120     function showNotice($notice, $out)
121     {
122         $photo = Photo::getByNotice($notice);
123         if ($photo) {
124             if($photo->title){
125                 // TODO: ugly. feel like we should have a more abstract way
126                 // of choosing the h-level.
127                 $out->element('h3', array(), $title);
128             }
129             $out->element('img', array('src' => $photo->photo_uri,
130                 'width' => '100%'));
131             // TODO: add description
132         }
133     }
134
135     function deleteRelated($notice)
136     {
137         $photo = Photo::getByNotice($notice);
138         if ($photo) {
139             $photo->delete();
140         }
141     }
142 }