57f45e | 1996-11-27 | Per Hedbor | |
|
88e1cb | 1996-12-07 | David Hedbor | | string cvs_version = "$Id: indirect_href.pike,v 1.5 1996/12/07 11:37:54 neotron Exp $";
|
b1fca0 | 1996-11-12 | Per Hedbor | | #include <module.h>
inherit "module";
inherit "roxenlib";
mapping hrefs;
string tagname;
void create()
{
defvar( "hrefs", "", "Indirect hrefs", TYPE_TEXT_FIELD,
|
57f45e | 1996-11-27 | Per Hedbor | | "Syntax:<br>\n"
"[name] = [URL]\n" );
|
b1fca0 | 1996-11-12 | Per Hedbor | | defvar( "tagname", "newa", "Tagname", TYPE_STRING,
"Name of the tag\n"
|
57f45e | 1996-11-27 | Per Hedbor | | "<tag name=[name]>foo</tag> will be replaced with\n"
"<a href=[URL]>foo</a>" );
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
57f45e | 1996-11-27 | Per Hedbor | | array (mixed) register_module()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
88e1cb | 1996-12-07 | David Hedbor | | return ({ MODULE_PARSER, "Indirect href", "Indirect href. Adds a new tag (with a configurable name, if the name is changed, the module has to be reloaded for the namechange to take effect), 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/\n"
" infovav=http://www.infovav.se/</pre>", });
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
void start()
{
|
57f45e | 1996-11-27 | Per Hedbor | | array (string) lines, foo;
string line;
string variable, value;
|
b1fca0 | 1996-11-12 | Per Hedbor | | string dir = "";
mapping all = ([ ]);
hrefs = ([ ]);
if (lines = query( "hrefs" ) /"\n")
foreach (lines, line)
if (sscanf( line, "%s=%s", variable, value ) >= 2)
hrefs[ variable - " " - "\t" ] = value - " " - "\t";
tagname = query( "tagname" );
}
string tag_newa( string tag, mapping m, string q, mapping got )
{
if (m[ "name" ] && hrefs[ m[ "name" ] ])
return "<a href=" + hrefs[ m[ "name" ] ] + ">" + q + "</a>";
else if (m[ "random" ])
return "<a href=" + values( hrefs )[ random( sizeof( hrefs ) ) ] + ">"
+ q + "</a>";
else
return q;
}
mapping query_container_callers()
{
return ([ tagname : tag_newa ]);
}
|