PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.2.18
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.2.18
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / includes / Admin.php

Admin.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 2.2.18, at includes/Admin.php

654 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hurrytimer;
4
5 use Carbon\Carbon;
6 use Hurrytimer\Utils\Helpers;
7
8 class Admin {
9 /**
10 * The ID of this plugin.
11 *
12 * @since 1.0.0
13 * @access private
14 * @var string $pluginName The ID of this plugin.
15 */
16 private $pluginName;
17
18 /**
19 * The version of this plugin.
20 *
21 * @since 1.0.0
22 * @access private
23 * @var string $version The current version of this plugin.
24 */
25 private $version;
26
27 /**
28 * Initialize the class and set its properties.
29 *
30 * @param string $pluginName The name of this plugin.
31 * @param string $version The version of this plugin.
32 *
33 * @since 1.0.0
34 *
35 */
36 public function __construct( $pluginName, $version ) {
37 $this->pluginName = $pluginName;
38 $this->version = $version;
39 add_action( 'wp_insert_post', [ $this, 'regenerate_css' ], 10, 3 );
40 add_action( 'wp_ajax_wcSearchProducts', [ $this, 'ajaxWcSearchProducts' ] );
41 add_action( 'wp_ajax_add_wc_condition_group', [ $this, 'ajaxAddWcConditionGroup' ] );
42 add_action( 'wp_ajax_add_wc_condition', [ $this, 'ajaxAddWcCondition' ] );
43 add_action( 'wp_ajax_load_wc_condition', [ $this, 'ajaxLoadWcCondition' ] );
44 add_action( 'admin_init', [ $this, 'activateCampaign' ] );
45 add_action( 'admin_init', [ $this, 'deactivateCampaign' ] );
46 add_action( 'admin_init', [ $this, 'resetEvergreenCampaign' ] );
47 add_action( 'admin_init', [ $this, 'resetAllEvergreenCampaigns' ] );
48 add_action( 'admin_init', [ $this, 'pluginSettings' ] );
49 add_filter( 'post_row_actions', [ $this, 'campaignsListRowActions' ] );
50 add_action( 'admin_menu', [ $this, 'menu' ] );
51 add_filter( 'bulk_actions-edit-' . HURRYT_POST_TYPE,
52 [ $this, 'campaignsListBulkActions', ] );
53
54 add_filter( 'manage_' . HURRYT_POST_TYPE . '_posts_columns',
55 [ $this, 'campaignsListColumns', ] );
56
57
58 add_action( 'manage_' . HURRYT_POST_TYPE . '_posts_custom_column',
59 [ $this, 'countdownListColumnsContent' ], 10, 2 );
60
61 add_filter( 'bulk_post_updated_messages',
62 [ $this, 'customBulkPostUpdatedMessages' ], 10, 2 );
63
64 add_action( 'admin_menu', [ $this, 'helpTabs' ] );
65 add_action( 'admin_notices', [ $this, 'resetEvergreenCampaignNotice' ] );
66 add_action( 'admin_notices', [ $this, 'resetAllEvergreenCampaignNotice' ] );
67
68 add_action( 'admin_notices', [ $this, 'countdown_activation_notice' ] );
69 add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] );
70 add_filter( 'wp_insert_post_data', [ $this, 'mark_post_being_saved' ] );
71
72 //removeIf(pro)
73 add_filter( 'plugin_action_links_' . HURRYT_BASENAME, [ $this, 'add_upgrade_link' ] );
74 //endRemoveIf(pro)
75
76 }
77
78 function mark_post_being_saved( $data ) {
79
80 global $hurryt_saving_post;
81
82 $hurryt_saving_post = 1;
83
84 return $data;
85 }
86
87 /**
88 * Generate published campaigns CSS file.
89 *
90 * @param $post_id
91 * @param $post
92 * @param $update
93 */
94 function regenerate_css( $post_id, $post, $update ) {
95 if ( wp_is_post_revision( $post_id ) ) {
96 return;
97 }
98
99 if ( $post->post_type !== HURRYT_POST_TYPE ) {
100 return;
101 }
102
103 if ( $update ) {
104 // TODO: Check if custom CSS has been changed.
105 Campaign::generate_css();
106 }
107
108 }
109
110 public function admin_footer_text() {
111 $screen = get_current_screen();
112 if ( $screen->post_type === HURRYT_POST_TYPE ) {
113 include HURRYT_DIR . 'admin/templates/footer-rate-plugin.php';
114 }
115 }
116
117 //removeIf(pro)
118 public function add_upgrade_link( $links ) {
119 $links[]
120 = '<a href="https://hurrytimer.com/?utm_source=plugin&utm_medium=installed_plugins&utm_campaign=go_pro" target="_blank" class="hurryt-text-green-500 hurryt-font-bold">Go Pro</a>';
121
122 return $links;
123 }
124
125 //endRemoveIf(pro)
126
127 public function countdown_activation_notice() {
128 $post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
129 $status = filter_input( INPUT_GET, 'hurrytimer_action' );
130
131 if ( ! $post_id || ! $status || ! ( $post = get_post( $post_id ) ) ) {
132 return;
133 }
134 if (
135 $status === "activate-compaign"
136 &&
137 ! Utils\Helpers::isPostActive( $post_id )
138 ) { ?>
139 <div class="notice notice-success is-dismissible">
140 <p><?php _e(
141 'Countdown timer deactivated.',
142 "hurrytimer"
143 ); ?></p>
144 </div>
145 <?php } else { ?>
146 <div class="notice notice-success is-dismissible">
147 <p><?php _e( 'Countdown timer activated.', "hurrytimer" ); ?></p>
148 </div>
149 <?php }
150 }
151
152 public function helpTabs() {
153 add_action( 'load-edit.php', [ $this, 'editHelpTabs' ] );
154 add_action( 'load-post-new.php', [ $this, 'editHelpTabs' ] );
155 add_action( 'load-post.php', [ $this, 'editHelpTabs' ] );
156 }
157
158 public function editHelpTabs() {
159 $screen = get_current_screen();
160 if ( strpos( $screen->id, 'hurrytimer_countdown' ) === false ) {
161 return;
162 }
163 $screen->remove_help_tabs();
164 }
165
166 public function customBulkPostUpdatedMessages( $bulk_messages, $bulk_counts ) {
167 $bulk_messages[ HURRYT_POST_TYPE ] = [
168 'updated' => _n(
169 '%s countdown timer updated.',
170 '%s countdown timers updated.',
171 $bulk_counts[ 'updated' ]
172 ),
173 'locked' => _n(
174 '%s countdown timer not updated, somebody is editing it.',
175 '%s countdown timers not updated, somebody is editing them.',
176 $bulk_counts[ 'locked' ]
177 ),
178 'deleted' => _n(
179 '%s countdown timer permanently deleted.',
180 '%s countdown timers permanently deleted.',
181 $bulk_counts[ 'deleted' ]
182 ),
183 'trashed' => _n(
184 '%s countdown timer deleted.',
185 '%s countdown timers deleted.',
186 $bulk_counts[ 'trashed' ]
187 ),
188 'untrashed' => _n(
189 '%s countdown timer restored from the Trash.',
190 '%s countdown timers restored from the Trash.',
191 $bulk_counts[ 'untrashed' ]
192 ),
193 ];
194
195 return $bulk_messages;
196 }
197
198 public function countdownListColumnsContent( $column, $post_id ) {
199 $campaign = new Campaign( $post_id );
200 switch ( $column ) {
201 case 'status':
202 echo $campaign->is_published()
203 ? __( 'Active', "hurrytimer" )
204 : __( 'Inactive', "hurrytimer" );
205 break;
206 case 'mode':
207 if ( $campaign->is_evergreen() ) {
208 echo __( 'Evergreen', "hurrytimer" );
209 }
210 if ( $campaign->is_one_time() ) {
211 echo __( 'One-Time', "hurrytimer" );
212 }
213 if ( $campaign->is_recurring() ) {
214 echo __( 'Recurring', "hurrytimer" );
215 }
216 break;
217 case 'CampaignShortcode':
218 echo '<pre class="htmr-list-shortcode">[hurrytimer id="' .
219 $post_id .
220 '"]</pre>';
221 break;
222 }
223 }
224
225 public function campaignsListBulkActions( $actions ) {
226 unset( $actions[ 'edit' ] );
227
228 return $actions;
229 }
230
231 public function campaignsListColumns( $columns ) {
232 $allowed_columns = [];
233 foreach ( $columns as $column_name => $value ) {
234 if ( in_array( $column_name, [ 'cb', 'title', 'date' ] ) ) {
235 $allowed_columns[ $column_name ] = $value;
236 }
237 }
238
239 $columns = $allowed_columns;
240 $date = $columns[ 'date' ];
241 unset( $columns[ 'date' ] );
242 $columns = array_merge( $columns, [
243 'status' => __( 'Status', "hurrytimer" ),
244 'mode' => __( 'Mode', "hurrytimer" ),
245 'CampaignShortcode' => __( 'CampaignShortcode', "hurrytimer" ),
246 ] );
247 $columns[ 'date' ] = $date;
248
249 return $columns;
250 }
251
252 /**
253 * Register the stylesheets for the admin area.
254 *
255 * @since 1.0.0
256 */
257 public function enqueueStyles() {
258 $version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : $this->version;
259 wp_enqueue_style( 'wp-color-picker' );
260 wp_enqueue_style( 'iris' );
261 wp_dequeue_style( 'select2' );
262
263 wp_enqueue_style(
264 "codemirror",
265 HURRYT_URL . 'assets/css/codemirror.css',
266 [],
267 "5.42.2",
268 'all'
269 );
270 wp_enqueue_style(
271 'hurryt-select2',
272 HURRYT_URL . 'assets/css/select2.css',
273 array(),
274 '4.0.5',
275 'all'
276 );
277
278 wp_enqueue_style(
279 'hurryt-base-css',
280 HURRYT_URL . 'assets/css/base.css',
281 array(),
282 $version,
283 'all'
284 );
285
286 wp_enqueue_style(
287 $this->pluginName,
288 HURRYT_URL . 'assets/css/admin.css',
289 [ 'hurryt-base-css', 'hurryt-select2' ],
290 $version,
291 'all'
292 );
293 }
294
295 public function campaignsListRowActions( $actions ) {
296 global $post;
297 if ( $post->post_type === HURRYT_POST_TYPE ) {
298 unset( $actions[ 'inline hide-if-no-js' ] );
299 }
300
301 return $actions;
302 }
303
304 /**
305 * Register the JavaScript for the admin area.
306 *
307 * @since 1.0.0
308 */
309 public function enqueueScripts() {
310 wp_enqueue_script( 'jquery-ui-core' );
311 wp_enqueue_script( 'jquery-ui-tooltip' );
312 wp_enqueue_script( 'wp-color-picker' );
313 wp_enqueue_script( 'iris' );
314 wp_enqueue_script( 'jquery-ui-slider' );
315 wp_dequeue_script( 'select2' );
316
317 wp_enqueue_script(
318 'hurryt-cookie',
319 HURRYT_URL . 'assets/js/cookie.min.js',
320 [],
321 '2.2.0',
322 true
323 );
324
325 wp_enqueue_script(
326 'jq-date-picker-addon',
327 HURRYT_URL . 'assets/js/timepicker-addon.js',
328 [ 'jquery-ui-datepicker' ],
329 '1.6.3',
330 true
331 );
332
333 wp_enqueue_script(
334 'hurryt-select2',
335 HURRYT_URL . 'assets/js/select2.min.js',
336 [ 'jquery' ],
337 '4.0.5',
338 true
339 );
340
341 $deps = [ 'hurryt-cookie', 'jq-date-picker-addon', 'hurryt-select2' ];
342
343 wp_enqueue_script(
344 $this->pluginName,
345 HURRYT_URL . 'assets/js/admin.js',
346 $deps,
347 $this->version,
348 true
349 );
350
351 wp_localize_script( $this->pluginName, 'hurrytimer_ajax_object', array(
352 'ajax_nonce' => wp_create_nonce( 'hurryt-admin' ),
353 'ajax_url' => admin_url( 'admin-ajax.php' ),
354 'headline_pos' => [
355 'above_timer' => C::HEADLINE_POSITION_ABOVE_TIMER,
356 'below_timer' => C::HEADLINE_POSITION_BELOW_TIMER,
357 ],
358 'mode' => [
359 'evergreen' => C::MODE_EVERGREEN,
360 'regular' => C::MODE_REGULAR,
361 'recurring' => C::MODE_RECURRING,
362 ],
363 'browser_tz_offset' => Carbon::now( hurryt_tz() )->getOffset() / 60,
364 ) );
365
366 }
367
368 public function menu() {
369 add_menu_page(
370 'HurryTimer',
371 'HurryTimer',
372 apply_filters('hurryt_admin_capability', 'edit_posts', 'campaigns_list'),
373 'hurrytimer',
374 null,
375 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNjkuNTYgNzAuNjIiPiAgPGRlZnM+ICAgIDxsaW5lYXJHcmFkaWVudCBpZD0iYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlIiB5MT0iMzUuMzEiIHgyPSI2NS4wNyIgeTI9IjM1LjMxIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+ICAgICAgPHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjZjg1MzdmIi8+ICAgICAgPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjNjIi8+ICAgIDwvbGluZWFyR3JhZGllbnQ+ICAgIDx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),
382 apply_filters('hurryt_admin_capability', 'edit_posts', 'add_campaign'),
383 'post-new.php?post_type=hurrytimer_countdown'
384 );
385
386 add_submenu_page(
387 'hurrytimer',
388 __( 'Settings', 'hurrytimer' ),
389 __( 'Settings', 'hurrytimer' ),
390 apply_filters('hurryt_admin_capability', 'manage_options', 'settings'),
391 'hurrytimer_settings',
392 [ $this, 'settings' ]
393 );
394 }
395
396 private function get_menu_position( $start, $increment = 0.3 ) {
397 $menus_positions = [];
398 foreach ( $GLOBALS[ 'menu' ] as $key => $menu ) {
399 $menus_positions[] = $key;
400 }
401 if ( ! in_array( $start, $menus_positions ) ) {
402 return $start;
403 }
404
405 /* the position is already reserved find the closet one */
406 while ( in_array( $start, $menus_positions ) ) {
407 $start += $increment;
408 }
409
410 return $start;
411 }
412
413 public function settings() {
414 include_once HURRYT_DIR . 'admin/templates/settings.php';
415 }
416
417 public function activateCampaign() {
418 if (
419 isset( $_GET[ 'hurrytimer_action' ] )
420 && $_GET[ 'hurrytimer_action' ] === "activate-compaign"
421 && isset( $_GET[ '_wpnonce' ] )
422 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'activate-compaign' )
423 ) {
424 $postId = intval( $_GET[ 'post' ] );
425 wp_update_post( [ 'ID' => $postId, 'post_status' => 'publish' ] );
426 }
427 }
428
429 function resetEvergreenCampaignNotice() {
430 if (
431 isset( $_GET[ 'hurryt-action' ] )
432 && isset( $_GET[ 'hurryt-scope' ] )
433 && isset( $_GET[ 'post' ] )
434 && $_GET[ 'hurryt-action' ] === "reset-evergreen-compaign"
435 && isset( $_GET[ '_wpnonce' ] )
436 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-evergreen-compaign' )
437 ) {
438 $scopeText
439 = $_GET[ 'hurryt-scope' ] === 'admin'
440 ? ' you '
441 : ' all visitors '; ?>
442 <div class="notice notice-success is-dismissible">
443 <p><?php _e(
444 "Campaign has been reset for $scopeText successfully.",
445 'hurrytimer'
446 ); ?></p>
447 </div>
448 <?php
449 }
450 }
451
452 function resetAllEvergreenCampaignNotice() {
453 if (
454 isset( $_GET[ 'hurryt-page' ] )
455 && isset( $_GET[ 'hurryt-scope' ] )
456 && isset( $_GET[ 'hurryt-action' ] )
457 && $_GET[ 'hurryt-page' ] === "hurrytimer_settings"
458 && $_GET[ 'hurryt-action' ] === "reset-all-evergreen-compaigns"
459 && isset( $_GET[ '_wpnonce' ] )
460 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-all-evergreen-compaigns' )
461 ) {
462 $scopeText
463 = $_GET[ 'hurryt-scope' ] === 'admin'
464 ? ' you '
465 : ' all visitors '; ?>
466 <div class="notice notice-success is-dismissible">
467 <p><?php _e(
468 "All evergreen campaigns have been reset for $scopeText successfully.",
469 'hurrytimer'
470 ); ?></p>
471 </div>
472 <?php
473 }
474 }
475
476 public function resetEvergreenCampaign() {
477 if (
478 isset( $_GET[ 'hurryt-action' ] )
479 && isset( $_GET[ 'hurryt-scope' ] )
480 && isset( $_GET[ 'post' ] )
481 && $_GET[ 'hurryt-action' ] === "reset-evergreen-compaign"
482 && isset( $_GET[ '_wpnonce' ] )
483 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-evergreen-compaign' )
484 ) {
485 $postId = intval( $_GET[ 'post' ] );
486 $IPDetection = new IPDetection();
487 $cookieDetection = new CookieDetection();
488 $campaign = new EvergreenCampaign(
489 $postId,
490 $cookieDetection,
491 $IPDetection
492 );
493 $campaign->reset( sanitize_text_field( $_GET[ 'hurryt-scope' ] ) );
494 }
495 }
496
497 public function resetAllEvergreenCampaigns() {
498 if (
499 isset( $_GET[ 'hurryt-page' ] )
500 && isset( $_GET[ 'hurryt-scope' ] )
501 && isset( $_GET[ 'hurryt-action' ] )
502 && $_GET[ 'hurryt-page' ] === "hurrytimer_settings"
503 && $_GET[ 'hurryt-action' ] === "reset-all-evergreen-compaigns"
504 && isset( $_GET[ '_wpnonce' ] )
505 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-all-evergreen-compaigns' )
506 ) {
507 $evergreenCampaign = new EvergreenCampaign( null, new CookieDetection(),
508 new IPDetection() );
509 $evergreenCampaign->resetAll( sanitize_text_field( $_GET[ 'hurryt-scope' ] ) );
510 }
511 }
512
513 public function deactivateCampaign() {
514 if (
515 isset( $_GET[ 'hurrytimer_action' ] )
516 && $_GET[ 'hurrytimer_action' ] === "deactivate-compaign"
517 && isset( $_GET[ '_wpnonce' ] )
518 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'deactivate-compaign' )
519 ) {
520 $postId = intval( $_GET[ 'post' ] );
521 wp_update_post( [ 'ID' => $postId, 'post_status' => 'draft' ] );
522 }
523 }
524
525 public function settingsBox() {
526 require plugin_dir_path( dirname( __FILE__ ) ) .
527 'admin/CampaignSettings.php';
528 new CampaignSettings();
529 }
530
531 //removeIf(pro)
532 public function upgradeBanner() {
533 add_meta_box(
534 'hurrytimer-upgrade-banner',
535 __( 'Get the Most of HurryTimer', 'hurrytimer' ),
536 function () {
537 include HURRYT_DIR . 'admin/templates/upgrade-banner.php';
538 },
539 HURRYT_POST_TYPE,
540 'side',
541 'low'
542 );
543 }
544 //endRemoveIf(pro)
545
546 /**
547 * Search products
548 *
549 * @return void
550 */
551 public function ajaxWcSearchProducts() {
552 $search = sanitize_text_field( $_GET[ 'search' ] );
553 $selection = sanitize_text_field( $_GET[ 'productsSelection' ] );
554 $exclude = array_map( 'intval', $_GET[ 'exclude' ] );
555
556 if (
557 in_array( $selection, [
558 C::WC_PS_TYPE_INCLUDE_CATEGORIES,
559 C::WC_PS_TYPE_EXCLUDE_CATEGORIES,
560 ] )
561 ) {
562 $args = [
563 "hide_empty" => false,
564 "taxonomy" => "product_cat",
565 "name__like" => $search,
566 'exclude' => $exclude,
567 ];
568
569 $items = get_terms( $args );
570 $results = array_map( function ( $item ) {
571 return [
572 "id" => $item->term_id,
573 "text" => $item->name,
574 ];
575 }, $items );
576 } else {
577 $args = [
578 's' => $search,
579 'post_type' => 'product',
580 'post__not_in' => $exclude,
581 'posts_per_page' => -1,
582 ];
583 $items = get_posts( $args );
584 $results = array_map( function ( $item ) {
585 return [
586 "id" => $item->ID,
587 "text" => $item->post_title,
588 ];
589 }, $items );
590 }
591 exit( json_encode( [ "results" => $results, "pagination" => true ] ) );
592 }
593
594 public function pluginSettings() {
595 register_setting( 'hurrytimer_settings', 'hurryt_settings' );
596 add_settings_section(
597 'hurryt_settings_general',
598 __( 'General', 'hurrytimer' ),
599 null,
600 'hurrytimer_settings'
601 );
602 add_settings_field(
603 'hurryt_disable_actions_edit_mode',
604 'Disable actions in the admin area',
605 function ( $args ) {
606 $options = get_option( 'hurryt_settings' ); ?>
607 <label for="">
608 <input type="checkbox"
609 name="hurryt_settings[disable_actions]" <?php checked(
610 isset( $options[ 'disable_actions' ] )
611 && $options[ 'disable_actions' ],
612 1
613 ); ?> id="hurryt-disable-actions" value="1"/>
614 </label>
615 <p class="description">
616 Don't run actions when editing or previewing a page in the admin area.
617 </p>
618 <?php
619 },
620 'hurrytimer_settings',
621 'hurryt_settings_general'
622 );
623 }
624
625 function ajaxAddWcConditionGroup() {
626 check_ajax_referer( 'hurryt-admin', 'nonce' );
627
628 ob_start();
629 include HURRYT_DIR . 'admin/templates/wc-condition-group.php';
630 echo ob_get_clean();
631 wp_die();
632 }
633
634 function ajaxAddWcCondition() {
635 check_ajax_referer( 'hurryt-admin', 'nonce' );
636
637 ob_start();
638 $groupId = sanitize_key( $_GET[ 'group_id' ] );
639 include HURRYT_DIR . 'admin/templates/wc-condition.php';
640 echo ob_get_clean();
641 wp_die();
642 }
643
644 function ajaxLoadWcCondition() {
645 check_ajax_referer( 'hurryt-admin', 'nonce' );
646 ob_start();
647 $groupId = sanitize_key( $_GET[ 'group_id' ] );
648 $selected = hurryt_wc_conditions()[ sanitize_key( $_GET[ 'condition_key' ] ) ];
649 include HURRYT_DIR . 'admin/templates/wc-condition.php';
650 echo ob_get_clean();
651 wp_die();
652 }
653 }
654