-
Notifications
You must be signed in to change notification settings - Fork 1
/
Annotation.php
executable file
·111 lines (98 loc) · 2.79 KB
/
Annotation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* File Node
*
* @package MediaWiki
* @subpackage Document
* @version 1.0
* @author Yannick Le Guédart
*/
namespace Overblog\MediaWiki;
/**
* Class Node
*
* This class handles Annotations.
*
* @package MediaWiki
* @subpackage Document
* @author Yannick Le Guédart
*/
class Annotation
{
const BOLD = 'textStyle/bold';
const ITALIC = 'textStyle/italic';
const EMPHASIZE = 'textStyle/emphasize';
const STRONG = 'textStyle/strong';
const DEL = 'textStyle/delete';
const BIG = 'textStyle/big';
const SMALL = 'textStyle/small';
const SUBSCRIPT = 'textStyle/subScript';
const SUPERSCRIPT = 'textStyle/superScript';
const LINK_INTERNAL = 'link/internal';
const LINK_EXTERNAL = 'link/external';
/**
* @var array List of valid wikidom tags and their HTML equivalents
*/
static protected $_tags =
array(
self::BOLD => 'b',
self::ITALIC => 'i',
self::EMPHASIZE => 'em',
self::STRONG => 'strong',
self::DEL => 'del',
self::BIG => 'big',
self::SMALL => 'small',
self::SUBSCRIPT => 'sub',
self::SUPERSCRIPT => 'sup',
self::LINK_INTERNAL => 'a',
self::LINK_EXTERNAL => 'a',
);
/**
* @var array liste des conversion Wikidom => html
*/
static protected $_data2attribute =
[
self::LINK_INTERNAL =>
[
'link' => 'href="%s"',
'title' => 'href="%s"',
'popup' => 'class="popup"'
],
self::LINK_EXTERNAL =>
[
'link' => 'href="%s"',
'title' => 'href="%s"',
'popup' => 'class="popup"'
]
];
/**
* Generate the html tag (begin or end) from the annotation
*
* @param string $type tag type (@see self::$_tags)
* @param bool $begin whether it's the tag start or end
* @param array $data array of special attributes
*
* @return string
*/
static public function getTag(
$type,
$begin = true,
$data = null)
{
$tag = '<' . (($begin === false) ? '/' : '') . self::$_tags[$type];
if (($begin === true) and ! is_null($data))
{
foreach ($data as $k => $v)
{
$tag .=
' ' .
sprintf(
self::$_data2attribute[$type][$k],
addslashes($v)
);
}
}
$tag .= '>';
return $tag;
}
}