0e834c | 2000-02-24 | Martin Nilsson | |
|
57f45e | 1996-11-27 | Per Hedbor | |
|
eaca17 | 2000-04-19 | Martin Nilsson | | #pragma strict_types
|
60bf7c | 2001-08-17 | Martin Nilsson | | constant cvs_version = "$Id: indirect_href.pike,v 1.29 2001/08/17 18:41:59 nilsson Exp $";
|
de905c | 2000-04-16 | Martin Nilsson | | constant thread_safe = 1;
|
b1fca0 | 1996-11-12 | Per Hedbor | | #include <module.h>
inherit "module";
void create()
{
|
de905c | 2000-04-16 | Martin Nilsson | | defvar( "hrefs", "roxen = http://www.roxen.com\n"
"community = http://community.roxen.com", "Indirect hrefs",
TYPE_TEXT_FIELD, "The URL database with the syntax:<br>\n"
|
57f45e | 1996-11-27 | Per Hedbor | | "[name] = [URL]\n" );
|
de905c | 2000-04-16 | Martin Nilsson | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
b3281f | 2000-09-10 | Martin Nilsson | | constant module_type = MODULE_TAG;
|
bc0fa0 | 2001-03-08 | Per Hedbor | | constant module_name = "Tags: Indirect href";
|
de905c | 2000-04-16 | Martin Nilsson | |
|
197355 | 2000-02-10 | Martin Nilsson | | constant module_doc =
|
eaca17 | 2000-04-19 | Martin Nilsson | | #"Indirect href. Adds a new tag <tt><ai name=\"\"></ai></tt> that works like
<tt><a href=\"\"></a></tt> but uses a symbolic name instead of a URL. The
|
69ab4c | 2000-04-06 | Mattias Wingstedt | | symbolic name is translated to a proper URL and the tag rewritten to a
|
eaca17 | 2000-04-19 | Martin Nilsson | | proper <tt><a href=\"\"></a></tt> tag. The translation between symbolic names and
|
69ab4c | 2000-04-06 | Mattias Wingstedt | | 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 | |
|
eaca17 | 2000-04-19 | Martin Nilsson | | mapping(string:string) hrefs;
|
be754f | 1999-12-09 | Martin Nilsson | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | void start()
{
|
de905c | 2000-04-16 | Martin Nilsson | | array(string) lines;
|
57f45e | 1996-11-27 | Per Hedbor | | string variable, value;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
hrefs = ([ ]);
|
eaca17 | 2000-04-19 | Martin Nilsson | | if (lines = ([string]query( "hrefs" )-" "-"\t") /"\n")
|
be754f | 1999-12-09 | Martin Nilsson | | 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 | | }
|
de905c | 2000-04-16 | Martin Nilsson | | class TagAI {
inherit RXML.Tag;
string name;
|
49040d | 2000-09-02 | Martin Nilsson | | mapping(string:object) req_arg_types = (["name":RXML.t_text(RXML.PEnt)]);
|
de905c | 2000-04-16 | Martin Nilsson | |
void create() {
if(variables->tagname)
|
eaca17 | 2000-04-19 | Martin Nilsson | | name = [string]query("tagname");
|
de905c | 2000-04-16 | Martin Nilsson | | else
name = "ai";
|
be754f | 1999-12-09 | Martin Nilsson | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
de905c | 2000-04-16 | Martin Nilsson | | class Frame {
inherit RXML.Frame;
array do_return() {
if(!args->name || !sizeof(hrefs)) {
result = content;
return 0;
}
if(!(hrefs->random) && args->name=="random")
args->href=values(hrefs)[random(sizeof(hrefs))];
else
args->href=hrefs[args->name];
|
60bf7c | 2001-08-17 | Martin Nilsson | | m_delete([mapping(string:string)]args, "name");
|
de905c | 2000-04-16 | Martin Nilsson | |
|
60bf7c | 2001-08-17 | Martin Nilsson | | result = Roxen.make_container("a", [mapping(string:string)]args, [string]content);
|
de905c | 2000-04-16 | Martin Nilsson | | return 0;
}
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
c589a2 | 2000-04-15 | Per Hedbor | | TAGDOCUMENTATION;
#ifdef manual
constant tagdoc=([
|
9b0365 | 2001-03-07 | Kenneth Johansson | | "ai":#"<desc cont='cont'><p><short>
|
c589a2 | 2000-04-15 | Per Hedbor | | Makes it possible to use a database of links.</short> Each link is referred
|
9b0365 | 2001-03-07 | Kenneth Johansson | | to by a symbolic name instead of the URL.</p>
|
c589a2 | 2000-04-15 | Per Hedbor | |
<p>The database is updated through the configuration interface. The
|
945a52 | 2001-03-12 | Kenneth Johansson | | tag is available through the <i>Indirect href</i>
|
c589a2 | 2000-04-15 | Per Hedbor | | module.</p></desc>
|
9b0365 | 2001-03-07 | Kenneth Johansson | | <attr name='name' value='string' required='required'><p>
|
c589a2 | 2000-04-15 | Per Hedbor | | Which link to fetch from the database. There is a special case,
<att>name='random'</att> that will choose a random link from the
|
9b0365 | 2001-03-07 | Kenneth Johansson | | database.</p>
|
ae8b25 | 2000-05-05 | Kenneth Johansson | | <ex><ai name='roxen'>Roxen Platform</ai></ex>
|
c589a2 | 2000-04-15 | Per Hedbor | | </attr>",
]);
#endif
|