1<?php
2  /**
3   * @license    http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
4   * @author     Francois <dokuplugin@merciol.fr>
5   *
6   * Plugin touchtile: display URL in tiles
7   */
8
9if (!defined ('DOKU_INC'))
10    define ('DOKU_INC', realpath (dirname (__FILE__).'/../../').'/');
11if (!defined ('DOKU_PLUGIN'))
12    define ('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'syntax.php');
14
15// ============================================================
16class syntax_plugin_tile extends DokuWiki_Syntax_Plugin {
17
18  // ============================================================
19  function getType () { return 'substition'; }
20  function getPType () { return 'block';}
21  function getSort () { return 299; }
22  function connectTo ($mode) {
23    $this->Lexer->addEntryPattern ('<tile[^>]*>', $mode, 'plugin_tile');
24  }
25  function postConnect() {
26    $this->Lexer->addExitPattern ('</tile>', 'plugin_tile');
27  }
28
29  // ============================================================
30  function handle ($match, $state, $pos, Doku_Handler $handler){
31    switch ($state) {
32    case DOKU_LEXER_ENTER:
33      return array ($state, trim (substr ($match, 5, -1))); // "<title" => 5 ">" => 1
34    case DOKU_LEXER_UNMATCHED:
35      return array ($state, $match);
36    case DOKU_LEXER_EXIT:
37      return array ($state);
38    }
39    return false;
40  }
41
42  var $iconSize;
43  var $imgAttr;
44
45  // ============================================================
46  function render ($mode, Doku_Renderer $renderer, $indata) {
47    if ($mode != 'xhtml')
48      return false;
49    if (empty ($indata))
50      return false;
51    list ($instr, $data) = $indata;
52    switch ($instr) {
53    case DOKU_LEXER_ENTER :
54      if (preg_match_all ("#(\"[^\"]*\")*help(\"[^\"]*\")*#", $data, $dumy) > 0)
55	$this->help ($renderer);
56      $this->iconSize = $this->getConf ('iconSize');
57      if (preg_match_all ("#(\"[^\"]*\")*width=\"(?<width>[^\"]*)\"(\"[^\"]*\")*#", $data, $dumy) > 0)
58	$this->iconSize = $dumy ['width'][0];
59      $this->imgAttr = ' width="'.$this->iconSize.'"';
60      $renderer->doc .= '      <div class="tiles">';
61      break;
62    case DOKU_LEXER_EXIT :
63      $renderer->doc .= '      </div>';
64      break;
65    case DOKU_LEXER_UNMATCHED :
66      $data = trim ($data);
67      if (empty ($data))
68	return false;
69      global $_REQUEST;
70      foreach (explode ("\n", $data) as $line) {
71	$line = trim ($line);
72	if (!$line)
73	  continue;
74	$line = preg_replace ("#\s+\|#", "|", $line);
75	$line = preg_replace ("#\|\s+#", "|", $line);
76	$line = trim ($line,'|');
77	list ($id, $title, $img, $email, $name) = explode ("|", $line);
78	if (!$id)
79	  continue;
80	$email = obfuscate ($email);
81	$mailto = $email ? '<a class="mail JSnocheck" href="mailto:'.$email.'" >'.($name ? $name : $email).'</a>' : "";
82	$renderer->doc .= '
83       <div class="tile">
84        <a href="'.(str_starts_with ($id, 'http') ? $id : wl ($id)).'">
85         <p>'.$title.'</p>
86         <div class="img"><span></span><img src="'.ml ($img, array ('cache'=>$_REQUEST['cache'], 'w'=>$this->iconSize)).'"'.$this->imgAttr.' alt="'.$title.'"/></div>
87        </a>
88        <p>'.$mailto.'</p>
89       </div>';
90      }
91      break;
92    }
93    return true;
94  }
95
96    // ============================================================
97  function help (Doku_Renderer $renderer) {
98    $url = "http://admin.parlenet.org/plugins/tile/";
99    $renderer->doc .=
100      '      <h1>Tile Help</h1>'.NL.
101      '      <ul>'.NL.
102      '        <li>Syntax : <b>&lt;tile [help] [width=pp]&gt;</b><br/>'.
103      '           | :dokuwiki:namespace:page | Short Description | :dokuwiki:namespace:icon.png | member.mel@some.where.org | nickname |<br/>'.
104      '           | http... | Short Description | :dokuwiki:namespace:icon.png | member.mel@some.where.org | nickname |<br/>'.
105      '           ...<br/>'.
106      '           <b>&lt;/tile&gt;</b></li>'.NL.
107      '        <li>Info : <a class="urlextern" rel="nofollow" title="'.$url.'" href="'.$url.'">'.$url.'</a></li>'.NL.
108      '      </ul>'.NL;
109  }
110
111  // ============================================================
112} // syntax_plugin_tile
113?>
114