1<?php
2/**
3 * Plugin Links: Vytváří odkazy s automatickým načtením titulku stránky
4 */
5if(!defined('DOKU_INC')) die();
6
7class syntax_plugin_links extends DokuWiki_Syntax_Plugin {
8
9    public function getType() {
10        return 'substition';
11    }
12
13    public function getPType() {
14        return 'normal';
15    }
16
17    public function getSort() {
18        return 159;
19    }
20
21    public function connectTo($mode) {
22        $this->Lexer->addSpecialPattern('\{\{link>[^}]*\}\}', $mode, 'plugin_links');
23    }
24
25    public function handle($match, $state, $pos, Doku_Handler $handler) {
26        $url = substr($match, 7, -2); // odstranění {{link> a }}
27        return array($url);
28    }
29
30    public function render($mode, Doku_Renderer $renderer, $data) {
31        if($mode !== 'xhtml') return false;
32
33        list($url) = $data;
34        $url = trim($url);
35
36        try {
37            // Přidání protokolu, pokud chybí
38            if (!preg_match('~^(?:f|ht)tps?://~i', $url)) {
39                $url = 'http://' . $url;
40            }
41
42            // Nastavení kontextu pro stream
43            $context = stream_context_create([
44                'http' => [
45                    'method' => 'GET',
46                    'header' => [
47                        'User-Agent: DokuWiki Links Plugin',
48                        'Accept: text/html,application/xhtml+xml,application/xml'
49                    ],
50