2 rcs_id('$Id: Transclude.php,v 1.1 2002-09-17 02:26:20 dairiki Exp $');
4 * Transclude: Include an external web page within the body of a wiki page.
7 * <?plugin Transclude src=http://www.internet-technology.de/fourwins_de.htm ?>
9 * @author Geoffrey T. Dairiki
11 * @see http://www.cs.tut.fi/~jkorpela/html/iframe.html
14 * Will only work if the browser supports <iframe>s (which is a recent,
17 * The auto-vertical resize javascript code only works if the transcluded
18 * page comes from the PhpWiki server. Otherwise (due to "tainting"
19 * security checks in JavaScript) I can't figure out how to deduce the
20 * height of the transcluded page via JavaScript... :-/
23 class WikiPlugin_Transclude
27 return _("Transclude");
30 function getDescription() {
31 return _("Include an external web page within the body of a wiki page.");
34 function getDefaultArguments() {
35 return array( 'src' => false, // the src url to include
36 'height' => 450 // height of the iframe
40 function run($dbi, $argstr, $request) {
43 $args = ($this->getArgs($argstr, $request));
47 return $this->error(fmt("%s parameter missing", "'src'"));
49 // FIXME: Better recursion detection.
50 // FIXME: Currently this doesnt work at all.
51 if ($src == $request->getURLtoSelf() ) {
52 return $this->error(fmt("recursive inclusion of url %s", $src));
55 if (! IsSafeURL($src)) {
56 return $this->error(_("Bad url in src: remove all of <, >, \""));
59 $params = array('src' => $src,
65 'class' => 'transclude',
66 "onload" => "adjust_iframe_height(this);");
69 = _("Cannot transclude document since your browser does not support <iframe>s.)");
71 $noframe_msg[] = fmt("Click %s to view the transcluded page",
72 HTML::a(array('href' => $src), _("here")));
74 $noframe_msg = HTML::div(array('class' => 'transclusion'),
75 HTML::p(array(), $noframe_msg));
77 $iframe = HTML::div(HTML::iframe($params, $noframe_msg));
79 /* This doesn't work very well... maybe because CSS screws up NS4 anyway...
80 $iframe = new HtmlElement('ilayer', array('src' => $src), $iframe);
83 return HTML(HTML::p(array('class' => 'transclusion-title'),
84 fmt("Transcluded from %s", LinkURL($src))),
85 $this->_js(), $iframe);
89 * Produce our javascript.
91 * This is used to resize the iframe to fit the content.
92 * Currently it only works if the transcluded document comes
93 * from the same server as the wiki server.
105 function adjust_iframe_height(frame) {
106 var content = frame.contentDocument;
108 frame.height = content.height + 2 * frame.marginHeight;
111 // Can not get content.height unless transcluded doc
112 // is from the same server...
115 frame.scrolling = "no"; // This does nothing in Galeon
118 return HTML::script(array('language' => 'JavaScript',
119 'type' => 'text/javascript'),
120 new RawXml("<!-- //\n$script\n// -->"));
125 // (c-file-style: "gnu")
130 // c-hanging-comment-ender-p: nil
131 // indent-tabs-mode: nil