DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:smblink

This is an old revision of the document!


smblink

Compatible with DokuWiki

rc2007-05-24

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

Last updated on
2009-02-09
Provides
Syntax

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with firefox, link, samba, share, smb

By enki
Download smblink.zip

Description

A replacement for DokuWiki'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 script and registry fix (discussed here and available for download 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! Further, I don't currently have a Linux box to test any of this, but I could pretty easily modify this to work for any smb: links as well (in fact that was my original plan, but I got lazy. ;) )

Syntax

[[\\Host\Share\Path\to\file]]

Installation

  1. To install using plugin manager, paste the url http://doku-smblink.googlecode.com/files/smblink.zip into the Download and install field.
  2. If you're using Firefox and Windows, download and install url-handlers.zip to properly handle the smb: protocol.
  3. See issues below.

Change Log

  • 2009-02-09
    • Using the new samba link handler, as the old one is deprecated.
    • Cleaned up the code, added some fluffy comments.
    • The new handler doesn't show the black command window box.
  • 2007-07-09
    • Added linux support
  • 2007-06-03
    • Initial release

Issues

There's an annoying javascript alert box that always pops up. I can't seem to override this using the plugin API, so the only way to fix it is to comment it out of doku's source. The line is in lib/scripts/script.js:

                    alert(LANG['nosmblinks']);

Simply comment the line out:

//                    alert(LANG['nosmblinks']);

Obviously the warning will now not show up even if you don't have the smb url handler installed.

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

Source Code

/lib/plugins/smblink/syntax.php

<?php
/**
 * Plugin SMB: Makes file system 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('meh.');
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'   => '2009-02-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) {
        //Add the smblink pattern to the lexer. Pattern will match [[\ASDF]]
        //$this->Lexer->addSpecialPattern("\[\[(?i)smb://.+?\]\]",$mode,'plugin_smblink');
        $this->Lexer->addSpecialPattern("\[\[\\\\.+?\]\]",$mode,'plugin_smblink');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        //Break the link out of [[ ]] and split it into link and description if there is a '|'
        $link = preg_replace(array('/^\[\[/','/\]\]$/u'),'',$match);
        $link = preg_split('/\|/u',$link,2);
        return array($state, $link);
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if ($mode != 'xhtml') return;
        global $conf, $lang;
        list($state, $matchdata) = $data;
        list($url, $name) = $matchdata;
        //If no name is given, use the last bit of the url
        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';
        }
        //Format the link for smb (Linux or Win-Firefox)
        //Just replace all \ with / to get something like smb://host/path/to/file
        $smburl='smb:' . str_replace('\\', '/', $url);
        //If we're using linux, then smb:// protocol works fine.
        if (strstr($_SERVER['HTTP_USER_AGENT'], 'Linux')) {
            $url = $smburl;
        } else {
            //If we're not on linux, we might be using IE, so...
            //Replace the \\ with the file:/// protocol and put the \\ back in
            $url = str_replace('\\\\', 'file:///\\\\', $url);
            //Use javascript to change the link in Firefox to the smb url.
            $link['more'] =
                'onclick="if(document.all == null){' .
                    "parent.location='".$smburl."';" .
                '}" ' .
                'onkeypress="if(document.all == null){' .
                    "parent.location='".$smburl."';" .
                '}"';
        }
 
        $link['url'] = $url;
 
        //output formatted
        $renderer->doc .= $renderer->_formatLink($link);
        return;
    }
}
?>
plugin/smblink.1234291880.txt.gz · Last modified: 2009-10-06 10:00 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki