IncludeUrl
Question
How can I include the contents of another page in a wiki page?
Answer
First, be sure you're aware of the security and possible copyright risks of letting the content of other (arbitrary!) URLs appear in your pages.
Once you've gotten past that hurdle, the following code in your config.php
adds a (:includeurl http://...:)
markup that lets you embed the contents of other pages into a wiki page.
Markup('includeurl', 'directives', "/\\(:includeurl\\s+(http:[^$UrlExcludeChars]*?)\\s*:\\)/", "IncludeUrlMarkup"); function IncludeUrlMarkup($m) { return Keep(implode('',file(str_replace('&','&',$m[1])))); }
Embedding other pages (Alternative Answer)
includeurl.phpΔ lets you embed other pages in a wiki page. Download script, copy to cookbook folder, and install by adding to config.php:
include_once("$FarmD/cookbook/includeurl.php");
The script adds the markup (:includeurl http://.... [width=..] [height=..] [border=...] [type=...]:)
The url should follow the InterMap specification.
The included page is an embedded object, size can be determined with width and height parameters (default is width=100% and height=400px). This means the page will display with its own styling etc, not just a crude text content display and erronous inclusion of html head code as happens with above markup. Links will continue to work, as does everything else. Embedding a page as an object is similar to the html iframe element. Internet Explorer 6, 7, Firefox and all modern Mozilla browswers support embedded objects, IE5 and earlier does not.
The parameter iframe=1 or iframe=true will result in the use of the <iframe ..> html tag instead of the more general <object ..> tag. But still use optional parameter border=.. if needed, not frameborder. Note that <iframe> is discontinued in the XHTML 1.1 specification. But some browsers may have difficulties with the use of the <object> tag. If iframe option is not used, browsers will use <object> tag, except IE, which will use <iframe> (since IE seems not to cope with <object> too well).
Setting $EnableExternalResource = 0;
will disallow the inclusion of pages with http or https as prefix and still allow inclusion of pages with a relative path url from the same server, for instance like
(:includeurl Path:/samplesite/path/page.html :)
Release history
- 20230214: Update for PHP 8.2, replace FmtPageName() call with XL(), remove <object> interface, only keep <iframe>. (Petko)
- 2019-09-08: Update for PHP 7.4 (Petko)
- 2019-08-05 Fix backward compatibility with Path: links, reported by Byron Lunz. Pass correct option pattern to ParseArgs(). Fix $EnableExternalResource was checked too early and could embed external InterMap links. (Petko)
- 2017-06-21: update for PHP 7.2 compatibility (HansB)
- 2014-12-01: update for PHP 5.5 compatibility
- 2007-11-23: Enabled support of UrlApprovals and InterMap links.
- 2007-04-28: Simplified markup to be kinder to author (no spaces needed at the end). Fixed bug which prevented
$EnableExternalResource = 0;
of working. - 2006-10-28: Added $RecipeInfo
- 2006-08-03a: Added automatic switch, so IE will use <iframe>, and other browsers <object>. Thanks Dominic!
- 2006-08-03: Added iframe=1 or iframe=true option, to use <iframe> html tag instead of the more general <object> tag
- 2006-08-02: Changed type= to be optionally set within the markup, default is type="text/html".
- 2006-07-17: added type="text/html" to code to make it more browser friendly (thanks Christian!)
- 2006-04-24: original release
Example
Here's an example that includes the contents from http://www.example.com into this page:
(:includeurl http://www.example.com:)
Notes
- This will emit some very ugly-looking error messages if the included URL times out. Joachim Durchholz April 11, 2005, at 07:25 AM
- Maybe this could be used with ApproveURLs so that it would not be as insecure? - Martin Fick
- URLs must point to files which do not cause a redirect. So pointing this to a directory will usually cause the server to send a redirect to index.html which will work in a browser, but fail with this recipe. (~from the mailing list)
- I've noticed that IncludeUrl didn't work with IE or Netscape (and by report not with Firefox either). It might be that these browsers don't support <object>...</object>?? Is there a known workaround? 2006-07-17, chr
Markup for https
To get https to also work with the includeurl markup, use the following:
Markup('includeurl', 'directives', "/\\(:includeurl\\s+(https?:[^$UrlExcludeChars]*?)\\s*:\\)/e", "Keep(implode('',file(str_replace('&','&','$1'))))");
Markup when allow_url_fopen is disabled
On some systems the option to open files via their URI is diasbled. One can bypass this by using a class that emulates the identical behavior.
Download browseremulator.class.phpΔ and place into the cookbook/ directory.
Place this into the local/config.php file:
function BrowserEmulatorFile($file){ include_once('cookbook/browseremulator.class.php'); $BrowserEmulator = new BrowserEmulator(); return implode('',$BrowserEmulator->file($file)); } Markup('includeurl', 'directives', "/\\(:includeurl\\s+(http:[^$UrlExcludeChars]*?)\\s*:\\)/e", "Keep(BrowserEmulatorFile('$1'))");
Security
Did I mention that this can be a really dangerous thing to allow on an open-edit website?
See Also
- Cookbook /
- Ape Embed videos, maps, documents, and more in wiki pages (Stable)
- PmWiki /
- IncludeOtherPages Include contents from other PmWiki pages
Contributors
Comments
See discussion at IncludeUrl-Talk
User notes +2: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.