Changeset 1674 for trunk


Ignore:
Timestamp:
Dec 18, 2006, 7:44:11 AM (18 years ago)
Author:
vdigital
Message:

WEB Service: Some corrections but still an incomplete version.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_webserv.inc.php

    r1671 r1674  
    127127  return $list;
    128128}
     129
     130
     131// FIXME Function which could already exist somewhere else
     132function convert_catlist($cat_ids)
     133{
     134  $cat_list = implode(',', $cat_ids);
     135  $ret_ids = array();
     136  $query = '
     137  SELECT DISTINCT image_id
     138    FROM '.IMAGE_CATEGORY_TABLE.'
     139  WHERE category_id in ('.$cat_list.')
     140  ;';
     141  $result = pwg_query($query);
     142  while ($row = mysql_fetch_array($result))
     143  {
     144    $ret_ids[] = $row['image_id'];
     145  }
     146  return $ret_ids;
     147}
    129148?>
  • trunk/web_service.php

    r1670 r1674  
    2828include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
    2929
    30 if((!defined("PHPWG_ROOT_PATH")) or (!$conf['allow_web_services']))
     30if ( !$conf['allow_web_services'] )
    3131{
    3232  die('Hacking attempt!');
     
    5454// Check call process (Keyed call)
    5555//
    56 if (!isset($_get['key']))
     56
     57if (!isset($_GET['key']))
    5758{
    5859  die('Hacking attempt!');
    5960}
    60 if ( strlen($_get['key']) < 12 )
     61if ( strlen($_GET['key']) < 12 )
    6162{
    6263  die('Invalid key (Length issue)!');
     
    7071;';
    7172$active = mysql_fetch_array(pwg_query($query));
    72 if ($active='false')
     73if ( $active['value']=='false' )
    7374{
    7475  die('Web service is temporary inactive');
     
    7778// Look for partner_key
    7879//
    79 $key = $_get['key'];
     80$key = $_GET['key'];
    8081$key = ( strlen($key) > 20 ) ? substr($key,0,20) : $key;
    8182$len = strlen($key);
    82 &hash = 0;
    83 if (isset($_get['pos']))
    84 {
    85   $hash = (!is_numeric($hash)) ? 0 : $_get['pos'];
     83$hash = 0;
     84if (isset($_GET['pos']))
     85{
     86  $hash = (!is_numeric($_GET['pos'])) ? 0 : $_GET['pos'];
    8687  $hash = (int) $hash;
    8788  $hash = $hash % 12;
    8889}
    8990$query = '
    90 SELECT *
     91SELECT `id`, `name`, `access`, `start`, `end`, `request`,
     92  `high`, `normal`, `limit`, `comment`
    9193  FROM '.WEB_SERVICES_ACCESS_TABLE.'
    9294;';
     95
    9396$result = pwg_query($query);
    9497
     
    98101  {
    99102    $len = 0;
     103    $def = $row;
    100104    continue;
    101105  }
     
    105109  die('Invalid key!');
    106110}
     111
    107112// $def = Web service already defined partner access
    108 $def = $row;
     113
    109114//
    110115// Now, the partner will get a reply in time
     
    119124}
    120125
    121 
    122 
    123 // FIXME// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME
    124 
    125126// Check keywords
    126127// Key and pos are correct
    127128// &acc=cat/23,25-32&req=landscape&lim=5&tpl=myxml
    128 
     129$req_access ='';
     130if (isset($_GET['pos']))
     131{
     132  $req_access = check_target($_GET['acc']);
     133}
     134// on one hand $req_access, requested ids
     135$req_type = explode('/',$req_access);
     136$req_ids = explode( ',',$req_type[1] );
     137$req_list = expand_id_list( $req_ids );
     138if ($req_type[0]=='cat')
     139{
     140  $req_list = convert_catlist($req_list);
     141}
     142if ($req_type[0]=='tag')
     143{
     144  $req_list = get_image_ids_for_tags($req_list);
     145}
     146echo $def['name'].'<br />';
     147// on the other hand $def['access'], authorized default ids
     148$def_type = explode('/',$def['access']);
     149$def_ids = explode( ',',$def_type[1] );
     150$def_list = expand_id_list( $def_ids );
     151if ($def_type[0]=='cat')
     152{
     153  $def_list = convert_catlist($def_list);
     154}
     155if ($def_type[0]=='tag')
     156{
     157  $def_list = get_image_ids_for_tags($def_list);
     158}
     159
     160// could be no necessary, a surplus but
     161// Filter on forbidden_categories
     162$list = implode(',',$def_list);
     163
     164$ret_ids = array();
     165$query = '
     166SELECT DISTINCT image_id
     167  FROM '.IMAGE_CATEGORY_TABLE.'
     168WHERE  category_id NOT IN ('.$user['forbidden_categories'].')
     169  AND  image_id IN ('.$list.')
     170;';
     171$result = pwg_query($query);
     172while ($row = mysql_fetch_array($result))
     173{
     174  $ret_ids[] = $row['image_id'];
     175}
     176
     177// 77f1180bd215a0edf66939
     178// web_service.php?key=77f1180bd215&pos=3&acc=list/41,73,142,178,190,204,235-238&req=recent&lim=1&tpl=myxml
     179
     180echo 'temporaire<br />';
     181echo '$req_list' . var_dump($req_list);
     182
     183if (count($req_list)==0)
     184{
     185  $req_list = $def_list;
     186
     187//
     188  die('FIXME!');
     189// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME
     190
     191// Both may empty
     192// Both can be build on differents basis cat/tag/list
     193// Both have to be convert in list
     194// if no requested ids then is the complete default
     195// if some requested ids they must be in the complete default and only those
     196// will be transmitted.
    129197
    130198
Note: See TracChangeset for help on using the changeset viewer.