C:\xampp\htdocs\landing\wp-content\plugins\penci-framework\lib\meta-box\inc\fields\datetime.php


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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
/**
 * The date and time picker field which allows users to select both date and time via jQueryUI datetime picker.
 *
 * @package Meta Box
 */

/**
 * Datetime field class.
 */
class RWMB_Datetime_Field extends RWMB_Text_Field {
    
/**
     * Translate date format from jQuery UI date picker to PHP date().
     * It's used to store timestamp value of the field.
     * Missing:  '!' => '', 'oo' => '', '@' => '', "''" => "'".
     *
     * @var array
     */
    
protected static $date_formats = array(
        
'd'  => 'j',
        
'dd' => 'd',
        
'oo' => 'z',
        
'D'  => 'D',
        
'DD' => 'l',
        
'm'  => 'n',
        
'mm' => 'm',
        
'M'  => 'M',
        
'MM' => 'F',
        
'y'  => 'y',
        
'yy' => 'Y',
        
'o'  => 'z',
    );

    
/**
     * Translate time format from jQuery UI time picker to PHP date().
     * It's used to store timestamp value of the field.
     * Missing: 't' => '', T' => '', 'm' => '', 's' => ''.
     *
     * @var array
     */
    
protected static $time_formats = array(
        
'H'  => 'G',
        
'HH' => 'H',
        
'h'  => 'g',
        
'hh' => 'h',
        
'mm' => 'i',
        
'ss' => 's',
        
'l'  => 'u',
        
'tt' => 'a',
        
'TT' => 'A',
    );

    
/**
     * Register scripts and styles.
     */
    
public static function admin_register_scripts() {
        
$url RWMB_CSS_URL 'jqueryui';
        
wp_register_style'jquery-ui-core'"$url/jquery.ui.core.css", array(), '1.8.17' );
        
wp_register_style'jquery-ui-theme'"$url/jquery.ui.theme.css", array(), '1.8.17' );
        
wp_register_style'jquery-ui-datepicker'"$url/jquery.ui.datepicker.css", array( 'jquery-ui-core''jquery-ui-theme' ), '1.8.17' );
        
wp_register_style'rwmb-date'RWMB_CSS_URL 'datepicker.css', array( 'jquery-ui-datepicker' ), '1.8.17' );

        
wp_register_style'jquery-ui-slider'"$url/jquery.ui.slider.css", array( 'jquery-ui-core''jquery-ui-theme' ), '1.8.17' );
        
wp_register_style'jquery-ui-timepicker'"$url/jquery-ui-timepicker-addon.min.css", array( 'rwmb-date''jquery-ui-slider' ), '1.5.0' );

        
$url RWMB_JS_URL 'jqueryui';
        
wp_register_script'jquery-ui-timepicker'"$url/jquery-ui-timepicker-addon.min.js", array( 'jquery-ui-datepicker''jquery-ui-slider' ), '1.5.0'true );
        
wp_register_script'jquery-ui-timepicker-i18n'"$url/jquery-ui-timepicker-addon-i18n.min.js", array( 'jquery-ui-timepicker' ), '1.5.0'true );

        
wp_register_script'rwmb-datetime'RWMB_JS_URL 'datetime.js', array( 'jquery-ui-datepicker''jquery-ui-timepicker-i18n' ), RWMB_VERtrue );
        
wp_register_script'rwmb-date'RWMB_JS_URL 'date.js', array( 'jquery-ui-datepicker' ), RWMB_VERtrue );
        
wp_register_script'rwmb-time'RWMB_JS_URL 'time.js', array( 'jquery-ui-timepicker-i18n' ), RWMB_VERtrue );

        
$handles      = array( 'datetime''time' );
        
$locale       str_replace'_''-'get_locale() );
        
$locale_short substr$locale0);
        
$data         = array(
            
'locale'      => $locale,
            
'localeShort' => $locale_short,
        );
        foreach ( 
$handles as $handle ) {
            
self::localize_script"rwmb-$handle"'RWMB_' ucfirst$handle ), $data );
        }
    }

    
/**
     * Enqueue scripts and styles.
     */
    
public static function admin_enqueue_scripts() {
        
self::admin_register_scripts();
        
wp_enqueue_style'jquery-ui-timepicker' );
        
wp_enqueue_script'rwmb-datetime' );
    }

    
/**
     * Get field HTML.
     *
     * @param mixed $meta  The field meta value.
     * @param array $field The field parameters.
     *
     * @return string
     */
    
public static function html$meta$field ) {
        
$output '';

        if ( 
$field['timestamp'] ) {
            
$name  $field['field_name'];
            
$field wp_parse_args( array(
                
'field_name' => $name '[formatted]',
            ), 
$field );
            
$output .= sprintf(
                
'<input type="hidden" name="%s" class="rwmb-datetime-timestamp" value="%s">',
                
esc_attr$name '[timestamp]' ),
                isset( 
$meta['timestamp'] ) ? intval$meta['timestamp'] ) : ''
            
);
            
$meta = isset( $meta['formatted'] ) ? $meta['formatted'] : '';
        }

        
$output .= parent::html$meta$field );

        if ( 
$field['inline'] ) {
            
$output .= '<div class="rwmb-datetime-inline"></div>';
        }

        return 
$output;
    }

    
/**
     * Calculates the timestamp from the datetime string and returns it if $field['timestamp'] is set or the datetime string if not.
     *
     * @param mixed $new     The submitted meta value.
     * @param mixed $old     The existing meta value.
     * @param int   $post_id The post ID.
     * @param array $field   The field parameters.
     *
     * @return string|int
     */
    
public static function value$new$old$post_id$field ) {
        return 
$field['timestamp'] ? $new['timestamp'] : $new;
    }

    
/**
     * Get meta value.
     *
     * @param int   $post_id The post ID.
     * @param bool  $saved   Whether the meta box is saved at least once.
     * @param array $field   The field parameters.
     *
     * @return mixed
     */
    
public static function meta$post_id$saved$field ) {
        
$meta parent::meta$post_id$saved$field );
        if ( 
$field['timestamp'] ) {
            
$meta self::prepare_meta$meta$field );
        }
        return 
$meta;
    }

    
/**
     * Format meta value if set 'timestamp'.
     *
     * @param array|string $meta  The meta value.
     * @param array        $field Field parameters.
     * @return array
     */
    
protected static function prepare_meta$meta$field ) {
        if ( 
is_array$meta ) ) {
            foreach ( 
$meta as $key => $value ) {
                
$meta$key ] = self::prepare_meta$value$field );
            }
            return 
$meta;
        }
        return array(
            
'timestamp' => $meta $meta null,
            
'formatted' => $meta dateself::call'translate_format'$field ), intval$meta ) ) : '',
        );
    }

    
/**
     * Normalize parameters for field.
     *
     * @param array $field The field parameters.
     * @return array
     */
    
public static function normalize$field ) {
        
$field wp_parse_args$field, array(
            
'timestamp'  => false,
            
'inline'     => false,
            
'js_options' => array(),
        ) );

        
// Deprecate 'format', but keep it for backward compatible.
        // Use 'js_options' instead.
        
$field['js_options'] = wp_parse_args$field['js_options'], array(
            
'timeFormat'      => 'HH:mm',
            
'separator'       => ' ',
            
'dateFormat'      => empty( $field['format'] ) ? 'yy-mm-dd' $field['format'],
            
'showButtonPanel' => true,
        ) );

        if ( 
$field['inline'] ) {
            
$field['js_options'] = wp_parse_args$field['js_options'], array(
                
'altFieldTimeOnly' => false,
            ) );
        }

        
$field parent::normalize$field );

        return 
$field;
    }

    
/**
     * Get the attributes for a field.
     *
     * @param array $field The field parameters.
     * @param mixed $value The meta value.
     *
     * @return array
     */
    
public static function get_attributes$field$value null ) {
        
$attributes parent::get_attributes$field$value );
        
$attributes wp_parse_args$attributes, array(
            
'data-options' => wp_json_encode$field['js_options'] ),
        ) );
        
$attributes['type'] = 'text';

        return 
$attributes;
    }

    
/**
     * Returns a date() compatible format string from the JavaScript format.
     *
     * @link http://www.php.net/manual/en/function.date.php
     * @param array $field The field parameters.
     *
     * @return string
     */
    
public static function translate_format$field ) {
        return 
strtr$field['js_options']['dateFormat'], self::$date_formats )
        . 
$field['js_options']['separator']
        . 
strtr$field['js_options']['timeFormat'], self::$time_formats );
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586