Index: /trunk/include/functions.inc.php
===================================================================
--- /trunk/include/functions.inc.php	(revision 22728)
+++ /trunk/include/functions.inc.php	(revision 22729)
@@ -173,12 +173,4 @@
   }
   return true;
-}
-
-/* Returns true if the string appears to be encoded in UTF-8. (from wordpress)
- * @param string Str
- */
-function seems_utf8($Str) {
-  // OBSOLETE !!!
-  return qualify_utf8($Str) >= 0;
 }
 
Index: /trunk/include/ws_core.inc.php
===================================================================
--- /trunk/include/ws_core.inc.php	(revision 22728)
+++ /trunk/include/ws_core.inc.php	(revision 22729)
@@ -41,5 +41,4 @@
 
 define( 'WS_XML_ATTRIBUTES', 'attributes_xml_');
-define( 'WS_XML_CONTENT', 'content_xml_');
 
 /**
@@ -99,5 +98,4 @@
 {
   /*private*/ var $_content;
-  /*private*/ var $_name;
   /*private*/ var $_xmlAttributes;
 
@@ -111,7 +109,6 @@
    *    whenever possible)
    */
-  function PwgNamedStruct($name, $content, $xmlAttributes=null, $xmlElements=null )
-  {
-    $this->_name = $name;
+  function PwgNamedStruct($content, $xmlAttributes=null, $xmlElements=null )
+  {
     $this->_content = $content;
     if ( isset($xmlAttributes) )
@@ -183,44 +180,28 @@
    * usually called by every response encoder, except rest xml.
    */
-  static function flattenResponse(&$response)
-  {
-    PwgResponseEncoder::_mergeAttributesAndContent($response);
-    PwgResponseEncoder::_removeNamedArray($response);
-    PwgResponseEncoder::_removeNamedStruct($response);
-    if (is_array($response))
-    { // need to call 2 times (first time might add new arrays)
-      array_walk_recursive($response, array('PwgResponseEncoder', '_remove_named_callback') );
-      array_walk_recursive($response, array('PwgResponseEncoder', '_remove_named_callback') );
-    }
-//print_r($response);
-    PwgResponseEncoder::_mergeAttributesAndContent($response);
-  }
-
-  private static function _remove_named_callback(&$value, $key)
-  {
-    do
-    {
-      $changed = 0;
-      $changed += PwgResponseEncoder::_removeNamedArray($value);
-      $changed += PwgResponseEncoder::_removeNamedStruct($value);
-  //    print_r('walk '.$key."<br>\n");
-    }
-    while ($changed);
-  }
-
-  private static function _mergeAttributesAndContent(&$value)
-  {
-    if ( !is_array($value) )
+  static function flattenResponse(&$value)
+  {
+    self::flatten($value);
+  }
+
+  private static function flatten(&$value)
+  {
+    if (is_object($value))
+    {
+      $class = strtolower( @get_class($value) );
+      if ($class == 'pwgnamedarray')
+      {
+        $value = $value->_content;
+      }
+      if ($class == 'pwgnamedstruct')
+      {
+        $value = $value->_content;
+      }
+    }
+
+    if (!is_array($value))
       return;
-/*    $first_key = '';
-    if (count($value)) { $ak = array_keys($value); $first_key = $ak[0]; }
-
-    print_r( '_mergeAttributesAndContent is_struct='.PwgResponseEncoder::is_struct($value)
-      .' count='.count($value)
-      .' first_key='.$first_key
-      ."<br>\n"
-      );*/
-    $ret = 0;
-    if (PwgResponseEncoder::is_struct($value))
+
+    if (self::is_struct($value))
     {
       if ( isset($value[WS_XML_ATTRIBUTES]) )
@@ -228,68 +209,11 @@
         $value = array_merge( $value, $value[WS_XML_ATTRIBUTES] );
         unset( $value[WS_XML_ATTRIBUTES] );
-        $ret=1;
-      }
-      if ( isset($value[WS_XML_CONTENT]) )
-      {
-        $cont_processed = 0;
-        if ( count($value)==1 )
-        {
-          $value = $value[WS_XML_CONTENT];
-          $cont_processed=1;
-        }
-        else
-        {
-          if (PwgResponseEncoder::is_struct($value[WS_XML_CONTENT]))
-          {
-            $value = array_merge( $value, $value[WS_XML_CONTENT] );
-            unset( $value[WS_XML_CONTENT] );
-            $cont_processed=1;
-          }
-        }
-        $ret += $cont_processed;
-        if (!$cont_processed)
-        {
-          $value['_content'] = $value[WS_XML_CONTENT];
-          unset( $value[WS_XML_CONTENT] );
-          $ret++;
-        }
-      }
-    }
-
-    foreach ($value as $key=>$v)
-    {
-      if ( PwgResponseEncoder::_mergeAttributesAndContent($v) )
-      {
-        $value[$key]=$v;
-        $ret++;
-      }
-    }
-    return $ret;
-  }
-
-  private static function _removeNamedArray(&$value)
-  {
-    if ( strtolower( @get_class($value) ) =='pwgnamedarray')
-    {
-      $value = $value->_content;
-      return 1;
-    }
-    return 0;
-  }
-
-  private static function _removeNamedStruct(&$value)
-  {
-    if ( strtolower( @get_class($value) ) =='pwgnamedstruct')
-    {
-      if ( isset($value->_content['']) )
-      {
-        $unknown = $value->_content[''];
-        unset( $value->_content[''] );
-        $value->_content[$value->_name] = $unknown;
-      }
-      $value = $value->_content;
-      return 1;
-    }
-    return 0;
+      }
+    }
+
+    foreach ($value as $key=>&$v)
+    {
+      self::flatten($v);
+    }
   }
 }
Index: /trunk/include/ws_functions.inc.php
===================================================================
--- /trunk/include/ws_functions.inc.php	(revision 22728)
+++ /trunk/include/ws_functions.inc.php	(revision 22729)
@@ -193,5 +193,19 @@
 }
 
-function ws_getMissingDerivatives($params, &$service)
+function ws_std_get_category_xml_attributes()
+{
+  return array(
+    'id', 'url', 'nb_images', 'total_nb_images', 'nb_categories', 'date_last', 'max_date_last',
+    );
+}
+
+function ws_std_get_tag_xml_attributes()
+{
+  return array(
+    'id', 'name', 'url_name', 'counter', 'url', 'page_url',
+    );
+}
+
+function ws_getMissingDerivatives($params, $service)
 {
   if (!is_admin())
@@ -292,5 +306,5 @@
  * returns PWG version (web service method)
  */
-function ws_getVersion($params, &$service)
+function ws_getVersion($params, $service)
 {
   global $conf;
@@ -304,5 +318,5 @@
  * returns general informations (web service method)
  */
-function ws_getInfos($params, &$service)
+function ws_getInfos($params, $service)
 {
   if (!is_admin())
@@ -368,5 +382,5 @@
 }
 
-function ws_caddie_add($params, &$service)
+function ws_caddie_add($params, $service)
 {
   if (!is_admin())
@@ -401,5 +415,5 @@
  * returns images per category (web service method)
  */
-function ws_categories_getImages($params, &$service)
+function ws_categories_getImages($params, $service)
 {
   global $user, $conf;
@@ -470,4 +484,7 @@
     $order_by = empty($order_by) ? $conf['order_by'] : 'ORDER BY '.$order_by;
 
+    $params['per_page'] = (int)$params['per_page'];
+    $params['page'] = (int)$params['page'];
+
     $query = '
 SELECT i.*, GROUP_CONCAT(category_id) AS cat_ids
@@ -478,5 +495,5 @@
 GROUP BY i.id
 '.$order_by.'
-LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']);
+LIMIT '.$params['per_page'].' OFFSET '.($params['per_page']*$params['page']);
 
     $result = pwg_query($query);
@@ -512,12 +529,9 @@
                   )
                 );
-        array_push( $image_cats,  array(
-              WS_XML_ATTRIBUTES => array (
-                  'id' => (int)$cat_id,
-                  'url' => $url,
-                  'page_url' => $page_url,
-                )
-            )
-          );
+        $image_cats[] = array (
+                'id' => (int)$cat_id,
+                'url' => $url,
+                'page_url' => $page_url,
+            );
       }
 
@@ -525,19 +539,16 @@
             $image_cats,'category', array('id','url','page_url')
           );
-      array_push($images, $image);
-    }
-  }
-
-  return array( 'images' =>
-    array (
-      WS_XML_ATTRIBUTES =>
+      $images[] = $image;
+    }
+  }
+
+  return array (
+      'paging' => new PwgNamedStruct(
         array(
             'page' => $params['page'],
             'per_page' => $params['per_page'],
             'count' => count($images)
-          ),
-       WS_XML_CONTENT => new PwgNamedArray($images, 'image',
-          ws_std_get_image_xml_attributes() )
-      )
+          ) ),
+       'images' => new PwgNamedArray($images, 'image', ws_std_get_image_xml_attributes() )
     );
 }
