Changeset 200970
- Timestamp:
- 02/02/2010 05:45:55 AM (16 years ago)
- Location:
- collapsing-categories/trunk
- Files:
-
- 2 edited
-
collapscat.php (modified) (1 diff)
-
collapscatlist.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
collapsing-categories/trunk/collapscat.php
r200947 r200970 168 168 } 169 169 //print_r($subCatPosts); 170 echo phpArrayToJS($subCatPosts );170 echo phpArrayToJS($subCatPosts, 'subCatPosts'); 171 171 // now we create an array indexed by the id of the ul for posts 172 172 -
collapsing-categories/trunk/collapscatlist.php
r200947 r200970 2 2 /* 3 3 collapsing categories version: 1.1.1 4 copyright 2007-2010 robert felty 4 copyright 2007 robert felty 5 6 this work is largely based on the collapsing categories plugin by andrew rader 7 (http://voidsplat.org), which was also distributed under the gplv2. i have tried 8 contacting him, but his website has been down for quite some time now. see the 9 changelog file for more information. 5 10 6 11 this file is part of collapsing categories … … 24 29 25 30 26 function phpArrayToJS($array ) {31 function phpArrayToJS($array,$name) { 27 32 /* generates javscript code to create an array from a php array */ 28 $script = "var subCatPosts= new Object();\n";33 $script = "var $name = new Object();\n"; 29 34 foreach ($array as $key => $value){ 30 $script .= "subCatPosts['$key'] = '" .35 $script .= $name . "['$key'] = '" . 31 36 addslashes(str_replace("\n", '', $value)) . "';\n"; 32 37 } 33 38 return($script); 34 39 } 35 36 40 37 41 function add_to_includes($cat, $inexclusionarray) { … … 78 82 function miscPosts($cat,$catlink,$subcatpostcount2, $posttext) { 79 83 /* this function will group posts into a miscellaneous sub-category */ 80 global $options, $ cur_categories, $subCatPosts;84 global $options, $subCatPosts, $cur_categories; 81 85 extract($options); 82 86 $showHide='expand'; … … 137 141 * add option to display number of comments 138 142 */ 139 function getSubPosts($posts, $cat2, $showPosts, $theID) {143 function getSubPosts($posts, $cat2, $showPosts, $theID) { 140 144 /* returns all the posts for a given category */ 141 145 global $postsToExclude, $options, $thisPost, $subCatPosts; … … 186 190 } 187 191 } 188 if ($theID!='' && !$subCatPosts[$theID]) {189 $subCatPosts[$theID] = $posttext2;190 }191 192 return array($subCatPostCount2, $posttext2); 192 193 } … … 210 211 $subCatCount,$subCatPostCount,$expanded, $depth) { 211 212 /* returns all the subcategories for a given category */ 212 global $options,$expandSym, $collapseSym, $expandSymJS, $collapseSymJS, 213 $autoExpand, $postsToExclude, $subCatPostCounts, $catlink, $postsInCat, 214 $cur_categories; 213 global $options, $subCatPosts, $autoExpand, $postsToExclude, 214 $subCatPostCounts, $catlink, $postsInCat, $cur_categories; 215 215 $subCatLinks=''; 216 216 $postself=''; … … 243 243 } 244 244 if (!in_array($cat2->term_id, $parents)) { 245 if ($theID!='' && !$subCatPosts[$theID]) { 246 $subCatPosts[$theID] = $posttext2; 247 } 245 248 // check to see if there are more subcategories under this one 246 249 $subCatCount=0; … … 343 346 if (($subCatCount>0) || ($showPosts)) { 344 347 $subCatLinks.="\n<ul id='$theID' style=\"display:$expanded\">\n"; 345 if ($expanded!='block')346 $posttext2='';347 348 if ($subCatCount>0 && $posttext2!='' && $addMisc) { 348 $ subCatLinks.=miscPosts($cat2,$catlink,$subCatPostCount2,349 $posttext2=miscPosts($cat2,$catlink,$subCatPostCount2, 349 350 $posttext2); 350 } else {351 } 351 352 $subCatLinks.=$posttext2; 352 }353 353 } 354 354 // add in additional subcategory information 355 355 $subCatLinks.="$subCatLink2"; 356 if ($theID!='' && !$subCatPosts[$theID]) { 357 $subCatPosts[$theID] = $posttext2 . $subCatLink2; 358 } 356 359 // close <ul> and <li> before starting a new category 357 360 if (($subCatCount>0) || ($showPosts)) { … … 550 553 /* returns a list of categories, and optionally subcategories and posts, 551 554 which can be collapsed or expanded with javascript */ 552 global $ wpdb,$options,$wp_query, $autoExpand, $postsToExclude, $subCatPosts,555 global $subCatPosts, $wpdb,$options,$wp_query, $autoExpand, $postsToExclude, 553 556 $cur_categories, $thisPost, $wp_rewrite, $catlink, $postsInCat; 554 557 extract($options); … … 570 573 571 574 foreach( $categories as $cat ) { 572 $theID='collapsCat-' . $cat->term_id . "-$number";573 575 if ($inExclude=='include' && !empty($includeCatArray)) { 574 576 if (!in_array($cat->term_id, $includeCatArray) && … … 593 595 get_sub_cat($cat, $categories, $parents, $posts, 594 596 $subCatCount,$subCatPostCount,$expanded,0); 595 //list($subCatPostCount2, $posttext2) = 596 //getSubPosts($postsInCat[$cat->term_id],$cat, $showPosts, $theID); 597 // Get post info 598 $posttext=''; 599 if( ! empty($postsInCat[$cat->term_id]) ) { 600 list ($subCatPostCount, $posttext) = getSubPosts($posts, $cat, 601 $showPosts, $theID); 602 } 597 list($subCatPostCount2, $posttext2) = 598 getSubPosts($postsInCat[$cat->term_id],$cat, $showPosts, $theID); 603 599 604 //$theCount=$subCatPostCount2+$subCatPostCount; 605 $theCount= $subCatPostCount; 606 600 $theCount=$subCatPostCount2+$subCatPostCount; 607 601 if ($theCount>0) { 608 602 $expanded='none'; 603 $theID='collapsCat-' . $cat->term_id . "-$number"; 609 604 if (in_array($cat->name, $autoExpand) || 610 605 in_array($cat->slug, $autoExpand) || … … 624 619 "<span class='collapsing categories $showHide' ". 625 620 "onclick='expandCollapse(event, \"$expandSymJS\"," . 626 "\"$collapseSymJS\", $animate, \"collapsing categories\"); " .627 " return false'><span class='sym'>$symbol</span>";621 "\"$collapseSymJS\", $animate, \"collapsing categories\"); return false'>". 622 "<span class='sym'>$symbol</span>"; 628 623 } else { 629 624 $span = " <li class='collapsing categories item'>"; … … 655 650 } 656 651 } 652 // Now print out the post info 653 $posttext=''; 654 if( ! empty($postsInCat[$cat->term_id]) ) { 655 list ($subCatPostCount, $posttext) = getSubPosts($posts, $cat, 656 $subCatPosts, $showPosts); 657 } 657 658 if( $showPostCount=='yes') { 658 659 $link .= ' (' . $theCount.')'; … … 672 673 if ($showPosts) { 673 674 if ($subCatPostCount>0 && $subCatLinks!='' && $addMisc) { 674 $posttext = (miscPosts($cat,$catlink,$subCatPostCount,$posttext)); 675 } 676 } 675 $posttext = (miscPosts($cat,$catlink,$subCatPostCount2,$posttext)); 676 } 677 } 678 /* we only actually add the posts if it is expanded. Otherwise we add 679 the posts dynamically to the dom from a javascript array 680 However, we can't have an empty ul, so we create one emtpy li here */ 677 681 if ($postsBeforeCats) { 678 682 $text =$posttext . $subCatLinks; … … 680 684 $text = $subCatLinks . $posttext; 681 685 } 682 if ($theID!='' ) {686 if ($theID!='' && !$subCatPosts[$theID]) { 683 687 $subCatPosts[$theID] = $text; 684 688 } 685 /* we only actually add the posts if it is expanded. Otherwise we add686 the posts dynamically to the dom from a javascript array687 However, we can't have an empty ul, so we create one emtpy li here */688 689 if ($expanded!='block') { 689 690 $posttext='<li></li>';
Note: See TracChangeset
for help on using the changeset viewer.