0e834c | 2000-02-24 | Martin Nilsson | |
|
57f45e | 1996-11-27 | Per Hedbor | |
|
ee8324 | 2000-05-05 | Kenneth Johansson | | constant cvs_version = "$Id: indirect_href.pike,v 1.20 2000/05/05 15:29:31 kuntri 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()
{
|
0e834c | 2000-02-24 | Martin Nilsson | | defvar( "hrefs", "", "Indirect hrefs", TYPE_TEXT_FIELD,
|
59ae15 | 2000-04-06 | Mattias Wingstedt | | "The URL database with the syntax:<br>\n"
|
57f45e | 1996-11-27 | Per Hedbor | | "[name] = [URL]\n" );
|
f27cc8 | 1998-11-04 | Peter Bortas | |
|
59ae15 | 2000-04-06 | Mattias Wingstedt | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
197355 | 2000-02-10 | Martin Nilsson | | constant module_type = MODULE_PARSER;
constant module_name = "Indirect href";
constant module_doc =
|
69ab4c | 2000-04-06 | Mattias Wingstedt | | #"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.";
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
be754f | 1999-12-09 | Martin Nilsson | |
|
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;
|
59ae15 | 2000-04-06 | Mattias Wingstedt | | tagname = "ai";
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
604e29 | 2000-03-17 | Martin Nilsson | | string 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 | | }
|
d024df | 2000-03-17 | Martin Nilsson | | mapping query_simpletag_callers()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
604e29 | 2000-03-17 | Martin Nilsson | | return ([ tagname : ({ 0, newa }) ]);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
387034 | 2000-04-15 | Kenneth Johansson | | TAGDOCUMENTATION;
#ifdef manual
constant tagdoc=([
|
29d034 | 2000-04-15 | Kenneth Johansson | | "ai":#"<desc cont><short>
|
387034 | 2000-04-15 | Kenneth Johansson | | Makes it possible to use a database of links.</short> Each link is referred
to by a symbolic name instead of the URL.
<p>The database is updated through the configuration interface. The
tag is available through the <module>Indirect href</module>
module.</p></desc>
<attr name='name' value='string' required>
Which link to fetch from the database. There is a special case,
<att>name='random'</att> that will choose a random link from the
database.
|
ee8324 | 2000-05-05 | Kenneth Johansson | | <ex><ai name=roxen>Roxen Platform</ai></ex>
|
387034 | 2000-04-15 | Kenneth Johansson | | </attr>",
]);
#endif
|