Plugin Directory

Changeset 200970


Ignore:
Timestamp:
02/02/2010 05:45:55 AM (16 years ago)
Author:
robfelty
Message:

javascript array storing posts is workign

Location:
collapsing-categories/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • collapsing-categories/trunk/collapscat.php

    r200947 r200970  
    168168      }
    169169      //print_r($subCatPosts);
    170       echo phpArrayToJS($subCatPosts);
     170      echo phpArrayToJS($subCatPosts, 'subCatPosts');
    171171      // now we create an array indexed by the id of the ul for posts
    172172
  • collapsing-categories/trunk/collapscatlist.php

    r200947 r200970  
    22/*
    33collapsing categories version: 1.1.1
    4 copyright 2007-2010 robert felty
     4copyright 2007 robert felty
     5
     6this 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
     8contacting him, but his website has been down for quite some time now. see the
     9changelog file for more information.
    510
    611this file is part of collapsing categories
     
    2429
    2530
    26 function phpArrayToJS($array) {
     31function phpArrayToJS($array,$name) {
    2732  /* 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";
    2934  foreach ($array as $key => $value){
    30     $script .= "subCatPosts['$key'] = '" .
     35    $script .= $name . "['$key'] = '" .
    3136        addslashes(str_replace("\n", '', $value)) . "';\n";
    3237  }
    3338  return($script);
    3439}
    35 
    3640
    3741function add_to_includes($cat, $inexclusionarray) {
     
    7882function miscPosts($cat,$catlink,$subcatpostcount2, $posttext) {
    7983  /* this function will group posts into a miscellaneous sub-category */
    80   global $options, $cur_categories, $subCatPosts;
     84  global $options, $subCatPosts, $cur_categories;
    8185  extract($options);
    8286  $showHide='expand';
     
    137141* add option to display number of comments
    138142*/
    139 function getSubPosts($posts, $cat2,$showPosts, $theID) {
     143function getSubPosts($posts, $cat2, $showPosts, $theID) {
    140144  /* returns all the posts for a given category */
    141145  global $postsToExclude, $options, $thisPost, $subCatPosts;
     
    186190    }
    187191  }
    188   if ($theID!='' && !$subCatPosts[$theID]) {
    189     $subCatPosts[$theID] = $posttext2;
    190   }
    191192  return array($subCatPostCount2, $posttext2);
    192193}
     
    210211  $subCatCount,$subCatPostCount,$expanded, $depth) {
    211212  /* 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;
    215215  $subCatLinks='';
    216216  $postself='';
     
    243243        }
    244244        if (!in_array($cat2->term_id, $parents)) {
     245          if ($theID!='' && !$subCatPosts[$theID]) {
     246            $subCatPosts[$theID] = $posttext2;
     247          }
    245248                    // check to see if there are more subcategories under this one
    246249          $subCatCount=0;
     
    343346        if (($subCatCount>0) || ($showPosts)) {
    344347          $subCatLinks.="\n<ul id='$theID' style=\"display:$expanded\">\n";
    345           if ($expanded!='block')
    346             $posttext2='';
    347348          if ($subCatCount>0 && $posttext2!='' && $addMisc) {
    348             $subCatLinks.=miscPosts($cat2,$catlink,$subCatPostCount2,
     349            $posttext2=miscPosts($cat2,$catlink,$subCatPostCount2,
    349350                $posttext2);
    350           } else {
     351          }
    351352            $subCatLinks.=$posttext2;
    352           }
    353353        }
    354354        // add in additional subcategory information
    355355        $subCatLinks.="$subCatLink2";
     356          if ($theID!='' && !$subCatPosts[$theID]) {
     357            $subCatPosts[$theID] =  $posttext2 . $subCatLink2;
     358          }
    356359        // close <ul> and <li> before starting a new category
    357360        if (($subCatCount>0) || ($showPosts)) {
     
    550553  /* returns a list of categories, and optionally subcategories and posts,
    551554  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,
    553556      $cur_categories, $thisPost, $wp_rewrite, $catlink, $postsInCat;
    554557  extract($options);
     
    570573
    571574  foreach( $categories as $cat ) {
    572     $theID='collapsCat-' . $cat->term_id . "-$number";
    573575    if ($inExclude=='include' && !empty($includeCatArray)) {
    574576      if (!in_array($cat->term_id, $includeCatArray) &&
     
    593595        get_sub_cat($cat, $categories, $parents, $posts,
    594596        $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);
    603599     
    604     //$theCount=$subCatPostCount2+$subCatPostCount;
    605     $theCount= $subCatPostCount;
    606 
     600    $theCount=$subCatPostCount2+$subCatPostCount;
    607601    if ($theCount>0) {
    608602      $expanded='none';
     603      $theID='collapsCat-' . $cat->term_id . "-$number";
    609604      if (in_array($cat->name, $autoExpand) ||
    610605          in_array($cat->slug, $autoExpand) ||
     
    624619            "<span class='collapsing categories $showHide' ".
    625620            "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>";
    628623      } else {
    629624        $span = "      <li class='collapsing categories item'>";
     
    655650        }
    656651      }
     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      }
    657658      if( $showPostCount=='yes') {
    658659        $link .= ' (' . $theCount.')';
     
    672673      if ($showPosts) {
    673674        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 */
    677681      if ($postsBeforeCats) {
    678682        $text =$posttext . $subCatLinks;
     
    680684        $text = $subCatLinks . $posttext;
    681685      }
    682       if ($theID!='') {
     686      if ($theID!='' && !$subCatPosts[$theID]) {
    683687        $subCatPosts[$theID] = $text;
    684688      }
    685       /* we only actually add the posts if it is expanded. Otherwise we add
    686          the posts dynamically to the dom from a javascript array
    687          However, we can't have an empty ul, so we create one emtpy li here */
    688689      if ($expanded!='block') {
    689690        $posttext='<li></li>';
Note: See TracChangeset for help on using the changeset viewer.