PluginProbe
Hash Form – Drag & Drop Form Builder / trunk
Hash Form – Drag & Drop Form Builder vtrunk
1.4.4 1.4.3 1.4.2 1.4.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.6.1 1.2.7 1.2.8 1.2.9 1.3.0 All 47 releases
hash-form / includes / fields / HashFormFieldSeparator.php

HashFormFieldSeparator.php in Hash Form – Drag & Drop Form Builder trunk, at includes/fields/HashFormFieldSeparator.php

81 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || die();
3
4 class HashFormFieldSeparator extends HashFormFieldType {
5
6 protected $type = 'separator';
7
8 public function field_settings_for_type() {
9 return array(
10 'label' => false,
11 'default' => false,
12 'description' => false,
13 'label_position' => false,
14 'required' => false,
15 'field_alignment' => true,
16 );
17 }
18
19 protected function extra_field_default_opts() {
20 return array(
21 'border_width' => '2',
22 'border_style' => 'solid',
23 'separator_spacing' => '',
24 'field_alignment' => 'left',
25 );
26 }
27
28 /**
29 * The line styles the setting offers.
30 */
31 public static function border_styles() {
32 return array('solid', 'double', 'dotted', 'dashed', 'groove', 'ridge');
33 }
34
35 /**
36 * The stored style, held to that list.
37 *
38 * It used to go into the style attribute as it stood, where esc_attr() is
39 * no protection: `solid; height:80px` carries no quotes to escape and each
40 * declaration after the first simply applies.
41 */
42 private function border_style($field) {
43 $style = isset($field['border_style']) ? strtolower(trim($field['border_style'])) : '';
44
45 return in_array($style, self::border_styles(), true) ? $style : 'solid';
46 }
47
48 /**
49 * The line's thickness in whole pixels.
50 *
51 * An empty setting used to be written out as `border-bottom-width:px`,
52 * which browsers throw away, leaving the line at whatever `medium` happens
53 * to be — 3px — rather than at the 2px the field says it defaults to.
54 */
55 private function border_width($field) {
56 $width = isset($field['border_width']) ? $field['border_width'] : '';
57
58 return is_numeric($width) && $width >= 0 ? (int) $width : 2;
59 }
60
61 protected function input_html() {
62 $field = $this->get_field();
63
64 $style = array(
65 'border-bottom-style:' . $this->border_style($field),
66 'border-bottom-width:' . $this->border_width($field) . 'px',
67 );
68
69 $spacing = isset($field['separator_spacing']) ? $field['separator_spacing'] : '';
70
71 if (is_numeric($spacing)) {
72 $style[] = 'margin-top:' . absint($spacing) . 'px';
73 $style[] = 'margin-bottom:' . absint($spacing) . 'px';
74 }
75 ?>
76 <hr class="hf-separator-border" style="<?php echo esc_attr(implode('; ', $style) . ';'); ?>" id="field_change_style_<?php echo absint($field['id']); ?>" />
77 <?php
78 }
79
80 }
81