PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.2
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.2
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / controls / group / format-date-time.php

format-date-time.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.2, at inc/controls/group/format-date-time.php

190 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Inc\Controls\Group;
4
5 use Elementor\Group_Control_Base;
6 use Elementor\Controls_Manager;
7
8
9 if (!defined('ABSPATH')) {
10 exit; // Exit if accessed directly
11 }
12
13
14 abstract class JLTMA_Format_Date_Time extends Group_Control_Base
15 {
16
17 protected function init_fields()
18 {
19 $fields = array();
20 $format_general = static::get_field_format_option();
21
22 $fields[static::get_name_field()] = array(
23 'label' => static::get_format_label(),
24 'type' => Controls_Manager::SELECT,
25 'options' => $this->get_format_options(),
26 );
27
28 $fields[static::get_name_field_custom()] = array(
29 'label' => static::get_custom_format_label(),
30 'type' => Controls_Manager::TEXT,
31 'description' => sprintf(
32 '%1$s: <a href="https://wordpress.org/support/article/formatting-date-and-time/" target="_blank">%2$s</a>',
33 __('Link', 'master-addons' ),
34 __('Documentation on date and time formatting', 'master-addons' )
35 ),
36 'default' => $format_general,
37 'placeholder' => $format_general,
38 'condition' => array(
39 static::get_name_field() => 'custom',
40 ),
41 );
42
43 return $fields;
44 }
45
46 protected function filter_fields()
47 {
48 $fields = parent::filter_fields();
49 $args = $this->get_args();
50
51 if (!empty($args['human_readable'])) {
52 $fields[static::get_name_field()]['options']['human_readable'] = __('Human Readable', 'master-addons' );
53 }
54
55 return $fields;
56 }
57
58 /**
59 * @since 1.0.0
60 * @since 1.0.1 Fixed PHP 5.6 support.
61 *
62 * @return string
63 */
64 public static function get_render_format($prefix, $settings, $timestamp)
65 {
66 $format = static::get_format($prefix, $settings);
67
68 if ('human_readable' === $format) {
69 return /* translators: %s: Human readable date/time. */ sprintf(__('%s ago', 'master-addons' ), human_time_diff($timestamp));
70 } else {
71 return gmdate($format, $timestamp);
72 }
73 }
74
75 protected function get_default_options()
76 {
77 return array(
78 'popover' => false,
79 );
80 }
81
82 protected function get_child_default_args()
83 {
84 return array(
85 'human_readable' => true,
86 );
87 }
88
89 private static function get_name_field()
90 {
91 return static::get_field_type() . '_format';
92 }
93
94 private static function get_name_field_custom()
95 {
96 return static::get_name_field() . '_custom';
97 }
98
99 /**
100 * @since 1.0.0
101 * @since 1.0.1 Fixed PHP 5.6 support.
102 *
103 * @return string
104 */
105 public static function get_format($prefix, $settings)
106 {
107 $format_name = $prefix . '_' . static::get_name_field();
108 $format_name_custom = $prefix . '_' . static::get_name_field_custom();
109 $format = Utils::get_if_isset($settings, $format_name);
110
111 if ($format && 'custom' === $format && isset($settings[$format_name_custom])) {
112 $format = $settings[$format_name_custom];
113 }
114
115 if (!$format) {
116 $format = static::get_field_format_option();
117 }
118
119 return $format;
120 }
121
122 protected static function get_format_options()
123 {
124 $format_general = static::get_field_format_option();
125 $formats_general = static::get_main_formats();
126
127 /* Translate Date Formats */
128 $format_i18n = array(
129 '' => __('Default', 'master-addons' ) . ' - ' . date_i18n($format_general),
130 );
131
132 foreach ($formats_general as $format) {
133 $format_i18n[$format] = date_i18n($format) . " ({$format})";
134 }
135
136 $format_i18n['custom'] = __('Custom', 'master-addons' );
137
138 return $format_i18n;
139 }
140
141 /**
142 * @return string
143 */
144 protected static function get_custom_format_label()
145 {
146 return __('Custom Format', 'master-addons' );
147 }
148
149 /**
150 * @since 1.0.0
151 * @since 1.0.1 Fixed PHP Strict Standards.
152 *
153 * @return string
154 */
155 protected static function get_field_type()
156 {
157 }
158
159 /**
160 * @since 1.0.0
161 * @since 1.0.1 Fixed PHP Strict Standards.
162 *
163 * @return string
164 */
165 protected static function get_format_label()
166 {
167 }
168
169 /**
170 * @since 1.0.0
171 * @since 1.0.1 Fixed PHP Strict Standards.
172 *
173 * @return array
174 */
175 protected static function get_main_formats()
176 {
177 return array();
178 }
179
180 /**
181 * @since 1.0.0
182 * @since 1.0.1 Fixed PHP Strict Standards.
183 *
184 * @return string
185 */
186 protected static function get_field_format_option()
187 {
188 }
189 }
190