Ignore:
Timestamp:
Dec 23, 2010, 11:22:51 AM (13 years ago)
Author:
plg
Message:

feature 2083 added: implement method pwg.images.addSimple in core

makes admin/include/function_upload.inc.php not dependant from include/ws_functions.inc.php (moves functions file_path_for_type and ready_for_upload_message)

cleaner method to initialize the upload settings

File:
1 edited

Legend:

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

    r8126 r8249  
    10771077function add_file($file_path, $type, $original_sum, $file_sum)
    10781078{
     1079  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
     1080 
    10791081  $file_path = file_path_for_type($file_path, $type);
    10801082
     
    13361338 
    13371339  invalidate_user_cache();
     1340}
     1341
     1342function ws_images_addSimple($params, &$service)
     1343{
     1344  global $conf;
     1345  if (!is_admin() || is_adviser() )
     1346  {
     1347    return new PwgError(401, 'Access denied');
     1348  }
     1349
     1350  if (!$service->isPost())
     1351  {
     1352    return new PwgError(405, "This method requires HTTP POST");
     1353  }
     1354
     1355  // category
     1356  $params['category'] = (int)$params['category'];
     1357  if ($params['category'] <= 0)
     1358  {
     1359    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
     1360  }
     1361
     1362  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
     1363  prepare_upload_configuration();
     1364
     1365  $image_id = add_uploaded_file(
     1366    $_FILES['image']['tmp_name'],
     1367    $_FILES['image']['name'],
     1368    array($params['category']),
     1369    8
     1370    );
     1371
     1372  $info_columns = array(
     1373    'name',
     1374    'author',
     1375    'comment',
     1376    'level',
     1377    'date_creation',
     1378    );
     1379
     1380  foreach ($info_columns as $key)
     1381  {
     1382    if (isset($params[$key]))
     1383    {
     1384      $update[$key] = $params[$key];
     1385    }
     1386  }
     1387
     1388  if (count(array_keys($update)) > 0)
     1389  {
     1390    $update['id'] = $image_id;
     1391
     1392    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     1393    mass_updates(
     1394      IMAGES_TABLE,
     1395      array(
     1396        'primary' => array('id'),
     1397        'update'  => array_diff(array_keys($update), array('id'))
     1398        ),
     1399      array($update)
     1400      );
     1401  }
     1402
     1403
     1404  if (isset($params['tags']) and !empty($params['tags']))
     1405  {
     1406    $tag_ids = array();
     1407    $tag_names = explode(',', $params['tags']);
     1408    foreach ($tag_names as $tag_name)
     1409    {
     1410      $tag_id = tag_id_from_tag_name($tag_name);
     1411      array_push($tag_ids, $tag_id);
     1412    }
     1413
     1414    add_tags($tag_ids, array($image_id));
     1415  }
     1416
     1417  $query = '
     1418SELECT id, name, permalink
     1419  FROM '.CATEGORIES_TABLE.'
     1420  WHERE id = '.$params['category'].'
     1421;';
     1422  $result = pwg_query($query);
     1423  $category = pwg_db_fetch_assoc($result);
     1424
     1425  return array(
     1426    'image_id' => $image_id,
     1427    'url' => make_picture_url(
     1428      array(
     1429        'image_id' => $image_id,
     1430        'section' => 'categories',
     1431        'category' => $category
     1432        )
     1433      ),
     1434    );
    13381435}
    13391436
     
    17451842
    17461843    if (isset($params[$param_name.'_sum'])) {
     1844      include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    17471845      $type_path = file_path_for_type($path, $type);
    17481846      if (!is_file($type_path)) {
     
    17611859
    17621860  return $ret;
    1763 }
    1764 
    1765 function file_path_for_type($file_path, $type='thumb')
    1766 {
    1767   // resolve the $file_path depending on the $type
    1768   if ('thumb' == $type) {
    1769     $file_path = get_thumbnail_location(
    1770       array(
    1771         'path' => $file_path,
    1772         'tn_ext' => 'jpg',
    1773         )
    1774       );
    1775   }
    1776 
    1777   if ('high' == $type) {
    1778     @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    1779     $file_path = get_high_location(
    1780       array(
    1781         'path' => $file_path,
    1782         'has_high' => 'true'
    1783         )
    1784       );
    1785   }
    1786 
    1787   return $file_path;
    17881861}
    17891862
     
    21532226  }
    21542227
     2228  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    21552229  $ret['message'] = ready_for_upload_message();
    21562230  $ret['ready_for_upload'] = true;
     
    21632237  return $ret;
    21642238}
    2165 
    2166 function ready_for_upload_message()
    2167 {
    2168   global $conf;
    2169 
    2170   $relative_dir = preg_replace('#^'.PHPWG_ROOT_PATH.'#', '', $conf['upload_dir']);
    2171 
    2172   if (!is_dir($conf['upload_dir']))
    2173   {
    2174     if (!is_writable(dirname($conf['upload_dir'])))
    2175     {
    2176       return sprintf(
    2177         l10n('Create the "%s" directory at the root of your Piwigo installation'),
    2178         $relative_dir
    2179         );
    2180     }
    2181   }
    2182   else
    2183   {
    2184     if (!is_writable($conf['upload_dir']))
    2185     {
    2186       @chmod($conf['upload_dir'], 0777);
    2187      
    2188       if (!is_writable($conf['upload_dir']))
    2189       {
    2190         return sprintf(
    2191           l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'),
    2192           $relative_dir
    2193           );
    2194       }
    2195     }
    2196   }
    2197 
    2198   return null;
    2199 }
    22002239?>
Note: See TracChangeset for help on using the changeset viewer.