@@ -558,5 +569,5 @@
     if (!isset($node['id_uppercat']))
     {
-      $tree[$key] = &$node;
+      $tree[] = &$node;
     }
     else
@@ -564,8 +575,8 @@
       if (!isset($categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories']))
       {
-        $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] = array();
+        $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] = new PwgNamedArray(array(), 'category', ws_std_get_category_xml_attributes());
       }
 
-      $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'][$key] = &$node;
+      $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories']->_content[] = &$node;
     }
   }
@@ -577,23 +588,7 @@
  * returns a list of categories (web service method)
  */
-function ws_categories_getList($params, &$service)
+function ws_categories_getList($params, $service)
 {
   global $user,$conf;
-
-  if ($params['tree_output'])
-  {
-    if (!isset($_GET['format']) or !in_array($_GET['format'], array('php', 'json')))
-    {
-      // the algorithm used to build a tree from a flat list of categories
-      // keeps original array keys, which is not compatible with
-      // PwgNamedArray.
-      //
-      // PwgNamedArray is useful to define which data is an attribute and
-      // which is an element in the XML output. The "hierarchy" output is
-      // only compatible with json/php output.
-
-      return new PwgError(405, "The tree_output option is only compatible with json/php output formats");
-    }
-  }
 
   $where = array('1=1');
@@ -609,5 +604,5 @@
       $where[] = 'id_uppercat IS NULL';
   }
-  else if ($params['cat_id']>0)
+  elseif ($params['cat_id']>0)
   {
     $where[] = 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.
@@ -705,9 +700,9 @@
       $image_id = $row['user_representative_picture_id'];
     }
-    else if (!empty($row['representative_picture_id']))
+    elseif (!empty($row['representative_picture_id']))
     { // if a representative picture is set, it has priority
       $image_id = $row['representative_picture_id'];
     }
-    else if ($conf['allow_random_representative'])
+    elseif ($conf['allow_random_representative'])
     {
       // searching a random representant among elements in sub-categories
@@ -747,10 +742,10 @@
       if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id)
       {
-        $user_representative_updates_for[ $user['id'].'#'.$row['id'] ] = $image_id;
+        $user_representative_updates_for[ $row['id'] ] = $image_id;
       }
 
       $row['representative_picture_id'] = $image_id;
-      array_push($image_ids, $image_id);
-      array_push($categories, $row);
+      $image_ids[] = $image_id;
+      $categories[] = $row;
     }
     unset($image_id);
@@ -758,5 +753,5 @@
 
 
-    array_push($cats, $row);
+    $cats[] = $row;
   }
   usort($cats, 'global_rank_compare');
@@ -804,5 +799,5 @@
             if ($conf['representative_cache_on_level'])
             {
-              $user_representative_updates_for[ $user['id'].'#'.$category['id'] ] = $image_id;
+              $user_representative_updates_for[ $category['id'] ] = $image_id;
             }
 
@@ -836,12 +831,10 @@
     $updates = array();
 
-    foreach ($user_representative_updates_for as $user_cat => $image_id)
-    {
-      list($user_id, $cat_id) = explode('#', $user_cat);
-
+    foreach ($user_representative_updates_for as $cat_id => $image_id)
+    {
       array_push(
         $updates,
         array(
-          'user_id' => $user_id,
+          'user_id' => $user['id'],
           'cat_id' => $cat_id,
           'user_representative_picture_id' => $image_id,
@@ -879,24 +872,10 @@
   if ($params['tree_output'])
   {
-    return categories_flatlist_to_tree($cats);
-  }
-  else
-  {
-    return array(
-      'categories' => new PwgNamedArray(
-        $cats,
-        'category',
-        array(
-          'id',
-          'url',
-          'nb_images',
-          'total_nb_images',
-          'nb_categories',
-          'date_last',
-          'max_date_last',
-          )
-        )
-      );
-  }
+    $cats = categories_flatlist_to_tree($cats);
+  }
+
+  return array(
+    'categories' => new PwgNamedArray($cats, 'category', ws_std_get_category_xml_attributes())
+    );
 }
 
@@ -908,5 +887,5 @@
  * account.
  */
-function ws_categories_getAdminList($params, &$service)
+function ws_categories_getAdminList($params, $service)
 {
   if (!is_admin())
@@ -954,5 +933,5 @@
         )
       );
-    array_push($cats, $row);
+    $cats[] = $row;
   }
 
@@ -976,5 +955,5 @@
  * returns detailed information for an element (web service method)
  */
-function ws_images_addComment($params, &$service)
+function ws_images_addComment($params, $service)
 {
   if (!$service->isPost())
@@ -1024,9 +1003,5 @@
           'validation' => $comment_action=='validate',
         );
-      return new PwgNamedStruct(
-          'comment',
-          $ret,
-          null, array()
-        );
+      return array( 'comment' =>  new PwgNamedStruct($ret) );
     default:
       return new PwgError(500, "Unknown comment action ".$comment_action );
@@ -1037,5 +1012,5 @@
  * returns detailed information for an element (web service method)
  */
-function ws_images_getInfo($params, &$service)
+function ws_images_getInfo($params, $service)
 {
   global $user, $conf;
@@ -1172,5 +1147,5 @@
     {
       $row['id']=(int)$row['id'];
-      array_push($related_comments, $row);
+      $related_comments[] = $row;
     }
   }
@@ -1202,21 +1177,22 @@
   $ret['rates'] = array( WS_XML_ATTRIBUTES => $rating );
   $ret['categories'] = new PwgNamedArray($related_categories, 'category', array('id','url', 'page_url') );
-  $ret['tags'] = new PwgNamedArray($related_tags, 'tag', array('id','url_name','url','name','page_url') );
+  $ret['tags'] = new PwgNamedArray($related_tags, 'tag', ws_std_get_tag_xml_attributes() );
   if ( isset($comment_post_data) )
   {
     $ret['comment_post'] = array( WS_XML_ATTRIBUTES => $comment_post_data );
   }
-  $ret['comments'] = array(
-     WS_XML_ATTRIBUTES =>
-        array(
-          'page' => $params['comments_page'],
-          'per_page' => $params['comments_per_page'],
-          'count' => count($related_comments),
-          'nb_comments' => $nb_comments,
-        ),
-     WS_XML_CONTENT => new PwgNamedArray($related_comments, 'comment', array('id','date') )
-      );
-
-  return new PwgNamedStruct('image',$ret, null, array('name','comment') );
+  $ret['comments_paging'] = new PwgNamedStruct( array(
+        'page' => $params['comments_page'],
+        'per_page' => $params['comments_per_page'],
+        'count' => count($related_comments),
+        'total_count' => $nb_comments,
+      ) );
+
+  $ret['comments'] = new PwgNamedArray($related_comments, 'comment', array('id','date') );
+
+  if ($service->_responseFormat != 'rest')
+    return $ret; // for backward compatibility only
+  else
+    return array( 'image' => new PwgNamedStruct($ret, null, array('name','comment') ) );
 }
 
@@ -1225,5 +1201,5 @@
  * rates the image_id in the parameter
  */
-function ws_images_Rate($params, &$service)
+function ws_images_Rate($params, $service)
 {
   $image_id = (int)$params['image_id'];
@@ -1259,5 +1235,5 @@
  * returns a list of elements corresponding to a query search
  */
-function ws_images_search($params, &$service)
+function ws_images_search($params, $service)
 {
   global $page;
@@ -1280,4 +1256,7 @@
       implode(' AND ', $where_clauses)
     );
+
+  $params['per_page'] = (int)$params['per_page'];
+  $params['page'] = (int)$params['page'];
 
   $image_ids = array_slice(
@@ -1316,20 +1295,18 @@
   }
 
-
-  return array( 'images' =>
-    array (
-      WS_XML_ATTRIBUTES =>
-        array(
-            'page' => $params['page'],
-            'per_page' => $params['per_page'],
-            'count' => count($images)
-          ),
-       WS_XML_CONTENT => new PwgNamedArray($images, 'image',
-          ws_std_get_image_xml_attributes() )
-      )
+  return array (
+    'paging' => new PwgNamedStruct(
+      array(
+        'page' => $params['page'],
+        'per_page' => $params['per_page'],
+        'count' => count($images),
+        'total_count' => count($search_result['items']),
+        ) ),
+     'images' => new PwgNamedArray($images, 'image',
+        ws_std_get_image_xml_attributes() )
     );
 }
 
-function ws_images_setPrivacyLevel($params, &$service)
+function ws_images_setPrivacyLevel($params, $service)
 {
   if (!is_admin())
@@ -1366,5 +1343,5 @@
 }
 
-function ws_images_setRank($params, &$service)
+function ws_images_setRank($params, $service)
 {
   if (!is_admin())
@@ -1478,5 +1455,5 @@
 }
 
-function ws_images_add_chunk($params, &$service)
+function ws_images_add_chunk($params, $service)
 {
   global $conf;
@@ -1637,5 +1614,5 @@
 }
 
-function ws_images_addFile($params, &$service)
+function ws_images_addFile($params, $service)
 {
   ws_logfile(__FUNCTION__.', input :  '.var_export($params, true));
@@ -1732,5 +1709,5 @@
 }
 
-function ws_images_add($params, &$service)
+function ws_images_add($params, $service)
 {
   global $conf, $user;
@@ -1890,5 +1867,5 @@
 }
 
-function ws_images_addSimple($params, &$service)
+function ws_images_addSimple($params, $service)
 {
   global $conf;
@@ -2027,5 +2004,5 @@
 }
 
-function ws_rates_delete($params, &$service)
+function ws_rates_delete($params, $service)
 {
   global $conf;
@@ -2069,5 +2046,5 @@
  * perform a login (web service method)
  */
-function ws_session_login($params, &$service)
+function ws_session_login($params, $service)
 {
   global $conf;
@@ -2088,5 +2065,5 @@
  * performs a logout (web service method)
  */
-function ws_session_logout($params, &$service)
+function ws_session_logout($params, $service)
 {
   if (!is_a_guest())
@@ -2097,5 +2074,5 @@
 }
 
-function ws_session_getStatus($params, &$service)
+function ws_session_getStatus($params, $service)
 {
   global $user;
@@ -2119,5 +2096,5 @@
  * returns a list of tags (web service method)
  */
-function ws_tags_getList($params, &$service)
+function ws_tags_getList($params, $service)
 {
   $tags = get_available_tags();
@@ -2141,5 +2118,5 @@
       );
   }
-  return array('tags' => new PwgNamedArray($tags, 'tag', array('id','url_name','url', 'name', 'counter' )) );
+  return array('tags' => new PwgNamedArray($tags, 'tag', ws_std_get_tag_xml_attributes()) );
 }
 
@@ -2151,5 +2128,5 @@
  * account.
  */
-function ws_tags_getAdminList($params, &$service)
+function ws_tags_getAdminList($params, $service)
 {
   if (!is_admin())
@@ -2163,9 +2140,5 @@
       $tags,
       'tag',
-      array(
-        'name',
-        'id',
-        'url_name',
-        )
+      ws_std_get_tag_xml_attributes()
       )
     );
@@ -2175,5 +2148,5 @@
  * returns a list of images for tags (web service method)
  */
-function ws_tags_getImages($params, &$service)
+function ws_tags_getImages($params, $service)
 {
   global $conf;
@@ -2203,6 +2176,8 @@
     ws_std_image_sql_order($params) );
 
-
-  $image_ids = array_slice($image_ids, (int)($params['per_page']*$params['page']), (int)$params['per_page'] );
+  $count_set = count($image_ids);
+  $params['per_page'] = (int)$params['per_page'];
+  $params['page'] = (int)$params['page'];
+  $image_ids = array_slice($image_ids, $params['per_page']*$params['page'], $params['per_page'] );
 
   $image_tag_map = array();
@@ -2218,5 +2193,5 @@
     {
       $row['image_id'] = (int)$row['image_id'];
-      array_push( $image_ids, $row['image_id'] );
+      $image_ids[] = $row['image_id'];
       $image_tag_map[ $row['image_id'] ] = explode(',', $row['tag_ids']);
     }
@@ -2265,15 +2240,12 @@
                 )
               );
-        array_push($image_tags, array(
+        $image_tags[] = array(
                 'id' => (int)$tag_id,
                 'url' => $url,
                 'page_url' => $page_url,
-              )
-            );
+              );
       }
-      $image['tags'] = new PwgNamedArray($image_tags, 'tag',
-              array('id','url_name','url','page_url')
-            );
-      array_push($images, $image);
+      $image['tags'] = new PwgNamedArray($image_tags, 'tag', ws_std_get_tag_xml_attributes() );
+      $images[] = $image;
     }
     usort($images, 'rank_compare');
@@ -2281,19 +2253,18 @@
   }
 
-  return array( 'images' =>
-    array (
-      WS_XML_ATTRIBUTES =>
+  return array( 
+      'paging' => new PwgNamedStruct(
         array(
-            'page' => $params['page'],
-            'per_page' => $params['per_page'],
-            'count' => count($images)
-          ),
-       WS_XML_CONTENT => new PwgNamedArray($images, 'image',
+          'page' => $params['page'],
+          'per_page' => $params['per_page'],
+          'count' => count($images),
+          'total_count' => $count_set,
+          ) ),
+       'images' => new PwgNamedArray($images, 'image',
           ws_std_get_image_xml_attributes() )
-      )
     );
 }
 
-function ws_categories_add($params, &$service)
+function ws_categories_add($params, $service)
 {
   if (!is_admin())
@@ -2342,5 +2313,5 @@
 }
 
-function ws_tags_add($params, &$service)
+function ws_tags_add($params, $service)
 {
   if (!is_admin())
@@ -2361,5 +2332,5 @@
 }
 
-function ws_images_exist($params, &$service)
+function ws_images_exist($params, $service)
 {
   ws_logfile(__FUNCTION__.' '.var_export($params, true));
@@ -2441,5 +2412,5 @@
 }
 
-function ws_images_checkFiles($params, &$service)
+function ws_images_checkFiles($params, $service)
 {
   ws_logfile(__FUNCTION__.', input :  '.var_export($params, true));
@@ -2514,5 +2485,5 @@
 }
 
-function ws_images_setInfo($params, &$service)
+function ws_images_setInfo($params, $service)
 {
   global $conf;
@@ -2661,5 +2632,5 @@
 }
 
-function ws_images_delete($params, &$service)
+function ws_images_delete($params, $service)
 {
   global $conf;
@@ -2852,5 +2823,5 @@
 }
 
-function ws_categories_setInfo($params, &$service)
+function ws_categories_setInfo($params, $service)
 {
   global $conf;
@@ -2910,5 +2881,5 @@
 }
 
-function ws_categories_setRepresentative($params, &$service)
+function ws_categories_setRepresentative($params, $service)
 {
   global $conf;
@@ -2982,5 +2953,5 @@
 }
 
-function ws_categories_delete($params, &$service)
+function ws_categories_delete($params, $service)
 {
   global $conf;
@@ -3050,5 +3021,5 @@
 }
 
-function ws_categories_move($params, &$service)
+function ws_categories_move($params, $service)
 {
   global $conf, $page;
@@ -3186,5 +3157,5 @@
 }
 
-function ws_images_checkUpload($params, &$service)
+function ws_images_checkUpload($params, $service)
 {
   global $conf;
@@ -3207,5 +3178,5 @@
 }
 
-function ws_plugins_getList($params, &$service)
+function ws_plugins_getList($params, $service)
 {
   global $conf;
@@ -3232,6 +3203,5 @@
     }
 
-    array_push(
-      $plugin_list,
+    $plugin_list[] =
       array(
         'id' => $plugin_id,
@@ -3240,6 +3210,5 @@
         'state' => $state,
         'description' => $fs_plugin['description'],
-        )
-      );
+        );
   }
 
@@ -3281,5 +3250,5 @@
 }
 
-function ws_themes_performAction($params, &$service)
+function ws_themes_performAction($params, $service)
 {
   global $template;
@@ -3314,5 +3283,5 @@
 }
 
-function ws_extensions_update($params, &$service)
+function ws_extensions_update($params, $service)
 {
   if (!is_webmaster())
@@ -3404,5 +3373,5 @@
 }
 
-function ws_extensions_ignoreupdate($params, &$service)
+function ws_extensions_ignoreupdate($params, $service)
 {
   global $conf;
@@ -3458,5 +3427,5 @@
 }
 
-function ws_extensions_checkupdates($params, &$service)
+function ws_extensions_checkupdates($params, $service)
 {
   global $conf;
Index: /trunk/include/ws_protocols/rest_encoder.php
===================================================================
--- /trunk/include/ws_protocols/rest_encoder.php	(revision 22728)
+++ /trunk/include/ws_protocols/rest_encoder.php	(revision 22729)
@@ -227,9 +227,7 @@
       if ( is_null($value) )
         continue; // null means we dont put it
-      if ($name!=WS_XML_CONTENT)
-        $this->_writer->start_element($name);
+      $this->_writer->start_element($name);
       $this->encode($value);
-      if ($name!=WS_XML_CONTENT)
-        $this->_writer->end_element($name);
+      $this->_writer->end_element($name);
     }
   }
@@ -271,5 +269,5 @@
             break;
           case 'pwgnamedstruct':
-            $this->encode_array( array($data->_content), $data->_name, $data->_xmlAttributes);
+						$this->encode_struct($data->_content, false, $data->_xmlAttributes);
             break;
           default:
