Changeset 610
- Timestamp:
- Nov 20, 2004, 6:23:42 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r606 r610 487 487 AND id IN ('.implode(',', $cat_ids).') 488 488 ;'; 489 $result = pwg_query( $query);490 while ( $row = mysql_fetch_array( $result ))489 $result = pwg_query($query); 490 while ($row = mysql_fetch_array($result)) 491 491 { 492 492 $query = ' … … 496 496 AND image_id = '.$row['representative_picture_id'].' 497 497 ;'; 498 $result = pwg_query( $query ); 499 if (mysql_num_rows($result) == 0) 500 { 498 $sub_result = pwg_query($query); 499 if (mysql_num_rows($sub_result) == 0) 500 { 501 // set a new representative element for this category 501 502 $query = ' 503 SELECT image_id 504 FROM '.IMAGE_CATEGORY_TABLE.' 505 WHERE category_id = '.$row['id'].' 506 ORDER BY RAND() 507 LIMIT 0,1 508 ;'; 509 $sub_sub_result = pwg_query($query); 510 if (mysql_num_rows($sub_sub_result) > 0) 511 { 512 list($representative) = mysql_fetch_array(pwg_query($query)); 513 $query = ' 514 UPDATE '.CATEGORIES_TABLE.' 515 SET representative_picture_id = '.$representative.' 516 WHERE id = '.$row['id'].' 517 ;'; 518 pwg_query($query); 519 } 520 else 521 { 522 $query = ' 502 523 UPDATE '.CATEGORIES_TABLE.' 503 524 SET representative_picture_id = NULL 504 525 WHERE id = '.$row['id'].' 505 526 ;'; 506 pwg_query( $query ); 527 pwg_query($query); 528 } 507 529 } 508 530 } -
trunk/admin/remote_site.php
r606 r610 431 431 } 432 432 $query.= ' 433 ;'; 434 pwg_query($query); 435 // set a new representative element for this category 436 $query = ' 437 SELECT image_id 438 FROM '.IMAGE_CATEGORY_TABLE.' 439 WHERE category_id = '.$category_id.' 440 ORDER BY RAND() 441 LIMIT 0,1 442 ;'; 443 list($representative) = mysql_fetch_array(pwg_query($query)); 444 $query = ' 445 UPDATE '.CATEGORIES_TABLE.' 446 SET representative_picture_id = '.$representative.' 447 WHERE id = '.$category_id.' 433 448 ;'; 434 449 pwg_query($query); -
trunk/admin/update.php
r606 r610 513 513 (category_id,image_id) VALUES 514 514 '.implode(',', $ids).' 515 ;'; 516 pwg_query($query); 517 518 // set a new representative element for this category 519 $query = ' 520 SELECT image_id 521 FROM '.IMAGE_CATEGORY_TABLE.' 522 WHERE category_id = '.$category_id.' 523 ORDER BY RAND() 524 LIMIT 0,1 525 ;'; 526 list($representative) = mysql_fetch_array(pwg_query($query)); 527 $query = ' 528 UPDATE '.CATEGORIES_TABLE.' 529 SET representative_picture_id = '.$representative.' 530 WHERE id = '.$category_id.' 515 531 ;'; 516 532 pwg_query($query); -
trunk/include/category_recent_cats.inc.php
r606 r610 36 36 // easier to use 37 37 $query = ' 38 SELECT id AS category_id 39 FROM '.CATEGORIES_TABLE.' 38 SELECT c.id AS category_id,uppercats,representative_picture_id,path,file,tn_ext 39 FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGES_TABLE.' AS i 40 ON i.id = c.representative_picture_id 40 41 WHERE date_last > SUBDATE(CURRENT_DATE 41 42 ,INTERVAL '.$user['recent_period'].' DAY)'; … … 63 64 while ( $row = mysql_fetch_array( $result ) ) 64 65 { 65 $cat_infos = get_cat_info( $row['category_id'] ); 66 $name = get_cat_display_name($cat_infos['name'],'<br />','',false); 67 68 $query = ' 69 SELECT path,file,tn_ext 70 FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.' 71 WHERE category_id = '.$row['category_id'].' 72 AND date_available > SUBDATE(CURRENT_DATE 73 ,INTERVAL '.$user['recent_period'].' DAY) 74 AND id = image_id 75 ORDER BY RAND() 76 LIMIT 0,1 77 ;'; 78 $subrow = mysql_fetch_array(pwg_query($query)); 66 $name = get_cat_display_name_cache($row['uppercats'], '<br />', '', false); 79 67 80 $thumbnail_src = get_thumbnail_src($ subrow['path'], @$subrow['tn_ext']);68 $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']); 81 69 82 70 $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id']; … … 86 74 array( 87 75 'IMAGE' => $thumbnail_src, 88 'IMAGE_ALT' => $ subrow['file'],76 'IMAGE_ALT' => $row['file'], 89 77 'IMAGE_TITLE' => $lang['hint_category'], 90 78 'IMAGE_NAME' => '['.$name.']', 91 79 'IMAGE_STYLE' => 'thumb_category', 92 80 93 'U_IMG_LINK' => add_session_id( $url_link)81 'U_IMG_LINK' => add_session_id($url_link) 94 82 ) 95 83 ); -
trunk/include/category_subcats.inc.php
r606 r610 32 32 */ 33 33 34 $subcats = array(); 35 if (isset($page['cat'])) 34 $query = ' 35 SELECT id, name, date_last 36 FROM '.CATEGORIES_TABLE.' 37 WHERE id_uppercat '; 38 if (!isset($page['cat']) or !is_numeric($page['cat'])) 36 39 { 37 $ subcats = get_non_empty_subcat_ids($page['cat']);40 $query.= 'is NULL'; 38 41 } 39 42 else 40 43 { 41 $ subcats = get_non_empty_subcat_ids('');44 $query.= '= '.$page['cat']; 42 45 } 46 // we must not show pictures of a forbidden category 47 if ($user['forbidden_categories'] != '') 48 { 49 $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')'; 50 } 51 $query.= ' 52 ORDER BY rank 53 ;'; 54 $result = pwg_query($query); 43 55 44 56 // template thumbnail initialization 45 if ( count($subcats) > 0)57 if (mysql_num_rows($result) > 0) 46 58 { 47 59 $template->assign_block_vars('thumbnails', array()); … … 52 64 } 53 65 54 foreach ($subcats as $subcat_id => $non_empty_id) 66 while ($row = mysql_fetch_array($result)) 55 67 { 56 $name = $page['plain_structure'][$subcat_id]['name']; 68 $query = ' 69 SELECT path, tn_ext 70 FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGES_TABLE.' AS i 71 ON i.id = c.representative_picture_id 72 WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\' 73 ORDER BY RAND() 74 LIMIT 0,1 75 ;'; 76 $element_result = pwg_query($query); 77 if (mysql_num_rows($element_result) == 0) 78 { 79 continue; 80 } 81 $element_row = mysql_fetch_array($element_result); 57 82 58 // searching the representative picture of the category 59 $query = ' 60 SELECT representative_picture_id 61 FROM '.CATEGORIES_TABLE.' 62 WHERE id = '.$non_empty_id.' 63 ;'; 64 $row = mysql_fetch_array(pwg_query($query)); 65 66 $query = ' 67 SELECT file,path,tn_ext 68 FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.' 69 WHERE category_id = '.$non_empty_id.' 70 AND id = image_id'; 71 // if the category has a representative picture, this is its thumbnail 72 // that will be displayed ! 73 if (isset($row['representative_picture_id'])) 74 { 75 $query.= ' 76 AND id = '.$row['representative_picture_id']; 77 } 78 else 79 { 80 $query.= ' 81 ORDER BY RAND() 82 LIMIT 0,1'; 83 } 84 $query.= ' 85 ;'; 86 $image_result = pwg_query($query); 87 $image_row = mysql_fetch_array($image_result); 88 89 $thumbnail_link = get_thumbnail_src($image_row['path'], 90 @$image_row['tn_ext']); 83 $thumbnail_link = get_thumbnail_src($element_row['path'], 84 @$element_row['tn_ext']); 91 85 92 86 $thumbnail_title = $lang['hint_category']; 93 87 94 $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$subcat_id; 95 96 $date = $page['plain_structure'][$subcat_id]['date_last']; 88 $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['id']; 97 89 98 90 $template->assign_block_vars( … … 100 92 array( 101 93 'IMAGE' => $thumbnail_link, 102 'IMAGE_ALT' => $ image_row['file'],94 'IMAGE_ALT' => $row['name'], 103 95 'IMAGE_TITLE' => $thumbnail_title, 104 'IMAGE_NAME' => '['.$ name.']',105 'IMAGE_TS' => get_icon( $date),96 'IMAGE_NAME' => '['.$row['name'].']', 97 'IMAGE_TS' => get_icon(@$row['date_last']), 106 98 'IMAGE_STYLE' => 'thumb_category', 107 99 -
trunk/include/functions_category.inc.php
r605 r610 829 829 } 830 830 831 // get_non_empty_subcat_ids returns an array with sub-categories id832 // associated with their first non empty category id.833 //834 // example :835 //836 // - catname [cat_id]837 // - cat1 [1] -> given uppercat838 // - cat1.1 [12] (empty)839 // - cat1.1.1 [5] (empty)840 // - cat1.1.2 [6]841 // - cat1.2 [3]842 // - cat1.3 [4]843 //844 // get_non_empty_sub_cat_ids will return :845 // $ids[12] = 6;846 // $ids[3] = 3;847 // $ids[4] = 4;848 function get_non_empty_subcat_ids( $id_uppercat )849 {850 global $user;851 852 $ids = array();853 854 $query = 'SELECT id,nb_images';855 $query.= ' FROM '.CATEGORIES_TABLE;856 $query.= ' WHERE id_uppercat ';857 if ( !is_numeric( $id_uppercat ) ) $query.= 'is NULL';858 else $query.= '= '.$id_uppercat;859 // we must not show pictures of a forbidden category860 if ( $user['forbidden_categories'] != '' )861 {862 $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')';863 }864 $query.= ' ORDER BY rank';865 $query.= ';';866 867 $result = pwg_query( $query );868 while ( $row = mysql_fetch_array( $result ) )869 {870 // only categories with findable picture in any of its subcats is871 // represented.872 if ( ( $row['nb_images'] != 0 and $non_empty_cat = $row['id'] )873 or $non_empty_cat = get_first_non_empty_cat_id( $row['id'] ) )874 {875 $ids[$row['id']] = $non_empty_cat;876 }877 }878 return $ids;879 }880 881 // get_first_non_empty_cat_id returns the id of the first non empty882 // sub-category to the given uppercat. If no picture is found in any883 // subcategory, false is returned.884 function get_first_non_empty_cat_id( $id_uppercat )885 {886 global $user;887 888 $query = 'SELECT id,nb_images';889 $query.= ' FROM '.CATEGORIES_TABLE;890 $query.= ' WHERE id_uppercat = '.$id_uppercat;891 // we must not show pictures of a forbidden category892 if ( $user['forbidden_categories'] != '' )893 {894 $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')';895 }896 $query.= ' ORDER BY RAND()';897 $query.= ';';898 $result = pwg_query( $query );899 while ( $row = mysql_fetch_array( $result ) )900 {901 if ( $row['nb_images'] > 0 )902 {903 return $row['id'];904 }905 }906 $result = pwg_query( $query );907 while ( $row = mysql_fetch_array( $result ) )908 {909 // recursive call910 if ( $subcat = get_first_non_empty_cat_id( $row['id'] ) )911 {912 return $subcat;913 }914 }915 return false;916 }917 918 831 function display_select_categories($categories, 919 832 $indent, -
trunk/include/functions_html.inc.php
r593 r610 198 198 199 199 /** 200 * returns the list of categories as a HTML string, with cache of names 201 * 202 * categories string returned contains categories as given in the input 203 * array $cat_informations. $uppercats is the list of category ids to 204 * display in the right order. If url input parameter is empty, returns only 205 * the categories name without links. 206 * 207 * @param string uppercats 208 * @param string separator 209 * @param string url 210 * @param boolean replace_space 211 * @return string 212 */ 213 function get_cat_display_name_cache($uppercats, 214 $separator, 215 $url = 'category.php?cat=', 216 $replace_space = true) 217 { 218 global $cat_names; 219 220 if (!isset($cat_names)) 221 { 222 $query = ' 223 SELECT id,name 224 FROM '.CATEGORIES_TABLE.' 225 ;'; 226 $result = pwg_query($query); 227 while ($row = mysql_fetch_array($result)) 228 { 229 $cat_names[$row['id']] = $row['name']; 230 } 231 } 232 233 $output = ''; 234 $is_first = true; 235 foreach (explode(',', $uppercats) as $category_id) 236 { 237 $name = $cat_names[$category_id]; 238 239 if ($is_first) 240 { 241 $is_first = false; 242 } 243 else 244 { 245 $output.= $separator; 246 } 247 248 if ($url == '') 249 { 250 $output.= $name; 251 } 252 else 253 { 254 $output.= ' 255 <a class="" 256 href="'.add_session_id(PHPWG_ROOT_PATH.$url.$category_id).'">'.$name.'</a>'; 257 } 258 } 259 if ($replace_space) 260 { 261 return replace_space($output); 262 } 263 else 264 { 265 return $output; 266 } 267 } 268 269 /** 200 270 * returns the HTML code for a category item in the menu (for category.php) 201 271 *
Note: See TracChangeset
for help on using the changeset viewer.