2 rcs_id('$Id: Transclude.php,v 1.2 2002-09-17 02:34:18 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... :-/
22 * Sometimes the auto-vertical resize code doesn't seem to make the iframe
23 * quite big enough --- the scroll bars remain. Not sure why.
26 class WikiPlugin_Transclude
30 return _("Transclude");
33 function getDescription() {
34 return _("Include an external web page within the body of a wiki page.");
37 function getDefaultArguments() {
38 return array( 'src' => false, // the src url to include
39 'height' => 450 // height of the iframe
43 function run($dbi, $argstr, $request) {
46 $args = ($this->getArgs($argstr, $request));
50 return $this->error(fmt("%s parameter missing", "'src'"));
52 // FIXME: Better recursion detection.
53 // FIXME: Currently this doesnt work at all.
54 if ($src == $request->getURLtoSelf() ) {
55 return $this->error(fmt("recursive inclusion of url %s", $src));
58 if (! IsSafeURL($src)) {
59 return $this->error(_("Bad url in src: remove all of <, >, \""));
62 $params = array('src' => $src,
67 'class' => 'transclude',
68 "onload" => "adjust_iframe_height(this);");
71 = _("Cannot transclude document since your browser does not support <iframe>s.)");
73 $noframe_msg[] = fmt("Click %s to view the transcluded page",
74 HTML::a(array('href' => $src), _("here")));
76 $noframe_msg = HTML::div(array('class' => 'transclusion'),
77 HTML::p(array(), $noframe_msg));
79 $iframe = HTML::div(HTML::iframe($params, $noframe_msg));
81 /* This doesn't work very well... maybe because CSS screws up NS4 anyway...
82 $iframe = new HtmlElement('ilayer', array('src' => $src), $iframe);
85 return HTML(HTML::p(array('class' => 'transclusion-title'),
86 fmt("Transcluded from %s", LinkURL($src))),
87 $this->_js(), $iframe);
91 * Produce our javascript.
93 * This is used to resize the iframe to fit the content.
94 * Currently it only works if the transcluded document comes
95 * from the same server as the wiki server.
100 static $seen = false;
107 function adjust_iframe_height(frame) {
108 var content = frame.contentDocument;
110 frame.height = content.height + 2 * frame.marginHeight;
113 // Can not get content.height unless transcluded doc
114 // is from the same server...
119 return HTML::script(array('language' => 'JavaScript',
120 'type' => 'text/javascript'),
121 new RawXml("<!-- //\n$script\n// -->"));
126 // (c-file-style: "gnu")
131 // c-hanging-comment-ender-p: nil
132 // indent-tabs-mode: nil