PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.3.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.3.1
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
insert-php / libs / factory / forms / controls / datepicker-range.php

datepicker-range.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.3.1, at libs/factory/forms/controls/datepicker-range.php

106 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Datepicker range control
5 *
6 * @author Alex Kovalev <alex.kovalevv@gmail.com>
7 * @copyright (c) 2018, Webcraftic Ltd
8 *
9 * Example:
10 * 'type' => 'datetimepicker-range',
11 * 'name' => 'facebook_start_date_filter',
12 * 'range_1' => array(
13 * 'format' => 'YYYY/MM/DD HH:mm',
14 * 'default' => date('Y/m/d H:i', strtotime('-1 week'))
15 * ),
16 * 'range_2' => array(
17 * 'format' => 'YYYY/MM/DD HH:mm',
18 * 'default' => date('Y/m/d H:i')
19 * ),
20 * 'title' => __('Выберите период', 'wpcr-scrapes'),
21 * 'hint' => __('Если Вкл., вы сможете установить настройки выбора записей за установленный период времени.', 'wpcr-scrapes')
22 *
23 * @package factory-forms
24 * @since 1.0.0
25 */
26
27 // Exit if accessed directly
28 if( !defined('ABSPATH') ) {
29 exit;
30 }
31
32 if( !class_exists('Wbcr_FactoryForms420_DatepickerRangeControl') ) {
33
34 class Wbcr_FactoryForms420_DatepickerRangeControl extends Wbcr_FactoryForms420_ComplexControl {
35
36 public $type = 'datetimepicker-range';
37
38 public function __construct($options, $form, $provider = null)
39 {
40 parent::__construct($options, $form, $provider);
41
42 if( !isset($options['range_1']) ) {
43 $options['range_1'] = array();
44 }
45
46 $options['range_1'] = array_merge(array(
47 'scope' => isset($options['scope'])
48 ? $options['scope']
49 : 'factory',
50 'name' => $this->options['name'] . '__range_1',
51 'format' => 'YYYY/MM/DD HH:mm',
52 'default' => date('Y/m/d H:i')
53 ), $options['range_1']);
54
55 if( !isset($options['range_2']) ) {
56 $options['range_2'] = array();
57 }
58
59 $options['range_2'] = array_merge(array(
60 'scope' => isset($options['scope'])
61 ? $options['scope']
62 : 'factory',
63 'name' => $this->options['name'] . '__range_2',
64 'format' => 'YYYY/MM/DD HH:mm',
65 'default' => date('Y/m/d H:i', strtotime("+1 month"))
66 ), $options['range_2']);
67
68 $this->range_1 = new Wbcr_FactoryForms420_TextboxControl($options['range_1'], $form, $provider);
69 $this->range_2 = new Wbcr_FactoryForms420_TextboxControl($options['range_2'], $form, $provider);
70 $this->inner_controls = array($this->range_1, $this->range_2);
71
72 foreach($this->inner_controls as $key => $control) {
73 $control->addCssClass('factory-datetimepicker-range-' . $key);
74 $control->addHtmlAttr('data-date-show-today-button', 'true');
75 $control->addHtmlAttr('data-date-show-clear', 'true');
76
77 $format = $control->getOption('format');
78
79 if( !empty($format) ) {
80 //'YYYY/MM/DD HH:mm'
81 $control->addHtmlAttr('data-date-format', $format);
82 }
83
84 $locale_parts = explode('_', get_locale());
85
86 $locale = isset($locale_parts[0])
87 ? $locale_parts[0]
88 : 'en';
89
90 $control->addHtmlAttr('data-date-locale', $locale);
91 }
92 }
93
94 public function render()
95 {
96 ?>
97 <div class='input-group date factory-datetimepicker-input-group' style="display:inline-block; width: 200px">
98 <?php $this->range_1->render(); ?>
99 </div>
100 <div class='input-group date factory-datetimepicker-input-group' style="display:inline-block; width: 200px">
101 <?php $this->range_2->render(); ?>
102 </div>
103 <?php
104 }
105 }
106 }