0e834c2000-02-24Martin Nilsson /* This is a roxen module. Copyright © 1997-1999, Roxen IS.
2b004e1997-01-25Peter Bortas  * * Adds some java script that will prevent others from putting * your page in a frame.
30338e1999-11-29Martin Nilsson  *
bd8fa31998-04-03Peter Bortas  * Will also remove occuranses of "indexfiles" from the end of the URL.
30338e1999-11-29Martin Nilsson  *
0e834c2000-02-24Martin Nilsson  * made by Peter Bortas <peter@roxen.com> Januari -97
aa899c1997-11-14Peter Bortas  *
bd8fa31998-04-03Peter Bortas  * Thanks for suggestions and bugreports: * Barry Treahy <treahy@allianceelec.com> * Chris Burgess <chris@ibex.co.nz>
2b004e1997-01-25Peter Bortas  */
0e834c2000-02-24Martin Nilsson constant cvs_version = "$Id: killframe.pike,v 1.27 2000/02/24 05:20:10 nilsson Exp $";
07bf511997-08-31Peter Bortas constant thread_safe=1;
6677ac1997-08-31Peter Bortas 
2b004e1997-01-25Peter Bortas #include <module.h> inherit "module";
93f8551998-04-03Peter Bortas void create() {
485b561999-11-29Martin Nilsson  defvar( "killindex", 1, "Kill trailing 'indexfiles'?", TYPE_FLAG,
e859de1998-04-03Peter Bortas  "When set, the killframe module will remove occurrences of "
93f8551998-04-03Peter Bortas  "'indexfiles' (as set in the active directory module) from " "the end of the URL, leaving only a slash." ); }
2b004e1997-01-25Peter Bortas 
1973552000-02-10Martin Nilsson constant module_type = MODULE_PARSER; constant module_name = "Killframe tag"; constant module_doc = "This module defines a the tag &lt;killframe&gt; that "
399fbc1999-12-08Martin Nilsson  "adds some java script that will prevent others " "from putting your page in a frame. It can " "also strip any occurrences of 'indexfiles' " "from the end of the URL."; TAGDOCUMENTATION #ifdef manual constant tagdoc=(["killframe":"<desc tag>"+module_desc+"</desc>" "<attr name=killindex>Removes trailing index.html from the URL</attr>"]); #endif
2b004e1997-01-25Peter Bortas string tag_killframe( string tag, mapping m, object id ) {
3f094d1998-08-10Per Hedbor  NOCACHE();
6b56dc1998-06-06Peter Bortas  if( !id->supports->javascript ) return "";
30338e1999-11-29Martin Nilsson 
6b56dc1998-06-06Peter Bortas  string javascript;
30338e1999-11-29Martin Nilsson 
93f8551998-04-03Peter Bortas  while( id->misc->orig ) id = id->misc->orig;
30338e1999-11-29Martin Nilsson 
6b56dc1998-06-06Peter Bortas  // Some versions of IE will choke on :80. (Reload and repeat..) string tmp;
ceccc01998-08-01Peter Bortas  string prestate;
6b56dc1998-06-06Peter Bortas  string my_url = id->conf->query("MyWorldLocation");
ceccc01998-08-01Peter Bortas  //Get the prestates in correct order. id->prestates is sorted. if( sscanf(id->raw_url, "/(%s)", tmp) ) prestate = "("+ tmp +")/";
6b56dc1998-06-06Peter Bortas  if( sscanf(my_url, "%s:80/", tmp ) )
ceccc01998-08-01Peter Bortas  my_url = tmp +"/"+ (prestate?prestate:"") + id->not_query[1..];
6b56dc1998-06-06Peter Bortas  else
ceccc01998-08-01Peter Bortas  my_url += (prestate?prestate:"") + id->not_query[1..];
30338e1999-11-29Martin Nilsson 
6b56dc1998-06-06Peter Bortas  // Links to index.html are ugly. All pages deserve a uniqe URL, and for // index-pages that URL in /.
485b561999-11-29Martin Nilsson  if( query("killindex") || m->killindex )
93f8551998-04-03Peter Bortas  {
6b56dc1998-06-06Peter Bortas  //Get indexfiles from the directory-module if there is one. array indexfiles = ({}); if( id->conf->dir_module ) indexfiles = id->conf->dir_module->query("indexfiles");
93f8551998-04-03Peter Bortas 
6b56dc1998-06-06Peter Bortas  int l=strlen(my_url)-1;
30338e1999-11-29Martin Nilsson 
6b56dc1998-06-06Peter Bortas  foreach( indexfiles, string index ) if( my_url[l-strlen(index)..] == "/" +index ) my_url = my_url[..l-strlen(index)];
93f8551998-04-03Peter Bortas  }
6b56dc1998-06-06Peter Bortas  // Put back the variables if there were any. if(id->query) my_url += "?"+ id->query;
93f8551998-04-03Peter Bortas 
ceccc01998-08-01Peter Bortas  //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" );
a4f2a41999-07-21Martin Nilsson  return("<script language=\"javascript\"><!--\n"
6b56dc1998-06-06Peter Bortas  + javascript + "//--></script>\n");
2b004e1997-01-25Peter Bortas }