Changeset 1624 for trunk/include
- Timestamp:
- Dec 2, 2006, 12:31:19 AM (18 years ago)
- Location:
- trunk/include
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/category_cats.inc.php
r1597 r1624 34 34 if ($page['section']=='recent_cats') 35 35 { 36 // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE 36 37 $query = ' 37 SELECT id,name,date_last,representative_picture_id,comment,nb_images,uppercats 38 FROM '.CATEGORIES_TABLE.' 38 SELECT 39 id,name, representative_picture_id, comment, nb_images, uppercats, 40 max_date_last, is_child_date_last, count_images, count_categories 41 FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' 42 ON id = cat_id and user_id = '.$user['id'].' 39 43 WHERE date_last > SUBDATE( 40 44 CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY 41 ) 42 AND id NOT IN ('.$user['forbidden_categories'].')'; 45 );'; 43 46 } 44 47 else 45 48 { 49 // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE 46 50 $query = ' 47 SELECT id,name,date_last,representative_picture_id,comment,nb_images 48 FROM '.CATEGORIES_TABLE.' 51 SELECT 52 id,name, representative_picture_id, comment, nb_images, 53 max_date_last, is_child_date_last, count_images, count_categories 54 FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' 55 ON id = cat_id and user_id = '.$user['id'].' 49 56 WHERE id_uppercat '. 50 57 (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).' 51 AND id NOT IN ('.$user['forbidden_categories'].')52 58 ORDER BY rank 53 59 ;'; … … 60 66 while ($row = mysql_fetch_assoc($result)) 61 67 { 68 $row['is_child_date_last'] = get_boolean($row['is_child_date_last']); 69 62 70 if (isset($row['representative_picture_id']) 63 71 and is_numeric($row['representative_picture_id'])) … … 146 154 { 147 155 $name = $category['name']; 148 $icon_ts = get_icon( @$category['date_last']);156 $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']); 149 157 } 150 158 … … 163 171 ) 164 172 ), 165 'CAPTION_NB_IMAGES' => (($category['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $category['nb_images'])), 173 'CAPTION_NB_IMAGES' => get_display_images_count 174 ( 175 $category['nb_images'], 176 $category['count_images'], 177 $category['count_categories'] 178 ), 166 179 'DESCRIPTION' => @$comment, 167 180 'NAME' => $name, … … 214 227 'thumbnails.line.thumbnail', 215 228 array( 216 'IMAGE_TS' => get_icon( @$category['date_last']),229 'IMAGE_TS' => get_icon($category['max_date_last'], $category['is_child_date_last']), 217 230 ) 218 231 ); -
trunk/include/constants.php
r1584 r1624 66 66 define('RATE_TABLE', $prefixeTable.'rate'); 67 67 define('USER_CACHE_TABLE', $prefixeTable.'user_cache'); 68 define('USER_CACHE_CATEGORIES_TABLE', $prefixeTable.'user_cache_categories'); 68 69 define('CADDIE_TABLE', $prefixeTable.'caddie'); 69 70 define('UPGRADE_TABLE', $prefixeTable.'upgrade'); -
trunk/include/functions_category.inc.php
r1573 r1624 53 53 function get_categories_menu() 54 54 { 55 global $page,$user; 56 57 $infos = array(''); 58 59 $query = ' 60 SELECT name,id,date_last,nb_images,global_rank 61 FROM '.CATEGORIES_TABLE.' 62 WHERE 1 = 1'; // stupid but permit using AND after it ! 55 global $page, $user; 56 57 $query = ' 58 SELECT '; 59 // From CATEGORIES_TABLE 60 $query.= ' 61 name, id, nb_images, global_rank,'; 62 // From USER_CACHE_CATEGORIES_TABLE 63 $query.= ' 64 max_date_last, is_child_date_last, count_images, count_categories'; 65 66 // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE 67 $query.= ' 68 FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' 69 ON id = cat_id and user_id = '.$user['id']; 63 70 if (!$user['expand']) 64 71 { 65 72 $query.= ' 66 AND(id_uppercat is NULL';73 WHERE (id_uppercat is NULL'; 67 74 if (isset($page['category'])) 68 75 { … … 70 77 } 71 78 $query.= ')'; 72 }73 if ($user['forbidden_categories'] != '')74 {75 $query.= '76 AND id NOT IN ('.$user['forbidden_categories'].')';77 79 } 78 80 $query.= ' … … 83 85 while ($row = mysql_fetch_array($result)) 84 86 { 87 $row['is_child_date_last'] = get_boolean($row['is_child_date_last']); 85 88 array_push($cats, $row); 86 89 } … … 89 92 return get_html_menu_category($cats); 90 93 } 94 91 95 92 96 /** … … 353 357 return ($a['rank'] < $b['rank']) ? -1 : 1; 354 358 } 359 360 /** 361 * returns display text for information images of category 362 * 363 * @param array categories 364 * @return string 365 */ 366 function get_display_images_count($cat_nb_images, $cat_count_images, $cat_count_categories, $short_message = true) 367 { 368 $display_text = ''; 369 370 // Count of category is main 371 // if not picture on categorie, test on sub-categories 372 $count = ($cat_nb_images > 0 ? $cat_nb_images : $cat_count_images); 373 374 if ($count > 0) 375 { 376 $display_text.= sprintf(l10n(($count > 1 ? 'images_available' : 'image_available')), $count); 377 378 if ($cat_nb_images > 0) 379 { 380 if (! $short_message) 381 { 382 $display_text.= ' '.l10n('images_available_cpl'); 383 } 384 } 385 else 386 { 387 $display_text.= ' '.sprintf(l10n(($cat_count_categories > 1 ? 'images_available_cats' : 'images_available_cat')), $cat_count_categories); 388 } 389 } 390 391 return $display_text; 392 } 393 355 394 ?> -
trunk/include/functions_html.inc.php
r1606 r1624 25 25 // +-----------------------------------------------------------------------+ 26 26 27 function get_icon($date )27 function get_icon($date, $is_child_date = false) 28 28 { 29 29 global $page, $user, $conf, $lang; … … 34 34 } 35 35 36 if (isset($page['get_icon_cache'][$ date]))37 { 38 return $page['get_icon_cache'][$ date];36 if (isset($page['get_icon_cache'][$is_child_date][$date])) 37 { 38 return $page['get_icon_cache'][$is_child_date][$date]; 39 39 } 40 40 … … 42 42 { 43 43 // date can be empty, no icon to display 44 $page['get_icon_cache'][$ date] = '';45 return $page['get_icon_cache'][$ date];44 $page['get_icon_cache'][$is_child_date][$date] = ''; 45 return $page['get_icon_cache'][$is_child_date][$date]; 46 46 } 47 47 … … 52 52 or $unixtime === -1) // PHP prior to 5.1.0 53 53 { 54 $page['get_icon_cache'][$ date] = '';55 return $page['get_icon_cache'][$ date];54 $page['get_icon_cache'][$is_child_date][$date] = ''; 55 return $page['get_icon_cache'][$is_child_date][$date]; 56 56 } 57 57 … … 62 62 if ( $diff < $user['recent_period'] * $day_in_seconds ) 63 63 { 64 $icon_url = get_themeconf('icon_dir').'/ recent.png';64 $icon_url = get_themeconf('icon_dir').'/'.($is_child_date ? 'recent_by_child.png' : 'recent.png'); 65 65 $title .= $user['recent_period']; 66 66 $title .= ' '.$lang['days']; … … 71 71 } 72 72 73 $page['get_icon_cache'][$ date] = $output;74 75 return $page['get_icon_cache'][$ date];73 $page['get_icon_cache'][$is_child_date][$date] = $output; 74 75 return $page['get_icon_cache'][$is_child_date][$date]; 76 76 } 77 77 … … 393 393 * HTML code generated uses logical list tags ul and each category is an 394 394 * item li. The paramter given is the category informations as an array, 395 * used keys are : id, name, nb_images, date_last 395 * used keys are : id, name, nb_images, max_date_last, is_child_date_last, 396 * count_images, count_categories 396 397 * 397 398 * @param array categories … … 454 455 $menu.= '>'.$category['name'].'</a>'; 455 456 456 if ($category['nb_images'] > 0) 457 { 458 $menu.= "\n".'<span class="menuInfoCat"'; 459 $menu.= ' title="'.$category['nb_images']; 460 $menu.= ' '.$lang['images_available'].'">'; 461 $menu.= '['.$category['nb_images'].']'; 457 // Count of category is main 458 // if not picture on categorie, test on sub-categories 459 if (($category['nb_images'] > 0) or ($category['count_images'] > 0)) 460 { 461 $menu.= "\n".'<span class="'; 462 $menu.= ($category['nb_images'] > 0 ? "menuInfoCat" 463 : "menuInfoCatByChild").'"'; 464 $menu.= ' title="'; 465 $menu.= ' '.get_display_images_count 466 ( 467 $category['nb_images'], 468 $category['count_images'], 469 $category['count_categories'], 470 false 471 ).'">'; 472 $menu.= '['.($category['nb_images'] > 0 ? $category['nb_images'] 473 : $category['count_images']).']'; 462 474 $menu.= '</span>'; 463 $menu.= get_icon($category['date_last']); 464 } 475 } 476 477 $menu.= get_icon($category['max_date_last'], $category['is_child_date_last']); 465 478 } 466 479 -
trunk/include/functions_user.inc.php
r1622 r1624 273 273 calculate_permissions($userdata['id'], $userdata['status']); 274 274 275 update_user_cache_categorie($userdata['id'], $userdata['forbidden_categories']); 276 277 // Set need update are done 278 $userdata['need_update'] = false; 279 275 280 $query = ' 276 281 SELECT COUNT(DISTINCT(image_id)) as total … … 289 294 $query = ' 290 295 INSERT INTO '.USER_CACHE_TABLE.' 291 (user_id, need_update,forbidden_categories,nb_total_images)296 (user_id, need_update, forbidden_categories, nb_total_images) 292 297 VALUES 293 ('.$userdata['id'].',\' false\',\''298 ('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\',\'' 294 299 .$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].') 295 300 ;'; 296 301 pwg_query($query); 302 } 303 304 { 297 305 } 298 306 } … … 438 446 439 447 return implode(',', $forbidden_array); 448 } 449 450 /** 451 * update data of user_cache_categorie 452 * 453 * @param int user_id 454 * @return null 455 */ 456 function update_user_cache_categorie($user_id, $user_forbidden_categories) 457 { 458 function compute_branch_cat_data(&$cats, &$list_cat_id, &$level, &$ref_level) 459 { 460 $date = ''; 461 $count_images = 0; 462 $count_categories = 0; 463 do 464 { 465 $cat_id = array_pop($list_cat_id); 466 if (!is_null($cat_id)) 467 { 468 // Count images and categories 469 $cats[$cat_id]['count_images'] += $count_images; 470 $cats[$cat_id]['count_categories'] += $count_categories; 471 $count_images = $cats[$cat_id]['count_images']; 472 $count_categories = $cats[$cat_id]['count_categories'] + 1; 473 474 if ((empty($cats[$cat_id]['max_date_last'])) or ($cats[$cat_id]['max_date_last'] < $date)) 475 { 476 $cats[$cat_id]['max_date_last'] = $date; 477 $cats[$cat_id]['is_child_date_last'] = true; 478 } 479 else 480 { 481 $date = $cats[$cat_id]['max_date_last']; 482 } 483 $ref_level = substr_count($cats[$cat_id]['global_rank'], '.') + 1; 484 } 485 else 486 { 487 $ref_level = 0; 488 } 489 } while ($level <= $ref_level); 490 491 // Last cat updating must be added to list for next branch 492 if ($ref_level <> 0) 493 { 494 array_push($list_cat_id, $cat_id); 495 } 496 } 497 498 // delete user cache 499 $query = ' 500 delete from '.USER_CACHE_CATEGORIES_TABLE.' 501 where user_id = '.$user_id.' 502 ;'; 503 pwg_query($query); 504 505 $query = ' 506 select 507 id cat_id, date_last, 508 nb_images, global_rank 509 from '.CATEGORIES_TABLE; 510 if ($user_forbidden_categories != '') 511 { 512 $query.= ' 513 where id not in ('.$user_forbidden_categories.')'; 514 } 515 $query.= ';'; 516 517 $result = pwg_query($query); 518 519 $cats = array(); 520 while ($row = mysql_fetch_array($result)) 521 { 522 $cats += array($row['cat_id'] => $row); 523 } 524 usort($cats, 'global_rank_compare'); 525 526 $ref_level = 0; 527 $level = 0; 528 $list_cat_id = array(); 529 530 foreach ($cats as $id => $category) 531 { 532 // Update field 533 $cats[$id]['user_id'] = $user_id; 534 $cats[$id]['is_child_date_last'] = false; 535 $cats[$id]['max_date_last'] = $cats[$id]['date_last']; 536 $cats[$id]['count_images'] = $cats[$id]['nb_images']; 537 $cats[$id]['count_categories'] = 0; 538 539 // Compute 540 $level = substr_count($category['global_rank'], '.') + 1; 541 if ($level > $ref_level) 542 { 543 array_push($list_cat_id, $id); 544 } 545 else 546 { 547 compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level); 548 array_push($list_cat_id, $id); 549 } 550 $ref_level = $level; 551 } 552 553 $level = 1; 554 compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level); 555 556 foreach ($cats as $id => $category) 557 { 558 // Convert field 559 $cats[$id]['is_child_date_last'] = boolean_to_string($cats[$id]['is_child_date_last']); 560 } 561 562 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 563 mass_inserts 564 ( 565 USER_CACHE_CATEGORIES_TABLE, 566 array 567 ( 568 'user_id', 'cat_id', 569 'is_child_date_last', 'max_date_last', 570 'count_images', 'count_categories' 571 ), 572 $cats 573 ); 440 574 } 441 575
Note: See TracChangeset
for help on using the changeset viewer.