Changeset 2516 for trunk/include


Ignore:
Timestamp:
Sep 11, 2008, 3:20:25 AM (16 years ago)
Author:
rvelices
Message:

remove ws access table/partners functionality

Location:
trunk/include
Files:
3 edited

Legend:

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

    r2451 r2516  
    618618// Maximum number of images to be returned foreach call to the web service
    619619$conf['ws_max_images_per_page'] = 500;
    620 
    621 // On Access control false / Admim Web Service need Php cURL extension
    622 // Controls are done on public basis or
    623 // if connected on member authorization basis
    624 $conf['ws_access_control'] = false;
    625 
    626 // Additionnal controls are made based on Web Service Access Table
    627 // Max returned rows number ( > 0 )
    628 $conf['ws_allowed_limit'] = array(1,2,3,5,10,25);
    629 
    630 // By default can be delayed by 0, 1, 2, 3, 5, 7, 14 or 30 days
    631 // 0 it's Now(), don't remove that one
    632 $conf['ws_postponed_start'] = array(0,1,2,3,5,7,14,30); /* In days */
    633 
    634 // By default 10, 5, 2, 1 year(s) or 6, 3, 1 month(s)
    635 // or 15, 10, 7, 5, 1, 0 day(s)
    636 // 0 it's temporary closed (Useful for one access)
    637 $conf['ws_durations'] = array(3650,1825,730,365,182,91,30,15,10,7,5,1,0);
    638620
    639621// +-----------------------------------------------------------------------+
  • trunk/include/constants.php

    r2343 r2516  
    105105if (!defined('PLUGINS_TABLE'))
    106106  define('PLUGINS_TABLE', $prefixeTable.'plugins');
    107 if (!defined('WEB_SERVICES_ACCESS_TABLE'))
    108   define('WEB_SERVICES_ACCESS_TABLE', $prefixeTable.'ws_access');
    109107if (!defined('OLD_PERMALINKS_TABLE'))
    110108  define('OLD_PERMALINKS_TABLE', $prefixeTable.'old_permalinks');
  • trunk/include/ws_functions.inc.php

    r2511 r2516  
    4343  }
    4444
    45   if ( !$conf['ws_access_control'] )
    46   {
    47     return $res; // No controls are requested
    48   }
    49   $query = '
    50 SELECT * FROM '.WEB_SERVICES_ACCESS_TABLE."
    51  WHERE `name` = '$calling_partner_id'
    52    AND NOW() <= end; ";
    53   $result = pwg_query($query);
    54   $row = mysql_fetch_assoc($result);
    55   if ( empty($row) )
    56   {
    57     return new PwgError(403, 'Partner id does not exist or is expired');
    58   }
    59   if ( !empty($row['request'])
    60       and strpos($methodName, $row['request'])==false
    61       and strpos($methodName, 'session')==false
    62       and strpos($methodName, 'getVersion')==false )
    63   { // session and getVersion are allowed to diagnose any failure reason
    64     return new PwgError(403, 'Method not allowed');
    65   }
    66 
    6745  return $res;
    68 }
    69 
    70 /**
    71  * ws_addControls
    72  * returns additionnal controls if requested
    73  * usable for 99% of Web Service methods
    74  *
    75  * - Args
    76  * $methodName: is the requested method
    77  * $partner: is the key
    78  * $tbl_name: is the alias_name in the query (sometimes called correlation name)
    79  *            null if !getting picture informations
    80  * - Logic
    81  * Access_control is not active: Return
    82  * Key is incorrect: Return 0 = 1 (False condition for MySQL)
    83  * One of Params doesn't match with type of request: return 0 = 1 again
    84  * Access list(id/cat/tag) is converted in expended image-id list
    85  * image-id list: converted to an in-where-clause
    86  *
    87  * The additionnal in-where-clause is return
    88  */
    89 function ws_addControls( $methodName, &$params, $tbl_name )
    90 {
    91   global $conf, $calling_partner_id;
    92   if ( !$conf['ws_access_control'] or !isset($calling_partner_id) )
    93   {
    94     return '1=1'; // No controls are requested
    95   }
    96 
    97 // Is it an active Partner?
    98   $query = '
    99 SELECT * FROM '.WEB_SERVICES_ACCESS_TABLE."
    100  WHERE `name` = '$calling_partner_id'
    101    AND NOW() <= end; ";
    102 $result = pwg_query($query);
    103   if ( mysql_num_rows( $result ) == 0 )
    104   {
    105     return '0=1'; // Unknown partner or Obsolate agreement
    106   }
    107 
    108   $row = mysql_fetch_array($result);
    109 
    110 // Overide general object limit
    111   $params['per_page'] = $row['limit'];
    112 
    113 // Target restrict
    114 // 3 cases: list, cat or tag
    115 // Behind / we could found img-ids, cat-ids or tag-ids
    116   $target = $row['access'];
    117   if ( $target == '')
    118   {
    119     return '1=1'; // No controls are requested
    120   }
    121   list($type, $str_ids) = explode('/',$target); // Find type list
    122 
    123 // (array) 1,2,21,3,22,4,5,9-12,6,11,12,13,2,4,6,
    124   $arr_ids = expand_id_list( explode( ',',$str_ids ) );
    125   $addings = implode(',', $arr_ids);
    126 // (string) 1,2,3,4,5,6,9,10,11,12,13,21,22,
    127   if ( $type == 'list')
    128   {
    129     return $tbl_name . 'id IN ( ' . $addings . ' ) ';
    130   }
    131 
    132   if ( $type == 'cat' )
    133   {
    134     $addings = implode(',', get_image_ids_for_cats($arr_ids));
    135     return $tbl_name . 'id IN ( ' . $addings . ' ) ';
    136   }
    137 
    138   if ( $type == 'tag' )
    139   {
    140     $addings = implode(',', get_image_ids_for_tags($arr_ids, 'OR'));
    141     return $tbl_name . 'id IN ( ' . $addings . ' ) ';
    142   }
    143   // Unmanaged new type?
    144   return ' 0 = 1 '; // ???
    14546}
    14647
     
    372273        ), null, true
    373274      );
    374     $where_clauses[] = ws_addControls( 'categories.getImages', $params, 'i.' );
    375275
    376276    $order_by = ws_std_image_sql_order($params, 'i.');
     
    610510      array('visible_images' => 'id'),
    611511      ' AND'
    612     ).' AND '.
    613     ws_addControls( 'images.getInfo', $params, '' ).'
    614 LIMIT 1;';
     512    ).'
     513LIMIT 1';
    615514
    616515  $image_row = mysql_fetch_assoc(pwg_query($query));
     
    11841083      );
    11851084    $where_clauses[] = 'id IN ('.implode(',',$image_ids).')';
    1186     $where_clauses[] = ws_addControls( 'tags.getImages', $params, 'i.' );
    11871085
    11881086    $order_by = ws_std_image_sql_order($params);
     
    12671165}
    12681166
    1269 
    1270 /**
    1271  * expand_id_list($ids) convert a human list expression to a full ordered list
    1272  * example : expand_id_list( array(5,2-3,2) ) returns array( 2, 3, 5)
    1273  * */
    1274 function expand_id_list($ids)
    1275 {
    1276   $tid = array();
    1277   foreach ( $ids as $id )
    1278   {
    1279     if ( is_numeric($id) )
    1280     {
    1281       $tid[] = (int) $id;
    1282     }
    1283     else
    1284     {
    1285       $range = explode( '-', $id );
    1286       if ( is_numeric($range[0]) and is_numeric($range[1]) )
    1287       {
    1288         $from = min($range[0],$range[1]);
    1289         $to = max($range[0],$range[1]);
    1290         for ($i = $from; $i <= $to; $i++)
    1291         {
    1292           $tid[] = (int) $i;
    1293         }
    1294       }
    1295     }
    1296   }
    1297   $result = array_unique ($tid); // remove duplicates...
    1298   sort ($result);
    1299   return $result;
    1300 }
    1301 
    1302 
    1303 /**
    1304  * converts a cat-ids array in image-ids array
    1305  * FIXME Function which should already exist somewhere else
    1306  * */
    1307 function get_image_ids_for_cats($cat_ids)
    1308 {
    1309   $cat_list = implode(',', $cat_ids);
    1310   $ret_ids = array();
    1311   $query = '
    1312   SELECT DISTINCT image_id
    1313     FROM '.IMAGE_CATEGORY_TABLE.'
    1314   WHERE category_id in ('.$cat_list.')
    1315   ;';
    1316   return array_from_query($query, 'image_id');
    1317 }
    1318 
    13191167?>
Note: See TracChangeset for help on using the changeset viewer.