|
|
|
|
|
|
|
constant cvs_version = "$Id: indirect_href.pike,v 1.17 2000/04/14 22:34:07 per 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, |
"The URL database with the syntax:<br>\n" |
"[name] = [URL]\n" ); |
|
|
|
|
|
|
|
|
|
} |
|
constant module_type = MODULE_PARSER; |
constant module_name = "Indirect href"; |
constant module_doc = |
#"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."; |
|
|
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 = "ai"; |
} |
|
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) { |
m->href=values(hrefs)[random(sizeof(hrefs))]; |
m_delete(m, "random"); |
} |
return make_container("a",m,q); |
} |
|
mapping query_simpletag_callers() |
{ |
return ([ tagname : ({ 0, newa }) ]); |
} |
|
TAGDOCUMENTATION; |
#ifdef manual |
constant tagdoc=([ |
"ai":#"<desc><short> |
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. |
|
<ex> |
<ai name='roxen'>Roxen WebServer</ai> |
</ex> |
</attr>", |
]); |
#endif |
|
|