Flickr plugin

About

The Flickr plugin provides an easy access to any Flickr image. It creates a usual external media with a link to the image’s Flickr page.

Syntax

The syntax is very similar to the default media links:

{{flickr>static-link-to-the-image}}

The link of our Flickr image can be found on the all sizes page of the image. You can simply use the photo’s URL on the bottom of the page. You should use the parameters defined in the syntax of dokuwiki’s image handling.

Example

The link should look like this:

http://static.flickr.com/63/161846933_929e8990ae_m.jpg

The only important part of the link is the 161846933 number in the start of the file name. It contains the id of the image. This is used to generate the link of your image:

http://www.flickr.com/photos/csiknor/161846933/

Rendering the image in different size in the middle of the screen is as follows:

{{flickr> http://static.flickr.com/63/161846933_929e8990ae_m.jpg?100 |Some label}}

Some label

Configuration

The personal part of the link is comes from the config file:1)

$conf['plugin']['flickr']['accounturl'] = 'photos/csiknor';

Installation

Plugin sources: zip format (3k)

If your wiki uses either the plugin manager 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/flickr, and install the plugin.

The folder will contain:

syntax.php                             plugin script

The plugin is now installed.

Deatils

The plugin is just one file.

syntax.php

<?php
/**
 * Plugin Flickr: Embedding Flickr image
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Norbert Csík <norbert.csik@gmail.com>
 * @version    0.2.0
 */
 
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_flickr extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Norbert Csík',
            'email'  => 'norbert.csik@gmail.com',
            'date'   => '2006-06-07',
            'name'   => 'Flickr Plugin',
            'desc'   => 'Embedding Flickr image',
            'url'    => 'http://www.csik.net/project:flickr',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * What kind of syntax do we allow (optional)
     */
//    function getAllowedTypes() {
//        return array();
//    }
 
    /**
     * What about paragraphs? (optional)
     */
//    function getPType(){
//        return 'normal';
//    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 1;
    }
 
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern('\{\{flickr>.*?\}\}',$mode,'plugin_flickr');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        switch ($state) {
          case DOKU_LEXER_ENTER :
            break;
          case DOKU_LEXER_MATCHED :
            break;
          case DOKU_LEXER_UNMATCHED :
            break;
          case DOKU_LEXER_EXIT :
            break;
          case DOKU_LEXER_SPECIAL :
            return $match;
            break;
        }
        return array();
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
        	global $conf;
        
			// strip flickr> from start
			$data = "{{".substr($data,9,-2)."}}"; 
 
			// get flickr image id
			$start = strrpos($data, "/")+1;
			$end = strpos($data, "_", $start);
			$imageid = substr($data, $start, $end-$start);
    		
    		// parse the media az an external media
    		$p = Doku_Handler_Parse_Media($data);
 
			// render the media as a flickr external media
			$link = array();
			$link['class']  = 'media';
			$link['style']  = '';
			$link['pre']    = '';
			$link['suf']    = '';
			$link['more']   = '';
			$link['target'] = $conf['target']['media'];
 
			$link['title']  = $p['title'];
			$link['url']    = "http://www.flickr.com/".$conf['plugin']['flickr']['accounturl']."/".$imageid."/";
			$link['name']   = $renderer->_media ($p['src'], $p['title'], $p['align'], $p['width'], $p['height'], $p['cache']);
			
			list($ext,$mime) = mimetype($p['src']);
			if(substr($mime,0,5) == 'image'){
				// link only jpeg images
				// if ($ext != 'jpg' && $ext != 'jpeg') $noLink = TRUE;
			}elseif($mime == 'application/x-shockwave-flash'){
				// don't link flash movies
				$noLink = TRUE;
			}else{
				// add file icons
				$link['class'] .= ' mediafile mf_'.$ext;
			}
 
			//output formatted
			$renderer->doc .= $renderer->_formatLink($link);
			
            return true;
        }
        return false;
    }
}

Change log

  • 2006-06-07 – 0.2 First release

To Do

  • Make it simplier generating a wiki image link from the syntax and let dokuwiki handle the link and image creation.
  • Be able to use more user’s images using a property
1) conf/local.php
 
project/flickr.txt · Utolsó módosítás: 2006.06.07 13:49 szerkesztette: norbert
 
Valid XHTML 1.0 Valid CSS Driven by DokuWiki Get Firefox! Hosted by AION CSIK.net