Overview

Namespaces

  • None
  • Quform
    • Traduttore_Registry

Classes

  • Quform
  • Quform_Admin_InsertForm
  • Quform_Admin_Page
  • Quform_Admin_Page_Controller
  • Quform_Admin_Page_Dashboard
  • Quform_Admin_Page_Entries
  • Quform_Admin_Page_Entries_Edit
  • Quform_Admin_Page_Entries_List
  • Quform_Admin_Page_Entries_View
  • Quform_Admin_Page_Factory
  • Quform_Admin_Page_Forms_Add
  • Quform_Admin_Page_Forms_Edit
  • Quform_Admin_Page_Forms_List
  • Quform_Admin_Page_Help
  • Quform_Admin_Page_Preview
  • Quform_Admin_Page_Settings
  • Quform_Admin_Page_Tools
  • Quform_Admin_Page_Tools_ExportEntries
  • Quform_Admin_Page_Tools_ExportForm
  • Quform_Admin_Page_Tools_Home
  • Quform_Admin_Page_Tools_ImportForm
  • Quform_Admin_Page_Tools_Migrate
  • Quform_Admin_Page_Tools_Uninstall
  • Quform_Api
  • Quform_Block
  • Quform_Builder
  • Quform_Captcha
  • Quform_ClassLoader
  • Quform_Confirmation
  • Quform_Container
  • Quform_Dashboard_Widget
  • Quform_Dispatcher
  • Quform_Element
  • Quform_Element_Captcha
  • Quform_Element_Checkbox
  • Quform_Element_Column
  • Quform_Element_Container
  • Quform_Element_Container_Iterator
  • Quform_Element_Date
  • Quform_Element_Email
  • Quform_Element_Factory
  • Quform_Element_Field
  • Quform_Element_File
  • Quform_Element_Group
  • Quform_Element_Hidden
  • Quform_Element_Honeypot
  • Quform_Element_Html
  • Quform_Element_Multi
  • Quform_Element_Multiselect
  • Quform_Element_Name
  • Quform_Element_Page
  • Quform_Element_Password
  • Quform_Element_Radio
  • Quform_Element_Recaptcha
  • Quform_Element_Row
  • Quform_Element_Select
  • Quform_Element_Submit
  • Quform_Element_Text
  • Quform_Element_Textarea
  • Quform_Element_Time
  • Quform_Entry_Controller
  • Quform_Entry_Exporter
  • Quform_Entry_List_Settings
  • Quform_Entry_List_Table
  • Quform_Entry_Processor
  • Quform_Entry_UserSearcher
  • Quform_Filter_Abstract
  • Quform_Filter_Alpha
  • Quform_Filter_AlphaNumeric
  • Quform_Filter_Digits
  • Quform_Filter_Regex
  • Quform_Filter_Static
  • Quform_Filter_StripTags
  • Quform_Filter_Trim
  • Quform_Form
  • Quform_Form_Controller
  • Quform_Form_Exporter
  • Quform_Form_Factory
  • Quform_Form_Importer
  • Quform_Form_Iterator
  • Quform_Form_List_Settings
  • Quform_Form_List_Table
  • Quform_Form_Processor
  • Quform_License
  • Quform_Migrator
  • Quform_NonceRefresher
  • Quform_Notification
  • Quform_Notification_Resender
  • Quform_Options
  • Quform_Permissions
  • Quform_Repository
  • Quform_ScriptLoader
  • Quform_Session
  • Quform_Settings
  • Quform_Shortcode
  • Quform_Themes
  • Quform_TokenReplacer
  • Quform_Toolbar
  • Quform_Translations
  • Quform_Updater
  • Quform_Upgrader
  • Quform_Uploader
  • Quform_Validator_Abstract
  • Quform_Validator_Alpha
  • Quform_Validator_AlphaNumeric
  • Quform_Validator_Array
  • Quform_Validator_Captcha
  • Quform_Validator_Date
  • Quform_Validator_Digits
  • Quform_Validator_Duplicate
  • Quform_Validator_Email
  • Quform_Validator_FileUpload
  • Quform_Validator_GreaterThan
  • Quform_Validator_Honeypot
  • Quform_Validator_Identical
  • Quform_Validator_InArray
  • Quform_Validator_Length
  • Quform_Validator_LessThan
  • Quform_Validator_Recaptcha
  • Quform_Validator_Regex
  • Quform_Validator_Required
  • Quform_Validator_Static
  • Quform_Validator_Time
  • Quform_View
  • Quform_ViewFactory
  • Quform_Widget_Form
  • Quform_Widget_Popup

