Changeset 657 for trunk/admin/include
- Timestamp:
- Dec 25, 2004, 8:33:36 PM (19 years ago)
- Location:
- trunk/admin/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r650 r657 200 200 return; 201 201 } 202 203 // add sub-category ids to the given ids : if a category is deleted, all 204 // sub-categories must be so 205 $ids = get_subcat_ids($ids); 202 206 203 207 // destruction of all the related elements … … 205 209 SELECT id 206 210 FROM '.IMAGES_TABLE.' 207 WHERE storage_category_id IN ('.implode(',', $ids).') 211 WHERE storage_category_id IN ( 212 '.wordwrap(implode(', ', $ids), 80, "\n").') 208 213 ;'; 209 214 $result = pwg_query($query); … … 218 223 $query = ' 219 224 DELETE FROM '.IMAGE_CATEGORY_TABLE.' 220 WHERE category_id IN ('.implode(',', $ids).') 225 WHERE category_id IN ( 226 '.wordwrap(implode(', ', $ids), 80, "\n").') 221 227 ;'; 222 228 pwg_query($query); … … 225 231 $query = ' 226 232 DELETE FROM '.USER_ACCESS_TABLE.' 227 WHERE cat_id IN ('.implode(',', $ids).') 233 WHERE cat_id IN ( 234 '.wordwrap(implode(', ', $ids), 80, "\n").') 228 235 ;'; 229 236 pwg_query($query); 230 237 $query = ' 231 238 DELETE FROM '.GROUP_ACCESS_TABLE.' 232 WHERE cat_id IN ('.implode(',', $ids).') 233 ;'; 234 pwg_query($query); 235 236 // destruction of the sub-categories 237 $query = ' 238 SELECT id 239 FROM '.CATEGORIES_TABLE.' 240 WHERE id_uppercat IN ('.implode(',', $ids).') 241 ;'; 242 $result = pwg_query($query); 243 $subcat_ids = array(); 244 while($row = mysql_fetch_array($result)) 245 { 246 array_push($subcat_ids, $row['id']); 247 } 248 if (count($subcat_ids) > 0) 249 { 250 delete_categories($subcat_ids); 251 } 239 WHERE cat_id IN ( 240 '.wordwrap(implode(', ', $ids), 80, "\n").') 241 ;'; 242 pwg_query($query); 252 243 253 244 // destruction of the category 254 245 $query = ' 255 246 DELETE FROM '.CATEGORIES_TABLE.' 256 WHERE id IN ('.implode(',', $ids).') 247 WHERE id IN ( 248 '.wordwrap(implode(', ', $ids), 80, "\n").') 257 249 ;'; 258 250 pwg_query($query); … … 762 754 } 763 755 return $sub_dirs; 756 } 757 758 /** 759 * returns an array containing sub-directories which can be a category, 760 * recursive by default 761 * 762 * directories nammed "thumbnail", "pwg_high" or "pwg_representative" are 763 * omitted 764 * 765 * @param string $basedir 766 * @return array 767 */ 768 function get_fs_directories($path, $recursive = true) 769 { 770 $dirs = array(); 771 772 if (is_dir($path)) 773 { 774 if ($contents = opendir($path)) 775 { 776 while (($node = readdir($contents)) !== false) 777 { 778 if (is_dir($path.'/'.$node) 779 and $node != '.' 780 and $node != '..' 781 and $node != 'thumbnail' 782 and $node != 'pwg_high' 783 and $node != 'pwg_representative') 784 { 785 array_push($dirs, $path.'/'.$node); 786 if ($recursive) 787 { 788 $dirs = array_merge($dirs, get_fs_directories($path.'/'.$node)); 789 } 790 } 791 } 792 } 793 } 794 795 return $dirs; 764 796 } 765 797 … … 1009 1041 if ($value == 'true') 1010 1042 { 1011 $uppercats = array(); 1012 $query = ' 1013 SELECT uppercats 1014 FROM '.CATEGORIES_TABLE.' 1015 WHERE id IN ('.implode(',', $categories).') 1016 ;'; 1017 $result = pwg_query($query); 1018 while ($row = mysql_fetch_array($result)) 1019 { 1020 $uppercats = array_merge($uppercats, 1021 explode(',', $row['uppercats'])); 1022 } 1023 $uppercats = array_unique($uppercats); 1024 1043 $uppercats = get_uppercat_ids($categories); 1025 1044 $query = ' 1026 1045 UPDATE '.CATEGORIES_TABLE.' … … 1060 1079 if ($value == 'public') 1061 1080 { 1062 $uppercats = array(); 1063 $query = ' 1064 SELECT uppercats 1065 FROM '.CATEGORIES_TABLE.' 1066 WHERE id IN ('.implode(',', $categories).') 1067 ;'; 1068 $result = pwg_query($query); 1069 while ($row = mysql_fetch_array($result)) 1070 { 1071 $uppercats = array_merge($uppercats, 1072 explode(',', $row['uppercats'])); 1073 } 1074 $uppercats = array_unique($uppercats); 1075 1081 $uppercats = get_uppercat_ids($categories); 1076 1082 $query = ' 1077 1083 UPDATE '.CATEGORIES_TABLE.' … … 1092 1098 pwg_query($query); 1093 1099 } 1100 } 1101 1102 /** 1103 * returns all uppercats category ids of the given category ids 1104 * 1105 * @param array cat_ids 1106 * @return array 1107 */ 1108 function get_uppercat_ids($cat_ids) 1109 { 1110 if (!is_array($cat_ids) or count($cat_ids) < 1) 1111 { 1112 return array(); 1113 } 1114 1115 $uppercats = array(); 1116 1117 $query = ' 1118 SELECT uppercats 1119 FROM '.CATEGORIES_TABLE.' 1120 WHERE id IN ('.implode(',', $cat_ids).') 1121 ;'; 1122 $result = pwg_query($query); 1123 while ($row = mysql_fetch_array($result)) 1124 { 1125 $uppercats = array_merge($uppercats, 1126 explode(',', $row['uppercats'])); 1127 } 1128 $uppercats = array_unique($uppercats); 1129 1130 return $uppercats; 1094 1131 } 1095 1132 … … 1158 1195 mass_updates(CATEGORIES_TABLE, $fields, $datas); 1159 1196 } 1197 1198 /** 1199 * returns the fulldir for each given category id 1200 * 1201 * @param array cat_ids 1202 * @return array 1203 */ 1204 function get_fulldirs($cat_ids) 1205 { 1206 if (count($cat_ids) == 0) 1207 { 1208 return array(); 1209 } 1210 1211 // caching directories of existing categories 1212 $query = ' 1213 SELECT id, dir 1214 FROM '.CATEGORIES_TABLE.' 1215 WHERE dir IS NOT NULL 1216 ;'; 1217 $result = pwg_query($query); 1218 $cat_dirs = array(); 1219 while ($row = mysql_fetch_array($result)) 1220 { 1221 $cat_dirs[$row['id']] = $row['dir']; 1222 } 1223 1224 // filling $uppercats_array : to each category id the uppercats list is 1225 // associated 1226 $uppercats_array = array(); 1227 1228 $query = ' 1229 SELECT id, uppercats 1230 FROM '.CATEGORIES_TABLE.' 1231 WHERE id IN ( 1232 '.wordwrap(implode(', ', $cat_ids), 80, "\n").') 1233 ;'; 1234 $result = pwg_query($query); 1235 while ($row = mysql_fetch_array($result)) 1236 { 1237 $uppercats_array[$row['id']] = $row['uppercats']; 1238 } 1239 1240 $query = ' 1241 SELECT galleries_url 1242 FROM '.SITES_TABLE.' 1243 WHERE id = 1 1244 '; 1245 $row = mysql_fetch_array(pwg_query($query)); 1246 $basedir = $row['galleries_url']; 1247 1248 // filling $cat_fulldirs 1249 $cat_fulldirs = array(); 1250 foreach ($uppercats_array as $cat_id => $uppercats) 1251 { 1252 $uppercats = str_replace(',', '/', $uppercats); 1253 $cat_fulldirs[$cat_id] = $basedir.preg_replace('/(\d+)/e', 1254 "\$cat_dirs['$1']", 1255 $uppercats); 1256 } 1257 1258 return $cat_fulldirs; 1259 } 1260 1261 /** 1262 * returns an array with all file system files according to 1263 * $conf['file_ext'] 1264 * 1265 * @param string $path 1266 * @param bool recursive 1267 * @return array 1268 */ 1269 function get_fs($path, $recursive = true) 1270 { 1271 global $conf; 1272 1273 // because isset is faster than in_array... 1274 if (!isset($conf['flip_picture_ext'])) 1275 { 1276 $conf['flip_picture_ext'] = array_flip($conf['picture_ext']); 1277 } 1278 if (!isset($conf['flip_file_ext'])) 1279 { 1280 $conf['flip_file_ext'] = array_flip($conf['file_ext']); 1281 } 1282 1283 $fs['elements'] = array(); 1284 $fs['thumbnails'] = array(); 1285 $fs['representatives'] = array(); 1286 $subdirs = array(); 1287 1288 if (is_dir($path)) 1289 { 1290 if ($contents = opendir($path)) 1291 { 1292 while (($node = readdir($contents)) !== false) 1293 { 1294 if (is_file($path.'/'.$node)) 1295 { 1296 $extension = get_extension($node); 1297 1298 // if (in_array($extension, $conf['picture_ext'])) 1299 if (isset($conf['flip_picture_ext'][$extension])) 1300 { 1301 if (basename($path) == 'thumbnail') 1302 { 1303 array_push($fs['thumbnails'], $path.'/'.$node); 1304 } 1305 else if (basename($path) == 'pwg_representative') 1306 { 1307 array_push($fs['representatives'], $path.'/'.$node); 1308 } 1309 else 1310 { 1311 array_push($fs['elements'], $path.'/'.$node); 1312 } 1313 } 1314 // else if (in_array($extension, $conf['file_ext'])) 1315 else if (isset($conf['flip_file_ext'][$extension])) 1316 { 1317 array_push($fs['elements'], $path.'/'.$node); 1318 } 1319 } 1320 else if (is_dir($path.'/'.$node) 1321 and $node != '.' 1322 and $node != '..' 1323 and $node != 'pwg_high' 1324 and $recursive) 1325 { 1326 array_push($subdirs, $node); 1327 } 1328 } 1329 } 1330 closedir($contents); 1331 1332 foreach ($subdirs as $subdir) 1333 { 1334 $tmp_fs = get_fs($path.'/'.$subdir); 1335 1336 $fs['elements'] = array_merge($fs['elements'], 1337 $tmp_fs['elements']); 1338 1339 $fs['thumbnails'] = array_merge($fs['thumbnails'], 1340 $tmp_fs['thumbnails']); 1341 1342 $fs['representatives'] = array_merge($fs['representatives'], 1343 $tmp_fs['representatives']); 1344 } 1345 } 1346 return $fs; 1347 } 1160 1348 ?> -
trunk/admin/include/functions_metadata.php
r625 r657 133 133 function get_filelist($category_id = '', $recursive = false, $only_new = false) 134 134 { 135 $files = array(); 136 137 $query = ' 138 SELECT id, dir 139 FROM '.CATEGORIES_TABLE.' 140 WHERE dir IS NOT NULL 141 ;'; 142 $result = pwg_query($query); 143 $cat_dirs = array(); 144 while ($row = mysql_fetch_array($result)) 145 { 146 $cat_dirs[$row['id']] = $row['dir']; 147 } 148 149 // filling $uppercats_array : to each category id the uppercats list is 150 // associated 151 $uppercats_array = array(); 135 // filling $cat_ids : all categories required 136 $cat_ids = array(); 152 137 153 138 $query = ' 154 SELECT id , uppercats139 SELECT id 155 140 FROM '.CATEGORIES_TABLE.' 156 141 WHERE site_id = 1 … … 176 161 while ($row = mysql_fetch_array($result)) 177 162 { 178 $uppercats_array[$row['id']] = $row['uppercats'];163 array_push($cat_ids, $row['id']); 179 164 } 180 165 181 if (count($ uppercats_array) == 0)166 if (count($cat_ids) == 0) 182 167 { 183 168 return array(); 184 169 } 185 170 186 $query = ' 187 SELECT galleries_url 188 FROM '.SITES_TABLE.' 189 WHERE id = 1 190 '; 191 $row = mysql_fetch_array(pwg_query($query)); 192 $basedir = $row['galleries_url']; 193 194 // filling $cat_fulldirs 195 $cat_fulldirs = array(); 196 foreach ($uppercats_array as $cat_id => $uppercats) 197 { 198 $uppercats = str_replace(',', '/', $uppercats); 199 $cat_fulldirs[$cat_id] = $basedir.preg_replace('/(\d+)/e', 200 "\$cat_dirs['$1']", 201 $uppercats); 202 } 171 $files = array(); 203 172 204 173 $query = ' 205 SELECT id, file, storage_category_id174 SELECT id, path 206 175 FROM '.IMAGES_TABLE.' 207 WHERE storage_category_id IN ('.implode(',' 208 ,array_keys($uppercats_array)).')'; 176 WHERE storage_category_id IN ('.implode(',', $cat_ids).')'; 209 177 if ($only_new) 210 178 { … … 218 186 while ($row = mysql_fetch_array($result)) 219 187 { 220 $files[$row['id']] 221 = $cat_fulldirs[$row['storage_category_id']].'/'.$row['file']; 188 $files[$row['id']] = $row['path']; 222 189 } 223 190
Note: See TracChangeset
for help on using the changeset viewer.