space Baylys
Just practicing to pass the Turing test.
space
space
space
space
Developer for Hire!
space
addedValues Plugin
space

Home

What's new

Bayly.Root

Cornershop Plugin

Career

edutools Root

Enhancements

space

Mainresponder

manila

space
space

callbacks

space
space

finalFilter.rewriteURLs

ManilaSiteCallbacks Suite

Interests

linguist Plugin

Manila

Patches

Patches by Group

Papers

Sales

Sign My Guestbook

User(land) Relations.

Contact Address

Search Baylys

urlchains

space
Join Now
Login
space space space

finalFilter.rewriteURLs

This callback rewrites urls in a page so that they begin with the url that the user entered to get to the site. Thus many entries in config.mainresponder.domains, even siteTrees, can point to the same Manila website and pages are always rendered as if the site had been installed with the user entered url.

This script is perfectly general, but it requires that there is at last one script in config.mainResponder.callbacks.pathEvaluation because that's the only time that an entry called domainPath is placed in the page table by mainresponder.respond if you don't have an entry insert a script at config.mainResponder.callbacks.pathEvaluation.rewriteURLs with the body return true.

One major gotcha is that the Manila referer check prevents posting.

The rewrite process is compatibe with the ManilaFixer turboCache because pages are cached before the rewrite process is invoked.

«config.manila.callbacks.finalFilter.rewriteURLs : 02/04/13, 18:23:10 by David Bayly, Jobsurf Ltd. UK
  «This callback rewrites urls in a page so that they begin with the url that the user
  «entered to get to the site. Thus many entries in config.mainresponder.domains, even siteTrees, can
  «point to the same Manila website and pages are always rendered as if the site had been installed
  «with the user entered url.
  «This script is perfectly general, but it requires that there is at last one script in config.mainResponder.callbacks.pathEvaluation
  «because that's the only time that an entry called domainPath is placed in the page table by mainresponder.respond
  «if you don't have an entry; insert a script at config.mainResponder.callbacks.pathEvaluation.rewriteURLs with the body
  «return true
if not defined(domainPath)
  return false
local (newURL = "", adr)
case typeof(domainPath)
  filespectype
  «msg(string.popfilefromAddress(adrSiteRootTable))
  for adr in @config.manila.sites
  if not (defined(adr^) and defined(adr^^))
  continue
  «window.msg(adr^)
  if adr^ == adrSiteRootTable
  newURL = "http://" + host + "/" + nameOf(adr^) + "/"
  break
  if newURL == ""
  return false
  addressType
  «newURL = "/"
  «bundle «strip site related part of path
  «local (subPath = string.popFilefromAddress(adrObject) - string.popFileFromAddress(adrSiteRootTable))
  «subPath = string.lower(string.replaceAll(subPath, ".", "/"))
  «if subPath == "" «02/04/16, 06:38:34 by DAB
  «return ""
  «local (ix = string.patternMatch(subPath, string.lower(path)))
  «if ix == 0
  «local (lastID = string.lower(string.nthField(subPath, "/", string.countFields(subPath, "/"))))
  «if {"index", "default"} contains lastID
  «subPath = string.mid(subPath, 1, string.length(subPath) - string.length(lastID))
  «if subPath == "/" «02/04/16, 06:38:30 by DAB
  «return ""
  «ix = string.patternMatch(subPath, string.lower(path))
  «if ix == 0
  «return false
  «newURL = string.delete(path, ix +1, infinity) «trailing slash
  «newURL = string.urldecode(path) «02/05/04, 14:53:16 by DAB
  if sys.os() == "MacOS" «02/06/21, 17:58:11 by DAB
  newURL = string.latinToMac(string.urldecode(path)) «02/06/21, 17:58:06 by DAB
  else
  newURL = string.urldecode(path) «02/05/04, 14:53:16 by DAB
  bundle « removing that part of pta^.path that is WITHIN the site from newurl
  local (subPath = string.popFilefromAddress(adrObject) - string.popFileFromAddress(adrSiteRootTable))
  subPath = string.lower(string.replaceAll(subPath, ".", "/"))
  if subPath != "" «02/04/16, 06:38:34 by DAB
  local (ix = string.patternMatch(subPath, string.lower(newurl)))
  if ix == 0
  local (lastID = string.lower(string.nthField(subPath, "/", string.countFields(subPath, "/"))))
  case true
  {"index", "default"} contains lastID
  subPath = string.mid(subPath, 1, string.length(subPath) - string.length(lastID))
  if subPath != "/" «02/04/16, 06:38:30 by DAB
  ix = string.patternMatch(subPath, string.lower(newurl))
  if ix == 0
  return false
  lastID == "[\"#objectnotfoundhandler\"]" «remainingpath contains site portion
  ix = string.patternMatch(string.lower(remainingPath), string.lower(newurl))
  «else
  «return false
  if ix > 0
  newURL = string.popTrailing(string.delete(newurl, ix, infinity), "/") + "/"
  adr = domainPath
  loop «walk UP the site tree table
  case true
  «defined(adr^.["/atts"])
  «local (s = xml.getAttributeValue(adr, "name"))
  «if s != ""
  «newURL = "/" + s + newURL
  adr == adrSiteRootTable «02/04/16, 19:19:23 by DAB
  parentOf(adr^) == @config.mainresponder.domains
  newURL = "http://" + host + "/" + string.popLeading(newURL, "/")
  break
  adr = parentOf(adr^)
  «window.msg(newURL)
else
  return false
renderedText = string.replaceAll(string.replaceAll(renderedtext, "\"" + ftpSite^.url, "\"" + newURL, false), "'" + ftpSite^.url, "'" + newURL, false)
return true

Relative to Frontier version 9.7b10