be754f | 1999-12-09 | Martin Nilsson | | |
f27cc8 | 1998-11-04 | Peter Bortas | | *
* This module makes it possible to write symbolic names instead of
* absoulte hrefs.
*
* made by Mattias Wingstedt <peter@idonex.se> -96
*/
|
57f45e | 1996-11-27 | Per Hedbor | |
|
be754f | 1999-12-09 | Martin Nilsson | | constant cvs_version = "$Id: indirect_href.pike,v 1.10 1999/12/09 21:40:56 nilsson Exp $";
|
07bf51 | 1997-08-31 | Peter Bortas | | constant thread_safe=1;
|
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,
|
f27cc8 | 1998-11-04 | Peter Bortas | | "Syntax:<br>\n"
|
57f45e | 1996-11-27 | Per Hedbor | | "[name] = [URL]\n" );
|
f27cc8 | 1998-11-04 | Peter Bortas | |
defvar( "tagname", "ai", "Tagname", TYPE_STRING|VAR_EXPERT,
"Name of the tag\n"
|
57f45e | 1996-11-27 | Per Hedbor | | "<tag name=[name]>foo</tag> will be replaced with\n"
|
f27cc8 | 1998-11-04 | Peter Bortas | | "<a href=[URL]>foo</a>"
"if the name is changed, the module has to be reloaded for the "
"namechange to take effect)" );
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
57f45e | 1996-11-27 | Per Hedbor | | array (mixed) register_module()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
07bf51 | 1997-08-31 | Peter Bortas | | return ({ MODULE_PARSER, "Indirect href",
|
f27cc8 | 1998-11-04 | Peter Bortas | | "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/\n"
" idonex=http://www.idonex.se/</pre>", });
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
be754f | 1999-12-09 | Martin Nilsson | |
mapping tagdocumentation() {
return ([tagname:"<desc cont>ai</desc>"]);
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | void start()
{
|
be754f | 1999-12-09 | Martin Nilsson | | array (string) lines;
|
57f45e | 1996-11-27 | Per Hedbor | | string variable, value;
|
b1fca0 | 1996-11-12 | Per Hedbor | | mapping all = ([ ]);
hrefs = ([ ]);
|
be754f | 1999-12-09 | Martin Nilsson | | if (lines = (query( "hrefs" )-" "-"\t") /"\n")
foreach (lines, string line)
|
b1fca0 | 1996-11-12 | Per Hedbor | | if (sscanf( line, "%s=%s", variable, value ) >= 2)
|
be754f | 1999-12-09 | Martin Nilsson | | hrefs[ variable ] = value;
|
b1fca0 | 1996-11-12 | Per Hedbor | | tagname = query( "tagname" );
}
|
be754f | 1999-12-09 | Martin Nilsson | | string tag_newa(string tag, mapping m, string q)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
be754f | 1999-12-09 | Martin Nilsson | | if(!m->name && !m->random) return q;
if(m->name) {
m->href=hrefs[m->name];
m_delete(m, "name");
}
if(m->random) {
m->href=values(hrefs)[random(sizeof(hrefs))];
m_delete(m, "random");
}
return make_container("a",m,q);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
mapping query_container_callers()
{
return ([ tagname : tag_newa ]);
}
|