Roxen.git
/
server
/
modules
/
tags
/
indirect_href.pike
version
»
Context lines:
10
20
40
80
file
none
3
Roxen.git/server/modules/tags/indirect_href.pike:1:
// This is a roxen module. Copyright © 1996 - 2000, Roxen IS. // // This module makes it possible to write symbolic names instead of // absoulte hrefs. // // made by Mattias Wingstedt
-
constant cvs_version = "$Id: indirect_href.pike,v 1.
14
2000/
03
/
17
00
:
51
:
00
nilsson
Exp $";
+
constant cvs_version = "$Id: indirect_href.pike,v 1.
15
2000/
04
/
06
06
:
16
:
06
wing
Exp $";
constant thread_safe=1; #include <module.h> inherit "module"; inherit "roxenlib"; mapping hrefs; string tagname; void create() { defvar( "hrefs", "", "Indirect hrefs", TYPE_TEXT_FIELD,
-
"
Syntax
:<br>\n"
+
"
The URL database with the syntax
:<br>\n"
"[name] = [URL]\n" ); //This pollutes namespace and makes the life hard on the manual writers. //Thus it's turned of for normal users.
-
defvar( "tagname", "ai", "Tagname", TYPE_STRING|VAR_EXPERT,
-
"Name of the tag\n"
-
"<tag name=[name]>foo</tag> will be replaced with\n"
-
"<a href=[URL]>foo</a>"
-
"if the name is changed, the module has to be reloaded for the "
-
"namechange to take effect)" );
+
//
defvar( "tagname", "ai", "Tagname", TYPE_STRING|VAR_EXPERT,
+
//
"Name of the tag\n"
+
//
"<tag name=[name]>foo</tag> will be replaced with\n"
+
//
"<a href=[URL]>foo</a>"
+
//
"if the name is changed, the module has to be reloaded for the "
+
//
"namechange to take effect)" );
} constant module_type = MODULE_PARSER; constant module_name = "Indirect href"; constant module_doc =
-
"Indirect href. Adds a new
container
<tt><ai></tt>"
-
",
with
a
single
argument,
"
-
"name=string
.
It
then
uses
the
name
to
index
a
database
of
"
-
"URLs,
and
inserts
a <a href=
...
> tag
instead
.
This
can
"
-
"
be
very
useful,
since
you
can
move
all
links
to
a
document
at
"
-
"once.
It
also
allows
the
special
case
'name=random'.
If
this
"
-
"
is
used
,
a
random
link
will
be
selected
from
the
database.
"
-
"
Example:
<
pre
>
"
-
"
roxen=http://www
.
roxen.com/</pre>
";
+
#
"Indirect href. Adds a new
tag
<tt><ai
name=
></tt>
that works like
"
+
<tt><a
href=></tt>
but
uses
a
symbolic
name
instead
of
a URL
.
The
"
+
"symbolic
name
is
translated
to a
proper
URL
and
the
tag
rewritten
to
a
"
+
"proper
<a href=> tag.
The
translation
between symbolic names and
"
+
"URLs
is
stored
in
a
module
variable.
The
advantage
of
this
module
is
that
"
+
"each
URL
will
only
be
stored
in
one
place
and
it
becomes
very
easy
to
"
+
"change
it
,
no
matter
how
many
links
use
it.
As an extra bonus
the
name
"
+
"<
tt
>
random</tt>
will
be
replaces
by
a random URL from the list
.";
// Dynamic tagname, hence dynamic documentation. mapping tagdocumentation() { return ([tagname:"<desc cont>ai</desc>"]); } void start() { array (string) lines; string variable, value; mapping all = ([ ]); hrefs = ([ ]); if (lines = (query( "hrefs" )-" "-"\t") /"\n") foreach (lines, string line) if (sscanf( line, "%s=%s", variable, value ) >= 2) hrefs[ variable ] = value;
-
tagname = query( "tagname" );
+
tagname =
"ai";//
query( "tagname" );
} string newa(string tag, mapping m, string q) { if(!m->name && !m->random) return q; if(m->name) { m->href=hrefs[m->name]; m_delete(m, "name"); } if(m->random) {