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
|
|
|
|