]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialPhoto/Photo.php
Initial work on a redo of the photo plugin. not yet functional.
[quix0rs-gnu-social.git] / plugins / GNUsocialPhoto / Photo.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  * @package   GNU Social
23  * @author    Ian Denhardt <ian@zenhack.net>
24  * @copyright 2011 Free Software Foundation, Inc.
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
26  */
27
28 if(!defined('STATUSNET')){
29     exit(1);
30 }
31
32 /**
33  * Data class for photos.
34  */
35
36 class Photo extends Managed_DataObject
37 {
38     const OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/photo';
39
40     public $__table = 'photo'; // table name
41     public $id;                // char (36) // UUID
42     public $uri;               // varchar (255)  // This is the corresponding notice's uri.
43     public $photo_uri;         // varchar (255)
44     public $thumb_uri;         // varchar (255)
45     public $title;             // varchar (255)
46     public $description;       // text
47     public $profile_id;        // int
48     
49     public function staticGet($k, $v=null)
50     {
51         return Memcached_DataObject::staticGet('photo', $k, $v);
52     }
53
54     public function getByNotice($notice)
55     {
56         return self::staticGet('uri', $notice->uri);
57     }
58
59     public function getNotice()
60     {
61         return Notice::staticGet('uri', $this->uri);
62     }
63
64     public static function schemaDef()
65     {
66         return array(
67             'description' => 'A photograph',
68             'fields' => array(
69                 'id' => array('type' => 'char',
70                               'length' => 36,
71                               'not null' => true,
72                               'description' => 'UUID'),
73                 'uri' => array('type' => 'varchar',
74                                'length' => 255,
75                                'not null' => true),
76                 'photo_uri' => array('type' => 'varchar',
77                                'length' => 255,
78                                'not null' => true),
79                 'photo_uri' => array('type' => 'varchar',
80                                'length' => 255,
81                                'not null' => true),
82                 'profile_id' => array('type' => 'int', 'not null' => true),
83             ),
84             'primary key' => array('id'),
85             'foreign keys' => array('photo_profile_id__key' => array('profile' => array('profile_id' => 'id'))),
86         );
87     }
88
89     function saveNew($profile, $photo_uri, $thumb_uri, $title, $description, $options=array())
90     {
91         $photo = new Photo();
92
93         $photo->id =  UUID::gen();
94         $photo->profile_id = $profile->id;
95         $photo->photo_uri = $photo_uri;
96         $photo->thumb_uri = $thumb_uri;
97
98
99         $options['object_type'] = Photo::OBJECT_TYPE;
100
101         if (!array_key_exists('uri', $options)) { 
102             $options['uri'] = common_local_url('showphoto', array('id' => $photo->id));
103         }
104
105         if (!array_key_exists('rendered', $options)) {
106             $options['rendered'] = sprintf("<img src=\"%s\" alt=\"%s\"></img>", $photo_uri,
107                 $title);
108         }
109
110         $photo->uri = $options['uri'];
111         
112         $photo->insert();
113
114         return Notice::saveNew($profile->id,
115                                '',
116                                'web',
117                                $options);
118
119     }
120 }