-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
executable file
·70 lines (63 loc) · 1.74 KB
/
plugin.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
<?php
class FontAwesomePlugin extends KokenPlugin
{
function __construct()
{
$this->register_hook('before_closing_head', 'insertFontAwesomeStyles');
$this->register_filter('site.output', 'filterFontAwesome');
}
/**
* Add the Font Awesome library to the page
*
* @return null
*/
public function insertFontAwesomeStyles()
{
echo '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">';
}
/**
* Filter the contents of a rendered page to replace
* text links with Font Awesome Icons.
*
* @param string $content
*
* @return string
*/
public function filterFontAwesome($content)
{
$content = $this->removeFontAwesomePrefixInTags($content);
$content = $this->replaceFontAwesomeContentWithIcon($content);
return $content;
}
/**
* Format any Font Awesome identifiers contained in html element tags.
*
* Input: <div title="fa-icon"></div>
*
* Result: <div title="icon"></div>
*
* @param string $string
*
* @return string
*/
protected function removeFontAwesomePrefixInTags($string)
{
return preg_replace('/"fa-(.+?)"/', '"$1"', $string);
}
/**
* Replace any content that starts with the Font Awesome prefix
* with a Font Awesome icont.
*
* Input: <div>fa-icon</div>
*
* Result: <div><i class="fa fa-icon" aria-hidden="true"></i></div>
*
* @param string $string
*
* @return string
*/
protected function replaceFontAwesomeContentWithIcon($string)
{
return preg_replace('/>(\s*?)fa-([a-z-]+?)(\s*?)</', '><i class="fa fa-$2"></i><', $string);
}
}