PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.2
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Core / wordpress / router.php

router.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.2, at back/Core/wordpress/router.php

101 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') || die('Restricted Access');
4
5 function acym_addScript(bool $raw, string $script, array $params = []): string
6 {
7 static $scriptNumber = 0;
8 $scriptNumber++;
9 $handle = 'acym_script'.$scriptNumber;
10
11 if (!isset($params['dependencies'])) {
12 $params['dependencies'] = ['jquery'];
13 }
14
15 if ($raw) {
16 if (!empty($params['dependencies']['script_name'])) {
17 wp_add_inline_script($params['dependencies']['script_name'], $script);
18 } else {
19 // TODO: refactor js insertion to use CMS dedicated methods
20 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Raw JS content passed by caller.
21 echo '<script type="text/javascript">'.$script.'</script>';
22 }
23 } elseif (!empty($params['defer']) || !empty($params['async']) || !empty($params['needTagScript'])) {
24 // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript -- After WordPress hook.
25 echo '<script type="text/javascript" src="'.esc_url($script).'"'.(!empty($params['async']) ? ' async' : '').(!empty($params['defer']) ? ' defer' : '').'></script>';
26 } else {
27 wp_enqueue_script(
28 $handle,
29 $script,
30 $params['dependencies'],
31 '11.0.2',
32 [
33 'in_footer' => false,
34 ]
35 );
36 }
37
38 return $handle;
39 }
40
41 function acym_addStyle(bool $raw, string $style): void
42 {
43 // TODO: refactor style insertion to use CMS dedicated methods
44
45 if ($raw) {
46 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Raw CSS content passed by caller.
47 echo '<style>'.$style.'</style>';
48 } else {
49 // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet -- To refactor.
50 echo '<link rel="stylesheet" href="'.esc_url($style).'" type="text/css">';
51 }
52 }
53
54 function acym_loadCmsScripts(): void
55 {
56 $toggleController = acym_isAdmin() ? 'toggle' : 'fronttoggle';
57 acym_addScript(
58 true,
59 '
60 var ACYM_AJAX_URL = "'.admin_url('admin-ajax.php').'?action='.ACYM_COMPONENT.'_router&'.acym_noTemplate().'&'.acym_getFormToken().'&nocache='.time().'";
61 var ACYM_TOGGLE_URL = ACYM_AJAX_URL + "&page='.ACYM_COMPONENT.'_toggle&ctrl='.$toggleController.'";
62 var ACYM_IS_ADMIN = '.(acym_isAdmin() ? 'true' : 'false').';
63 if("undefined" === typeof icl_ajxloaderimg_src) var icl_ajxloaderimg_src = "";'
64 );
65
66 // Without this line the image insertion and dtexts button doesn't work
67 wp_enqueue_media();
68
69 wp_enqueue_script('jquery');
70 wp_enqueue_script('jquery-ui-draggable');
71 wp_enqueue_script('jquery-ui-droppable');
72 wp_enqueue_script('jquery-ui-sortable');
73 wp_enqueue_script('jquery-effects-slide');
74 }
75
76 function acym_redirect(string $url, string $msg = '', string $msgType = 'message', bool $safe = true): void
77 {
78 if (acym_isAdmin() && substr($url, 0, 4) != 'http' && substr($url, 0, 4) != 'www.') {
79 $url = acym_addPageParam($url);
80 }
81
82 if (empty($url)) {
83 $url = acym_rootURI();
84 }
85
86 $wordpressOutput = @ob_get_clean();
87 if (headers_sent()) {
88 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped output from WordPress itself.
89 echo $wordpressOutput;
90 acym_addScript(true, 'window.location.href = '.wp_json_encode($url).';');
91 } else {
92 if ($safe) {
93 wp_safe_redirect($url);
94 } else {
95 // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- mainly for email links after tracking is applied
96 wp_redirect($url);
97 }
98 }
99 exit;
100 }
101