xref: /plugin/bez/syntax/qlink.php (revision 9b93b298b733352a4f0b80f5605eb1f78a853271)
165cfcae3Sghi<?php
265cfcae3Sghi// must be run within DokuWiki
365cfcae3Sghiif(!defined('DOKU_INC')) die();
465cfcae3Sghi
5b898877eSghiif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
6b898877eSghirequire_once DOKU_PLUGIN.'syntax.php';
765cfcae3Sghi/**
865cfcae3Sghi * All DokuWiki plugins to extend the parser/rendering mechanism
965cfcae3Sghi * need to inherit from this class
1065cfcae3Sghi */
11b898877eSghiclass syntax_plugin_bez_qlink extends DokuWiki_Syntax_Plugin {
1265cfcae3Sghi
1365cfcae3Sghi    function getType() { return 'substition'; }
1465cfcae3Sghi    function getSort() { return 34; }
1565cfcae3Sghi	function connectTo($mode) {
16*9b93b298SSzymon Olewniczak		$this->Lexer->addSpecialPattern('#(?:z|zk|k)?[0-9]+',$mode,'plugin_bez_qlink');
1765cfcae3Sghi	}
1865cfcae3Sghi
1965cfcae3Sghi
203b3e3ab0Sghi    function handle($match, $state, $pos, Doku_Handler $handler) {
21*9b93b298SSzymon Olewniczak        preg_match('/#([a-z]*)([0-9]+)/', $match, $matches);
22*9b93b298SSzymon Olewniczak        list(,$code, $id) = $matches;
23*9b93b298SSzymon Olewniczak
24*9b93b298SSzymon Olewniczak        $anchor = '';
25*9b93b298SSzymon Olewniczak        $id_key = 'id';
26*9b93b298SSzymon Olewniczak        switch ($code) {
27*9b93b298SSzymon Olewniczak            case '':
28*9b93b298SSzymon Olewniczak                $table = 'thread';
29*9b93b298SSzymon Olewniczak                break;
30*9b93b298SSzymon Olewniczak            case 'k':
31*9b93b298SSzymon Olewniczak                $table = 'thread';
32*9b93b298SSzymon Olewniczak                $anchor = '#k' . $id;
33*9b93b298SSzymon Olewniczak
34*9b93b298SSzymon Olewniczak                /** @var helper_plugin_sqlite $sqlite */
35*9b93b298SSzymon Olewniczak                $sqlite = plugin_load('helper', 'bez_db')->getDB();
36*9b93b298SSzymon Olewniczak                $res = $sqlite->query("SELECT thread_id FROM thread_comment WHERE id=?", $id);
37*9b93b298SSzymon Olewniczak                $id = $res->fetchColumn();
38*9b93b298SSzymon Olewniczak                break;
39*9b93b298SSzymon Olewniczak            case 'z':
40*9b93b298SSzymon Olewniczak                $table = 'task';
41*9b93b298SSzymon Olewniczak                $id_key = 'tid';
42*9b93b298SSzymon Olewniczak                break;
43*9b93b298SSzymon Olewniczak            case 'zk':
44*9b93b298SSzymon Olewniczak                $table = 'task';
45*9b93b298SSzymon Olewniczak                $id_key = 'tid';
46*9b93b298SSzymon Olewniczak                $anchor = '#zk' . $id;
47*9b93b298SSzymon Olewniczak
48*9b93b298SSzymon Olewniczak                /** @var helper_plugin_sqlite $sqlite */
49*9b93b298SSzymon Olewniczak                $sqlite = plugin_load('helper', 'bez_db')->getDB();
50*9b93b298SSzymon Olewniczak                $res = $sqlite->query("SELECT task_id FROM task_comment WHERE id=?", $id);
51*9b93b298SSzymon Olewniczak                $id = $res->fetchColumn();
52*9b93b298SSzymon Olewniczak                break;
5365cfcae3Sghi        }
5465cfcae3Sghi
55*9b93b298SSzymon Olewniczak        return array($match, $table, $id_key, $id, $anchor);
56*9b93b298SSzymon Olewniczak    }
57*9b93b298SSzymon Olewniczak
58*9b93b298SSzymon Olewniczak    function render($mode, Doku_Renderer $renderer, $data) {
5965cfcae3Sghi		if ($mode == 'xhtml') {
6005c9d3bcSghi			$id = $_GET['id'];
6105c9d3bcSghi			$ex = explode(':', $id);
6265cfcae3Sghi
6305c9d3bcSghi			$lang_code = '';
6405c9d3bcSghi			/*english namespace*/
6505c9d3bcSghi			switch($ex[0]) {
6605c9d3bcSghi				case 'en':
6705c9d3bcSghi					$lang_code = $ex[0].':';
6805c9d3bcSghi			}
69*9b93b298SSzymon Olewniczak
70*9b93b298SSzymon Olewniczak            list($match, $table, $id_key, $id, $anchor) = $data;
71*9b93b298SSzymon Olewniczak            $renderer->doc .= '<a href="?id='.$lang_code.'bez:'.$table.':'.$id_key.':'.$id.$anchor.'">'.$match.'</a>';
72*9b93b298SSzymon Olewniczak
7365cfcae3Sghi			return true;
7465cfcae3Sghi		}
7565cfcae3Sghi		return false;
7665cfcae3Sghi    }
7765cfcae3Sghi}
78