/** * Filters each field. * * Uses 'wpcf_field' hook. Filters field settings. * * @param type $field * @return int */ function filter_field($field) { if ($field['type'] == 'date') { if (!fields_date_timestamp_neg_supported()) { if (!isset($field['data']['validate']) || !is_array($field['data']['validate'])) { $field['data']['validate'] = array(); } $field['data']['validate']['negativeTimestamp'] = array('active' => 1, 'value' => 'true', 'message' => wpcf_admin_validation_messages('negativeTimestamp')); } } return $field; }
/** * Renders inline JS. * TODO this seems DEPRECATED and not used anymore, need to check (although I do not know where) */ function wpcf_fields_date_meta_box_js_inline() { $date_format = wpcf_get_date_format(); $date_format = _wpcf_date_convert_wp_to_js($date_format); $date_format_note = '<span style="margin-left:10px"><i>' . esc_js(sprintf(__('Input format: %s', 'wpcf'), wpcf_get_date_format_text())) . '</i></span>'; $year_range = fields_date_timestamp_neg_supported() ? '1902:2037' : '1970:2037'; ?> <script type="text/javascript"> //<![CDATA[ jQuery(document).ready(function(){ wpcfFieldsDateInit(''); }); function wpcfFieldsDateInit(div) { if (jQuery.isFunction(jQuery.fn.datepicker)) { jQuery(div+' .wpcf-datepicker').each(function(index) { if (!jQuery(this).is(':disabled') && !jQuery(this).hasClass('hasDatepicker')) { jQuery(this).datepicker({ showOn: "button", buttonImage: "<?php echo WPCF_EMBEDDED_RES_RELPATH; ?> /images/calendar.gif", buttonImageOnly: true, buttonText: "<?php _e('Select date', 'wpcf'); ?> ", dateFormat: "<?php echo $date_format; ?> ", altFormat: "<?php echo $date_format; ?> ", changeMonth: true, changeYear: true, yearRange: "<?php echo $year_range; ?> ", onSelect: function(dateText, inst) { jQuery(this).trigger('wpcfDateBlur'); } }); jQuery(this).next().after('<?php echo $date_format_note; ?> '); // Wrap in CSS Scope jQuery("#ui-datepicker-div").each(function(){ if (!jQuery(this).hasClass('wpcf-jquery-ui-wrapped')) { jQuery(this).wrap('<div class="wpcf-jquery-ui" />') .addClass('wpcf-jquery-ui-wrapped'); } }); } }); } } //]]> </script> <?php }
public static function negativeTimestamp($args, $value) { if (!fields_date_timestamp_neg_supported() && intval($value) < 0) { return array('error' => 1); } return true; }
/** * Checks if timestamp is numeric and within range. * * @param type $timestamp * @return type */ function wpcf_fields_date_timestamp_is_valid($timestamp) { /* * http://php.net/manual/en/function.strtotime.php * The valid range of a timestamp is typically * from Fri, 13 Dec 1901 20:45:54 UTC * to Tue, 19 Jan 2038 03:14:07 UTC. * (These are the dates that correspond to the minimum * and maximum values for a 32-bit signed integer.) * Additionally, not all platforms support negative timestamps, * therefore your date range may be limited to no earlier than * the Unix epoch. * This means that e.g. dates prior to Jan 1, 1970 will not * work on Windows, some Linux distributions, * and a few other operating systems. * PHP 5.1.0 and newer versions overcome this limitation though. */ // MIN 'Jan 1, 1970' - 0 | Fri, 13 Dec 1901 20:45:54 UTC $_min_timestamp = fields_date_timestamp_neg_supported() ? -2147483646 : 0; // MAX 'Tue, 19 Jan 2038 03:14:07 UTC' - 2147483647 $_max_timestamp = 2147483647; return WPToolset_Field_Date_Scripts::_isTimestampInRange($timestamp); //return is_numeric( $timestamp ) && $_min_timestamp <= $timestamp && $timestamp <= $_max_timestamp; }
/** * From data for post edit page. * * @param type $field * @param type $data * @param type $field_object Field instance */ function wpcf_fields_date_meta_box_form($field, $field_object = null) { /* * Added extra fields 'hour' and 'minute'. * * If value is not array it is assumed that DB entry is timestamp() * and data is converted to array. */ $value = $field['value'] = wpcf_fields_date_value_get_filter($field['value'], $field_object); // TODO WPML Set disable_in_form or similar to true, use hook for WPML if (wpcf_wpml_field_is_copied($field)) { $attributes = array('style' => 'width:150px;'); } else { $attributes = array('class' => 'wpcf-datepicker', 'style' => 'width:150px;'); } /* * * Do not forget to trigger datepicker script * Only trigger on AJAX call (inserting new) */ $js_trigger = defined('DOING_AJAX') ? '<script type="text/javascript">wpcfFieldsDateInit(\'\');</script>' : ''; /* * * * Set Form */ $unique_id = wpcf_unique_id(serialize($field)); $form = array(); $form[$unique_id . '-datepicker'] = array('#type' => 'textfield', '#title' => ' ' . $field['name'], '#attributes' => $attributes, '#name' => 'wpcf[' . $field['slug'] . '][datepicker]', '#id' => 'wpcf-date-' . $field['slug'] . '-datepicker-' . $unique_id, '#value' => $value['datepicker'], '#after' => '' . $js_trigger, '#_validate_this' => true); // Add warning about supported timestamp if (!fields_date_timestamp_neg_supported()) { $_visible = !empty($value['datepicker']) && intval($value['timestamp']) < 0 ? '' : ' style="display:none;"'; $form[$unique_id . '-warning'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-error"' . $_visible . '><p>' . __('Please enter a date after 1 January 1970', 'wpcf') . '</p></div>'); } /* * * If set 'date_and_time' add time */ if (!empty($field['data']['date_and_time']) && $field['data']['date_and_time'] == 'and_time') { // Set parent CSS inline $form[$unique_id . '-datepicker']['#inline'] = true; $hours = 24; $minutes = 60; $options = array(); // Hour for ($index = 0; $index < $hours; $index++) { $prefix = $index < 10 ? '0' : ''; $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index); } $form[$unique_id . 'time_hour'] = array('#type' => 'select', '#title' => __('Hour', 'wpcf'), '#inline' => true, '#before' => '<br />', '#after' => ' ', '#options' => $options, '#default_value' => $value['hour'], '#name' => 'wpcf[' . $field['slug'] . '][hour]', '#id' => 'wpcf-date-' . $field['slug'] . '-select-hour-' . $unique_id, '#inline' => true); // Minutes for ($index = 1; $index < $minutes; $index++) { $prefix = $index < 10 ? '0' : ''; $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index); } $form[$unique_id . 'time_minute'] = array('#type' => 'select', '#title' => __('Minute', 'wpcf'), '#after' => '<br /><br />', '#inline' => true, '#options' => $options, '#default_value' => $value['minute'], '#name' => 'wpcf[' . $field['slug'] . '][minute]', '#id' => 'wpcf-date-' . $field['slug'] . '-minute-' . $unique_id); } return $form; }