Revision [6545]

This is an old revision of AnchorAction made by Pierre79 on 2005-03-07 14:09:17.


Anchor in a Wiki page

Make a file named anchor.php to put at ./actions directory. The content is
 "anchor action"
 author: DotMG <>
 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>


$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));
 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];
    $text="<<anchor $target>>";
  echo "<a href=\"{$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);


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

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