1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | define ('PHPWG_ROOT_PATH', './'); |
---|
25 | |
---|
26 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
27 | check_status(ACCESS_FREE); |
---|
28 | include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php'); |
---|
29 | |
---|
30 | if ( !$conf['allow_web_services'] ) |
---|
31 | { |
---|
32 | page_forbidden('Web services are disabled'); |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * event handler that registers standard methods with the web service |
---|
37 | */ |
---|
38 | function ws_addDefaultMethods( $arr ) |
---|
39 | { |
---|
40 | include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php'); |
---|
41 | global $conf, $user; |
---|
42 | $service = &$arr[0]; |
---|
43 | $service->addMethod('pwg.getVersion', 'ws_getVersion', null, |
---|
44 | 'retrieves the PWG version'); |
---|
45 | |
---|
46 | $service->addMethod('pwg.caddie.add', 'ws_caddie_add', |
---|
47 | array( |
---|
48 | 'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
49 | ), |
---|
50 | 'adds the elements to the caddie'); |
---|
51 | |
---|
52 | $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages', |
---|
53 | array( |
---|
54 | 'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY), |
---|
55 | 'recursive'=>array('default'=>false), |
---|
56 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
57 | 'page' => array('default'=>0), |
---|
58 | 'order' => array('default'=>null), |
---|
59 | 'f_min_rate' => array( 'default'=> null ), |
---|
60 | 'f_max_rate' => array( 'default'=> null ), |
---|
61 | 'f_min_hit' => array( 'default'=> null ), |
---|
62 | 'f_max_hit' => array( 'default'=> null ), |
---|
63 | 'f_min_date_available' => array( 'default'=> null ), |
---|
64 | 'f_max_date_available' => array( 'default'=> null ), |
---|
65 | 'f_min_date_created' => array( 'default'=> null ), |
---|
66 | 'f_max_date_created' => array( 'default'=> null ), |
---|
67 | 'f_min_ratio' => array( 'default'=> null ), |
---|
68 | 'f_max_ratio' => array( 'default'=> null ), |
---|
69 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
70 | ), |
---|
71 | 'Returns elements for the corresponding categories. |
---|
72 | <br/><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array. |
---|
73 | <br/><b>order</b> comma separated fields for sorting (file,id, average_rate,...)' |
---|
74 | ); |
---|
75 | |
---|
76 | $service->addMethod('pwg.categories.getList', 'ws_categories_getList', |
---|
77 | array( |
---|
78 | 'cat_id' => array('default'=>0), |
---|
79 | 'recursive' => array('default'=>false), |
---|
80 | 'public' => array('default'=>false), |
---|
81 | ), |
---|
82 | 'retrieves a list of categories' ); |
---|
83 | |
---|
84 | $service->addMethod('pwg.images.addComment', 'ws_images_addComment', |
---|
85 | array( |
---|
86 | 'image_id' => array(), |
---|
87 | 'author' => array( 'default' => is_a_guest()? 'guest':$user['username']), |
---|
88 | 'content' => array(), |
---|
89 | 'key' => array(), |
---|
90 | ), |
---|
91 | 'add a comment to an image' ); |
---|
92 | |
---|
93 | $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo', |
---|
94 | array( |
---|
95 | 'image_id' => array(), |
---|
96 | 'comments_page' => array('default'=>0 ), |
---|
97 | 'comments_per_page' => array( |
---|
98 | 'default' => $conf['nb_comment_page'], |
---|
99 | 'maxValue' => 2*$conf['nb_comment_page'], |
---|
100 | ), |
---|
101 | ), |
---|
102 | 'retrieves information about the given photo' ); |
---|
103 | |
---|
104 | $service->addMethod('pwg.images.rate', 'ws_images_rate', |
---|
105 | array( |
---|
106 | 'image_id' => array(), |
---|
107 | 'rate' => array(), |
---|
108 | ), |
---|
109 | 'rate the image' ); |
---|
110 | |
---|
111 | $service->addMethod('pwg.images.search', 'ws_images_search', |
---|
112 | array( |
---|
113 | 'query'=>array(), |
---|
114 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
115 | 'page' => array('default'=>0), |
---|
116 | 'order' => array('default'=>null), |
---|
117 | 'f_min_rate' => array( 'default'=> null ), |
---|
118 | 'f_max_rate' => array( 'default'=> null ), |
---|
119 | 'f_min_hit' => array( 'default'=> null ), |
---|
120 | 'f_max_hit' => array( 'default'=> null ), |
---|
121 | 'f_min_date_available' => array( 'default'=> null ), |
---|
122 | 'f_max_date_available' => array( 'default'=> null ), |
---|
123 | 'f_min_date_created' => array( 'default'=> null ), |
---|
124 | 'f_max_date_created' => array( 'default'=> null ), |
---|
125 | 'f_min_ratio' => array( 'default'=> null ), |
---|
126 | 'f_max_ratio' => array( 'default'=> null ), |
---|
127 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
128 | ), |
---|
129 | 'Returns elements for the corresponding query search.' |
---|
130 | ); |
---|
131 | $service->addMethod('pwg.images.setPrivacyLevel', 'ws_images_setPrivacyLevel', |
---|
132 | array( |
---|
133 | 'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY), |
---|
134 | 'level' => array('maxValue'=>$conf['available_permission_levels']), |
---|
135 | ), |
---|
136 | 'sets the privacy levels for the images' ); |
---|
137 | |
---|
138 | $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' ); |
---|
139 | $service->addMethod('pwg.session.login', 'ws_session_login', |
---|
140 | array('username', 'password'), |
---|
141 | 'POST method only' ); |
---|
142 | $service->addMethod('pwg.session.logout', 'ws_session_logout', null, ''); |
---|
143 | |
---|
144 | $service->addMethod('pwg.tags.getList', 'ws_tags_getList', |
---|
145 | array('sort_by_counter' => array('default' =>false) ), |
---|
146 | 'retrieves a list of available tags'); |
---|
147 | $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages', |
---|
148 | array( |
---|
149 | 'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
150 | 'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
151 | 'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
152 | 'tag_mode_and'=>array('default'=>false), |
---|
153 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
154 | 'page' => array('default'=>0), |
---|
155 | 'order' => array('default'=>null), |
---|
156 | 'f_min_rate' => array( 'default'=> null ), |
---|
157 | 'f_max_rate' => array( 'default'=> null ), |
---|
158 | 'f_min_hit' => array( 'default'=> null ), |
---|
159 | 'f_max_hit' => array( 'default'=> null ), |
---|
160 | 'f_min_date_available' => array( 'default'=> null ), |
---|
161 | 'f_max_date_available' => array( 'default'=> null ), |
---|
162 | 'f_min_date_created' => array( 'default'=> null ), |
---|
163 | 'f_max_date_created' => array( 'default'=> null ), |
---|
164 | 'f_min_ratio' => array( 'default'=> null ), |
---|
165 | 'f_max_ratio' => array( 'default'=> null ), |
---|
166 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
167 | ), |
---|
168 | 'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. ' |
---|
169 | ); |
---|
170 | } |
---|
171 | |
---|
172 | add_event_handler('ws_add_methods', 'ws_addDefaultMethods'); |
---|
173 | |
---|
174 | |
---|
175 | add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
176 | |
---|
177 | $calling_partner_id = ''; |
---|
178 | $requestFormat = null; |
---|
179 | $responseFormat = null; |
---|
180 | |
---|
181 | if ( isset($_GET['partner']) ) |
---|
182 | { |
---|
183 | $calling_partner_id = $_GET['partner']; |
---|
184 | } |
---|
185 | if ( isset($_GET['format']) ) |
---|
186 | { |
---|
187 | $responseFormat = $_GET['format']; |
---|
188 | } |
---|
189 | |
---|
190 | if ( isset($HTTP_RAW_POST_DATA) ) |
---|
191 | { |
---|
192 | $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); |
---|
193 | if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 ) |
---|
194 | { |
---|
195 | } |
---|
196 | else |
---|
197 | { |
---|
198 | $requestFormat = "json"; |
---|
199 | } |
---|
200 | } |
---|
201 | else |
---|
202 | { |
---|
203 | $requestFormat = "rest"; |
---|
204 | } |
---|
205 | |
---|
206 | if ( !isset($responseFormat) and isset($requestFormat) ) |
---|
207 | { |
---|
208 | $responseFormat = $requestFormat; |
---|
209 | } |
---|
210 | |
---|
211 | $service = new PwgServer(); |
---|
212 | |
---|
213 | if (!is_null($requestFormat)) |
---|
214 | { |
---|
215 | $handler = null; |
---|
216 | switch ($requestFormat) |
---|
217 | { |
---|
218 | case 'rest': |
---|
219 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php'); |
---|
220 | $handler = new PwgRestRequestHandler(); |
---|
221 | break; |
---|
222 | } |
---|
223 | $service->setHandler($requestFormat, $handler); |
---|
224 | } |
---|
225 | |
---|
226 | if (!is_null($responseFormat)) |
---|
227 | { |
---|
228 | $encoder = null; |
---|
229 | switch ($responseFormat) |
---|
230 | { |
---|
231 | case 'rest': |
---|
232 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php'); |
---|
233 | $encoder = new PwgRestEncoder(); |
---|
234 | break; |
---|
235 | case 'php': |
---|
236 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php'); |
---|
237 | $encoder = new PwgSerialPhpEncoder(); |
---|
238 | break; |
---|
239 | case 'json': |
---|
240 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php'); |
---|
241 | $encoder = new PwgJsonEncoder(); |
---|
242 | break; |
---|
243 | case 'xmlrpc': |
---|
244 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php'); |
---|
245 | $encoder = new PwgXmlRpcEncoder(); |
---|
246 | break; |
---|
247 | } |
---|
248 | $service->setEncoder($responseFormat, $encoder); |
---|
249 | } |
---|
250 | |
---|
251 | set_make_full_url(); |
---|
252 | $service->run(); |
---|
253 | |
---|
254 | ?> |
---|