| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uji Countdown Admin |
| 4 |
* |
| 5 |
* Handles all admin |
| 6 |
* |
| 7 |
* @author WPmanage |
| 8 |
* @category Admin |
| 9 |
* @package Uji-Countdown/Classes |
| 10 |
* @version 2.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
class Uji_Countdown_Admin { |
| 18 |
|
| 19 |
/** |
| 20 |
* Deferred admin messages. |
| 21 |
* |
| 22 |
* @since 2.3.4 |
| 23 |
* |
| 24 |
* @var array |
| 25 |
*/ |
| 26 |
private $ujic_admin_messages = array(); |
| 27 |
|
| 28 |
/** |
| 29 |
* Styles |
| 30 |
* |
| 31 |
* @since 2.1 |
| 32 |
* |
| 33 |
* @var string |
| 34 |
*/ |
| 35 |
public function ujic_styles() { |
| 36 |
return apply_filters( 'ujic_styles', array( 'classic' ) ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Init label vars |
| 41 |
* |
| 42 |
* @since 2.0 |
| 43 |
*/ |
| 44 |
public static function ujic_labels() { |
| 45 |
return array( |
| 46 |
'ujic_years' => 'Years', |
| 47 |
'ujic_year' => 'Year', |
| 48 |
'ujic_months' => 'Months', |
| 49 |
'ujic_month' => 'Month', |
| 50 |
'ujic_weeks' => 'Weeks', |
| 51 |
'ujic_week' => 'Week', |
| 52 |
'ujic_days' => 'Days', |
| 53 |
'ujic_day' => 'Day', |
| 54 |
'ujic_hours' => 'Hours', |
| 55 |
'ujic_hour' => 'Hour', |
| 56 |
'ujic_minutes' => 'Minutes', |
| 57 |
'ujic_minute' => 'Minute', |
| 58 |
'ujic_seconds' => 'Seconds', |
| 59 |
'ujic_second' => 'Second', |
| 60 |
); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Keep legacy Pro label sources visually aligned with the refreshed admin UI. |
| 65 |
* |
| 66 |
* @since 2.2 |
| 67 |
*/ |
| 68 |
public function ujic_admin_label_text( $translated, $text, $domain ) { |
| 69 |
if ( 'ujicountdown' !== $domain || ! is_admin() ) { |
| 70 |
return $translated; |
| 71 |
} |
| 72 |
|
| 73 |
$label_map = array( |
| 74 |
'Select Style' => 'Choose Style', |
| 75 |
'Select Style:' => 'Choose Style:', |
| 76 |
'Main format:' => 'Primary Units:', |
| 77 |
'Main Format:' => 'Primary Units:', |
| 78 |
'Secondary format:' => 'Additional Units:', |
| 79 |
'Secondary Format:' => 'Additional Units:', |
| 80 |
'Ring Progress' => 'Progress Fill', |
| 81 |
'Ring Progress:' => 'Progress Fill:', |
| 82 |
'Line Color' => 'Ring Colors', |
| 83 |
'Line Color:' => 'Ring Colors:', |
| 84 |
'Select Line Color:' => 'Ring Colors:', |
| 85 |
'Thickness' => 'Ring Thickness', |
| 86 |
'Thickness:' => 'Ring Thickness:', |
| 87 |
'Timer Size:' => 'Counter Size:', |
| 88 |
'Save Timer Style' => 'Save Style', |
| 89 |
); |
| 90 |
|
| 91 |
if ( isset( $label_map[ $text ] ) ) { |
| 92 |
return $label_map[ $text ]; |
| 93 |
} |
| 94 |
|
| 95 |
return $translated; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Print template of table counters. |
| 100 |
* |
| 101 |
* @since 2.0 |
| 102 |
*/ |
| 103 |
public function admin_tablelist() { |
| 104 |
$this->cform_delete(); |
| 105 |
|
| 106 |
if ( $this->saved_db_style() ) { |
| 107 |
global $wpdb; |
| 108 |
|
| 109 |
$style_count = absint( $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $this->ujic_tab_name() ) ); |
| 110 |
$count_label = sprintf( |
| 111 |
_n( '%s style', '%s styles', $style_count, 'ujicountdown' ), |
| 112 |
number_format_i18n( $style_count ) |
| 113 |
); |
| 114 |
|
| 115 |
$table_headers = ' |
| 116 |
<th class="manage-column" scope="col"><span>' . __( 'Created On', 'ujicountdown' ) . '</span></th> |
| 117 |
<th class="manage-column" scope="col"><span>' . __( 'Name', 'ujicountdown' ) . '</span></th> |
| 118 |
<th class="manage-column" scope="col"><span>' . __( 'Style', 'ujicountdown' ) . '</span></th> |
| 119 |
<th class="manage-column" scope="col"><span>' . __( 'Actions', 'ujicountdown' ) . '</span></th>'; |
| 120 |
|
| 121 |
echo '<div id="ujic_table" class="list ujic-list-card"> |
| 122 |
<div class="ujic-list-header"> |
| 123 |
<h2><span class="ujic-list-dot" aria-hidden="true"></span>' . esc_html__( 'Your Timer Styles', 'ujicountdown' ) . '</h2> |
| 124 |
<span class="ujic-list-count">' . esc_html( $count_label ) . '</span> |
| 125 |
</div> |
| 126 |
<div class="ujic-list-toolbar"> |
| 127 |
<a href="?page=ujicountdown&tab=tab_ujic_new" class="button button-primary ujic-list-primary"><i class="dashicons dashicons-plus ujic-list-button-icon" aria-hidden="true"></i>' . esc_html__( 'Create a New Timer Style', 'ujicountdown' ) . '</a> |
| 128 |
<a href="?page=ujicountdown&tab=tab_ujic_shortcode" class="button button-secondary ujic-list-secondary"><i class="dashicons dashicons-shortcode ujic-list-button-icon" aria-hidden="true"></i>' . esc_html__( 'Generate ShortCode', 'ujicountdown' ) . '</a> |
| 129 |
</div> |
| 130 |
<table cellspacing="0" class="widefat fixed ujic-list-table"> |
| 131 |
<thead> |
| 132 |
<tr> |
| 133 |
' . wp_kses_post( $table_headers ) . ' |
| 134 |
</tr> |
| 135 |
</thead> |
| 136 |
<tbody> |
| 137 |
' . $this->ujic_tabs_values() . ' |
| 138 |
</tbody> |
| 139 |
</table> |
| 140 |
</div>'; |
| 141 |
|
| 142 |
} else { |
| 143 |
$introLayout = '<div id="ujic_new"><h1>' . esc_html( ujic_plugin_name() . ' ' . ujic_plugin_version() ) . '</h1><h4>The most customizable countdown plugin for WordPress</h4>'; |
| 144 |
$introLayout .= '<a href="?page=ujicountdown&tab=tab_ujic_new" class="ujic_butnew" id="ujic_table_new">' . __( 'Add New Style', 'ujicountdown' ) . '</a>'; |
| 145 |
$introLayout .= '<div class="ujic_new_cnt"><h2>WHAT\'S NEW</h2>'; |
| 146 |
$introLayout .= '<ul> |
| 147 |
<li> |
| 148 |
<img alt="shortcode generator" src="' . esc_url( UJICOUNTDOWN_URL ) . 'assets/images/icon-sc.png"> |
| 149 |
<h3>Shortcode Generator</h3> |
| 150 |
<p>Quickly generate shortcode and copy/paste in your page or post.</p> |
| 151 |
<p>Compatibility with any theme</p> |
| 152 |
</li> |
| 153 |
<li> |
| 154 |
<img alt="wordpress" src="' . esc_url( UJICOUNTDOWN_URL ) . 'assets/images/icon-wp.png"> |
| 155 |
<h3>WordPress Block Editor</h3> |
| 156 |
<p>Fully supports WordPress Block Editor, while maintaining compatibility through Classic Editor</p> |
| 157 |
</li> |
| 158 |
<li> |
| 159 |
<img alt="recurring time" src="' . esc_url( UJICOUNTDOWN_URL ) . 'assets/images/icon-rec.png"> |
| 160 |
<h3>Recurring Timer</h3> |
| 161 |
<p>Introducing the recurring time option</p> |
| 162 |
<p>Reschedule the countdown timer after the event has ended</p> |
| 163 |
</li> |
| 164 |
<li> |
| 165 |
<img alt="email subscription" src="' . esc_url( UJICOUNTDOWN_URL ) . 'assets/images/icon-email.png"> |
| 166 |
<h3>Email Subscription Add-on</h3> |
| 167 |
<p>Visitors have now the option to subscribe using the email subscription form</p> |
| 168 |
<p>Create unlimited Campaigns</p> |
| 169 |
</li> |
| 170 |
<li> |
| 171 |
<img alt="responsive" src="' . esc_url( UJICOUNTDOWN_URL ) . 'assets/images/icon-mob.png"> |
| 172 |
<h3>Responsive (Pro Version)</h3> |
| 173 |
<p>Responsive to all formats. You can use it on your PC, Laptop, Mobile and Tablet</p> |
| 174 |
</li> |
| 175 |
<li> |
| 176 |
<img alt="more customization" src="' . esc_url( UJICOUNTDOWN_URL ) . 'assets/images/icon-custom.png"> |
| 177 |
<h3>More Customization</h3> |
| 178 |
<p>Option to enable/disable the units of the time</p> |
| 179 |
<p>Option to change the label color and size</p> |
| 180 |
</li> |
| 181 |
<li> |
| 182 |
<img alt="Multilanguage support" src="' . esc_url( UJICOUNTDOWN_URL ) . 'assets/images/icon-glob.png"> |
| 183 |
<h3>Multilanguage Support</h3> |
| 184 |
<p>This plugins come with translation capability. That means can be translated (aka localized) to other languages </p> |
| 185 |
<p>Quick translation for the units of time </p> |
| 186 |
</li> |
| 187 |
<li> |
| 188 |
<img alt="google fonts" src="' . esc_url( UJICOUNTDOWN_URL ) . 'assets/images/icon-font.png"> |
| 189 |
<h3>Google Fonts</h3> |
| 190 |
<p>Now support google fonts inclusion</p> |
| 191 |
</li> |
| 192 |
<li> |
| 193 |
<img alt="rtl support" src="' . esc_url( UJICOUNTDOWN_URL ) . 'assets/images/icon-rtl.png"> |
| 194 |
<h3>Right-To-Left (RTL)</h3> |
| 195 |
<p>Support "Left to Right" to Arabic "Right to Left" </p> |
| 196 |
</li> |
| 197 |
</ul>'; |
| 198 |
$introLayout .= '</div></div>'; |
| 199 |
|
| 200 |
echo $introLayout; |
| 201 |
} |
| 202 |
|
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* Shortcode generator. |
| 207 |
* |
| 208 |
* @since 2.1.3 |
| 209 |
*/ |
| 210 |
public function admin_shortcode() { |
| 211 |
// ID |
| 212 |
$cur_id = ( $this->cform_is_edit() ) ? $this->ujic_request_id( 'edit' ) : ''; |
| 213 |
|
| 214 |
// Get vars |
| 215 |
$vars = $this->ujic_option( $cur_id ); |
| 216 |
|
| 217 |
// Curent style |
| 218 |
$cur_style = ( $this->cform_is_edit() ) ? $vars['ujic_style'] : $this->ujic_request_text( 'style', 'classic' ); |
| 219 |
|
| 220 |
$saved_styles = ujic_styles_get( 'Select saved style' ); |
| 221 |
|
| 222 |
if ( empty( $saved_styles ) ) { |
| 223 |
$add_style_url = add_query_arg( |
| 224 |
array( |
| 225 |
'page' => 'ujicountdown', |
| 226 |
'tab' => 'tab_ujic_new', |
| 227 |
), |
| 228 |
admin_url( 'options-general.php' ) |
| 229 |
); |
| 230 |
|
| 231 |
$cnt = '<p>' . esc_html( __( 'Create a Counter Style before generating a shortcode.', 'ujicountdown' ) ) . '</p>'; |
| 232 |
$cnt .= '<p><a href="' . esc_url( $add_style_url ) . '" class="button button-primary">' . esc_html( __( 'Create Counter Style', 'ujicountdown' ) ) . '</a></p>'; |
| 233 |
|
| 234 |
echo $this->custom_metabox( __( 'Generate Shortcode', 'ujicountdown' ), $cnt, 'ujic-create' ); |
| 235 |
return; |
| 236 |
} |
| 237 |
|
| 238 |
$this->sc_metaboxes( $cur_style, $vars ); |
| 239 |
|
| 240 |
$cnt = '<form id="uji-shortcode">'; |
| 241 |
// Style |
| 242 |
$cnt .= $this->cform_select( __( 'Choose Style:', 'ujicountdown' ), 'ujic_style', $saved_styles, '' ); |
| 243 |
// Timer Type: |
| 244 |
$vars['ujic_type'] = array( 'onetime', 'repeat' ); |
| 245 |
$cnt .= $this->cform_radiobox( __( 'Timer Type:', 'ujicountdown' ), 'ujic_type', array( __( 'One Time Timer', 'ujicountdown' ), __( 'Repeating Timer', 'ujicountdown' ) ), $vars['ujic_type'], 'onetime' ); |
| 246 |
// Expiration Date and Time: |
| 247 |
$cnt .= $this->cform_date( __( 'Expiration Date:', 'ujicountdown' ), 'ujic_exp_date' ); |
| 248 |
// Expiration Date and Time select HH:MM |
| 249 |
$hh = ujic_datetime_get( 23 ); |
| 250 |
$mm = ujic_datetime_get( 59 ); |
| 251 |
$cnt .= $this->cform_select_time( __( 'Expiration Time:', 'ujicountdown' ), 'ujic_seltime', $hh, $mm ); |
| 252 |
// Repeat Every: |
| 253 |
$cnt .= $this->cform_time( __( 'Repeat Every:', 'ujicountdown' ), 'ujic_time' ); |
| 254 |
// After expire Hide |
| 255 |
$cnt .= $this->cform_checkbox( __( 'After expiration:', 'ujicountdown' ), array( 'ujic_exp_hide' ), array( 'Hide countdown' ), array( 'true' ) ); |
| 256 |
// Or go to URL |
| 257 |
$cnt .= $this->cform_input( __( 'Or go to the Link:', 'ujicountdown' ), 'ujic_url', '' ); |
| 258 |
// Recurring Time: |
| 259 |
$cnt .= $this->cform_reccur( __( 'Recurring Time:', 'ujicountdown' ), ujic_reclab_get(), __( 'leave it empty for unlimited', 'ujicountdown' ) ); |
| 260 |
// Subscription |
| 261 |
if ( defined( 'UJICSU_VERS' ) ) { |
| 262 |
$cnt .= $this->cform_input( __( 'Campaign Name:', 'ujicountdown' ), 'ujic_camp', '' ); |
| 263 |
} |
| 264 |
|
| 265 |
$cnt .= '<div class="ujic-shortcode-actions ujic-submit-hold"> |
| 266 |
<button type="button" class="button button-primary" id="uji-gen-shortcode"> |
| 267 |
Generate Shortcode |
| 268 |
</button> |
| 269 |
</div>'; |
| 270 |
|
| 271 |
$cnt .= '</form>'; |
| 272 |
|
| 273 |
echo $this->custom_metabox( __( 'Generate Shortcode', 'ujicountdown' ), $cnt, 'ujic-create' ); |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Print template new/edit countdown. |
| 278 |
* |
| 279 |
* @since 2.0 |
| 280 |
*/ |
| 281 |
public function admin_countdown() { |
| 282 |
// Save/Edit in database |
| 283 |
$this->cform_save_db(); |
| 284 |
|
| 285 |
// ID |
| 286 |
$cur_id = ( $this->cform_is_edit() ) ? $this->ujic_request_id( 'edit' ) : ''; |
| 287 |
|
| 288 |
// Get vars |
| 289 |
$vars = $this->ujic_option( $cur_id ); |
| 290 |
|
| 291 |
// Curent style |
| 292 |
$cur_style = ( $this->cform_is_edit() ) ? $vars['ujic_style'] : $this->ujic_request_text( 'style', 'classic' ); |
| 293 |
|
| 294 |
// Build Forms |
| 295 |
// $cnt = '<form method="post" action="page=ujicountdown&tab=tab_ujic_new&style=' . $cur_style . '&save=true">'; |
| 296 |
$cnt = $this->cform_ftype( $cur_style, $cur_id ); |
| 297 |
$cnt .= $this->cform_style( $cur_style ); |
| 298 |
$cnt .= '<input name="ujic_style" id="ujic-style" type="hidden" class="normal-text" value="' . esc_attr( $cur_style ) . '"/>'; |
| 299 |
$cnt .= $this->cform_input( __( 'Timer Title:', 'ujicountdown' ), 'ujic_name', $vars['ujic_name'] ); |
| 300 |
$cnt .= $this->cform_select( __( 'Google Font:', 'ujicountdown' ), 'ujic_goof', ujic_googlefonts(), $vars['ujic_goof'] ); |
| 301 |
$cnt .= $this->cform_radiobox( __( 'Alignment:', 'ujicountdown' ), 'ujic_pos', array( __( 'None', 'ujicountdown' ), __( 'Left', 'ujicountdown' ), __( 'Center', 'ujicountdown' ), __( 'Right', 'ujicountdown' ) ), array( 'none', 'left', 'center', 'right' ), $vars['ujic_pos'] ); |
| 302 |
$cnt .= $this->cform_checkbox( __( 'Primary Units:', 'ujicountdown' ), array( 'ujic_d', 'ujic_h', 'ujic_m', 'ujic_s' ), array( __( 'Days', 'ujicountdown' ), __( 'Hours', 'ujicountdown' ), __( 'Minutes', 'ujicountdown' ), __( 'Seconds', 'ujicountdown' ) ), array( $vars['ujic_d'], $vars['ujic_h'], $vars['ujic_m'], $vars['ujic_s'] ) ); |
| 303 |
$cnt .= $this->cform_checkbox( __( 'Additional Units:', 'ujicountdown' ), array( 'ujic_y', 'ujic_o', 'ujic_w' ), array( __( 'Years', 'ujicountdown' ), __( 'Months', 'ujicountdown' ), __( 'Weeks', 'ujicountdown' ) ), array( $vars['ujic_y'], $vars['ujic_o'], $vars['ujic_w'] ) ); |
| 304 |
|
| 305 |
// Filter for new options |
| 306 |
if ( has_filter( 'ujic_admin_add_circform' ) ) { |
| 307 |
$cnt .= apply_filters( 'ujic_admin_add_circform', $cnt, $vars, $cur_style ); |
| 308 |
} |
| 309 |
|
| 310 |
$cnt .= $this->cform_checkbox( __( 'Show Time Labels:', 'ujicountdown' ), array( 'ujic_txt' ), array( '' ), array( $vars['ujic_txt'] ) ); |
| 311 |
$cnt .= '<input type="hidden" name="ujic_ani" value="false">'; |
| 312 |
$cnt .= $this->cform_checkbox( __( 'Number Animation:', 'ujicountdown' ), array( 'ujic_ani' ), array( __( 'Animate number changes', 'ujicountdown' ) ), array( $vars['ujic_ani'] ) ); |
| 313 |
if ( $cur_style == 'classic' ) { |
| 314 |
$cnt .= $this->cform_sliderui( __( 'Counter Size:', 'ujicountdown' ), 'ujic_size', $vars['ujic_size'], 10, 80, 1 ); |
| 315 |
} |
| 316 |
if ( $cur_style == 'classic' ) { |
| 317 |
$cnt .= '<input type="hidden" name="ujic_no_box_color" value="false">'; |
| 318 |
$cnt .= $this->cform_checkbox( __( 'Disable Box Color:', 'ujicountdown' ), array( 'ujic_no_box_color' ), array( __( 'Transparent background', 'ujicountdown' ) ), array( $vars['ujic_no_box_color'] ) ); |
| 319 |
$cnt .= $this->cform_color( __( 'Select Box Color:', 'ujicountdown' ), array( 'ujic_col_dw', 'ujic_col_up' ), array( __( 'Bottom', 'ujicountdown' ), __( 'Up', 'ujicountdown' ) ), array( $vars['ujic_col_dw'], $vars['ujic_col_up'] ), 'ujic-box-color-setting' ); |
| 320 |
} |
| 321 |
if ( $cur_style == 'classic' ) { |
| 322 |
$cnt .= $this->cform_color( __( 'Text Color:', 'ujicountdown' ), array( 'ujic_col_txt', 'ujic_col_sw' ), array( __( 'Number Color', 'ujicountdown' ), __( 'Shadow Color', 'ujicountdown' ) ), array( $vars['ujic_col_txt'], $vars['ujic_col_sw'] ) ); |
| 323 |
$cnt .= '<input type="hidden" name="ujic_no_text_shadow" value="false">'; |
| 324 |
$cnt .= $this->cform_checkbox( __( 'Shadow Transparency:', 'ujicountdown' ), array( 'ujic_no_text_shadow' ), array( __( 'Transparent shadow', 'ujicountdown' ) ), array( $vars['ujic_no_text_shadow'] ) ); |
| 325 |
} |
| 326 |
|
| 327 |
$cnt .= $this->cform_color( __( 'Label Color:', 'ujicountdown' ), array( 'ujic_col_lab' ), array( __( 'Label Text Color', 'ujicountdown' ) ), array( $vars['ujic_col_lab'] ) ); |
| 328 |
$cnt .= $this->cform_sliderui( __( 'Label Size:', 'ujicountdown' ), 'ujic_lab_sz', $vars['ujic_lab_sz'], 8, 25, 1 ); |
| 329 |
|
| 330 |
// Newsletter form |
| 331 |
if ( has_filter( 'ujic_admin_add_form' ) ) { |
| 332 |
$cnt .= apply_filters( 'ujic_admin_add_form', $cnt, $vars ); |
| 333 |
} |
| 334 |
|
| 335 |
$cnt .= wp_nonce_field( 'ujic_secure', 'ujic_secure_form', true, false ); |
| 336 |
|
| 337 |
$cnt .= $this->cform_buttons(); |
| 338 |
|
| 339 |
$cnt .= '</form>'; |
| 340 |
|
| 341 |
// Preview Metaboxes |
| 342 |
$this->prev_metaboxes( $cur_style, $vars ); |
| 343 |
|
| 344 |
$style_message = $this->ujic_collect_messages(); |
| 345 |
if ( ! empty( $style_message ) ) { |
| 346 |
echo $style_message; |
| 347 |
} |
| 348 |
|
| 349 |
// Build Metabox |
| 350 |
|
| 351 |
if ( $cur_id ) { |
| 352 |
echo $this->custom_metabox( __( 'Edit Timer Style', 'ujicountdown' ), $cnt, 'ujic-create uji-fedit' ); |
| 353 |
} else { |
| 354 |
echo $this->custom_metabox( __( 'Create New Timer Style', 'ujicountdown' ), $cnt, 'ujic-create' ); |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
/** |
| 359 |
* Print checkbox field. |
| 360 |
* |
| 361 |
* @since 2.0 |
| 362 |
*/ |
| 363 |
public function cform_checkbox( $label, $names, $name_val, $val ) { |
| 364 |
$form = '<div class="ujic-box">'; |
| 365 |
$form .= '<div class="label">' . esc_html( $label ) . '</div>'; |
| 366 |
$form .= '<div class="ujic-chkbtn">'; |
| 367 |
$i = 0; |
| 368 |
foreach ( $names as $name ) { |
| 369 |
$form .= '<input id="' . esc_attr( $name ) . '" type="checkbox" value="true" class="icheckbox_flat-pink" name="' . esc_attr( $name ) . '" ' . checked( $val[ $i ], 'true', false ) . '>'; |
| 370 |
$form .= '<label for="' . esc_attr( $name ) . '">' . wp_kses_post ($name_val[ $i ]) . '</label>'; |
| 371 |
$i++; |
| 372 |
} |
| 373 |
$form .= '</div>'; |
| 374 |
$form .= '</div>'; |
| 375 |
|
| 376 |
return $form; |
| 377 |
} |
| 378 |
|
| 379 |
/** |
| 380 |
* Custom Metabox template. |
| 381 |
* |
| 382 |
* @since 2.0 |
| 383 |
*/ |
| 384 |
public function custom_metabox( $name, $cnt, $class = null, $toggle = false ) { |
| 385 |
$meta = '<div class="metabox-holder' . ( ( isset( $class ) && ! empty( $class ) ) ? ' ' . esc_attr( $class ) : '' ) . '"> |
| 386 |
<div class="postbox">'; |
| 387 |
|
| 388 |
$hndl = ''; |
| 389 |
if ( $toggle ) { |
| 390 |
$meta .= '<div class="handlediv" title="Click to toggle"></div>'; |
| 391 |
$hndl = ' class="hndle"'; |
| 392 |
} |
| 393 |
|
| 394 |
$meta .= '<h3' . esc_html( $hndl ) . '><span>' . esc_html( $name ) . '</span></h3> |
| 395 |
<div class="inside">'; |
| 396 |
$meta .= $cnt; |
| 397 |
$meta .= '</div></div></div>'; |
| 398 |
|
| 399 |
return $meta; |
| 400 |
} |
| 401 |
|
| 402 |
/** |
| 403 |
* Preview metaboxes. |
| 404 |
* |
| 405 |
* @since 2.0 |
| 406 |
*/ |
| 407 |
private function sc_metaboxes( $style, $countDownOptions ) { |
| 408 |
$sc = '<div class="ujic-shortcode"> |
| 409 |
<div id="ujic-scode">[ujicountdown]</div> |
| 410 |
<button type="button" class="ujibtn-sc-copy button button-secondary" data-clipboard-action="copy" data-clipboard-target="#ujic-scode" disabled="disabled"> |
| 411 |
Copy Shortcode |
| 412 |
</button> |
| 413 |
</div>'; |
| 414 |
|
| 415 |
if ( isset( $sc ) && ! empty( $sc ) ) { |
| 416 |
echo $this->custom_metabox( __( 'Shortcode', 'ujicountdown' ), $sc, 'ujic-create ujic-sc ujic-shortcode-preview', false ); |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
/** |
| 421 |
* Preview metaboxes. |
| 422 |
* |
| 423 |
* @since 2.0 |
| 424 |
*/ |
| 425 |
private function prev_metaboxes( $style, $countDownOptions ) { |
| 426 |
$prw = '<div class="ujic-' . $style . ' hasCountdown" id="ujiCountdown">'; |
| 427 |
$prw .= '<span class="countdown_row ujicf"> |
| 428 |
<span class="countdown_section ujic_y"> |
| 429 |
<span class="countdown_amount"><span class="ujic-number-value">0</span></span> |
| 430 |
<span class="countdown_amount"><span class="ujic-number-value">1</span></span> |
| 431 |
<span class="countdown_txt">' . __( 'Years', 'ujicountdown' ) . '</span> |
| 432 |
</span> |
| 433 |
<span class="countdown_section ujic_o"> |
| 434 |
<span class="countdown_amount"><span class="ujic-number-value">1</span></span> |
| 435 |
<span class="countdown_amount"><span class="ujic-number-value">1</span></span> |
| 436 |
<span class="countdown_txt">' . __( 'Months', 'ujicountdown' ) . '</span> |
| 437 |
</span> |
| 438 |
<span class="countdown_section ujic_w"> |
| 439 |
<span class="countdown_amount"><span class="ujic-number-value">0</span></span> |
| 440 |
<span class="countdown_amount"><span class="ujic-number-value">2</span></span> |
| 441 |
<span class="countdown_txt">' . __( 'Weeks', 'ujicountdown' ) . '</span> |
| 442 |
</span> |
| 443 |
<span class="countdown_section ujic_d"> |
| 444 |
<span class="countdown_amount"><span class="ujic-number-value">2</span></span> |
| 445 |
<span class="countdown_amount"><span class="ujic-number-value">9</span></span> |
| 446 |
<span class="countdown_txt">' . __( 'Days', 'ujicountdown' ) . '</span> |
| 447 |
</span> |
| 448 |
<span class="countdown_section ujic_h"> |
| 449 |
<span class="countdown_amount"><span class="ujic-number-value">0</span></span> |
| 450 |
<span class="countdown_amount"><span class="ujic-number-value">9</span></span> |
| 451 |
<span class="countdown_txt">' . __( 'Hours', 'ujicountdown' ) . '</span> |
| 452 |
</span> |
| 453 |
<span class="countdown_section ujic_m"> |
| 454 |
<span class="countdown_amount"><span class="ujic-number-value">3</span></span> |
| 455 |
<span class="countdown_amount"><span class="ujic-number-value">1</span></span> |
| 456 |
<span class="countdown_txt">' . __( 'Minutes', 'ujicountdown' ) . '</span> |
| 457 |
</span> |
| 458 |
<span class="countdown_section ujic_s"> |
| 459 |
<span class="countdown_amount"><span class="ujic-number-value">5</span></span> |
| 460 |
<span class="countdown_amount"><span class="ujic-number-value">3</span></span> |
| 461 |
<span class="countdown_txt">' . __( 'Seconds', 'ujicountdown' ) . '</span> |
| 462 |
</span> |
| 463 |
</span>'; |
| 464 |
|
| 465 |
if ( has_filter( 'ujic_admin_add_prw' ) ) { |
| 466 |
$prw .= apply_filters( 'ujic_admin_add_prw', $countDownOptions ); |
| 467 |
} |
| 468 |
|
| 469 |
$prw .= '</div>'; |
| 470 |
|
| 471 |
if ( has_filter( 'ujic_admin_add_preview' ) ) { |
| 472 |
$prw = apply_filters( 'ujic_admin_add_preview', $countDownOptions, $prw, $style ); |
| 473 |
} |
| 474 |
if ( isset( $prw ) && ! empty( $prw ) ) { |
| 475 |
echo $this->custom_metabox( __( 'Preview Timer Style', 'ujicountdown' ), $prw, 'ujic-preview', true ); |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* Print form style. |
| 481 |
* |
| 482 |
* @since 2.0 |
| 483 |
*/ |
| 484 |
public function cform_style( $val ) { |
| 485 |
$styles = $this->ujic_styles(); |
| 486 |
$form = '<div class="ujic-box ujic-style-box">'; |
| 487 |
if ( $this->cform_is_edit() ) { |
| 488 |
$form .= '<div class="label">' . __( 'Style Type:', 'ujicountdown' ) . '</div>'; |
| 489 |
$form .= '<div class="ujic-style-options">'; |
| 490 |
$form .= '<span id="ujic-style-' . esc_attr( $val ) . '" class="ujic-types ujic-types-sel">' . esc_attr( $val ) . '</span>'; |
| 491 |
} else { |
| 492 |
$form .= '<div class="label">' . __( 'Choose Style:', 'ujicountdown' ) . '</div>'; |
| 493 |
$form .= '<div class="ujic-style-options">'; |
| 494 |
foreach ( $styles as $style ) { |
| 495 |
$sel = ( $style == $this->ujic_request_text( 'style', 'classic' ) ) ? ' ujic-types-sel' : ''; |
| 496 |
$form .= '<a href="#" onclick="sel_style(\'' . esc_attr( $style ) . '\')" id="ujic-style-' . esc_attr( $style ) . '" class="ujic-types' . esc_attr( $sel ) . '">' . esc_attr( $style ) . '</a>'; |
| 497 |
} |
| 498 |
} |
| 499 |
$form .= '<input name="ujic_style" id="ujic-style" type="hidden" class="normal-text" value="' . esc_attr( $val ) . '"/>'; |
| 500 |
$form .= '</div>'; |
| 501 |
$form .= '</div>'; |
| 502 |
return $form; |
| 503 |
} |
| 504 |
|
| 505 |
/** |
| 506 |
* Print title. |
| 507 |
* |
| 508 |
* @since 2.0 |
| 509 |
*/ |
| 510 |
public function cform_title( $title ) { |
| 511 |
$form = '<div class="ujic-box">'; |
| 512 |
$form .= '<h3 style="padding-left: 0">' . esc_html( $title ) . '</h3>'; |
| 513 |
$form .= '</div>'; |
| 514 |
return $form; |
| 515 |
} |
| 516 |
|
| 517 |
/** |
| 518 |
* Print input field. |
| 519 |
* |
| 520 |
* @since 2.0 |
| 521 |
*/ |
| 522 |
public function cform_input( $label, $name, $val, $cls = null ) { |
| 523 |
$form = '<div class="ujic-box">'; |
| 524 |
$form .= '<div class="label">' . esc_html( $label ) . '</div>'; |
| 525 |
|
| 526 |
$form .= '<input type="text" value="' . esc_attr( $val ) . '" name="' . esc_attr( $name ) . '" id="' . esc_attr( $name ) . '" class="' . ( $cls ? esc_attr( $cls ) : 'regular-text' ) . '">'; |
| 527 |
$form .= '</div>'; |
| 528 |
return $form; |
| 529 |
} |
| 530 |
|
| 531 |
/** |
| 532 |
* Print radio field. |
| 533 |
* |
| 534 |
* @since 2.0 |
| 535 |
*/ |
| 536 |
public function cform_radiobox( $label, $name, $name_val, $types, $val ) { |
| 537 |
$form = '<div class="ujic-box">'; |
| 538 |
$form .= '<div class="label">' . esc_html( $label ) . '</div>'; |
| 539 |
$form .= '<div class="ujic-radbtn">'; |
| 540 |
$i = 0; |
| 541 |
foreach ( $types as $type ) { |
| 542 |
$form .= '<input id="ujic-' . esc_attr( $type ) . '" type="radio" value="' . esc_attr( $type ) . '" class="iradio_flat-pink" name="' . esc_attr( $name ) . '" ' . checked( $val, $type, false ) . '>'; |
| 543 |
$form .= '<label for="ujic-' . esc_attr( $type ) . '" id="img-' . esc_attr( $type ) . '">' . esc_html( $name_val[ $i ] ) . '</label>'; |
| 544 |
$i++; |
| 545 |
} |
| 546 |
$form .= '</div>'; |
| 547 |
$form .= '</div>'; |
| 548 |
return $form; |
| 549 |
} |
| 550 |
|
| 551 |
/** |
| 552 |
* Print select field. |
| 553 |
* |
| 554 |
* @since 2.0 |
| 555 |
*/ |
| 556 |
public function cform_select( $label, $name, $types, $val ) { |
| 557 |
$form = '<div class="ujic-box">'; |
| 558 |
$form .= '<div class="label">' . esc_html( $label ) . '</div>'; |
| 559 |
$form .= '<div class="ujic-select">'; |
| 560 |
$form .= '<select class="select of-input" name="' . esc_attr( $name ) . '" id="' . esc_attr( $name ) . '">'; |
| 561 |
foreach ( $types as $type => $option ) { |
| 562 |
$form .= '<option id="' . esc_attr( $type ) . '" value="' . esc_attr( $type ) . '" ' . selected( $type, $val, false ) . ' />' . esc_html( $option ) . '</option>'; |
| 563 |
} |
| 564 |
$form .= '</select></div>'; |
| 565 |
$form .= '</div>'; |
| 566 |
return $form; |
| 567 |
} |
| 568 |
|
| 569 |
/** |
| 570 |
* MM and SS. |
| 571 |
* |
| 572 |
* @since 2.1.3 |
| 573 |
*/ |
| 574 |
public function cform_select_time( $label, $cls, $hh, $mm ) { |
| 575 |
$form = '<div class="ujic-box ' . esc_attr( $cls ) . '">'; |
| 576 |
$form .= '<div class="label">' . esc_html( $label ) . '</div>'; |
| 577 |
$form .= '<div class="ujic-select ujic-time-selects">'; |
| 578 |
$form .= '<select class="select of-input" name="ujic_hh" id="ujic_hh">'; |
| 579 |
foreach ( $hh as $time ) { |
| 580 |
$form .= '<option value="' . esc_attr( $time['value'] ) . '" />' . esc_attr( $time['text'] ) . '</option>'; |
| 581 |
} |
| 582 |
$form .= '</select><span class="ujic-time-separator">:</span>'; |
| 583 |
|
| 584 |
$form .= '<select class="select of-input" name="ujic_mm" id="ujic_mm">'; |
| 585 |
foreach ( $mm as $time ) { |
| 586 |
$form .= '<option value="' . esc_attr( $time['value'] ) . '" />' . esc_html( $time['text'] ) . '</option>'; |
| 587 |
} |
| 588 |
$form .= '</select>'; |
| 589 |
|
| 590 |
$form .= '</div></div>'; |
| 591 |
return $form; |
| 592 |
} |
| 593 |
|
| 594 |
/** |
| 595 |
* Recurring time |
| 596 |
* |
| 597 |
* @since 2.1.3 |
| 598 |
*/ |
| 599 |
public function cform_reccur( $label, $timelabel, $info ) { |
| 600 |
$form = '<div class="ujic-box ujic-recurring"> |
| 601 |
<div class="label">' . esc_html( $label ) . '</div>'; |
| 602 |
$form .= '<div class="ujic-select ujic-recurring-controls"><input type="text" value="" name="ujic_rec_every" id="ujic_rec_every" class="small-text">'; |
| 603 |
$form .= ' <select class="select of-input" name="ujic_rec_time" id="ujic_rec_time">'; |
| 604 |
foreach ( $timelabel as $time ) { |
| 605 |
$form .= '<option value="' . esc_attr( $time['value'] ) . '" />' . esc_html( $time['text'] ) . '</option>'; |
| 606 |
} |
| 607 |
$form .= '</select></div>'; |
| 608 |
$form .= '<div class="ujic-block-box ujic-recurring-repeat"><input type="text" value="" name="ujic_rec_repeat" id="ujic_rec_repeat" class="small-text"> <span>' . esc_html( $info ) . '</span></div>'; |
| 609 |
$form .= '</div>'; |
| 610 |
return $form; |
| 611 |
} |
| 612 |
|
| 613 |
/** |
| 614 |
* Print slider-ui field. |
| 615 |
* |
| 616 |
* @since 2.0 |
| 617 |
*/ |
| 618 |
public function cform_sliderui( $label, $name, $val, $min, $max, $step ) { |
| 619 |
$form = '<div class="ujic-box ujic_slider">'; |
| 620 |
$form .= '<div class="label">' . esc_html( $label ) . '</div>'; |
| 621 |
// values |
| 622 |
$val = ( $val == '' ) ? 32 : esc_attr( $val ); |
| 623 |
// html output |
| 624 |
$form .= '<div class="ujic-slider-control">'; |
| 625 |
$form .= '<input type="text" name="' . esc_attr( $name ) . '" id="' . esc_attr( $name ) . '" value="' . esc_attr( $val ) . '" class="mini" readonly="readonly" />'; |
| 626 |
$form .= '<div id="' . esc_attr( $name ) . '-slider" class="ujic_sliderui" data-id="' . esc_attr( $name ) . '" data-val="' . esc_attr( $val ) . '" data-min="' . esc_attr( $min ) . '" data-max="' . esc_attr( $max ) . '" data-step="' . esc_attr( $step ) . '"></div>'; |
| 627 |
$form .= '</div>'; |
| 628 |
$form .= '</div>'; |
| 629 |
return $form; |
| 630 |
} |
| 631 |
|
| 632 |
/** |
| 633 |
* Color picker field. |
| 634 |
* |
| 635 |
* @since 2.0 |
| 636 |
*/ |
| 637 |
public function cform_color( $label, $names, $clabels, $vals, $class = '' ) { |
| 638 |
$form = '<div class="ujic-box ujic-color' . ( ! empty( $class ) ? ' ' . esc_attr( $class ) : '' ) . '">'; |
| 639 |
$form .= '<div class="label">' . esc_html( $label ) . '</div>'; |
| 640 |
$form .= '<div class="ujic-color-box">'; |
| 641 |
$i = 0; |
| 642 |
foreach ( $names as $name ) { |
| 643 |
// values |
| 644 |
$default_color = ' data-default-color="' . esc_attr( $vals[ $i ] ) . '" '; |
| 645 |
|
| 646 |
$form .= '<div class="ujic-color-hold">'; |
| 647 |
$form .= '<span> ' . esc_html( $clabels[ $i ] ) . ' :</span>'; |
| 648 |
$form .= '<input name="' . esc_attr( $name ) . '" id="' . esc_attr( $name ) . '" class="ujic_colorpick" type="text" value="' . esc_attr( $vals[ $i ] ) . '"' . esc_html( $default_color ) . ' />'; |
| 649 |
$form .= '</div>'; |
| 650 |
$i++; |
| 651 |
} |
| 652 |
$form .= '</div>'; |
| 653 |
$form .= '</div>'; |
| 654 |
return $form; |
| 655 |
} |
| 656 |
|
| 657 |
/** |
| 658 |
* Add buttons. |
| 659 |
* |
| 660 |
* @since 2.0 |
| 661 |
*/ |
| 662 |
private function cform_buttons() { |
| 663 |
$type = $this->ujic_request_id( 'edit' ); |
| 664 |
$form = '<div class="ujic-submit-hold">'; |
| 665 |
if ( ! empty( $type ) ) { |
| 666 |
$form .= get_submit_button( __( 'Update Style', 'ujicountdown' ), 'primary', 'submit_ujic', true ); |
| 667 |
$form .= '<a href="?page=ujicountdown&tab=tab_ujic_new" class="button button-secondary" id="ujic_table_new">' . __( 'Add New Style', 'ujicountdown' ) . '</a>'; |
| 668 |
} else { |
| 669 |
$form .= get_submit_button( __( 'Save Style', 'ujicountdown' ), 'primary', 'submit_ujic', true ); |
| 670 |
} |
| 671 |
$form .= '</div>'; |
| 672 |
|
| 673 |
return $form; |
| 674 |
} |
| 675 |
|
| 676 |
/** |
| 677 |
* Form Date. |
| 678 |
* |
| 679 |
* @since 2.0 |
| 680 |
*/ |
| 681 |
private function cform_date( $label, $id ) { |
| 682 |
$form = '<div class="ujic-box ujic-date">'; |
| 683 |
$form .= '<div class="label">' . esc_html( $label ) . '</div>'; |
| 684 |
|
| 685 |
$form .= '<input type="date" class="ujic-date-input" name="' . esc_attr( $id ) . '" id="' . esc_attr( $id ) . '" />'; |
| 686 |
|
| 687 |
$form .= '</div>'; |
| 688 |
|
| 689 |
return $form; |
| 690 |
} |
| 691 |
|
| 692 |
/** |
| 693 |
* Form Date. |
| 694 |
* |
| 695 |
* @since 2.0 |
| 696 |
*/ |
| 697 |
private function cform_time( $label ) { |
| 698 |
$form = '<div class="ujic-box ujic-time">'; |
| 699 |
$form .= '<div class="label">' . esc_html( $label ) . '</div>'; |
| 700 |
|
| 701 |
$form .= '<div class="ujic-duration-controls">'; |
| 702 |
$form .= '<input type="text" class="ujic_thou small-text" name="ujic_thou" value="" placeholder="Hour(s)" /> <span class="ujic-time-separator">:</span>'; |
| 703 |
$form .= '<input type="text" class="ujic_tmin small-text" name="ujic_tmin" value="" placeholder="Minute(s)" /> <span class="ujic-time-separator">:</span>'; |
| 704 |
$form .= '<input type="text" class="ujic_tsec small-text" name="ujic_tsec" value="" placeholder="Second(s)" />'; |
| 705 |
$form .= '</div>'; |
| 706 |
|
| 707 |
$form .= '</div>'; |
| 708 |
|
| 709 |
return $form; |
| 710 |
} |
| 711 |
|
| 712 |
/** |
| 713 |
* Form Type. |
| 714 |
* |
| 715 |
* @since 2.0 |
| 716 |
*/ |
| 717 |
private function cform_ftype( $cur_style, $id = null ) { |
| 718 |
$type = $this->ujic_request_id( 'edit' ); |
| 719 |
|
| 720 |
if ( ! empty( $type ) && ! empty( $id ) ) { |
| 721 |
$form = '<form method="post" action="options-general.php?page=ujicountdown&tab=tab_ujic_new&edit=' . esc_attr( $id ) . '">'; |
| 722 |
} else { |
| 723 |
$form = '<form method="post" action="options-general.php?page=ujicountdown&tab=tab_ujic_new&style=' . esc_attr( $cur_style ) . '&save=true">'; |
| 724 |
} |
| 725 |
|
| 726 |
return $form; |
| 727 |
} |
| 728 |
|
| 729 |
/** |
| 730 |
* Insert/Edit database values. |
| 731 |
* |
| 732 |
* @since 2.0 |
| 733 |
*/ |
| 734 |
private function cform_save_db() { |
| 735 |
$posts = $this->ujic_post_values(); |
| 736 |
|
| 737 |
if ( $this->cform_is_create() ) { |
| 738 |
$this->ujic_require_manage_options(); |
| 739 |
|
| 740 |
if ( $this->cform_errors( $posts ) ) { |
| 741 |
$this->ins_ujic_db( $posts ); |
| 742 |
$this->ujic_message( __( 'Timer style created successfully.', 'ujicountdown' ), false, true ); |
| 743 |
wp_add_inline_script( 'jquery-core', 'ujic_admin_home();' ); |
| 744 |
} |
| 745 |
} |
| 746 |
|
| 747 |
if ( ! empty( $posts ) && $this->cform_is_edit() ) { |
| 748 |
$this->ujic_require_manage_options(); |
| 749 |
|
| 750 |
if ( $this->cform_errors( $posts ) ) { |
| 751 |
$this->upd_ujic_db( $posts, $this->ujic_request_id( 'edit' ) ); |
| 752 |
$this->ujic_message( __( 'Timer style updated successfully.', 'ujicountdown' ), false, true ); |
| 753 |
} |
| 754 |
} |
| 755 |
} |
| 756 |
|
| 757 |
/** |
| 758 |
* Errors check. |
| 759 |
* |
| 760 |
* @since 2.0 |
| 761 |
*/ |
| 762 |
private function cform_errors( $posts ) { |
| 763 |
global $wpdb; |
| 764 |
$ujic_form_err = ''; |
| 765 |
$name = $posts['ujic_name'] ?? ''; |
| 766 |
$formats = array( 'ujic_d', 'ujic_h', 'ujic_m', 'ujic_s', 'ujic_y', 'ujic_o', 'ujic_w' ); |
| 767 |
|
| 768 |
// name not empty |
| 769 |
if ( '' === $name ) { |
| 770 |
$ujic_form_err .= __( 'Please enter timer title', 'ujicountdown' ) . '<br/>'; |
| 771 |
} |
| 772 |
|
| 773 |
// check format |
| 774 |
if ( empty( array_intersect( $formats, array_keys( $posts ) ) ) ) { |
| 775 |
$ujic_form_err .= __( 'Please select the timer format', 'ujicountdown' ) . '<br/>'; |
| 776 |
} |
| 777 |
|
| 778 |
// check name exist |
| 779 |
if ( '' !== $name && ! $this->cform_is_edit() ) { |
| 780 |
$cname = $wpdb->get_var( |
| 781 |
$wpdb->prepare( |
| 782 |
'SELECT title FROM ' . $this->ujic_tab_name() . ' WHERE title = %s', |
| 783 |
$name |
| 784 |
) |
| 785 |
); |
| 786 |
if ( ! empty( $cname ) ) { |
| 787 |
$ujic_form_err .= __( 'This name already exist. Please change the timer name. <br/>', 'ujicountdown' ); |
| 788 |
} |
| 789 |
} |
| 790 |
|
| 791 |
if ( empty( $ujic_form_err ) ) { |
| 792 |
return true; |
| 793 |
} elseif ( ! empty( $ujic_form_err ) ) { |
| 794 |
$this->ujic_message( $ujic_form_err, true, true ); |
| 795 |
return false; |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
/** |
| 800 |
* Check if have saved style. |
| 801 |
* |
| 802 |
* @since 2.0 |
| 803 |
*/ |
| 804 |
private function saved_db_style() { |
| 805 |
global $wpdb; |
| 806 |
$cname = $wpdb->get_var( 'SELECT title FROM ' . $this->ujic_tab_name() . ' LIMIT 1' ); |
| 807 |
if ( ! empty( $cname ) ) { |
| 808 |
return true; |
| 809 |
} else { |
| 810 |
return false; |
| 811 |
} |
| 812 |
} |
| 813 |
|
| 814 |
/** |
| 815 |
* Return If Create Form. |
| 816 |
* |
| 817 |
* @since 2.0 |
| 818 |
*/ |
| 819 |
public function cform_is_create() { |
| 820 |
$posts = $this->ujic_post_values(); |
| 821 |
|
| 822 |
if ( ! empty( $posts ) && 'true' === $this->ujic_request_text( 'save' ) ) { |
| 823 |
// 2.0.7 Fix Cross-Site Request Forgery attacks |
| 824 |
$this->ujic_secure( 'ujic_secure', 'ujic_secure_form', $posts ); |
| 825 |
return true; |
| 826 |
} else { |
| 827 |
return false; |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
/** |
| 832 |
* Return Edit Form. |
| 833 |
* |
| 834 |
* @since 2.0 |
| 835 |
*/ |
| 836 |
public function cform_is_edit() { |
| 837 |
return 0 !== $this->ujic_request_id( 'edit' ); |
| 838 |
} |
| 839 |
|
| 840 |
/** |
| 841 |
* Return Delete Form. |
| 842 |
* |
| 843 |
* @since 2.0 |
| 844 |
*/ |
| 845 |
private function cform_delete() { |
| 846 |
$id = $this->ujic_request_id( 'del' ); |
| 847 |
|
| 848 |
if ( ! $id ) { |
| 849 |
return; |
| 850 |
} |
| 851 |
|
| 852 |
$this->ujic_require_manage_options(); |
| 853 |
check_admin_referer( 'ujic_delete_style_' . $id ); |
| 854 |
|
| 855 |
$this->del_ujic_db( $id ); |
| 856 |
$this->ujic_message( __( 'Your countdown style was deleted', 'ujicountdown' ) ); |
| 857 |
} |
| 858 |
|
| 859 |
/** |
| 860 |
* Creating The Tabs. |
| 861 |
* |
| 862 |
* @since 2.0 |
| 863 |
*/ |
| 864 |
private function ujic_tabs_values() { |
| 865 |
global $wpdb; |
| 866 |
$ujictab = ''; |
| 867 |
$table_name = $wpdb->prefix . 'uji_counter'; |
| 868 |
$ujic_datas = $wpdb->get_results( "SELECT * FROM $table_name ORDER BY `time` DESC" ); |
| 869 |
if ( ! empty( $ujic_datas ) ) { |
| 870 |
foreach ( $ujic_datas as $ujic ) { |
| 871 |
$ujic_style = ! empty( $ujic->style ) ? $ujic->style : 'classic'; |
| 872 |
$style_name = ucwords( str_replace( array( '-', '_' ), ' ', $ujic_style ) ); |
| 873 |
$row_time = strtotime( $ujic->time ); |
| 874 |
$row_date = $row_time ? date_i18n( 'M j, Y', $row_time ) : $ujic->time; |
| 875 |
$row_clock = $row_time ? date_i18n( 'H:i:s', $row_time ) : ''; |
| 876 |
$delete_url = wp_nonce_url( |
| 877 |
add_query_arg( |
| 878 |
array( |
| 879 |
'page' => 'ujicountdown', |
| 880 |
'del' => absint( $ujic->id ), |
| 881 |
), |
| 882 |
admin_url( 'options-general.php' ) |
| 883 |
), |
| 884 |
'ujic_delete_style_' . absint( $ujic->id ) |
| 885 |
); |
| 886 |
$ujictab .= '<tr class="ujic-style-row"> |
| 887 |
<td class="ujic-list-date"><span class="ujic-list-date-main">' . esc_html( $row_date ) . '</span><span class="ujic-list-time">' . esc_html( $row_clock ) . '</span></td> |
| 888 |
<td class="ujic-list-name"><span>' . esc_html( $ujic->title ) . '</span><span class="ujic-list-subtitle">' . esc_html( $style_name ) . ' countdown</span></td> |
| 889 |
<td class="ujic-list-style"><span id="ujic-style-' . esc_attr( $ujic_style ) . '" class="ujic-types">' . esc_attr( $ujic_style ) . '</span></td> |
| 890 |
<td class="ujic-list-actions"><a class="ujic-action-link ujic-action-edit" href="?page=ujicountdown&tab=tab_ujic_new&edit=' . esc_attr( $ujic->id ) . '"><i class="dashicons dashicons-welcome-write-blog"></i><span>Edit</span></a><a class="ujic-action-link ujic-action-delete" href="' . esc_url( $delete_url ) . '"><i class="dashicons dashicons-trash"></i><span>Delete</span></a></td> |
| 891 |
</tr>'; |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
return $ujictab; |
| 896 |
} |
| 897 |
|
| 898 |
/** |
| 899 |
* Message Notification. |
| 900 |
* |
| 901 |
* @since 2.0 |
| 902 |
*/ |
| 903 |
private function ujic_message( $message, $errormsg = false, $defer = false ) { |
| 904 |
$message_html = $this->ujic_message_markup( $message, $errormsg ); |
| 905 |
|
| 906 |
if ( $defer ) { |
| 907 |
$this->ujic_admin_messages[] = $message_html; |
| 908 |
return; |
| 909 |
} |
| 910 |
|
| 911 |
echo $message_html; |
| 912 |
} |
| 913 |
|
| 914 |
/** |
| 915 |
* Collect deferred admin messages. |
| 916 |
* |
| 917 |
* @since 2.3.4 |
| 918 |
*/ |
| 919 |
private function ujic_collect_messages() { |
| 920 |
$messages = implode( '', $this->ujic_admin_messages ); |
| 921 |
$this->ujic_admin_messages = array(); |
| 922 |
|
| 923 |
return $messages; |
| 924 |
} |
| 925 |
|
| 926 |
/** |
| 927 |
* Build message notification markup. |
| 928 |
* |
| 929 |
* @since 2.3.4 |
| 930 |
*/ |
| 931 |
private function ujic_message_markup( $message, $errormsg = false ) { |
| 932 |
$type = $errormsg ? 'error' : 'success'; |
| 933 |
$title = $errormsg ? __( 'Action needed', 'ujicountdown' ) : __( 'Saved', 'ujicountdown' ); |
| 934 |
$icon = $errormsg ? 'dashicons-warning' : 'dashicons-yes-alt'; |
| 935 |
$role = $errormsg ? 'alert' : 'status'; |
| 936 |
$html = ''; |
| 937 |
|
| 938 |
$html .= '<div class="ujic-admin-message ujic-admin-message--' . esc_attr( $type ) . '" role="' . esc_attr( $role ) . '">'; |
| 939 |
$html .= '<span class="dashicons ' . esc_attr( $icon ) . '" aria-hidden="true"></span>'; |
| 940 |
$html .= '<p><strong class="ujic-message-title">' . esc_html( $title ) . '</strong><span class="ujic-message-text">' . wp_kses_post( $message ) . '</span></p></div>'; |
| 941 |
|
| 942 |
return $html; |
| 943 |
} |
| 944 |
|
| 945 |
/** |
| 946 |
* Timer settings |
| 947 |
* |
| 948 |
* @since 2.0 |
| 949 |
*/ |
| 950 |
public function admin_timerset() { |
| 951 |
// Save data |
| 952 |
$this->save_timerset(); |
| 953 |
// Get data |
| 954 |
$vars = $this->get_timerset(); |
| 955 |
apply_filters( 'ujic_get_vars_set', $vars ); |
| 956 |
|
| 957 |
// Build Forms |
| 958 |
$cnt = '<form method="post" action="options-general.php?page=ujicountdown&tab=tab_ujic_set&saveset=true">'; |
| 959 |
$cnt .= apply_filters( 'ujic_admin_newset', $cnt ); |
| 960 |
$default_time_help = __( 'Default is the server time!', 'ujicountdown' ); |
| 961 |
$cnt .= $this->cform_checkbox( |
| 962 |
__( 'Enable user time:', 'ujicountdown' ), |
| 963 |
array( 'ujic_utime' ), |
| 964 |
array( |
| 965 |
sprintf( |
| 966 |
'%s<br>%s <span class="ujic-info-tooltip" title="%s"><span class="dashicons dashicons-info-outline" aria-hidden="true"></span><span class="ujic-info-tooltip-text">%s</span></span>', |
| 967 |
esc_html__( 'Timer based on the users system time not the server time.', 'ujicountdown' ), |
| 968 |
esc_html__( "Don't enable it if you need the same time for any timezone!", 'ujicountdown' ), |
| 969 |
esc_attr( $default_time_help ), |
| 970 |
esc_html( $default_time_help ) |
| 971 |
), |
| 972 |
), |
| 973 |
array( ( isset( $vars['ujic_utime'] ) ? $vars['ujic_utime'] : false ) ) |
| 974 |
); |
| 975 |
$cnt .= $this->cform_checkbox( __( 'Right-To-Left (RTL):', 'ujicountdown' ), array( 'ujic_rtl' ), array( __( 'Writing starts from the right of the page and continues to the left.', 'ujicountdown' ) ), array( ( isset( $vars['ujic_rtl'] ) ? $vars['ujic_rtl'] : false ) ) ); |
| 976 |
$cnt .= $this->cform_checkbox( __( 'Remove Settings', 'ujicountdown' ), array( 'ujic_remove' ), array( __( 'This option will remove all settings and styles when <strong>Delete plugin</strong>', 'ujicountdown' ) ), array( ( isset( $vars['ujic_remove'] ) ? $vars['ujic_remove'] : false ) ) ); |
| 977 |
$cnt .= $this->cform_title( __( 'Quick Translation', 'ujicountdown' ) ); |
| 978 |
|
| 979 |
$labels = self::ujic_labels(); |
| 980 |
|
| 981 |
foreach ( $labels as $v => $n ) { |
| 982 |
$val = ( isset( $vars[ $v ] ) ) ? $vars[ $v ] : ''; |
| 983 |
$cnt .= $this->cform_input( __( $n . ':', 'ujicountdown' ), $v, $val, 'default-text' ); |
| 984 |
} |
| 985 |
$cnt .= '<div class="ujic-settings-actions ujic-submit-hold">'; |
| 986 |
$cnt .= get_submit_button( __( 'Save Changes', 'ujicountdown' ), 'primary', 'submit_ujic', true ); |
| 987 |
$cnt .= '</div>'; |
| 988 |
|
| 989 |
$cnt .= wp_nonce_field( 'ujic_secureset', 'ujic_secureset_form', true, false ); |
| 990 |
|
| 991 |
$cnt .= '</form>'; |
| 992 |
|
| 993 |
echo $this->custom_metabox( __( 'Timer Settings', 'ujicountdown' ), $cnt, 'ujic-create ujic-settings' ); |
| 994 |
} |
| 995 |
|
| 996 |
/** |
| 997 |
* Save timer settings |
| 998 |
* |
| 999 |
* @since 2.0 |
| 1000 |
*/ |
| 1001 |
public function save_timerset() { |
| 1002 |
$settings = $this->ujic_post_values(); |
| 1003 |
|
| 1004 |
if ( ! empty( $settings ) && 'true' === $this->ujic_request_text( 'saveset' ) ) { |
| 1005 |
$this->ujic_require_manage_options(); |
| 1006 |
// 2.0.7 Fix Cross-Site Request Forgery attacks |
| 1007 |
$this->ujic_secure( 'ujic_secureset', 'ujic_secureset_form', $settings ); |
| 1008 |
|
| 1009 |
unset( $settings['submit_ujic'] ); |
| 1010 |
update_option( 'ujic_set', $settings ); |
| 1011 |
$this->ujic_message( __( 'Settings saved.', 'ujicountdown' ) ); |
| 1012 |
} elseif ( ! empty( $settings ) ) { |
| 1013 |
$this->ujic_message( __( 'Some error occured. Please try again.', 'ujicountdown' ) ); |
| 1014 |
} |
| 1015 |
} |
| 1016 |
|
| 1017 |
/** |
| 1018 |
* Get timer settings |
| 1019 |
* |
| 1020 |
* @since 2.0 |
| 1021 |
*/ |
| 1022 |
public function get_timerset( $name = null ) { |
| 1023 |
$vars = get_option( 'ujic_set', array() ); |
| 1024 |
if ( $name ) { |
| 1025 |
return $vars[ $name ] ?? false; |
| 1026 |
} else { |
| 1027 |
return $vars; |
| 1028 |
} |
| 1029 |
} |
| 1030 |
|
| 1031 |
/** |
| 1032 |
* Secure against Cross-Site Request Forgery |
| 1033 |
* |
| 1034 |
* @since 2.0.7 |
| 1035 |
*/ |
| 1036 |
public function ujic_secure( $secure, $secure_filed, $posts ) { |
| 1037 |
if ( ! isset( $posts[ $secure_filed ] ) || ! wp_verify_nonce( $posts[ $secure_filed ], $secure ) |
| 1038 |
) { |
| 1039 |
wp_die( __( 'Cheatin’ huh?', 'ujicountdown' ) ); |
| 1040 |
} |
| 1041 |
} |
| 1042 |
|
| 1043 |
/** |
| 1044 |
* Get a sanitized text value from the admin query string. |
| 1045 |
* |
| 1046 |
* @since 2.3.5 |
| 1047 |
*/ |
| 1048 |
protected function ujic_request_text( $key, $default = '' ) { |
| 1049 |
if ( ! isset( $_GET[ $key ] ) ) { |
| 1050 |
return $default; |
| 1051 |
} |
| 1052 |
|
| 1053 |
$value = sanitize_text_field( wp_unslash( $_GET[ $key ] ) ); |
| 1054 |
return '' === $value ? $default : $value; |
| 1055 |
} |
| 1056 |
|
| 1057 |
/** |
| 1058 |
* Get a positive id value from the admin query string. |
| 1059 |
* |
| 1060 |
* @since 2.3.5 |
| 1061 |
*/ |
| 1062 |
protected function ujic_request_id( $key ) { |
| 1063 |
if ( ! isset( $_GET[ $key ] ) ) { |
| 1064 |
return 0; |
| 1065 |
} |
| 1066 |
|
| 1067 |
return absint( wp_unslash( $_GET[ $key ] ) ); |
| 1068 |
} |
| 1069 |
|
| 1070 |
/** |
| 1071 |
* Get sanitized admin form data. |
| 1072 |
* |
| 1073 |
* @since 2.3.5 |
| 1074 |
*/ |
| 1075 |
protected function ujic_post_values() { |
| 1076 |
if ( empty( $_POST ) ) { |
| 1077 |
return array(); |
| 1078 |
} |
| 1079 |
|
| 1080 |
return $this->sanitize_array( wp_unslash( $_POST ) ); |
| 1081 |
} |
| 1082 |
|
| 1083 |
/** |
| 1084 |
* Require settings capability before data changes. |
| 1085 |
* |
| 1086 |
* @since 2.3.5 |
| 1087 |
*/ |
| 1088 |
protected function ujic_require_manage_options() { |
| 1089 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 1090 |
wp_die( esc_html__( 'Sorry, you are not allowed to manage Uji Countdown.', 'ujicountdown' ) ); |
| 1091 |
} |
| 1092 |
} |
| 1093 |
|
| 1094 |
/** |
| 1095 |
* Sanitize values in array |
| 1096 |
* |
| 1097 |
* @since 2.3 |
| 1098 |
*/ |
| 1099 |
public function sanitize_array( $input ) { |
| 1100 |
// Initialize the new array that will hold the sanitize values |
| 1101 |
$new_input = array(); |
| 1102 |
|
| 1103 |
// Loop through the input and sanitize each of the values |
| 1104 |
foreach ( (array) $input as $key => $val ) { |
| 1105 |
$clean_key = sanitize_key( $key ); |
| 1106 |
|
| 1107 |
if ( is_array( $val ) ) { |
| 1108 |
$new_input[ $clean_key ] = $this->sanitize_array( $val ); |
| 1109 |
continue; |
| 1110 |
} |
| 1111 |
|
| 1112 |
$new_input[ $clean_key ] = sanitize_text_field( $val ); |
| 1113 |
} |
| 1114 |
|
| 1115 |
return $new_input; |
| 1116 |
} |
| 1117 |
|
| 1118 |
} |
| 1119 |
|