PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / libs / factory / forms / includes / html-builder.class.php
robin-image-optimizer / libs / factory / forms / includes Last commit date
providers 5 months ago complex-control.class.php 5 months ago control-holder.class.php 5 months ago control.class.php 5 months ago custom-element.class.php 5 months ago form-element.class.php 5 months ago form-layout.class.php 5 months ago form.class.php 5 months ago holder.class.php 5 months ago html-builder.class.php 5 months ago index.php 5 months ago
html-builder.class.php
129 lines
1 <?php
2 /**
3 * The file contains Html Attribute Builder.
4 *
5 * @package factory-forms
6 * @since 1.0.0
7 */
8
9 // Exit if accessed directly
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 if ( ! class_exists( 'Wbcr_FactoryForms600_HtmlAttributeBuilder' ) ) {
15 /**
16 * Html Attribute Builder
17 *
18 * @since 1.0.0
19 */
20 class Wbcr_FactoryForms600_HtmlAttributeBuilder {
21
22 /**
23 * An array to store css classes.
24 *
25 * @since 1.0.0
26 * @var string[]
27 */
28 protected $css_classes = [];
29
30 /**
31 * An array to store html attributes.
32 *
33 * @since 1.0.0
34 * @var string[]
35 */
36 protected $html_attrs = [];
37
38 /**
39 * An array to store html data.
40 *
41 * @since 1.0.0
42 * @var string[]
43 */
44 protected $html_data = [];
45
46 /**
47 * Adds a new CSS class.
48 *
49 * @since 1.0.0
50 * @return void
51 */
52 public function addCssClass( $class ) {
53 if ( ! is_array( $class ) ) {
54 $this->css_classes[] = $class;
55 } else {
56 $this->css_classes = array_merge( $this->css_classes, $class );
57 }
58 }
59
60 /**
61 * Prints CSS classes.
62 *
63 * @since 1.0.0
64 * @return void
65 */
66 public function printCssClass() {
67 echo implode( ' ', $this->css_classes );
68 }
69
70 /**
71 * Adds a new html data item.
72 *
73 * @since 1.0.0
74 * @param string $dataKey
75 * @param string $dataValue
76 * @return void
77 */
78 public function addHtmlData( $dataKey, $dataValue ) {
79 $this->html_data[ $dataKey ] = $dataValue;
80 }
81
82 /**
83 * Prints html data items.
84 *
85 * @since 1.0.0
86 * @return void
87 */
88 public function printHtmlData() {
89 foreach ( $this->html_data as $key => $value ) {
90 echo 'data-' . $key . '="' . $value . '" ';
91 }
92 }
93
94 /**
95 * Adds a new html attribute.
96 *
97 * @since 1.0.0
98 * @param string $attr_name
99 * @param string $attr_value
100 * @return void
101 */
102 public function addHtmlAttr( $attr_name, $attr_value ) {
103 $this->html_attrs[ $attr_name ] = $attr_value;
104 }
105
106 /**
107 * Prints all html attributes, including css classes and data.
108 *
109 * @since 1.0.0
110 * @return void
111 */
112 public function printAttrs() {
113 $attrs = $this->html_attrs;
114
115 if ( ! empty( $this->css_classes ) ) {
116 $attrs['class'] = implode( ' ', $this->css_classes );
117 }
118
119 foreach ( $this->html_data as $data_key => $data_value ) {
120 $attrs[ 'data-' . $data_key ] = $data_value;
121 }
122
123 foreach ( $attrs as $key => $value ) {
124 echo $key . '="' . $value . '" ';
125 }
126 }
127 }
128 }
129