aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/functions.inc.php8
-rw-r--r--include/ws_core.inc.php114
-rw-r--r--include/ws_functions.inc.php303
-rw-r--r--include/ws_protocols/rest_encoder.php8
4 files changed, 158 insertions, 275 deletions
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 1bc4db298..9d8bfa923 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -174,14 +174,6 @@ function mkgetdir($dir, $flags=MKGETDIR_DEFAULT)
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;
-}
-
/* returns 0 if $str is Ascii, 1 if utf-8, -1 otherwise */
function qualify_utf8($Str)
{
diff --git a/include/ws_core.inc.php b/include/ws_core.inc.php
index fdddbdf06..e72c7d57a 100644
--- a/include/ws_core.inc.php
+++ b/include/ws_core.inc.php
@@ -40,7 +40,6 @@ define( 'WS_ERR_MISSING_PARAM', 1002 );
define( 'WS_ERR_INVALID_PARAM', 1003 );
define( 'WS_XML_ATTRIBUTES', 'attributes_xml_');
-define( 'WS_XML_CONTENT', 'content_xml_');
/**
* PwgError object can be returned from any web service function implementation.
@@ -98,7 +97,6 @@ class PwgNamedArray
class PwgNamedStruct
{
/*private*/ var $_content;
- /*private*/ var $_name;
/*private*/ var $_xmlAttributes;
/**
@@ -110,9 +108,8 @@ class PwgNamedStruct
* encoded as xml attributes (if null - automatically prefer xml attributes
* whenever possible)
*/
- function PwgNamedStruct($name, $content, $xmlAttributes=null, $xmlElements=null )
+ function PwgNamedStruct($content, $xmlAttributes=null, $xmlElements=null )
{
- $this->_name = $name;
$this->_content = $content;
if ( isset($xmlAttributes) )
{
@@ -182,115 +179,42 @@ class PwgResponseEncoder
* removes all XML formatting from $response (named array, named structs, etc)
* usually called by every response encoder, except rest xml.
*/
- static function flattenResponse(&$response)
+ static function flattenResponse(&$value)
{
- 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);
+ self::flatten($value);
}
- private static function _mergeAttributesAndContent(&$value)
+ private static function flatten(&$value)
{
- 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 (is_object($value))
{
- if ( isset($value[WS_XML_ATTRIBUTES]) )
+ $class = strtolower( @get_class($value) );
+ if ($class == 'pwgnamedarray')
{
- $value = array_merge( $value, $value[WS_XML_ATTRIBUTES] );
- unset( $value[WS_XML_ATTRIBUTES] );
- $ret=1;
+ $value = $value->_content;
}
- if ( isset($value[WS_XML_CONTENT]) )
+ if ($class == 'pwgnamedstruct')
{
- $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++;
- }
+ $value = $value->_content;
}
}
- foreach ($value as $key=>$v)
+ if (!is_array($value))
+ return;
+
+ if (self::is_struct($value))
{
- if ( PwgResponseEncoder::_mergeAttributesAndContent($v) )
+ if ( isset($value[WS_XML_ATTRIBUTES]) )
{
- $value[$key]=$v;
- $ret++;
+ $value = array_merge( $value, $value[WS_XML_ATTRIBUTES] );
+ unset( $value[WS_XML_ATTRIBUTES] );
}
}
- 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')
+ foreach ($value as $key=>&$v)
{
- if ( isset($value->_content['']) )
- {
- $unknown = $value->_content[''];
- unset( $value->_content[''] );
- $value->_content[$value->_name] = $unknown;
- }
- $value = $value->_content;
- return 1;
+ self::flatten($v);
}
- return 0;
}
}
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 73f8e9942..43ecffd07 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -192,7 +192,21 @@ function ws_std_get_image_xml_attributes()
);
}
-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())
{
@@ -291,7 +305,7 @@ function ws_getMissingDerivatives($params, &$service)
/**
* returns PWG version (web service method)
*/
-function ws_getVersion($params, &$service)
+function ws_getVersion($params, $service)
{
global $conf;
if ($conf['show_version'] or is_admin() )
@@ -303,7 +317,7 @@ function ws_getVersion($params, &$service)
/**
* returns general informations (web service method)
*/
-function ws_getInfos($params, &$service)
+function ws_getInfos($params, $service)
{
if (!is_admin())
{
@@ -367,7 +381,7 @@ function ws_getInfos($params, &$service)
return array('infos' => new PwgNamedArray($output, 'item'));
}
-function ws_caddie_add($params, &$service)
+function ws_caddie_add($params, $service)
{
if (!is_admin())
{
@@ -400,7 +414,7 @@ SELECT id
/**
* returns images per category (web service method)
*/
-function ws_categories_getImages($params, &$service)
+function ws_categories_getImages($params, $service)
{
global $user, $conf;
@@ -469,6 +483,9 @@ SELECT id, name, permalink, image_order
}
$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
FROM '.IMAGES_TABLE.' i
@@ -477,7 +494,7 @@ SELECT i.*, GROUP_CONCAT(category_id) AS cat_ids
AND ', $where_clauses).'
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);
while ($row = pwg_db_fetch_assoc($result))
@@ -511,34 +528,28 @@ LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['p
'image_file' => $row['file'],
)
);
- 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,
+ );
}
$image['categories'] = new PwgNamedArray(
$image_cats,'category', array('id','url','page_url')
);
- array_push($images, $image);
+ $images[] = $image;
}
}
- 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',
- ws_std_get_image_xml_attributes() )
- )
+ ) ),
+ 'images' => new PwgNamedArray($images, 'image', ws_std_get_image_xml_attributes() )
);
}
@@ -557,16 +568,16 @@ function categories_flatlist_to_tree($categories)
if (!isset($node['id_uppercat']))
{
- $tree[$key] = &$node;
+ $tree[] = &$node;
}
else
{
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;
}
}
@@ -576,26 +587,10 @@ function categories_flatlist_to_tree($categories)
/**
* 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');
$join_type = 'INNER';
$join_user = $user['id'];
@@ -608,7 +603,7 @@ function ws_categories_getList($params, &$service)
else
$where[] = 'id_uppercat IS NULL';
}
- else if ($params['cat_id']>0)
+ elseif ($params['cat_id']>0)
{
$where[] = 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.
(int)($params['cat_id'])
@@ -704,11 +699,11 @@ SELECT id, name, permalink, uppercats, global_rank, id_uppercat,
{
$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
$image_id = get_random_image_in_category($row);
@@ -746,18 +741,18 @@ SELECT id, name, permalink, uppercats, global_rank, id_uppercat,
{
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);
// management of the album thumbnail -- stops here
- array_push($cats, $row);
+ $cats[] = $row;
}
usort($cats, 'global_rank_compare');
@@ -803,7 +798,7 @@ SELECT id, path, representative_ext, level
if ($conf['representative_cache_on_level'])
{
- $user_representative_updates_for[ $user['id'].'#'.$category['id'] ] = $image_id;
+ $user_representative_updates_for[ $category['id'] ] = $image_id;
}
$category['representative_picture_id'] = $image_id;
@@ -835,14 +830,12 @@ SELECT id, path, representative_ext
{
$updates = array();
- foreach ($user_representative_updates_for as $user_cat => $image_id)
+ foreach ($user_representative_updates_for as $cat_id => $image_id)
{
- list($user_id, $cat_id) = explode('#', $user_cat);
-
array_push(
$updates,
array(
- 'user_id' => $user_id,
+ 'user_id' => $user['id'],
'cat_id' => $cat_id,
'user_representative_picture_id' => $image_id,
)
@@ -878,26 +871,12 @@ SELECT id, path, representative_ext
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())
+ );
}
/**
@@ -907,7 +886,7 @@ SELECT id, path, representative_ext
* Only admin can run this method and permissions are not taken into
* account.
*/
-function ws_categories_getAdminList($params, &$service)
+function ws_categories_getAdminList($params, $service)
{
if (!is_admin())
{
@@ -953,7 +932,7 @@ SELECT
'ws_categories_getAdminList'
)
);
- array_push($cats, $row);
+ $cats[] = $row;
}
usort($cats, 'global_rank_compare');
@@ -975,7 +954,7 @@ SELECT
/**
* returns detailed information for an element (web service method)
*/
-function ws_images_addComment($params, &$service)
+function ws_images_addComment($params, $service)
{
if (!$service->isPost())
{
@@ -1023,11 +1002,7 @@ SELECT DISTINCT image_id
'id' => $comm['id'],
'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 );
}
@@ -1036,7 +1011,7 @@ SELECT DISTINCT image_id
/**
* returns detailed information for an element (web service method)
*/
-function ws_images_getInfo($params, &$service)
+function ws_images_getInfo($params, $service)
{
global $user, $conf;
$params['image_id'] = (int)$params['image_id'];
@@ -1171,7 +1146,7 @@ SELECT id, date, author, content
while ($row = pwg_db_fetch_assoc($result))
{
$row['id']=(int)$row['id'];
- array_push($related_comments, $row);
+ $related_comments[] = $row;
}
}
@@ -1201,30 +1176,31 @@ SELECT id, date, author, content
$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') )
- );
+ $ret['comments_paging'] = new PwgNamedStruct( array(
+ 'page' => $params['comments_page'],
+ 'per_page' => $params['comments_per_page'],
+ 'count' => count($related_comments),
+ 'total_count' => $nb_comments,
+ ) );
- return new PwgNamedStruct('image',$ret, null, array('name','comment') );
+ $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') ) );
}
/**
* 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'];
$query = '
@@ -1258,7 +1234,7 @@ SELECT DISTINCT id FROM '.IMAGES_TABLE.'
/**
* returns a list of elements corresponding to a query search
*/
-function ws_images_search($params, &$service)
+function ws_images_search($params, $service)
{
global $page;
$images = array();
@@ -1280,6 +1256,9 @@ function ws_images_search($params, &$service)
implode(' AND ', $where_clauses)
);
+ $params['per_page'] = (int)$params['per_page'];
+ $params['page'] = (int)$params['page'];
+
$image_ids = array_slice(
$search_result['items'],
$params['page']*$params['per_page'],
@@ -1315,22 +1294,20 @@ SELECT * FROM '.IMAGES_TABLE.'
$images = array_values($images);
}
-
- 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())
{
@@ -1365,7 +1342,7 @@ UPDATE '.IMAGES_TABLE.'
return $affected_rows;
}
-function ws_images_setRank($params, &$service)
+function ws_images_setRank($params, $service)
{
if (!is_admin())
{
@@ -1477,7 +1454,7 @@ UPDATE '.IMAGE_CATEGORY_TABLE.'
);
}
-function ws_images_add_chunk($params, &$service)
+function ws_images_add_chunk($params, $service)
{
global $conf;
@@ -1636,7 +1613,7 @@ function remove_chunks($original_sum, $type)
}
}
-function ws_images_addFile($params, &$service)
+function ws_images_addFile($params, $service)
{
ws_logfile(__FUNCTION__.', input : '.var_export($params, true));
// image_id
@@ -1731,7 +1708,7 @@ SELECT
);
}
-function ws_images_add($params, &$service)
+function ws_images_add($params, $service)
{
global $conf, $user;
if (!is_admin())
@@ -1889,7 +1866,7 @@ SELECT id, name, permalink
);
}
-function ws_images_addSimple($params, &$service)
+function ws_images_addSimple($params, $service)
{
global $conf;
if (!is_admin())
@@ -2026,7 +2003,7 @@ SELECT id, name, permalink
);
}
-function ws_rates_delete($params, &$service)
+function ws_rates_delete($params, $service)
{
global $conf;
@@ -2068,7 +2045,7 @@ DELETE FROM '.RATE_TABLE.'
/**
* perform a login (web service method)
*/
-function ws_session_login($params, &$service)
+function ws_session_login($params, $service)
{
global $conf;
@@ -2087,7 +2064,7 @@ function ws_session_login($params, &$service)
/**
* performs a logout (web service method)
*/
-function ws_session_logout($params, &$service)
+function ws_session_logout($params, $service)
{
if (!is_a_guest())
{
@@ -2096,7 +2073,7 @@ function ws_session_logout($params, &$service)
return true;
}
-function ws_session_getStatus($params, &$service)
+function ws_session_getStatus($params, $service)
{
global $user;
$res = array();
@@ -2118,7 +2095,7 @@ function ws_session_getStatus($params, &$service)
/**
* returns a list of tags (web service method)
*/
-function ws_tags_getList($params, &$service)
+function ws_tags_getList($params, $service)
{
$tags = get_available_tags();
if ($params['sort_by_counter'])
@@ -2140,7 +2117,7 @@ function ws_tags_getList($params, &$service)
)
);
}
- 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()) );
}
/**
@@ -2150,7 +2127,7 @@ function ws_tags_getList($params, &$service)
* Only admin can run this method and permissions are not taken into
* account.
*/
-function ws_tags_getAdminList($params, &$service)
+function ws_tags_getAdminList($params, $service)
{
if (!is_admin())
{
@@ -2162,11 +2139,7 @@ function ws_tags_getAdminList($params, &$service)
'tags' => new PwgNamedArray(
$tags,
'tag',
- array(
- 'name',
- 'id',
- 'url_name',
- )
+ ws_std_get_tag_xml_attributes()
)
);
}
@@ -2174,7 +2147,7 @@ function ws_tags_getAdminList($params, &$service)
/**
* returns a list of images for tags (web service method)
*/
-function ws_tags_getImages($params, &$service)
+function ws_tags_getImages($params, $service)
{
global $conf;
@@ -2202,8 +2175,10 @@ function ws_tags_getImages($params, &$service)
$where_clauses,
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();
if ( !empty($image_ids) and !$params['tag_mode_and'] )
@@ -2217,7 +2192,7 @@ SELECT image_id, GROUP_CONCAT(tag_id) AS tag_ids
while ( $row=pwg_db_fetch_assoc($result) )
{
$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']);
}
}
@@ -2264,37 +2239,33 @@ SELECT * FROM '.IMAGES_TABLE.'
'image_file' => $row['file'],
)
);
- 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');
unset($rank_of);
}
- 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())
{
@@ -2341,7 +2312,7 @@ function ws_categories_add($params, &$service)
return $creation_output;
}
-function ws_tags_add($params, &$service)
+function ws_tags_add($params, $service)
{
if (!is_admin())
{
@@ -2360,7 +2331,7 @@ function ws_tags_add($params, &$service)
return $creation_output;
}
-function ws_images_exist($params, &$service)
+function ws_images_exist($params, $service)
{
ws_logfile(__FUNCTION__.' '.var_export($params, true));
@@ -2440,7 +2411,7 @@ SELECT
return $result;
}
-function ws_images_checkFiles($params, &$service)
+function ws_images_checkFiles($params, $service)
{
ws_logfile(__FUNCTION__.', input : '.var_export($params, true));
@@ -2513,7 +2484,7 @@ SELECT
return $ret;
}
-function ws_images_setInfo($params, &$service)
+function ws_images_setInfo($params, $service)
{
global $conf;
if (!is_admin())
@@ -2660,7 +2631,7 @@ SELECT *
invalidate_user_cache();
}
-function ws_images_delete($params, &$service)
+function ws_images_delete($params, $service)
{
global $conf;
if (!is_admin())
@@ -2851,7 +2822,7 @@ SELECT
update_category($new_cat_ids);
}
-function ws_categories_setInfo($params, &$service)
+function ws_categories_setInfo($params, $service)
{
global $conf;
if (!is_admin())
@@ -2909,7 +2880,7 @@ function ws_categories_setInfo($params, &$service)
}
-function ws_categories_setRepresentative($params, &$service)
+function ws_categories_setRepresentative($params, $service)
{
global $conf;
@@ -2981,7 +2952,7 @@ UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
pwg_query($query);
}
-function ws_categories_delete($params, &$service)
+function ws_categories_delete($params, $service)
{
global $conf;
if (!is_admin())
@@ -3049,7 +3020,7 @@ SELECT id
update_global_rank();
}
-function ws_categories_move($params, &$service)
+function ws_categories_move($params, $service)
{
global $conf, $page;
@@ -3185,7 +3156,7 @@ function ws_logfile($string)
);
}
-function ws_images_checkUpload($params, &$service)
+function ws_images_checkUpload($params, $service)
{
global $conf;
@@ -3206,7 +3177,7 @@ function ws_images_checkUpload($params, &$service)
return $ret;
}
-function ws_plugins_getList($params, &$service)
+function ws_plugins_getList($params, $service)
{
global $conf;
@@ -3231,16 +3202,14 @@ function ws_plugins_getList($params, &$service)
$state = 'uninstalled';
}
- array_push(
- $plugin_list,
+ $plugin_list[] =
array(
'id' => $plugin_id,
'name' => $fs_plugin['name'],
'version' => $fs_plugin['version'],
'state' => $state,
'description' => $fs_plugin['description'],
- )
- );
+ );
}
return $plugin_list;
@@ -3280,7 +3249,7 @@ function ws_plugins_performAction($params, &$service)
}
}
-function ws_themes_performAction($params, &$service)
+function ws_themes_performAction($params, $service)
{
global $template;
@@ -3313,7 +3282,7 @@ function ws_themes_performAction($params, &$service)
}
}
-function ws_extensions_update($params, &$service)
+function ws_extensions_update($params, $service)
{
if (!is_webmaster())
{
@@ -3403,7 +3372,7 @@ function ws_extensions_update($params, &$service)
}
}
-function ws_extensions_ignoreupdate($params, &$service)
+function ws_extensions_ignoreupdate($params, $service)
{
global $conf;
@@ -3457,7 +3426,7 @@ function ws_extensions_ignoreupdate($params, &$service)
return true;
}
-function ws_extensions_checkupdates($params, &$service)
+function ws_extensions_checkupdates($params, $service)
{
global $conf;
diff --git a/include/ws_protocols/rest_encoder.php b/include/ws_protocols/rest_encoder.php
index 5f86acb6d..c02d18222 100644
--- a/include/ws_protocols/rest_encoder.php
+++ b/include/ws_protocols/rest_encoder.php
@@ -226,11 +226,9 @@ class PwgRestEncoder extends PwgResponseEncoder
continue;
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);
}
}
@@ -270,7 +268,7 @@ class PwgRestEncoder extends PwgResponseEncoder
$this->encode_array($data->_content, $data->_itemName, $data->_xmlAttributes);
break;
case 'pwgnamedstruct':
- $this->encode_array( array($data->_content), $data->_name, $data->_xmlAttributes);
+ $this->encode_struct($data->_content, false, $data->_xmlAttributes);
break;
default:
$this->encode_struct(get_object_vars($data), true);