1<?php
2
3
4/**
5 * Matches web-style hash tags: #tags #mutli_word_tag
6 * No spaces allowed, but all UTF-8 chars recognised
7 * Underscores are displayed as spaces
8 * Also honours the * at the end like normal entries
9 */
10class SI_EntryTag extends SI_Entry {
11
12    public $order   = 10;
13    public $type    = 'tag';
14    public $section = 1;
15
16    // first is for Dokuwiki syntax parser matching, second for internal lexing
17    public $regex = '(?<=\s|^)\#[^\s]+';
18    private $_regex = '`(?:\s|^)\#([^#*\s]+)(\*?)`';
19
20
21    function match($text) {
22        $this->items = array();
23        $matches = array();
24        $hits = preg_match_all($this->_regex, $text, $matches, PREG_SET_ORDER);
25        if ($hits > 0) {
26            foreach ($matches as $match) {
27                $item = &$this->items[];
28                $tag = $match[1];
29                $item['entry'] = $tag;
30                $item['display'] = str_replace('_', ' ', $tag);  // swap '_' for spaces for display
31                $item['section'] = $this->section;
32                $item['type'] = $this->type;
33                $item['star'] = $match[2] == '*' ? true : false;
34            }
35            return true;
36        } else {
37            return false;
38        }
39    }
40}