Index: trunk/include/ws_functions.inc.php
===================================================================
--- trunk/include/ws_functions.inc.php	(revision 12749)
+++ trunk/include/ws_functions.inc.php	(revision 12796)
@@ -147,13 +147,20 @@
 function ws_std_get_urls($image_row)
 {
-  $ret = array(
-    'tn_url' => get_thumbnail_url($image_row),
-    'element_url' => get_element_url($image_row)
-  );
+  $ret = array();
   global $user;
-  if ($user['enabled_high'] and $image_row['has_high'] )
-  {
-    $ret['high_url'] = get_high_url($image_row);
-  }
+  if ($user['enabled_high'])
+  {
+    $ret['element_url'] = get_element_url($image_row);
+  }
+  
+  $derivatives = DerivativeImage::get_all($image_row);
+  $derivatives_arr = array();
+  foreach($derivatives as $type=>$derivative)
+  {
+    $size = $derivative->get_size();
+    $size != null or $size=array(null,null);
+    $derivatives_arr[$type] = array('url' => $derivative->get_url(), 'width'=>$size[0], 'height'=>$size[1] );
+  }
+  $ret['derivatives'] = $derivatives_arr;;
   return $ret;
 }
@@ -166,5 +173,5 @@
 {
   return array(
-    'id','tn_url','element_url','high_url', 'file','width','height','hit','date_available','date_creation'
+    'id','element_url', 'file','width','height','hit','date_available','date_creation'
     );
 }
@@ -621,5 +628,5 @@
 
     $query = '
-SELECT id, path, tn_ext, level
+SELECT id, path, representative_ext, level
   FROM '.IMAGES_TABLE.'
   WHERE id IN ('.implode(',', $image_ids).')
@@ -630,5 +637,5 @@
       if ($row['level'] <= $user['level'])
       {
-        $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
+        $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row);
       }
       else
@@ -669,5 +676,5 @@
     {
       $query = '
-SELECT id, path, tn_ext
+SELECT id, path, representative_ext
   FROM '.IMAGES_TABLE.'
   WHERE id IN ('.implode(',', $new_image_ids).')
@@ -676,5 +683,5 @@
       while ($row = pwg_db_fetch_assoc($result))
       {
-        $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
+        $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row);
       }
     }
@@ -1371,6 +1378,5 @@
   if (!is_dir($upload_dir)) {
     umask(0000);
-    $recursive = true;
-    if (!@mkdir($upload_dir, 0777, $recursive))
+    if (!@mkdir($upload_dir, 0777, true))
     {
       return new PwgError(500, 'error during buffer directory creation');
@@ -1425,6 +1431,5 @@
     if (is_file($output_filepath))
     {
-      new PwgError(500, '[merge_chunks] error while trying to remove existing '.$output_filepath);
-      exit();
+      return new PwgError(500, '[merge_chunks] error while trying to remove existing '.$output_filepath);
     }
   }
@@ -1465,6 +1470,5 @@
     if (!file_put_contents($output_filepath, $string, FILE_APPEND))
     {
-      new PwgError(500, '[merge_chunks] error while writting chunks for '.$output_filepath);
-      exit();
+      return new PwgError(500, '[merge_chunks] error while writting chunks for '.$output_filepath);
     }
 
@@ -1501,6 +1505,5 @@
     if (!@mkdir($upload_dir, 0777, $recursive))
     {
-      new PwgError(500, '[add_file] error during '.$type.' directory creation');
-      exit();
+      return new PwgError(500, '[add_file] error during '.$type.' directory creation');
     }
   }
@@ -1513,6 +1516,5 @@
     if (!is_writable($upload_dir))
     {
-      new PwgError(500, '[add_file] '.$type.' directory has no write access');
-      exit();
+      return new PwgError(500, '[add_file] '.$type.' directory has no write access');
     }
   }
@@ -1526,7 +1528,7 @@
   // check dumped thumbnail md5
   $dumped_md5 = md5_file($file_path);
-  if ($dumped_md5 != $file_sum) {
-    new PwgError(500, '[add_file] '.$type.' transfer failed');
-    exit();
+  if ($dumped_md5 != $file_sum) 
+  {
+    return new PwgError(500, '[add_file] '.$type.' transfer failed');
   }
 
@@ -2452,5 +2454,5 @@
       else
       {
-        new PwgError(
+        return new PwgError(
           500,
           '[ws_images_setInfo]'
@@ -2458,5 +2460,4 @@
           .', possible values are {fill_if_empty, replace}.'
           );
-        exit();
       }
     }
@@ -2467,6 +2468,5 @@
     if (!empty($image_row['storage_category_id']))
     {
-      new PwgError(500, '[ws_images_setInfo] updating "file" is forbidden on photos added by synchronization');
-      exit();
+      return new PwgError(500, '[ws_images_setInfo] updating "file" is forbidden on photos added by synchronization');
     }
 
@@ -2518,5 +2518,5 @@
     else
     {
-      new PwgError(
+      return new PwgError(
         500,
         '[ws_images_setInfo]'
@@ -2524,5 +2524,4 @@
         .', possible values are {replace, append}.'
         );
-      exit();
     }
   }
@@ -2611,9 +2610,8 @@
   if (count($cat_ids) == 0)
   {
-    new PwgError(
+    return new PwgError(
       500,
       '[ws_add_image_category_relations] there is no category defined in "'.$categories_string.'"'
       );
-    exit();
   }
 
@@ -2629,9 +2627,8 @@
   if (count($unknown_cat_ids) != 0)
   {
-    new PwgError(
+    return new PwgError(
       500,
       '[ws_add_image_category_relations] the following categories are unknown: '.implode(', ', $unknown_cat_ids)
       );
-    exit();
   }
 
