Table of Contents

iframe plugin

iframe plugin by Christopher Smith
Allows external URLs to be loaded into an iframe in your Dokuwiki page.

Last updated on 2006-12-17. Provides Syntax.
No compatibility info given!

Tagged with embed, iframe.

Acknowledgements

The plugin was created in response to an idea mentioned by Styno.

This plugin was used as a basis for google_cal by Kite

Syntax

Simple:

{{url>http://www.somesite.com/somepage.html}}

Complete:

{{url>someurl [ width , height ] | alternate-text }}

See the plugin in action here.

Configuration

The plugin has one configuration setting, which can be set via the admin/configuration settings page.

Installation

Plugin sources: zip format (4k), tar.gz format (3k), darcs repository

If your wiki uses either the plugin manager or the darcs plugin you can use them with the links above to install the plugin.

To install the plugin manually, download the source to your plugin folder, lib/plugins and extract its contents. That will create a new plugin folder, lib/plugins/iframe, and install the plugin.

The folder will contain:

conf/default.php                       default settings
conf/metadata.php                      settings information for the config plugin
lang/xx/lang.php                       language strings for config plugin
syntax.php                             plugin script

The plugin is now installed.

Details

The plugin consists of one file, the plugin script syntax.php.

syntax.php

<?php
/**
 * Plugin Iframe: Inserts an iframe element to include the specified url
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Christopher Smith <chris@jalakai.co.uk>
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_iframe extends DokuWiki_Syntax_Plugin {
 
    function getInfo(){
      return array(
        'author' => 'Christopher Smith',
        'email'  => 'chris@jalakai.co.uk',
        'date'   => '2006-12-17',
        'name'   => 'Iframe Plugin',
        'desc'   => 'Add an iframe containing the specified url
                     syntax: {{url>http://www.somesite.com/somepage.htm[w,h]|alternate text}}',
        'url'    => 'http://www.dokuwiki.org/plugin:iframe',
      );
    }
 
    function getType() { return 'substition'; }
    function getSort() { return 305; }
    function connectTo($mode) { $this->Lexer->addSpecialPattern('{{url>.*?}}',$mode,'plugin_iframe'); }
 
    function handle($match, $state, $pos, &$handler){
      $match = html_entity_decode(substr($match, 6, -2));
      @list($url, $alt) = explode('|',$match,2);
      $matches=array();
// '/^\s*([^\[|]+)(?:\[(?:([^,\]]*),)?([^,\]]*)\])?(?:\s*(?:\|\s*(.*))?)?$/mD'
      if (preg_match('/(.*)\[(.*)\]$/',trim($url),$matches)) {
        $url = $matches[1];
        if (strpos($matches[2],',') !== false) {
          @list($w, $h) = explode(',',$matches[2],2);
        } else {
          $h = $matches[2];
          $w = '98%';
        }
      } else {
        $w = '98%';
        $h = '400px';
      }
 
      if (!isset($alt)) $alt = '';
      if (!$this->getConf('js_ok') && substr($url,0,11) == 'javascript:') $url = 'error';
 
      return array(hsc(trim($url)), hsc(trim($alt)), hsc(trim($w)), hsc(trim($h))); 
    }
 
    function render($mode, &$renderer, $data) {
 
      list($url, $alt, $w, $h) = $data;
      if($mode == 'xhtml'){
          if ($url != 'error') {
            $renderer->doc .= '<iframe title="'.$alt.'" src="'.$url.'" style="width:'.$w.'; height: '.$h.';">'.$alt.'</iframe>';
          } else {
            $renderer->doc .= '<div>'.$alt.'</div>';
          }
          return true;
      }
      return false;
    }
}

Revision History

To Do

Bugs

Discussion

Would it be a good idea to add some class identifier to the iframe element? This way one can use a stylesheet to style the iframe (e.g. remove the ugly border). – Styno 2005-10-17 23:17

There are no other iframes in a normal Dokuwiki page, your style rule can target the tag itself or the tag as a a descendent of the dokuwiki page, e.g.
iframe {...}
or 
.dokuwiki iframe {...}

If you have a recommended style (I don't use iframes normally) add it here. — Christopher Smith 2005-10-17 23:28


For what its worth, i use (added to layout.css):

iframe {
border-style: none;
background-color: white;
position: relative;
left: -28px;
}

My template is non-standard, so you may not need to move it to the left.

Green Box 2006-02-02 03:48

or this one that integrate nicelly with the default theme:

iframe {
border: 1px solid __border__;
background-color: white;
}

Is it possible that links that are opened from the iframe get also loaded in the iframe and not in the complete page? Sorry I don't know how this stuff works, just thought this would be very nice… — Thomas 2005-11-25 09:22

I don't think so. The behaviour of links contained within the iframe content is solely determined by that content not by the iframe itself. Links in that content which have a target value of “_top” will load in the browser window, links which no target value or a value of “_self” should reload in the iframe. — Christopher Smith 2005-11-25 14:34
Not that bad, so when the content I include is my own content, I could change all links in the way that they use “_self”… Since I don't want to include external webpages, that could be enough for my needs. — Thomas 2005-11-25 16:41

I don't particularly like the kind of user interface that results from the use of the iframe. Is there any way of including the HTML directly? I guess in order to make this work well, you might want to be able to specify an XPath, as in

{{ihtml>http://somehost/foo.html //title[@lang='eng'}}

Tom


Thanks Chris, I like this plugin – it's just the right to include the motto of the day like it can be obtained froWerner Flamme 2006-08-30


Hi, Chris
I've simplified plugin and made it PHP5 compatible (at least, on mine 5.1.6 original plugin does not work)
    function handle($match, $state, $pos, &$handler){
      $match = html_entity_decode(substr($match, 6, -2));
      list($url, $alt) = explode('|',$match,2);
 
      $matches=array();
      preg_match('/^([^\s]+)\s*(\[(.*)\])?$/',trim($url),$matches);
 
      $url = $matches[1];
      @list($h,$w) = explode(",",$matches[3]); // width/height order is reverted, regarding to the original plugin
 
      if (!$h) $h = '400px';
      if (!$w) $w = '98%';
 
      if (!isset($alt)) $alt = '';
      if (!$js_ok && substr($url,0,11) == 'javascript:') $url = 'error';
 
      return array(hsc(trim($url)), hsc(trim($alt)), hsc(trim($w)), hsc(trim($h))); 
    }


Best regards, — Ilya Lebedev 2006-11-09 15:00

Hi Ilya, thank you for the modification.
But in line 7 you had to change h and w
    @list($w,$h) = explode(",",$matches[3]);

Sebastian

Hi Sebastian,
Sorry, i forgot to explain this: IMHO, the height is the more important parameter, than the width. If you would like to define only the height, in the original plugin you have to specify the width too. — Ilya Lebedev 2006-11-21 09:55



Hello Christopher,
I am now looking at a way to publish my Menu'ed HTML E-book collection within my local network. I already use KnowledgeTree to distribute the non-html content (like PDF's and Doc's). Now I came to DokuWiki with the iFrame-plugin installed to see if it's fitting my needs. I am missing only one thing in the iFrame-plugin to be honest.
It's a possibility to add a link below or above the iFrame to open the iFrame-content in a new window by utilizing e.g. _blank. This way I can make one wiki-page per book with the iFrame to the actual location on my server. Then, when users feel the need to read the book in a full window (I think some really want this…) they can click the “open in new window” button and then they are being served…:-P
Would it be possible to extend the plugin with this feature or can you maybe give me some hints to extend the plugin myself?
Thanks in advance… Best regards, — Mischa The Evil 2007-03-15 07:44

Add the following line immediately prior the the iframe line (#64 in current release)
$renderer->doc .= '<p>Click <a href="'.$url.'" alt="'.$alt.'" target="_new">here</a> to open the page in its own window.</p>';

Christopher Smith 2007-03-15 23:11

Thanks Chris. This really helped me out and I've now implemented the snippet and it works great. Here's how I changed the posted snippet to fit my wishes…

$renderer->doc .= '<p align="right">Click <a href="'.$url.'" alt="'.$alt.'" target="_blank">here</a> to open the page in its own window.</p>';


I placed the new line directly below line 64 since I wanted the link below the iFrame and also aligned to the right of the page. Also a change to the target-argument from _new to _blank since this is the way the W3C wants it….LOL. Again: thanks for the help…

Regards, — Mischa The Evil 2007-03-17 00:18


Hello, I would like to integrate Google Calender on my wiki but I want it to be editable, so that I can add meetings and stuff, I tried to just copy the url from my url bar in IE and it works until I close the wiki and then open it again. It says that cookies isn't enabled.. Is there a way to get around this? Regards, — Victor Pettersson 2008-02-06 18:17

Hello, it would be nice to make it possible to set parameters like frameborder=“0” allowtransparency=“true” to let things like this looking a bit more nice: http://www.google.com/talk/service/badge/NewStefan Pampel 2008-03-03


Admin Only

Would be a good idea to make this a admin only or use the ACL to prevent embedding of spamvertized website from being embedded. Scott 06.21.2007 22:22