iframe plugin

This plugin allows external urls to be loaded into an iframe in your Dokuwiki page.

  • My version of this page - which could be more recently updated - can be found here

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 }}

  • [width,height] is optional. If only one dimension is specified, it is assumed to be height. Default values are: width - 98%, height - 400px. Do not forget to type the brackets around!
  • |alternate text is optional. If not specified an empty string will be used.

See the plugin in action here.

Configuration

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

  • $js_ok — default value - false, set to true to enable javascript urls.

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://wiki.splitbrain.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

  • 2006-12-17
    • update for stricter type/error checking in php 5 (thanks Ilya)
    • add support for controlling settings through config plugin
  • 2006-05-01 — (darcs version only, others to follow) settings moved to use common plugin functions making them editable via the configuration manager in the admin menu.
  • 2005-10-17 — Released.

To Do

Bugs

Discussion

I would like to ask a question; I use the iFrame plugin for my wiki, embedding html document made in visio. These html documents do not print correct in Internet Explorer (nor any other browers). I'm curious if it is possible to supress the iFrame window on printing (to exclude it)

Grtz. Theo


I've installed the iframe to embed an excel spreadsheet but I'm stuck on how to use it and achieve my goal. Could someone help me? I'm coming from http://www.dokuwiki.org/tips:xls2wiki?s[]=excel#installation. Thx in adv

 
tutorials/iframe.txt · Last modified: 2009/10/15 15:03 by 216.16.224.140
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki