source: trunk/ws.php @ 1750

Last change on this file since 1750 was 1750, checked in by rvelices, 17 years ago
  • plugins with own independent scripts work now (cookie_path and url root are

correct)

  • prepare a bit some url functions so that later we can fully embed pwg in

scripts located outside pwg

  • remove some unnecessary language strings
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 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 1750 2007-01-24 05:07:08Z rvelices $
8// | last update   : $Date: 2007-01-24 05:07:08 +0000 (Wed, 24 Jan 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Rev: 1750 $
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
32function ws_addDefaultMethods( $arr )
33{
34  include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php');
35  $service = &$arr[0];
36  $service->addMethod('pwg.getVersion', 'ws_getVersion', null,
37      'retrieves the PWG version');
38
39  $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages',
40      array(
41        'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY),
42        'recursive'=>array('default'=>false),
43        'per_page' => array('default'=>100),
44        'page' => array('default'=>0),
45        'order' => array('default'=>null),
46        'f_min_rate' => array( 'default'=> null ),
47        'f_max_rate' => array( 'default'=> null ),
48        'f_min_hit' => array( 'default'=> null ),
49        'f_max_hit' => array( 'default'=> null ),
50        'f_min_date_available' => array( 'default'=> null ),
51        'f_max_date_available' => array( 'default'=> null ),
52        'f_min_date_created' => array( 'default'=> null ),
53        'f_max_date_created' => array( 'default'=> null ),
54        'f_min_ratio' => array( 'default'=> null ),
55        'f_max_ratio' => array( 'default'=> null ),
56        'f_with_thumbnail' => array( 'default'=> false ),
57      ),
58      'Returns elements for the corresponding categories.
59<br/><b>cat_id</b> can be empty if <b>recursive</b> is true. Can be sent as an array.
60<br/><b>order</b> comma separated fields for sorting (file,id, average_rate,...)'
61    );
62
63  $service->addMethod('pwg.categories.getList', 'ws_categories_getList',
64      array(
65        'cat_id' => array('default'=>0),
66        'recursive' => array('default'=>false),
67        'public' => array('default'=>false),
68      ),
69      'retrieves a list of categories' );
70
71  $service->addMethod('pwg.images.getInfo', 'ws_images_getInfo',
72      array('image_id'),
73      'retrieves information about the given photo' );
74
75  $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' );
76  $service->addMethod('pwg.session.login', 'ws_session_login',
77    array('username', 'password'),
78    'POST method only' );
79  $service->addMethod('pwg.session.logout', 'ws_session_logout', null, '');
80
81  $service->addMethod('pwg.tags.getList', 'ws_tags_getList',
82    array('sort_by_counter' => array('default' =>false) ),
83    'retrieves a list of available tags');
84  $service->addMethod('pwg.tags.getImages', 'ws_tags_getImages',
85      array(
86        'tag_id'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
87        'tag_url_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
88        'tag_name'=>array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY ),
89        'tag_mode_and'=>array('default'=>false),
90        'per_page' => array('default'=>100),
91        'page' => array('default'=>0),
92        'order' => array('default'=>null),
93        'f_min_rate' => array( 'default'=> null ),
94        'f_max_rate' => array( 'default'=> null ),
95        'f_min_hit' => array( 'default'=> null ),
96        'f_max_hit' => array( 'default'=> null ),
97        'f_min_date_available' => array( 'default'=> null ),
98        'f_max_date_available' => array( 'default'=> null ),
99        'f_min_date_created' => array( 'default'=> null ),
100        'f_max_date_created' => array( 'default'=> null ),
101        'f_min_ratio' => array( 'default'=> null ),
102        'f_max_ratio' => array( 'default'=> null ),
103        'f_with_thumbnail' => array( 'default'=> false ),
104      ),
105      'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
106    );
107}
108
109add_event_handler('ws_add_methods', 'ws_addDefaultMethods' );
110
111$requestFormat = null;
112$responseFormat = null;
113
114if ( isset($_GET['format']) )
115{
116  $responseFormat = $_GET['format'];
117}
118
119if ( isset($HTTP_RAW_POST_DATA) )
120{
121  $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
122  if ( strncmp($HTTP_RAW_POST_DATA, '<?xml', 5) == 0 )
123  {
124  }
125  else
126  {
127    $requestFormat = "json";
128  }
129}
130else
131{
132  $requestFormat = "rest";
133}
134
135if ( !isset($responseFormat) and isset($requestFormat) )
136{
137  $responseFormat = $requestFormat;
138}
139
140$service = new PwgServer();
141
142if (!is_null($requestFormat))
143{
144  $handler = null;
145  switch ($requestFormat)
146  {
147    case 'rest':
148      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_handler.php');
149      $handler = new PwgRestRequestHandler();
150      break;
151  }
152  $service->setHandler($requestFormat, $handler);
153}
154
155if (!is_null($responseFormat))
156{
157  $encoder = null;
158  switch ($responseFormat)
159  {
160    case 'rest':
161      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/rest_encoder.php');
162      $encoder = new PwgRestEncoder();
163      break;
164    case 'php':
165      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/php_encoder.php');
166      $encoder = new PwgSerialPhpEncoder();
167      break;
168    case 'json':
169      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/json_encoder.php');
170      $encoder = new PwgJsonEncoder();
171      break;
172    case 'xmlrpc':
173      include_once(PHPWG_ROOT_PATH.'include/ws_protocols/xmlrpc_encoder.php');
174      $encoder = new PwgXmlRpcEncoder();
175      break;
176  }
177  $service->setEncoder($responseFormat, $encoder);
178}
179
180set_make_full_url();
181$service->run();
182
183?>
Note: See TracBrowser for help on using the repository browser.