Changeset 8802 for trunk/include/category_cats.inc.php
- Timestamp:
- Jan 20, 2011, 2:32:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/category_cats.inc.php
r8728 r8802 28 28 */ 29 29 30 if ($page['section']=='recent_cats') 31 { 32 // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE 33 $query = ' 30 // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE 31 $query = ' 34 32 SELECT 35 c.*, nb_images, date_last, max_date_last, count_images, count_categories 36 FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' 37 ON id = cat_id and user_id = '.$user['id'].' 38 WHERE date_last >= '.pwg_db_get_recent_period_expression($user['recent_period']).' 39 '.get_sql_condition_FandF 40 ( 41 array 42 ( 43 'visible_categories' => 'id', 44 ), 45 'AND' 46 ).' 33 c.*, 34 user_representative_picture_id, 35 nb_images, 36 date_last, 37 max_date_last, 38 count_images, 39 count_categories 40 FROM '.CATEGORIES_TABLE.' c 41 INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ucc ON id = cat_id AND user_id = '.$user['id']; 42 43 if ('recent_cats' == $page['section']) 44 { 45 $query.= ' 46 WHERE date_last >= '.pwg_db_get_recent_period_expression($user['recent_period']); 47 } 48 else 49 { 50 $query.= ' 51 WHERE id_uppercat '.(!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']); 52 } 53 54 $query.= get_sql_condition_FandF( 55 array( 56 'visible_categories' => 'id', 57 ), 58 'AND' 59 ); 60 61 if ('recent_cats' != $page['section']) 62 { 63 $query.= ' 64 ORDER BY rank'; 65 } 66 67 $query.= ' 47 68 ;'; 48 }49 else50 {51 // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE52 $query = '53 SELECT54 c.*, nb_images, date_last, max_date_last, count_images, count_categories55 FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'56 ON id = cat_id and user_id = '.$user['id'].'57 WHERE id_uppercat '.58 (!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']).'59 '.get_sql_condition_FandF60 (61 array62 (63 'visible_categories' => 'id',64 ),65 'AND'66 ).'67 ORDER BY rank68 ;';69 }70 69 71 70 $result = pwg_query($query); … … 73 72 $category_ids = array(); 74 73 $image_ids = array(); 74 $user_representative_updates_for = array(); 75 75 76 76 while ($row = pwg_db_fetch_assoc($result)) … … 78 78 $row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last']; 79 79 80 if (isset($row['representative_picture_id']) 81 and is_numeric($row['representative_picture_id'])) 80 if (!empty($row['user_representative_picture_id'])) 81 { 82 $image_id = $row['user_representative_picture_id']; 83 } 84 else if (!empty($row['representative_picture_id'])) 82 85 { // if a representative picture is set, it has priority 83 86 $image_id = $row['representative_picture_id']; 84 87 } 85 88 else if ($conf['allow_random_representative']) 86 {// searching a random representant among elements in sub-categories 87 if ($row['count_images']>0) 88 { 89 $query = ' 90 SELECT image_id 91 FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic 92 ON ic.category_id = c.id'; 93 $query.= ' 94 WHERE (c.id='.$row['id'].' OR uppercats LIKE \''.$row['uppercats'].',%\')' 95 .get_sql_condition_FandF 96 ( 97 array 98 ( 99 'forbidden_categories' => 'c.id', 100 'visible_categories' => 'c.id', 101 'visible_images' => 'image_id' 102 ), 103 "\n AND" 104 ).' 105 ORDER BY '.DB_RANDOM_FUNCTION.'() 106 LIMIT 1 107 ;'; 108 $subresult = pwg_query($query); 109 if (pwg_db_num_rows($subresult) > 0) 110 { 111 list($image_id) = pwg_db_fetch_row($subresult); 112 } 113 } 89 { 90 // searching a random representant among elements in sub-categories 91 $image_id = get_random_image_in_category($row); 114 92 } 115 93 else … … 144 122 if (isset($image_id)) 145 123 { 124 if ($row['user_representative_picture_id'] != $image_id) 125 { 126 $user_representative_updates_for[ $user['id'].'#'.$row['id'] ] = $image_id; 127 } 128 146 129 $row['representative_picture_id'] = $image_id; 147 130 array_push($image_ids, $image_id); … … 194 177 { 195 178 $thumbnail_src_of = array(); 179 $new_image_ids = array(); 196 180 197 181 $query = ' 198 SELECT id, path, tn_ext 182 SELECT id, path, tn_ext, level 199 183 FROM '.IMAGES_TABLE.' 200 184 WHERE id IN ('.implode(',', $image_ids).') … … 203 187 while ($row = pwg_db_fetch_assoc($result)) 204 188 { 205 $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); 206 } 189 if ($row['level'] <= $user['level']) 190 { 191 $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); 192 } 193 else 194 { 195 // problem: we must not display the thumbnail of a photo which has a 196 // higher privacy level than user privacy level 197 // 198 // * what is the represented category? 199 // * find a random photo matching user permissions 200 // * register it at user_representative_picture_id 201 // * set it as the representative_picture_id for the category 202 203 foreach ($categories as &$category) 204 { 205 if ($row['id'] == $category['representative_picture_id']) 206 { 207 if ($category['count_images']>0) 208 { 209 // searching a random representant among elements in sub-categories 210 $image_id = get_random_image_in_category($category); 211 212 if (isset($image_id)) 213 { 214 if (!in_array($image_id, $image_ids)) 215 { 216 array_push($new_image_ids, $image_id); 217 } 218 219 $user_representative_updates_for[ $user['id'].'#'.$category['id'] ] = $image_id; 220 221 $category['representative_picture_id'] = $image_id; 222 } 223 } 224 } 225 } 226 unset($category); 227 } 228 } 229 230 if (count($new_image_ids) > 0) 231 { 232 $query = ' 233 SELECT id, path, tn_ext 234 FROM '.IMAGES_TABLE.' 235 WHERE id IN ('.implode(',', $new_image_ids).') 236 ;'; 237 $result = pwg_query($query); 238 while ($row = pwg_db_fetch_assoc($result)) 239 { 240 $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); 241 } 242 } 243 } 244 245 if (count($user_representative_updates_for)) 246 { 247 $updates = array(); 248 249 foreach ($user_representative_updates_for as $user_cat => $image_id) 250 { 251 list($user_id, $cat_id) = explode('#', $user_cat); 252 253 array_push( 254 $updates, 255 array( 256 'user_id' => $user_id, 257 'cat_id' => $cat_id, 258 'user_representative_picture_id' => $image_id, 259 ) 260 ); 261 } 262 263 mass_updates( 264 USER_CACHE_CATEGORIES_TABLE, 265 array( 266 'primary' => array('user_id', 'cat_id'), 267 'update' => array('user_representative_picture_id') 268 ), 269 $updates 270 ); 207 271 } 208 272
Note: See TracChangeset
for help on using the changeset viewer.