Translations of this page?:

smblink

smblink plugin by enki
A replacement for doku's default Windows Share Link feature which supports firefox.

Last updated on 2007-07-09. Provides Syntax.
Compatible with DokuWiki rc2007-05-24.

Tagged with firefox, link, share, smb.

Description

A replacement for doku's default Windows Share Link feature which supports firefox. This plugin replaces the default action of Windows Share Links (WSL) to better support the firefox browser. WSLs are still created the same way:

[[\\Host\Share\Directory\File.ext]]

And in Internet Explorer, links will still be the same:

file://///Host/Share/Directory/File.ext

But in firefox, the link will run a javascript onclick which redirects to:

smb://\\Host\Share\Directory\File.ext

This, in itself, is pretty useless, but with a neat little application and registry fix (provided here) this will now make firefox launch the smb: link in Internet Explorer, thus dealing with the file as if you were running IE. I know it's a hack, but that's life! ;)

Oh yeah, if anyone can think of a better way to do this, I'd love to hear it! Futher, I don't currently have a linux box to test any of this, but I could pretty easilly modify this to work for any smb: links as well (in fact that was my original plan, but I got lazy. ;) )

Source Code

/lib/plugins/smblink/syntax.php

<?php
/**
 * Plugin SMB: Makes filesystem links globally accessible, even through firefox.
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Enki <enki1337@gmail.com>
 */
 
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
 
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_smblink extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Enki',
            'email'  => 'enki1337@gmail.com',
            'date'   => '2007-07-09',
            'name'   => 'SMB Plugin',
            'desc'   => 'Makes filesystem links globally accessible, even through firefox.',
            'url'    => 'http://www.dokuwiki.org/',
        );
    }
 
    function getType(){ return 'substition'; }
 
    function getAllowedTypes() { return array(); }   
 
    function getSort(){ return 295; }
 
    function connectTo($mode) {
        //$this->Lexer->addSpecialPattern("\[\[(?i)smb://.+?\]\]",$mode,'plugin_smblink');
        $this->Lexer->addSpecialPattern("\[\[\\\\.+?\]\]",$mode,'plugin_smblink');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        $link = preg_replace(array('/^\[\[/','/\]\]$/u'),'',$match);
        $link = preg_split('/\|/u',$link,2);
        return array($state, $link);
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        list($state, $matchdata) = $data;
        if ($mode == 'xhtml') {
            global $conf;
            global $lang;
            list($url, $name) = $matchdata;
            if (strlen($name) == 0) {
                $urlbits = preg_split('/(\\\|\\/)/u',$url);
                $name = $urlbits[count($urlbits)-1];
            }
            //simple setup
            $link['target'] = $conf['target']['windows'];
            $link['pre']    = '';
            $link['suf']   = '';
            $link['style']  = '';
            $link['name'] = $renderer->_getLinkTitle($name, $url, $isImage);
            $link['title'] = $renderer->_xmlEntities($url);
            if ( !$isImage ) {
                $link['class'] = 'windows';
            } else {
                $link['class'] = 'media';
            }
            if (strstr($_SERVER['HTTP_USER_AGENT'], 'Linux')) {
                $url = 'smb:' . str_replace('\\', '/', $url);
            }
            else {
                //Display error on browsers other than IE
                $link['more'] = 
                    'onclick="if(document.all == null){' .
                        "parent.location='smb://".$url."';" .
                    '}" ' .
                    'onkeypress="if(document.all == null){' . 
                        "parent.location='smb://".$url."';" .
                    '}"';
                    $url = str_replace('\\','/',$url);
                    $url = 'file:///'.$url;
            }
 
            $link['url'] = $url;
 
            //output formatted
            $renderer->doc .= $renderer->_formatLink($link);
        }
        return;
    }
}
?>

Discussion

If you've got any comments or questions, please feel free to add them here. You might consider also emailing me since I might not check back all that often. :)

Linux

Linux works fine with just smb://host/path/to/share (at least FF does - not tested in Konqueror but should work). So I hacked this around a bit to have it work in both Windows FF and Linux…

Great work! Integrated it! I would've done this, but I don't currently have access to a linux box :$ Thanks for the contribution! ~Enki

 
plugin/smblink.txt · Last modified: 2008/02/18 14:14 by 137.226.231.60
 

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported

Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate