1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
/* This is a Roxen module. Copyright © 1996-1999 Idonex AB. 
 * 
 * This module makes it possible to write symbolic names instead of 
 * absoulte hrefs. 
 * 
 * made by Mattias Wingstedt <peter@idonex.se> -96 
 */ 
 
constant cvs_version = "$Id: indirect_href.pike,v 1.10 1999/12/09 21:40:56 nilsson 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,  
          "Syntax:<br>\n" 
          "[name] = [URL]\n" ); 
 
 
  //This pollutes namespace and makes the life hard on the manual writers. 
  //Thus it's turned of for normal users. 
  defvar( "tagname", "ai", "Tagname", TYPE_STRING|VAR_EXPERT,   
          "Name of the tag\n" 
          "&lt;tag name=[name]&gt;foo&lt;/tag&gt; will be replaced with\n" 
          "&lt;a href=[URL]&gt;foo&lt;/a&gt;" 
          "if the name is changed, the module has to be reloaded for the " 
          "namechange to take effect)" ); 
} 
 
array (mixed) register_module() 
{ 
  return ({ MODULE_PARSER, "Indirect href", 
            "Indirect href. Adds a new container <tt>&lt;ai&gt;</tt>" 
            ", with a single argument, " 
            "name=string. It then uses the name to index a database of " 
            "URLs, and inserts a &lt;a href=...&gt; 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>", }); 
} 
 
// Dynamic tagname, hence dynamic documentation. 
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 = query( "tagname" ); 
} 
 
string tag_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_container_callers() 
{ 
  return ([ tagname : tag_newa ]); 
}