Changeset 4347 for trunk/include


Ignore:
Timestamp:
Nov 23, 2009, 12:58:44 AM (14 years ago)
Author:
plg
Message:

merge r4344 from branch 2.0 to trunk

feature 1051: new API method pwg.images.checkFiles. This method will be useful
before asking for an update on photo files.

Enhancement in code factorization.

File:
1 edited

Legend:

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

    r4346 r4347  
    990990function add_file($file_path, $type, $original_sum, $file_sum)
    991991{
    992   // resolve the $file_path depending on the $type
    993   if ('thumb' == $type) {
    994     $file_path = get_thumbnail_location(
    995       array(
    996         'path' => $file_path,
    997         'tn_ext' => 'jpg',
    998         )
    999       );
    1000   }
    1001 
    1002   if ('high' == $type) {
    1003     @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    1004     $file_path = get_high_location(
    1005       array(
    1006         'path' => $file_path,
    1007         'has_high' => 'true'
    1008         )
    1009       );
    1010   }
     992  $file_path = file_path_for_type($file_path, $type);
    1011993
    1012994  $upload_dir = dirname($file_path);
     
    15021484}
    15031485
     1486function ws_images_checkFiles($params, &$service)
     1487{
     1488  if (!is_admin() or is_adviser())
     1489  {
     1490    return new PwgError(401, 'Access denied');
     1491  }
     1492
     1493  // input parameters
     1494  //
     1495  // image_id
     1496  // thumbnail_sum
     1497  // file_sum
     1498  // high_sum
     1499
     1500  $params['image_id'] = (int)$params['image_id'];
     1501  if ($params['image_id'] <= 0)
     1502  {
     1503    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
     1504  }
     1505
     1506  $query = '
     1507SELECT
     1508    path
     1509  FROM '.IMAGES_TABLE.'
     1510  WHERE id = '.$params['image_id'].'
     1511;';
     1512  $result = pwg_query($query);
     1513  if (mysql_num_rows($result) == 0) {
     1514    return new PwgError(404, "image_id not found");
     1515  }
     1516  list($path) = mysql_fetch_row($result);
     1517
     1518  $ret = array();
     1519
     1520  foreach (array('thumb', 'file', 'high') as $type) {
     1521    $param_name = $type;
     1522    if ('thumb' == $type) {
     1523      $param_name = 'thumbnail';
     1524    }
     1525
     1526    if (isset($params[$param_name.'_sum'])) {
     1527      $type_path = file_path_for_type($path, $type);
     1528      if (!is_file($type_path)) {
     1529        $ret[$param_name] = 'missing';
     1530      }
     1531      else {
     1532        if (md5_file($type_path) != $params[$param_name.'_sum']) {
     1533          $ret[$param_name] = 'differs';
     1534        }
     1535        else {
     1536          $ret[$param_name] = 'equals';
     1537        }
     1538      }
     1539    }
     1540  }
     1541
     1542  return $ret;
     1543}
     1544
     1545function file_path_for_type($file_path, $type='thumb')
     1546{
     1547  // resolve the $file_path depending on the $type
     1548  if ('thumb' == $type) {
     1549    $file_path = get_thumbnail_location(
     1550      array(
     1551        'path' => $file_path,
     1552        'tn_ext' => 'jpg',
     1553        )
     1554      );
     1555  }
     1556
     1557  if ('high' == $type) {
     1558    @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     1559    $file_path = get_high_location(
     1560      array(
     1561        'path' => $file_path,
     1562        'has_high' => 'true'
     1563        )
     1564      );
     1565  }
     1566
     1567  return $file_path;
     1568}
     1569
    15041570function ws_images_setInfo($params, &$service)
    15051571{
Note: See TracChangeset for help on using the changeset viewer.