Changeset 2569
- Timestamp:
- Sep 22, 2008, 11:47:03 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/ws_functions.inc.php
r2563 r2569 975 975 // fwrite($fh_log, 'output: '.md5_file($thumbnail_path)."\n"); 976 976 977 list($width, $height) = getimagesize($file_path); 978 977 979 // database registration 978 980 $insert = array( … … 982 984 'name' => $params['name'], 983 985 'path' => $file_path, 984 ); 986 'filesize' => floor(filesize($file_path)/1024), 987 'width' => $width, 988 'height' => $height, 989 ); 990 991 $info_columns = array( 992 'name', 993 'author', 994 'comment', 995 'level', 996 'date_creation', 997 ); 998 999 foreach ($info_columns as $key) 1000 { 1001 if (isset($params[$key])) 1002 { 1003 $insert[$key] = $params[$key]; 1004 } 1005 } 985 1006 986 1007 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); … … 993 1014 $image_id = mysql_insert_id(); 994 1015 995 $insert = array( 996 'category_id' => $params['category_id'], 997 'image_id' => $image_id, 998 ); 999 1000 if ('auto' == $params['rank']) 1001 { 1002 $query = ' 1016 // let's add links between the image and the categories 1017 // 1018 // $params['categories'] should look like 123,12;456,auto;789 which means: 1019 // 1020 // 1. associate with category 123 on rank 12 1021 // 2. associate with category 456 on automatic rank 1022 // 3. associate with category 789 on automatic rank 1023 if (isset($params['categories'])) 1024 { 1025 $cat_ids = array(); 1026 $rank_on_category = array(); 1027 $search_current_ranks = false; 1028 1029 $tokens = explode(';', $params['categories']); 1030 foreach ($tokens as $token) 1031 { 1032 list($cat_id, $rank) = explode(',', $token); 1033 1034 array_push($cat_ids, $cat_id); 1035 1036 if (!isset($rank)) 1037 { 1038 $rank = 'auto'; 1039 } 1040 $rank_on_category[$cat_id] = $rank; 1041 1042 if ($rank == 'auto') 1043 { 1044 $search_current_ranks = true; 1045 } 1046 } 1047 1048 $cat_ids = array_unique($cat_ids); 1049 1050 if (count($cat_ids) > 0) 1051 { 1052 if ($search_current_ranks) 1053 { 1054 $query = ' 1003 1055 SELECT 1056 category_id, 1004 1057 MAX(rank) AS max_rank 1005 1058 FROM '.IMAGE_CATEGORY_TABLE.' 1006 1059 WHERE rank IS NOT NULL 1007 AND category_id = '.$params['category_id'].' 1060 AND category_id IN ('.implode(',', $cat_ids).') 1061 GROUP BY category_id 1008 1062 ;'; 1009 $row = mysql_fetch_assoc(pwg_query($query)); 1010 $insert['rank'] = isset($row['max_rank']) ? $row['max_rank']+1 : 1; 1011 } 1012 else if (is_numeric($params['rank'])) 1013 { 1014 $insert['rank'] = (int)$params['rank']; 1063 $current_rank_of = simple_hash_from_query( 1064 $query, 1065 'category_id', 1066 'max_rank' 1067 ); 1068 1069 foreach ($cat_ids as $cat_id) 1070 { 1071 if ('auto' == $rank_on_category[$cat_id]) 1072 { 1073 $rank_on_category[$cat_id] = $current_rank_of[$cat_id] + 1; 1074 } 1075 } 1076 } 1077 1078 $inserts = array(); 1079 1080 foreach ($cat_ids as $cat_id) 1081 { 1082 array_push( 1083 $inserts, 1084 array( 1085 'image_id' => $image_id, 1086 'category_id' => $cat_id, 1087 'rank' => $rank_on_category[$cat_id], 1088 ) 1089 ); 1090 } 1091 1092 mass_inserts( 1093 IMAGE_CATEGORY_TABLE, 1094 array_keys($inserts[0]), 1095 $inserts 1096 ); 1097 } 1098 } 1099 1100 // and now, let's create tag associations 1101 if (isset($params['tag_ids'])) 1102 { 1103 set_tags( 1104 explode(',', $params['tag_ids']), 1105 $image_id 1106 ); 1015 1107 } 1016 1108 1017 mass_inserts(1018 IMAGE_CATEGORY_TABLE,1019 array_keys($insert),1020 array($insert)1021 );1022 1023 1109 invalidate_user_cache(); 1024 1110 … … 1250 1336 ); 1251 1337 } 1252 1253 1338 ?> -
trunk/tools/piwigo_remote.pl
r2553 r2569 11 11 GetOptions( 12 12 \%opt, 13 qw/action=s file=s thumbnail=s categor y_id=i name=s rank=s/13 qw/action=s file=s thumbnail=s categories=s define=s%/ 14 14 ); 15 15 … … 60 60 thumbnail_sum => $thumbnail_sum, 61 61 thumbnail_content => $thumbnail_content, 62 category_id => $opt{category_id}, 63 name => $opt{name}, 64 rank => defined($opt{rank}) ? $opt{rank} : 'auto', 62 categories => $opt{categories}, 65 63 }; 64 65 foreach my $key (keys %{ $opt{define} }) { 66 $form->{$key} = $opt{define}{$key}; 67 } 66 68 67 69 my $response = $ua->post( -
trunk/ws.php
r2563 r2569 177 177 'ws_images_add', 178 178 array( 179 'name', 180 'category_id', 181 'file_content', 182 'file_sum', 183 'thumbnail_content', 184 'thumbnail_sum', 185 'rank', 186 ), 187 'POST method only' 179 'file_content' => array(), 180 'file_sum' => array(), 181 'thumbnail_content' => array(), 182 'thumbnail_sum' => array(), 183 'name' => array('default' => null), 184 'author' => array('default' => null), 185 'date_creation' => array('default' => null), 186 'comment' => array('default' => null), 187 'categories' => array('default' => null), 188 'tag_ids' => array('default' => null), 189 'level' => array( 190 'default' => 0, 191 'maxValue' => $conf['available_permission_levels'] 192 ), 193 ), 194 'POST method only. 195 <br/><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.' 188 196 ); 189 197
Note: See TracChangeset
for help on using the changeset viewer.