1: <?php
2:
3: 4: 5:
6: class Quform_Element_Html extends Quform_Element
7: {
8: 9: 10: 11: 12: 13:
14: public function render(array $context = array())
15: {
16: $output = '';
17:
18: if ($this->isVisible()) {
19: $output .= sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getElementClasses($context))));
20: $output .= sprintf('<div class="quform-spacer">%s</div>', $this->getContent());
21: $output .= '</div>';
22: }
23:
24: return $output;
25: }
26:
27: 28: 29: 30: 31: 32:
33: protected function getElementClasses(array $context = array())
34: {
35: $classes = array(
36: 'quform-element',
37: sprintf('quform-element-%s', $this->config('type')),
38: sprintf('quform-element-%s', $this->getIdentifier()),
39: 'quform-cf'
40: );
41:
42: if (Quform::isNonEmptyString($this->config('customElementClass'))) {
43: $classes[] = $this->config('customElementClass');
44: }
45:
46: $classes = apply_filters('quform_element_classes', $classes, $this, $context);
47: $classes = apply_filters('quform_element_classes_' . $this->getIdentifier(), $classes, $this, $context);
48:
49: return $classes;
50: }
51:
52: 53: 54: 55: 56: 57:
58: public function getContent($format = 'html')
59: {
60: if ($format == 'text' && Quform::isNonEmptyString($this->config('plainTextContent'))) {
61: $content = $this->config('plainTextContent');
62: } else {
63: $content = $this->config('content');
64:
65: if ($this->config('autoFormat')) {
66: $content = nl2br($content);
67: }
68: }
69:
70: $content = $this->form->replaceVariablesPreProcess($content);
71:
72: $content = do_shortcode($content);
73:
74: if (is_admin()) {
75:
76: $content = wp_kses_post($content);
77: }
78:
79: $content = apply_filters('quform_html_content', $content, $format, $this, $this->form);
80: $content = apply_filters('quform_html_content_' . $this->getIdentifier(), $content, $format, $this, $this->form);
81:
82: return $content;
83: }
84:
85: 86: 87:
88: public function isEmpty()
89: {
90: return $this->getContent() === '';
91: }
92:
93: 94: 95: 96: 97:
98: protected function getCssSelectors()
99: {
100: return array(
101: 'element' => '%s .quform-element-%s',
102: 'elementSpacer' => '%s .quform-element-%s > .quform-spacer'
103: );
104: }
105:
106: 107: 108: 109: 110: 111:
112: public static function getDefaultConfig($key = null)
113: {
114: $config = apply_filters('quform_default_config_html', array(
115:
116: 'label' => __('HTML', 'quform'),
117: 'content' => '',
118: 'autoFormat' => false,
119:
120:
121: 'customElementClass' => '',
122: 'styles' => array(),
123:
124:
125: 'logicEnabled' => false,
126: 'logicAction' => true,
127: 'logicMatch' => 'all',
128: 'logicRules' => array(),
129:
130:
131: 'showInEmail' => false,
132: 'plainTextContent' => '',
133: 'showInEntry' => false,
134:
135:
136: 'visibility' => ''
137: ));
138:
139: $config['type'] = 'html';
140:
141: if (Quform::isNonEmptyString($key)) {
142: return Quform::get($config, $key);
143: }
144:
145: return $config;
146: }
147: }
148: