e914ca6f6c54ab2937834de1dd40d7570acf2c04
2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
23 class SharingAPIModule
extends PlModule
28 'api/1/sharing/search' => $this->make_api_hook('search', AUTH_COOKIE
, 'api_user_readonly'),
29 'api/1/sharing/bulkmail' => $this->make_api_hook('bulkmail', AUTH_COOKIE
, 'api_user_readonly'),
30 'api/1/sharing/picture' => $this->make_hook('picture_token', AUTH_PUBLIC
),
34 function handler_search(PlPage
$page, PlUser
$authUser, $payload)
36 require_once 'partnersharing.inc.php';
37 $partner = PartnerSharing
::fetchByAPIUser($authUser);
38 if ($partner == null ||
!$partner->has_directory
) {
42 $this->load('request.inc.php');
44 $payload = new PlDict($payload);
46 $errors = WSDirectoryRequest
::validatePayload($payload);
49 foreach ($errors as $error_code) {
50 $page->trigError(WSDirectoryRequest
::$ERROR_MESSAGES[$error_code]);
52 return PL_BAD_REQUEST
;
56 $request = new WSDirectoryRequest($partner, $payload);
57 $request->assignToPage($page);
61 function handler_bulkmail(PlPage
$page, PlUser
$authUser, $payload)
63 require_once 'partnersharing.inc.php';
64 $partner = PartnerSharing
::fetchByAPIUser($authUser);
65 if ($partner == null ||
!$partner->has_bulkmail
) {
69 if (!isset($payload['uids'])) {
70 $page->trigError('Malformed query.');
71 return PL_BAD_REQUEST
;
74 $uids = $payload['uids'];
78 new UFC_PartnerSharingID($partner->id
, $uids),
79 new UFC_HasValidEmail(),
80 new UFC_PartnerSharingEmail($partner->id
)
84 foreach ($pf->iterUsers() as $user) {
86 'name' => $user->fullName(),
87 'email' => $user->bestEmail(),
88 'gender' => $user->isFemale() ?
'woman' : 'man',
91 $page->jsonAssign('contexts', $contexts);
95 function handler_picture_token(PlPage
$page, $size, $token)
97 XDB
::rawExecute('DELETE FROM profile_photo_tokens
98 WHERE expires <= NOW()');
99 $pid = XDB
::fetchOneCell('SELECT pid
100 FROM profile_photo_tokens
101 WHERE token = {?}', $token);
103 $res = XDB
::fetchOneAssoc('SELECT attach, attachmime, x, y, last_update
105 WHERE pid = {?}', $pid);
106 $photo = PlImage
::fromData($res['attach'], 'image/' . $res['attachmime'], $res['x'], $res['y'], $res['last_update']);
114 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: