Changeset 467 for trunk/admin/include/functions.php
- Timestamp:
- Aug 5, 2004, 7:35:43 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r423 r467 64 64 65 65 /** 66 * returns an array with all picture files according to $conf[' picture_ext']66 * returns an array with all picture files according to $conf['file_ext'] 67 67 * 68 68 * @param string $dir 69 69 * @return array 70 70 */ 71 function get_p icture_files( $dir)71 function get_pwg_files($dir) 72 72 { 73 73 global $conf; 74 74 75 75 $pictures = array(); 76 if ( $opendir = opendir( $dir ))77 { 78 while ( $file = readdir( $opendir ))79 { 80 if ( in_array( get_extension( $file ), $conf['picture_ext'] ))76 if ($opendir = opendir($dir)) 77 { 78 while ($file = readdir($opendir)) 79 { 80 if (in_array(get_extension($file), $conf['file_ext'])) 81 81 { 82 array_push( $pictures, $file);82 array_push($pictures, $file); 83 83 } 84 84 } … … 94 94 * @return array 95 95 */ 96 function get_thumb_files( $dir)96 function get_thumb_files($dir) 97 97 { 98 98 global $conf; 99 99 100 $prefix_length = strlen( $conf['prefix_thumbnail']);100 $prefix_length = strlen($conf['prefix_thumbnail']); 101 101 102 102 $thumbnails = array(); 103 if ( $opendir = @opendir( $dir ))104 { 105 while ( $file = readdir( $opendir ))106 { 107 if ( in_array( get_extension( $file ), $conf['picture_ext'])108 and substr($file,0,$prefix_length) == $conf['prefix_thumbnail'])103 if ($opendir = @opendir($dir.'/thumbnail')) 104 { 105 while ($file = readdir($opendir)) 106 { 107 if (in_array(get_extension($file), $conf['picture_ext']) 108 and substr($file, 0, $prefix_length) == $conf['prefix_thumbnail']) 109 109 { 110 array_push( $thumbnails, $file);110 array_push($thumbnails, $file); 111 111 } 112 112 } 113 113 } 114 114 return $thumbnails; 115 } 116 117 /** 118 * returns an array with representative picture files of a directory 119 * according to $conf['picture_ext'] 120 * 121 * @param string $dir 122 * @return array 123 */ 124 function get_representative_files($dir) 125 { 126 global $conf; 127 128 $pictures = array(); 129 if ($opendir = @opendir($dir.'/representative')) 130 { 131 while ($file = readdir($opendir)) 132 { 133 if (in_array(get_extension($file), $conf['picture_ext'])) 134 { 135 array_push($pictures, $file); 136 } 137 } 138 } 139 return $pictures; 115 140 } 116 141 … … 131 156 132 157 133 // The function delete_site deletes a site 134 // and call the function delete_categoryfor each primary category of the site158 // The function delete_site deletes a site and call the function 159 // delete_categories for each primary category of the site 135 160 function delete_site( $id ) 136 161 { 137 162 // destruction of the categories of the site 138 $query = 'SELECT id'; 139 $query.= ' FROM '.CATEGORIES_TABLE; 140 $query.= ' WHERE site_id = '.$id; 141 $query.= ';'; 142 $result = mysql_query( $query ); 143 while ( $row = mysql_fetch_array( $result ) ) 144 { 145 delete_category( $row['id'] ); 146 } 163 $query = ' 164 SELECT id 165 FROM '.CATEGORIES_TABLE.' 166 WHERE site_id = '.$id.' 167 ;'; 168 $result = mysql_query($query); 169 $category_ids = array(); 170 while ($row = mysql_fetch_array($result)) 171 { 172 array_push($category_ids, $row['id']); 173 } 174 delete_categories($category_ids); 147 175 148 176 // destruction of the site 149 $query = 'DELETE FROM '.PREFIX_TABLE.'sites'; 150 $query.= ' WHERE id = '.$id; 151 $query.= ';'; 152 mysql_query( $query ); 177 $query = ' 178 DELETE FROM '.SITES_TABLE.' 179 WHERE id = '.$id.' 180 ;'; 181 mysql_query($query); 153 182 } 154 183 155 184 156 // The function delete_categor y deletes the category identified by the $id157 // It also deletes (in the database) :158 // - all the images of the images (thanks to delete_image, see further)159 // - all the links between images and this category185 // The function delete_categories deletes the categories identified by the 186 // (numeric) key of the array $ids. It also deletes (in the database) : 187 // - all the elements of the category (delete_elements, see further) 188 // - all the links between elements and this category 160 189 // - all the restrictions linked to the category 161 190 // The function works recursively. 162 function delete_category( $id ) 163 { 164 // destruction of all the related images 165 $query = 'SELECT id'; 166 $query.= ' FROM '.PREFIX_TABLE.'images'; 167 $query.= ' WHERE storage_category_id = '.$id; 168 $query.= ';'; 169 $result = mysql_query( $query ); 170 while ( $row = mysql_fetch_array( $result ) ) 171 { 172 delete_image( $row['id'] ); 173 } 191 function delete_categories($ids) 192 { 193 // destruction of all the related elements 194 $query = ' 195 SELECT id 196 FROM '.IMAGES_TABLE.' 197 WHERE storage_category_id IN ('.implode(',', $ids).') 198 ;'; 199 $result = mysql_query($query); 200 $element_ids = array(); 201 while ($row = mysql_fetch_array($result)) 202 { 203 array_push($element_ids, $row['id']); 204 } 205 delete_elements($element_ids); 174 206 175 207 // destruction of the links between images and this category 176 $query = 'DELETE FROM '.PREFIX_TABLE.'image_category'; 177 $query.= ' WHERE category_id = '.$id; 178 $query.= ';'; 179 mysql_query( $query ); 208 $query = ' 209 DELETE FROM '.IMAGE_CATEGORY_TABLE.' 210 WHERE category_id IN ('.implode(',', $ids).') 211 ;'; 212 mysql_query($query); 180 213 181 214 // destruction of the access linked to the category 182 $query = 'DELETE FROM '.PREFIX_TABLE.'user_access'; 183 $query.= ' WHERE cat_id = '.$id; 184 $query.= ';'; 185 mysql_query( $query ); 186 $query = 'DELETE FROM '.PREFIX_TABLE.'group_access'; 187 $query.= ' WHERE cat_id = '.$id; 188 $query.= ';'; 189 mysql_query( $query ); 215 $query = ' 216 DELETE FROM '.USER_ACCESS_TABLE.' 217 WHERE cat_id IN ('.implode(',', $ids).') 218 ;'; 219 mysql_query($query); 220 $query = ' 221 DELETE FROM '.GROUP_ACCESS_TABLE.' 222 WHERE cat_id IN ('.implode(',', $ids).') 223 ;'; 224 mysql_query($query); 190 225 191 226 // destruction of the sub-categories 192 $query = 'SELECT id'; 193 $query.= ' FROM '.CATEGORIES_TABLE; 194 $query.= ' WHERE id_uppercat = '.$id; 195 $query.= ';'; 196 $result = mysql_query( $query ); 197 while( $row = mysql_fetch_array( $result ) ) 198 { 199 delete_category( $row['id'] ); 200 } 227 $query = ' 228 SELECT id 229 FROM '.CATEGORIES_TABLE.' 230 WHERE id_uppercat IN ('.implode(',', $ids).') 231 ;'; 232 $result = mysql_query($query); 233 $subcat_ids = array(); 234 while($row = mysql_fetch_array($result)) 235 { 236 array_push($subcat_ids, $row['id']); 237 } 238 delete_categories($subcat_ids); 201 239 202 240 // destruction of the category 203 $query = 'DELETE FROM '.CATEGORIES_TABLE; 204 $query.= ' WHERE id = '.$id; 205 $query.= ';'; 206 mysql_query( $query ); 241 $query = ' 242 DELETE FROM '.CATEGORIES_TABLE.' 243 WHERE id IN ('.implode(',', $ids).') 244 ;'; 245 mysql_query($query); 207 246 } 208 247 209 248 210 // The function delete_image deletes the image identified by the $id 211 // It also deletes (in the database) : 212 // - all the comments related to the image 213 // - all the links between categories and this image 214 // - all the favorites associated to the image 215 function delete_image( $id ) 216 { 217 global $count_deleted; 218 249 // The function delete_elements deletes the elements identified by the 250 // (numeric) values of the array $ids. It also deletes (in the database) : 251 // - all the comments related to elements 252 // - all the links between categories and elements 253 // - all the favorites associated to elements 254 function delete_elements($ids) 255 { 219 256 // destruction of the comments on the image 220 $query = 'DELETE FROM '.PREFIX_TABLE.'comments'; 221 $query.= ' WHERE image_id = '.$id; 222 $query.= ';'; 223 mysql_query( $query ); 257 $query = ' 258 DELETE FROM '.COMMENTS_TABLE.' 259 WHERE image_id IN ('.implode(',', $ids).') 260 ;'; 261 echo '<pre>'.$query.'</pre>'; 262 mysql_query($query); 224 263 225 264 // destruction of the links between images and this category 226 $query = 'DELETE FROM '.PREFIX_TABLE.'image_category'; 227 $query.= ' WHERE image_id = '.$id; 228 $query.= ';'; 229 mysql_query( $query ); 265 $query = ' 266 DELETE FROM '.IMAGE_CATEGORY_TABLE.' 267 WHERE image_id IN ('.implode(',', $ids).') 268 ;'; 269 mysql_query($query); 230 270 231 271 // destruction of the favorites associated with the picture 232 $query = 'DELETE FROM '.PREFIX_TABLE.'favorites'; 233 $query.= ' WHERE image_id = '.$id; 234 $query.= ';'; 235 mysql_query( $query ); 272 $query = ' 273 DELETE FROM '.FAVORITES_TABLE.' 274 WHERE image_id IN ('.implode(',', $ids).') 275 ;'; 276 mysql_query($query); 236 277 237 278 // destruction of the image 238 $query = ' DELETE FROM '.PREFIX_TABLE.'images';239 $query.= ' WHERE id = '.$id; 240 $query.= ';';241 mysql_query( $query );242 $count_deleted++;279 $query = ' 280 DELETE FROM '.IMAGES_TABLE.' 281 WHERE id IN ('.implode(',', $ids).') 282 ;'; 283 mysql_query($query); 243 284 } 244 285
Note: See TracChangeset
for help on using the changeset viewer.