====== ISBN Plugin ======
---- plugin ----
description: Links to amazon.com and shows book cover image by ISBN
author : kimes
email : bektek@gmail.com
type : syntax
lastupdate : 2005-07-02
compatible : 2006-11-06
depends :
conflicts :
similar : amazon
tags : media, images, listing, books, embed, !broken
----
===== 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:
* ''%%~~isbn:[ISBN] ~~%%'' -> left aligned
* ''%%~~isbn: [ISBN] ~~%%'' -> centered
* ''%%~~isbn: [ISBN]~~%%'' -> right aligned
===== Installation =====
* make a new file and name it syntax.php and paste this code in it and save it!
* make a directory named isbn under [dokuwiki's home]/lib/plugins
* Put the made php file in the folder made above.
* That's it.
>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@puzzlers.org|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. --- //[[bektek@gmail.com|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 --- //[[benpollinger@gmail.com|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/ {{http://pollinger.34sp.com/offsite/isbn.png}}, or if it you want to show it's a link to Amazon, you could use this {{http://pollinger.34sp.com/offsite/amazon.png}} - but rename it to isbn.png if you do.
====== Code ======
'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 .= '';
$renderer->doc .= '';
$renderer->doc .= '';
return true;
}
return false;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>
====== Discussion ======
* I made a small change: The generated image link is now with the same attributes as other DokuWiki links.
* I just realized that in the code you allow a title to be appended after the ISBN and a pipe char. Is this the intended behavior or just a leftover from my code? -- I think it could be useful so I changed the syntax description for the plugin.
* I now implemented an alignment attribute like that of images and adjusted the syntax.
--- //[[esther@kaffeehaus.ch|Esther Brunner]] 2005-07-02, 2005-07-13 14:20//
* Great work. It'd be good to be able to pull more info from Amazon (author, title, price) just by giving the ISBN to the plugin. [[http://www.amazon.com/webservices|AWS]] would seem to enable this. Output could look like:
|{{wiki:dokuwiki-64.png}}| $Title by $Author, priced $Price|
--- //[[benpollinger@gmail.com|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. --- //[[flow@project22.org|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@rollerorgans.com]] 2007-02-26