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