Revision [5751]

This is an old revision of AnchorAction made by GregorLindner on 2005-02-07 15:02:24.

 

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->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->tag}#$target\">$text</a>";
 }
}
?>


The code above did not work on my or a friends system. I had to change the echo part:

 echo "<a href=\"wikka.php?wakka={$this->tag}#$target\">$text</a>";




Following lines shoud be added at end of ./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');

?>

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