Changeset 9913 for branches/2.1


Ignore:
Timestamp:
Mar 29, 2011, 12:52:44 PM (13 years ago)
Author:
plg
Message:

merge back r9743, wrong method to merge a commit from trunk to branch 2.1

Location:
branches/2.1/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.1/include/ws_core.inc.php

    r9743 r9913  
    11<?php
    22// +-----------------------------------------------------------------------+
    3 // | Piwigo - a PHP based photo gallery                                    |
     3// | Piwigo - a PHP based picture gallery                                  |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    372372    @header('Content-Type: '.$contentType.'; charset='.get_pwg_charset());
    373373    print_r($encodedResponse);
    374     trigger_action('sendResponse', $encodedResponse );
    375374  }
    376375
  • branches/2.1/include/ws_functions.inc.php

    r9743 r9913  
    11<?php
    22// +-----------------------------------------------------------------------+
    3 // | Piwigo - a PHP based photo gallery                                    |
     3// | Piwigo - a PHP based picture gallery                                  |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    6969    $clauses[] = $tbl_name.'hit<='.$params['f_max_hit'];
    7070  }
    71   if ( isset($params['f_min_date_available']) )
    72   {
    73     $clauses[] = $tbl_name."date_available>='".$params['f_min_date_available']."'";
    74   }
    75   if ( isset($params['f_max_date_available']) )
    76   {
    77     $clauses[] = $tbl_name."date_available<'".$params['f_max_date_available']."'";
     71  if ( isset($params['f_min_date_posted']) )
     72  {
     73    $clauses[] = $tbl_name."date_available>='".$params['f_min_date_posted']."'";
     74  }
     75  if ( isset($params['f_max_date_posted']) )
     76  {
     77    $clauses[] = $tbl_name."date_available<'".$params['f_max_date_posted']."'";
    7878  }
    7979  if ( isset($params['f_min_date_created']) )
     
    176176{
    177177  global $conf;
    178   if ($conf['show_version'] or is_admin() )
     178  if ($conf['show_version'])
    179179    return PHPWG_VERSION;
    180180  else
     
    743743  {
    744744    $comment_post_data['author'] = stripslashes($user['username']);
    745     $comment_post_data['key'] = get_ephemeral_key(2, $params['image_id']);
     745    $comment_post_data['key'] = get_comment_post_key($params['image_id']);
    746746  }
    747747
     
    893893function ws_images_setPrivacyLevel($params, &$service)
    894894{
    895   if (!is_admin())
     895  if (!is_admin() || is_adviser() )
    896896  {
    897897    return new PwgError(401, 'Access denied');
     
    936936  // position
    937937
    938   if (!is_admin())
     938  if (!is_admin() || is_adviser() )
    939939  {
    940940    return new PwgError(401, 'Access denied');
     
    10771077function add_file($file_path, $type, $original_sum, $file_sum)
    10781078{
    1079   include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    1080  
    10811079  $file_path = file_path_for_type($file_path, $type);
    10821080
     
    11421140
    11431141  global $conf;
    1144   if (!is_admin())
     1142  if (!is_admin() || is_adviser() )
    11451143  {
    11461144    return new PwgError(401, 'Access denied');
     
    12101208function ws_images_add($params, &$service)
    12111209{
    1212   global $conf, $user;
    1213   if (!is_admin())
     1210  global $conf;
     1211  if (!is_admin() || is_adviser() )
    12141212  {
    12151213    return new PwgError(401, 'Access denied');
     
    12851283    'height' => $file_infos['height'],
    12861284    'md5sum' => $params['original_sum'],
    1287     'added_by' => $user['id'],
    12881285    );
    12891286
     
    13391336 
    13401337  invalidate_user_cache();
    1341 }
    1342 
    1343 function ws_images_addSimple($params, &$service)
    1344 {
    1345   global $conf;
    1346   if (!is_admin())
    1347   {
    1348     return new PwgError(401, 'Access denied');
    1349   }
    1350 
    1351   if (!$service->isPost())
    1352   {
    1353     return new PwgError(405, "This method requires HTTP POST");
    1354   }
    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='
    1362 SELECT *
    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   }
    1373 
    1374   // category
    1375   $params['category'] = (int)$params['category'];
    1376   if ($params['category'] <= 0 and $params['image_id'] <= 0)
    1377   {
    1378     return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
    1379   }
    1380 
    1381   include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    1382   prepare_upload_configuration();
    1383 
    1384   $image_id = add_uploaded_file(
    1385     $_FILES['image']['tmp_name'],
    1386     $_FILES['image']['name'],
    1387     $params['category'] > 0 ? array($params['category']) : null,
    1388     8,
    1389     $params['image_id'] > 0 ? $params['image_id'] : null
    1390     );
    1391 
    1392   $info_columns = array(
    1393     'name',
    1394     'author',
    1395     'comment',
    1396     'level',
    1397     'date_creation',
    1398     );
    1399 
    1400   foreach ($info_columns as $key)
    1401   {
    1402     if (isset($params[$key]))
    1403     {
    1404       $update[$key] = $params[$key];
    1405     }
    1406   }
    1407 
    1408   if (count(array_keys($update)) > 0)
    1409   {
    1410     $update['id'] = $image_id;
    1411 
    1412     include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    1413     mass_updates(
    1414       IMAGES_TABLE,
    1415       array(
    1416         'primary' => array('id'),
    1417         'update'  => array_diff(array_keys($update), array('id'))
    1418         ),
    1419       array($update)
    1420       );
    1421   }
    1422 
    1423 
    1424   if (isset($params['tags']) and !empty($params['tags']))
    1425   {
    1426     $tag_ids = array();
    1427     $tag_names = explode(',', $params['tags']);
    1428     foreach ($tag_names as $tag_name)
    1429     {
    1430       $tag_id = tag_id_from_tag_name($tag_name);
    1431       array_push($tag_ids, $tag_id);
    1432     }
    1433 
    1434     add_tags($tag_ids, array($image_id));
    1435   }
    1436 
    1437   $url_params = array('image_id' => $image_id);
    1438 
    1439   if ($params['category'] > 0)
    1440   {
    1441     $query = '
    1442 SELECT id, name, permalink
    1443   FROM '.CATEGORIES_TABLE.'
    1444   WHERE id = '.$params['category'].'
    1445 ;';
    1446     $result = pwg_query($query);
    1447     $category = pwg_db_fetch_assoc($result);
    1448 
    1449     $url_params['section'] = 'categories';
    1450     $url_params['category'] = $category;
    1451   }
    1452 
    1453   return array(
    1454     'image_id' => $image_id,
    1455     'url' => make_picture_url($url_params),
    1456     );
    14571338}
    14581339
     
    15801461
    15811462
    1582   $where_clauses = ws_std_image_sql_filter($params);
    1583   if (!empty($where_clauses))
    1584   {
    1585     $where_clauses = implode( ' AND ', $where_clauses);
    1586   }
    1587   $image_ids = get_image_ids_for_tags(
    1588     $tag_ids,
    1589     $params['tag_mode_and'] ? 'AND' : 'OR',
    1590     $where_clauses,
    1591     ws_std_image_sql_order($params) );
    1592 
    1593 
    1594   $image_ids = array_slice($image_ids, (int)($params['per_page']*$params['page']), (int)$params['per_page'] );
    1595  
     1463  $image_ids = array();
    15961464  $image_tag_map = array();
    1597   if ( !empty($image_ids) and !$params['tag_mode_and'] )
     1465
     1466  if ( !empty($tag_ids) )
    15981467  { // build list of image ids with associated tags per image
    1599     $query = '
     1468    if ($params['tag_mode_and'])
     1469    {
     1470      $image_ids = get_image_ids_for_tags( $tag_ids );
     1471    }
     1472    else
     1473    {
     1474      $query = '
    16001475SELECT image_id, GROUP_CONCAT(tag_id) AS tag_ids
    16011476  FROM '.IMAGE_TAG_TABLE.'
    1602   WHERE tag_id IN ('.implode(',',$tag_ids).') AND image_id IN ('.implode(',',$image_ids).')
     1477  WHERE tag_id IN ('.implode(',',$tag_ids).')
    16031478  GROUP BY image_id';
     1479      $result = pwg_query($query);
     1480      while ( $row=pwg_db_fetch_assoc($result) )
     1481      {
     1482        $row['image_id'] = (int)$row['image_id'];
     1483        array_push( $image_ids, $row['image_id'] );
     1484        $image_tag_map[ $row['image_id'] ] = explode(',', $row['tag_ids']);
     1485      }
     1486    }
     1487  }
     1488
     1489  $images = array();
     1490  if ( !empty($image_ids))
     1491  {
     1492    $where_clauses = ws_std_image_sql_filter($params);
     1493    $where_clauses[] = get_sql_condition_FandF(
     1494        array
     1495          (
     1496            'forbidden_categories' => 'category_id',
     1497            'visible_categories' => 'category_id',
     1498            'visible_images' => 'i.id'
     1499          ),
     1500        '', true
     1501      );
     1502    $where_clauses[] = 'id IN ('.implode(',',$image_ids).')';
     1503
     1504    $order_by = ws_std_image_sql_order($params);
     1505    if (empty($order_by))
     1506    {
     1507      $order_by = $conf['order_by'];
     1508    }
     1509    else
     1510    {
     1511      $order_by = 'ORDER BY '.$order_by;
     1512    }
     1513
     1514    $query = '
     1515SELECT DISTINCT i.* FROM '.IMAGES_TABLE.' i
     1516  INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id
     1517  WHERE '. implode('
     1518    AND ', $where_clauses).'
     1519'.$order_by.'
     1520LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']);
     1521
    16041522    $result = pwg_query($query);
    1605     while ( $row=pwg_db_fetch_assoc($result) )
    1606     {
    1607       $row['image_id'] = (int)$row['image_id'];
    1608       array_push( $image_ids, $row['image_id'] );
    1609       $image_tag_map[ $row['image_id'] ] = explode(',', $row['tag_ids']);
    1610     }
    1611   }
    1612 
    1613   $images = array();
    1614   if (!empty($image_ids))
    1615   {
    1616     $rank_of = array_flip($image_ids);
    1617     $result = pwg_query('
    1618 SELECT * FROM '.IMAGES_TABLE.'
    1619   WHERE id IN ('.implode(',',$image_ids).')');
    16201523    while ($row = pwg_db_fetch_assoc($result))
    16211524    {
    16221525      $image = array();
    1623       $image['rank'] = $rank_of[ $row['id'] ];
    16241526      foreach ( array('id', 'width', 'height', 'hit') as $k )
    16251527      {
     
    16651567      array_push($images, $image);
    16661568    }
    1667     usort($images, 'rank_compare');
    1668     unset($rank_of);
    16691569  }
    16701570
     
    16851585function ws_categories_add($params, &$service)
    16861586{
    1687   if (!is_admin())
     1587  if (!is_admin() or is_adviser())
    16881588  {
    16891589    return new PwgError(401, 'Access denied');
     
    17091609function ws_tags_add($params, &$service)
    17101610{
    1711   if (!is_admin())
     1611  if (!is_admin() or is_adviser())
    17121612  {
    17131613    return new PwgError(401, 'Access denied');
     
    17301630  global $conf;
    17311631 
    1732   if (!is_admin())
     1632  if (!is_admin() or is_adviser())
    17331633  {
    17341634    return new PwgError(401, 'Access denied');
     
    18061706function ws_images_checkFiles($params, &$service)
    18071707{
    1808   if (!is_admin())
     1708  if (!is_admin() or is_adviser())
    18091709  {
    18101710    return new PwgError(401, 'Access denied');
     
    18451745
    18461746    if (isset($params[$param_name.'_sum'])) {
    1847       include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    18481747      $type_path = file_path_for_type($path, $type);
    18491748      if (!is_file($type_path)) {
     
    18641763}
    18651764
     1765function 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;
     1788}
     1789
    18661790function ws_images_setInfo($params, &$service)
    18671791{
    18681792  global $conf;
    1869   if (!is_admin())
     1793  if (!is_admin() || is_adviser() )
    18701794  {
    18711795    return new PwgError(401, 'Access denied');
     
    19931917}
    19941918
    1995 function ws_images_delete($params, &$service)
    1996 {
    1997   global $conf;
    1998   if (!is_admin())
    1999   {
    2000     return new PwgError(401, 'Access denied');
    2001   }
    2002 
    2003   if (!$service->isPost())
    2004   {
    2005     return new PwgError(405, "This method requires HTTP POST");
    2006   }
    2007 
    2008   if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
    2009   {
    2010     return new PwgError(403, 'Invalid security token');
    2011   }
    2012 
    2013   $params['image_id'] = preg_split(
    2014     '/[\s,;\|]/',
    2015     $params['image_id'],
    2016     -1,
    2017     PREG_SPLIT_NO_EMPTY
    2018     );
    2019   $params['image_id'] = array_map('intval', $params['image_id']);
    2020 
    2021   $image_ids = array();
    2022   foreach ($params['image_id'] as $image_id)
    2023   {
    2024     if ($image_id > 0)
    2025     {
    2026       array_push($image_ids, $image_id);
    2027     }
    2028   }
    2029 
    2030   include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    2031   delete_elements($image_ids, true);
    2032 }
    2033 
    20341919function ws_add_image_category_relations($image_id, $categories_string, $replace_mode=false)
    20351920{
     
    21892074{
    21902075  global $conf;
    2191   if (!is_admin())
     2076  if (!is_admin() || is_adviser() )
    21922077  {
    21932078    return new PwgError(401, 'Access denied');
     
    22442129}
    22452130
    2246 function ws_categories_delete($params, &$service)
    2247 {
    2248   global $conf;
    2249   if (!is_admin())
    2250   {
    2251     return new PwgError(401, 'Access denied');
    2252   }
    2253 
    2254   if (!$service->isPost())
    2255   {
    2256     return new PwgError(405, "This method requires HTTP POST");
    2257   }
    2258 
    2259   if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
    2260   {
    2261     return new PwgError(403, 'Invalid security token');
    2262   }
    2263 
    2264   $modes = array('no_delete', 'delete_orphans', 'force_delete');
    2265   if (!in_array($params['photo_deletion_mode'], $modes))
    2266   {
    2267     return new PwgError(
    2268       500,
    2269       '[ws_categories_delete]'
    2270       .' invalid parameter photo_deletion_mode "'.$params['photo_deletion_mode'].'"'
    2271       .', possible values are {'.implode(', ', $modes).'}.'
    2272       );
    2273   }
    2274 
    2275   $params['category_id'] = preg_split(
    2276     '/[\s,;\|]/',
    2277     $params['category_id'],
    2278     -1,
    2279     PREG_SPLIT_NO_EMPTY
    2280     );
    2281   $params['category_id'] = array_map('intval', $params['category_id']);
    2282 
    2283   $category_ids = array();
    2284   foreach ($params['category_id'] as $category_id)
    2285   {
    2286     if ($category_id > 0)
    2287     {
    2288       array_push($category_ids, $category_id);
    2289     }
    2290   }
    2291 
    2292   if (count($category_ids) == 0)
    2293   {
    2294     return;
    2295   }
    2296 
    2297   $query = '
    2298 SELECT id
    2299   FROM '.CATEGORIES_TABLE.'
    2300   WHERE id IN ('.implode(',', $category_ids).')
    2301 ;';
    2302   $category_ids = array_from_query($query, 'id');
    2303 
    2304   if (count($category_ids) == 0)
    2305   {
    2306     return;
    2307   }
    2308  
    2309   include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    2310   delete_categories($category_ids, $params['photo_deletion_mode']);
    2311   update_global_rank();
    2312 }
    2313 
    2314 function ws_categories_move($params, &$service)
    2315 {
    2316   global $conf, $page;
    2317  
    2318   if (!is_admin())
    2319   {
    2320     return new PwgError(401, 'Access denied');
    2321   }
    2322 
    2323   if (!$service->isPost())
    2324   {
    2325     return new PwgError(405, "This method requires HTTP POST");
    2326   }
    2327 
    2328   if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
    2329   {
    2330     return new PwgError(403, 'Invalid security token');
    2331   }
    2332 
    2333   $params['category_id'] = preg_split(
    2334     '/[\s,;\|]/',
    2335     $params['category_id'],
    2336     -1,
    2337     PREG_SPLIT_NO_EMPTY
    2338     );
    2339   $params['category_id'] = array_map('intval', $params['category_id']);
    2340 
    2341   $category_ids = array();
    2342   foreach ($params['category_id'] as $category_id)
    2343   {
    2344     if ($category_id > 0)
    2345     {
    2346       array_push($category_ids, $category_id);
    2347     }
    2348   }
    2349 
    2350   if (count($category_ids) == 0)
    2351   {
    2352     return new PwgError(403, 'Invalid category_id input parameter, no category to move');
    2353   }
    2354 
    2355   // we can't move physical categories
    2356   $categories_in_db = array();
    2357  
    2358   $query = '
    2359 SELECT
    2360     id,
    2361     name,
    2362     dir
    2363   FROM '.CATEGORIES_TABLE.'
    2364   WHERE id IN ('.implode(',', $category_ids).')
    2365 ;';
    2366   $result = pwg_query($query);
    2367   while ($row = pwg_db_fetch_assoc($result))
    2368   {
    2369     $categories_in_db[$row['id']] = $row;
    2370     // we break on error at first physical category detected
    2371     if (!empty($row['dir']))
    2372     {
    2373       $row['name'] = strip_tags(
    2374         trigger_event(
    2375           'render_category_name',
    2376           $row['name'],
    2377           'ws_categories_move'
    2378           )
    2379         );
    2380      
    2381       return new PwgError(
    2382         403,
    2383         sprintf(
    2384           'Category %s (%u) is not a virtual category, you cannot move it',
    2385           $row['name'],
    2386           $row['id']
    2387           )
    2388         );
    2389     }
    2390   }
    2391 
    2392   if (count($categories_in_db) != count($category_ids))
    2393   {
    2394     $unknown_category_ids = array_diff($category_ids, array_keys($categories_in_db));
    2395    
    2396     return new PwgError(
    2397       403,
    2398       sprintf(
    2399         'Category %u does not exist',
    2400         $unknown_category_ids[0]
    2401         )
    2402       );
    2403   }
    2404 
    2405   // does this parent exists? This check should be made in the
    2406   // move_categories function, not here
    2407   //
    2408   // 0 as parent means "move categories at gallery root"
    2409   if (!is_numeric($params['parent']))
    2410   {
    2411     return new PwgError(403, 'Invalid parent input parameter');
    2412   }
    2413  
    2414   if (0 != $params['parent']) {
    2415     $params['parent'] = intval($params['parent']);
    2416     $subcat_ids = get_subcat_ids(array($params['parent']));
    2417     if (count($subcat_ids) == 0)
    2418     {
    2419       return new PwgError(403, 'Unknown parent category id');
    2420     }
    2421   }
    2422 
    2423   $page['infos'] = array();
    2424   $page['errors'] = array();
    2425   include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    2426   move_categories($category_ids, $params['parent']);
    2427   invalidate_user_cache();
    2428 
    2429   if (count($page['errors']) != 0)
    2430   {
    2431     return new PwgError(403, implode('; ', $page['errors']));
    2432   }
    2433 }
    2434 
    24352131function ws_logfile($string)
    24362132{
     
    24522148  global $conf;
    24532149
    2454   if (!is_admin())
     2150  if (!is_admin() or is_adviser())
    24552151  {
    24562152    return new PwgError(401, 'Access denied');
    24572153  }
    24582154
    2459   include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    24602155  $ret['message'] = ready_for_upload_message();
    24612156  $ret['ready_for_upload'] = true;
     
    24692164}
    24702165
    2471 function ws_plugins_getList($params, &$service)
     2166function ready_for_upload_message()
    24722167{
    24732168  global $conf;
    2474  
    2475   if (!is_admin())
    2476   {
    2477     return new PwgError(401, 'Access denied');
    2478   }
    2479 
    2480   include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
    2481   $plugins = new plugins();
    2482   $plugins->sort_fs_plugins('name');
    2483   $plugin_list = array();
    2484 
    2485   foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
    2486   {
    2487     if (isset($plugins->db_plugins_by_id[$plugin_id]))
    2488     {
    2489       $state = $plugins->db_plugins_by_id[$plugin_id]['state'];
    2490     }
    2491     else
    2492     {
    2493       $state = 'uninstalled';
    2494     }
    2495 
    2496     array_push(
    2497       $plugin_list,
    2498       array(
    2499         'id' => $plugin_id,
    2500         'name' => $fs_plugin['name'],
    2501         'version' => $fs_plugin['version'],
    2502         'state' => $state,
    2503         'description' => $fs_plugin['description'],
    2504         )
    2505       );
    2506   }
    2507 
    2508   return $plugin_list;
    2509 }
    2510 
    2511 function ws_plugins_performAction($params, &$service)
    2512 {
    2513   global $template;
    2514  
    2515   if (!is_admin())
    2516   {
    2517     return new PwgError(401, 'Access denied');
    2518   }
    2519 
    2520   if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
    2521   {
    2522     return new PwgError(403, 'Invalid security token');
    2523   }
    2524 
    2525   define('IN_ADMIN', true);
    2526   include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
    2527   $plugins = new plugins();
    2528   $errors = $plugins->perform_action($params['action'], $params['plugin']);
    2529 
    2530  
    2531   if (!empty($errors))
    2532   {
    2533     return new PwgError(500, $errors);
     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    }
    25342181  }
    25352182  else
    25362183  {
    2537     if (in_array($params['action'], array('activate', 'deactivate')))
    2538     {
    2539       $template->delete_compiled_templates();
    2540     }
    2541     return true;
    2542   }
    2543 }
    2544 
    2545 function ws_themes_performAction($params, &$service)
    2546 {
    2547   global $template;
    2548  
    2549   if (!is_admin())
    2550   {
    2551     return new PwgError(401, 'Access denied');
    2552   }
    2553 
    2554   if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
    2555   {
    2556     return new PwgError(403, 'Invalid security token');
    2557   }
    2558 
    2559   define('IN_ADMIN', true);
    2560   include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
    2561   $themes = new themes();
    2562   $errors = $themes->perform_action($params['action'], $params['theme']);
    2563  
    2564   if (!empty($errors))
    2565   {
    2566     return new PwgError(500, $errors);
    2567   }
    2568   else
    2569   {
    2570     if (in_array($params['action'], array('activate', 'deactivate')))
    2571     {
    2572       $template->delete_compiled_templates();
    2573     }
    2574     return true;
    2575   }
     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;
    25762199}
    25772200?>
Note: See TracChangeset for help on using the changeset viewer.