f41b982009-05-07Martin Stjernholm /* This is a roxen module. Copyright © 1997 - 2009, 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  */
0917d32013-03-04Anders Johansson constant cvs_version = "$Id$";
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() {
59ae152000-04-06Mattias Wingstedt  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." );
93f8551998-04-03Peter Bortas }
2b004e1997-01-25Peter Bortas 
6557212018-03-12Pontus Östlund constant module_type = MODULE_TAG | MODULE_DEPRECATED;
bc0fa02001-03-08Per Hedbor constant module_name = "Tags: Kill frame";
1973552000-02-10Martin Nilsson constant module_doc = "This module defines a the tag &lt;killframe&gt; that "
59ae152000-04-06Mattias Wingstedt  "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>, "
399fbc1999-12-08Martin Nilsson  "from the end of the URL."; TAGDOCUMENTATION #ifdef manual
9b03652001-03-07Kenneth Johansson constant tagdoc=(["killframe":#"<desc tag='tag'><p><short>
baf02c2000-04-15Per Hedbor  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
9b03652001-03-07Kenneth Johansson  URL.</p></desc>
baf02c2000-04-15Per Hedbor 
ce8fb02001-09-21Johan Sundström <attr name='killindex'><p>
9b03652001-03-07Kenneth Johansson  Removes trailing index.html from the URL.</p> </attr>",
baf02c2000-04-15Per Hedbor  ]);
399fbc1999-12-08Martin Nilsson #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 }