2 rcs_id('$Id: Transclude.php,v 1.9 2004-06-14 11:31:39 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Transclude: Include an external web page within the body of a wiki page.
28 * src=http://www.internet-technology.de/fourwins_de.htm
31 * @author Geoffrey T. Dairiki
33 * @see http://www.cs.tut.fi/~jkorpela/html/iframe.html
36 * Will only work if the browser supports <iframe>s (which is a recent,
39 * The auto-vertical resize javascript code only works if the transcluded
40 * page comes from the PhpWiki server. Otherwise (due to "tainting"
41 * security checks in JavaScript) I can't figure out how to deduce the
42 * height of the transcluded page via JavaScript... :-/
44 * Sometimes the auto-vertical resize code doesn't seem to make the iframe
45 * quite big enough --- the scroll bars remain. Not sure why.
47 class WikiPlugin_Transclude
51 return _("Transclude");
54 function getDescription() {
55 return _("Include an external web page within the body of a wiki page.");
58 function getVersion() {
59 return preg_replace("/[Revision: $]/", '',
63 function getDefaultArguments() {
64 return array( 'src' => false, // the src url to include
65 'height' => 450 // height of the iframe
69 function run($dbi, $argstr, &$request, $basepage) {
72 $args = ($this->getArgs($argstr, $request));
76 return $this->error(fmt("%s parameter missing", "'src'"));
78 // FIXME: Better recursion detection.
79 // FIXME: Currently this doesnt work at all.
80 if ($src == $request->getURLtoSelf() ) {
81 return $this->error(fmt("recursive inclusion of url %s", $src));
84 if (! IsSafeURL($src)) {
85 return $this->error(_("Bad url in src: remove all of <, >, \""));
88 $params = array('title' => _("Transcluded page"),
94 'class' => 'transclude',
95 "onload" => "adjust_iframe_height(this);");
97 $noframe_msg[] = fmt("See: %s", HTML::a(array('href' => $src), $src));
99 $noframe_msg = HTML::div(array('class' => 'transclusion'),
100 HTML::p(array(), $noframe_msg));
102 $iframe = HTML::div(HTML::iframe($params, $noframe_msg));
104 /* This doesn't work very well... maybe because CSS screws up NS4 anyway...
105 $iframe = new HtmlElement('ilayer', array('src' => $src), $iframe);
108 return HTML(HTML::p(array('class' => 'transclusion-title'),
109 fmt("Transcluded from %s", LinkURL($src))),
110 $this->_js(), $iframe);
114 * Produce our javascript.
116 * This is used to resize the iframe to fit the content.
117 * Currently it only works if the transcluded document comes
118 * from the same server as the wiki server.
123 static $seen = false;
130 function adjust_iframe_height(frame) {
131 var content = frame.contentDocument;
133 frame.height = content.height + 2 * frame.marginHeight;
136 // Can not get content.height unless transcluded doc
137 // is from the same server...
142 window.addEventListener("resize", function() {
143 f = this.document.body.getElementsByTagName("iframe");
144 for (var i = 0; i < f.length; i++)
145 adjust_iframe_height(f[i]);
151 // $Log: not supported by cvs2svn $
152 // Revision 1.8 2004/02/17 12:11:36 rurban
153 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
155 // Revision 1.7 2003/02/27 22:47:27 dairiki
156 // New functions in HtmlElement:
159 // Helper for generating javascript.
161 // IfJavaScript($if_content, $else_content)
162 // Helper for generating
163 // <script>document.write('...')</script><noscript>...</noscript>
166 // Revision 1.6 2003/02/25 05:45:34 carstenklapp
167 // Added "See: " in front of url, so for browsers that do not support
168 // <iframe> at least there is an indication to the user that this
169 // plugin is actually doing something while at the same time without
170 // being (subjectively) too disruptive to page content.
172 // Revision 1.5 2003/02/24 14:34:44 carstenklapp
173 // Added iframe title (bobby.org accessibility guidelines).
174 // Simplified output for non-iframe and non-visual browsers (as suggested
175 // by http://www.uwosh.edu/programs/accessibility/tutorial.html).
177 // Revision 1.4 2003/01/18 22:08:01 carstenklapp
179 // Reformatting & tabs to spaces;
180 // Added copyleft, getVersion, getDescription, rcs_id.
183 // (c-file-style: "gnu")
188 // c-hanging-comment-ender-p: nil
189 // indent-tabs-mode: nil