Ignore:
Timestamp:
Feb 11, 2011, 11:57:23 PM (14 years ago)
Author:
plg
Message:

feature 2189 added: ability to update a photo (the JPEG/PNG file) with
pwg.images.addSimple, simply by adding an $image_id as argument.

File:
1 edited

Legend:

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

    r8728 r9191  
    13531353    return new PwgError(405, "This method requires HTTP POST");
    13541354  }
     1355 
     1356  $params['image_id'] = (int)$params['image_id'];
     1357  if ($params['image_id'] > 0)
     1358  {
     1359    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     1360
     1361    $query='
     1362SELECT *
     1363  FROM '.IMAGES_TABLE.'
     1364  WHERE id = '.$params['image_id'].'
     1365;';
     1366
     1367    $image_row = pwg_db_fetch_assoc(pwg_query($query));
     1368    if ($image_row == null)
     1369    {
     1370      return new PwgError(404, "image_id not found");
     1371    }
     1372  }
    13551373
    13561374  // category
    13571375  $params['category'] = (int)$params['category'];
    1358   if ($params['category'] <= 0)
     1376  if ($params['category'] <= 0 and $params['image_id'] <= 0)
    13591377  {
    13601378    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
     
    13671385    $_FILES['image']['tmp_name'],
    13681386    $_FILES['image']['name'],
    1369     array($params['category']),
    1370     8
     1387    $params['category'] > 0 ? array($params['category']) : null,
     1388    8,
     1389    $params['image_id'] > 0 ? $params['image_id'] : null
    13711390    );
    13721391
     
    14161435  }
    14171436
    1418   $query = '
     1437  $url_params = array('image_id' => $image_id);
     1438
     1439  if ($params['category'] > 0)
     1440  {
     1441    $query = '
    14191442SELECT id, name, permalink
    14201443  FROM '.CATEGORIES_TABLE.'
    14211444  WHERE id = '.$params['category'].'
    14221445;';
    1423   $result = pwg_query($query);
    1424   $category = pwg_db_fetch_assoc($result);
     1446    $result = pwg_query($query);
     1447    $category = pwg_db_fetch_assoc($result);
     1448
     1449    $url_params['section'] = 'categories';
     1450    $url_params['category'] = $category;
     1451  }
    14251452
    14261453  return array(
    14271454    'image_id' => $image_id,
    1428     'url' => make_picture_url(
    1429       array(
    1430         'image_id' => $image_id,
    1431         'section' => 'categories',
    1432         'category' => $category
    1433         )
    1434       ),
     1455    'url' => make_picture_url($url_params),
    14351456    );
    14361457}
Note: See TracChangeset for help on using the changeset viewer.