Menu

recursive include (UnfoldSiteMap)

Anonymous
2003-03-15
2012-10-11
  • Anonymous

    Anonymous - 2003-03-15

    Hi there!

    Love phpwiki. Using UnfoldSubpages but hate having to declare each subpage manually. Love BackLinks, and SiteMap... why not combine em?

    In order to use it for our 'dynamic as we wanna be' documentation effort, we need to be able to explode the indented 'SiteMap' recursive backlinks and display the content in one long appended page...

    Anyone with any hints, or any interest in working with me to achieve this? Thanks.

     
    • Anonymous

      Anonymous - 2003-03-27

      Hi there!

      I worked with DevNull Cat, and we came up with a recursive Include version of the SiteMap plugin. The full text is below.

      INSTRUCTIONS and NOTES

      Using the 'IncludeSiteMap' plugin for phpwiki (which I tweaked together with the author of the 'SiteMap' plugin) you can have each page of the auto-generated outline appear below, on one big page.

      Known issues:
      - it has a problem with 'subpages' (WikiName/WikiOtherName). Nested IncludePages work fine.
      - 'MetaData' is not displayed recursively... instead, the 'actual' page's MetaData is displayed any time an Include-d page calls the EditMetaData plugin.

      Upcoming features:
      - nesting the includes INSIDE the outline (may be too ambitious).
      - fixing 'subpages' issues.

      Here's the text to add to your WikiPages:

      Code:
      <?plugin IncludeSiteMap ?>

      You can use

      Code:
      direction=forward/back

      to determine the direction and

      Code:
      page=WikiPageName

      to determine the 'parent' of the outline (if left blank, the parent is the current page.

      Currently the recursion limit is set to 8.

      The contents of the IncludeSiteMap plugin (to be stored in wiki/lib/plugin)
      ---------

      <?php // -*-php-*-
      rcs_id('$Id: SiteMap.php,v 1.5 2002/11/04 19:17:16 carstenklapp Exp $');
      /**
      http://sourceforge.net/tracker/?func=detail&aid=537380&group_id=6121&atid=306121

      Submitted By: Cuthbert Cat (cuthbertcat)

      This is a quick mod of BackLinks to do the job recursively. If your
      site is categorized correctly, and all the categories are listed in
      CategoryCategory, then a RecBackLinks there will produce a contents
      page for the entire site.

      The list is as deep as the recursion level.

      direction: Get BackLinks or forward links (links listed on the page)

      firstreversed: If true, get BackLinks for the first page and forward
      links for the rest. Only applicable when direction = 'forward'.

      excludeunknown: If true (default) then exclude any mentioned pages
      which don't exist yet.  Only applicable when direction = 'forward'.
      */

      require_once('lib/PageList.php');

      class WikiPlugin_IncludeSiteMap
      extends WikiPlugin
      {
          function getName () {
              return _("IncludeSiteMap");
          }

          function getDescription () {
              return sprintf(_("IncludeSiteMap: Recursively get BackLinks or links for %s"),
                             '[pagename]');
          }

          function getDefaultArguments() {
              return array('exclude'        => '',
                           'include_self'    => 0,
                           'noheader'         => 0,
                           'page'        => '[pagename]',
                           'description'    => $this->getDescription(),
                           'reclimit'         => 8,
                           'info'        => false,
                           'direction'    => 'back',
                           'firstreversed'    => false,
                           'excludeunknown'    => true
                           );
          }
          // info arg allows multiple columns
          // info=mtime,hits,summary,version,author,locked,minor
          //
          // exclude arg allows multiple pagenames
          // exclude=HomePage,RecentChanges

          function recursivelyGetBackLinks($startpage, $pagearr, $level = '*',
                                       $reclimit = '***') {
              static $VisitedPages = array();
              $startpagename = $startpage->getName();
              //trigger_error("DEBUG: recursivelyGetBackLinks( $startpagename , $level )");
              if ($level == $reclimit)
                  return $pagearr;
              if (in_array($startpagename, $VisitedPages))
                  return $pagearr;
              array_push($VisitedPages, $startpagename);
              $pagelinks = $startpage->getLinks();
              while ($link = $pagelinks->next()) {
                  $linkpagename = $link->getName();
                  if (($linkpagename != $startpagename)
                      && !in_array($linkpagename, $this->ExcludedPages)) {
                  $pagearr[$level . " [$linkpagename]"] = $link;
                  $pagearr = $this->recursivelyGetBackLinks($link, $pagearr, $level . '*', $reclimit);
                  }
              }
              return $pagearr;
          }

          function recursivelyGetLinks($startpage, $pagearr, $level = '*',
                                       $reclimit = '***') {
              static $VisitedPages = array();

              $startpagename = $startpage->getName();
              //trigger_error("DEBUG: recursivelyGetLinks( $startpagename , $level )");
              if ($level == $reclimit)
                  return $pagearr;
              if (in_array($startpagename, $VisitedPages))
                  return $pagearr;
              array_push($VisitedPages, $startpagename);
              $reversed = (($this->firstreversed) && ($startpagename == $this->initialpage));
              //trigger_error("DEBUG: \$reversed = $reversed");
              $pagelinks = $startpage->getLinks($reversed);
              while ($link = $pagelinks->next()) {
                  $linkpagename = $link->getName();
                  if (($linkpagename != $startpagename)
                      && !in_array($linkpagename, $this->ExcludedPages)) {
                      if (!$this->excludeunknown || $this->dbi->isWikiPage($linkpagename)) {
                      $pagearr[$level . " [$linkpagename]"] = $link;
                        $pagearr = $this->recursivelyGetLinks($link, $pagearr, $level . '*', $reclimit);
                      }
                  }
              }
              return $pagearr;
          }

          function run($dbi, $argstr, $request) {
              $args = $this->getArgs($argstr, $request, false);
              extract($args);
              if (!$page)
                  return '';
              $out = '';
              $exclude = $exclude ? explode(",", $exclude) : array();
              if (!$include_self)
                  $exclude[] = $page;
              $this->ExcludedPages = $exclude;
              $this->_default_limit = str_pad('', 3, '*');
              if (is_numeric($reclimit)) {
                  if ($reclimit < 0)
                      $reclimit = 0;
                  if ($reclimit > 10)
                      $reclimit = 10;
                  $limit = str_pad('', $reclimit + 2, '*');
              } else {
                  $limit = '***';
              }
              if (! $noheader)
                  $out .= $description ." ". sprintf(_("(max. recursion level: %d)"),
                                                     $reclimit) . ":\n\n";
              $pagelist = new PageList($info, $exclude);
              $p = $dbi->getPage($page);

              $pagearr = array();
              if ($direction == 'back')
                  $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*", $limit);
              else {
                  $this->dbi = $dbi;
                  $this->initialpage = $page;
                  $this->firstreversed = $firstreversed;
                  $this->excludeunknown = $excludeunknown;
                  $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit);
              }

              reset($pagearr);

                 $nothing = "";
                 $includepages = 'true';
                 $indenter = "";
                 $nothing = "";
                 while (list($key, $link) = each($pagearr)) {
                  if ($includepages = 'true')
                   {
                   $a = substr_count($key, '*');
                   $indenter = str_pad($nothing, $a);
                    $out .= $indenter  . '<?plugin IncludePage page='  . $link->getName() . " ?>" . "\n";
                    }
                  else
                  {
                    $out .= $key . "\n";
              }
              }
              return TransformText($out);
               $nothing = "";
                 $includepages = 'true';
                 $indenter = "";
                 $nothing = "";
               }
      };

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.