Anchor in a Wiki page


Make a file named anchor.php to put at ./actions directory. The content is
<?php
/**
 "anchor action"
 author: DotMG <m.randimbisoa@dotmg.net>
 Parameters :
 § name : name of anchor to set
 § target : name of an anchor to go to
 § text : Text to be displayed on link to anchor, optional
 § title : optional, a code {{anchor target="Sometarget"}} without the parameter text will
   display between tags <a> and </a> the value of parameter title, if set, when defining
   {{anchor name="Sometarget"}}. (see usage).
 § h3 : Dispaly a <h3></h3> tag after the anchor newly set, all link to that anchor without
   the parameter text will have h3 as caption.
 § special : if this parameter is set, its value should be one of "table_of_contents" or "usage"

 > parameter name goes with title or h3, should not be used with parameter target.
 > parameter target goes with text.

  Special use :
   . {{anchor special="table_of_contents"}} : Display a list of anchors having the parameter h3 set.
   . {{anchor special="usage"}} : Show this help.

 Usage :
  {{anchor name="top" title="Top of page"}} => <a name="top"></a>
  {{anchor target="top"}} => <a href="#top">Top of page</a>
  {{anchor target="top" text="Back to top"}} => <a href="#top">Back to top</a>
  {{anchor name="paragraph1" h3="Introduction"}} => <a name="paragraph1"></a><h3>Introduction</h3>
  {{anchor target="paragraph1"}} => <a href="#paragraph1">Introduction</a>
**/

$_SESSION['anchor_list'];

$name = $vars['name'];
$text = $vars['text'];
$target = $vars['target'];
$special = $vars['special'];

if ($special)
{
 if ($special == 'table_of_contents')
 {
  echo "<<anchor table_of_contents>>";
 }
 if ($special == 'usage')
 {
  $fp = fopen('actions/anchor.php', 'r');
  $data = fread($fp, 1000000);
  $data = preg_replace("#(^.*/\*\*|\*\*/.*$)#ms", '', $data);
  echo nl2br(htmlspecialchars($data));
  fclose($fp);
 }
}
else
{
 if ($name)
 {
  echo "<a name=\"$name\"></a>";
  if ($vars['h3'])
  {
   echo "<h3>$h3</h3>";
   $this->anchor_list[$name] = $h3;
   $this->anchor_list['table_of_contents'] .= "<a href=\"". $this->Href('', $this->tag) ."#$name\">$h3</a><br />\n";
  }
  if ($vars['title'])
  {
   $this->anchor_list[$name] = $title;
  }
 }
 if ($target)
 {
  if (!$text)
  {
   if ($this->anchor_list[$target])
   {
    $text = $this->anchor_list[$target];
   }
   else
   {
    $text="<<anchor $target>>";
   }
  }
  echo "<a href=\"".$this->Href('', $this->tag)."#$target\">$text</a>";
 }
}
?>



Following lines shoud be added at end of ./formatters/wakka.php :
if (isset($this->anchor_list))
{
 $text = preg_replace("/<<anchor (.*?)>>/e", "\$this->anchor_list['\\1'] ? \$this->anchor_list['\\1'] : '\\1';", $text);
}

echo ($text);
wakka2callback('closetags');

?>



Pierre79 -07/3/05
I propose to write ...
in the head of header.php
<a name="top"></a>
<a href="#bottom" title="Click to go to bottom of this page"> v </a>;
in the foot of footer.php.php
<a name="bottom"></a>
<a href="#top" title="Click to go to the top of this page"> ^ </a>';



In Header.php, add (only!) the lines that begin with ----->
<head>
        // Create anchor
----->  <a name="top" id="top"></a>
    <title><?php echo $this->GetWakkaName().": ".$this->PageTitle(); ?></title>
    <base href="<?php echo $site_base ?>" />
    <?php if ($this->GetMethod() != 'show' || $this->page["latest"] == 'N' || $this->page["tag"] == 'SandBox') echo "<meta name=\"robots\" content=\"noindex, nofollow, noarchive\" />\n"; ?>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="keywords" content="<?php echo $this->GetConfigValue("meta_keywords") ?>" />
    <meta name="description" content="<?php echo $this->GetConfigValue("meta_description") ?>" />
    <link rel="stylesheet" type="text/css" href="css/<?php echo $this->GetSkin() ?>" media="screen" />
    <link rel="stylesheet" type="text/css" href="css/print.css" media="print" />
    <link rel="stylesheet" type="text/css" href="css/sidenote.css" />
</head>
<body <?php echo $message ? "onLoad=\"alert('".$message."');\" " : "" ?> >
<div class="header">
    <h2><?php echo $this->config["wakka_name"] ?> : <a href="<?php echo $this->href("", "TextSearch", "phrase=").urlencode($this->GetPageTag()); ?>"><?php echo $this->GetPageTag(); ?></a></h2>

    <?php
        echo $this->Link($this->config["root_page"]);
        // Create link to bottom anchor
----->      echo " :: <a href=\"".$this->Href('', $this->tag)."#bottom\">Go bottom</a>";
    ?>
NickDamoulakis


In Footer.php, add (only!) the lines that begin with ----->
    echo $this->FormOpen("", "TextSearch", "get");
        // Create anchor
----->  echo('<a name="bottom" id="bottom"></a>');
       // Create link to top anchor
----->  echo "<a href=\"".$this->Href('', $this->tag)."#top\">Go top</a> :: ";

    echo $this->HasAccess("write") ? "<a href=\"".$this->href("edit")."\" title=\"Click to edit this page\">Edit page</a> ::\n" : "";
    echo "<a href=\"".$this->href("history")."\" title=\"Click to view recent edits to this page\">Page History</a> ::\n";
    echo $this->GetPageTime() ? "<a href=\"".$this->href("revisions")."\" title=\"Click to view recent revisions list for this page\">".$this->GetPageTime()."</a> <a href=\"".$this->href("revisions.xml")."\" title=\"Click to view recent page revisions in XML format.\"><img src=\"images/xml.png\" width=\"36\" height=\"14\" align=\"middle\" style=\"border : 0px;\" alt=\"XML\" /></a> ::\n" : "";

    // if this page exists
NickDamoulakis


Category
CategoryUserContributions
There are 8 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki