1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
// Prevent loading this file directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'WCQD_METABOX_Fieldset_Text_Field' ) )
{
class WCQD_METABOX_Fieldset_Text_Field extends WCQD_METABOX_Field
{
/**
* Get field HTML
*
* @param mixed $meta
* @param array $field
*
* @return string
*/
static function html( $meta, $field )
{
$html = array();
$tpl = '<label>%s <input type="text" class="rwmb-fieldset-text" name="%s[%d][%s]" value="%s"></label>';
for ( $row = 0; $row < $field['rows']; $row ++ )
{
foreach ( $field['options'] as $key => $label )
{
$value = isset( $meta[$row][$key] ) ? $meta[$row][$key] : '';
$html[] = sprintf( $tpl, $label, $field['id'], $row, $key, $value );
}
$html[] = '<br>';
}
$out = '<fieldset><legend>' . $field['desc'] . '</legend>' . implode( ' ', $html ) . '</fieldset>';
return $out;
}
/**
* Show end HTML markup for fields
* Do not show field description. Field description is shown before list of fields
*
* @param mixed $meta
* @param array $field
*
* @return string
*/
static function end_html( $meta, $field )
{
$button = $field['clone'] ? call_user_func( array( RW_Meta_Box::get_class_name( $field ), 'add_clone_button' ), $field ) : '';
// Closes the container
$html = "$button</div>";
return $html;
}
/**
* Normalize parameters for field
*
* @param array $field
*
* @return array
*/
static function normalize_field( $field )
{
$field['multiple'] = false;
return $field;
}
/**
* Output the field value
* Display options in format Label: value in unordered list
*
* @param array $field Field parameters
* @param array $args Additional arguments. Not used for these fields.
* @param int|null $post_id Post ID. null for current post. Optional.
*
* @return mixed Field value
*/
static function the_value( $field, $args = array(), $post_id = null )
{
$value = self::get_value( $field, $args, $post_id );
if ( ! $value )
return '';
$output = '<table>';
$output .= '<thead><tr>';
foreach ( $field['options'] as $label )
{
$output .= "<th>$label</th>";
}
$output .= '</tr></thead><tbody>';
foreach ( $value as $subvalue )
{
$output .= '<tr>';
foreach ( $subvalue as $value )
{
$output .= "<td>$value</td>";
}
$output .= '</tr>';
}
$output .= '</tbody></table>';
return $output;
}
}
}