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.categories.getImages', 'ws_categories_getImages', |
---|
47 | array( |
---|
48 | 'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY), |
---|
49 | 'recursive'=>array('default'=>false), |
---|
50 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
51 | 'page' => array('default'=>0), |
---|
52 | 'order' => array('default'=>null), |
---|
53 | 'f_min_rate' => array( 'default'=> null ), |
---|
54 | 'f_max_rate' => array( 'default'=> null ), |
---|
55 | 'f_min_hit' => array( 'default'=> null ), |
---|
56 | 'f_max_hit' => array( 'default'=> null ), |
---|
57 | 'f_min_date_available' => array( 'default'=> null ), |
---|
58 | 'f_max_date_available' => array( 'default'=> null ), |
---|
59 | 'f_min_date_created' => array( 'default'=> null ), |
---|
60 | 'f_max_date_created' => array( 'default'=> null ), |
---|
61 | 'f_min_ratio' => array( 'default'=> null ), |
---|
62 | 'f_max_ratio' => array( 'default'=> null ), |
---|
63 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
64 | ), |
---|
65 | 'Returns elements for the corresponding categories. |
---|
66 | <br/><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array. |
---|
67 | <br/><b>order</b> comma separated fields for sorting (file,id, average_rate,...)' |
---|
68 | ); |
---|
69 | |
---|
70 | $service->addMethod('pwg.categories.getList', 'ws_categories_getList', |
---|
71 | array( |
---|
72 | 'cat_id' => array('default'=>0), |
---|
73 | 'recursive' => array('default'=>false), |
---|
74 | 'public' => array('default'=>false), |
---|
75 | ), |
---|
76 | 'retrieves a list of categories' ); |
---|
77 | |
---|
78 | $service->addMethod('pwg.images.addComment', 'ws_images_addComment', |
---|
79 | array( |
---|
80 | 'image_id' => array(), |
---|
81 | 'author' => array( 'default' => is_a_guest()? 'guest':$user['username']), |
---|
82 | 'content' => array(), |
---|
83 | 'key' => array(), |
---|
84 | ), |
---|
85 | 'add a comment to an image' ); |
---|
86 | |
---|
87 | $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo', |
---|
88 | array( |
---|
89 | 'image_id' => array(), |
---|
90 | 'comments_page' => array('default'=>0 ), |
---|
91 | 'comments_per_page' => array( |
---|
92 | 'default' => $conf['nb_comment_page'], |
---|
93 | 'maxValue' => 2*$conf['nb_comment_page'], |
---|
94 | ), |
---|
95 | ), |
---|
96 | 'retrieves information about the given photo' ); |
---|
97 | |
---|
98 | $service->addMethod('pwg.images.search', 'ws_images_search', |
---|
99 | array( |
---|
100 | 'query'=>array(), |
---|
101 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
102 | 'page' => array('default'=>0), |
---|
103 | 'order' => array('default'=>null), |
---|
104 | 'f_min_rate' => array( 'default'=> null ), |
---|
105 | 'f_max_rate' => array( 'default'=> null ), |
---|
106 | 'f_min_hit' => array( 'default'=> null ), |
---|
107 | 'f_max_hit' => array( 'default'=> null ), |
---|
108 | 'f_min_date_available' => array( 'default'=> null ), |
---|
109 | 'f_max_date_available' => array( 'default'=> null ), |
---|
110 | 'f_min_date_created' => array( 'default'=> null ), |
---|
111 | 'f_max_date_created' => array( 'default'=> null ), |
---|
112 | 'f_min_ratio' => array( 'default'=> null ), |
---|
113 | 'f_max_ratio' => array( 'default'=> null ), |
---|
114 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
115 | ), |
---|
116 | 'Returns elements for the corresponding query search.' |
---|
117 | ); |
---|
118 | $service->addMethod('pwg.images.setPrivacyLevel', 'ws_images_setPrivacyLevel', |
---|
119 | array( |
---|
120 | 'image_id' => array('flags'=>WS_PARAM_FORCE_ARRAY), |
---|
121 | 'level' => array('maxValue'=>$conf['available_permission_levels']), |
---|
122 | ), |
---|
123 | 'sets the privacy levels for the images' ); |
---|
124 | |
---|
125 | $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' ); |
---|
126 | $service->addMethod('pwg.session.login', 'ws_session_login', |
---|
127 | array('username', 'password'), |
---|
128 | 'POST method only' ); |
---|
129 | $service->addMethod('pwg.session.logout', 'ws_session_logout', null, ''); |
---|
130 | |
---|
131 | $service->addMethod('pwg.tags.getList', 'ws_tags_getList', |
---|
132 | array('sort_by_counter' => array('default' =>false) ), |
---|
133 | 'retrieves a list of available tags'); |
---|
134 | $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages', |
---|
135 | array( |
---|
136 | 'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
137 | 'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
138 | 'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ), |
---|
139 | 'tag_mode_and'=>array('default'=>false), |
---|
140 | 'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']), |
---|
141 | 'page' => array('default'=>0), |
---|
142 | 'order' => array('default'=>null), |
---|
143 | 'f_min_rate' => array( 'default'=> null ), |
---|
144 | 'f_max_rate' => array( 'default'=> null ), |
---|
145 | 'f_min_hit' => array( 'default'=> null ), |
---|
146 | 'f_max_hit' => array( 'default'=> null ), |
---|
147 | 'f_min_date_available' => array( 'default'=> null ), |
---|
148 | 'f_max_date_available' => array( 'default'=> null ), |
---|
149 | 'f_min_date_created' => array( 'default'=> null ), |
---|
150 | 'f_max_date_created' => array( 'default'=> null ), |
---|
151 | 'f_min_ratio' => array( 'default'=> null ), |
---|
152 | 'f_max_ratio' => array( 'default'=> null ), |
---|
153 | 'f_with_thumbnail' => array( 'default'=> false ), |
---|
154 | ), |
---|
155 | 'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. ' |
---|
156 | ); |
---|
157 | } |
---|
158 | |
---|
159 | add_event_handler('ws_add_methods', 'ws_addDefaultMethods'); |
---|
160 | |
---|
161 | |
---|
162 | add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
163 | |
---|
164 | $calling_partner_id = ''; |
---|
165 | $requestFormat = null; |
---|
166 | $responseFormat = null; |
---|
167 | |
---|
168 | if ( isset($_GET['partner']) ) |
---|
169 | { |
---|
170 | $calling_partner_id = $_GET['partner']; |
---|
171 | } |
---|
172 | if ( isset($_GET['format']) ) |
---|
173 | { |
---|
174 | $responseFormat = $_GET['format']; |
---|
175 | } |
---|
176 | |
---|
177 | if ( isset($HTTP_RAW_POST_DATA) ) |
---|
178 | { |
---|
179 | $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); |
---|
180 | if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 ) |
---|
181 | { |
---|
182 | } |
---|
183 | else |
---|
184 | { |
---|
185 | $requestFormat = "json"; |
---|
186 | } |
---|
187 | } |
---|
188 | else |
---|
189 | { |
---|
190 | $requestFormat = "rest"; |
---|
191 | } |
---|
192 | |
---|
193 | if ( !isset($responseFormat) and isset($requestFormat) ) |
---|
194 | { |
---|
195 | $responseFormat = $requestFormat; |
---|
196 | } |
---|
197 | |
---|
198 | $service = new PwgServer(); |
---|
199 | |
---|
200 | if (!is_null($requestFormat)) |
---|
201 | { |
---|
202 | $handler = null; |
---|
203 | switch ($requestFormat) |
---|
204 | { |
---|
205 | case 'rest': |
---|
206 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php'); |
---|
207 | $handler = new PwgRestRequestHandler(); |
---|
208 | break; |
---|
209 | } |
---|
210 | $service->setHandler($requestFormat, $handler); |
---|
211 | } |
---|
212 | |
---|
213 | if (!is_null($responseFormat)) |
---|
214 | { |
---|
215 | $encoder = null; |
---|
216 | switch ($responseFormat) |
---|
217 | { |
---|
218 | case 'rest': |
---|
219 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php'); |
---|
220 | $encoder = new PwgRestEncoder(); |
---|
221 | break; |
---|
222 | case 'php': |
---|
223 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php'); |
---|
224 | $encoder = new PwgSerialPhpEncoder(); |
---|
225 | break; |
---|
226 | case 'json': |
---|
227 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php'); |
---|
228 | $encoder = new PwgJsonEncoder(); |
---|
229 | break; |
---|
230 | case 'xmlrpc': |
---|
231 | include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php'); |
---|
232 | $encoder = new PwgXmlRpcEncoder(); |
---|
233 | break; |
---|
234 | } |
---|
235 | $service->setEncoder($responseFormat, $encoder); |
---|
236 | } |
---|
237 | |
---|
238 | set_make_full_url(); |
---|
239 | $service->run(); |
---|
240 | |
---|
241 | ?> |
---|