/
PluginHtml.php
104 lines (91 loc) · 1.74 KB
/
PluginHtml.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
<?php
namespace voku\twig;
use Twig_Extension;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
/**
* TwigWrapper-Plugins for Html-Helpers
*/
class PluginHtml extends Twig_Extension
{
/**
* __construct()
*/
public function __construct()
{
}
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return array(
new Twig_SimpleFunction(
'getHtmljQuery', array(
$this,
'getHtmljQuery'
)
)
);
}
/**
* {@inheritdoc}
*/
public function getFilters()
{
return array(
new Twig_SimpleFilter(
'lettering', array(
$this,
'lettering'
)
)
);
}
/**
* get jQuery
*
* @param string $localPath
* @param string $jQueryVersion
*
* @return string
*/
public function getHtmljQuery($localPath, $jQueryVersion = '2.1.0')
{
$html = '
<script src="//ajax.googleapis.com/ajax/libs/jquery/' . $jQueryVersion . '/jquery.js"></script>
<script>
if (typeof jQuery == \'undefined\') {
document.write(unescape("%3Cscript src=\'' . $localPath. '\' type=\'text/javascript\'%3E%3C/script%3E"));
}
</script>
';
return $html;
}
/**
* a port of "Lettering.js" in php
*
* @param $str
*
* @return string
*/
public function lettering($str)
{
$output = '';
$array = str_split($str);
$idx = 1;
foreach ($array as $letter) {
$output .= '<span class="char' . $idx++ . '">' . $letter . '</span>';
}
return $output;
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'twig_plugin_Html';
}
}