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
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
/* This is a roxen module. Copyright © 1997 - 2009, Roxen IS. 
 * 
 * Adds some java script that will prevent others from putting 
 * your page in a frame. 
 * 
 * Will also remove occuranses of "indexfiles" from the end of the URL. 
 * 
 * made by Peter Bortas <peter@roxen.com> Januari -97 
 * 
 * Thanks for suggestions and bugreports: 
 * Barry Treahy <treahy@allianceelec.com> 
 * Chris Burgess <chris@ibex.co.nz> 
 */ 
 
constant cvs_version = "$Id$"; 
constant thread_safe=1; 
 
#include <module.h> 
inherit "module"; 
 
void create() 
{ 
  defvar( "killindex", 1, "Remove index files from the URL", TYPE_FLAG, 
          "If set, the module will remove occurrences of any index file from " 
          "the end of the URL, leaving only a slash. The index file " 
          "definition is taken from the active directory module." ); 
} 
 
constant module_type = MODULE_TAG; 
constant module_name = "Tags: Kill frame"; 
constant module_doc  = "This module defines a the tag &lt;killframe&gt; that " 
  "adds some JavaScript that will prevent others " 
  "from putting the page in a frame. It can " 
  "also strip any occurrences of index files, like <tt>index.html</tt>, " 
  "from the end of the URL."; 
 
TAGDOCUMENTATION 
#ifdef manual 
constant tagdoc=(["killframe":#"<desc tag='tag'><p><short> 
 This tag adds some JavaScript that will prevent others from putting 
 the page in a frame.</short> It can also strip any occurrences of 
 index files, like <ext>index.html</ext>, from the end of the 
 URL.</p></desc> 
 
<attr name='killindex'><p> 
 Removes trailing index.html from the URL.</p> 
</attr>", 
                ]); 
#endif 
 
string tag_killframe( string tag, mapping m, object id ) 
{ 
  NOCACHE(); 
 
  if( !id->supports->javascript ) return ""; 
 
  string javascript; 
 
  while( id->misc->orig ) 
    id = id->misc->orig; 
 
  // Some versions of IE will choke on :80. (Reload and repeat..) 
  string tmp; 
  string prestate; 
  string my_url = id->conf->query("MyWorldLocation"); 
 
  //Get the prestates in correct order. id->prestates is sorted. 
  if( sscanf(id->raw_url, "/(%s)", tmp) ) 
    prestate = "("+ tmp +")/"; 
 
  if( sscanf(my_url, "%s:80/", tmp ) ) 
    my_url = tmp +"/"+ (prestate?prestate:"") + id->not_query[1..]; 
  else 
    my_url += (prestate?prestate:"") + id->not_query[1..]; 
 
  // Links to index.html are ugly. All pages deserve a uniqe URL, and for 
  // index-pages that URL in /. 
  if( query("killindex") || m->killindex ) 
  { 
    //Get indexfiles from the directory-module if there is one. 
    array indexfiles = ({}); 
    if( id->conf->dir_module ) 
      indexfiles = id->conf->dir_module->query("indexfiles"); 
 
    int l=strlen(my_url)-1; 
 
    foreach( indexfiles, string index ) 
      if( my_url[l-strlen(index)..] == "/" +index ) 
        my_url = my_url[..l-strlen(index)]; 
  } 
 
  // Put back the variables if there were any. 
  if(id->query) 
    my_url += "?"+ id->query; 
 
  //top.location = self.location breaks some versions of IE. 
  //Mozilla 3 on Solaris cows with top.frames.length 
  if( id->client && id->client[0][..8] == "Mozilla/3" ) 
    javascript = ( "   if(top.location != \""+ my_url  +"\")\n" 
                   "     top.location = \""+ my_url  +"\";\n" ); 
  else 
    javascript = ( "   if(top.frames.length>1)\n" 
                   "     top.location = \""+ my_url +"\";\n" ); 
 
  return("<script language=\"javascript\"><!--\n" 
         + javascript 
         + "//--></script>\n"); 
}