Table of Contents

ISBN Plugin

Compatible with DokuWiki

2006-11-06

plugin Links to amazon.com and shows book cover image by ISBN

Last updated on
2005-07-02
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.

Similar to amazon

Tagged with !broken, books, embed, images, listing, media

Syntax

The syntax is like this

~~isbn:[ISBN]~~
or
~~isbn:[ISBN]|[title]~~

change [ISBN] to whatever ISBN you want
change [title] to the book title

Like with other images, you can specify the alignment through spaces:

Installation

getSort determines the order in which the plugin is executed. So, if you want to replace .* with your own syntax, you can do that be changing the getSort result to be first. – kite 2006-10-03
I still don't know what getSort function does.. :)
And my English not good enough to explain something well. If my English has some grammatical mistakes, please correct it. — kimes 2005-07-02 05:38

Adding a toolbar function

If this is a function that might be used a lot in your wiki, you could add a toolbar function — Ben Pollinger 2005-10-01 13:40.

In inc/toolbar.php, find:

       array(
            'type'   => 'format',
            'title'  => $lang['qb_extlink'],
            'icon'   => 'linkextern.png',
            'open'   => '[[',
            'close'  => ']]',
            'sample' => 'http://example.com|'.$lang['qb_extlink'],
            ),

After it, add:

       array(
            'type'   => 'format',
            'title'  => $lang['qb_isbn'],
            'icon'   => 'isbn.png',
            'open'   => '~~',
            'close'  => '~~',
            'sample' => 'isbn:0000000000|'.$lang['qb_isbn'],
            ),

In inc/lang/en/lang.php, find:

$lang['qb_extlink'] = 'External Link';

After it, add:

$lang['qb_isbn']  = 'ISBN Link';

Upload this image to lib/images/toolbar/ , or if it you want to show it's a link to Amazon, you could use this - but rename it to isbn.png if you do.

Code

syntax.php
<?php
/**
 * ISBN Plugin: links to amazon.com and shows book cover image by ISBN
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     bektek
 */
 
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_isbn extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'bektek',
            'email'  => 'bektek@gmail.com',
            'date'   => '2005-07-02',
            'name'   => 'ISBN Plugin',
            'desc'   => 'ISBN - link to amazon.com and show image',
            'url'    => 'http://www.dokuwiki.org/plugin:isbn',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 322;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern("~~isbn:.+?~~",$mode,'plugin_isbn');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        $match = substr($match,7,-2); // Strip markup
        $match = preg_split('/\|/u',$match,2); // Split title from URL
 
        // Check alignment
        $ralign = (bool)preg_match('/^ /',$match[0]);
        $lalign = (bool)preg_match('/ $/',$match[0]);
        if ($lalign & $ralign) $align = 'center';
        else if ($ralign)      $align = 'right';
        else if ($lalign)      $align = 'left';
        else                   $align = NULL;
 
        if (!isset($match[1])) $match[1] = NULL;
        return array(trim($match[0]),trim($match[1]),$align);
    }            
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
            $isbn    = $data[0]; 
            $target  = '_blank'; // You may adjust this
            $href    = 'http://www.amazon.com/exec/obidos/ISBN='.$isbn;
            $imglink = 'http://images.amazon.com/images/P/'.$isbn.'.01.MZZZZZZZ.gif';
            $title   = ($data[1] ? htmlspecialchars($data[1]) : $isbn);
            $src     = DOKU_BASE.'lib/exe/fetch.php?media='.urlencode($imglink);
 
            $renderer->doc .= '<a href="'.$href.'" target="'.$target.'" class="media" '.
                'title="'.$title.'" onclick="return svchk()" onkeypress="return svchk()">';
            $renderer->doc .= '<img src="'.$src.'" class="media'.$data[2].'" title="'.$title.'" alt="'.$title.'" />';
            $renderer->doc .= '</a>';
            return true;
        }
        return false;
    }
 
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>

Discussion

Esther Brunner 2005-07-02, 2005-07-13 14:20

$Title by $Author, priced $Price

Ben Pollinger 2005-09-30 19:16

It would be awesome if the Link could provide you with the most basic BibTex-Information, if this was possible. Have a look at this page: http://www.2ndminute.org:8080/amatex - once you provide your ISBN Number, it returns the BibTex-Code. — f 2006-12-06 11:02
Note that the JavaScript function “svchk()” no longer exists (and is now unnecessary) in DokuWiki, and does cause JavaScript errors, so it should be removed.
todd [at] rollerorgans [dot] com 2007-02-26