1<?php
2/**
3 * Plugin Slideshare: Create Slideshare link and object from ID.
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Detlef Burkhardt
7 * @version    0.1.0
8 * @update     2011-09-20
9 *
10
11if(!defined('DOKU_INC')) die();
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'syntax.php');
14
15/**
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
18 */
19class syntax_plugin_slideshare extends DokuWiki_Syntax_Plugin {
20  var $html;
21  var $pattern;
22
23  function syntax_plugin_slideshare(){
24    $this->html    = @file_get_contents(DOKU_PLUGIN.'slideshare/div.htm');
25    $this->pattern = '/\{\{(\s?)slide>(|link):([^} |]+)\|?(.*?)(\s?)\}\}/';
26  }
27
28  function getInfo() {
29    return array(
30    'author' => 'Detlef Burkhardt',
31    'email'  => 'burkhardt@web.de',
32    'date'   => '2008-04-05',
33    'name'   => 'Slideshare Plugin',
34    'desc'   => 'Slideshare link and object{{slide>[|link]:ID}}',
35    'url'    => 'github commes here',
36    );
37  }
38
39  function getType(){ return 'substition'; }
40  function getSort(){ return 159; }
41  function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{\s?slide>[^}]*\s?\}\}',$mode,'plugin_slideshare'); }
42
43  function handle($match, $state, $pos, &$handler){
44    $pm = preg_match_all($this->pattern,$match,$result);
45    $left  = ($result[1][0]==" ");
46    $right = ($result[5][0]==" ");
47    $cmd   = $result[2][0];
48    $id    = $result[3][0];
49    $title = $result[4][0];
50    if ($left==true && $right==true){
51      $align = 'center';
52    }else if($left==true){
53      $align = 'right';
54    }else if($right==true){
55      $align = 'left';
56    }
57    return array($state, array($cmd,$id,$align,$title));
58  }
59
60  function render($mode, &$renderer, $data){
61    if($mode != 'xhtml'){return false;}
62    list($state, $match) = $data;
63    list($cmd,$id,$align,$title) = $match;
64    $id    = urlencode($id);
65    $title = urlencode($title);
66    $title = str_replace("+"," ",$title);
67
68    if ($cmd=='link') {
69        $lnkFormat='<a href="http://www.slideshare.net/slideshow/embed_code/%s" title="Slideshare-Link: %s">';
70        $href_start=sprintf($lnkFormat,$id,empty($title)?$id:$title.' ('.$id.')');
71        $renderer->doc.=$href_start.'<div class="slide_icon">'.$title.'</div></a>';
72        return true;
73    } else {
74        if ($align=='center'){$renderer->doc.="<center>";}
75        $renderer->doc.=sprintf($this->html,$id,425,350,$align,$id,425,350,$align,$title);
76        if ($align=='center'){$renderer->doc.="</center>";}
77        $renderer->doc.=NL;
78        return true;
79    }
80
81/*
82    switch($cmd){
83      case 'link':
84        $lnkFormat='<a href="http://www.slideshare.net/slideshow/embed_code/%s" title="Slideshare-Link: %s">';
85        $href_start=sprintf($lnkFormat,$id,empty($title)?$id:$title.' ('.$id.')');
86        $renderer->doc.=$href_start.'<div class="slide_icon">'.$title.'</div></a>';
87        return true;
88
89      case "em":
90        if ($align=='center'){$renderer->doc.="<center>";}
91
92        $renderer->doc.=sprintf($this->html,$id,425,350,$align,$id,425,350,$align,$title);
93        if ($align=='center'){$renderer->doc.="</center>";}
94        $renderer->doc.=NL;
95        return true;
96
97
98      case 'small':
99        if ($align=='center'){$renderer->doc.="<center>";}
100        $renderer->doc.=sprintf($this->html,255,210,$id,$align,$title,$id);
101        if ($align=='center'){$renderer->doc.="</center>";}
102        return true;
103
104    }
105*/
106    $renderer->doc.=NL;
107  }
108}
109?>