PluginProbe
CoolClock / 4.3.6
CoolClock v4.3.6
4.3.9 4.3.8 trunk 0.1 2.0 2.9.8 3.0 3.1 3.2 3.3 4.0 4.1 4.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7
coolclock / includes / class-coolclock-widget.php

class-coolclock-widget.php in CoolClock 4.3.6, at includes/class-coolclock-widget.php

277 lines 13.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CoolClock Widget Class
4 */
5
6 class CoolClock_Widget extends WP_Widget {
7
8 /** PHP5+ constructor */
9 public function __construct()
10 {
11 parent::__construct(
12 'coolclock-widget',
13 __('Analog Clock', 'coolclock'),
14 array(
15 'classname' => 'coolclock',
16 'description' => __('Add an analog clock to your sidebar.', 'coolclock')
17 ),
18 array(
19 'width' => 300,
20 'id_base' => 'coolclock-widget'
21 )
22 );
23 }
24
25 /** @see WP_Widget::widget -- do not rename this */
26 public function widget( $args, $instance )
27 {
28 extract( $args );
29
30 $defaults = array_merge( array('title'=>'','custom_skin'=>''), CoolClock::$defaults, CoolClock::$advanced_defaults );
31
32 // backward compat
33 if ( isset($instance['digitalcolor']) && !isset($instance['fontcolor']) ) $instance['fontcolor'] = $instance['digitalcolor'];
34
35 $title = !empty($instance['title']) ? apply_filters( 'widget_title', $instance['title'] ) : '';
36 //$number = $this->number;
37
38 // set footer script flags
39 CoolClock::$add_script = true;
40
41 // Print output
42 echo $before_widget;
43
44 if ( $title )
45 echo $before_title . $title . $after_title;
46
47 // set skin
48 $instance['skin'] = CoolClock::parse_skin(
49 ! empty( $instance['skin'] ) ? $instance['skin'] : $defaults['skin'],
50 ! empty( $instance['custom_skin'] ) ? $instance['custom_skin'] : ''
51 );
52
53 // radius, used in wrapper style and coolclock fields
54 $instance['radius'] = !empty( $instance['radius'] ) && is_numeric( $instance['radius'] ) ? (int) $instance['radius'] : $defaults['radius'];
55 if ( 10 > $instance['radius'] ) $instance['radius'] = 10; // absolute minimum size 20x20
56
57 $align = !empty( $instance['align'] ) ? $instance['align'] : $defaults['align'];
58 $styles = array(
59 'width' => 2 * $instance['radius'] . 'px',
60 'height' => 'auto',
61 );
62 if ( in_array( $align, array('left','center') ) ) {
63 $styles['margin-right'] = 'auto';
64 if ( 'left' == $align ) $styles['margin-left'] = '0';
65 }
66 if ( in_array( $align, array('right','center') ) ) {
67 $styles['margin-left'] = 'auto';
68 if ( 'right' == $align ) $styles['margin-right'] = '0';
69 }
70 $styles = apply_filters( 'coolclock_container_styles', $styles, $instance, $defaults );
71
72 // Build output
73 // begin wrapper
74 $output = '<div class="coolclock-container"' . CoolClock::inline_style( $styles ) . '>';
75 // add canvas
76 $output .= CoolClock::canvas( $instance );
77 // end wrapper
78 $output .= '</div>';
79
80 // Print filtered output
81 echo apply_filters( 'coolclock_widget', $output, $args, $instance );
82
83 echo $after_widget;
84 }
85
86 /** @see WP_Widget::update -- do not rename this */
87 public function update( $new_instance, $old_instance )
88 {
89 // parse custom skin code
90 $skin_array = !empty($new_instance['custom_skin']) ? CoolClock::skin_array( wp_strip_all_tags( $new_instance['custom_skin'] ) ) : array();
91
92 $instance['title'] = !empty($new_instance['title']) ? wp_strip_all_tags( $new_instance['title'] ) : '';
93 $instance['skin'] = !empty($new_instance['skin']) ? wp_strip_all_tags( $new_instance['skin'] ) : '';
94 $instance['custom_skin'] = !empty($skin_array) ? wp_json_encode( $skin_array ) : '';
95 $instance['radius'] = ( empty($new_instance['radius']) || (int) $new_instance['radius'] < 5 ) ? 5 : (int) $new_instance['radius'];
96 $instance['noseconds'] = !empty($new_instance['noseconds']) ? '1' : '';
97 $instance['gmtoffset'] = isset($new_instance['gmtoffset']) && $new_instance['gmtoffset'] !== '' ? (float) $new_instance['gmtoffset'] : '';
98 $instance['showdigital'] = !empty($new_instance['showdigital']) ? wp_strip_all_tags( $new_instance['showdigital'] ) : '';
99 $instance['fontcolor'] = !empty($new_instance['fontcolor']) ? CoolClock::colorval( $new_instance['fontcolor'] ) : '';
100 $instance['scale'] = !empty($new_instance['scale']) ? wp_strip_all_tags( $new_instance['scale'] ) : '';
101 $instance['align'] = !empty($new_instance['align']) ? wp_strip_all_tags( $new_instance['align'] ) : '';
102 $instance['subtext'] = wp_kses( $new_instance['subtext'], CoolClock::$allowed_tags );
103
104 return apply_filters( 'coolclock_widget_update_advanced', $instance, $new_instance );
105 }
106
107 /** @see WP_Widget::form -- do not rename this */
108 public function form( $instance )
109 {
110 $output = '';
111 $advanced = '';
112
113 // backward compat
114 if ( isset($instance['digitalcolor']) && !isset($instance['fontcolor']) ) $instance['fontcolor'] = $instance['digitalcolor'];
115
116 $defaults = array_merge( array('title'=>'','custom_skin'=>''), CoolClock::$defaults, CoolClock::$advanced_defaults );
117
118 $instance = wp_parse_args( (array) $instance, $defaults );
119
120 $title = esc_attr( $instance['title'] );
121 $subtext = esc_attr( $instance['subtext'] );
122 $custom_skin = esc_attr( $instance['custom_skin'] );
123
124 // Translatable skin names go here
125 $skin_names = array (
126 'swissrail' => __('Swiss Rail','coolclock'),
127 'chunkyswiss' => __('Chunky Swiss','coolclock'),
128 'chunkyswissonblack' => __('Chunky Swiss White','coolclock'),
129 'fancy' => __('Fancy','coolclock'),
130 'machine' => __('Machine','coolclock'),
131 'simonbaird_com' => __('SimonBaird.com','coolclock'),
132 'classic' => __('Classic by Bonstio','coolclock'),
133 'modern' => __('Modern by Bonstio','coolclock'),
134 'simple' => __('Simple by Bonstio','coolclock'),
135 'securephp' => __('SecurePHP','coolclock'),
136 'tes2' => __('Tes2','coolclock'),
137 'lev' => __('Lev','coolclock'),
138 'sand' => __('Sand','coolclock'),
139 'sun' => __('Sun','coolclock'),
140 'tor' => __('Tor','coolclock'),
141 'cold' => __('Cold','coolclock'),
142 'babosa' => __('Babosa','coolclock'),
143 'tumb' => __('Tumb','coolclock'),
144 'stone' => __('Stone','coolclock'),
145 'disc' => __('Disc','coolclock'),
146 'watermelon' => __('Watermelon by Yoo Nhe','coolclock'),
147 'mister' => __('Mister by Carl Lister','coolclock'),
148 'minimal' => __('Minimal','coolclock')
149 );
150
151 // Translatable type names go here
152 $type_names = array (
153 'linear' => __('Linear','coolclock'),
154 'logclock' => __('Logarithmic','coolclock'),
155 'logclockrev' => __('Logarithmic reversed','coolclock')
156 );
157
158 // Translatable show digital options go here
159 $showdigital_names = array (
160 '' => translate('No'),
161 'digital12' => __('time (am/pm)','coolclock'),
162 'digital24' => __('time (24h)','coolclock'),
163 'date' => __('date','coolclock'),
164 'digital12+' => __('time + seconds (am/pm)','coolclock'),
165 'digital24+' => __('time + seconds (24h)','coolclock'),
166 'text' => __('custom text','coolclock')
167 );
168
169 // Misc translations
170 $stray = array(
171 'extra_settings' => __('Extra settings for the CoolClock widget.', 'coolclock')
172 );
173
174 // Title
175 $output .= '<style type="text/css">#available-widgets [class*=clock] .widget-title:before{content:"\f469"}</style>
176 <p><label for="' . $this->get_field_id('title') . '">' . __('Title:') . '</label> ';
177 $output .= '<input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></p>';
178
179 // Clock settings
180 $output .= '<p><strong>' . __('Clock', 'coolclock') . '</strong></p>';
181 $output .= '<p><a href="https://premium.status301.com/coolclock-widget-settings/" target="_blank">' . __('CoolClock widget instructions &raquo;', 'coolclock') . '</a></p>';
182
183 $output .= '<p><label for="' . $this->get_field_id('skin') . '">' . __('Skin:', 'coolclock') . '</label> ';
184 $output .= '<select class="select" id="' . $this->get_field_id('skin') . '" name="' . $this->get_field_name('skin') . '">';
185 $output .= '<option value="' . $defaults['skin'] . '" ' . selected( $defaults['skin'], $instance['skin'], false ) . '>';
186 $output .= ( isset($skin_names[$defaults['skin']]) ) ? $skin_names[$defaults['skin']] : $defaults['skin'];
187 $output .= '</option>';
188 foreach ( CoolClock::get_all_skins() as $skin => $parms ) {
189 $output .= '<option value="' . $skin . '" ' . selected( $skin, $instance['skin'], false ) . '>';
190 $output .= ( isset($skin_names[$skin]) ) ? $skin_names[$skin] : $skin;
191 $output .= '</option>';
192 }
193 $output .= '<option value="custom_' . $this->number . '" ' . selected( 'custom_'.$this->number, $instance['skin'], false ) . '>';
194 $output .= __('Custom (define below)', 'coolclock') . '</option></select></p>';
195
196 // Custom skin field
197 $output .= '<p><label for="' . $this->get_field_id('custom_skin') . '">' . __('Custom skin parameters:', 'coolclock') . '</label> ';
198 $output .= '<textarea class="widefat" id="' . $this->get_field_id('custom_skin') . '" name="' . $this->get_field_name('custom_skin') . '">' . $custom_skin . '</textarea> ';
199 $output .= '<em>' . sprintf( __('(set Skin to Custom above, then add %s here)', 'coolclock'), '<a href="https://premium.status301.com/coolclock-custom-skin/" target="_blank">' . __('parameters in JSON format', 'coolclock') . '</a>' ) . '</em></p>';
200
201 // Radius
202 $output .= '<p><label for="' . $this->get_field_id('radius') . '">' . __('Radius:', 'coolclock') . '</label> ';
203 $output .= '<input class="small-text" id="' . $this->get_field_id('radius') . '" name="' . $this->get_field_name('radius') . '" type="number" min="10" value="' . $instance['radius'] . '" /></p>';
204
205 // Second hand
206 $output .= '<p><input id="' . $this->get_field_id('noseconds') . '" name="' . $this->get_field_name('noseconds') . '" type="checkbox" value=';
207 $output .= ( $instance['noseconds'] ) ? '"true" checked="checked" />' : '"false" />';
208 $output .= ' <label for="' . $this->get_field_id('noseconds') . '">' . __('Hide second hand', 'coolclock') . '</label></p>';
209
210 // Align
211 $output .= '<p><label for="' . $this->get_field_id('align') . '">' . __('Align:', 'coolclock') . '</label> ';
212 $output .= '<select class="select" id="' . $this->get_field_id('align') . '" name="' . $this->get_field_name('align') . '">';
213 $output .= '<option value="">';
214 $output .= translate('none') . '</option>';
215 $output .= '<option value="left" ' . selected( $instance['align'], 'left', false ) . '>';
216 $output .= __('left', 'coolclock') . '</option>';
217 $output .= '<option value="right" ' . selected( $instance['align'], 'right', false ) . '>';
218 $output .= __('right', 'coolclock') . '</option>';
219 $output .= '<option value="center" ' . selected( $instance['align'], 'center', false ) . '>';
220 $output .= __('center', 'coolclock') . '</option>';
221 $output .= '</select></p>';
222
223 // Subtext
224 $output .= '<p><label for="' . $this->get_field_id('subtext') . '">' . __('Subtext:', 'coolclock') . '</label> ';
225 $output .= '<input class="widefat" id="' . $this->get_field_id('subtext') . '" name="' . $this->get_field_name('subtext') . '" type="text" value="' . $subtext . '" /> <em>' . __('(basic HTML allowed)', 'coolclock') . '</em></p>';
226
227 $output .= '<div class="coolclock-advanced" style="background-color:rgba(0,0,0,.03);padding:1px 7px;border-radius:5px;margin-bottom:10px">';
228
229 $output .= '<p><strong>' . translate('Advanced') . '</strong></p>';
230
231 // Use GMT offset
232 $output .= '<p><label for="' . $this->get_field_id('gmtoffset') . '">' . __('GMT offset:', 'coolclock') . '</label> ';
233 $output .= '<input class="small-text" id="' . $this->get_field_id('gmtoffset') . '" name="' . $this->get_field_name('gmtoffset') . '" type="number" step="0.5" value="' . $instance['gmtoffset'] . '" /> <em>' . __('(leave blank for visitor local time)', 'coolclock') . '</em></p>';
234
235 // Scale
236 $output .= '<p><label for="' . $this->get_field_id('scale') . '">' . __('Scale:', 'coolclock') . '</label> ';
237 $output .= '<select class="select" id="' . $this->get_field_id('scale') . '" name="' . $this->get_field_name('scale') . '">';
238 foreach ( CoolClock::$clock_types as $key => $value ) {
239 $output .= '<option value="' . $key . '" ' . selected( $key, strtolower($instance['scale']), false ) . '>';
240 $output .= ( isset($type_names[$key]) ) ? $type_names[$key] : $value;
241 $output .= '</option>';
242 }
243 $output .= '</select></p>';
244
245 // Show digital
246 if ( $instance['showdigital'] == 'true' || $instance['showdigital'] == '1' )
247 $instance['showdigital'] = 'digital12'; // backward compat
248
249 $output .= '<p><label for="' . $this->get_field_id('showdigital') . '">' . __('Show digital:', 'coolclock') . '</label> ';
250 $output .= '<select class="select" id="' . $this->get_field_id('showdigital') . '" name="' . $this->get_field_name('showdigital') . '">';
251 foreach ( CoolClock::$showdigital_options as $key => $value ) {
252 $output .= '<option value="' . $key . '" ' . selected( $key, $instance['showdigital'], false ) . '>';
253 $output .= ( isset($showdigital_names[$key]) ) ? $showdigital_names[$key] : $value;
254 $output .= '</option>';
255 }
256 $output .= '</select></p>';
257
258 $output .= '<p><label for="' . $this->get_field_id('fontcolor') . '">' . __('Digital font color:', 'coolclock') . '</label> ';
259 $output .= '<input id="' . $this->get_field_id('fontcolor') . '" name="' . $this->get_field_name('fontcolor') . '" type="text" value="' . $instance['fontcolor'] . '" /> <em>' . __('(use a valid HTML color code or name)', 'coolclock') . '</em></p>';
260
261 $advanced .= '<p><a href="https://premium.status301.com/downloads/coolclock-advanced/">' . __('More digital font options &raquo;', 'coolclock') . '</a></p>
262 <p><strong>' . __('Background') . '</strong></p><p><a href="https://premium.status301.com/downloads/coolclock-advanced/">' . __('Available in the Advanced extension &raquo;', 'coolclock') . '</a></p>';
263
264 // Advanced filter
265 $output .= apply_filters( 'coolclock_widget_form_advanced', $advanced, $this, $instance, $defaults );
266
267 $output .= '</div>';
268
269 if ( class_exists( 'CoolClockAdvanced' ) && isset(CoolClockAdvanced::$plugin_version) && version_compare( CoolClockAdvanced::$plugin_version, '7.1', '<' ) ) { // add an upgrade notice
270 $output .= '<div class="update-nag"><strong>' . __('Please upgrade the CoolClock - Advanced extension.', 'coolclock') . '</strong> '. ' <a href="https://premium.status301.com/account/" target="_blank">' . __('Please log in with your account credentials here.', 'coolclock') . '</a>' . __('You can download the new version using the link in the downloads list.', 'coolclock') . '</div>';
271 }
272
273 echo $output;
274 }
275
276 }
277