====== iframe plugin ====== ---- plugin ---- description: Allows external URLs to be loaded into an iframe in your Dokuwiki page. author : Christopher Smith email : chris@jalakai.co.uk type : syntax lastupdate : 2006-12-17 compatible : depends : conflicts : similar : tags : iframe, embed ---- * My version of this page - which could be more recently updated - can be found [[http://wiki.jalakai.co.uk/dokuwiki/doku.php/tutorials/iframe|here]] ===== Acknowledgements ===== The plugin was created in response to an idea mentioned by [[styno@hotmail.com|Styno]]. This plugin was used as a basis for [[plugin:google_cal]] by [[Kite@puzzlers.org|Kite]] ===== Syntax ===== Simple: ''%%{{url>http://www.somesite.com/somepage.html}}%%'' Complete: ''%%{{%%url>//someurl// [ //width// , //height// ] | //alternate-text// %%}}%%'' \\ * [//width//,//height//] is optional. In pixels (i.e. 100px) or percents (i.e. 50%). 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 [[http://wiki.jalakai.co.uk/dokuwiki/doku.php/test/iframe|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: [[http://dokuwiki.jalakai.co.uk/plugin-iframe.zip|zip format (4k)]], [[http://dokuwiki.jalakai.co.uk/plugin-iframe.tar.gz|tar.gz format (3k)]], [[http://wiki.jalakai.co.uk/repo/dokuwiki/plugins/iframe|darcs repository]] If your wiki uses either the [[plugin:plugin]] manager or the [[plugin:darcs|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 ==== */ 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 .= ''; } else { $renderer->doc .= '
'.$alt.'
'; } 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 [[devel:common plugin functions]] making them editable via the [[plugin:config|configuration manager]] in the admin menu. * 2005-10-17 --- Released. ===== 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@hotmail.com|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. --- //[[chris@jalakai.co.uk|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. --- //[[greenboxster@gmail.com|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... --- //[[just.for.rubbish@gmail.com|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. --- //[[chris@jalakai.co.uk|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. --- //[[just.for.rubbish@gmail.com|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'}} --- //[[nobody@nowhere.com|Tom]]// ---- Thanks Chris, I like this plugin -- it's just the right to include the motto of the day like it can be obtained fro[[http://bowp.netaction.de/ausrede/ (german language only) :-) -- [[werner.flamme@ufz.de|Werner 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.net|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.net|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 [[http://www.knowledgetree.com/|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@hotmail.com|Mischa The Evil]] 2007-03-15 07:44// > Add the following line immediately prior the the iframe line (#64 in current release) $renderer->doc .= '

Click here to open the page in its own window.

';
--- //[[chris@jalakai.co.uk|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 .= '

Click here to open the page in its own window.

';
>> 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 [[http://www.w3.org/TR/html401/types.html#h-6.16|wants]] it....LOL. Again: thanks for the help...\\ Regards, --- //[[mischa_the_evil@hotmail.com|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, --- //[[vices.jkpg@gmail.com|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/New --- //[[polyformal --at -- gmail +dot+ com |Stefan 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//