Changeset 12 for trunk/admin/include/functions.php
- Timestamp:
- May 17, 2003, 1:01:12 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r2 r12 1 1 <?php 2 2 /*************************************************************************** 3 * functions.php is a part of PhpWebGallery*3 * functions.php * 4 4 * ------------------- * 5 * last update : Tuesday, September 26, 2002*6 * email : pierrick@z0rglub.com*5 * application : PhpWebGallery 1.3 * 6 * author : Pierrick LE GALL <pierrick@z0rglub.com> * 7 7 * * 8 8 *************************************************************************** … … 15 15 * * 16 16 ***************************************************************************/ 17 18 $tab_ext = array ( 'jpg', 'gif', 'JPG','GIF','png','PNG' ); 19 $tab_ext_create_TN = array ( 'jpg', 'JPG','png','PNG' ); 20 21 function get_extension( $filename ) 22 { 23 return substr ( strrchr($filename,"."), 1, strlen ( $filename ) ); 24 } 25 26 function is_image( $filename, $create_thumbnail = false ) 27 { 28 global $tab_ext, $tab_ext_create_TN; 29 $is_image = false; 30 if ( is_file ( $filename ) ) 31 { 32 $size = getimagesize( $filename ); 33 // $size[2] == 1 means GIF 34 // $size[2] == 2 means JPG 35 // $size[2] == 3 means PNG 36 if ( !$create_thumbnail ) 37 { 38 if ( in_array ( get_extension( $filename ), $tab_ext ) && ( $size[2] == 1 || $size[2] == 2 || $size[2] == 3 ) ) 39 { 40 $is_image = true; 41 } 42 } 43 else 44 { 45 if ( in_array ( get_extension( $filename ), $tab_ext_create_TN ) && ( $size[2] == 2 || $size[2] == 3 ) ) 46 { 47 $is_image = true; 48 } 49 } 50 } 51 return $is_image; 52 } 53 54 function TN_exist ( $dir, $file ) 55 { 56 global $tab_ext, $conf; 57 $titre = substr ( $file, 0, strrpos ( $file, ".") ); 58 for ( $i = 0; $i < sizeof ( $tab_ext ); $i++ ) 59 { 60 $test = $dir."/thumbnail/".$conf['prefixe_thumbnail'].$titre.".".$tab_ext[$i]; 61 if ( is_file ( $test ) ) 62 { 63 return $tab_ext[$i]; 64 } 65 } 66 return false; 67 } 68 69 // The function delete_site deletes a site 70 // and call the function delete_category for each primary category of the site 71 function delete_site( $id ) 72 { 73 global $prefixeTable; 74 75 // destruction of the categories of the site 76 $query = "select id from $prefixeTable"."categories where site_id = $id;"; 77 $result = mysql_query( $query ); 78 while ( $row = mysql_fetch_array( $result ) ) 79 { 80 delete_category( $row['id'] ); 81 } 82 83 // destruction of the site 84 $query = "delete from $prefixeTable"."sites where id = $id;"; 85 mysql_query( $query ); 86 } 87 88 // The function delete_category deletes the category identified by the $id 89 // It also deletes (in the database) : 90 // - all the images of the images (thanks to delete_image, see further) 91 // - all the restrictions linked to the category 92 // The function works recursively. 93 function delete_category( $id ) 94 { 95 global $prefixeTable; 96 97 // destruction of all the related images 98 $query = "select id from $prefixeTable"."images where cat_id = '".$id."';"; 99 $result = mysql_query( $query ); 100 while ( $row = mysql_fetch_array( $result ) ) 101 { 102 delete_image( $row['id'] ); 103 } 104 105 // destruction of the restrictions linked to the category 106 $query = "delete from $prefixeTable"."restrictions where cat_id = '".$id."';"; 107 mysql_query( $query ); 108 109 // destruction of the sub-categories 110 $query = "select id from $prefixeTable"."categories where id_uppercat = '$id';"; 111 $result = mysql_query( $query ); 112 while( $row = mysql_fetch_array( $result ) ) 113 { 114 delete_category( $row['id'] ); 115 } 116 117 // destruction of the category 118 $query = "delete from $prefixeTable"."categories where id = '$id';"; 119 mysql_query( $query ); 120 } 121 122 // The function delete_image deletes the image identified by the $id 123 // It also deletes (in the database) : 124 // - all the comments related to the image 125 // - all the favorites associated to the image 126 function delete_image( $id ) 127 { 128 global $prefixeTable,$count_deleted; 129 130 // destruction of the comments on the image 131 $query = "delete from $prefixeTable"."comments where image_id = $id;"; 132 mysql_query( $query ); 133 134 // destruction of the favorites associated with the picture 135 $query = "delete from $prefixeTable"."favorites where image_id = $id;"; 136 mysql_query( $query ); 137 138 // destruction of the image 139 $query = "delete from $prefixeTable"."images where id = $id;"; 140 mysql_query( $query ); 141 $count_deleted++; 142 } 143 144 // The delete_user function delete a user identified by the $user_id 145 // It also deletes : 146 // - all the restrictions linked to this user 147 // - all the favorites linked to this user 148 function delete_user( $user_id ) 149 { 150 global $prefixeTable; 151 152 // destruction of the restrictions linked to the user 153 $query = "delete from $prefixeTable"."restrictions where user_id = $user_id;"; 154 mysql_query( $query ); 155 156 // destruction of the favorites associated with the user 157 $query = "delete from $prefixeTable"."favorites where user_id = $user_id;"; 158 mysql_query( $query ); 159 160 // destruction of the user 161 $query = "delete from $prefixeTable"."users where id = $user_id;"; 162 mysql_query( $query ); 163 } 164 165 // The check_favorites function deletes all the favorites of a user if he is not allowed to see them 166 // (the category or an upper category is restricted or invisible) 167 function check_favorites( $user_id ) 168 { 169 global $prefixeTable; 170 171 $row = mysql_fetch_array( mysql_query( "select status from $prefixeTable"."users where id = $user_id;" ) ); 172 $status = $row['status']; 173 // retrieving all the restricted categories for this user 174 $restricted_cat = get_all_restrictions( $user_id, $status ); 175 // retrieving all the favorites for this user and comparing their categories to the restricted categories 176 $query = "select image_id, cat_id"; 177 $query.= " from $prefixeTable"."favorites, $prefixeTable"."images"; 178 $query.= " where user_id = $user_id"; 179 $query.= " and id = image_id"; 180 $query.= ";"; 181 $result = mysql_query ( $query ); 182 while ( $row = mysql_fetch_array( $result ) ) 183 { 184 if ( in_array( $row['cat_id'], $restricted_cat ) ) 185 { 186 $query = "delete from $prefixeTable"."favorites"; 187 $query.= " where image_id = ".$row['image_id']; 188 $query.= " and user_id = $user_id"; 189 $query.= ";"; 190 mysql_query( $query ); 191 } 192 } 193 } 17 18 $tab_ext_create_TN = array ( 'jpg', 'png' ); 19 20 function is_image( $filename, $create_thumbnail = false ) 21 { 22 global $tab_ext_create_TN, $conf; 23 24 $is_image = false; 25 26 if ( is_file ( $filename ) ) 27 { 28 $size = getimagesize( $filename ); 29 // $size[2] == 1 means GIF 30 // $size[2] == 2 means JPG 31 // $size[2] == 3 means PNG 32 if ( !$create_thumbnail ) 33 { 34 if ( in_array( get_extension( $filename ), $conf['picture_ext'] ) 35 and ( $size[2] == 1 or $size[2] == 2 or $size[2] == 3 ) ) 36 { 37 $is_image = true; 38 } 39 } 40 else 41 { 42 if ( in_array( get_extension( $filename ), $tab_ext_create_TN ) 43 and ( $size[2] == 2 or $size[2] == 3 ) ) 44 { 45 $is_image = true; 46 } 47 } 48 } 49 return $is_image; 50 } 51 52 function TN_exists( $dir, $file ) 53 { 54 global $conf; 55 56 $filename = get_filename_wo_extension( $file ); 57 foreach ( $conf['picture_ext'] as $ext ) { 58 $test = $dir.'/thumbnail/'.$conf['prefixe_thumbnail'].$filename.'.'.$ext; 59 if ( is_file ( $test ) ) 60 { 61 return $ext; 62 } 63 } 64 return false; 65 } 66 67 // The function delete_site deletes a site 68 // and call the function delete_category for each primary category of the site 69 function delete_site( $id ) 70 { 71 // destruction of the categories of the site 72 $query = 'SELECT id'; 73 $query.= ' FROM '.PREFIX_TABLE.'categories'; 74 $query.= ' WHERE site_id = '.$id; 75 $query.= ';'; 76 $result = mysql_query( $query ); 77 while ( $row = mysql_fetch_array( $result ) ) 78 { 79 delete_category( $row['id'] ); 80 } 81 82 // destruction of the site 83 $query = 'DELETE FROM '.PREFIX_TABLE.'sites'; 84 $query.= ' WHERE id = '.$id; 85 $query.= ';'; 86 mysql_query( $query ); 87 } 88 89 // The function delete_category deletes the category identified by the $id 90 // It also deletes (in the database) : 91 // - all the images of the images (thanks to delete_image, see further) 92 // - all the restrictions linked to the category 93 // The function works recursively. 94 function delete_category( $id ) 95 { 96 // destruction of all the related images 97 $query = 'SELECT id'; 98 $query.= ' FROM '.PREFIX_TABLE.'images'; 99 $query.= ' WHERE cat_id = '.$id; 100 $query.= ';'; 101 $result = mysql_query( $query ); 102 while ( $row = mysql_fetch_array( $result ) ) 103 { 104 delete_image( $row['id'] ); 105 } 106 107 // destruction of the restrictions linked to the category 108 $query = 'DELETE FROM '.PREFIX_TABLE.'restrictions'; 109 $query.= ' WHERE cat_id = '.$id; 110 $query.= ';'; 111 mysql_query( $query ); 112 113 // destruction of the sub-categories 114 $query = 'SELECT id'; 115 $query.= ' FROM '.PREFIX_TABLE.'categories'; 116 $query.= ' WHERE id_uppercat = '.$id; 117 $query.= ';'; 118 $result = mysql_query( $query ); 119 while( $row = mysql_fetch_array( $result ) ) 120 { 121 delete_category( $row['id'] ); 122 } 123 124 // destruction of the category 125 $query = 'DELETE FROM '.PREFIX_TABLE.'categories'; 126 $query.= ' WHERE id = '.$id; 127 $query.= ';'; 128 mysql_query( $query ); 129 } 130 131 // The function delete_image deletes the image identified by the $id 132 // It also deletes (in the database) : 133 // - all the comments related to the image 134 // - all the favorites associated to the image 135 function delete_image( $id ) 136 { 137 global $count_deleted; 138 139 // destruction of the comments on the image 140 $query = 'DELETE FROM '.PREFIX_TABLE.'comments'; 141 $query.= ' WHERE image_id = '.$id; 142 $query.= ';'; 143 mysql_query( $query ); 144 145 // destruction of the favorites associated with the picture 146 $query = 'DELETE FROM '.PREFIX_TABLE.'favorites'; 147 $query.= ' WHERE image_id = '.$id; 148 $query.= ';'; 149 mysql_query( $query ); 150 151 // destruction of the image 152 $query = 'DELETE FROM '.PREFIX_TABLE.'images'; 153 $query.= ' WHERE id = '.$id; 154 $query.= ';'; 155 mysql_query( $query ); 156 $count_deleted++; 157 } 158 159 // The delete_user function delete a user identified by the $user_id 160 // It also deletes : 161 // - all the restrictions linked to this user 162 // - all the favorites linked to this user 163 function delete_user( $user_id ) 164 { 165 // destruction of the restrictions linked to the user 166 $query = 'DELETE FROM '.PREFIX_TABLE.'restrictions'; 167 $query.= ' WHERE user_id = '.$user_id; 168 $query.= ';'; 169 mysql_query( $query ); 170 171 // destruction of the favorites associated with the user 172 $query = 'DELETE FROM '.PREFIX_TABLE.'favorites'; 173 $query.= ' WHERE user_id = '.$user_id; 174 $query.= ';'; 175 mysql_query( $query ); 176 177 // destruction of the user 178 $query = 'DELETE FROM '.PREFIX_TABLE.'users'; 179 $query.= ' WHERE id = '.$user_id; 180 $query.= ';'; 181 mysql_query( $query ); 182 } 183 184 // The check_favorites function deletes all the favorites of a user if he is 185 // not allowed to see them (the category or an upper category is restricted 186 // or invisible) 187 function check_favorites( $user_id ) 188 { 189 $query = 'SELECT status'; 190 $query.= ' FROM '.PREFIX_TABLE.'users'; 191 $query.= ' WHERE id = '.$user_id; 192 $query.= ';'; 193 $row = mysql_fetch_array( mysql_query( $query ) ); 194 $status = $row['status']; 195 // retrieving all the restricted categories for this user 196 $restricted_cat = get_all_restrictions( $user_id, $status ); 197 // retrieving all the favorites for this user and comparing their 198 // categories to the restricted categories 199 $query = 'SELECT image_id, cat_id'; 200 $query.= ' FROM '.PREFIX_TABLE.'favorites, '.PREFIX_TABLE.'images'; 201 $query.= ' WHERE user_id = '.$user_id; 202 $query.= ' AND id = image_id'; 203 $query.= ';'; 204 $result = mysql_query ( $query ); 205 while ( $row = mysql_fetch_array( $result ) ) 206 { 207 if ( in_array( $row['cat_id'], $restricted_cat ) ) 208 { 209 $query = 'DELETE FROM '.PREFIX_TABLE.'favorites'; 210 $query.= ' WHERE image_id = '.$row['image_id']; 211 $query.= ' AND user_id = '.$user_id; 212 $query.= ';'; 213 mysql_query( $query ); 214 } 215 } 216 } 194 217 ?>
Note: See TracChangeset
for help on using the changeset viewer.