source: trunk/ws.php @ 1781

Last change on this file since 1781 was 1781, checked in by rvelices, 18 years ago

web services:

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 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 1781 2007-02-06 01:02:06Z rvelices $
8// | last update   : $Date: 2007-02-06 01:02:06 +0000 (Tue, 06 Feb 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Rev: 1781 $
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.session.getStatus', 'ws_session_getStatus', null, '' );
85  $service->addMethod('pwg.session.login', 'ws_session_login',
86    array('username', 'password'),
87    'POST method only' );
88  $service->addMethod('pwg.session.logout', 'ws_session_logout', null, '');
89
90  $service->addMethod('pwg.tags.getList', 'ws_tags_getList',
91    array('sort_by_counter' => array('default' =>false) ),
92    'retrieves a list of available tags');
93  $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages',
94      array(
95        'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
96        'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
97        'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
98        'tag_mode_and'=>array('default'=>false),
99        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
100        'page' => array('default'=>0),
101        'order' => array('default'=>null),
102        'f_min_rate' => array( 'default'=> null ),
103        'f_max_rate' => array( 'default'=> null ),
104        'f_min_hit' => array( 'default'=> null ),
105        'f_max_hit' => array( 'default'=> null ),
106        'f_min_date_available' => array( 'default'=> null ),
107        'f_max_date_available' => array( 'default'=> null ),
108        'f_min_date_created' => array( 'default'=> null ),
109        'f_max_date_created' => array( 'default'=> null ),
110        'f_min_ratio' => array( 'default'=> null ),
111        'f_max_ratio' => array( 'default'=> null ),
112        'f_with_thumbnail' => array( 'default'=> false ),
113      ),
114      'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
115    );
116}
117
118add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
119
120
121add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
122
123$calling_partner_id = '';
124$requestFormat = null;
125$responseFormat = null;
126
127if ( isset($_GET['partner']) )
128{
129  $calling_partner_id = $_GET['partner'];
130}
131if ( isset($_GET['format']) )
132{
133  $responseFormat = $_GET['format'];
134}
135
136if ( isset($HTTP_RAW_POST_DATA) )
137{
138  $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
139  if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 )
140  {
141  }
142  else
143  {
144    $requestFormat = "json";
145  }
146}
147else
148{
149  $requestFormat = "rest";
150}
151
152if ( !isset($responseFormat) and isset($requestFormat) )
153{
154  $responseFormat = $requestFormat;
155}
156
157$service = new PwgServer();
158
159if (!is_null($requestFormat))
160{
161  $handler = null;
162  switch ($requestFormat)
163  {
164    case 'rest':
165      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
166      $handler = new PwgRestRequestHandler();
167      break;
168  }
169  $service->setHandler($requestFormat, $handler);
170}
171
172if (!is_null($responseFormat))
173{
174  $encoder = null;
175  switch ($responseFormat)
176  {
177    case 'rest':
178      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
179      $encoder = new PwgRestEncoder();
180      break;
181    case 'php':
182      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
183      $encoder = new PwgSerialPhpEncoder();
184      break;
185    case 'json':
186      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
187      $encoder = new PwgJsonEncoder();
188      break;
189    case 'xmlrpc':
190      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
191      $encoder = new PwgXmlRpcEncoder();
192      break;
193  }
194  $service->setEncoder($responseFormat, $encoder);
195}
196
197set_make_full_url();
198$service->run();
199
200?>
Note: See TracBrowser for help on using the repository browser.