Changeset 22729 for trunk/include/ws_functions.inc.php
- Timestamp:
- May 18, 2013, 5:58:36 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/ws_functions.inc.php
r22302 r22729 193 193 } 194 194 195 function ws_getMissingDerivatives($params, &$service) 195 function ws_std_get_category_xml_attributes() 196 { 197 return array( 198 'id', 'url', 'nb_images', 'total_nb_images', 'nb_categories', 'date_last', 'max_date_last', 199 ); 200 } 201 202 function ws_std_get_tag_xml_attributes() 203 { 204 return array( 205 'id', 'name', 'url_name', 'counter', 'url', 'page_url', 206 ); 207 } 208 209 function ws_getMissingDerivatives($params, $service) 196 210 { 197 211 if (!is_admin()) … … 292 306 * returns PWG version (web service method) 293 307 */ 294 function ws_getVersion($params, &$service)308 function ws_getVersion($params, $service) 295 309 { 296 310 global $conf; … … 304 318 * returns general informations (web service method) 305 319 */ 306 function ws_getInfos($params, &$service)320 function ws_getInfos($params, $service) 307 321 { 308 322 if (!is_admin()) … … 368 382 } 369 383 370 function ws_caddie_add($params, &$service)384 function ws_caddie_add($params, $service) 371 385 { 372 386 if (!is_admin()) … … 401 415 * returns images per category (web service method) 402 416 */ 403 function ws_categories_getImages($params, &$service)417 function ws_categories_getImages($params, $service) 404 418 { 405 419 global $user, $conf; … … 470 484 $order_by = empty($order_by) ? $conf['order_by'] : 'ORDER BY '.$order_by; 471 485 486 $params['per_page'] = (int)$params['per_page']; 487 $params['page'] = (int)$params['page']; 488 472 489 $query = ' 473 490 SELECT i.*, GROUP_CONCAT(category_id) AS cat_ids … … 478 495 GROUP BY i.id 479 496 '.$order_by.' 480 LIMIT '. (int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']);497 LIMIT '.$params['per_page'].' OFFSET '.($params['per_page']*$params['page']); 481 498 482 499 $result = pwg_query($query); … … 512 529 ) 513 530 ); 514 array_push( $image_cats, array( 515 WS_XML_ATTRIBUTES => array ( 516 'id' => (int)$cat_id, 517 'url' => $url, 518 'page_url' => $page_url, 519 ) 520 ) 521 ); 531 $image_cats[] = array ( 532 'id' => (int)$cat_id, 533 'url' => $url, 534 'page_url' => $page_url, 535 ); 522 536 } 523 537 … … 525 539 $image_cats,'category', array('id','url','page_url') 526 540 ); 527 array_push($images, $image); 528 } 529 } 530 531 return array( 'images' => 532 array ( 533 WS_XML_ATTRIBUTES => 541 $images[] = $image; 542 } 543 } 544 545 return array ( 546 'paging' => new PwgNamedStruct( 534 547 array( 535 548 'page' => $params['page'], 536 549 'per_page' => $params['per_page'], 537 550 'count' => count($images) 538 ), 539 WS_XML_CONTENT => new PwgNamedArray($images, 'image', 540 ws_std_get_image_xml_attributes() ) 541 ) 551 ) ), 552 'images' => new PwgNamedArray($images, 'image', ws_std_get_image_xml_attributes() ) 542 553 ); 543 554 } … … 558 569 if (!isset($node['id_uppercat'])) 559 570 { 560 $tree[ $key] = &$node;571 $tree[] = &$node; 561 572 } 562 573 else … … 564 575 if (!isset($categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'])) 565 576 { 566 $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] = array();577 $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] = new PwgNamedArray(array(), 'category', ws_std_get_category_xml_attributes()); 567 578 } 568 579 569 $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] [$key] = &$node;580 $categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories']->_content[] = &$node; 570 581 } 571 582 } … … 577 588 * returns a list of categories (web service method) 578 589 */ 579 function ws_categories_getList($params, &$service)590 function ws_categories_getList($params, $service) 580 591 { 581 592 global $user,$conf; 582 583 if ($params['tree_output'])584 {585 if (!isset($_GET['format']) or !in_array($_GET['format'], array('php', 'json')))586 {587 // the algorithm used to build a tree from a flat list of categories588 // keeps original array keys, which is not compatible with589 // PwgNamedArray.590 //591 // PwgNamedArray is useful to define which data is an attribute and592 // which is an element in the XML output. The "hierarchy" output is593 // only compatible with json/php output.594 595 return new PwgError(405, "The tree_output option is only compatible with json/php output formats");596 }597 }598 593 599 594 $where = array('1=1'); … … 609 604 $where[] = 'id_uppercat IS NULL'; 610 605 } 611 else 606 elseif ($params['cat_id']>0) 612 607 { 613 608 $where[] = 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'. … … 705 700 $image_id = $row['user_representative_picture_id']; 706 701 } 707 else 702 elseif (!empty($row['representative_picture_id'])) 708 703 { // if a representative picture is set, it has priority 709 704 $image_id = $row['representative_picture_id']; 710 705 } 711 else 706 elseif ($conf['allow_random_representative']) 712 707 { 713 708 // searching a random representant among elements in sub-categories … … 747 742 if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id) 748 743 { 749 $user_representative_updates_for[ $ user['id'].'#'.$row['id'] ] = $image_id;744 $user_representative_updates_for[ $row['id'] ] = $image_id; 750 745 } 751 746 752 747 $row['representative_picture_id'] = $image_id; 753 array_push($image_ids, $image_id);754 array_push($categories, $row);748 $image_ids[] = $image_id; 749 $categories[] = $row; 755 750 } 756 751 unset($image_id); … … 758 753 759 754 760 array_push($cats, $row);755 $cats[] = $row; 761 756 } 762 757 usort($cats, 'global_rank_compare'); … … 804 799 if ($conf['representative_cache_on_level']) 805 800 { 806 $user_representative_updates_for[ $ user['id'].'#'.$category['id'] ] = $image_id;801 $user_representative_updates_for[ $category['id'] ] = $image_id; 807 802 } 808 803 … … 836 831 $updates = array(); 837 832 838 foreach ($user_representative_updates_for as $user_cat => $image_id) 839 { 840 list($user_id, $cat_id) = explode('#', $user_cat); 841 833 foreach ($user_representative_updates_for as $cat_id => $image_id) 834 { 842 835 array_push( 843 836 $updates, 844 837 array( 845 'user_id' => $user _id,838 'user_id' => $user['id'], 846 839 'cat_id' => $cat_id, 847 840 'user_representative_picture_id' => $image_id, … … 879 872 if ($params['tree_output']) 880 873 { 881 return categories_flatlist_to_tree($cats); 882 } 883 else 884 { 885 return array( 886 'categories' => new PwgNamedArray( 887 $cats, 888 'category', 889 array( 890 'id', 891 'url', 892 'nb_images', 893 'total_nb_images', 894 'nb_categories', 895 'date_last', 896 'max_date_last', 897 ) 898 ) 899 ); 900 } 874 $cats = categories_flatlist_to_tree($cats); 875 } 876 877 return array( 878 'categories' => new PwgNamedArray($cats, 'category', ws_std_get_category_xml_attributes()) 879 ); 901 880 } 902 881 … … 908 887 * account. 909 888 */ 910 function ws_categories_getAdminList($params, &$service)889 function ws_categories_getAdminList($params, $service) 911 890 { 912 891 if (!is_admin()) … … 954 933 ) 955 934 ); 956 array_push($cats, $row);935 $cats[] = $row; 957 936 } 958 937 … … 976 955 * returns detailed information for an element (web service method) 977 956 */ 978 function ws_images_addComment($params, &$service)957 function ws_images_addComment($params, $service) 979 958 { 980 959 if (!$service->isPost()) … … 1024 1003 'validation' => $comment_action=='validate', 1025 1004 ); 1026 return new PwgNamedStruct( 1027 'comment', 1028 $ret, 1029 null, array() 1030 ); 1005 return array( 'comment' => new PwgNamedStruct($ret) ); 1031 1006 default: 1032 1007 return new PwgError(500, "Unknown comment action ".$comment_action ); … … 1037 1012 * returns detailed information for an element (web service method) 1038 1013 */ 1039 function ws_images_getInfo($params, &$service)1014 function ws_images_getInfo($params, $service) 1040 1015 { 1041 1016 global $user, $conf; … … 1172 1147 { 1173 1148 $row['id']=(int)$row['id']; 1174 array_push($related_comments, $row);1149 $related_comments[] = $row; 1175 1150 } 1176 1151 } … … 1202 1177 $ret['rates'] = array( WS_XML_ATTRIBUTES => $rating ); 1203 1178 $ret['categories'] = new PwgNamedArray($related_categories, 'category', array('id','url', 'page_url') ); 1204 $ret['tags'] = new PwgNamedArray($related_tags, 'tag', array('id','url_name','url','name','page_url') );1179 $ret['tags'] = new PwgNamedArray($related_tags, 'tag', ws_std_get_tag_xml_attributes() ); 1205 1180 if ( isset($comment_post_data) ) 1206 1181 { 1207 1182 $ret['comment_post'] = array( WS_XML_ATTRIBUTES => $comment_post_data ); 1208 1183 } 1209 $ret['comments'] = array( 1210 WS_XML_ATTRIBUTES => 1211 array( 1212 'page' => $params['comments_page'], 1213 'per_page' => $params['comments_per_page'], 1214 'count' => count($related_comments), 1215 'nb_comments' => $nb_comments, 1216 ), 1217 WS_XML_CONTENT => new PwgNamedArray($related_comments, 'comment', array('id','date') ) 1218 ); 1219 1220 return new PwgNamedStruct('image',$ret, null, array('name','comment') ); 1184 $ret['comments_paging'] = new PwgNamedStruct( array( 1185 'page' => $params['comments_page'], 1186 'per_page' => $params['comments_per_page'], 1187 'count' => count($related_comments), 1188 'total_count' => $nb_comments, 1189 ) ); 1190 1191 $ret['comments'] = new PwgNamedArray($related_comments, 'comment', array('id','date') ); 1192 1193 if ($service->_responseFormat != 'rest') 1194 return $ret; // for backward compatibility only 1195 else 1196 return array( 'image' => new PwgNamedStruct($ret, null, array('name','comment') ) ); 1221 1197 } 1222 1198 … … 1225 1201 * rates the image_id in the parameter 1226 1202 */ 1227 function ws_images_Rate($params, &$service)1203 function ws_images_Rate($params, $service) 1228 1204 { 1229 1205 $image_id = (int)$params['image_id']; … … 1259 1235 * returns a list of elements corresponding to a query search 1260 1236 */ 1261 function ws_images_search($params, &$service)1237 function ws_images_search($params, $service) 1262 1238 { 1263 1239 global $page; … … 1280 1256 implode(' AND ', $where_clauses) 1281 1257 ); 1258 1259 $params['per_page'] = (int)$params['per_page']; 1260 $params['page'] = (int)$params['page']; 1282 1261 1283 1262 $image_ids = array_slice( … … 1316 1295 } 1317 1296 1318 1319 return array( 'images' => 1320 array ( 1321 WS_XML_ATTRIBUTES => 1322 array( 1323 'page' => $params['page'], 1324 'per_page' => $params['per_page'], 1325 'count' => count($images) 1326 ), 1327 WS_XML_CONTENT => new PwgNamedArray($images, 'image', 1328 ws_std_get_image_xml_attributes() ) 1329 ) 1297 return array ( 1298 'paging' => new PwgNamedStruct( 1299 array( 1300 'page' => $params['page'], 1301 'per_page' => $params['per_page'], 1302 'count' => count($images), 1303 'total_count' => count($search_result['items']), 1304 ) ), 1305 'images' => new PwgNamedArray($images, 'image', 1306 ws_std_get_image_xml_attributes() ) 1330 1307 ); 1331 1308 } 1332 1309 1333 function ws_images_setPrivacyLevel($params, &$service)1310 function ws_images_setPrivacyLevel($params, $service) 1334 1311 { 1335 1312 if (!is_admin()) … … 1366 1343 } 1367 1344 1368 function ws_images_setRank($params, &$service)1345 function ws_images_setRank($params, $service) 1369 1346 { 1370 1347 if (!is_admin()) … … 1478 1455 } 1479 1456 1480 function ws_images_add_chunk($params, &$service)1457 function ws_images_add_chunk($params, $service) 1481 1458 { 1482 1459 global $conf; … … 1637 1614 } 1638 1615 1639 function ws_images_addFile($params, &$service)1616 function ws_images_addFile($params, $service) 1640 1617 { 1641 1618 ws_logfile(__FUNCTION__.', input : '.var_export($params, true)); … … 1732 1709 } 1733 1710 1734 function ws_images_add($params, &$service)1711 function ws_images_add($params, $service) 1735 1712 { 1736 1713 global $conf, $user; … … 1890 1867 } 1891 1868 1892 function ws_images_addSimple($params, &$service)1869 function ws_images_addSimple($params, $service) 1893 1870 { 1894 1871 global $conf; … … 2027 2004 } 2028 2005 2029 function ws_rates_delete($params, &$service)2006 function ws_rates_delete($params, $service) 2030 2007 { 2031 2008 global $conf; … … 2069 2046 * perform a login (web service method) 2070 2047 */ 2071 function ws_session_login($params, &$service)2048 function ws_session_login($params, $service) 2072 2049 { 2073 2050 global $conf; … … 2088 2065 * performs a logout (web service method) 2089 2066 */ 2090 function ws_session_logout($params, &$service)2067 function ws_session_logout($params, $service) 2091 2068 { 2092 2069 if (!is_a_guest()) … … 2097 2074 } 2098 2075 2099 function ws_session_getStatus($params, &$service)2076 function ws_session_getStatus($params, $service) 2100 2077 { 2101 2078 global $user; … … 2119 2096 * returns a list of tags (web service method) 2120 2097 */ 2121 function ws_tags_getList($params, &$service)2098 function ws_tags_getList($params, $service) 2122 2099 { 2123 2100 $tags = get_available_tags(); … … 2141 2118 ); 2142 2119 } 2143 return array('tags' => new PwgNamedArray($tags, 'tag', array('id','url_name','url', 'name', 'counter')) );2120 return array('tags' => new PwgNamedArray($tags, 'tag', ws_std_get_tag_xml_attributes()) ); 2144 2121 } 2145 2122 … … 2151 2128 * account. 2152 2129 */ 2153 function ws_tags_getAdminList($params, &$service)2130 function ws_tags_getAdminList($params, $service) 2154 2131 { 2155 2132 if (!is_admin()) … … 2163 2140 $tags, 2164 2141 'tag', 2165 array( 2166 'name', 2167 'id', 2168 'url_name', 2169 ) 2142 ws_std_get_tag_xml_attributes() 2170 2143 ) 2171 2144 ); … … 2175 2148 * returns a list of images for tags (web service method) 2176 2149 */ 2177 function ws_tags_getImages($params, &$service)2150 function ws_tags_getImages($params, $service) 2178 2151 { 2179 2152 global $conf; … … 2203 2176 ws_std_image_sql_order($params) ); 2204 2177 2205 2206 $image_ids = array_slice($image_ids, (int)($params['per_page']*$params['page']), (int)$params['per_page'] ); 2178 $count_set = count($image_ids); 2179 $params['per_page'] = (int)$params['per_page']; 2180 $params['page'] = (int)$params['page']; 2181 $image_ids = array_slice($image_ids, $params['per_page']*$params['page'], $params['per_page'] ); 2207 2182 2208 2183 $image_tag_map = array(); … … 2218 2193 { 2219 2194 $row['image_id'] = (int)$row['image_id']; 2220 array_push( $image_ids, $row['image_id'] );2195 $image_ids[] = $row['image_id']; 2221 2196 $image_tag_map[ $row['image_id'] ] = explode(',', $row['tag_ids']); 2222 2197 } … … 2265 2240 ) 2266 2241 ); 2267 array_push($image_tags,array(2242 $image_tags[] = array( 2268 2243 'id' => (int)$tag_id, 2269 2244 'url' => $url, 2270 2245 'page_url' => $page_url, 2271 ) 2272 ); 2246 ); 2273 2247 } 2274 $image['tags'] = new PwgNamedArray($image_tags, 'tag', 2275 array('id','url_name','url','page_url') 2276 ); 2277 array_push($images, $image); 2248 $image['tags'] = new PwgNamedArray($image_tags, 'tag', ws_std_get_tag_xml_attributes() ); 2249 $images[] = $image; 2278 2250 } 2279 2251 usort($images, 'rank_compare'); … … 2281 2253 } 2282 2254 2283 return array( 'images' => 2284 array ( 2285 WS_XML_ATTRIBUTES => 2255 return array( 2256 'paging' => new PwgNamedStruct( 2286 2257 array( 2287 'page' => $params['page'], 2288 'per_page' => $params['per_page'], 2289 'count' => count($images) 2290 ), 2291 WS_XML_CONTENT => new PwgNamedArray($images, 'image', 2258 'page' => $params['page'], 2259 'per_page' => $params['per_page'], 2260 'count' => count($images), 2261 'total_count' => $count_set, 2262 ) ), 2263 'images' => new PwgNamedArray($images, 'image', 2292 2264 ws_std_get_image_xml_attributes() ) 2293 )2294 2265 ); 2295 2266 } 2296 2267 2297 function ws_categories_add($params, &$service)2268 function ws_categories_add($params, $service) 2298 2269 { 2299 2270 if (!is_admin()) … … 2342 2313 } 2343 2314 2344 function ws_tags_add($params, &$service)2315 function ws_tags_add($params, $service) 2345 2316 { 2346 2317 if (!is_admin()) … … 2361 2332 } 2362 2333 2363 function ws_images_exist($params, &$service)2334 function ws_images_exist($params, $service) 2364 2335 { 2365 2336 ws_logfile(__FUNCTION__.' '.var_export($params, true)); … … 2441 2412 } 2442 2413 2443 function ws_images_checkFiles($params, &$service)2414 function ws_images_checkFiles($params, $service) 2444 2415 { 2445 2416 ws_logfile(__FUNCTION__.', input : '.var_export($params, true)); … … 2514 2485 } 2515 2486 2516 function ws_images_setInfo($params, &$service)2487 function ws_images_setInfo($params, $service) 2517 2488 { 2518 2489 global $conf; … … 2661 2632 } 2662 2633 2663 function ws_images_delete($params, &$service)2634 function ws_images_delete($params, $service) 2664 2635 { 2665 2636 global $conf; … … 2852 2823 } 2853 2824 2854 function ws_categories_setInfo($params, &$service)2825 function ws_categories_setInfo($params, $service) 2855 2826 { 2856 2827 global $conf; … … 2910 2881 } 2911 2882 2912 function ws_categories_setRepresentative($params, &$service)2883 function ws_categories_setRepresentative($params, $service) 2913 2884 { 2914 2885 global $conf; … … 2982 2953 } 2983 2954 2984 function ws_categories_delete($params, &$service)2955 function ws_categories_delete($params, $service) 2985 2956 { 2986 2957 global $conf; … … 3050 3021 } 3051 3022 3052 function ws_categories_move($params, &$service)3023 function ws_categories_move($params, $service) 3053 3024 { 3054 3025 global $conf, $page; … … 3186 3157 } 3187 3158 3188 function ws_images_checkUpload($params, &$service)3159 function ws_images_checkUpload($params, $service) 3189 3160 { 3190 3161 global $conf; … … 3207 3178 } 3208 3179 3209 function ws_plugins_getList($params, &$service)3180 function ws_plugins_getList($params, $service) 3210 3181 { 3211 3182 global $conf; … … 3232 3203 } 3233 3204 3234 array_push( 3235 $plugin_list, 3205 $plugin_list[] = 3236 3206 array( 3237 3207 'id' => $plugin_id, … … 3240 3210 'state' => $state, 3241 3211 'description' => $fs_plugin['description'], 3242 ) 3243 ); 3212 ); 3244 3213 } 3245 3214 … … 3281 3250 } 3282 3251 3283 function ws_themes_performAction($params, &$service)3252 function ws_themes_performAction($params, $service) 3284 3253 { 3285 3254 global $template; … … 3314 3283 } 3315 3284 3316 function ws_extensions_update($params, &$service)3285 function ws_extensions_update($params, $service) 3317 3286 { 3318 3287 if (!is_webmaster()) … … 3404 3373 } 3405 3374 3406 function ws_extensions_ignoreupdate($params, &$service)3375 function ws_extensions_ignoreupdate($params, $service) 3407 3376 { 3408 3377 global $conf; … … 3458 3427 } 3459 3428 3460 function ws_extensions_checkupdates($params, &$service)3429 function ws_extensions_checkupdates($params, $service) 3461 3430 { 3462 3431 global $conf;
Note: See TracChangeset
for help on using the changeset viewer.