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_Time 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('timeFormat'),
 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 == '99:99') {
 62:             return false;
 63:         }
 64: 
 65:         return preg_match('/^([0-9]{2}):([0-9]{2})$/', $value);
 66:     }
 67: 
 68:     /**
 69:      * Prepare the dynamic default value
 70:      *
 71:      * Supports a time string in the format HH:MM
 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])) {
 82:                 $hour = (int) $parts[0];
 83:                 $minute = (int) $parts[1];
 84: 
 85:                 if ($hour >= 0 && $hour <= 23 && $minute >= 0 && $minute <= 59) {
 86:                     try {
 87:                         return Quform::date(
 88:                             'H:i',
 89:                             new DateTime("$hour:$minute", new DateTimeZone('UTC')),
 90:                             new DateTimeZone('UTC')
 91:                         );
 92:                     } catch (Exception $e) {
 93:                         // If there was an error creating the DateTime object, fall through to return the empty value
 94:                     }
 95:                 }
 96:             }
 97:         }
 98: 
 99:         return $this->getEmptyValue();
100:     }
101: 
102:     /**
103:      * Get the HTML attributes for the field
104:      *
105:      * @param   array  $context
106:      * @return  array
107:      */
108:     protected function getFieldAttributes(array $context = array())
109:     {
110:         $attributes = array(
111:             'type' => 'text',
112:             'id' => $this->getUniqueId(),
113:             'name' => $this->getFullyQualifiedName(),
114:             'class' => Quform::sanitizeClass($this->getFieldClasses($context)),
115:             'placeholder' => 'HH:MM',
116:             'data-options' => wp_json_encode($this->getTimepickerOptions())
117:         );
118: 
119:         if ( ! $this->isEmpty()) {
120:             $attributes['value'] = $this->getValue();
121:         }
122: 
123:         if ($this->config('readOnly')) {
124:             $attributes['readonly'] = true;
125:         }
126: 
127:         $attributes = apply_filters('quform_field_attributes', $attributes, $this, $this->form, $context);
128:         $attributes = apply_filters('quform_field_attributes_' . $this->getIdentifier(), $attributes, $this, $this->form, $context);
129: 
130:         return $attributes;
131:     }
132: 
133:     /**
134:      * Get the timepicker options for the field
135:      *
136:      * @return array
137:      */
138:     protected function getTimepickerOptions()
139:     {
140:         $options = array(
141:             'min' => $this->config('timeMin'),
142:             'max' => $this->config('timeMax'),
143:             'interval' => $this->config('timeInterval'),
144:             'locale' => $this->config('timeLocale'),
145:             'format' => $this->config('timeFormatJs'),
146:             'placeholder' => $this->config('placeholder'),
147:             'autoOpen' => $this->config('timeAutoOpen'),
148:             'identifier' => $this->getIdentifier()
149:         );
150: 
151:         return $options;
152:     }
153: 
154:     /**
155:      * Get the classes for the field
156:      *
157:      * @param   array  $context
158:      * @return  array
159:      */
160:     protected function getFieldClasses(array $context = array())
161:     {
162:         $classes = array(
163:             'quform-field',
164:             'quform-field-time',
165:             sprintf('quform-field-%s', $this->getIdentifier())
166:         );
167: 
168:         if ($this->form->config('tooltipsEnabled') && Quform::isNonEmptyString($this->config('tooltip')) && Quform::get($context, 'tooltipType') == 'field') {
169:             $classes[] = sprintf('quform-tooltip-%s', Quform::get($context, 'tooltipEvent'));
170:         }
171: 
172:         if (Quform::isNonEmptyString($this->config('customClass'))) {
173:             $classes[] = $this->config('customClass');
174:         }
175: 
176:         $classes = apply_filters('quform_field_classes', $classes, $this, $this->form, $context);
177:         $classes = apply_filters('quform_field_classes_' . $this->getIdentifier(), $classes, $this, $this->form, $context);
178: 
179:         return $classes;
180:     }
181: 
182:     /**
183:      * Get the HTML for the field
184:      *
185:      * @param   array   $context
186:      * @return  string
187:      */
188:     protected function getFieldHtml(array $context = array())
189:     {
190:         return Quform::getHtmlTag('input', $this->getFieldAttributes($context));
191:     }
192: 
193:     /**
194:      * Get the field HTML when editing
195:      *
196:      * @return string
197:      */
198:     public function getEditFieldHtml()
199:     {
200:         return $this->getFieldHtml();
201:     }
202: 
203:     /**
204:      * Render the CSS for this element
205:      *
206:      * @param   array   $context
207:      * @return  string
208:      */
209:     protected function renderCss(array $context = array())
210:     {
211:         $css = parent::renderCss($context);
212: 
213:         if ($context['fieldWidth'] == 'custom' && Quform::isNonEmptyString($context['fieldWidthCustom'])) {
214:             $css .= sprintf('.quform-input-time.quform-input-%s { width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
215:             $css .= sprintf('.quform-inner-%s > .quform-error > .quform-error-inner { float: left; min-width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
216:         }
217: 
218:         return $css;
219:     }
220: 
221:     /**
222:      * Does the given logic rule match the given value?
223:      *
224:      * @param   mixed  $value
225:      * @param   array  $rule
226:      * @return  bool
227:      */
228:     protected function isLogicValueMatch($value, array $rule)
229:     {
230:         if ($rule['operator'] == 'gt' || $rule['operator'] == 'lt') {
231:             if ( ! $this->isEmpty()) {
232:                 $result = Quform::compareDates($value, $rule['value']);
233: 
234:                 if ($result !== false) {
235:                     return $rule['operator'] == 'gt' ? $result === 1 : $result === -1;
236:                 }
237:             }
238: 
239:             return false;
240:         }
241: 
242:         return parent::isLogicValueMatch($value, $rule);
243:     }
244: 
245:     /**
246:      * Get the default element configuration
247:      *
248:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
249:      * @return  array
250:      */
251:     public static function getDefaultConfig($key = null)
252:     {
253:         $config = apply_filters('quform_default_config_time', array(
254:             // Basic
255:             'label' => __('Time', 'quform'),
256:             'description' => '',
257:             'descriptionAbove' => '',
258:             'required' => false,
259: 
260:             // Styles
261:             'labelIcon' => '',
262:             'fieldIconLeft' => '',
263:             'fieldIconRight' => 'qicon-schedule',
264:             'fieldSize' => 'inherit',
265:             'fieldWidth' => 'inherit',
266:             'fieldWidthCustom' => '',
267:             'customClass' => '',
268:             'customElementClass' => '',
269:             'styles' => array(),
270: 
271:             // Labels
272:             'placeholder' => '',
273:             'subLabel' => '',
274:             'subLabelAbove' => '',
275:             'adminLabel' => '',
276:             'tooltip' => '',
277:             'tooltipType' => 'inherit',
278:             'tooltipEvent' => 'inherit',
279:             'labelPosition' => 'inherit',
280:             'labelWidth' => '',
281: 
282:             // Logic
283:             'logicEnabled' => false,
284:             'logicAction' => true,
285:             'logicMatch' => 'all',
286:             'logicRules' => array(),
287: 
288:             // Data
289:             'defaultValue' => '',
290:             'dynamicDefaultValue' => false,
291:             'dynamicKey' => '',
292:             'timeMin' => '',
293:             'timeMax' => '',
294:             'timeInterval' => '',
295:             'timeLocale' => '',
296:             'timeFormatJs' => '',
297:             'timeFormat' => '',
298:             'timeAutoOpen' => true,
299:             'readOnly' => false,
300:             'showInEmail' => true,
301:             'saveToDatabase' => true,
302: 
303:             // Advanced
304:             'visibility' => '',
305:             'validators' => array(),
306: 
307:             // Translations
308:             'messageRequired' => '',
309:             'messageTimeInvalidTime' => '',
310:             'messageTimeTooEarly' => '',
311:             'messageTimeTooLate' => ''
312:         ));
313: 
314:         $config['type'] = 'time';
315: 
316:         if (Quform::isNonEmptyString($key)) {
317:             return Quform::get($config, $key);
318:         }
319: 
320:         return $config;
321:     }
322: }
323: 
API documentation generated by ApiGen