Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

IncludeUrl

Summary: Include html pages into PmWiki 2.x pages
Version: 2007-11-23
Status: stable
Prerequisites: pmwiki-2.0
Maintainer:
Categories: Includes
Download: includeurl.phpΔ

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*:\\)/e",
      "Keep(implode('',file(str_replace('&','&','$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 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 /samplesite/path/page.html :)

Version updates of includeurl.php

  • 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:)

Discussion

Keep in mind that most things served up by a browser aren't designed to be included by other pages -- i.e., they have extra <html>, <head>, <title>, <body>, etc. tags in them that will probably not display correctly when embedded in another page. This recipe makes no attempt to remove the extra information.

Note that this isn't needed if you just want to include an external resource in a layout template -- you can just use <!--file:http://...--> for that. If using an http://... link doesn't work, try using an absolute directory link, such as /home/mysite/public/file.ext.


IncludeUrl not working in IE / changed "object" to "iframe"

It doesn't work yet! s. Re: IncludeUrl not working with IE or Netscape?. Perhaps it's because of a object tag vulnerability in IE and/or a security fix, cause other object types are working in IE, e.g. SVG-objects or IE doesn't support the object types text/html.

For this reason and becaus in the IncludeUrl cookbook is hard coded type="text/html" - so you can't anyway use this markup for other things like html - I have replaced <object> with <iframe> and now it works in IE too:

Has somebody any reasons to do this not?

cg, 2006-08-01

Seems reasonable, but IFRAME is not supported any longer from XHTML 1.1. - I changed the hard-coded type="twext/html" to be optionally set within the markup in includeurl.phpΔ, for those who like to experiment with othe robject types. HansB August 02, 2006, at 03:41 AM

I changed includeurl.php so that it will now use the <iframe> tag if the option iframe=1 or iframe=true is specified in the markup. HansB August 03, 2006, at 03:58 AM


Security

Did I mention that this can be a really dangerous thing to allow on an open-edit website?

See Also

IncludeOtherPages

Contributors

Mimick old IncludeUrl script [*http://foo.bar/bleh.html*]

    
Markup('includeurl', 'directives',
      "/\\(:includeurl\\s+(http:[^$UrlExcludeChars]*?)\\s*:\\)/e",
      "Keep(implode('',file(str_replace('&amp;','&','$1'))))");

Markup('[*','_begin',
      "/\\[\\*(http:[^$UrlExcludeChars]*?)\\*\\]/e",
      "Keep(implode('',file(str_replace('&amp;','&','$1'))))");

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('&amp;','&','$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'))");

Using IncludeUrl to embed files from a Subversion repository via TRAC

Here is how I, Christian Ridderström, have used this recipe to embed files from a Subversion repository via TRAC. Download the script as usual, then insert something like the following into your configuration file:

// Enable a restricted version of includeurl for embedding
// material from the repositor via TRAC
if(true) {
  include_once("$FarmD/cookbook/includeurl.php");
  DisableMarkup("includeurl");  // Arbitrary URIs may not be included 
  Markup('includesvn', 'directives',
         '/\\(:includesvn (.*?) (.*?)\\s*:\\)/ei',
         "IncludeSvn(\$pagename, PSS('$1'), PSS('$2'))");

  function IncludeSvn($pagename, $path, $opt) {
    $uri = "http://www.lyx.org/trac/browser/lyx-devel/trunk/"
	. $path . "?format=raw";
    return IncludeUrl($pagename, $uri, $opt);
  }
 }

You can then use the markup (:includeSvn somefile :) to embed a file from the repository.

Edit - History - Print - Recent Changes - Search
Page last modified on June 05, 2008, at 07:53 AM