source: trunk/ws.php @ 1837

Last change on this file since 1837 was 1837, checked in by rvelices, 17 years ago

web service: added method to query search elements
picture: small correction on my last commit
monthly calendar nice view: always use getimagesize instead of guessing the size
query search: improved results (filename is searched separately) and sometimes less sql queries than before

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | branch        : BSF (Best So Far)
7// | file          : $Id: ws.php 1837 2007-02-19 16:25:47Z rvelices $
8// | last update   : $Date: 2007-02-19 16:25:47 +0000 (Mon, 19 Feb 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Rev: 1837 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27define ('PHPWG_ROOT_PATH', './');
28
29include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
30include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');
31
32if ( !$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 */
40function ws_addDefaultMethods( $arr )
41{
42  include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
43  global $conf;
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.getInfo', 'ws_images_getInfo',
81      array('image_id'),
82      'retrieves information about the given photo' );
83
84  $service->addMethod('pwg.images.search', 'ws_images_search',
85      array(
86        'query'=>array(),
87        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
88        'page' => array('default'=>0),
89        'order' => array('default'=>null),
90        'f_min_rate' => array( 'default'=> null ),
91        'f_max_rate' => array( 'default'=> null ),
92        'f_min_hit' => array( 'default'=> null ),
93        'f_max_hit' => array( 'default'=> null ),
94        'f_min_date_available' => array( 'default'=> null ),
95        'f_max_date_available' => array( 'default'=> null ),
96        'f_min_date_created' => array( 'default'=> null ),
97        'f_max_date_created' => array( 'default'=> null ),
98        'f_min_ratio' => array( 'default'=> null ),
99        'f_max_ratio' => array( 'default'=> null ),
100        'f_with_thumbnail' => array( 'default'=> false ),
101      ),
102      'Returns elements for the corresponding query search.'
103    );
104
105  $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' );
106  $service->addMethod('pwg.session.login', 'ws_session_login',
107    array('username', 'password'),
108    'POST method only' );
109  $service->addMethod('pwg.session.logout', 'ws_session_logout', null, '');
110
111  $service->addMethod('pwg.tags.getList', 'ws_tags_getList',
112    array('sort_by_counter' => array('default' =>false) ),
113    'retrieves a list of available tags');
114  $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages',
115      array(
116        'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
117        'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
118        'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
119        'tag_mode_and'=>array('default'=>false),
120        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
121        'page' => array('default'=>0),
122        'order' => array('default'=>null),
123        'f_min_rate' => array( 'default'=> null ),
124        'f_max_rate' => array( 'default'=> null ),
125        'f_min_hit' => array( 'default'=> null ),
126        'f_max_hit' => array( 'default'=> null ),
127        'f_min_date_available' => array( 'default'=> null ),
128        'f_max_date_available' => array( 'default'=> null ),
129        'f_min_date_created' => array( 'default'=> null ),
130        'f_max_date_created' => array( 'default'=> null ),
131        'f_min_ratio' => array( 'default'=> null ),
132        'f_max_ratio' => array( 'default'=> null ),
133        'f_with_thumbnail' => array( 'default'=> false ),
134      ),
135      'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
136    );
137}
138
139add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
140
141
142add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
143
144$calling_partner_id = '';
145$requestFormat = null;
146$responseFormat = null;
147
148if ( isset($_GET['partner']) )
149{
150  $calling_partner_id = $_GET['partner'];
151}
152if ( isset($_GET['format']) )
153{
154  $responseFormat = $_GET['format'];
155}
156
157if ( isset($HTTP_RAW_POST_DATA) )
158{
159  $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
160  if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 )
161  {
162  }
163  else
164  {
165    $requestFormat = "json";
166  }
167}
168else
169{
170  $requestFormat = "rest";
171}
172
173if ( !isset($responseFormat) and isset($requestFormat) )
174{
175  $responseFormat = $requestFormat;
176}
177
178$service = new PwgServer();
179
180if (!is_null($requestFormat))
181{
182  $handler = null;
183  switch ($requestFormat)
184  {
185    case 'rest':
186      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
187      $handler = new PwgRestRequestHandler();
188      break;
189  }
190  $service->setHandler($requestFormat, $handler);
191}
192
193if (!is_null($responseFormat))
194{
195  $encoder = null;
196  switch ($responseFormat)
197  {
198    case 'rest':
199      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
200      $encoder = new PwgRestEncoder();
201      break;
202    case 'php':
203      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
204      $encoder = new PwgSerialPhpEncoder();
205      break;
206    case 'json':
207      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
208      $encoder = new PwgJsonEncoder();
209      break;
210    case 'xmlrpc':
211      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
212      $encoder = new PwgXmlRpcEncoder();
213      break;
214  }
215  $service->setEncoder($responseFormat, $encoder);
216}
217
218set_make_full_url();
219$service->run();
220
221?>
Note: See TracBrowser for help on using the repository browser.