aboutsummaryrefslogtreecommitdiffstats
path: root/ws.php
blob: a196d49e0d615933d7c76a78fee52fdcf0e5ddd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery                           |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch        : BSF (Best So Far)
// | file          : $Id$
// | last update   : $Date$
// | last modifier : $Author$
// | revision      : $Rev$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+

define ('PHPWG_ROOT_PATH', './');

include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
include_once(PHPWG_ROOT_PATH.'include/ws_core.inc.php');

if ( !$conf['allow_web_services'] )
{
  page_forbidden('Web services are disabled');
}

/**
 * event handler that registers standard methods with the web service
 */
function ws_addDefaultMethods( $arr )
{
  include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
  global $conf;
  $service = &$arr[0];
  $service->addMethod('pwg.getVersion', 'ws_getVersion', null,
      'retrieves the PWG version');

  $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages',
      array(
        'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY),
        'recursive'=>array('default'=>false),
        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
        'page' => array('default'=>0),
        'order' => array('default'=>null),
        'f_min_rate' => array( 'default'=> null ),
        'f_max_rate' => array( 'default'=> null ),
        'f_min_hit' => array( 'default'=> null ),
        'f_max_hit' => array( 'default'=> null ),
        'f_min_date_available' => array( 'default'=> null ),
        'f_max_date_available' => array( 'default'=> null ),
        'f_min_date_created' => array( 'default'=> null ),
        'f_max_date_created' => array( 'default'=> null ),
        'f_min_ratio' => array( 'default'=> null ),
        'f_max_ratio' => array( 'default'=> null ),
        'f_with_thumbnail' => array( 'default'=> false ),
      ),
      'Returns elements for the corresponding categories.
<br/><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array.
<br/><b>order</b> comma separated fields for sorting (file,id, average_rate,...)'
    );

  $service->addMethod('pwg.categories.getList', 'ws_categories_getList',
      array(
        'cat_id' => array('default'=>0),
        'recursive' => array('default'=>false),
        'public' => array('default'=>false),
      ),
      'retrieves a list of categories' );

  $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo',
      array('image_id'),
      'retrieves information about the given photo' );

  $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' );
  $service->addMethod('pwg.session.login', 'ws_session_login',
    array('username', 'password'),
    'POST method only' );
  $service->addMethod('pwg.session.logout', 'ws_session_logout', null, '');

  $service->addMethod('pwg.tags.getList', 'ws_tags_getList',
    array('sort_by_counter' => array('default' =>false) ),
    'retrieves a list of available tags');
  $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages',
      array(
        'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
        'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
        'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
        'tag_mode_and'=>array('default'=>false),
        'per_page' => array('default'=>100, 'maxValue'=>$conf['ws_max_images_per_page']),
        'page' => array('default'=>0),
        'order' => array('default'=>null),
        'f_min_rate' => array( 'default'=> null ),
        'f_max_rate' => array( 'default'=> null ),
        'f_min_hit' => array( 'default'=> null ),
        'f_max_hit' => array( 'default'=> null ),
        'f_min_date_available' => array( 'default'=> null ),
        'f_max_date_available' => array( 'default'=> null ),
        'f_min_date_created' => array( 'default'=> null ),
        'f_max_date_created' => array( 'default'=> null ),
        'f_min_ratio' => array( 'default'=> null ),
        'f_max_ratio' => array( 'default'=> null ),
        'f_with_thumbnail' => array( 'default'=> false ),
      ),
      'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
    );
}

add_event_handler('ws_add_methods', 'ws_addDefaultMethods');


add_event_handler('ws_invoke_allowed', 'ws_isInvokeAllowed', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);

$calling_partner_id = '';
$requestFormat = null;
$responseFormat = null;

if ( isset($_GET['partner']) )
{
  $calling_partner_id = $_GET['partner'];
}
if ( isset($_GET['format']) )
{
  $responseFormat = $_GET['format'];
}

if ( isset($HTTP_RAW_POST_DATA) )
{
  $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
  if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 )
  {
  }
  else
  {
    $requestFormat = "json";
  }
}
else
{
  $requestFormat = "rest";
}

if ( !isset($responseFormat) and isset($requestFormat) )
{
  $responseFormat = $requestFormat;
}

$service = new PwgServer();

if (!is_null($requestFormat))
{
  $handler = null;
  switch ($requestFormat)
  {
    case 'rest':
      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
      $handler = new PwgRestRequestHandler();
      break;
  }
  $service->setHandler($requestFormat, $handler);
}

if (!is_null($responseFormat))
{
  $encoder = null;
  switch ($responseFormat)
  {
    case 'rest':
      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
      $encoder = new PwgRestEncoder();
      break;
    case 'php':
      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
      $encoder = new PwgSerialPhpEncoder();
      break;
    case 'json':
      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
      $encoder = new PwgJsonEncoder();
      break;
    case 'xmlrpc':
      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
      $encoder = new PwgXmlRpcEncoder();
      break;
  }
  $service->setEncoder($responseFormat, $encoder);
}

set_make_full_url();
$service->run();

?>