Interfaces

  • Quform_Attachable
  • Quform_Element_Editable
  • Quform_Filter_Interface
  • Quform_Validator_Interface

Constants

  • Quform\Traduttore_Registry\TRANSIENT_KEY_PLUGIN
  • Quform\Traduttore_Registry\TRANSIENT_KEY_THEME

Functions

  • Quform\Traduttore_Registry\add_project
  • Quform\Traduttore_Registry\clean_translations_cache
  • Quform\Traduttore_Registry\get_available_locales
  • Quform\Traduttore_Registry\get_installed_translations
  • Quform\Traduttore_Registry\get_translations
  • Quform\Traduttore_Registry\register_clean_translations_cache
  • Quform\Traduttore_Registry\sanitize_date
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
  5:  */
  6: class Quform_Element_Date extends Quform_Element_Field implements Quform_Element_Editable
  7: {
  8:     /**
  9:      * Get the value formatted in HTML
 10:      *
 11:      * @return  string
 12:      */
 13:     public function getValueHtml()
 14:     {
 15:         $value = Quform::escape($this->getValueText());
 16: 
 17:         $value = apply_filters('quform_get_value_html_' . $this->getIdentifier(), $value, $this, $this->getForm());
 18: 
 19:         return $value;
 20:     }
 21: 
 22:     /**
 23:      * Get the value formatted in plain text
 24:      *
 25:      * @param   string  $separator
 26:      * @return  string
 27:      */
 28:     public function getValueText($separator = ', ')
 29:     {
 30:         $value = '';
 31: 
 32:         if ( ! $this->isEmpty()) {
 33:             try {
 34:                 $value = Quform::date(
 35:                     $this->config('dateFormat'),
 36:                     new DateTime($this->getValue(), new DateTimeZone('UTC')),
 37:                     new DateTimeZone('UTC')
 38:                 );
 39:             } catch (Exception $e) {
 40:                 // If there was an error creating the DateTime object, the value will be an empty string
 41:             }
 42:         }
 43: 
 44:         $value = apply_filters('quform_get_value_text_' . $this->getIdentifier(), $value, $this, $this->getForm());
 45: 
 46:         return $value;
 47:     }
 48: 
 49:     /**
 50:      * Is the given value valid for this element type
 51:      *
 52:      * @param   string  $value
 53:      * @return  bool
 54:      */
 55:     protected function isValidValue($value)
 56:     {
 57:         if ( ! is_string($value)) {
 58:             return false;
 59:         }
 60: 
 61:         if ($value == '9999-99-99') {
 62:             return false;
 63:         }
 64: 
 65:         return preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/', $value);
 66:     }
 67: 
 68:     /**
 69:      * Prepare the dynamic default value
 70:      *
 71:      * Supports a date string in the format YYYY-MM-DD
 72:      *
 73:      * @param   string  $value
 74:      * @return  string
 75:      */
 76:     public function prepareDynamicValue($value)
 77:     {
 78:         if (Quform::isNonEmptyString($value)) {
 79:             $parts = explode('-', $value);
 80: 
 81:             if (isset($parts[0], $parts[1], $parts[2])) {
 82:                 $year = (int) $parts[0];
 83:                 $month = (int) $parts[1];
 84:                 $day = (int) $parts[2];
 85: 
 86:                 if (checkdate($month, $day, $year)) {
 87:                     try {
 88:                         return Quform::date(
 89:                             'Y-m-d',
 90:                             new DateTime("$year-$month-$day", new DateTimeZone('UTC')),
 91:                             new DateTimeZone('UTC')
 92:                         );
 93:                     } catch (Exception $e) {
 94:                         // If there was an error creating the DateTime object, fall through to return the empty value
 95:                     }
 96:                 }
 97:             }
 98:         }
 99: 
100:         return $this->getEmptyValue();
101:     }
102: 
103:     /**
104:      * Get the HTML attributes for the field
105:      *
106:      * @param   array  $context
107:      * @return  array
108:      */
109:     protected function getFieldAttributes(array $context = array())
110:     {
111:         $attributes = array(
112:             'type' => 'text',
113:             'id' => $this->getUniqueId(),
114:             'name' => $this->getFullyQualifiedName(),
115:             'class' => Quform::sanitizeClass($this->getFieldClasses($context)),
116:             'placeholder' => 'YYYY-MM-DD',
117:             'data-options' => wp_json_encode($this->getDatepickerOptions())
118:         );
119: 
120:         if ( ! $this->isEmpty()) {
121:             $attributes['value'] = $this->getValue();
122:         }
123: 
124:         if ($this->config('readOnly')) {
125:             $attributes['readonly'] = true;
126:         }
127: 
128:         $attributes = apply_filters('quform_field_attributes', $attributes, $this, $this->form, $context);
129:         $attributes = apply_filters('quform_field_attributes_' . $this->getIdentifier(), $attributes, $this, $this->form, $context);
130: 
131:         return $attributes;
132:     }
133: 
134:     /**
135:      * Get the datepicker options for the field
136:      *
137:      * @return array
138:      */
139:     protected function getDatepickerOptions()
140:     {
141:         $options = array(
142:             'format' => $this->config('dateFormatJs'),
143:             'min' => $this->config('dateMin'),
144:             'max' => $this->config('dateMax'),
145:             'start' => $this->config('dateViewStart'),
146:             'depth' => $this->config('dateViewDepth'),
147:             'showFooter' => $this->config('dateShowFooter'),
148:             'locale' => $this->config('dateLocale'),
149:             'placeholder' => $this->config('placeholder'),
150:             'autoOpen' => $this->config('dateAutoOpen'),
151:             'identifier' => $this->getIdentifier()
152:         );
153: 
154:         return $options;
155:     }
156: 
157:     /**
158:      * Get the classes for the field
159:      *
160:      * @param   array  $context
161:      * @return  array
162:      */
163:     protected function getFieldClasses(array $context = array())
164:     {
165:         $classes = array(
166:             'quform-field',
167:             'quform-field-date',
168:             sprintf('quform-field-%s', $this->getIdentifier())
169:         );
170: 
171:         if ($this->form->config('tooltipsEnabled') && Quform::isNonEmptyString($this->config('tooltip')) && Quform::get($context, 'tooltipType') == 'field') {
172:             $classes[] = sprintf('quform-tooltip-%s', Quform::get($context, 'tooltipEvent'));
173:         }
174: 
175:         if (Quform::isNonEmptyString($this->config('customClass'))) {
176:             $classes[] = $this->config('customClass');
177:         }
178: 
179:         $classes = apply_filters('quform_field_classes', $classes, $this, $this->form, $context);
180:         $classes = apply_filters('quform_field_classes_' . $this->getIdentifier(), $classes, $this, $this->form, $context);
181: 
182:         return $classes;
183:     }
184: 
185:     /**
186:      * Get the HTML for the field
187:      *
188:      * @param   array   $context
189:      * @return  string
190:      */
191:     protected function getFieldHtml(array $context = array())
192:     {
193:         return Quform::getHtmlTag('input', $this->getFieldAttributes($context));
194:     }
195: 
196:     /**
197:      * Get the field HTML when editing
198:      *
199:      * @return string
200:      */
201:     public function getEditFieldHtml()
202:     {
203:         return $this->getFieldHtml();
204:     }
205: 
206:     /**
207:      * Render the CSS for this element
208:      *
209:      * @param   array   $context
210:      * @return  string
211:      */
212:     protected function renderCss(array $context = array())
213:     {
214:         $css = parent::renderCss($context);
215: 
216:         if ($context['fieldWidth'] == 'custom' && Quform::isNonEmptyString($context['fieldWidthCustom'])) {
217:             $css .= sprintf('.quform-input-date.quform-input-%s { width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
218:             $css .= sprintf('.quform-inner-%s > .quform-error > .quform-error-inner { float: left; min-width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
219:         }
220: 
221:         return $css;
222:     }
223: 
224:     /**
225:      * Get the list of CSS selectors
226:      *
227:      * @return array
228:      */
229:     protected function getCssSelectors()
230:     {
231:         return parent::getCssSelectors() + array(
232:             'datepickerHeader' => '%1$s-datepicker.quform-%2$s-datepicker.quform-datepicker .k-calendar .k-header, %1$s-datepicker.quform-%2$s-datepicker .k-calendar .k-header .k-state-hover',
233:             'datepickerHeaderText' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar .k-header .k-link',
234:             'datepickerHeaderTextHover' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar .k-header .k-link:hover',
235:             'datepickerFooter' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar .k-footer',
236:             'datepickerFooterText' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar .k-footer .k-link',
237:             'datepickerFooterTextHover' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar .k-footer .k-link:hover',
238:             'datepickerSelectionText' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar td.k-state-focused .k-link',
239:             'datepickerSelectionTextHover' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar td.k-state-focused .k-link:hover',
240:             'datepickerSelectionActiveText' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar td.k-state-selected.k-state-focused .k-link',
241:             'datepickerSelectionActiveTextHover' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar td.k-state-selected.k-state-focused .k-link:hover',
242:             'datepickerSelection' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar td.k-state-focused',
243:             'datepickerSelectionActive' => '%s-datepicker.quform-%s-datepicker.quform-datepicker .k-calendar td.k-state-selected.k-state-focused'
244:         );
245:     }
246: 
247:     /**
248:      * Does the given logic rule match the given value?
249:      *
250:      * @param   mixed  $value
251:      * @param   array  $rule
252:      * @return  bool
253:      */
254:     protected function isLogicValueMatch($value, array $rule)
255:     {
256:         if ($rule['operator'] == 'gt' || $rule['operator'] == 'lt') {
257:             if ( ! $this->isEmpty()) {
258:                 $result = Quform::compareDates($value, $rule['value']);
259: 
260:                 if ($result !== false) {
261:                     return $rule['operator'] == 'gt' ? $result === 1 : $result === -1;
262:                 }
263:             }
264: 
265:             return false;
266:         }
267: 
268:         return parent::isLogicValueMatch($value, $rule);
269:     }
270: 
271:     /**
272:      * Get the default element configuration
273:      *
274:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
275:      * @return  array
276:      */
277:     public static function getDefaultConfig($key = null)
278:     {
279:         $config = apply_filters('quform_default_config_date', array(
280:             // Basic
281:             'label' => __('Date', 'quform'),
282:             'description' => '',
283:             'descriptionAbove' => '',
284:             'required' => false,
285: 
286:             // Styles
287:             'labelIcon' => '',
288:             'fieldIconLeft' => '',
289:             'fieldIconRight' => 'qicon-calendar',
290:             'fieldSize' => 'inherit',
291:             'fieldWidth' => 'inherit',
292:             'fieldWidthCustom' => '',
293:             'customClass' => '',
294:             'customElementClass' => '',
295:             'styles' => array(),
296: 
297:             // Labels
298:             'placeholder' => '',
299:             'subLabel' => '',
300:             'subLabelAbove' => '',
301:             'adminLabel' => '',
302:             'tooltip' => '',
303:             'tooltipType' => 'inherit',
304:             'tooltipEvent' => 'inherit',
305:             'labelPosition' => 'inherit',
306:             'labelWidth' => '',
307: 
308:             // Logic
309:             'logicEnabled' => false,
310:             'logicAction' => true,
311:             'logicMatch' => 'all',
312:             'logicRules' => array(),
313: 
314:             // Data
315:             'defaultValue' => '',
316:             'dynamicDefaultValue' => false,
317:             'dynamicKey' => '',
318:             'dateMin' => '',
319:             'dateMax' => '',
320:             'dateViewStart' => 'month',
321:             'dateViewDepth' => 'month',
322:             'dateShowFooter' => false,
323:             'dateLocale' => '',
324:             'dateFormatJs' => '',
325:             'dateFormat' => '',
326:             'dateAutoOpen' => true,
327:             'readOnly' => false,
328:             'showInEmail' => true,
329:             'saveToDatabase' => true,
330: 
331:             // Advanced
332:             'visibility' => '',
333:             'validators' => array(),
334: 
335:             // Translation
336:             'messageRequired' => '',
337:             'messageDateInvalidDate' => '',
338:             'messageDateTooEarly' => '',
339:             'messageDateTooLate' => ''
340:         ));
341: 
342:         $config['type'] = 'date';
343: 
344:         if (Quform::isNonEmptyString($key)) {
345:             return Quform::get($config, $key);
346:         }
347: 
348:         return $config;
349:     }
350: }
351: 
API documentation generated by ApiGen