Changeset 1670


Ignore:
Timestamp:
Dec 16, 2006, 1:14:59 PM (17 years ago)
Author:
vdigital
Message:

Externalization of common functions of web service.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/ws_checker.php

    r1663 r1670  
    2626// +-----------------------------------------------------------------------+
    2727
    28 // +-----------------------------------------------------------------------+
    29 // |                             functions                                 |
    30 // +-----------------------------------------------------------------------+
    31 
    32 // Function to migrate be useful for ws
    33 function official_req()
    34 {
    35 return array(
    36     'random'                              /* Random order */
    37   , 'list'               /* list on MBt & z0rglub request */
    38   , 'maxviewed'             /* hit > 0 and hit desc order */
    39   , 'recent'        /* recent = Date_available desc order */
    40   , 'highrated'            /* avg_rate > 0 and desc order */
    41   , 'oldest'                  /* Date_available asc order */
    42   , 'lessviewed'                         /* hit asc order */
    43   , 'lowrated'                      /* avg_rate asc order */
    44   , 'undescribed'                  /* description missing */
    45   , 'unnamed'                         /* new name missing */
    46   , 'portraits'     /* width < height (portrait oriented) */
    47   , 'landscapes'   /* width > height (landscape oriented) */
    48   , 'squares'             /* width ~ height (square form) */
    49 );
    50 }
    51 
    52 function expand_id_list($ids)
    53 {
    54     $tid = array();
    55     foreach ( $ids as $id )
    56     {
    57       if ( is_numeric($id) )
    58       {
    59         $tid[] = (int) $id;
    60       }
    61       else
    62       {
    63         $range = explode( '-', $id );
    64         if ( is_numeric($range[0]) and is_numeric($range[1]) )
    65         {
    66           $from = min($range[0],$range[1]);
    67           $to = max($range[0],$range[1]);
    68           for ($i = $from; $i <= $to; $i++)
    69           {
    70             $tid[] = (int) $i;
    71           }
    72         }
    73       }
    74     }
    75     $result = array_unique ($tid); // remove duplicates...
    76     sort ($result);
    77     return $result;
    78 }
    79 
    80 function check_target($list)
    81 {
    82   if ( $list !== '' )
    83   {
    84     $type = explode('/',$list); // Find type list
    85     if ( !in_array($type[0],array('list','cat','tag') ) )
    86     {
    87       $type[0] = 'list'; // Assume an id list
    88     }
    89     $ids = explode( ',',$type[1] );
    90     $list = $type[0] . '/';
    91 
    92     // 1,2,21,3,22,4,5,9-12,6,11,12,13,2,4,6,
    93 
    94     $result = expand_id_list( $ids );
    95 
    96     // 1,2,3,4,5,6,9,10,11,12,13,21,22,
    97     // I would like
    98     // 1-6,9-13,21-22
    99     $serial[] = $result[0]; // To be shifted                     
    100     foreach ($result as $k => $id)
    101     {
    102       $next_less_1 = (isset($result[$k + 1]))? $result[$k + 1] - 1:-1;
    103       if ( $id == $next_less_1 and end($serial)=='-' )
    104       { // nothing to do
    105       }
    106       elseif ( $id == $next_less_1 )
    107       {
    108         $serial[]=$id;
    109         $serial[]='-';
    110       }
    111       else
    112       {
    113         $serial[]=$id;  // end serie or non serie
    114       }
    115     }
    116     $null = array_shift($serial); // remove first value
    117     $list .= array_shift($serial); // add the real first one
    118     $separ = ',';
    119     foreach ($serial as $id)
    120     {
    121       $list .= ($id=='-') ? '' : $separ . $id;
    122       $separ = ($id=='-') ? '-':','; // add comma except if hyphen
    123     }
    124   }
    125   return $list;
    126 }
    127 
    12828// Next evolution...
    12929// Out of parameter WS management
  • trunk/include/functions.inc.php

    r1649 r1670  
    3535include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' );
    3636include_once( PHPWG_ROOT_PATH .'include/functions_plugins.inc.php' );
     37include_once( PHPWG_ROOT_PATH .'include/functions_webserv.inc.php' );
    3738
    3839//----------------------------------------------------------- generic functions
  • trunk/web_service.php

    r1664 r1670  
    121121
    122122
    123 // FIXME
    124 
     123// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME
    125124
    126125// Check keywords
    127 //
     126// Key and pos are correct
     127// &acc=cat/23,25-32&req=landscape&lim=5&tpl=myxml
     128
     129
     130
     131
     132
    128133
    129134// Check requested XML template
     
    141146
    142147
    143 
     148// Old code below
    144149
    145150//------------ Main security strategy ---------------------
Note: See TracChangeset for help on using the changeset viewer.