PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / 1.0.24
OttoKit: All-in-One Automation Platform v1.0.24
1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Controllers / EventHelperController.php
suretriggers / src / Controllers Last commit date
AuthController.php 2 years ago AutomationController.php 3 years ago EventController.php 3 years ago EventHelperController.php 3 years ago GlobalSearchController.php 2 years ago IntegrationsController.php 3 years ago OptionController.php 3 years ago RestController.php 2 years ago RoutesController.php 3 years ago SettingsController.php 3 years ago
EventHelperController.php
176 lines
1 <?php
2 /**
3 * EventHelperController.
4 * php version 5.6
5 *
6 * @category EventHelperController
7 * @package SureTriggers
8 * @author BSF <username@example.com>
9 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
10 * @link https://www.brainstormforce.com/
11 * @since 1.0.0
12 */
13
14 namespace SureTriggers\Controllers;
15
16 use SureTriggers\Traits\SingletonLoader;
17
18 /**
19 * EventHelperController
20 *
21 * @category EventHelperController
22 * @package SureTriggers
23 * @author BSF <username@example.com>
24 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
25 * @link https://www.brainstormforce.com/
26 * @since 1.0.0
27 *
28 * @psalm-suppress UndefinedTrait
29 */
30 class EventHelperController {
31
32 use SingletonLoader;
33
34 /**
35 * Constructor
36 *
37 * @since 1.0.0
38 */
39 public function __construct() {
40 add_shortcode( 'sure_trigger_link', [ $this, 'sure_trigger_link' ] );
41 add_action( 'init', [ $this, 'sure_trigger_link_click_action' ] );
42 add_shortcode( 'sure_trigger_btn', [ $this, 'sure_trigger_btn' ] );
43 add_action( 'init', [ $this, 'sure_trigger_btn_click_action' ] );
44 }
45
46 /**
47 * Return the HTML template that is displayed by the shortcode
48 *
49 * @param array $atts The attributes passed in the the shortcode.
50 * @param string $content The content contained by the shortcode.
51 *
52 * @return string|void|bool
53 */
54 public static function sure_trigger_btn( $atts, $content = null ) {
55 $atts = shortcode_atts(
56 [
57 'id' => 0,
58 'label' => __( 'Click here', 'suretriggers' ),
59 ],
60 $atts,
61 'sure_trigger_btn'
62 );
63
64 if ( empty( $atts['id'] ) || 0 === intval( $atts['id'] ) ) {
65 return;
66 }
67
68 global $post;
69 $button_args = '';
70 if ( ! empty( $post ) && isset( $post->ID ) && isset( $post->post_title ) ) {
71 $button_args = '<input type="hidden" name="sure_trigger_button_post_id" value="' . $post->ID . '" />';
72 $button_args .= '<input type="hidden" name="sure_trigger_button_post_title" value="' . $post->post_title . '" />';
73 }
74
75 ob_start();
76 ?>
77 <form method="post" class="sure_trigger_button_form" id="sure_trigger_button_form_<?php echo esc_attr( $atts['id'] ); ?>">
78 <input type="hidden" name="sure_trigger_id" value="<?php echo esc_attr( $atts['id'] ); ?>"/><?php echo esc_html( $button_args ); ?>
79 <input type="hidden" name="sure_trigger_nonce" value="<?php echo esc_attr( wp_create_nonce( 'sure_trigger_btn_nonce' ) ); ?>"/>
80 <button type="submit" class="sure_trigger_button"><?php echo esc_html( $atts['label'] ); ?></button>
81 </form>
82 <?php
83 return ob_get_clean();
84 }
85
86 /**
87 * Handle button clicked action.
88 *
89 * @return void
90 */
91 public static function sure_trigger_btn_click_action() {
92 if ( ! isset( $_POST['sure_trigger_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['sure_trigger_nonce'] ) ), 'sure_trigger_btn_nonce' ) ) {
93 return;
94 }
95
96 $user_id = ap_get_current_user_id();
97 $ap_btn_trigger_id = isset( $_POST['sure_trigger_id'] ) ? sanitize_text_field( wp_unslash( $_POST['sure_trigger_id'] ) ) : '';
98
99 do_action( 'sure_trigger_user_clicks_btn', $ap_btn_trigger_id, $user_id );
100 }
101
102 /**
103 * Return the HTML template that is displayed by the shortcode
104 *
105 * @param array $atts The attributes passed in the the shortcode.
106 * @param string $content The content contained by the shortcode.
107 *
108 * @return string|void
109 */
110 public static function sure_trigger_link( $atts, $content = null ) {
111 $atts = shortcode_atts(
112 [
113 'id' => 0,
114 'text' => __( 'Click here', 'suretriggers' ),
115 ],
116 $atts,
117 'sure_trigger_link'
118 );
119
120 if ( empty( $atts['id'] ) || 0 === intval( $atts['id'] ) ) {
121 return;
122 }
123
124 $query_args = [];
125 global $post;
126 if ( ! empty( $post ) && isset( $post->ID ) && isset( $post->post_title ) ) {
127 $query_args['ap_link_post_id'] = $post->ID;
128 }
129 $query_args['ap_link_trigger_id'] = $atts['id'];
130 $query_args['ap_link_nonce'] = wp_create_nonce( 'sure_trigger_link_nonce' );
131 $link = add_query_arg( $query_args );
132
133 return '<a class="sure_trigger_link" href="' . $link . '">' . $atts['text'] . '</a>';
134 }
135
136 /**
137 * Handle link clicked action.
138 *
139 * @return void
140 */
141 public static function sure_trigger_link_click_action() {
142 $nonce = isset( $_GET['ap_link_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['ap_link_nonce'] ) ) : '';
143
144 if ( ! $nonce || ! wp_verify_nonce( $nonce, 'sure_trigger_link_nonce' ) ) {
145 return;
146 }
147
148 $user_id = ap_get_current_user_id();
149
150 $ap_link_trigger_id = absint( isset( $_GET['ap_link_trigger_id'] ) ? sanitize_text_field( wp_unslash( $_GET['ap_link_trigger_id'] ) ) : '' );
151
152 do_action( 'sure_trigger_user_clicks_link', $ap_link_trigger_id, $user_id );
153 $refresh = remove_query_arg( [ 'ap_link_trigger_id', 'ap_link_nonce', 'ap_link_post_id' ] );
154
155 wp_safe_redirect( $refresh );
156 exit();
157 }
158
159 /**
160 * Sure Triggers connection URL.
161 *
162 * @return string
163 */
164 public static function get_sure_triggers_url() {
165 return defined( 'SURE_TRIGGERS_URL' ) ? SURE_TRIGGERS_URL : apply_filters( 'sure_triggers_domain', 'https://staging-sc.bsf.io/' );
166 }
167
168 }
169
170 /**
171 * Ignore false positive
172 *
173 * @psalm-suppress UndefinedMethod
174 */
175 EventHelperController::get_instance();
176