57f45e1996-11-27Per Hedbor // This is a roxen module. (c) Informationsvvarna AB 1996. // This module makes it possible to write symbolic names instead of // absoulte hrefs. // Written by Mattias Wingstedt, <wing@infovav.se>, please refer // to him for further info.
5564241996-11-27Per Hedbor string cvs_version = "$Id: indirect_href.pike,v 1.3 1996/11/27 13:48:17 per Exp $";
b1fca01996-11-12Per Hedbor #include <module.h> inherit "module"; inherit "roxenlib"; mapping hrefs; string tagname; void create() { defvar( "hrefs", "", "Indirect hrefs", TYPE_TEXT_FIELD,
57f45e1996-11-27Per Hedbor  "Syntax:<br>\n" "[name] = [URL]\n" );
b1fca01996-11-12Per Hedbor  defvar( "tagname", "newa", "Tagname", TYPE_STRING, "Name of the tag\n"
57f45e1996-11-27Per Hedbor  "&lt;tag name=[name]&gt;foo&lt;/tag&gt; will be replaced with\n" "&lt;a href=[URL]&gt;foo&lt;/a&gt;" );
b1fca01996-11-12Per Hedbor }
57f45e1996-11-27Per Hedbor array (mixed) register_module()
b1fca01996-11-12Per Hedbor {
57f45e1996-11-27Per Hedbor  return ({ MODULE_PARSER, "Indirect href", "Indirect href", });
b1fca01996-11-12Per Hedbor } void start() {
57f45e1996-11-27Per Hedbor  array (string) lines, foo; string line; string variable, value;
b1fca01996-11-12Per 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 ]); }