|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the bootstrap-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension; |
|
15
|
|
|
use WBW\Library\Core\Utility\Argument\StringUtility; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Abstract plugin Twig extension. |
|
19
|
|
|
* |
|
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
21
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin |
|
22
|
|
|
* @abstract |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class AbstractPluginTwigExtension extends AbstractBootstrapTwigExtension { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Constructor. |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function __construct() { |
|
30
|
|
|
// NOTHING TO DO. |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Displays a Font Awesome icon. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $style The Font Awesome style. |
|
37
|
|
|
* @param string $name The Font Awesome name. |
|
38
|
|
|
* @param string $size The Font Awesome size. |
|
39
|
|
|
* @param boolean $fixedWidth Fixed width ? |
|
40
|
|
|
* @param boolean $bordered Bordered ? |
|
41
|
|
|
* @param string $pull The Font Awesome pull. |
|
42
|
|
|
* @param string $anime The Font Awesome animation. |
|
43
|
|
|
* @return string Returns the Font Awesome icon. |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function fontAwesomeIcon($style, $name, $size, $fixedWidth, $bordered, $pull, $anime) { |
|
46
|
|
|
|
|
47
|
|
|
// Initialize the values. |
|
48
|
|
|
$styles = ["", "s", "r", "l", "b"]; |
|
49
|
|
|
$sizes = ["xs", "sm", "lg", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "10x"]; |
|
50
|
|
|
$pulls = ["left", "right"]; |
|
51
|
|
|
$animates = ["spin", "pulse"]; |
|
52
|
|
|
|
|
53
|
|
|
// Initialize the template. |
|
54
|
|
|
$template = "<i %attributes%></i>"; |
|
55
|
|
|
|
|
56
|
|
|
// Initialize the attributes. |
|
57
|
|
|
$attributes = []; |
|
58
|
|
|
|
|
59
|
|
|
$attributes["class"][] = true === in_array($style, $styles) ? "fa" . $style : "fa"; |
|
60
|
|
|
$attributes["class"][] = null !== $name ? "fa-" . $name : null; |
|
61
|
|
|
$attributes["class"][] = true === in_array($size, $sizes) ? "fa-" . $size : null; |
|
62
|
|
|
$attributes["class"][] = true === $fixedWidth ? "fa-fw" : null; |
|
63
|
|
|
$attributes["class"][] = true === $bordered ? "fa-border" : null; |
|
64
|
|
|
$attributes["class"][] = true === in_array($pull, $pulls) ? "fa-pull-" . $pull : null; |
|
65
|
|
|
$attributes["class"][] = true === in_array($anime, $animates) ? "fa-" . $anime : null; |
|
66
|
|
|
|
|
67
|
|
|
// Return the HTML. |
|
68
|
|
|
return StringUtility::replace($template, ["%attributes%"], [StringUtility::parseArray($attributes)]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Displays a jQuery input mask. |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $selector The input mask selector. |
|
75
|
|
|
* @param string $mask The input mask. |
|
76
|
|
|
* @param boolean $scriptTag Script tag ? |
|
77
|
|
|
* @param array $options The input mask options. |
|
78
|
|
|
* @return string Returns the jQuery input mask. |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function jQueryInputMask($selector, $mask, $scriptTag, array $options) { |
|
81
|
|
|
|
|
82
|
|
|
// Initialize the template. |
|
83
|
|
|
$template = ["$('%selector%').inputmask(\"%mask%\",%arguments%);"]; |
|
84
|
|
|
if (true === $scriptTag) { |
|
85
|
|
|
array_unshift($template, "<script type=\"text/javascript\">"); |
|
86
|
|
|
array_push($template, "</script>"); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
// Return the HTML. |
|
90
|
|
|
return StringUtility::replace(implode("\n", $template), ["%selector%", "%mask%", "%arguments%"], [$selector, $mask, json_encode($options)]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Displays a Material Design Iconic Font icon. |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $name The Material Design Iconic Font name. |
|
97
|
|
|
* @param string $size The Material Design Iconic Font size. |
|
98
|
|
|
* @param boolean $fixedWidth Fixed width ? |
|
99
|
|
|
* @param string $border The Material Design Iconic Font border |
|
100
|
|
|
* @param string $pull The Material Design Iconic Font pull. |
|
101
|
|
|
* @param string $spin The Material Design Iconic Font spin. |
|
102
|
|
|
* @param string $rotate The Material Design Iconic Font rotate. |
|
103
|
|
|
* @param string $flip The Material Design Iconic Font flip. |
|
104
|
|
|
* @return string Returns the Material Design Iconic Font icon. |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function materialDesignIconicFontIcon($name, $size, $fixedWidth, $border, $pull, $spin, $rotate, $flip) { |
|
107
|
|
|
|
|
108
|
|
|
// Initialize the values. |
|
109
|
|
|
$sizes = ["lg", "2x", "3x", "4x", "5x"]; |
|
110
|
|
|
$borders = ["border", "border-circle"]; |
|
111
|
|
|
$pulls = ["left", "right"]; |
|
112
|
|
|
$spins = ["spin", "spin-reverse"]; |
|
113
|
|
|
$rotates = ["90", "180", "270"]; |
|
114
|
|
|
$flips = ["horizontal", "vertical"]; |
|
115
|
|
|
|
|
116
|
|
|
// Initialize the template. |
|
117
|
|
|
$template = "<i %attributes%></i>"; |
|
118
|
|
|
|
|
119
|
|
|
// Initialize the attributes. |
|
120
|
|
|
$attributes = []; |
|
121
|
|
|
|
|
122
|
|
|
$attributes["class"][] = "zmdi"; |
|
123
|
|
|
$attributes["class"][] = null !== $name ? "zmdi-" . $name : null; |
|
124
|
|
|
$attributes["class"][] = true === in_array($size, $sizes) ? "zmdi-hc-" . $size : null; |
|
125
|
|
|
$attributes["class"][] = true === $fixedWidth ? "zmdi-hc-fw" : null; |
|
126
|
|
|
$attributes["class"][] = true === in_array($border, $borders) ? "zmdi-hc-" . $border : null; |
|
127
|
|
|
$attributes["class"][] = true === in_array($pull, $pulls) ? "pull-" . $pull : null; |
|
128
|
|
|
$attributes["class"][] = true === in_array($spin, $spins) ? "zmdi-hc-" . $spin : null; |
|
129
|
|
|
$attributes["class"][] = true === in_array($rotate, $rotates) ? "zmdi-hc-rotate-" . $rotate : null; |
|
130
|
|
|
$attributes["class"][] = true === in_array($flip, $flips) ? "zmdi-hc-flip-" . $flip : null; |
|
131
|
|
|
|
|
132
|
|
|
// Return the HTML. |
|
133
|
|
|
return StringUtility::replace($template, ["%attributes%"], [StringUtility::parseArray($attributes)]); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|