Changeset 1758


Ignore:
Timestamp:
Jan 27, 2007, 4:06:33 PM (17 years ago)
Author:
vdigital
Message:

Web Service Merge functions_webserv.inc.php into ws_functions.inc.php

(Next steps:

  • Revise ws_checker
  • Restrict Method need to be more generic maybe
  • Delete functions_webserv.inc.php
  • ...)
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/ws_checker.php

    r1745 r1758  
    3232//  -  Does any access return something really?
    3333//     Give a way to check to the webmaster...
    34 // These questions are one of module name explainations (checker).
     34// These questions are one of module name explanations (checker).
    3535
    3636if((!defined("PHPWG_ROOT_PATH")) or (!$conf['allow_web_services']))
     
    4040include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    4141
     42/**
     43 * include ws_functions in only managed from ws_checker but
     44 * if ws_methods would be generalized in the code this one would be promoted
     45 * somewhere else... Maybe very soon because it can be in plugins.
     46 * */
     47include_once( PHPWG_ROOT_PATH .'include/ws_functions.inc.php' );
     48
    4249// +-----------------------------------------------------------------------+
    4350// | Check Access and exit when user status is not ok                      |
    4451// +-----------------------------------------------------------------------+
    4552check_status(ACCESS_ADMINISTRATOR);
    46 
    4753
    4854// accepted queries
     
    6773$add_comment = htmlspecialchars( $_POST['add_comment'], ENT_QUOTES);
    6874if ( strlen($add_partner) < 8 )
    69 {
     75{ // TODO What? Complete with some MD5...
    7076}
    7177  $query = '
  • trunk/include/functions.inc.php

    r1748 r1758  
    3535include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' );
    3636include_once( PHPWG_ROOT_PATH .'include/functions_plugins.inc.php' );
    37 include_once( PHPWG_ROOT_PATH .'include/functions_webserv.inc.php' );
    3837
    3938//----------------------------------------------------------- generic functions
  • trunk/include/ws_functions.inc.php

    r1757 r1758  
    6060   AND NOW() <= end; ";
    6161$result = pwg_query($query);
    62   if ( mysql_num_rows( $result ) = 0 )
     62  if ( mysql_num_rows( $result ) == 0 )
    6363  {     
    6464    return ' 0 = 1 '; // Unknown partner or Obsolate agreement
     
    822822}
    823823
     824/**
     825 * official_req returns the managed requests list in array format
     826 * FIXME A New list need to be build for ws_checker.php
     827 * returns array of authrorized request/methods
     828 * */   
     829function official_req()
     830{
     831return array(
     832    'random'                              /* Random order */
     833  , 'list'               /* list on MBt & z0rglub request */
     834  , 'maxviewed'             /* hit > 0 and hit desc order */
     835  , 'recent'        /* recent = Date_available desc order */
     836  , 'highrated'            /* avg_rate > 0 and desc order */
     837  , 'oldest'                  /* Date_available asc order */
     838  , 'lessviewed'                         /* hit asc order */
     839  , 'lowrated'                      /* avg_rate asc order */
     840  , 'undescribed'                  /* description missing */
     841  , 'unnamed'                         /* new name missing */
     842  , 'portraits'     /* width < height (portrait oriented) */
     843  , 'landscapes'   /* width > height (landscape oriented) */
     844  , 'squares'             /* width ~ height (square form) */
     845);
     846}
     847
     848/**
     849 * expand_id_list($ids) convert a human list expression to a full ordered list
     850 * example : expand_id_list( array(5,2-3,2) ) returns array( 2, 3, 5)
     851 * */
     852function expand_id_list($ids)
     853{
     854    $tid = array();
     855    foreach ( $ids as $id )
     856    {
     857      if ( is_numeric($id) )
     858      {
     859        $tid[] = (int) $id;
     860      }
     861      else
     862      {
     863        $range = explode( '-', $id );
     864        if ( is_numeric($range[0]) and is_numeric($range[1]) )
     865        {
     866          $from = min($range[0],$range[1]);
     867          $to = max($range[0],$range[1]);
     868          for ($i = $from; $i <= $to; $i++)
     869          {
     870            $tid[] = (int) $i;
     871          }
     872        }
     873      }
     874    }
     875    $result = array_unique ($tid); // remove duplicates...
     876    sort ($result);
     877    return $result;
     878}
     879
     880/**
     881 * check_target($string) verifies and corrects syntax of target parameter
     882 * example : check_target(cat/23,24,24,24,25,27) returns cat/23-25,27
     883 * */
     884function check_target($list)
     885{
     886  if ( $list !== '' )
     887  {
     888    $type = explode('/',$list); // Find type list
     889    if ( !in_array($type[0],array('list','cat','tag') ) )
     890    {
     891      $type[0] = 'list'; // Assume an id list
     892    }
     893    $ids = explode( ',',$type[1] );
     894    $list = $type[0] . '/';
     895
     896    // 1,2,21,3,22,4,5,9-12,6,11,12,13,2,4,6,
     897
     898    $result = expand_id_list( $ids );
     899
     900    // 1,2,3,4,5,6,9,10,11,12,13,21,22,
     901    // I would like
     902    // 1-6,9-13,21-22
     903    $serial[] = $result[0]; // To be shifted                     
     904    foreach ($result as $k => $id)
     905    {
     906      $next_less_1 = (isset($result[$k + 1]))? $result[$k + 1] - 1:-1;
     907      if ( $id == $next_less_1 and end($serial)=='-' )
     908      { // nothing to do
     909      }
     910      elseif ( $id == $next_less_1 )
     911      {
     912        $serial[]=$id;
     913        $serial[]='-';
     914      }
     915      else
     916      {
     917        $serial[]=$id;  // end serie or non serie
     918      }
     919    }
     920    $null = array_shift($serial); // remove first value
     921    $list .= array_shift($serial); // add the real first one
     922    $separ = ',';
     923    foreach ($serial as $id)
     924    {
     925      $list .= ($id=='-') ? '' : $separ . $id;
     926      $separ = ($id=='-') ? '-':','; // add comma except if hyphen
     927    }
     928  }
     929  return $list;
     930}
     931
     932/**
     933 * converts a cat-ids array in image-ids array
     934 * FIXME Function which should already exist somewhere else
     935 * */ 
     936function get_image_ids_for_cats($cat_ids)
     937{
     938  $cat_list = implode(',', $cat_ids);
     939  $ret_ids = array();
     940  $query = '
     941  SELECT DISTINCT image_id
     942    FROM '.IMAGE_CATEGORY_TABLE.'
     943  WHERE category_id in ('.$cat_list.')
     944  ;';
     945  return $array_from_query($query, 'image_id');
     946}
     947
    824948?>
Note: See TracChangeset for help on using the changeset viewer.