1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Luigi Micco <l.micco@tiscali.it>
5 */
6
7if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
8if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
9require_once(DOKU_PLUGIN.'syntax.php');
10
11class syntax_plugin_pagebox extends DokuWiki_Syntax_Plugin {
12
13	function getInfo(){
14		return array(
15      'author' => 'Luigi micco',
16      'email'  => 'l.micco@tiscali.it',
17      'date'   => '2010-09-06',
18      'name'   => 'Pagebox Plugin (syntax component)',
19      'desc'   => 'Allow to use box like MediaWiki to show table and pages',
20      'url'    => 'http://www.bitlibero.com/dokuwiki/pagebox-06.09.2010.zip',
21		);
22	}
23
24	function getType(){ return 'protected'; }
25	function getAllowedTypes() { return array('substition','protected','disabled','formatting'); }
26	function getSort(){ return 315; }
27	function getPType(){ return 'block'; }
28  function connectTo($mode) {
29      $this->Lexer->addSpecialPattern('{{pagebox>.+?}}', $mode, 'plugin_pagebox');
30  }
31
32  function handle($match, $state, $pos, &$handler) {
33
34    $match = substr($match, 2, -2); // strip markup
35    list($match, $flags) = explode('&', $match, 2);
36
37    // break the pattern up into its constituent parts
38    list($include, $id, $section) = preg_split('/>|#/u', $match, 3);
39    return array($include, $id, explode('&', $flags));
40
41  }
42
43	function render($mode, &$renderer, $data){
44
45    list($type, $page_id, $flags) = $data;
46    if ($type == "pagebox") {
47      if(auth_quickaclcheck($page_id) >= AUTH_READ) {
48        if($mode == 'xhtml'){
49
50          $align = 'void';
51          $width = 'auto';
52
53          foreach($flags as $value) {
54            if (is_numeric($value)) $width = $value.'px';
55            if (strtolower($value) == 'right') $align = 'right';
56            if (strtolower($value) == 'center') $align = 'center';
57            if (strtolower($value) == 'left') $align = 'left';
58          }
59
60          $renderer->doc.= '<div class="pagebox_out a'.$align.'" style="width:'.$width.'">';
61          $renderer->doc.= '<div class="pagebox_in">';
62          $renderer->doc.= tpl_include_page($page_id, false);
63          $renderer->doc.= '</div>';
64          $renderer->doc.= '</div>';
65
66          return true;
67        }
68        return false;
69      }
70    }
71		return false;
72	}
73}
74
75//Setup VIM: ex: et ts=4 enc=utf-8 :
76