Changeset 614 for trunk/include
- Timestamp:
- Nov 23, 2004, 11:31:24 PM (20 years ago)
- Location:
- trunk/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_category.inc.php
r610 r614 117 117 } 118 118 119 function get_ user_plain_structure()119 function get_categories_menu() 120 120 { 121 121 global $page,$user; 122 122 123 $infos = array('name','id','date_last','nb_images','dir','id_uppercat', 124 'rank','site_id','uppercats'); 123 $infos = array(''); 125 124 126 125 $query = ' 127 SELECT '.implode(',', $infos).'126 SELECT name,id,date_last,nb_images,global_rank 128 127 FROM '.CATEGORIES_TABLE.' 129 128 WHERE 1 = 1'; // stupid but permit using AND after it ! … … 144 143 } 145 144 $query.= ' 146 ORDER BY id_uppercat ASC, rank ASC147 145 ;'; 148 146 149 $plain_structure = array();150 147 $result = pwg_query($query); 148 $cats = array(); 151 149 while ($row = mysql_fetch_array($result)) 152 150 { 153 $category = array(); 154 foreach ($infos as $info) 155 { 156 if ($info == 'uc.date_last') 157 { 158 if (empty($row['date_last'])) 159 { 160 $category['date_last'] = 0; 161 } 162 else 163 { 164 list($year,$month,$day) = explode('-', $row['date_last']); 165 $category['date_last'] = mktime(0,0,0,$month,$day,$year); 166 } 167 } 168 else if (isset($row[$info])) 169 { 170 $category[$info] = $row[$info]; 171 } 172 else 173 { 174 $category[$info] = ''; 175 } 176 } 177 $plain_structure[$row['id']] = $category; 178 } 179 180 return $plain_structure; 181 } 182 183 function create_user_structure( $id_uppercat ) 184 { 185 global $page; 186 187 if ( !isset( $page['plain_structure'] ) ) 188 $page['plain_structure'] = get_user_plain_structure(); 189 190 $structure = array(); 191 $ids = get_user_subcat_ids( $id_uppercat ); 192 foreach ( $ids as $id ) { 193 $category = $page['plain_structure'][$id]; 194 $category['subcats'] = create_user_structure( $id ); 195 array_push( $structure, $category ); 196 } 197 return $structure; 198 } 199 200 function get_user_subcat_ids( $id_uppercat ) 201 { 202 global $page; 203 204 $ids = array(); 205 foreach ( $page['plain_structure'] as $id => $category ) { 206 if ( $category['id_uppercat'] == $id_uppercat ) array_push( $ids, $id ); 207 else if ( count( $ids ) > 0 ) return $ids; 208 } 209 return $ids; 210 } 211 212 // update_structure updates or add informations about each node of the 213 // structure : 214 // 215 // 1. should the category be expanded in the menu ? 216 // If the category has to be expanded (ie its id is in the 217 // $page['tab_expand'] or all the categories must be expanded by default), 218 // $category['expanded'] is set to true. 219 // 220 // 2. associated expand string 221 // in the menu, there is a expand string (used in the URL) to tell which 222 // categories must be expanded in the menu if this category is chosen 223 function update_structure( $categories ) 224 { 225 global $page, $user; 226 227 $updated_categories = array(); 228 229 foreach ( $categories as $category ) { 230 // update the "expanded" key 231 if ( $user['expand'] 232 or in_array( $category['id'], $page['tab_expand'] ) ) 233 { 234 $category['expanded'] = true; 235 } 236 else 237 { 238 $category['expanded'] = false; 239 } 240 // recursive call 241 $category['subcats'] = update_structure( $category['subcats'] ); 242 // adding the updated category 243 array_push( $updated_categories, $category ); 244 } 245 246 return $updated_categories; 247 } 248 249 // count_images returns the number of pictures contained in the given 250 // category represented by an array, in this array, we have (among other 251 // things) : 252 // $category['nb_images'] -> number of pictures in this category 253 // $category['subcats'] -> array of sub-categories 254 // count_images goes to the deepest sub-category to find the total number of 255 // pictures contained in the given given category 256 function count_images( $categories ) 257 { 258 return count_user_total_images(); 259 $total = 0; 260 foreach ( $categories as $category ) { 261 $total+= $category['nb_images']; 262 $total+= count_images( $category['subcats'] ); 263 } 264 return $total; 151 array_push($cats, $row); 152 } 153 usort($cats, 'global_rank_compare'); 154 155 return get_html_menu_category($cats); 265 156 } 266 157 … … 830 721 831 722 function display_select_categories($categories, 832 $indent,833 723 $selecteds, 834 724 $blockname, 835 $ CSS_classes)836 { 837 global $template ,$user;725 $fullname = true) 726 { 727 global $template; 838 728 839 729 foreach ($categories as $category) 840 730 { 841 if (!in_array($category['id'], $user['restrictions'])) 842 { 843 $selected = ''; 844 if (in_array($category['id'], $selecteds)) 845 { 846 $selected = ' selected="selected"'; 847 } 848 849 $class = ''; 850 foreach (array_keys($CSS_classes) as $CSS_class) 851 { 852 if (in_array($category['id'], $CSS_classes[$CSS_class])) 853 { 854 $class = $CSS_class; 855 } 856 } 857 858 $template->assign_block_vars( 859 $blockname, 860 array('SELECTED'=>$selected, 861 'VALUE'=>$category['id'], 862 'CLASS'=>$class, 863 'OPTION'=>$indent.'- '.$category['name'] 864 )); 865 866 display_select_categories($category['subcats'], 867 $indent.str_repeat(' ',3), 868 $selecteds, 869 $blockname, 870 $CSS_classes); 871 } 872 } 731 $selected = ''; 732 if (in_array($category['id'], $selecteds)) 733 { 734 $selected = ' selected="selected"'; 735 } 736 737 if ($fullname) 738 { 739 $option = get_cat_display_name_cache($category['uppercats'], 740 ' → ', 741 '', 742 false); 743 } 744 else 745 { 746 $option = str_repeat(' ', 747 (3 * substr_count($category['global_rank'], '.'))); 748 $option.= '- '.$category['name']; 749 } 750 751 $template->assign_block_vars( 752 $blockname, 753 array('SELECTED'=>$selected, 754 'VALUE'=>$category['id'], 755 'OPTION'=>$option 756 )); 757 } 758 } 759 760 function display_select_cat_wrapper($query, $selecteds, $blockname, 761 $fullname = true) 762 { 763 $result = pwg_query($query); 764 $categories = array(); 765 while ($row = mysql_fetch_array($result)) 766 { 767 array_push($categories, $row); 768 } 769 usort($categories, 'global_rank_compare'); 770 display_select_categories($categories, $selecteds, $blockname, $fullname); 873 771 } 874 772 … … 905 803 return $subcats; 906 804 } 805 806 function global_rank_compare($a, $b) 807 { 808 return strnatcasecmp($a['global_rank'], $b['global_rank']); 809 } 907 810 ?> -
trunk/include/functions_html.inc.php
r610 r614 212 212 */ 213 213 function get_cat_display_name_cache($uppercats, 214 $separator, 214 $separator, 215 215 $url = 'category.php?cat=', 216 216 $replace_space = true) … … 272 272 * HTML code generated uses logical list tags ul and each category is an 273 273 * item li. The paramter given is the category informations as an array, 274 * used keys are : id, name, dir, nb_images, date_last, subcats (sub-array)275 * 276 * @param array categor y274 * used keys are : id, name, nb_images, date_last 275 * 276 * @param array categories 277 277 * @return string 278 278 */ 279 function get_html_menu_category($categor y)279 function get_html_menu_category($categories) 280 280 { 281 281 global $page, $lang; 282 282 283 $ref_level = 0; 283 284 $menu = ' 285 <ul class="menu">'; 286 287 foreach ($categories as $category) 288 { 289 $level = substr_count($category['global_rank'], '.'); 290 if ($level > $ref_level) 291 { 292 $menu.= ' 293 <ul class="menu">'; 294 } 295 else if ($level < $ref_level) 296 { 297 $menu.= ' 298 </ul>'; 299 } 300 $ref_level = $level; 301 302 $menu.= ' 284 303 285 304 <li>'; 286 305 287 $url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']); 288 289 $class = ''; 290 if (isset($page['cat']) 291 and is_numeric($page['cat']) 292 and $category['id'] == $page['cat']) 293 { 294 $class = 'menuCategorySelected'; 295 } 296 else 297 { 298 $class = 'menuCategoryNotSelected'; 299 } 300 301 $name = $category['name']; 302 if (empty($name)) 303 { 304 $name = str_replace('_', ' ', $category['dir']); 305 } 306 307 $menu.= ' 306 $url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']); 307 308 $class = ''; 309 if (isset($page['cat']) 310 and is_numeric($page['cat']) 311 and $category['id'] == $page['cat']) 312 { 313 $class = 'menuCategorySelected'; 314 } 315 else 316 { 317 $class = 'menuCategoryNotSelected'; 318 } 319 320 $menu.= ' 308 321 <a href="'.$url.'" 309 322 title="'.$lang['hint_category'].'" 310 323 class="'.$class.'"> 311 '.$ name.'324 '.$category['name'].' 312 325 </a>'; 313 326 314 if ($category['nb_images'] > 0)315 {316 $menu.= '327 if ($category['nb_images'] > 0) 328 { 329 $menu.= ' 317 330 <span class="menuInfoCat" 318 331 title="'.$category['nb_images'].' … … 321 334 </span> 322 335 '.get_icon($category['date_last']); 323 } 324 325 // recursive call 326 if ($category['expanded'] and count($category['subcats']) > 0) 327 { 328 $menu.= ' 329 <ul class="menu">'; 330 foreach ($category['subcats'] as $subcat) 331 { 332 $menu.= get_html_menu_category($subcat); 333 } 334 $menu.= ' 336 } 337 338 $menu.= '</li>'; 339 } 340 341 $menu.= ' 335 342 </ul>'; 336 } 337 338 $menu.= '</li>'; 339 343 340 344 return $menu; 341 345 }
Note: See TracChangeset
for help on using the changeset viewer.