forked from wbobeirne/Phlickr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthedPhoto.php
213 lines (199 loc) · 6.35 KB
/
AuthedPhoto.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/**
* @version $Id$
* @author Andrew Morton <drewish@katherinehouse.com>
* @license http://opensource.org/licenses/lgpl-license.php
* GNU Lesser General Public License, Version 2.1
* @package Phlickr
*/
/**
* This class extends Phlickr_Photo.
*/
require_once dirname(__FILE__) . '/Photo.php';
/**
* This class extends Phlickr_Photo to allow modifications of a photo.
*
* @package Phlickr
* @author Andrew Morton <drewish@katherinehouse.com>
* @see Phlickr_Photo
* @since 0.2.1
* @todo Add sample code.
* @todo Implement a setPerms().
*/
class Phlickr_AuthedPhoto extends Phlickr_Photo {
/**
* Constructor.
*
* You can construct a photo from an Id or XML.
*
* @param object Phlickr_Api $api This object must have valid
* authentication information or an exception will be thrown.
* @param mixed $source string Id, object SimpleXMLElement
* @throws Phlickr_Exception, Phlickr_ConnectionException,
* Phlickr_XmlParseException
*/
function __construct(Phlickr_Api $api, $source) {
parent::__construct($api, $source);
}
/**
* Delete the photo. This requires delete permission.
*
* @return boolean
* @since 0.2.6
*/
function delete() {
$this->getApi()->executeMethod(
'flickr.photos.delete',
array('photo_id' => $this->getId())
);
}
/**
* Sets the license for a photo.
*
* @param integer $license_id The ID of the license. 0 to remove.
* @returns void
* @see Phlickr_Api::getLicenses()
*/
public function setLicense($license_id) {
$resp = $this->getApi()->executeMethod(
'flickr.photos.licenses.setLicense',
array(
'photo_id' => $this->getId(),
'license_id' => $license_id,
)
);
$this->refresh();
}
/**
* Change the photo's title and description
*
* @param string $title The title of the photo.
* @param string $description The description of the photo.
* @return void
* @throws Phlickr_Exception
*/
public function setMeta($title, $description) {
$resp = $this->getApi()->executeMethod(
'flickr.photos.setMeta',
array(
'photo_id' => $this->getId(),
'title' => $title,
'description' => $description
)
);
$this->refresh();
}
/**
* Change the photo's permissions.
*
* @param boolean $forPublic Should the photo be visible to everyone?
* @param boolean $forFriends If the photo is private, should friends
* be able to view it?
* @param boolean $forFamily If the photo is private, should family
* be able to view it?
* @param integer $whoCanComment 0: nobody, 1: friends & family, 2:
* contacts, 3: everybody
* @param integer $whoCanAddMeta 0: nobody, 1: friends & family, 2:
* contacts, 3: everybody
* @return void
* @throws Phlickr_Exception
* @see isForPublic(), isForFriends(), isForFamily()
*/
public function setPerms($forPublic, $forFriends, $forFamily, $whoCanComment, $whoCanAddMeta) {
$resp = $this->getApi()->executeMethod(
'flickr.photos.setPerms',
array(
'photo_id' => $this->getId(),
'is_public' => $forPublic,
'is_friend' => $forFriends,
'is_family' => $forFamily,
'perm_comment' => $whoCanComment,
'perm_addmeta' => $whoCanAddMeta,
)
);
$this->refresh();
}
/**
* Set the photo's posted date.
*
* @param integer $ts UNIX timestamp.
* @return void
* @since 0.2.1
* @see getPostedTimestamp(), getPostedDate()
*/
public function setPosted($ts) {
$resp = $this->getApi()->executeMethod(
'flickr.photos.setDates',
array('photo_id' => $this->getId(),
'date_posted' => $ts)
);
$this->refresh();
}
/**
* Specify the photo's tags.
*
* Note that this will remove any existing tags.
*
* @param array $tags An array of the tags to add to the photo.
* @return void
* @see addTags(), getTags(), removeTag()
*/
public function setTags($tags) {
$quotedTags = '"' . implode('" "', $tags) . '"';
$resp = $this->getApi()->executeMethod(
'flickr.photos.setTags',
array('photo_id' => $this->getId(),
'tags' => $quotedTags)
);
$this->refresh();
}
/**
* Set the photo's taken date.
*
* Note that on Windows times before 1970, the UNIX epoch, won't work.
*
* The granularity is the accuracy to of the date. At present, Flickr only
* uses three granularities:
* - 0 = Y-m-d H:i:s
* - 4 = Y-m
* - 6 = Y
*
* @param mixed $date Integer UNIX timestamp or String date.
* @param integer $granularity The granularity of the date.
* @return void
* @since 0.2.1
* @see getTakenTimestamp(), getTakenGranularity(), getTakenDate()
*/
public function setTaken($date, $granularity = null) {
if (is_long($date)) {
// convert the time stamp to the mysql format required by flickr.
switch ($granularity) {
case 6:
$takenDate = date('Y', $date);
break;
case 4:
$takenDate = date('Y-m-d', $date);
break;
case 0:
// make 0 the default case.
default:
$takenDate = date('Y-m-d H:i:s', $date);
break;
}
} else {
// treat it as a string.
$takenDate = (string) $date;
}
// build a parameter array...
$params = array(
'photo_id' => $this->getId(),
'date_taken' => $takenDate
);
// ...include the granularity if it was specified
if (!is_null($granularity)) {
$params['date_taken_granularity'] = $granularity;
}
$this->getApi()->executeMethod('flickr.photos.setDates', $params);
$this->refresh();
}
}