1<?php
2/**
3 * Plugin base links: Creates links relative to site root for all links beginning with "/"
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Jürgen A.Lamers <jaloma.ac@googlemail.com>
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_INC.'inc/search.php');
12require_once(DOKU_INC.'inc/JpegMeta.php');
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_jalbum_slideshow extends DokuWiki_Syntax_Plugin {
20
21  /**
22   * default parameters of the jalbum tag
23   */
24  var $dflt = array(
25		    'width' => 20,
26		    'height' => 20,
27		    'align' => 'top',
28		    'albumdir' => 'off',
29		    'albumtitle' => 'off'
30		    );
31
32  /**
33   * return some info
34   */
35  function getInfo(){
36    return array(
37		 'author' => 'Juergen A.Lamers',
38		 'email'  => 'jaloma.ac@googlemail.com',
39		 'date'   => @file_get_contents(DOKU_PLUGIN . 'jalbum/VERSION'),
40		 'name'   => 'jalbum',
41		 'desc'   => 'Slideshow auf Thumbs von JALbum',
42		 'url'    => 'http://wiki.splitbrain.org/plugin:jalbum'
43		 );
44  }
45
46  /**
47   * What kind of syntax are we?
48   */
49  function getType(){
50    return 'substition';
51  }
52
53  function getPType(){
54    return 'stack';
55  }
56
57  function getSort(){ return 305; }
58
59  function connectTo($mode) {
60    $this->Lexer->addSpecialPattern('~~jalbumshow.*?~~',$mode,'plugin_jalbum_slideshow');
61  }
62
63
64  /**
65   * Handle the match
66   */
67  function handle($match, $state, $pos, &$handler){
68    $match = str_replace("~~",null,$match);
69    $match = str_replace("jalbumshow",null,$match);
70    list($junk, $num) = explode(':', $match, 2);
71    $dirs = explode('|', $junk);
72    return array($num,$dirs);
73  }
74
75  /**
76   * Create output
77   */
78  function render($mode, &$renderer, $data) {
79    global $conf;
80    if ($mode == 'xhtml') {
81      list($num,$dirs) = $data;
82      if (sizeof($dirs) == 0) { return true;}
83      $jsscript ='<script type="text/javascript">'.
84	'<!--//--><![CDATA[//><!--'."\n";
85      foreach($dirs as $picdir) {
86	$pics = $this->_search($picdir);
87	if (sizeof($pics) == 0) { continue;}
88	$cc = 1;
89	foreach($pics as $p) {
90	  $jsscript .= '';
91	  $jsscript .= 'neu(';
92	  $jsscript .= '"';
93	  $jsscript .= $this->getConf('baseurl').'/'.$picdir.'thumbs/'.$p['file'];
94	  $jsscript .= '"';
95	  $jsscript .= ',';
96	  $jsscript .= '"';
97	  $jsscript .= '';
98	  $jsscript .= '"';
99	  $jsscript .= ',';
100	  $jsscript .= '"';
101	  $jsscript .= $this->getConf('baseurl').'/'.$picdir.'slides/'.str_replace('JPG','html',$p['file']);
102	  $jsscript .= '"';
103	  $jsscript .= ');'."\n";
104	  if (isset($num) && $cc>=$num) { break; }
105	  $cc++;
106	}
107      }
108      $jsscript .= ''.
109	'var changeTime 	= '.$this->getConf('changetime').';'.
110	'//--><!]]>'."\n".'</script>'."\n";
111
112      if (isset($this->getConf['target'])) {
113	$target = 'target="'.$this->getConf['target'].'" ';
114      } else {
115	$target = '';
116      }
117
118      $body = ''.
119	'<div class="jalbumslideshow">'.
120	'<a '.$target.' href="javascript:transport()">'.
121	'<img class="jalbumslide" src="'.$this->getConf('baseurl').'/'.$picdir.'thumbs/'.$pics[0]['file'].'"'.
122	' width="'.$this->getConf('slidewidth').'"'.
123	' height="'.$this->getConf('slideheight').'"'.
124	' name="bild" alt="Bueld"/>'.
125	'</a>'."\n".
126	'</div>'."\n".
127	'<script type="text/javascript">'."\n".
128	'<!--//--><![CDATA[//><!--'."\n".
129	'wechsel();'."\n".
130	'//--><!]]>'."\n".'</script>'."\n".
131	'';
132      $renderer->doc .= $jsscript;
133      $renderer->doc .= $body;
134      return true;
135    }
136    return false;
137  }
138
139  function _search($dir) {
140    $files = array();
141    search($files,$this->getConf('albumdir'),'search_media',array(),$dir."/thumbs");
142    return $files;
143  }
144}//class
145?>
146