AuthController.php
3 years ago
AutomationController.php
3 years ago
EventController.php
3 years ago
EventHelperController.php
3 years ago
GlobalSearchController.php
3 years ago
IntegrationsController.php
3 years ago
OptionController.php
3 years ago
RestController.php
3 years ago
RoutesController.php
3 years ago
SettingsController.php
3 years ago
GlobalSearchController.php
4667 lines
| 1 | <?php |
| 2 | /** |
| 3 | * GlobalSearchController. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category GlobalSearchController |
| 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 DOMDocument; |
| 17 | use FluentCrm\App\Models\CustomContactField; |
| 18 | use FluentCrm\App\Models\Subscriber; |
| 19 | use FluentCrm\App\Models\Tag; |
| 20 | use FluentCrm\Framework\Support\Arr; |
| 21 | use GFCommon; |
| 22 | use GFFormsModel; |
| 23 | use Give_Payment; |
| 24 | use MeprBaseRealGateway; |
| 25 | use MeprOptions; |
| 26 | use PrestoPlayer\Models\Video; |
| 27 | use RGFormsModel; |
| 28 | use SureTriggers\Integrations\AffiliateWP\AffiliateWP; |
| 29 | use SureTriggers\Integrations\EDD\EDD; |
| 30 | use SureTriggers\Integrations\LearnDash\LearnDash; |
| 31 | use SureTriggers\Integrations\LifterLMS\LifterLMS; |
| 32 | use SureTriggers\Integrations\MemberPress\MemberPress; |
| 33 | use SureTriggers\Integrations\PeepSo\PeepSo; |
| 34 | use SureTriggers\Integrations\RestrictContent\RestrictContent; |
| 35 | use SureTriggers\Integrations\TheEventCalendar\TheEventCalendar; |
| 36 | use SureTriggers\Integrations\WishlistMember\WishlistMember; |
| 37 | use SureTriggers\Integrations\WooCommerce\WooCommerce; |
| 38 | use SureTriggers\Integrations\WordPress\WordPress; |
| 39 | use SureTriggers\Models\Utilities; |
| 40 | use SureTriggers\Traits\SingletonLoader; |
| 41 | use Tribe__Tickets__Tickets_Handler; |
| 42 | use WC_Subscription; |
| 43 | use WC_Subscriptions_Product; |
| 44 | use WP_Query; |
| 45 | use WP_REST_Request; |
| 46 | use WP_REST_Response; |
| 47 | use WPForms_Form_Handler; |
| 48 | use CP_V2_Popups; |
| 49 | |
| 50 | /** |
| 51 | * GlobalSearchController- Add ajax related functions here. |
| 52 | * |
| 53 | * @category GlobalSearchController |
| 54 | * @package SureTriggers |
| 55 | * @author BSF <username@example.com> |
| 56 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 57 | * @link https://www.brainstormforce.com/ |
| 58 | * @since 1.0.0 |
| 59 | * |
| 60 | * @psalm-suppress UndefinedTrait |
| 61 | */ |
| 62 | class GlobalSearchController { |
| 63 | |
| 64 | use SingletonLoader; |
| 65 | |
| 66 | /** |
| 67 | * Search post by post type. |
| 68 | * |
| 69 | * @param array $data Search Params. |
| 70 | * |
| 71 | * @since 1.0.0 |
| 72 | * |
| 73 | * @return array |
| 74 | */ |
| 75 | public function search_post( $data ) { |
| 76 | $result = []; |
| 77 | $posts = Utilities::find_posts_by_title( $data ); |
| 78 | |
| 79 | foreach ( $posts['results'] as $post ) { |
| 80 | $result[] = [ |
| 81 | 'label' => $post['post_title'], |
| 82 | 'value' => $post['ID'], |
| 83 | ]; |
| 84 | } |
| 85 | |
| 86 | return [ |
| 87 | 'options' => $result, |
| 88 | 'hasMore' => $posts['has_more'], |
| 89 | ]; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Search Course. |
| 94 | * |
| 95 | * @param array $data quesry params. |
| 96 | * |
| 97 | * @return array |
| 98 | * @since 1.0.0 |
| 99 | */ |
| 100 | public function search_ld_course( $data ) { |
| 101 | $courses = get_posts( |
| 102 | [ |
| 103 | |
| 104 | 'post_type' => 'product', |
| 105 | 'meta_key' => '_related_course', |
| 106 | 'post_status' => 'publish', |
| 107 | ] |
| 108 | ); |
| 109 | $options = []; |
| 110 | foreach ( $courses as $course ) { |
| 111 | $options[] = [ |
| 112 | 'label' => $course->post_title, |
| 113 | 'value' => $course->ID, |
| 114 | ]; |
| 115 | } |
| 116 | |
| 117 | return [ |
| 118 | 'options' => $options, |
| 119 | 'hasMore' => false, |
| 120 | ]; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Search achievement by post type. |
| 125 | * |
| 126 | * @param array $data Search Params. |
| 127 | * |
| 128 | * @since 1.0.0 |
| 129 | * |
| 130 | * @return array |
| 131 | */ |
| 132 | public function search_achievements( $data ) { |
| 133 | $post = get_post( $data['dynamic'] ); |
| 134 | $slug = $post->post_name; |
| 135 | |
| 136 | $achievements = get_posts( |
| 137 | [ |
| 138 | 'post_type' => $slug, |
| 139 | 'post_status' => 'publish', |
| 140 | ] |
| 141 | ); |
| 142 | $options = []; |
| 143 | foreach ( $achievements as $achievement ) { |
| 144 | $options[] = [ |
| 145 | 'label' => $achievement->post_title, |
| 146 | 'value' => (string) $achievement->ID, |
| 147 | ]; |
| 148 | } |
| 149 | |
| 150 | return [ |
| 151 | 'options' => $options, |
| 152 | 'hasMore' => false, |
| 153 | ]; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Search Course. |
| 158 | * |
| 159 | * @param array $data quesry params. |
| 160 | * |
| 161 | * @return array |
| 162 | * @since 1.0.0 |
| 163 | */ |
| 164 | public function search_tutor_course( $data ) { |
| 165 | $courses = get_posts( |
| 166 | [ |
| 167 | 'post_type' => tutor()->course_post_type, |
| 168 | 'post_status' => 'publish', |
| 169 | 'numberposts' => '-1', |
| 170 | ] |
| 171 | ); |
| 172 | $options = []; |
| 173 | foreach ( $courses as $course ) { |
| 174 | $options[] = [ |
| 175 | 'label' => $course->post_title, |
| 176 | 'value' => $course->ID, |
| 177 | ]; |
| 178 | } |
| 179 | |
| 180 | return [ |
| 181 | 'options' => $options, |
| 182 | 'hasMore' => false, |
| 183 | ]; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Search Products. |
| 188 | * |
| 189 | * @param array $data quesry params. |
| 190 | * |
| 191 | * @return array |
| 192 | * @since 1.0.0 |
| 193 | */ |
| 194 | public function search_product( $data ) { |
| 195 | $result = []; |
| 196 | $posts = Utilities::find_posts_by_title( $data ); |
| 197 | |
| 198 | foreach ( $posts['results'] as $post ) { |
| 199 | $result[] = [ |
| 200 | 'label' => $post['post_title'], |
| 201 | 'value' => $post['post_title'], |
| 202 | ]; |
| 203 | } |
| 204 | |
| 205 | return [ |
| 206 | 'options' => $result, |
| 207 | 'hasMore' => $posts['has_more'], |
| 208 | ]; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Search Product Categories. |
| 213 | * |
| 214 | * @param array $data Search Params. |
| 215 | * |
| 216 | * @since 1.0.0 |
| 217 | */ |
| 218 | public function search_product_category( $data ) { |
| 219 | if ( ! empty( $data['dynamic'] ) ) { |
| 220 | $taxonomy = $data['dynamic']; |
| 221 | } else { |
| 222 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 223 | } |
| 224 | |
| 225 | $term = $data['term']; |
| 226 | $result = []; |
| 227 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 228 | foreach ( $terms['result'] as $tax_term ) { |
| 229 | $result[] = [ |
| 230 | 'label' => $tax_term->name, |
| 231 | 'value' => $tax_term->name, |
| 232 | ]; |
| 233 | } |
| 234 | |
| 235 | return [ |
| 236 | 'options' => $result, |
| 237 | 'hasMore' => $terms['has_more'], |
| 238 | ]; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Search Product Tags. |
| 243 | * |
| 244 | * @param array $data Search Params. |
| 245 | * |
| 246 | * @since 1.0.0 |
| 247 | */ |
| 248 | public function search_product_tags( $data ) { |
| 249 | if ( ! empty( $data['dynamic'] ) ) { |
| 250 | $taxonomy = $data['dynamic']; |
| 251 | } else { |
| 252 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 253 | } |
| 254 | |
| 255 | $term = $data['term']; |
| 256 | $result = []; |
| 257 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 258 | |
| 259 | foreach ( $terms['result'] as $tax_term ) { |
| 260 | $result[] = [ |
| 261 | 'label' => $tax_term->name, |
| 262 | 'value' => $tax_term->name, |
| 263 | ]; |
| 264 | } |
| 265 | |
| 266 | return [ |
| 267 | 'options' => $result, |
| 268 | 'hasMore' => $terms['has_more'], |
| 269 | ]; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Global ajax search. |
| 274 | * Here you need to add the field action name to work. |
| 275 | * |
| 276 | * @param WP_REST_Request $request Request data. |
| 277 | * |
| 278 | * @return WP_REST_Response |
| 279 | * @since 1.0.0 |
| 280 | */ |
| 281 | public function global_search( $request ) { |
| 282 | $post_type = $request->get_param( 'post_type' ); |
| 283 | $dynamic = $request->get_param( 'dynamic' ); |
| 284 | $search_term = $request->get_param( 'term' ); |
| 285 | $identifier = $request->get_param( 'field_identifier' ); |
| 286 | $page = max( 1, $request->get_param( 'page' ) ); |
| 287 | $taxonomy = $request->get_param( 'taxonomy' ) ? $request->get_param( 'taxonomy' ) : []; |
| 288 | |
| 289 | $filter = $request->get_param( 'filter' ) ? json_decode( stripslashes( $request->get_param( 'filter' ) ), true ) : []; |
| 290 | |
| 291 | $data = [ |
| 292 | 'dynamic' => $dynamic, |
| 293 | 'search_term' => $search_term, |
| 294 | 'page' => $page, |
| 295 | 'taxonomy' => $taxonomy, |
| 296 | 'filter' => $filter, |
| 297 | 'post_type' => $post_type, |
| 298 | ]; |
| 299 | $response = [ |
| 300 | 'hasMore' => false, |
| 301 | 'options' => [], |
| 302 | ]; |
| 303 | |
| 304 | $method_name = 'search_' . $identifier; |
| 305 | |
| 306 | if ( method_exists( $this, $method_name ) ) { |
| 307 | $response = $this->{$method_name}( $data ); |
| 308 | } else { |
| 309 | return RestController::error_message( 'Invalid field Identifier param.' ); |
| 310 | } |
| 311 | |
| 312 | return RestController::success_message( $response ); |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Search Taxonomy Terms. |
| 317 | * |
| 318 | * @param array $data Search Params. |
| 319 | * |
| 320 | * @since 1.0.0 |
| 321 | * |
| 322 | * @return array |
| 323 | */ |
| 324 | public function search_term( $data ) { |
| 325 | if ( ! empty( $data['dynamic'] ) ) { |
| 326 | $taxonomy = $data['dynamic']; |
| 327 | } else { |
| 328 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 329 | } |
| 330 | |
| 331 | $term = $data['term']; |
| 332 | $result = []; |
| 333 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 334 | foreach ( $terms['result'] as $tax_term ) { |
| 335 | $result[] = [ |
| 336 | 'label' => $tax_term->name, |
| 337 | 'value' => $tax_term->term_id, |
| 338 | ]; |
| 339 | } |
| 340 | |
| 341 | return [ |
| 342 | 'options' => $result, |
| 343 | 'hasMore' => $terms['has_more'], |
| 344 | ]; |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Search users. |
| 349 | * |
| 350 | * @param array $data Search Params. |
| 351 | * |
| 352 | * @since 1.0.0 |
| 353 | * |
| 354 | * @return array |
| 355 | */ |
| 356 | public function search_user( $data ) { |
| 357 | $result = []; |
| 358 | $page = $data['page']; |
| 359 | $users = Utilities::get_users( $data, $page ); |
| 360 | |
| 361 | if ( is_array( $users['results'] ) ) { |
| 362 | foreach ( $users['results'] as $user ) { |
| 363 | $result[] = [ |
| 364 | 'label' => $user->user_login, |
| 365 | 'value' => $user->ID, |
| 366 | ]; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | return [ |
| 371 | 'options' => $result, |
| 372 | 'hasMore' => $users['has_more'], |
| 373 | ]; |
| 374 | |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Search WPForm fields. |
| 379 | * |
| 380 | * @param array $data Search Params. |
| 381 | * |
| 382 | * @since 1.0.0 |
| 383 | * |
| 384 | * @return array |
| 385 | */ |
| 386 | public function search_pluggable_wpform_fields( $data ) { |
| 387 | $result = []; |
| 388 | $page = $data['page']; |
| 389 | $form_id = absint( $data['dynamic'] ); |
| 390 | $wpform_fields = Utilities::get_wpform_fields( $data['search_term'], $page, $form_id ); |
| 391 | |
| 392 | if ( is_array( $wpform_fields['results'] ) ) { |
| 393 | foreach ( $wpform_fields['results'] as $field ) { |
| 394 | $result[] = [ |
| 395 | 'label' => $field['label'], |
| 396 | 'value' => '{' . $field['id'] . '}', |
| 397 | ]; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return [ |
| 402 | 'options' => $result, |
| 403 | 'hasMore' => $wpform_fields['has_more'], |
| 404 | ]; |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Prepare variable products. |
| 409 | * |
| 410 | * @param array $data data. |
| 411 | * |
| 412 | * @return array |
| 413 | */ |
| 414 | public function search_variable_products( $data ) { |
| 415 | $products = Utilities::get_variable_products( $data['search_term'], $data['page'] ); |
| 416 | $options = []; |
| 417 | |
| 418 | foreach ( $products['result'] as $product ) { |
| 419 | $options[] = [ |
| 420 | 'label' => $product->get_title(), |
| 421 | 'value' => (string) $product->get_id(), |
| 422 | ]; |
| 423 | } |
| 424 | |
| 425 | return [ |
| 426 | 'options' => $options, |
| 427 | 'hasMore' => $products['has_more'], |
| 428 | ]; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Prepare variable products. |
| 433 | * |
| 434 | * @param array $data data. |
| 435 | * |
| 436 | * @return array |
| 437 | */ |
| 438 | public function search_product_variations( $data ) { |
| 439 | $variations = Utilities::get_product_variations( $data['dynamic'] ); |
| 440 | $options = []; |
| 441 | |
| 442 | foreach ( $variations['result'] as $product ) { |
| 443 | $options[] = [ |
| 444 | 'label' => ! empty( $product->post_excerpt ) ? $product->post_excerpt : $product->post_title, |
| 445 | 'value' => (string) $product->ID, |
| 446 | ]; |
| 447 | } |
| 448 | |
| 449 | return [ |
| 450 | 'options' => $options, |
| 451 | 'hasMore' => $variations['has_more'], |
| 452 | ]; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Search WooCommerce Subscriptions. |
| 457 | * |
| 458 | * @param array $data Search Params. |
| 459 | * |
| 460 | * @since 1.0.0 |
| 461 | * |
| 462 | * @return array |
| 463 | */ |
| 464 | public function search_subscription_variation( $data ) { |
| 465 | $subscription_products = Utilities::get_subscription_variation( $data['search_term'], $data['page'] ); |
| 466 | $result = []; |
| 467 | |
| 468 | if ( ! function_exists( 'wc_get_products' ) ) { |
| 469 | return $result; |
| 470 | } |
| 471 | |
| 472 | foreach ( $subscription_products['result'] as $post ) { |
| 473 | if ( $data['search_term'] ) { |
| 474 | if ( false !== stripos( $post->get_title(), $data['search_term'] ) ) { |
| 475 | $result[] = [ |
| 476 | 'label' => $post->get_title(), |
| 477 | 'value' => (string) $post->get_id(), |
| 478 | ]; |
| 479 | } |
| 480 | } else { |
| 481 | $result[] = [ |
| 482 | 'label' => $post->get_title(), |
| 483 | 'value' => (string) $post->get_id(), |
| 484 | ]; |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | return [ |
| 489 | 'options' => $result, |
| 490 | 'hasMore' => $subscription_products['has_more'], |
| 491 | ]; |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Prepare WooCommerce Payment Methods. |
| 496 | * |
| 497 | * @param array $data Search Params. |
| 498 | * @return array[] |
| 499 | */ |
| 500 | public function search_woo_payment_methods( $data ) { |
| 501 | $payment_methods = WC()->payment_gateways->get_available_payment_gateways(); |
| 502 | $options = []; |
| 503 | |
| 504 | if ( ! empty( $payment_methods ) ) { |
| 505 | foreach ( $payment_methods as $payment ) { |
| 506 | $options[] = [ |
| 507 | 'label' => $payment->title, |
| 508 | 'value' => $payment->id, |
| 509 | ]; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | return [ |
| 514 | 'options' => $options, |
| 515 | 'hasMore' => false, |
| 516 | ]; |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Prepare WooCommerce Order Status List. |
| 521 | * |
| 522 | * @param array $data Search Params. |
| 523 | * @return array[] |
| 524 | */ |
| 525 | public function search_woo_order_status_list( $data ) { |
| 526 | $order_status = wc_get_order_statuses(); |
| 527 | $options = []; |
| 528 | |
| 529 | if ( ! empty( $order_status ) ) { |
| 530 | foreach ( $order_status as $key => $status ) { |
| 531 | $options[] = [ |
| 532 | 'label' => $status, |
| 533 | 'value' => $key, |
| 534 | ]; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | return [ |
| 539 | 'options' => $options, |
| 540 | 'hasMore' => false, |
| 541 | ]; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Prepare WooCommerce Country List. |
| 546 | * |
| 547 | * @param array $data Search Params. |
| 548 | * @return array[] |
| 549 | */ |
| 550 | public function search_woo_country_list( $data ) { |
| 551 | $countries = WC()->countries->get_countries(); |
| 552 | $options = []; |
| 553 | |
| 554 | if ( ! empty( $countries ) ) { |
| 555 | foreach ( $countries as $key => $country ) { |
| 556 | $options[] = [ |
| 557 | 'label' => $country, |
| 558 | 'value' => $key, |
| 559 | ]; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | return [ |
| 564 | 'options' => $options, |
| 565 | 'hasMore' => false, |
| 566 | ]; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Prepare WooCommerce Country States List. |
| 571 | * |
| 572 | * @param array $data Search Params. |
| 573 | * @return array[] |
| 574 | */ |
| 575 | public function search_woo_country_state_list( $data ) { |
| 576 | if ( ! empty( $data['dynamic']['shipping_country'] ) ) { |
| 577 | $cc = $data['dynamic']['shipping_country']; |
| 578 | } else { |
| 579 | $cc = $data['dynamic']; |
| 580 | } |
| 581 | |
| 582 | $states = WC()->countries->get_states( $cc ); |
| 583 | |
| 584 | $options = []; |
| 585 | if ( ! empty( $states ) ) { |
| 586 | foreach ( $states as $key => $state ) { |
| 587 | $options[] = [ |
| 588 | 'label' => $state, |
| 589 | 'value' => $key, |
| 590 | ]; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | return [ |
| 595 | 'options' => $options, |
| 596 | 'hasMore' => false, |
| 597 | ]; |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * Get Memberpress gatways (payment methods) for subscription. |
| 602 | * |
| 603 | * @param array $data QueryParams. |
| 604 | * |
| 605 | * @return array |
| 606 | * @since 1.0.0 |
| 607 | */ |
| 608 | public function search_memberpress_gayways( $data ) { |
| 609 | $mp_options = MeprOptions::fetch(); |
| 610 | |
| 611 | $pms = array_keys( $mp_options->integrations ); |
| 612 | $gateways = []; |
| 613 | |
| 614 | foreach ( $pms as $pm_id ) { |
| 615 | $obj = $mp_options->payment_method( $pm_id ); |
| 616 | if ( $obj instanceof MeprBaseRealGateway ) { |
| 617 | $gateways[] = [ |
| 618 | 'label' => sprintf( '%1$s (%2$s)', $obj->label, $obj->name ), |
| 619 | 'value' => $obj->id, |
| 620 | ]; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | return [ |
| 625 | 'options' => $gateways, |
| 626 | 'hasMore' => false, |
| 627 | ]; |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * Prepare roles. |
| 632 | * |
| 633 | * @param array $data data. |
| 634 | * |
| 635 | * @return array |
| 636 | */ |
| 637 | public function search_roles( $data ) { |
| 638 | if ( function_exists( 'get_editable_roles' ) ) { |
| 639 | $roles = get_editable_roles(); |
| 640 | } else { |
| 641 | $roles = wp_roles()->roles; |
| 642 | $roles = apply_filters( 'editable_roles', $roles ); |
| 643 | } |
| 644 | |
| 645 | $options = []; |
| 646 | foreach ( $roles as $role => $details ) { |
| 647 | |
| 648 | $options[] = [ |
| 649 | 'label' => $details['name'], |
| 650 | 'value' => $role, |
| 651 | ]; |
| 652 | |
| 653 | } |
| 654 | |
| 655 | return [ |
| 656 | 'options' => $options, |
| 657 | 'hasMore' => false, |
| 658 | ]; |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Fetch operators. |
| 663 | * |
| 664 | * @return array |
| 665 | */ |
| 666 | public function search_condition_operators() { |
| 667 | return [ |
| 668 | 'options' => EventHelperController::get_instance()->prepare_operators(), |
| 669 | 'hasMore' => false, |
| 670 | ]; |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * Prepare post types. |
| 675 | * |
| 676 | * @param array $data data. |
| 677 | * |
| 678 | * @return array |
| 679 | */ |
| 680 | public function search_post_types( $data ) { |
| 681 | $post_types = get_post_types( [ 'public' => true ], 'object' ); |
| 682 | $post_types = apply_filters( 'suretriggers_post_types', $post_types ); |
| 683 | if ( isset( $post_types['attachment'] ) ) { |
| 684 | unset( $post_types['attachment'] ); |
| 685 | } |
| 686 | |
| 687 | $options = []; |
| 688 | foreach ( $post_types as $post_type => $details ) { |
| 689 | $options[] = [ |
| 690 | 'label' => $details->label, |
| 691 | 'value' => $post_type, |
| 692 | ]; |
| 693 | } |
| 694 | |
| 695 | return [ |
| 696 | 'options' => $options, |
| 697 | 'hasMore' => false, |
| 698 | ]; |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Get post statuses. |
| 703 | * |
| 704 | * @param array $data data. |
| 705 | * |
| 706 | * @return array |
| 707 | */ |
| 708 | public function search_post_statuses( $data ) { |
| 709 | $post_statuses = get_post_stati( [], 'objects' ); |
| 710 | $post_statuses = apply_filters( 'suretriggers_post_types', $post_statuses ); |
| 711 | $options = []; |
| 712 | |
| 713 | foreach ( $post_statuses as $post_status => $details ) { |
| 714 | if ( 'woocommerce' === $details->label_count['domain'] ) { |
| 715 | $options[] = [ |
| 716 | 'label' => 'WooCommerce - ' . $details->label, |
| 717 | 'value' => $post_status, |
| 718 | ]; |
| 719 | } else { |
| 720 | $options[] = [ |
| 721 | 'label' => $details->label, |
| 722 | 'value' => $post_status, |
| 723 | ]; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | return [ |
| 728 | 'options' => $options, |
| 729 | 'hasMore' => false, |
| 730 | ]; |
| 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Get Taxonomies. |
| 735 | * |
| 736 | * @param array $data data. |
| 737 | * |
| 738 | * @return array |
| 739 | */ |
| 740 | public function search_taxonomy_list( $data ) { |
| 741 | $taxonomies = get_taxonomies( [ 'public' => true ], 'objects' ); |
| 742 | $options = []; |
| 743 | $options[0] = [ |
| 744 | 'label' => 'Any Taxonomy', |
| 745 | 'value' => -1, |
| 746 | ]; |
| 747 | |
| 748 | foreach ( $taxonomies as $taxonomy => $taxonomy_obj ) { |
| 749 | $options[] = [ |
| 750 | 'label' => $taxonomy_obj->label, |
| 751 | 'value' => $taxonomy_obj->name, |
| 752 | ]; |
| 753 | } |
| 754 | |
| 755 | return [ |
| 756 | 'options' => $options, |
| 757 | 'hasMore' => false, |
| 758 | ]; |
| 759 | } |
| 760 | |
| 761 | /** |
| 762 | * Get WPForms. |
| 763 | * |
| 764 | * @param array $data data. |
| 765 | * |
| 766 | * @return array |
| 767 | */ |
| 768 | public function search_wp_forms( $data ) { |
| 769 | if ( ! class_exists( 'WPForms_Form_Handler' ) ) { |
| 770 | return; |
| 771 | } |
| 772 | |
| 773 | $wpforms = new WPForms_Form_Handler(); |
| 774 | $forms = $wpforms->get( '', [ 'orderby' => 'title' ] ); |
| 775 | $options = []; |
| 776 | |
| 777 | if ( ! empty( $forms ) ) { |
| 778 | foreach ( $forms as $form ) { |
| 779 | $options[] = [ |
| 780 | 'label' => $form->post_title, |
| 781 | 'value' => $form->ID, |
| 782 | ]; |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | return [ |
| 787 | 'options' => $options, |
| 788 | 'hasMore' => false, |
| 789 | ]; |
| 790 | } |
| 791 | |
| 792 | /** |
| 793 | * Get Gravity Forms. |
| 794 | * |
| 795 | * @param array $data data. |
| 796 | * |
| 797 | * @return array |
| 798 | */ |
| 799 | public function search_gravity_forms( $data ) { |
| 800 | if ( ! class_exists( 'GFFormsModel' ) ) { |
| 801 | return; |
| 802 | } |
| 803 | |
| 804 | $forms = GFFormsModel::get_forms(); |
| 805 | $options = []; |
| 806 | |
| 807 | if ( ! empty( $forms ) ) { |
| 808 | foreach ( $forms as $form ) { |
| 809 | $options[] = [ |
| 810 | 'label' => $form->title, |
| 811 | 'value' => $form->id, |
| 812 | ]; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | return [ |
| 817 | 'options' => $options, |
| 818 | 'hasMore' => false, |
| 819 | ]; |
| 820 | } |
| 821 | |
| 822 | /** |
| 823 | * Get tag & contact details. |
| 824 | * |
| 825 | * @param array $data data. |
| 826 | * |
| 827 | * @return array |
| 828 | */ |
| 829 | public function search_pluggables_fluentcrm_contact_added_to_tags( $data ) { |
| 830 | $context = []; |
| 831 | $pluggable_data = []; |
| 832 | $tag_id = $data['filter']; |
| 833 | |
| 834 | if ( $tag_id > 0 ) { |
| 835 | $tags = Tag::where( 'id', $tag_id )->first(); |
| 836 | } else { |
| 837 | $tags = Tag::orderBy( 'id', 'DESC' )->first(); |
| 838 | } |
| 839 | $contact = Subscriber::orderBy( 'id', 'DESC' )->first(); |
| 840 | if ( $contact ) { |
| 841 | $pluggable_data['contact'] = $contact; |
| 842 | $context['tag_id'] = $tag_id; |
| 843 | $pluggable_data['tag'] = $tags; |
| 844 | $context['response_type'] = 'live'; |
| 845 | } else { |
| 846 | $pluggable_data['conatct']['full_name'] = 'Test User'; |
| 847 | $pluggable_data['conatct']['first_name'] = 'Test'; |
| 848 | $pluggable_data['conatct']['last_name'] = 'User'; |
| 849 | $pluggable_data['conatct']['company_id'] = 112; |
| 850 | $pluggable_data['conatct']['email'] = 'testuser@gmail.com'; |
| 851 | $pluggable_data['conatct']['address_line_1'] = '33, Vincent Road'; |
| 852 | $pluggable_data['conatct']['address_line_2'] = 'Chicago Street'; |
| 853 | $pluggable_data['conatct']['postal_code'] = '212342'; |
| 854 | $pluggable_data['conatct']['city'] = 'New York City'; |
| 855 | $pluggable_data['conatct']['state'] = 'New York'; |
| 856 | $pluggable_data['conatct']['country'] = 'USA'; |
| 857 | $pluggable_data['conatct']['phone'] = '9992191911'; |
| 858 | $pluggable_data['conatct']['status'] = 'subscribed'; |
| 859 | $pluggable_data['conatct']['contact_type'] = 'lead'; |
| 860 | $pluggable_data['conatct']['source'] = ''; |
| 861 | $pluggable_data['conatct']['date_of_birth'] = '2022-11-09'; |
| 862 | $context['tag_id'] = 1; |
| 863 | $pluggable_data['tag'] = |
| 864 | [ |
| 865 | 'id' => '1', |
| 866 | 'title' => 'new', |
| 867 | 'slug' => 'new', |
| 868 | 'description' => null, |
| 869 | 'created_at' => '2023-01-19 10:23:23', |
| 870 | 'updated_at' => '2023-01-19 10:23:23', |
| 871 | 'pivot' => [ |
| 872 | 'subscriber_id' => '1', |
| 873 | 'object_id' => '1', |
| 874 | 'object_type' => 'FluentCrm\\App\\Models\\Tag', |
| 875 | 'created_at' => '2023-01-19 10:42:55', |
| 876 | 'updated_at' => '2023-01-19 10:42:55', |
| 877 | |
| 878 | ], |
| 879 | ]; |
| 880 | $context['response_type'] = 'sample'; |
| 881 | } |
| 882 | |
| 883 | $context['pluggable_data'] = $pluggable_data; |
| 884 | return $context; |
| 885 | } |
| 886 | |
| 887 | /** |
| 888 | * Get Divi Forms. |
| 889 | * |
| 890 | * @param array $data data. |
| 891 | * |
| 892 | * @return array |
| 893 | */ |
| 894 | public function search_divi_forms( $data ) { |
| 895 | $form_posts = Utilities::get_divi_forms(); |
| 896 | $options = []; |
| 897 | |
| 898 | if ( empty( $form_posts ) ) { |
| 899 | return [ |
| 900 | 'options' => [], |
| 901 | 'hasMore' => false, |
| 902 | ]; |
| 903 | } |
| 904 | |
| 905 | foreach ( $form_posts as $form_post ) { |
| 906 | $pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/'; |
| 907 | preg_match_all( $pattern_regex, $form_post['post_content'], $forms, PREG_SET_ORDER ); |
| 908 | if ( empty( $forms ) ) { |
| 909 | continue; |
| 910 | } |
| 911 | |
| 912 | $count = 0; |
| 913 | |
| 914 | foreach ( $forms as $form ) { |
| 915 | $pattern_form = get_shortcode_regex( [ 'et_pb_contact_form' ] ); |
| 916 | preg_match_all( "/$pattern_form/", $form[0], $forms_extracted, PREG_SET_ORDER ); |
| 917 | |
| 918 | if ( empty( $forms_extracted ) ) { |
| 919 | continue; |
| 920 | } |
| 921 | |
| 922 | foreach ( $forms_extracted as $form_extracted ) { |
| 923 | $form_attrs = shortcode_parse_atts( $form_extracted[3] ); |
| 924 | $form_id = isset( $form_attrs['_unique_id'] ) ? $form_attrs['_unique_id'] : ''; |
| 925 | if ( empty( $form_id ) ) { |
| 926 | continue; |
| 927 | } |
| 928 | $form_id = sprintf( '%d-%s', $form_post['ID'], $form_id ); |
| 929 | $form_title = isset( $form_attrs['title'] ) ? $form_attrs['title'] : ''; |
| 930 | $form_title = sprintf( '%s %s', $form_post['post_title'], $form_title ); |
| 931 | $options[] = [ |
| 932 | 'label' => $form_title, |
| 933 | 'value' => $form_id, |
| 934 | ]; |
| 935 | } |
| 936 | $count++; |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | return [ |
| 941 | 'options' => $options, |
| 942 | 'hasMore' => false, |
| 943 | ]; |
| 944 | } |
| 945 | |
| 946 | /** |
| 947 | * Get Comment Pluggable data. |
| 948 | * |
| 949 | * @param array $data data. |
| 950 | * |
| 951 | * @return array |
| 952 | */ |
| 953 | public function search_pluggables_wp_insert_comment( $data ) { |
| 954 | $context = []; |
| 955 | $post_data = []; |
| 956 | $args = [ |
| 957 | 'number' => '1', |
| 958 | 'status' => 'approve', |
| 959 | ]; |
| 960 | |
| 961 | if ( isset( $data['filter']['post']['value'] ) ) { |
| 962 | $post_id = $data['filter']['post']['value']; |
| 963 | if ( $post_id > 0 ) { |
| 964 | $args['post_id'] = $post_id; |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | $comments = get_comments( $args ); |
| 969 | if ( empty( $comments ) ) { |
| 970 | unset( $args['post_id'] ); |
| 971 | $comments = get_comments( $args ); |
| 972 | } |
| 973 | $context['context_data'] = $data; |
| 974 | $context['context_args'] = $args; |
| 975 | if ( ! empty( $comments ) ) { |
| 976 | foreach ( $comments as $comment ) : |
| 977 | if ( is_object( $comment ) ) { |
| 978 | $comment = get_object_vars( $comment ); |
| 979 | } |
| 980 | $post = get_post( absint( $comment['comment_post_ID'] ) ); |
| 981 | $user_email = $comment['comment_author_email']; |
| 982 | $user = get_user_by( 'email', $user_email ); |
| 983 | $context['pluggable_data'] = [ |
| 984 | 'post' => $post->ID, |
| 985 | 'post_title' => $post->post_title, |
| 986 | 'comment_id' => $comment['comment_ID'], |
| 987 | 'comment' => $comment['comment_content'], |
| 988 | ]; |
| 989 | if ( $user ) { |
| 990 | $context['pluggable_data']['wp_user_id'] = $user->ID; |
| 991 | $context['pluggable_data']['user_login'] = $user->user_login; |
| 992 | $context['pluggable_data']['display_name'] = $user->display_name; |
| 993 | $context['pluggable_data']['user_firstname'] = $user->user_firstname; |
| 994 | $context['pluggable_data']['user_lastname'] = $user->user_lastname; |
| 995 | $context['pluggable_data']['user_email'] = $user->user_email; |
| 996 | $context['pluggable_data']['user_role'] = $user->roles; |
| 997 | } |
| 998 | |
| 999 | $context['response_type'] = 'live'; |
| 1000 | endforeach; |
| 1001 | } else { |
| 1002 | $sample_comment = [ |
| 1003 | 'post' => 100, |
| 1004 | 'post_title' => 'Sample Post', |
| 1005 | 'comment_id' => 101, |
| 1006 | 'comment' => 'Sample Comment', |
| 1007 | ]; |
| 1008 | $sample_comment['wp_user_id'] = 7; |
| 1009 | $sample_comment['user_login'] = 'testuser@gmail.com'; |
| 1010 | $sample_comment['display_name'] = 'Test User'; |
| 1011 | $sample_comment['user_firstname'] = 'Test'; |
| 1012 | $sample_comment['user_lastname'] = 'User'; |
| 1013 | $sample_comment['user_email'] = 'testuser@gmail.com'; |
| 1014 | $sample_comment['user_role'] = [ 'Subscriber' ]; |
| 1015 | |
| 1016 | $context['pluggable_data'] = $sample_comment; |
| 1017 | $context['response_type'] = 'sample'; |
| 1018 | } |
| 1019 | return $context; |
| 1020 | } |
| 1021 | |
| 1022 | /** |
| 1023 | * User reset password. |
| 1024 | * |
| 1025 | * @param array $data data. |
| 1026 | * @return array |
| 1027 | */ |
| 1028 | public function search_pluggables_user_reset_password( $data ) { |
| 1029 | $user_context = $this->search_pluggables_add_user_role( $data ); |
| 1030 | $user_context['pluggable_data']['new_password'] = '***password***'; |
| 1031 | return $user_context; |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * User pluggable data. |
| 1036 | * |
| 1037 | * @param array $data data. |
| 1038 | * @return array |
| 1039 | */ |
| 1040 | public function search_pluggables_add_user_role( $data ) { |
| 1041 | $context = []; |
| 1042 | $args = [ |
| 1043 | 'meta_key' => 'last_update', |
| 1044 | 'order' => 'DESC', |
| 1045 | 'number' => 1, |
| 1046 | ]; |
| 1047 | |
| 1048 | if ( isset( $data['filter']['role']['value'] ) ) { |
| 1049 | $role = $data['filter']['role']['value']; |
| 1050 | $args['role'] = $role; |
| 1051 | } |
| 1052 | if ( isset( $data['filter']['new_role']['value'] ) ) { |
| 1053 | $role = $data['filter']['new_role']['value']; |
| 1054 | $args['role'] = $role; |
| 1055 | } |
| 1056 | |
| 1057 | $users = get_users( $args ); |
| 1058 | |
| 1059 | if ( isset( $data['filter']['meta_key']['value'] ) ) { |
| 1060 | $meta_key = $data['filter']['meta_key']['value']; |
| 1061 | $args['st_meta_key'] = $meta_key; |
| 1062 | } |
| 1063 | |
| 1064 | if ( isset( $data['filter']['profile_field']['value'] ) ) { |
| 1065 | $meta_key = $data['filter']['profile_field']['value']; |
| 1066 | $args['profile_field'] = $meta_key; |
| 1067 | } |
| 1068 | |
| 1069 | if ( ! empty( $users ) ) { |
| 1070 | $user = $users[0]; |
| 1071 | $pluggable_data = []; |
| 1072 | $pluggable_data['wp_user_id'] = $user->ID; |
| 1073 | $pluggable_data['user_login'] = $user->user_login; |
| 1074 | $pluggable_data['display_name'] = $user->display_name; |
| 1075 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 1076 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 1077 | $pluggable_data['user_email'] = $user->user_email; |
| 1078 | $pluggable_data['user_role'] = $user->roles; |
| 1079 | |
| 1080 | if ( isset( $args['st_meta_key'] ) ) { |
| 1081 | $pluggable_data['meta_key'] = $args['st_meta_key']; |
| 1082 | $pluggable_data['meta_value'] = get_user_meta( $user->ID, $args['st_meta_key'], true ); |
| 1083 | } |
| 1084 | if ( isset( $args['profile_field'] ) ) { |
| 1085 | $userdata = get_userdata( $user->ID ); |
| 1086 | $userdata = json_decode( wp_json_encode( $userdata->data ), true ); |
| 1087 | |
| 1088 | $pluggable_data['profile_field'] = $args['profile_field']; |
| 1089 | $pluggable_data['profile_field_value'] = $userdata[ $args['profile_field'] ]; |
| 1090 | } |
| 1091 | $context['pluggable_data'] = $pluggable_data; |
| 1092 | $context['response_type'] = 'live'; |
| 1093 | } else { |
| 1094 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 1095 | $context['pluggable_data'] = [ |
| 1096 | 'wp_user_id' => 1, |
| 1097 | 'user_login' => 'admin', |
| 1098 | 'display_name' => 'Test User', |
| 1099 | 'user_firstname' => 'Test', |
| 1100 | 'user_lastname' => 'User', |
| 1101 | 'user_email' => 'testuser@gmail.com', |
| 1102 | 'user_role' => [ $role ], |
| 1103 | ]; |
| 1104 | if ( isset( $args['st_meta_key'] ) ) { |
| 1105 | $context['pluggable_data']['meta_key'] = $args['st_meta_key']; |
| 1106 | $context['pluggable_data']['meta_value'] = 'test meta value'; |
| 1107 | } |
| 1108 | if ( isset( $args['profile_field'] ) ) { |
| 1109 | $context['pluggable_data']['profile_field'] = $args['profile_field']; |
| 1110 | $context['pluggable_data']['profile_field_value'] = 'Profile Field Value'; |
| 1111 | } |
| 1112 | $context['response_type'] = 'sample'; |
| 1113 | } |
| 1114 | return $context; |
| 1115 | } |
| 1116 | |
| 1117 | /** |
| 1118 | * User pluggable data. |
| 1119 | * |
| 1120 | * @param array $data data. |
| 1121 | * @return array |
| 1122 | */ |
| 1123 | public function search_pluggables_last_user_login( $data ) { |
| 1124 | $context = []; |
| 1125 | $args = [ |
| 1126 | 'orderby' => 'meta_value', |
| 1127 | 'meta_key' => 'st_last_login', |
| 1128 | 'order' => 'DESC', |
| 1129 | 'number' => 1, |
| 1130 | ]; |
| 1131 | $users = get_users( $args ); |
| 1132 | |
| 1133 | if ( ! empty( $users ) ) { |
| 1134 | $user = $users[0]; |
| 1135 | $pluggable_data = []; |
| 1136 | $pluggable_data['wp_user_id'] = $user->ID; |
| 1137 | $pluggable_data['user_login'] = $user->user_login; |
| 1138 | $pluggable_data['display_name'] = $user->display_name; |
| 1139 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 1140 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 1141 | $pluggable_data['user_email'] = $user->user_email; |
| 1142 | $pluggable_data['user_role'] = $user->roles; |
| 1143 | |
| 1144 | $context['pluggable_data'] = $pluggable_data; |
| 1145 | $context['response_type'] = 'live'; |
| 1146 | } else { |
| 1147 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 1148 | $context['pluggable_data'] = [ |
| 1149 | 'wp_user_id' => 1, |
| 1150 | 'user_login' => 'admin', |
| 1151 | 'display_name' => 'Test User', |
| 1152 | 'user_firstname' => 'Test', |
| 1153 | 'user_lastname' => 'User', |
| 1154 | 'user_email' => 'testuser@gmail.com', |
| 1155 | 'user_role' => [ $role ], |
| 1156 | ]; |
| 1157 | $context['response_type'] = 'sample'; |
| 1158 | } |
| 1159 | return $context; |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * Donation pluggable data. |
| 1164 | * |
| 1165 | * @param array $data data. |
| 1166 | * @return array |
| 1167 | */ |
| 1168 | public function search_pluggables_wordpress_post( $data ) { |
| 1169 | $context = []; |
| 1170 | $args = [ |
| 1171 | 'post_type' => 'any', |
| 1172 | 'posts_per_page' => 1, |
| 1173 | 'orderby' => 'modified', |
| 1174 | 'order' => 'DESC', |
| 1175 | ]; |
| 1176 | |
| 1177 | if ( isset( $data['filter']['post_type']['value'] ) ) { |
| 1178 | $post_type = $data['filter']['post_type']['value']; |
| 1179 | $args['post_type'] = $post_type; |
| 1180 | } |
| 1181 | |
| 1182 | if ( isset( $data['filter']['status']['value'] ) ) { |
| 1183 | $post_status = $data['filter']['status']['value']; |
| 1184 | $args['post_status'] = $post_status; |
| 1185 | } |
| 1186 | |
| 1187 | if ( isset( $data['filter']['post_status']['value'] ) ) { |
| 1188 | $post_status = $data['filter']['post_status']['value']; |
| 1189 | $args['post_status'] = $post_status; |
| 1190 | } |
| 1191 | |
| 1192 | if ( isset( $data['filter']['post']['value'] ) ) { |
| 1193 | $post_id = $data['filter']['post']['value']; |
| 1194 | if ( $post_id > 0 ) { |
| 1195 | $args['p'] = $post_id; |
| 1196 | unset( $args['post_status'] ); |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | $posts = get_posts( $args ); |
| 1201 | if ( ! empty( $posts ) ) { |
| 1202 | $context['pluggable_data'] = $posts[0]; |
| 1203 | $context['pluggable_data']->post = $posts[0]->ID; |
| 1204 | $context['response_type'] = 'live'; |
| 1205 | } else { |
| 1206 | $context['pluggable_data'] = [ |
| 1207 | 'ID' => 557, |
| 1208 | 'post' => 557, |
| 1209 | 'post_author' => 1, |
| 1210 | 'post_date' => '2022-11-18 12:18:14', |
| 1211 | 'post_date_gmt' => '2022-11-18 12:18:14', |
| 1212 | 'post_content' => 'Test Post Content', |
| 1213 | 'post_title' => 'Test Post', |
| 1214 | 'post_excerpt' => '', |
| 1215 | 'post_status' => $args['post_status'], |
| 1216 | 'comment_status' => 'open', |
| 1217 | 'ping_status' => 'open', |
| 1218 | 'post_password' => '', |
| 1219 | 'post_name' => 'test-post', |
| 1220 | 'to_ping' => '', |
| 1221 | 'pinged' => '', |
| 1222 | 'post_modified' => '2022-11-18 12:18:14', |
| 1223 | 'post_modified_gmt' => '2022-11-18 12:18:14', |
| 1224 | 'post_content_filtered' => '', |
| 1225 | 'post_parent' => 0, |
| 1226 | 'guid' => 'https://abc.com/test-post/', |
| 1227 | 'menu_order' => 0, |
| 1228 | 'post_type' => 'post', |
| 1229 | 'post_mime_type' => '', |
| 1230 | 'comment_count' => 0, |
| 1231 | 'filter' => 'raw', |
| 1232 | ]; |
| 1233 | $context['response_type'] = 'sample'; |
| 1234 | } |
| 1235 | |
| 1236 | return $context; |
| 1237 | } |
| 1238 | |
| 1239 | /** |
| 1240 | * Donation pluggable data |
| 1241 | * |
| 1242 | * @param array $data data. |
| 1243 | * @return array |
| 1244 | */ |
| 1245 | public function search_pluggables_givewp_donation_via_form( $data ) { |
| 1246 | global $wpdb; |
| 1247 | $context = []; |
| 1248 | $pluggable_data = []; |
| 1249 | |
| 1250 | $payment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type=%s ORDER BY id DESC LIMIT 1", 'give_payment' ) ); |
| 1251 | |
| 1252 | if ( ! empty( $payment ) ) { |
| 1253 | $payment = new Give_Payment( $payment->ID ); |
| 1254 | $address_data = $payment->address; |
| 1255 | |
| 1256 | $pluggable_data['first_name'] = $payment->first_name; |
| 1257 | $pluggable_data['last_name'] = $payment->last_name; |
| 1258 | $pluggable_data['email'] = $payment->email; |
| 1259 | $pluggable_data['currency'] = $payment->currency; |
| 1260 | $pluggable_data['donated_amount'] = $payment->subtotal; |
| 1261 | $pluggable_data['donation_amount'] = $payment->subtotal; |
| 1262 | $pluggable_data['form_id'] = (int) $payment->form_id; |
| 1263 | $pluggable_data['form_title'] = $payment->form_title; |
| 1264 | $pluggable_data['name_title_prefix'] = $payment->title_prefix; |
| 1265 | $pluggable_data['date'] = $payment->date; |
| 1266 | |
| 1267 | if ( is_array( $address_data ) ) { |
| 1268 | $pluggable_data['address_line_1'] = $address_data['line1']; |
| 1269 | $pluggable_data['address_line_2'] = $address_data['line2']; |
| 1270 | $pluggable_data['city'] = $address_data['city']; |
| 1271 | $pluggable_data['state'] = $address_data['state']; |
| 1272 | $pluggable_data['zip'] = $address_data['zip']; |
| 1273 | $pluggable_data['country'] = $address_data['country']; |
| 1274 | } |
| 1275 | $donor_comment = give_get_donor_donation_comment( $payment->ID, $payment->donor_id ); |
| 1276 | $pluggable_data['comment'] = isset( $doner['comment_content'] ) ? $donor_comment : ''; |
| 1277 | $context['response_type'] = 'live'; |
| 1278 | } else { |
| 1279 | $pluggable_data['first_name'] = 'Test'; |
| 1280 | $pluggable_data['last_name'] = 'User'; |
| 1281 | $pluggable_data['email'] = 'testuser@gmail.com'; |
| 1282 | $pluggable_data['currency'] = 'USD'; |
| 1283 | $pluggable_data['donated_amount'] = 100; |
| 1284 | $pluggable_data['donation_amount'] = 100; |
| 1285 | $pluggable_data['form_id'] = 23; |
| 1286 | $pluggable_data['form_title'] = 'Test Donation'; |
| 1287 | $pluggable_data['name_title_prefix'] = 'Mr'; |
| 1288 | $pluggable_data['date'] = '2022-11-07 16:06:05'; |
| 1289 | $pluggable_data['address_line_1'] = '33, Vincent Road'; |
| 1290 | $pluggable_data['address_line_2'] = 'Chicago Street'; |
| 1291 | $pluggable_data['city'] = 'New York City'; |
| 1292 | $pluggable_data['state'] = 'New York'; |
| 1293 | $pluggable_data['zip'] = '223131'; |
| 1294 | $pluggable_data['country'] = 'USA'; |
| 1295 | $pluggable_data['comment'] = 'Test Comment'; |
| 1296 | $context['response_type'] = 'sample'; |
| 1297 | } |
| 1298 | |
| 1299 | $context['pluggable_data'] = $pluggable_data; |
| 1300 | return $context; |
| 1301 | } |
| 1302 | |
| 1303 | /** |
| 1304 | * Search Divi Form fields. |
| 1305 | * |
| 1306 | * @param array $data Search Params. |
| 1307 | * |
| 1308 | * @since 1.0.0 |
| 1309 | * |
| 1310 | * @return array |
| 1311 | */ |
| 1312 | public function search_pluggable_divi_form_fields( $data ) { |
| 1313 | $result = []; |
| 1314 | $form_id = absint( $data['dynamic'] ); |
| 1315 | $form_posts = Utilities::get_divi_forms(); |
| 1316 | |
| 1317 | if ( empty( $form_posts ) ) { |
| 1318 | return [ |
| 1319 | 'options' => [], |
| 1320 | 'hasMore' => false, |
| 1321 | ]; |
| 1322 | } |
| 1323 | |
| 1324 | foreach ( $form_posts as $form_post ) { |
| 1325 | $pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/'; |
| 1326 | preg_match_all( $pattern_regex, $form_post['post_content'], $forms, PREG_SET_ORDER ); |
| 1327 | if ( empty( $forms ) ) { |
| 1328 | continue; |
| 1329 | } |
| 1330 | |
| 1331 | $count = 0; |
| 1332 | |
| 1333 | foreach ( $forms as $form ) { |
| 1334 | $pattern = get_shortcode_regex( [ 'et_pb_contact_field' ] ); |
| 1335 | |
| 1336 | preg_match_all( "/$pattern/", $form[0], $contact_fields, PREG_SET_ORDER ); |
| 1337 | |
| 1338 | if ( empty( $contact_fields ) ) { |
| 1339 | return $fields; |
| 1340 | } |
| 1341 | |
| 1342 | foreach ( $contact_fields as $contact_field ) { |
| 1343 | $contact_field_attrs = shortcode_parse_atts( $contact_field[3] ); |
| 1344 | $field_id = strtolower( self::array_get( $contact_field_attrs, 'field_id' ) ); |
| 1345 | $fields[] = [ |
| 1346 | 'field_title' => self::array_get( $contact_field_attrs, 'field_title', __( 'No title', 'suretriggers' ) ), |
| 1347 | 'field_id' => $field_id, |
| 1348 | ]; |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | if ( is_array( $fields ) ) { |
| 1354 | foreach ( $fields as $field ) { |
| 1355 | $result[] = [ |
| 1356 | 'label' => $field['field_title'], |
| 1357 | 'value' => '{' . $field['field_id'] . '}', |
| 1358 | ]; |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | return [ |
| 1363 | 'options' => $result, |
| 1364 | 'hasMore' => false, |
| 1365 | ]; |
| 1366 | } |
| 1367 | |
| 1368 | /** |
| 1369 | * Pseudo function copied from Divi |
| 1370 | * |
| 1371 | * @param array $array An array which contains value located at `$address`. |
| 1372 | * @param string|array $address The location of the value within `$array` (dot notation). |
| 1373 | * @param mixed $default Value to return if not found. Default is an empty string. |
| 1374 | * |
| 1375 | * @return mixed The value, if found, otherwise $default. |
| 1376 | */ |
| 1377 | public static function array_get( $array, $address, $default = '' ) { |
| 1378 | $keys = is_array( $address ) ? $address : explode( '.', $address ); |
| 1379 | $value = $array; |
| 1380 | |
| 1381 | foreach ( $keys as $key ) { |
| 1382 | if ( ! empty( $key ) && isset( $key[0] ) && '[' === $key[0] ) { |
| 1383 | $index = substr( $key, 1, -1 ); |
| 1384 | |
| 1385 | if ( is_numeric( $index ) ) { |
| 1386 | $key = (int) $index; |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | if ( ! isset( $value[ $key ] ) ) { |
| 1391 | return $default; |
| 1392 | } |
| 1393 | |
| 1394 | $value = $value[ $key ]; |
| 1395 | } |
| 1396 | |
| 1397 | return $value; |
| 1398 | } |
| 1399 | |
| 1400 | /** |
| 1401 | * Get UAG Forms. |
| 1402 | * |
| 1403 | * @param array $data data. |
| 1404 | * |
| 1405 | * @return array |
| 1406 | */ |
| 1407 | public function search_spectra_forms( $data ) { |
| 1408 | $form_posts = Utilities::get_uag_forms(); |
| 1409 | |
| 1410 | $options = []; |
| 1411 | if ( empty( $form_posts ) ) { |
| 1412 | return [ |
| 1413 | 'options' => [], |
| 1414 | 'hasMore' => false, |
| 1415 | ]; |
| 1416 | } |
| 1417 | |
| 1418 | foreach ( $form_posts as $form_post ) { |
| 1419 | $blocks = parse_blocks( $form_post['post_content'] ); |
| 1420 | |
| 1421 | foreach ( $blocks as $block ) { |
| 1422 | if ( 'uagb/forms' === $block['blockName'] ) { |
| 1423 | $options[] = [ |
| 1424 | 'label' => $form_post['post_title'], |
| 1425 | 'value' => $block['attrs']['block_id'], |
| 1426 | ]; |
| 1427 | } |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | return [ |
| 1432 | 'options' => $options, |
| 1433 | 'hasMore' => false, |
| 1434 | ]; |
| 1435 | } |
| 1436 | |
| 1437 | /** |
| 1438 | * Search UAG Form fields. |
| 1439 | * |
| 1440 | * @param array $data Search Params. |
| 1441 | * |
| 1442 | * @since 1.0.0 |
| 1443 | * |
| 1444 | * @return array |
| 1445 | */ |
| 1446 | public function search_spectraform_fields( $data ) { |
| 1447 | $result = []; |
| 1448 | $form_id = absint( $data['dynamic'] ); |
| 1449 | $form_posts = Utilities::get_uag_forms(); |
| 1450 | |
| 1451 | if ( empty( $form_posts ) ) { |
| 1452 | return [ |
| 1453 | 'options' => [], |
| 1454 | 'hasMore' => false, |
| 1455 | ]; |
| 1456 | } |
| 1457 | |
| 1458 | foreach ( $form_posts as $form_post ) { |
| 1459 | $blocks = parse_blocks( $form_post['post_content'] ); |
| 1460 | |
| 1461 | foreach ( $blocks as $block ) { |
| 1462 | if ( (int) $block['attrs']['block_id'] === $form_id ) { |
| 1463 | $doc = new DOMDocument(); |
| 1464 | $rendered_block = render_block( $block ); |
| 1465 | $doc->loadHTML( $rendered_block ); |
| 1466 | $child_node_list = $doc->getElementsByTagName( 'div' ); |
| 1467 | for ( $i = 0; $i < $child_node_list->length; $i++ ) { |
| 1468 | $temp = $child_node_list->item( $i ); |
| 1469 | if ( $temp && stripos( $temp->getAttribute( 'class' ), 'uagb-forms-input-label' ) !== false ) { |
| 1470 | $nodes[] = $temp; |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | foreach ( $nodes as $node ) { |
| 1475 | $result[] = [ |
| 1476 | 'label' => $node->textContent, //phpcs:ignore |
| 1477 | 'value' => $node->textContent, //phpcs:ignore |
| 1478 | ]; |
| 1479 | } |
| 1480 | } |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | return [ |
| 1485 | 'options' => $result, |
| 1486 | 'hasMore' => false, |
| 1487 | ]; |
| 1488 | } |
| 1489 | |
| 1490 | /** |
| 1491 | * Get Fluent Forms. |
| 1492 | * |
| 1493 | * @param array $data data. |
| 1494 | * |
| 1495 | * @return array |
| 1496 | */ |
| 1497 | public function search_fluent_forms( $data ) { |
| 1498 | |
| 1499 | if ( ! function_exists( 'wpFluent' ) ) { |
| 1500 | return [ |
| 1501 | 'options' => [], |
| 1502 | 'hasMore' => false, |
| 1503 | ]; |
| 1504 | } |
| 1505 | |
| 1506 | $forms = wpFluent()->table( 'fluentform_forms' ) |
| 1507 | ->select( [ 'id', 'title' ] ) |
| 1508 | ->orderBy( 'id', 'DESC' ) |
| 1509 | ->get(); |
| 1510 | |
| 1511 | $options = []; |
| 1512 | if ( ! empty( $forms ) ) { |
| 1513 | foreach ( $forms as $form ) { |
| 1514 | $options[] = [ |
| 1515 | 'label' => $form->title, |
| 1516 | 'value' => $form->id, |
| 1517 | ]; |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | return [ |
| 1522 | 'options' => $options, |
| 1523 | 'hasMore' => false, |
| 1524 | ]; |
| 1525 | |
| 1526 | } |
| 1527 | |
| 1528 | /** |
| 1529 | * Get Fluent Forms. |
| 1530 | * |
| 1531 | * @param array $data data. |
| 1532 | * |
| 1533 | * @return array |
| 1534 | */ |
| 1535 | public function search_bricks_builder_forms( $data ) { |
| 1536 | $bricks_theme = wp_get_theme( 'bricks' ); |
| 1537 | if ( ! $bricks_theme->exists() ) { |
| 1538 | return [ |
| 1539 | 'options' => [], |
| 1540 | 'hasMore' => false, |
| 1541 | ]; |
| 1542 | } |
| 1543 | |
| 1544 | $args = [ |
| 1545 | 'post_type' => 'bricks_template', |
| 1546 | 'post_status' => 'publish', |
| 1547 | 'posts_per_page' => -1, |
| 1548 | ]; |
| 1549 | |
| 1550 | $templates = get_posts( $args ); |
| 1551 | |
| 1552 | $options = []; |
| 1553 | if ( ! empty( $templates ) ) { |
| 1554 | foreach ( $templates as $template ) { |
| 1555 | $fetch_content = get_post_meta( $template->ID, BRICKS_DB_PAGE_CONTENT, true ); |
| 1556 | if ( is_array( $fetch_content ) ) { |
| 1557 | foreach ( $fetch_content as $content ) { |
| 1558 | if ( 'form' === $content['name'] ) { |
| 1559 | $options[] = [ |
| 1560 | 'label' => $template->post_title . ' - ' . ( isset( $content['label'] ) ? $content['label'] : 'Form' ), |
| 1561 | 'value' => $content['id'], |
| 1562 | ]; |
| 1563 | } |
| 1564 | } |
| 1565 | } |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | return [ |
| 1570 | 'options' => $options, |
| 1571 | 'hasMore' => false, |
| 1572 | ]; |
| 1573 | |
| 1574 | } |
| 1575 | |
| 1576 | /** |
| 1577 | * Bricks builder form fields. |
| 1578 | * |
| 1579 | * @param array $data data. |
| 1580 | * @return array |
| 1581 | */ |
| 1582 | public function search_pluggable_bricks_builder_form_fields( $data ) { |
| 1583 | $result = []; |
| 1584 | $fields = []; |
| 1585 | $form_id_str = $data['dynamic']; |
| 1586 | $ids = explode( '_', $form_id_str ); |
| 1587 | $post_id = $ids[0]; |
| 1588 | $form_id = $ids[1]; |
| 1589 | $fetch_content = get_post_meta( $post_id, BRICKS_DB_PAGE_CONTENT, true ); |
| 1590 | if ( is_array( $fetch_content ) ) { |
| 1591 | foreach ( $fetch_content as $content ) { |
| 1592 | if ( 'form' === $content['name'] && $form_id === $content['id'] ) { |
| 1593 | $fields = $content['settings']['fields']; |
| 1594 | break; |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | if ( ! empty( $fields ) ) { |
| 1600 | foreach ( $fields as $field ) { |
| 1601 | $result[] = [ |
| 1602 | 'label' => $field['label'], |
| 1603 | 'value' => '{' . strtolower( $field['label'] ) . '}', |
| 1604 | ]; |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | return [ |
| 1609 | 'options' => $result, |
| 1610 | 'hasMore' => false, |
| 1611 | ]; |
| 1612 | } |
| 1613 | |
| 1614 | /** |
| 1615 | * Get fluent form fields |
| 1616 | * |
| 1617 | * @param array $data Data array. |
| 1618 | * |
| 1619 | * @return array |
| 1620 | */ |
| 1621 | public function search_pluggable_fluent_form_fields( $data ) { |
| 1622 | $result = []; |
| 1623 | $form_id = absint( $data['dynamic'] ); |
| 1624 | |
| 1625 | $fluentform_fields = Utilities::get_fluentform_fields( $data['search_term'], -1, $form_id ); |
| 1626 | |
| 1627 | if ( is_array( $fluentform_fields['results'] ) ) { |
| 1628 | foreach ( $fluentform_fields['results'] as $field ) { |
| 1629 | $result[] = [ |
| 1630 | 'label' => $field['text'], |
| 1631 | 'value' => "{{$field['value']}}", |
| 1632 | ]; |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | $result[] = [ |
| 1637 | 'value' => '{form_id}', |
| 1638 | 'label' => 'Form ID', |
| 1639 | ]; |
| 1640 | |
| 1641 | $result[] = [ |
| 1642 | 'value' => '{form_title}', |
| 1643 | 'label' => 'Form Title', |
| 1644 | ]; |
| 1645 | $result[] = [ |
| 1646 | 'value' => '{entry_id}', |
| 1647 | 'label' => 'Entry ID', |
| 1648 | ]; |
| 1649 | |
| 1650 | $result[] = [ |
| 1651 | 'value' => '{entry_source_url}', |
| 1652 | 'label' => 'Entry Source URL', |
| 1653 | ]; |
| 1654 | |
| 1655 | $result[] = [ |
| 1656 | 'value' => '{submission_date}', |
| 1657 | 'label' => 'Submission Date', |
| 1658 | ]; |
| 1659 | |
| 1660 | $result[] = [ |
| 1661 | 'value' => '{user_ip}', |
| 1662 | 'label' => 'User IP', |
| 1663 | ]; |
| 1664 | |
| 1665 | return [ |
| 1666 | 'options' => $result, |
| 1667 | 'hasMore' => false, |
| 1668 | ]; |
| 1669 | } |
| 1670 | |
| 1671 | /** |
| 1672 | * Search Gravity Form fields. |
| 1673 | * |
| 1674 | * @param array $data Search Params. |
| 1675 | * |
| 1676 | * @since 1.0.0 |
| 1677 | */ |
| 1678 | public function search_gform_fields( $data ) { |
| 1679 | if ( ! class_exists( 'RGFormsModel' ) ) { |
| 1680 | return [ |
| 1681 | 'options' => [], |
| 1682 | 'hasMore' => false, |
| 1683 | ]; |
| 1684 | } |
| 1685 | $result = []; |
| 1686 | $page = $data['page']; |
| 1687 | $form_id = absint( $data['dynamic'] ); |
| 1688 | |
| 1689 | $form = RGFormsModel::get_form_meta( $form_id ); |
| 1690 | |
| 1691 | if ( is_array( $form['fields'] ) ) { |
| 1692 | foreach ( $form['fields'] as $field ) { |
| 1693 | if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { |
| 1694 | foreach ( $field['inputs'] as $input ) { |
| 1695 | if ( ! isset( $input['isHidden'] ) || ( isset( $input['isHidden'] ) && ! $input['isHidden'] ) ) { |
| 1696 | $result[] = [ |
| 1697 | 'value' => $input['id'], |
| 1698 | 'label' => GFCommon::get_label( $field, $input['id'] ), |
| 1699 | ]; |
| 1700 | } |
| 1701 | } |
| 1702 | } elseif ( ! rgar( $field, 'displayOnly' ) ) { |
| 1703 | $result[] = [ |
| 1704 | 'value' => $field['id'], |
| 1705 | 'label' => GFCommon::get_label( $field ), |
| 1706 | ]; |
| 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | return [ |
| 1712 | 'options' => $result, |
| 1713 | 'hasMore' => false, |
| 1714 | ]; |
| 1715 | |
| 1716 | } |
| 1717 | |
| 1718 | /** |
| 1719 | * Search Gravity Form fields. |
| 1720 | * |
| 1721 | * @param array $data Search Params. |
| 1722 | * |
| 1723 | * @since 1.0.0 |
| 1724 | */ |
| 1725 | public function search_pluggable_gravity_form_fields( $data ) { |
| 1726 | if ( ! class_exists( 'RGFormsModel' ) ) { |
| 1727 | return [ |
| 1728 | 'options' => [], |
| 1729 | 'hasMore' => false, |
| 1730 | ]; |
| 1731 | } |
| 1732 | $result = []; |
| 1733 | $form_id = absint( $data['dynamic'] ); |
| 1734 | |
| 1735 | $form = RGFormsModel::get_form_meta( $form_id ); |
| 1736 | |
| 1737 | if ( is_array( $form['fields'] ) ) { |
| 1738 | foreach ( $form['fields'] as $field ) { |
| 1739 | if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { |
| 1740 | foreach ( $field['inputs'] as $input ) { |
| 1741 | if ( ! isset( $input['isHidden'] ) || ( isset( $input['isHidden'] ) && ! $input['isHidden'] ) ) { |
| 1742 | $result[] = [ |
| 1743 | 'value' => '{' . $input['id'] . '}', |
| 1744 | 'label' => GFCommon::get_label( $field, $input['id'] ), |
| 1745 | ]; |
| 1746 | } |
| 1747 | } |
| 1748 | } elseif ( ! rgar( $field, 'displayOnly' ) ) { |
| 1749 | $result[] = [ |
| 1750 | 'value' => '{' . $field['id'] . '}', |
| 1751 | 'label' => GFCommon::get_label( $field ), |
| 1752 | ]; |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | $result[] = [ |
| 1758 | 'value' => '{gravity_form}', |
| 1759 | 'label' => 'Form ID', |
| 1760 | ]; |
| 1761 | $result[] = [ |
| 1762 | 'value' => '{form_title}', |
| 1763 | 'label' => 'Form Title', |
| 1764 | ]; |
| 1765 | $result[] = [ |
| 1766 | 'value' => '{entry_id}', |
| 1767 | 'label' => 'Entry ID', |
| 1768 | ]; |
| 1769 | $result[] = [ |
| 1770 | 'value' => '{user_ip}', |
| 1771 | 'label' => 'User IP', |
| 1772 | ]; |
| 1773 | $result[] = [ |
| 1774 | 'value' => '{entry_source_url}', |
| 1775 | 'label' => 'Entry Source URL', |
| 1776 | ]; |
| 1777 | $result[] = [ |
| 1778 | 'value' => '{entry_submission_date}', |
| 1779 | 'label' => 'Entry Submission Date', |
| 1780 | ]; |
| 1781 | |
| 1782 | return [ |
| 1783 | 'options' => $result, |
| 1784 | 'hasMore' => false, |
| 1785 | ]; |
| 1786 | |
| 1787 | } |
| 1788 | |
| 1789 | /** |
| 1790 | * Prepare fluentcrm lists. |
| 1791 | * |
| 1792 | * @param array $data Search Params. |
| 1793 | * |
| 1794 | * @return array[] |
| 1795 | */ |
| 1796 | public function search_fluentcrm_lists( $data ) { |
| 1797 | |
| 1798 | $list_api = FluentCrmApi( 'lists' ); |
| 1799 | $all_lists = $list_api->all(); |
| 1800 | $options = []; |
| 1801 | |
| 1802 | if ( ! empty( $all_lists ) ) { |
| 1803 | foreach ( $all_lists as $list ) { |
| 1804 | $options[] = [ |
| 1805 | 'label' => $list->title, |
| 1806 | 'value' => $list->id, |
| 1807 | ]; |
| 1808 | } |
| 1809 | } |
| 1810 | |
| 1811 | return [ |
| 1812 | 'options' => $options, |
| 1813 | 'hasMore' => false, |
| 1814 | ]; |
| 1815 | } |
| 1816 | |
| 1817 | /** |
| 1818 | * Prepare fluentcrm contact status. |
| 1819 | * |
| 1820 | * @param array $data Search Params. |
| 1821 | * |
| 1822 | * @return array[] |
| 1823 | */ |
| 1824 | public function search_fluentcrm_contact_status( $data ) { |
| 1825 | |
| 1826 | $options = [ |
| 1827 | [ |
| 1828 | 'label' => __( 'Subscribed', 'suretriggers' ), |
| 1829 | 'value' => 'subscribed', |
| 1830 | ], |
| 1831 | [ |
| 1832 | 'label' => __( 'Pending', 'suretriggers' ), |
| 1833 | 'value' => 'pending', |
| 1834 | ], |
| 1835 | [ |
| 1836 | 'label' => __( 'Unsubscribed', 'suretriggers' ), |
| 1837 | 'value' => 'unsubscribed', |
| 1838 | ], |
| 1839 | [ |
| 1840 | 'label' => __( 'Bounced', 'suretriggers' ), |
| 1841 | 'value' => 'bounced', |
| 1842 | ], |
| 1843 | [ |
| 1844 | 'label' => __( 'Complained', 'suretriggers' ), |
| 1845 | 'value' => 'complained', |
| 1846 | ], |
| 1847 | ]; |
| 1848 | |
| 1849 | return [ |
| 1850 | 'options' => $options, |
| 1851 | 'hasMore' => false, |
| 1852 | ]; |
| 1853 | } |
| 1854 | |
| 1855 | /** |
| 1856 | * Prepare fluentcrm contact status. |
| 1857 | * |
| 1858 | * @param array $data Search Params. |
| 1859 | * |
| 1860 | * @return array[] |
| 1861 | */ |
| 1862 | public function search_fluentcrm_fetch_custom_fields( $data ) { |
| 1863 | |
| 1864 | $options = [ |
| 1865 | [ |
| 1866 | 'label' => __( 'Yes', 'suretriggers' ), |
| 1867 | 'value' => 'true', |
| 1868 | ], |
| 1869 | [ |
| 1870 | 'label' => __( 'No', 'suretriggers' ), |
| 1871 | 'value' => 'false', |
| 1872 | ], |
| 1873 | ]; |
| 1874 | |
| 1875 | return [ |
| 1876 | 'options' => $options, |
| 1877 | 'hasMore' => false, |
| 1878 | ]; |
| 1879 | } |
| 1880 | |
| 1881 | /** |
| 1882 | * Prepare fluentcrm tags. |
| 1883 | * |
| 1884 | * @param array $data Search Params. |
| 1885 | * |
| 1886 | * @return array[] |
| 1887 | */ |
| 1888 | public function search_fluentcrm_tags( $data ) { |
| 1889 | |
| 1890 | $tag_api = FluentCrmApi( 'tags' ); |
| 1891 | $all_tags = $tag_api->all(); |
| 1892 | $options = []; |
| 1893 | |
| 1894 | if ( ! empty( $all_tags ) ) { |
| 1895 | foreach ( $all_tags as $tag ) { |
| 1896 | $options[] = [ |
| 1897 | 'label' => $tag->title, |
| 1898 | 'value' => $tag->id, |
| 1899 | ]; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | return [ |
| 1904 | 'options' => $options, |
| 1905 | 'hasMore' => false, |
| 1906 | ]; |
| 1907 | } |
| 1908 | |
| 1909 | /** |
| 1910 | * Prepare Wishlist Memberlists level. |
| 1911 | * |
| 1912 | * @param array $data Search Params. |
| 1913 | * |
| 1914 | * @return array[] |
| 1915 | */ |
| 1916 | public function search_wishlistmember_lists( $data ) { |
| 1917 | |
| 1918 | $wlm_levels = wlmapi_get_levels(); |
| 1919 | $options = []; |
| 1920 | |
| 1921 | if ( ! empty( $wlm_levels ) ) { |
| 1922 | foreach ( $wlm_levels['levels']['level'] as $list ) { |
| 1923 | $options[] = [ |
| 1924 | 'label' => $list['name'], |
| 1925 | 'value' => (string) $list['id'], |
| 1926 | ]; |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | return [ |
| 1931 | 'options' => $options, |
| 1932 | 'hasMore' => false, |
| 1933 | ]; |
| 1934 | } |
| 1935 | |
| 1936 | /** |
| 1937 | * Prepare elementor popups. |
| 1938 | * |
| 1939 | * @param array $data Search Params. |
| 1940 | * |
| 1941 | * @return array[] |
| 1942 | */ |
| 1943 | public function search_elementor_popups( $data ) { |
| 1944 | |
| 1945 | $posts = get_posts( |
| 1946 | [ |
| 1947 | 'post_type' => 'elementor_library', |
| 1948 | 'orderby' => 'title', |
| 1949 | 'order' => 'ASC', |
| 1950 | 'post_status' => 'publish', |
| 1951 | 'meta_query' => [ |
| 1952 | [ |
| 1953 | 'key' => '_elementor_template_type', |
| 1954 | 'value' => 'popup', |
| 1955 | 'compare' => '=', |
| 1956 | ], |
| 1957 | ], |
| 1958 | ] |
| 1959 | ); |
| 1960 | |
| 1961 | $options = []; |
| 1962 | if ( ! empty( $posts ) ) { |
| 1963 | foreach ( $posts as $post ) { |
| 1964 | $options[] = [ |
| 1965 | 'label' => $post->post_title, |
| 1966 | 'value' => $post->ID, |
| 1967 | ]; |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | return [ |
| 1972 | 'options' => $options, |
| 1973 | 'hasMore' => false, |
| 1974 | ]; |
| 1975 | } |
| 1976 | |
| 1977 | /** |
| 1978 | * Prepare givewp forms. |
| 1979 | * |
| 1980 | * @param array $data Search Params. |
| 1981 | * |
| 1982 | * @return array[] |
| 1983 | */ |
| 1984 | public function search_givewp_forms( $data ) { |
| 1985 | |
| 1986 | $posts = get_posts( |
| 1987 | [ |
| 1988 | 'post_type' => 'give_forms', |
| 1989 | 'orderby' => 'title', |
| 1990 | 'order' => 'ASC', |
| 1991 | 'post_status' => 'publish', |
| 1992 | ] |
| 1993 | ); |
| 1994 | |
| 1995 | $options = []; |
| 1996 | if ( ! empty( $posts ) ) { |
| 1997 | foreach ( $posts as $post ) { |
| 1998 | $options[] = [ |
| 1999 | 'label' => $post->post_title, |
| 2000 | 'value' => $post->ID, |
| 2001 | ]; |
| 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | return [ |
| 2006 | 'options' => $options, |
| 2007 | 'hasMore' => false, |
| 2008 | ]; |
| 2009 | } |
| 2010 | |
| 2011 | /** |
| 2012 | * Prepare buddyboss group users. |
| 2013 | * |
| 2014 | * @param array $data Search Params. |
| 2015 | * |
| 2016 | * @return array[] |
| 2017 | */ |
| 2018 | public function search_bb_group_users( $data ) { |
| 2019 | $options = []; |
| 2020 | |
| 2021 | $group_id = $data['dynamic']; |
| 2022 | $admins = groups_get_group_admins( $group_id ); |
| 2023 | |
| 2024 | if ( ! empty( $admins ) ) { |
| 2025 | foreach ( $admins as $admin ) { |
| 2026 | $admin_user = get_user_by( 'id', $admin->user_id ); |
| 2027 | $options[] = [ |
| 2028 | 'label' => $admin_user->display_name, |
| 2029 | 'value' => $admin_user->ID, |
| 2030 | ]; |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | $members = groups_get_group_members( [ 'group_id' => $group_id ] ); |
| 2035 | |
| 2036 | if ( isset( $members['members'] ) && ! empty( $members['members'] ) ) { |
| 2037 | foreach ( $members['members'] as $member ) { |
| 2038 | $options[] = [ |
| 2039 | 'label' => $member->display_name, |
| 2040 | 'value' => $member->ID, |
| 2041 | ]; |
| 2042 | } |
| 2043 | } |
| 2044 | return [ |
| 2045 | 'options' => $options, |
| 2046 | 'hasMore' => false, |
| 2047 | ]; |
| 2048 | } |
| 2049 | |
| 2050 | /** |
| 2051 | * Prepare buddyboss groups. |
| 2052 | * |
| 2053 | * @param array $data Search Params. |
| 2054 | * |
| 2055 | * @return array[] |
| 2056 | */ |
| 2057 | public function search_buddyboss_groups( $data ) { |
| 2058 | $args = [ |
| 2059 | 'status' => [ 'public' ], |
| 2060 | 'per_page' => -1, |
| 2061 | ]; |
| 2062 | $groups = groups_get_groups( $args ); |
| 2063 | |
| 2064 | if ( isset( $groups['groups'] ) ) { |
| 2065 | $groups = $groups['groups']; |
| 2066 | } |
| 2067 | |
| 2068 | $options = []; |
| 2069 | if ( ! empty( $groups ) ) { |
| 2070 | foreach ( $groups as $group ) { |
| 2071 | $options[] = [ |
| 2072 | 'label' => $group->name, |
| 2073 | 'value' => $group->id, |
| 2074 | ]; |
| 2075 | } |
| 2076 | } |
| 2077 | return [ |
| 2078 | 'options' => $options, |
| 2079 | 'hasMore' => false, |
| 2080 | ]; |
| 2081 | } |
| 2082 | |
| 2083 | /** |
| 2084 | * Prepare buddyboss public groups. |
| 2085 | * |
| 2086 | * @param array $data Search Params. |
| 2087 | * |
| 2088 | * @return array[] |
| 2089 | */ |
| 2090 | public function search_buddyboss_public_groups( $data ) { |
| 2091 | $options = []; |
| 2092 | $groups = groups_get_groups(); |
| 2093 | if ( isset( $groups['groups'] ) && ! empty( $groups['groups'] ) ) { |
| 2094 | foreach ( $groups['groups'] as $group ) { |
| 2095 | if ( 'public' === $group->status ) { |
| 2096 | $options[] = [ |
| 2097 | 'label' => $group->name, |
| 2098 | 'value' => $group->id, |
| 2099 | ]; |
| 2100 | } |
| 2101 | } |
| 2102 | } |
| 2103 | return [ |
| 2104 | 'options' => $options, |
| 2105 | 'hasMore' => false, |
| 2106 | ]; |
| 2107 | } |
| 2108 | |
| 2109 | /** |
| 2110 | * Prepare elementor forms. |
| 2111 | * |
| 2112 | * @param array $data Search Params. |
| 2113 | * |
| 2114 | * @return array[] |
| 2115 | */ |
| 2116 | public function search_elementor_forms( $data ) { |
| 2117 | |
| 2118 | $elementor_forms = Utilities::get_elementor_forms(); |
| 2119 | |
| 2120 | $options = []; |
| 2121 | if ( ! empty( $elementor_forms ) ) { |
| 2122 | foreach ( $elementor_forms as $key => $value ) { |
| 2123 | $options[] = [ |
| 2124 | 'label' => $value, |
| 2125 | 'value' => $key, |
| 2126 | ]; |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | return [ |
| 2131 | 'options' => $options, |
| 2132 | 'hasMore' => false, |
| 2133 | ]; |
| 2134 | } |
| 2135 | |
| 2136 | /** |
| 2137 | * Prepare elementor form fields. |
| 2138 | * |
| 2139 | * @param array $data Search Params. |
| 2140 | * |
| 2141 | * @return array[] |
| 2142 | */ |
| 2143 | public function search_pluggable_elementor_form_fields( $data ) { |
| 2144 | $result = []; |
| 2145 | $form_id = absint( $data['dynamic'] ); |
| 2146 | $elementor_form_fields = ( new Utilities() )->get_elementor_form_fields( $data ); |
| 2147 | $options = []; |
| 2148 | if ( ! empty( $elementor_form_fields ) ) { |
| 2149 | foreach ( $elementor_form_fields as $key => $value ) { |
| 2150 | $options[] = [ |
| 2151 | 'label' => $value, |
| 2152 | 'value' => '{' . $key . '}', |
| 2153 | ]; |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | return [ |
| 2158 | 'options' => $options, |
| 2159 | 'hasMore' => false, |
| 2160 | ]; |
| 2161 | } |
| 2162 | |
| 2163 | /** |
| 2164 | * Get all events |
| 2165 | * |
| 2166 | * @param array $data Data array. |
| 2167 | * |
| 2168 | * @return array |
| 2169 | */ |
| 2170 | public function search_event_calendar_event( $data ) { |
| 2171 | $page = $data['page']; |
| 2172 | $limit = Utilities::get_search_page_limit(); |
| 2173 | $offset = $limit * ( $page - 1 ); |
| 2174 | |
| 2175 | $posts = get_posts( |
| 2176 | [ |
| 2177 | 'post_type' => 'tribe_events', |
| 2178 | 'orderby' => 'title', |
| 2179 | 'order' => 'ASC', |
| 2180 | 'post_status' => 'publish', |
| 2181 | 'posts_per_page' => $limit, |
| 2182 | 'offset' => $offset, |
| 2183 | ] |
| 2184 | ); |
| 2185 | |
| 2186 | $options = []; |
| 2187 | if ( ! empty( $posts ) ) { |
| 2188 | foreach ( $posts as $post ) { |
| 2189 | $options[] = [ |
| 2190 | 'label' => $post->post_title, |
| 2191 | 'value' => $post->ID, |
| 2192 | ]; |
| 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | $count = count( $options ); |
| 2197 | |
| 2198 | return [ |
| 2199 | 'options' => $options, |
| 2200 | 'hasMore' => $count > $limit && $count > $offset, |
| 2201 | ]; |
| 2202 | } |
| 2203 | |
| 2204 | /** |
| 2205 | * Prepare rsvp event calendar events. |
| 2206 | * |
| 2207 | * @param array $data Search Params. |
| 2208 | * |
| 2209 | * @return array[] |
| 2210 | */ |
| 2211 | public function search_event_calendar_rsvp_event( $data ) { |
| 2212 | |
| 2213 | $posts = get_posts( |
| 2214 | [ |
| 2215 | 'post_type' => 'tribe_events', |
| 2216 | 'orderby' => 'title', |
| 2217 | 'order' => 'ASC', |
| 2218 | 'post_status' => 'publish', |
| 2219 | ] |
| 2220 | ); |
| 2221 | |
| 2222 | $options = []; |
| 2223 | if ( ! empty( $posts ) ) { |
| 2224 | $ticket_handler = new Tribe__Tickets__Tickets_Handler(); |
| 2225 | foreach ( $posts as $post ) { |
| 2226 | |
| 2227 | $get_rsvp_ticket = $ticket_handler->get_event_rsvp_tickets( $post->ID ); |
| 2228 | |
| 2229 | if ( ! empty( $get_rsvp_ticket ) ) { |
| 2230 | $options[] = [ |
| 2231 | 'label' => $post->post_title, |
| 2232 | 'value' => $post->ID, |
| 2233 | ]; |
| 2234 | } |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | return [ |
| 2239 | 'options' => $options, |
| 2240 | 'hasMore' => false, |
| 2241 | ]; |
| 2242 | } |
| 2243 | |
| 2244 | /** |
| 2245 | * Prepare Restrict Content Membership Level. |
| 2246 | * |
| 2247 | * @param array $data Search Params. |
| 2248 | * |
| 2249 | * @return array[] |
| 2250 | */ |
| 2251 | public function search_restrictcontent_membership_level( $data ) { |
| 2252 | |
| 2253 | $rcp_memberships = rcp_get_membership_levels(); |
| 2254 | $options = []; |
| 2255 | |
| 2256 | if ( ! empty( $rcp_memberships ) ) { |
| 2257 | foreach ( $rcp_memberships as $list ) { |
| 2258 | $options[] = [ |
| 2259 | 'label' => ucfirst( $list->name ), |
| 2260 | 'value' => $list->id, |
| 2261 | ]; |
| 2262 | } |
| 2263 | } |
| 2264 | |
| 2265 | return [ |
| 2266 | 'options' => $options, |
| 2267 | 'hasMore' => false, |
| 2268 | ]; |
| 2269 | } |
| 2270 | |
| 2271 | /** |
| 2272 | * Prepare Restrict Content Customer. |
| 2273 | * |
| 2274 | * @param array $data Search Params. |
| 2275 | * |
| 2276 | * @return array[] |
| 2277 | */ |
| 2278 | public function search_restrictcontent_customer( $data ) { |
| 2279 | |
| 2280 | $rcp_users = rcp_get_memberships(); |
| 2281 | $options = []; |
| 2282 | |
| 2283 | if ( ! empty( $rcp_users ) ) { |
| 2284 | foreach ( $rcp_users as $list ) { |
| 2285 | $user = get_user_by( 'ID', $list->get_user_id() ); |
| 2286 | $user_label = $user->user_email; |
| 2287 | |
| 2288 | if ( $user->display_name !== $user->user_email ) { |
| 2289 | $user_label .= ' (' . $user->display_name . ')'; |
| 2290 | } |
| 2291 | |
| 2292 | $options[] = [ |
| 2293 | 'label' => $user_label, |
| 2294 | 'value' => $list->get_customer_id(), |
| 2295 | ]; |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | return [ |
| 2300 | 'options' => $options, |
| 2301 | 'hasMore' => false, |
| 2302 | ]; |
| 2303 | } |
| 2304 | |
| 2305 | |
| 2306 | /** |
| 2307 | * Fetch the Presto Player video List. |
| 2308 | * |
| 2309 | * @param array $data Search Params. |
| 2310 | * |
| 2311 | * @return array[] |
| 2312 | */ |
| 2313 | public function search_ap_presto_player_video_list( $data ) { |
| 2314 | |
| 2315 | $videos = ( new Video() )->all(); |
| 2316 | $options = []; |
| 2317 | if ( ! empty( $videos ) ) { |
| 2318 | foreach ( $videos as $video ) { |
| 2319 | $options[] = [ |
| 2320 | 'label' => $video->__get( 'title' ), |
| 2321 | 'value' => (string) $video->__get( 'id' ), |
| 2322 | ]; |
| 2323 | } |
| 2324 | } |
| 2325 | |
| 2326 | return [ |
| 2327 | 'options' => $options, |
| 2328 | 'hasMore' => false, |
| 2329 | ]; |
| 2330 | } |
| 2331 | |
| 2332 | /** |
| 2333 | * Presto Player Video percentage. |
| 2334 | * |
| 2335 | * @param array $data Search Params. |
| 2336 | * |
| 2337 | * @return array[] |
| 2338 | */ |
| 2339 | public function search_prestoplayer_video_percent( $data ) { |
| 2340 | |
| 2341 | $percents = [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]; |
| 2342 | $options = []; |
| 2343 | |
| 2344 | foreach ( $percents as $percent ) { |
| 2345 | $options[] = [ |
| 2346 | 'label' => $percent . '%', |
| 2347 | 'value' => (string) $percent, |
| 2348 | ]; |
| 2349 | } |
| 2350 | |
| 2351 | return [ |
| 2352 | 'options' => $options, |
| 2353 | 'hasMore' => false, |
| 2354 | ]; |
| 2355 | } |
| 2356 | |
| 2357 | /** |
| 2358 | * Get user profile field options. |
| 2359 | * |
| 2360 | * @return array |
| 2361 | * @since 1.0.0 |
| 2362 | */ |
| 2363 | public function search_user_field_options() { |
| 2364 | |
| 2365 | $options = apply_filters( |
| 2366 | 'sure_trigger_get_user_field_options', |
| 2367 | [ |
| 2368 | [ |
| 2369 | 'label' => __( 'User Name', 'suretriggers' ), |
| 2370 | 'value' => 'user_login', |
| 2371 | ], |
| 2372 | [ |
| 2373 | 'label' => __( 'User Email', 'suretriggers' ), |
| 2374 | 'value' => 'user_email', |
| 2375 | ], |
| 2376 | [ |
| 2377 | 'label' => __( 'Display Name', 'suretriggers' ), |
| 2378 | 'value' => 'display_name', |
| 2379 | ], |
| 2380 | [ |
| 2381 | 'label' => __( 'User Password', 'suretriggers' ), |
| 2382 | 'value' => 'user_pass', |
| 2383 | ], |
| 2384 | [ |
| 2385 | 'label' => __( 'Website', 'suretriggers' ), |
| 2386 | 'value' => 'user_url', |
| 2387 | ], |
| 2388 | ] |
| 2389 | ); |
| 2390 | |
| 2391 | return [ |
| 2392 | 'options' => $options, |
| 2393 | 'hasMore' => false, |
| 2394 | ]; |
| 2395 | } |
| 2396 | |
| 2397 | /** |
| 2398 | * Get user post field options. |
| 2399 | * |
| 2400 | * @return array |
| 2401 | * @since 1.0.0 |
| 2402 | */ |
| 2403 | public function search_post_field_options() { |
| 2404 | |
| 2405 | return [ |
| 2406 | 'options' => [ |
| 2407 | [ |
| 2408 | 'label' => __( 'Type', 'suretriggers' ), |
| 2409 | 'value' => 'post_type', |
| 2410 | 'dynamic_field' => [ |
| 2411 | 'type' => 'select-creatable', |
| 2412 | 'ajaxIdentifier' => 'post_types', |
| 2413 | ], |
| 2414 | ], |
| 2415 | [ |
| 2416 | 'label' => __( 'Status', 'suretriggers' ), |
| 2417 | 'value' => 'post_status', |
| 2418 | 'dynamic_field' => [ |
| 2419 | 'type' => 'select-async', |
| 2420 | 'ajaxIdentifier' => 'post_statuses', |
| 2421 | ], |
| 2422 | ], |
| 2423 | [ |
| 2424 | 'label' => __( 'Author', 'suretriggers' ), |
| 2425 | 'value' => 'post_author', |
| 2426 | 'dynamic_field' => [ |
| 2427 | 'type' => 'select-async', |
| 2428 | 'ajaxIdentifier' => 'user', |
| 2429 | ], |
| 2430 | ], |
| 2431 | [ |
| 2432 | 'label' => __( 'Title', 'suretriggers' ), |
| 2433 | 'value' => 'post_title', |
| 2434 | 'dynamic_field' => [ |
| 2435 | 'type' => 'select-creatable', |
| 2436 | ], |
| 2437 | ], |
| 2438 | [ |
| 2439 | 'label' => __( 'Slug', 'suretriggers' ), |
| 2440 | 'value' => 'post_slug', |
| 2441 | 'dynamic_field' => [ |
| 2442 | 'type' => 'select-creatable', |
| 2443 | ], |
| 2444 | ], |
| 2445 | [ |
| 2446 | 'label' => __( 'Content', 'suretriggers' ), |
| 2447 | 'value' => 'post_content', |
| 2448 | 'dynamic_field' => [ |
| 2449 | 'type' => 'html-editor', |
| 2450 | ], |
| 2451 | ], |
| 2452 | ], |
| 2453 | 'hasMore' => false, |
| 2454 | ]; |
| 2455 | } |
| 2456 | |
| 2457 | /** |
| 2458 | * Bricksbuilder grouped data. |
| 2459 | * |
| 2460 | * @param array $data data. |
| 2461 | * @return array |
| 2462 | */ |
| 2463 | public function search_bb_groups( $data ) { |
| 2464 | |
| 2465 | global $wpdb; |
| 2466 | $options = []; |
| 2467 | |
| 2468 | if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'bp_groups' ) ) ) { |
| 2469 | |
| 2470 | $results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s', $wpdb->prefix . 'bp_groups' ) ); |
| 2471 | |
| 2472 | if ( $results ) { |
| 2473 | foreach ( $results as $result ) { |
| 2474 | $options[] = [ |
| 2475 | 'label' => $result->name, |
| 2476 | 'value' => $result->id, |
| 2477 | ]; |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | return [ |
| 2483 | 'options' => $options, |
| 2484 | 'hasMore' => false, |
| 2485 | ]; |
| 2486 | } |
| 2487 | |
| 2488 | /** |
| 2489 | * Search forms. |
| 2490 | * |
| 2491 | * @return array |
| 2492 | */ |
| 2493 | public function search_bb_forums() { |
| 2494 | $options = []; |
| 2495 | $allowed_atatus = [ 'publish', 'private' ]; |
| 2496 | $forum_args = [ |
| 2497 | 'post_type' => bbp_get_forum_post_type(), |
| 2498 | 'posts_per_page' => -1, |
| 2499 | 'orderby' => 'title', |
| 2500 | 'order' => 'ASC', |
| 2501 | 'post_status' => 'any', |
| 2502 | ]; |
| 2503 | $forums = get_posts( $forum_args ); |
| 2504 | |
| 2505 | if ( ! empty( $forums ) ) { |
| 2506 | foreach ( $forums as $forum ) { |
| 2507 | if ( in_array( $forum->post_status, $allowed_atatus, true ) ) { |
| 2508 | $options[] = [ |
| 2509 | 'label' => $forum->post_title, |
| 2510 | 'value' => $forum->ID, |
| 2511 | ]; |
| 2512 | } |
| 2513 | } |
| 2514 | } |
| 2515 | return [ |
| 2516 | 'options' => $options, |
| 2517 | 'hasMore' => false, |
| 2518 | ]; |
| 2519 | } |
| 2520 | |
| 2521 | |
| 2522 | /** |
| 2523 | * Get last data for trigger. |
| 2524 | * |
| 2525 | * @param array $data data. |
| 2526 | * @return array |
| 2527 | */ |
| 2528 | public function search_affiliate_wp_triggers_last_data( $data ) { |
| 2529 | global $wpdb; |
| 2530 | |
| 2531 | $context = []; |
| 2532 | $context['response_type'] = 'sample'; |
| 2533 | |
| 2534 | $user_data = WordPress::get_sample_user_context(); |
| 2535 | |
| 2536 | $affiliate_data = [ |
| 2537 | 'affiliate_id' => 1, |
| 2538 | 'rest_id' => '', |
| 2539 | 'user_id' => 1, |
| 2540 | 'rate' => '', |
| 2541 | 'rate_type' => '', |
| 2542 | 'flat_rate_basis' => '', |
| 2543 | 'payment_email' => 'admin@bsf.io', |
| 2544 | 'status' => 'active', |
| 2545 | 'earnings' => 0, |
| 2546 | 'unpaid_earnings' => 0, |
| 2547 | 'referrals' => 0, |
| 2548 | 'visits' => 0, |
| 2549 | 'date_registered' => '2023-01-18 13:35:22', |
| 2550 | 'dynamic_coupon' => 'KDJSKS', |
| 2551 | ]; |
| 2552 | |
| 2553 | $referral_data = [ |
| 2554 | 'referral_id' => 1, |
| 2555 | 'affiliate_id' => 1, |
| 2556 | 'visit_id' => 0, |
| 2557 | 'rest_id' => '', |
| 2558 | 'customer_id' => 0, |
| 2559 | 'parent_id' => 0, |
| 2560 | 'description' => 'Testing', |
| 2561 | 'status' => 'unpaid', |
| 2562 | 'amount' => '12.00', |
| 2563 | 'currency' => '', |
| 2564 | 'custom' => 'custom', |
| 2565 | 'context' => '', |
| 2566 | 'campaign' => '', |
| 2567 | 'reference' => 'Reference', |
| 2568 | 'products' => '', |
| 2569 | 'date' => '2023-01-18 16:36:59', |
| 2570 | 'type' => 'opt-in', |
| 2571 | 'payout_id' => 0, |
| 2572 | ]; |
| 2573 | |
| 2574 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 2575 | |
| 2576 | if ( in_array( $term, [ 'affiliate_approved', 'affiliate_awaiting_approval' ], true ) ) { |
| 2577 | $affiliate = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_affiliates WHERE affiliate_id = ( SELECT max(affiliate_id) FROM {$wpdb->prefix}affiliate_wp_affiliates )" ); |
| 2578 | |
| 2579 | if ( ! empty( $affiliate ) ) { |
| 2580 | $affiliate = affwp_get_affiliate( $affiliate->affiliate_id ); |
| 2581 | $affiliate_data = get_object_vars( $affiliate ); |
| 2582 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 2583 | $context['response_type'] = 'live'; |
| 2584 | } |
| 2585 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data ); |
| 2586 | |
| 2587 | } else { |
| 2588 | $referral = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE referral_id = ( SELECT max(referral_id) FROM {$wpdb->prefix}affiliate_wp_referrals )" ); |
| 2589 | |
| 2590 | if ( ! empty( $referral ) ) { |
| 2591 | $referral = affwp_get_referral( $referral->referral_id ); |
| 2592 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 2593 | $affiliate_data = get_object_vars( $affiliate ); |
| 2594 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 2595 | $referral_data = get_object_vars( $referral ); |
| 2596 | $context['response_type'] = 'live'; |
| 2597 | } |
| 2598 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data ); |
| 2599 | } |
| 2600 | |
| 2601 | return $context; |
| 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | /** |
| 2606 | * Get last data for trigger. |
| 2607 | * |
| 2608 | * @param array $data data. |
| 2609 | * @return array |
| 2610 | */ |
| 2611 | public function search_edd_triggers_last_data( $data ) { |
| 2612 | $context = []; |
| 2613 | $context['response_type'] = 'sample'; |
| 2614 | |
| 2615 | $order_data = [ |
| 2616 | 'order_id' => '1', |
| 2617 | 'customer_email' => 'john_doe@bsf.io', |
| 2618 | 'customer_first_name' => 'John', |
| 2619 | 'customer_last_name' => 'Doe', |
| 2620 | 'ordered_items' => 'Any Sample Book', |
| 2621 | 'currency' => 'USD', |
| 2622 | 'status' => 'complete', |
| 2623 | 'discount_codes' => 'KDJSKS', |
| 2624 | 'order_discounts' => '2.00', |
| 2625 | 'order_subtotal' => '48.00', |
| 2626 | 'order_tax' => '0.00', |
| 2627 | 'order_total' => '48.00', |
| 2628 | 'payment_method' => 'stripe', |
| 2629 | ]; |
| 2630 | |
| 2631 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 2632 | |
| 2633 | if ( 'order_created' === $term ) { |
| 2634 | $order_data['purchase_key'] = '06d3b7d923ca922dc889354f9bc33fbb'; |
| 2635 | |
| 2636 | $args = [ |
| 2637 | 'number' => 1, |
| 2638 | 'status' => [ 'complete', 'refunded', 'partially_refunded' ], |
| 2639 | ]; |
| 2640 | $payments = edd_get_payments( $args ); |
| 2641 | |
| 2642 | if ( count( $payments ) > 0 ) { |
| 2643 | $order_data = EDD::get_product_purchase_context( $payments[0] ); |
| 2644 | $context['response_type'] = 'live'; |
| 2645 | } |
| 2646 | } else { |
| 2647 | $args = [ |
| 2648 | 'number' => 1, |
| 2649 | 'status' => 'complete', |
| 2650 | 'type' => 'refund', |
| 2651 | ]; |
| 2652 | $payments = edd_get_payments( $args ); |
| 2653 | |
| 2654 | if ( count( $payments ) > 0 ) { |
| 2655 | $order_data = EDD::get_purchase_refund_context( $payments[0] ); |
| 2656 | $context['response_type'] = 'live'; |
| 2657 | } |
| 2658 | } |
| 2659 | |
| 2660 | $context['pluggable_data'] = $order_data; |
| 2661 | return $context; |
| 2662 | } |
| 2663 | |
| 2664 | /** |
| 2665 | * Get last data for trigger. |
| 2666 | * |
| 2667 | * @param array $data data. |
| 2668 | * @return array |
| 2669 | */ |
| 2670 | public function search_presto_player_triggers_last_data( $data ) { |
| 2671 | $context = []; |
| 2672 | $context['response_type'] = 'sample'; |
| 2673 | |
| 2674 | $user_data = WordPress::get_sample_user_context(); |
| 2675 | |
| 2676 | $video_data = [ |
| 2677 | 'pp_video' => '1', |
| 2678 | 'pp_video_percentage' => '100', |
| 2679 | 'video_id' => '1', |
| 2680 | 'video_title' => 'SureTriggers Is Here 🎉 The Easiest Automation Builder WordPress Websites & Apps', |
| 2681 | 'video_type' => 'youtube', |
| 2682 | 'video_external_id' => '-cYbNYgylLs', |
| 2683 | 'video_attachment_id' => '0', |
| 2684 | 'video_post_id' => '127', |
| 2685 | 'video_src' => 'https://www.youtube.com/watch?v=-cYbNYgylLs', |
| 2686 | 'video_created_by' => '1', |
| 2687 | 'video_created_at' => '2022-11-10 00:28:25', |
| 2688 | 'video_updated_at' => '2022-11-10 00:34:40', |
| 2689 | 'video_deleted_at' => '', |
| 2690 | ]; |
| 2691 | |
| 2692 | $videos = ( new Video() )->all(); |
| 2693 | |
| 2694 | if ( count( $videos ) > 0 ) { |
| 2695 | $video_id = '-1' === $data['filter']['pp_video']['value'] ? $videos[0]->id : $data['filter']['pp_video']['value']; |
| 2696 | $video_data = ( new Video( $video_id ) )->toArray(); |
| 2697 | $video_data['pp_video'] = $video_id; |
| 2698 | $video_data['pp_video_percentage'] = isset( $data['filter']['pp_video_percentage']['value'] ) ? $data['filter']['pp_video_percentage']['value'] : '100'; |
| 2699 | $user_data = WordPress::get_user_context( $video_data['created_by'] ); |
| 2700 | |
| 2701 | $context['response_type'] = 'live'; |
| 2702 | } |
| 2703 | |
| 2704 | $context['pluggable_data'] = array_merge( $user_data, $video_data ); |
| 2705 | |
| 2706 | return $context; |
| 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * Get last data for trigger. |
| 2711 | * |
| 2712 | * @param array $data data. |
| 2713 | * @return array |
| 2714 | */ |
| 2715 | public function search_member_press_triggers_last_data( $data ) { |
| 2716 | global $wpdb; |
| 2717 | |
| 2718 | $context = []; |
| 2719 | $context['response_type'] = 'sample'; |
| 2720 | |
| 2721 | $user_data = WordPress::get_sample_user_context(); |
| 2722 | |
| 2723 | $membership_data = [ |
| 2724 | 'membership_id' => '190', |
| 2725 | 'membership_title' => 'Sample Membership', |
| 2726 | 'amount' => '12.00', |
| 2727 | 'total' => '12.00', |
| 2728 | 'tax_amount' => '0.00', |
| 2729 | 'tax_rate' => '0.00', |
| 2730 | 'trans_num' => 't_63a03f3334f44', |
| 2731 | 'status' => 'complete', |
| 2732 | 'subscription_id' => '0', |
| 2733 | 'membership_url' => site_url() . '/register/premium/', |
| 2734 | 'membership_featured_image_id' => '521', |
| 2735 | 'membership_featured_image_url' => SURE_TRIGGERS_URL . 'assets/images/sample.svg', |
| 2736 | ]; |
| 2737 | |
| 2738 | $membership_id = (int) ( isset( $data['filter']['membership_id']['value'] ) ? $data['filter']['membership_id']['value'] : '-1' ); |
| 2739 | |
| 2740 | if ( $membership_id > 0 ) { |
| 2741 | |
| 2742 | $subscription = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mepr_transactions WHERE product_id= %s ORDER BY id DESC LIMIT 1", $membership_id ) ); |
| 2743 | } else { |
| 2744 | $subscription = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mepr_transactions ORDER BY id DESC LIMIT 1" ); |
| 2745 | } |
| 2746 | |
| 2747 | if ( ! empty( $subscription ) ) { |
| 2748 | $membership_data = MemberPress::get_membership_context( $subscription ); |
| 2749 | $user_data = WordPress::get_user_context( $subscription->user_id ); |
| 2750 | |
| 2751 | $context['response_type'] = 'live'; |
| 2752 | } |
| 2753 | |
| 2754 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 2755 | |
| 2756 | return $context; |
| 2757 | } |
| 2758 | |
| 2759 | /** |
| 2760 | * Get last data for trigger. |
| 2761 | * |
| 2762 | * @param array $data data. |
| 2763 | * @return array |
| 2764 | */ |
| 2765 | public function search_wishlist_member_triggers_last_data( $data ) { |
| 2766 | global $wpdb; |
| 2767 | |
| 2768 | $context = []; |
| 2769 | $context['response_type'] = 'sample'; |
| 2770 | |
| 2771 | $user_data = WordPress::get_sample_user_context(); |
| 2772 | |
| 2773 | $membership_data = [ |
| 2774 | 'membership_level_id' => '1', |
| 2775 | 'membership_level_name' => 'Sample Membership Level', |
| 2776 | ]; |
| 2777 | |
| 2778 | $membership_level_id = (int) ( isset( $data['filter']['membership_level_id']['value'] ) ? $data['filter']['membership_level_id']['value'] : '-1' ); |
| 2779 | |
| 2780 | if ( $membership_level_id > 0 ) { |
| 2781 | $membership = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wlm_userlevels WHERE level_id= %s ORDER BY id DESC LIMIT 1", $membership_level_id ) ); |
| 2782 | } else { |
| 2783 | $membership = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}wlm_userlevels ORDER BY id DESC LIMIT 1" ); |
| 2784 | } |
| 2785 | if ( ! empty( $membership ) ) { |
| 2786 | $membership_data = WishlistMember::get_membership_detail_context( (int) $membership->level_id ); |
| 2787 | $user_data = WordPress::get_user_context( $membership->user_id ); |
| 2788 | |
| 2789 | $context['response_type'] = 'live'; |
| 2790 | } |
| 2791 | |
| 2792 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 2793 | |
| 2794 | return $context; |
| 2795 | } |
| 2796 | |
| 2797 | /** |
| 2798 | * Get last data for trigger. |
| 2799 | * |
| 2800 | * @param array $data data. |
| 2801 | * @return array |
| 2802 | */ |
| 2803 | public function search_peepso_triggers_last_data( $data ) { |
| 2804 | global $wpdb; |
| 2805 | |
| 2806 | $context = []; |
| 2807 | $context['response_type'] = 'sample'; |
| 2808 | |
| 2809 | $user_data = WordPress::get_sample_user_context(); |
| 2810 | |
| 2811 | $post_data = [ |
| 2812 | 'post_id' => '1', |
| 2813 | 'activity_id' => '2', |
| 2814 | 'post_author' => '1', |
| 2815 | 'post_content' => 'New sample post...!', |
| 2816 | 'post_title' => 'Sample Post', |
| 2817 | 'post_excerpt' => 'sample', |
| 2818 | 'post_status' => 'publish', |
| 2819 | 'post_type' => 'peepso-post', |
| 2820 | ]; |
| 2821 | |
| 2822 | $post = $wpdb->get_row( "SELECT act_id, act_owner_id, act_external_id FROM {$wpdb->prefix}peepso_activities ORDER BY act_id DESC LIMIT 1" ); |
| 2823 | |
| 2824 | if ( ! empty( $post ) ) { |
| 2825 | $post_data = PeepSo::get_pp_activity_context( (int) $post->act_external_id, (int) $post->act_id ); |
| 2826 | $user_data = WordPress::get_user_context( $post->act_owner_id ); |
| 2827 | |
| 2828 | $context['response_type'] = 'live'; |
| 2829 | } |
| 2830 | |
| 2831 | $context['pluggable_data'] = array_merge( $user_data, $post_data ); |
| 2832 | |
| 2833 | return $context; |
| 2834 | } |
| 2835 | |
| 2836 | /** |
| 2837 | * Get last data for trigger |
| 2838 | * |
| 2839 | * @param array $data data. |
| 2840 | * @return array |
| 2841 | */ |
| 2842 | public function search_restrict_content_pro_triggers_last_data( $data ) { |
| 2843 | $context = []; |
| 2844 | $context['response_type'] = 'sample'; |
| 2845 | |
| 2846 | $user_data = WordPress::get_sample_user_context(); |
| 2847 | |
| 2848 | $membership_data = [ |
| 2849 | 'membership_level_id' => '190', |
| 2850 | 'membership_level' => 'Sample Membership', |
| 2851 | 'membership_initial_payment' => '0.00', |
| 2852 | 'membership_recurring_payment' => '0.00', |
| 2853 | 'membership_expiry_date' => 'January 22, 2023', |
| 2854 | ]; |
| 2855 | |
| 2856 | $customer_id = (int) ( isset( $data['filter']['membership_customer_id']['value'] ) ? $data['filter']['membership_customer_id']['value'] : '-1' ); |
| 2857 | $membership_id = (int) ( isset( $data['filter']['membership_level_id']['value'] ) ? $data['filter']['membership_level_id']['value'] : '-1' ); |
| 2858 | |
| 2859 | $args = [ |
| 2860 | 'status' => 'expired', |
| 2861 | 'number' => 1, |
| 2862 | 'orderby' => 'id', |
| 2863 | ]; |
| 2864 | |
| 2865 | if ( -1 !== $customer_id ) { |
| 2866 | $args['customer_id'] = $customer_id; |
| 2867 | } |
| 2868 | |
| 2869 | if ( -1 !== $membership_id ) { |
| 2870 | $args['object_id'] = $membership_id; |
| 2871 | } |
| 2872 | |
| 2873 | $memberships = rcp_get_memberships( $args ); |
| 2874 | if ( count( $memberships ) > 0 ) { |
| 2875 | $membership_data = RestrictContent::get_rcp_membership_detail_context( $memberships[0] ); |
| 2876 | $user_data = WordPress::get_user_context( $memberships[0]->get_user_id() ); |
| 2877 | |
| 2878 | $context['response_type'] = 'live'; |
| 2879 | } |
| 2880 | |
| 2881 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 2882 | |
| 2883 | return $context; |
| 2884 | } |
| 2885 | |
| 2886 | /** |
| 2887 | * Get last data for trigger |
| 2888 | * |
| 2889 | * @param array $data data. |
| 2890 | * @return array |
| 2891 | */ |
| 2892 | public function search_events_calendar_triggers_last_data( $data ) { |
| 2893 | $context = []; |
| 2894 | $context['response_type'] = 'sample'; |
| 2895 | |
| 2896 | $event_data = [ |
| 2897 | 'event' => [ |
| 2898 | 'ID' => 58, |
| 2899 | 'post_author' => 1, |
| 2900 | 'post_date' => '2023-01-19 09:27:58', |
| 2901 | 'post_date_gmt' => '2023-01-19 09:27:58', |
| 2902 | 'post_content' => '', |
| 2903 | 'post_title' => 'New event', |
| 2904 | 'post_excerpt' => '', |
| 2905 | 'post_status' => 'publish', |
| 2906 | 'comment_status' => 'open', |
| 2907 | 'ping_status' => 'closed', |
| 2908 | 'post_password' => '', |
| 2909 | 'post_name' => 'new-event', |
| 2910 | 'to_ping' => '', |
| 2911 | 'pinged' => '', |
| 2912 | 'post_modified' => '2023-01-19 09:44:25', |
| 2913 | 'post_modified_gmt' => '2023-01-19 09:44:25', |
| 2914 | 'post_content_filtered' => '', |
| 2915 | 'post_parent' => 0, |
| 2916 | 'guid' => 'http://connector.com/?post_type=tribe_events&p=58', |
| 2917 | 'menu_order' => -1, |
| 2918 | 'post_type' => 'tribe_events', |
| 2919 | 'post_mime_type' => '', |
| 2920 | 'comment_count' => 0, |
| 2921 | 'filter' => 'raw', |
| 2922 | ], |
| 2923 | 'attendies' => [ |
| 2924 | 'order_id' => 68, |
| 2925 | 'purchaser_name' => 'sapna Rana', |
| 2926 | 'purchaser_email' => 'sapnar@bsf.io', |
| 2927 | 'provider' => 'Tribe__Tickets__RSVP', |
| 2928 | 'provider_slug' => 'rsvp', |
| 2929 | 'purchase_time' => '2023-01-19 09:48:43', |
| 2930 | 'optout' => 1, |
| 2931 | 'ticket' => 'Prime', |
| 2932 | 'attendee_id' => 68, |
| 2933 | 'security' => '2cefc3b53e', |
| 2934 | 'product_id' => 65, |
| 2935 | 'check_in' => '', |
| 2936 | 'order_status' => 'yes', |
| 2937 | 'order_status_label' => 'Going', |
| 2938 | 'user_id' => 1, |
| 2939 | 'ticket_sent' => 1, |
| 2940 | 'event_id' => 58, |
| 2941 | 'ticket_name' => 'Prime', |
| 2942 | 'holder_name' => 'sapna Rana', |
| 2943 | 'holder_email' => 'sapnar@bsf.io', |
| 2944 | 'ticket_id' => 68, |
| 2945 | 'qr_ticket_id' => 68, |
| 2946 | 'security_code' => '2cefc3b53e', |
| 2947 | 'attendee_meta' => '', |
| 2948 | 'is_subscribed' => '', |
| 2949 | 'is_purchaser' => 1, |
| 2950 | 'ticket_exists' => 1, |
| 2951 | ], |
| 2952 | ]; |
| 2953 | |
| 2954 | $event_id = (int) ( isset( $data['filter']['event_id']['value'] ) ? $data['filter']['event_id']['value'] : '-1' ); |
| 2955 | |
| 2956 | $args = [ |
| 2957 | 'post_type' => 'tribe_rsvp_attendees', |
| 2958 | 'orderby' => 'ID', |
| 2959 | 'order' => 'DESC', |
| 2960 | 'post_status' => 'publish', |
| 2961 | 'numberposts' => 1, |
| 2962 | ]; |
| 2963 | |
| 2964 | if ( -1 !== $event_id ) { |
| 2965 | $args['meta_query'] = [ |
| 2966 | [ |
| 2967 | 'key' => '_tribe_rsvp_event', |
| 2968 | 'value' => $event_id, |
| 2969 | ], |
| 2970 | ]; |
| 2971 | } |
| 2972 | |
| 2973 | $attendees = get_posts( $args ); |
| 2974 | |
| 2975 | if ( count( $attendees ) > 0 ) { |
| 2976 | $attendee = $attendees[0]; |
| 2977 | $attendee_id = $attendee->ID; |
| 2978 | |
| 2979 | $product_id = get_post_meta( $attendee_id, '_tribe_rsvp_product', true ); |
| 2980 | $order_id = get_post_meta( $attendee_id, '_tribe_rsvp_order', true ); |
| 2981 | |
| 2982 | $event_data = TheEventCalendar::get_event_context( $product_id, $order_id ); |
| 2983 | $context['response_type'] = 'live'; |
| 2984 | } |
| 2985 | |
| 2986 | $context['pluggable_data'] = $event_data; |
| 2987 | |
| 2988 | return $context; |
| 2989 | } |
| 2990 | |
| 2991 | /** |
| 2992 | * Get last data for trigger |
| 2993 | * |
| 2994 | * @param array $data data. |
| 2995 | * @return array |
| 2996 | */ |
| 2997 | public function search_woo_commerce_triggers_last_data( $data ) { |
| 2998 | $context = []; |
| 2999 | $context['response_type'] = 'sample'; |
| 3000 | $user_data = WordPress::get_sample_user_context(); |
| 3001 | |
| 3002 | $product_data['product'] = [ |
| 3003 | 'id' => '169', |
| 3004 | 'name' => 'Sample Product', |
| 3005 | 'description' => 'This is description of sample product.', |
| 3006 | 'short_description' => 'This is short description of sample product.', |
| 3007 | 'image_url' => SURE_TRIGGERS_URL . 'assets/images/sample.svg', |
| 3008 | 'slug' => 'sample-product', |
| 3009 | 'status' => 'publish', |
| 3010 | 'type' => 'simple', |
| 3011 | 'price' => '89', |
| 3012 | 'featured' => '0', |
| 3013 | 'sku' => 'hoodie-blue-sm', |
| 3014 | 'regular_price' => '90', |
| 3015 | 'sale_price' => '89', |
| 3016 | 'total_sales' => '21', |
| 3017 | 'category' => 'Uncategorized', |
| 3018 | 'tags' => 'sample, new, 2022', |
| 3019 | ]; |
| 3020 | |
| 3021 | $comment_data = [ |
| 3022 | 'comment_id' => '1', |
| 3023 | 'comment' => 'This is a sample comment..!', |
| 3024 | ]; |
| 3025 | |
| 3026 | $order_data = [ |
| 3027 | 'order_id' => '500', |
| 3028 | 'total_order_value' => '45', |
| 3029 | 'currency' => 'USD', |
| 3030 | 'shipping_total' => '5', |
| 3031 | 'order_payment_method' => 'cod', |
| 3032 | 'billing_firstname' => 'John', |
| 3033 | 'billing_lastname' => 'Doe', |
| 3034 | 'billing_company' => 'BSF', |
| 3035 | 'billing_address_1' => '1004 Beaumont', |
| 3036 | 'billing_address_2' => '', |
| 3037 | 'billing_city' => 'Casper', |
| 3038 | 'billing_state' => 'Wyoming', |
| 3039 | 'billing_postcode' => '82601', |
| 3040 | 'billing_country' => 'US', |
| 3041 | 'billing_email' => 'john_doe@bsf.io', |
| 3042 | 'billing_phone' => '(307) 7626541', |
| 3043 | 'shipping_firstname' => 'John', |
| 3044 | 'shipping_lastname' => 'Doe', |
| 3045 | 'shipping_company' => 'BSF', |
| 3046 | 'shipping_address_1' => '1004 Beaumont', |
| 3047 | 'shipping_address_2' => '', |
| 3048 | 'shipping_city' => 'Casper', |
| 3049 | 'shipping_state' => 'Wyoming', |
| 3050 | 'shipping_postcode' => '82601', |
| 3051 | 'shipping_country' => 'US', |
| 3052 | 'coupon_codes' => 'e3mstekq, f24sjakb', |
| 3053 | 'total_items_in_order' => '1', |
| 3054 | 'user_id' => '1', |
| 3055 | ]; |
| 3056 | |
| 3057 | $variation_data = [ |
| 3058 | 'product_variation_id' => '626', |
| 3059 | 'product_variation' => 'Color: Silver', |
| 3060 | ]; |
| 3061 | |
| 3062 | $order_sample_data = json_decode( '{"id":37,"parent_id":0,"status":"processing","currency":"USD","version":"7.3.0","prices_include_tax":false,"date_created":{"date":"2023-01-18 08:00:49.000000","timezone_type":1,"timezone":"+00:00"},"date_modified":{"date":"2023-01-18 08:00:50.000000","timezone_type":1,"timezone":"+00:00"},"discount_total":"0","discount_tax":"0","shipping_total":"0","shipping_tax":"0","cart_tax":"0","total":"22.00","total_tax":"0","customer_id":1,"order_key":"wc_order_VdLfjJ9vP7pDs","billing":{"first_name":"John","last_name":"Rana","company":"","address_1":"test","address_2":"","city":"Mohali","state":"AL","postcode":"12344","country":"US","email":"test@example.com","phone":"13232323"},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"","phone":""},"payment_method":"cod","payment_method_title":"Cash on delivery","transaction_id":"","customer_ip_address":"::1","customer_user_agent":"Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/108.0.0.0 Safari\/537.36","created_via":"checkout","customer_note":"","date_completed":null,"date_paid":null,"cart_hash":"10b8e2799df0f88e1506edc0f3ed99c9","order_stock_reduced":true,"download_permissions_granted":true,"new_order_email_sent":true,"recorded_sales":true,"recorded_coupon_usage_counts":true,"number":"37","meta_data":[{"id":204,"key":"is_vat_exempt","value":"no"}],"line_items":{"id":"2, 3","order_id":"37, 37","name":"Variable product - Red, Test product","product_id":"34, 31","variation_id":"35, 0","quantity":"1, 1","tax_class":", ","subtotal":"12, 10","subtotal_tax":"0, 0","total":"12, 10","total_tax":"0, 0","taxes":", ","meta_data":", "},"tax_lines":[],"shipping_lines":[],"fee_lines":[],"coupon_lines":[],"products":[{"id":2,"order_id":37,"name":"Variable product - Red","product_id":34,"variation_id":35,"quantity":1,"tax_class":"","subtotal":"12","subtotal_tax":"0","total":"12","total_tax":"0","taxes":{"total":[],"subtotal":[]},"meta_data":{"19":{"key":"color","value":"Red","display_key":"Color","display_value":"<p>Red<\/p>\n"}}},{"id":3,"order_id":37,"name":"Test product","product_id":31,"variation_id":0,"quantity":1,"tax_class":"","subtotal":"10","subtotal_tax":"0","total":"10","total_tax":"0","taxes":{"total":[],"subtotal":[]},"meta_data":[]}],"quantity":"1, 1","wp_user_id":1,"user_login":"john","display_name":"john smith","user_firstname":"John","user_lastname":"Smith","user_email":"test@example.com","user_role":["subscriber"]}', true ); //phpcs:ignore |
| 3063 | |
| 3064 | $product_id = (int) ( isset( $data['filter']['product_id']['value'] ) ? $data['filter']['product_id']['value'] : -1 ); |
| 3065 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3066 | |
| 3067 | if ( in_array( $term, [ 'product_added_to_cart', 'product_viewed' ], true ) ) { |
| 3068 | if ( -1 === $product_id ) { |
| 3069 | $args = [ |
| 3070 | 'post_type' => 'product', |
| 3071 | 'orderby' => 'ID', |
| 3072 | 'order' => 'DESC', |
| 3073 | 'post_status' => 'publish', |
| 3074 | 'numberposts' => 1, |
| 3075 | ]; |
| 3076 | $products = get_posts( $args ); |
| 3077 | |
| 3078 | if ( count( $products ) > 0 ) { |
| 3079 | $product_id = $products[0]->ID; |
| 3080 | } |
| 3081 | } |
| 3082 | |
| 3083 | if ( -1 !== $product_id ) { |
| 3084 | $post = get_post( $product_id ); |
| 3085 | $user_data = WordPress::get_user_context( $post->post_author ); |
| 3086 | $product_data['product_id'] = $product_id; |
| 3087 | $product_data['product'] = WooCommerce::get_product_context( $product_id ); |
| 3088 | unset( $product_data['product']['id'] ); //phpcs:ignore |
| 3089 | $context['response_type'] = 'live'; |
| 3090 | } |
| 3091 | |
| 3092 | if ( 'product_added_to_cart' === $term ) { |
| 3093 | $product_data['product_quantity'] = 1; |
| 3094 | } |
| 3095 | |
| 3096 | $context['pluggable_data'] = array_merge( $product_data, $user_data ); |
| 3097 | |
| 3098 | } elseif ( 'product_reviewed' === $term ) { |
| 3099 | $comment_args = [ |
| 3100 | 'number' => 1, |
| 3101 | 'type' => 'review', |
| 3102 | 'orderby' => 'comment_ID', |
| 3103 | 'post_id' => -1 !== $product_id ? $product_id : 0, |
| 3104 | ]; |
| 3105 | |
| 3106 | $comments = get_comments( $comment_args ); |
| 3107 | |
| 3108 | if ( count( $comments ) > 0 ) { |
| 3109 | $comment = $comments[0]; |
| 3110 | $comment_data = [ |
| 3111 | 'comment_id' => $comment->comment_ID, |
| 3112 | 'comment' => $comment->comment_content, |
| 3113 | ]; |
| 3114 | $product_data = WooCommerce::get_product_context( $comment->comment_post_ID ); |
| 3115 | $user_data = WordPress::get_user_context( $comment->user_id ); |
| 3116 | $context['response_type'] = 'live'; |
| 3117 | } |
| 3118 | |
| 3119 | $context['pluggable_data'] = array_merge( $product_data, $user_data, $comment_data ); |
| 3120 | |
| 3121 | } elseif ( 'product_purchased' === $term ) { |
| 3122 | $order_id = 0; |
| 3123 | $product_data['quantity'] = '1'; |
| 3124 | if ( -1 !== $product_id ) { |
| 3125 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 3126 | if ( count( $order_ids ) > 0 ) { |
| 3127 | $order_id = $order_ids[0]; |
| 3128 | } |
| 3129 | } else { |
| 3130 | $orders = wc_get_orders( [ 'numberposts' => 1 ] ); |
| 3131 | if ( count( $orders ) > 0 ) { |
| 3132 | $order_id = $orders[0]->get_id(); |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | if ( 0 !== $order_id ) { |
| 3137 | $order = wc_get_order( $order_id ); |
| 3138 | |
| 3139 | if ( $order ) { |
| 3140 | $user_id = $order->get_customer_id(); |
| 3141 | $items = $order->get_items(); |
| 3142 | |
| 3143 | $product_ids = []; |
| 3144 | |
| 3145 | $iteration = 0; |
| 3146 | foreach ( $items as $item ) { |
| 3147 | $item_id = $item->get_product_id(); |
| 3148 | |
| 3149 | if ( -1 === $product_id && 0 === $iteration ) { |
| 3150 | $product_ids[] = $item_id; |
| 3151 | break; |
| 3152 | } elseif ( $item_id === $product_id ) { |
| 3153 | $product_ids[] = $item_id; |
| 3154 | break; |
| 3155 | } |
| 3156 | |
| 3157 | $iteration++; |
| 3158 | } |
| 3159 | $order_data = WooCommerce::get_order_context( $order_id ); |
| 3160 | $user_data = WordPress::get_user_context( $user_id ); |
| 3161 | $order_data['total_items_in_order'] = count( $product_ids ); |
| 3162 | |
| 3163 | $context['response_type'] = 'live'; |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | $context['pluggable_data'] = array_merge( $order_data, $product_data, $user_data ); |
| 3168 | |
| 3169 | } elseif ( 'variable_product_purchased' === $term ) { |
| 3170 | $product_variation_id = (int) ( isset( $data['filter']['product_variation_id']['value'] ) ? $data['filter']['product_variation_id']['value'] : -1 ); |
| 3171 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 3172 | |
| 3173 | foreach ( $order_ids as $order_id ) { |
| 3174 | $order = wc_get_order( $order_id ); |
| 3175 | |
| 3176 | if ( $order ) { |
| 3177 | $user_id = $order->get_customer_id(); |
| 3178 | $items = $order->get_items(); |
| 3179 | $product_variations = []; |
| 3180 | |
| 3181 | $iteration = 0; |
| 3182 | foreach ( $items as $item ) { |
| 3183 | $variation_id = $item->get_variation_id(); |
| 3184 | |
| 3185 | if ( -1 === $product_variation_id && 0 === $iteration ) { |
| 3186 | $product_variations[] = $variation_id; |
| 3187 | break; |
| 3188 | } elseif ( $variation_id === $product_variation_id ) { |
| 3189 | $product_variations[] = $variation_id; |
| 3190 | break; |
| 3191 | } |
| 3192 | |
| 3193 | $iteration++; |
| 3194 | } |
| 3195 | |
| 3196 | if ( count( $product_variations ) > 0 ) { |
| 3197 | $product_data = WooCommerce::get_product_context( $product_variation_id ); |
| 3198 | $order_data = WooCommerce::get_order_context( $order_id ); |
| 3199 | $user_data = WordPress::get_user_context( $user_id ); |
| 3200 | $variation_data = [ |
| 3201 | 'product_variation_id' => $product_variations[0], |
| 3202 | 'product_variation' => get_the_excerpt( $product_variations[0] ), |
| 3203 | ]; |
| 3204 | |
| 3205 | $context['response_type'] = 'live'; |
| 3206 | break; |
| 3207 | } |
| 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | $context['pluggable_data'] = array_merge( $order_data, $user_data, $variation_data ); |
| 3212 | |
| 3213 | } elseif ( 'variable_subscription_purchased' === $term ) { |
| 3214 | $product_data['quantity'] = '1'; |
| 3215 | $product_data['product_name'] = 'Sample Product'; |
| 3216 | $product_data['billing_period'] = '2021-2022'; |
| 3217 | |
| 3218 | $context['pluggable_data'] = array_merge( $order_data, $product_data, $user_data ); |
| 3219 | |
| 3220 | $subscription_order_id = 0; |
| 3221 | $order_ids = []; |
| 3222 | |
| 3223 | if ( -1 !== $product_id ) { |
| 3224 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 3225 | |
| 3226 | } else { |
| 3227 | $orders = wc_get_orders( [] ); |
| 3228 | if ( count( $orders ) > 0 ) { |
| 3229 | $order_ids[] = $orders[0]->get_id(); |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | foreach ( $order_ids as $order_id ) { |
| 3234 | $query_args = [ |
| 3235 | 'post_type' => 'shop_subscription', |
| 3236 | 'orderby' => 'ID', |
| 3237 | 'order' => 'DESC', |
| 3238 | 'post_status' => 'wc-active', |
| 3239 | 'posts_per_page' => 1, |
| 3240 | 'post_parent' => $order_id, |
| 3241 | ]; |
| 3242 | $query_result = new WP_Query( $query_args ); |
| 3243 | $subscription_orders = $query_result->get_posts(); |
| 3244 | |
| 3245 | if ( count( $subscription_orders ) > 0 ) { |
| 3246 | $subscription_order_id = $subscription_orders[0]->ID; |
| 3247 | break; |
| 3248 | } |
| 3249 | } |
| 3250 | |
| 3251 | if ( 0 !== $subscription_order_id ) { |
| 3252 | $subscription = wcs_get_subscription( $subscription_order_id ); |
| 3253 | if ( $subscription instanceof WC_Subscription ) { |
| 3254 | $last_order_id = $subscription->get_last_order(); |
| 3255 | if ( ! empty( $last_order_id ) && $last_order_id === $subscription->get_parent_id() ) { |
| 3256 | $user_id = wc_get_order( $last_order_id )->get_customer_id(); |
| 3257 | $items = $subscription->get_items(); |
| 3258 | |
| 3259 | foreach ( $items as $item ) { |
| 3260 | $product = $item->get_product(); |
| 3261 | if ( class_exists( '\WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) { |
| 3262 | if ( $product->is_type( [ 'subscription', 'subscription_variation', 'variable-subscription' ] ) ) { |
| 3263 | |
| 3264 | $product_data = WooCommerce::get_variable_subscription_product_context( $item, $last_order_id ); |
| 3265 | $user_data = WordPress::get_user_context( $user_id ); |
| 3266 | |
| 3267 | $context['response_type'] = 'live'; |
| 3268 | $context['pluggable_data'] = array_merge( $product_data, $user_data ); |
| 3269 | } |
| 3270 | } |
| 3271 | } |
| 3272 | } |
| 3273 | } |
| 3274 | } |
| 3275 | } elseif ( 'order_created' === $term ) { |
| 3276 | $orders = wc_get_orders( [ 'numberposts' => 1 ] ); |
| 3277 | if ( count( $orders ) > 0 ) { |
| 3278 | $order_id = $orders[0]->get_id(); |
| 3279 | } |
| 3280 | $order = wc_get_order( $order_id ); |
| 3281 | $user_id = $order->get_customer_id(); |
| 3282 | $order_sample_data = array_merge( |
| 3283 | WooCommerce::get_order_context( $order_id ), |
| 3284 | WordPress::get_user_context( $user_id ) |
| 3285 | ); |
| 3286 | $context['response_type'] = 'live'; |
| 3287 | $context['pluggable_data'] = $order_sample_data; |
| 3288 | |
| 3289 | } |
| 3290 | |
| 3291 | return $context; |
| 3292 | } |
| 3293 | |
| 3294 | /** |
| 3295 | * Search LMS data. |
| 3296 | * |
| 3297 | * @param array $data data. |
| 3298 | * @return array |
| 3299 | */ |
| 3300 | public function search_lifter_lms_last_data( $data ) { |
| 3301 | global $wpdb; |
| 3302 | $post_type = $data['post_type']; |
| 3303 | $meta_key = '_is_complete'; |
| 3304 | $trigger = $data['search_term']; |
| 3305 | $context = []; |
| 3306 | if ( 'lifterlms_purchase_course' === $trigger ) { |
| 3307 | $product_type = 'course'; |
| 3308 | $post_id = $data['filter']['course_id']['value']; |
| 3309 | } elseif ( 'lifterlms_purchase_membership' === $trigger ) { |
| 3310 | $product_type = 'membership'; |
| 3311 | $post_id = $data['filter']['membership_id']['value']; |
| 3312 | } elseif ( 'lifterlms_lesson_completed' === $trigger ) { |
| 3313 | $post_id = $data['filter']['lesson']['value']; |
| 3314 | } elseif ( 'lifterlms_course_completed' === $trigger ) { |
| 3315 | $post_id = $data['filter']['course']['value']; |
| 3316 | } |
| 3317 | |
| 3318 | $where = 'postmeta.post_id = "' . $post_id . '" AND'; |
| 3319 | |
| 3320 | if ( 'llms_order' === $post_type ) { |
| 3321 | if ( -1 === $post_id ) { |
| 3322 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='llms_order' AND posts.post_status= 'llms-completed' AND postmeta.meta_value=%s AND postmeta.meta_key= '_llms_product_type'", $product_type ) ); |
| 3323 | } else { |
| 3324 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='llms_order' AND posts.post_status= 'llms-completed' AND postmeta.meta_value=%s AND postmeta.meta_key= '_llms_product_id'", $post_id ) ); |
| 3325 | } |
| 3326 | } else { |
| 3327 | if ( -1 === $post_id ) { |
| 3328 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}lifterlms_user_postmeta as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.post_id WHERE postmeta.meta_value='yes' AND postmeta.meta_key=%s AND posts.post_type=%s", $meta_key, $post_type ) ); |
| 3329 | } else { |
| 3330 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}lifterlms_user_postmeta as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.post_id WHERE postmeta.post_id = %s AND postmeta.meta_value='yes' AND postmeta.meta_key=%s AND posts.post_type=%s", $post_id, $meta_key, $post_type ) ); |
| 3331 | } |
| 3332 | } |
| 3333 | |
| 3334 | $response = []; |
| 3335 | if ( ! empty( $result ) ) { |
| 3336 | $result_post_id = $result[0]->post_id; |
| 3337 | $result_user_id = $result[0]->user_id; |
| 3338 | |
| 3339 | switch ( $trigger ) { |
| 3340 | case 'lifterlms_lesson_completed': |
| 3341 | $context = array_merge( |
| 3342 | WordPress::get_user_context( $result_user_id ), |
| 3343 | LifterLMS::get_lms_lesson_context( $result_post_id ) |
| 3344 | ); |
| 3345 | |
| 3346 | $context['course'] = get_the_title( get_post_meta( $result_post_id, '_llms_parent_course', true ) ); |
| 3347 | if ( '' !== ( get_post_meta( $result_post_id, '_llms_parent_section', true ) ) ) { |
| 3348 | $context['parent_section'] = get_the_title( get_post_meta( $result_post_id, '_llms_parent_section', true ) ); |
| 3349 | } |
| 3350 | break; |
| 3351 | case 'lifterlms_course_completed': |
| 3352 | $context = array_merge( |
| 3353 | WordPress::get_user_context( $result_user_id ), |
| 3354 | LifterLMS::get_lms_course_context( $result_post_id ) |
| 3355 | ); |
| 3356 | break; |
| 3357 | case 'lifterlms_purchase_course': |
| 3358 | $user_id = get_post_meta( $result_post_id, '_llms_user_id', true ); |
| 3359 | $context['course_id'] = get_post_meta( $result_post_id, '_llms_product_id', true ); |
| 3360 | $context['course_name'] = get_post_meta( $result_post_id, '_llms_product_title', true ); |
| 3361 | $context['course_amount'] = get_post_meta( $result_post_id, '_llms_original_total', true ); |
| 3362 | $context['currency'] = get_post_meta( $result_post_id, '_llms_currency', true ); |
| 3363 | $context ['order'] = WordPress::get_post_context( $result_post_id ); |
| 3364 | $context['order_type'] = get_post_meta( $result_post_id, '_llms_order_type', true ); |
| 3365 | $context['trial_offer'] = get_post_meta( $result_post_id, '_llms_trial_offer', true ); |
| 3366 | $context['billing_frequency'] = get_post_meta( $result_post_id, '_llms_billing_frequency', true ); |
| 3367 | $context = array_merge( $context, WordPress::get_user_context( $user_id ) ); |
| 3368 | break; |
| 3369 | case 'lifterlms_purchase_membership': |
| 3370 | $user_id = get_post_meta( $result_post_id, '_llms_user_id', true ); |
| 3371 | $context['membership_id'] = get_post_meta( $result_post_id, '_llms_product_id', true ); |
| 3372 | $context['membership_name'] = get_post_meta( $result_post_id, '_llms_product_title', true ); |
| 3373 | $context['membership_amount'] = get_post_meta( $result_post_id, '_llms_original_total', true ); |
| 3374 | $context['currency'] = get_post_meta( $result_post_id, '_llms_currency', true ); |
| 3375 | $context ['order'] = WordPress::get_post_context( $result_post_id ); |
| 3376 | $context['order_type'] = get_post_meta( $result_post_id, '_llms_order_type', true ); |
| 3377 | $context['trial_offer'] = get_post_meta( $result_post_id, '_llms_trial_offer', true ); |
| 3378 | $context['billing_frequency'] = get_post_meta( $result_post_id, '_llms_billing_frequency', true ); |
| 3379 | $context = array_merge( $context, WordPress::get_user_context( $user_id ) ); |
| 3380 | break; |
| 3381 | default: |
| 3382 | return; |
| 3383 | |
| 3384 | } |
| 3385 | $response['pluggable_data'] = $context; |
| 3386 | $response['response_type'] = 'live'; |
| 3387 | |
| 3388 | } |
| 3389 | |
| 3390 | return $response; |
| 3391 | |
| 3392 | } |
| 3393 | |
| 3394 | /** |
| 3395 | * Search SM data. |
| 3396 | * |
| 3397 | * @param array $data data. |
| 3398 | * @return array |
| 3399 | */ |
| 3400 | public function search_suremember_last_data( $data ) { |
| 3401 | global $wpdb; |
| 3402 | $post_type = $data['post_type']; |
| 3403 | $meta_key = '_is_complete'; |
| 3404 | $trigger = $data['search_term']; |
| 3405 | $post_id = $data['filter']['group_id']['value']; |
| 3406 | |
| 3407 | if ( 'suremember_updated_group' === $trigger ) { |
| 3408 | if ( -1 === $post_id ) { |
| 3409 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts WHERE posts.post_type=%s", $post_type ) ); |
| 3410 | } else { |
| 3411 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts WHERE posts.ID=%s AND posts.post_type=%s", $post_id, $post_type ) ); |
| 3412 | } |
| 3413 | } else { |
| 3414 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usermeta as usermeta WHERE usermeta.meta_key = %s", 'suremembers_user_access_group_' . $post_id ) ); |
| 3415 | } |
| 3416 | |
| 3417 | $response = []; |
| 3418 | |
| 3419 | if ( ! empty( $result ) ) { |
| 3420 | $context = []; |
| 3421 | switch ( $trigger ) { |
| 3422 | case 'suremember_updated_group': |
| 3423 | $group_id = $result[0]->ID; |
| 3424 | $suremembers_post['rules'] = get_post_meta( $group_id, 'suremembers_plan_include', true ); |
| 3425 | $suremembers_post['exclude'] = get_post_meta( $group_id, 'suremembers_plan_exclude', true ); //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude |
| 3426 | $suremembers_post['suremembers_user_roles'] = get_post_meta( $group_id, 'suremembers_user_roles', true ); |
| 3427 | $suremembers_post['title'] = get_the_title( $group_id ); |
| 3428 | $suremembers_post['restrict'] = get_post_meta( $group_id, 'suremembers_plan_rules', true )['restrict']; |
| 3429 | $context['group'] = array_merge( WordPress::get_post_context( $group_id ), $suremembers_post ); |
| 3430 | $context['group_id'] = $group_id; |
| 3431 | unset( $context['group']['ID'] ); |
| 3432 | $response['pluggable_data'] = $context; |
| 3433 | $response['response_type'] = 'live'; |
| 3434 | break; |
| 3435 | case 'suremember_user_added_in_group': |
| 3436 | foreach ( $result as $res ) { |
| 3437 | $meta_value = unserialize( $res->meta_value ); |
| 3438 | if ( 'active' === $meta_value['status'] ) { |
| 3439 | $context = WordPress::get_user_context( $res->user_id ); |
| 3440 | $context['group'] = WordPress::get_post_context( $post_id ); |
| 3441 | $response['pluggable_data'] = $context; |
| 3442 | $response['response_type'] = 'live'; |
| 3443 | } |
| 3444 | } |
| 3445 | break; |
| 3446 | case 'suremember_user_removed_from_group': |
| 3447 | foreach ( $result as $res ) { |
| 3448 | $meta_value = unserialize( $res->meta_value ); |
| 3449 | if ( 'revoked' === $meta_value['status'] ) { |
| 3450 | $context = WordPress::get_user_context( $res->user_id ); |
| 3451 | $context['group'] = WordPress::get_post_context( $post_id ); |
| 3452 | $response['pluggable_data'] = $context; |
| 3453 | $response['response_type'] = 'live'; |
| 3454 | } |
| 3455 | } |
| 3456 | break; |
| 3457 | default: |
| 3458 | return; |
| 3459 | |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | return $response; |
| 3464 | |
| 3465 | } |
| 3466 | |
| 3467 | /** |
| 3468 | * Search CartFlows data. |
| 3469 | * |
| 3470 | * @param array $data data. |
| 3471 | * @return array |
| 3472 | */ |
| 3473 | public function search_cartflows_last_data( $data ) { |
| 3474 | global $wpdb; |
| 3475 | $trigger = $data['search_term']; |
| 3476 | $context = []; |
| 3477 | if ( 'cartflows_offer_accepted' === $trigger ) { |
| 3478 | $result = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts as posts JOIN {$wpdb->prefix}postmeta as postmeta ON posts.ID=postmeta.post_id WHERE posts.post_type ='shop_order' AND postmeta.meta_value='upsell' AND postmeta.meta_key= '_cartflows_offer_type'" ); |
| 3479 | } |
| 3480 | $response = []; |
| 3481 | if ( ! empty( $result ) ) { |
| 3482 | $context = []; |
| 3483 | $order_upsell_id = $result[0]->post_id; |
| 3484 | $step_id = get_post_meta( $order_upsell_id, '_cartflows_offer_step_id', true ); |
| 3485 | $order_id = get_post_meta( $order_upsell_id, '_cartflows_offer_parent_id', true ); |
| 3486 | $order = wc_get_order( $order_id ); |
| 3487 | $upsell_order = wc_get_order( $order_upsell_id ); |
| 3488 | $variation_id = $upsell_order->get_items()[0]['product_id']; |
| 3489 | $input_qty = $upsell_order->get_items()[0]['quantity']; |
| 3490 | $offer_product = wcf_pro()->utils->get_offer_data( $step_id, $variation_id, $input_qty, $order_id ); |
| 3491 | $user_id = get_post_meta( $order_upsell_id, '_customer_user', true ); |
| 3492 | $context = WordPress::get_user_context( $user_id ); |
| 3493 | $context['order'] = $order->get_data(); |
| 3494 | $context['upsell'] = $offer_product; |
| 3495 | $response['pluggable_data'] = $context; |
| 3496 | $response['response_type'] = 'live'; |
| 3497 | } |
| 3498 | |
| 3499 | return $response; |
| 3500 | |
| 3501 | } |
| 3502 | |
| 3503 | |
| 3504 | /** |
| 3505 | * Fetch user context. |
| 3506 | * |
| 3507 | * @param int $initiator_id initiator id. |
| 3508 | * @param int $friend_id friend id. |
| 3509 | * @return array |
| 3510 | */ |
| 3511 | public function get_user_context( $initiator_id, $friend_id ) { |
| 3512 | $context = WordPress::get_user_context( $initiator_id ); |
| 3513 | |
| 3514 | $friend_context = WordPress::get_user_context( $friend_id ); |
| 3515 | |
| 3516 | $avatar = get_avatar_url( $initiator_id ); |
| 3517 | |
| 3518 | $context['avatar_url'] = ( $avatar ) ? $avatar : ''; |
| 3519 | |
| 3520 | $context['friend_id'] = $friend_id; |
| 3521 | $context['friend_first_name'] = $friend_context['user_firstname']; |
| 3522 | $context['friend_last_name'] = $friend_context['user_lastname']; |
| 3523 | $context['friend_email'] = $friend_context['user_email']; |
| 3524 | |
| 3525 | $friend_avatar = get_avatar_url( $friend_id ); |
| 3526 | $context['friend_avatar_url'] = $friend_avatar; |
| 3527 | return $context; |
| 3528 | } |
| 3529 | |
| 3530 | /** |
| 3531 | * Search BP data. |
| 3532 | * |
| 3533 | * @param array $data data. |
| 3534 | * @return array |
| 3535 | */ |
| 3536 | public function search_pluggables_bp_friendships( $data ) { |
| 3537 | global $wpdb, $bp; |
| 3538 | $context = []; |
| 3539 | $friendships = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s LIMIT 1', $bp->friends->table_name ), ARRAY_A ); |
| 3540 | if ( ! empty( $friendships ) ) { |
| 3541 | $friendship = $friendships[0]; |
| 3542 | $initiator_id = $friendship['initiator_user_id']; |
| 3543 | $friend_user_id = $friendship['friend_user_id']; |
| 3544 | $context['pluggable_data'] = $this->get_user_context( $initiator_id, $friend_user_id ); |
| 3545 | $context['response_type'] = 'live'; |
| 3546 | } else { |
| 3547 | $context['pluggable_data'] = [ |
| 3548 | 'wp_user_id' => 4, |
| 3549 | 'user_login' => 'katy1ßßßß', |
| 3550 | 'display_name' => 'Katy Smith', |
| 3551 | 'user_firstname' => 'Katy', |
| 3552 | 'user_lastname' => 'Smith', |
| 3553 | 'user_email' => 'katy1@gmail.com', |
| 3554 | 'user_role' => [ 'subscriber' ], |
| 3555 | 'avatar_url' => 'http://pqr.com/avatar', |
| 3556 | 'friend_id' => 1, |
| 3557 | 'friend_first_name' => 'John', |
| 3558 | 'friend_last_name' => 'Wick', |
| 3559 | 'friend_email' => 'john@gmail.com', |
| 3560 | 'friend_avatar_url' => 'http://abc.com/avatar', |
| 3561 | ]; |
| 3562 | $context['response_type'] = 'sample'; |
| 3563 | } |
| 3564 | return $context; |
| 3565 | } |
| 3566 | |
| 3567 | /** |
| 3568 | * Search BP data. |
| 3569 | * |
| 3570 | * @param array $data data. |
| 3571 | * @return array |
| 3572 | */ |
| 3573 | public function search_pluggables_bp_groups( $data ) { |
| 3574 | global $wpdb, $bp; |
| 3575 | $context = []; |
| 3576 | $group_data = []; |
| 3577 | $args = [ |
| 3578 | 'orderby' => 'user_nicename', |
| 3579 | 'order' => 'ASC', |
| 3580 | 'number' => 1, |
| 3581 | ]; |
| 3582 | |
| 3583 | $users = get_users( $args ); |
| 3584 | |
| 3585 | if ( isset( $data['filter']['group_id']['value'] ) ) { |
| 3586 | $group_id = $data['filter']['group_id']['value']; |
| 3587 | $args['group_id'] = $group_id; |
| 3588 | if ( $group_id > 0 ) { |
| 3589 | $group = groups_get_group( $group_id ); |
| 3590 | $group_data['group_id'] = ( property_exists( $group, 'id' ) ) ? (int) $group->id : ''; |
| 3591 | $group_data['group_name'] = ( property_exists( $group, 'name' ) ) ? $group->name : ''; |
| 3592 | $group_data['group_description'] = ( property_exists( $group, 'description' ) ) ? $group->description : ''; |
| 3593 | } else { |
| 3594 | $groups = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s LIMIT 1', $bp->groups->table_name ) ); |
| 3595 | $context['groupss'] = $groups; |
| 3596 | if ( ! empty( $groups ) ) { |
| 3597 | foreach ( $groups as $group ) { |
| 3598 | $group_data['group_id'] = $group->id; |
| 3599 | $group_data['group_name'] = $group->name; |
| 3600 | $group_data['group_description'] = $group->description; |
| 3601 | } |
| 3602 | } |
| 3603 | } |
| 3604 | } |
| 3605 | |
| 3606 | if ( ! empty( $users ) ) { |
| 3607 | $user = $users[0]; |
| 3608 | $pluggable_data = $group_data; |
| 3609 | |
| 3610 | $avatar = get_avatar_url( $user->ID ); |
| 3611 | $pluggable_data['wp_user_id'] = $user->ID; |
| 3612 | $pluggable_data['avatar_url'] = ( $avatar ) ? $avatar : ''; |
| 3613 | $pluggable_data['user_login'] = $user->user_login; |
| 3614 | $pluggable_data['display_name'] = $user->display_name; |
| 3615 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 3616 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 3617 | $pluggable_data['user_email'] = $user->user_email; |
| 3618 | $pluggable_data['user_role'] = $user->roles; |
| 3619 | $context['pluggable_data'] = $pluggable_data; |
| 3620 | $context['response_type'] = 'live'; |
| 3621 | } else { |
| 3622 | $context['pluggable_data'] = [ |
| 3623 | 'wp_user_id' => 1, |
| 3624 | 'user_login' => 'admin', |
| 3625 | 'display_name' => 'Test User', |
| 3626 | 'user_firstname' => 'Test', |
| 3627 | 'user_lastname' => 'User', |
| 3628 | 'user_email' => 'testuser@gmail.com', |
| 3629 | 'user_role' => [ 'subscriber' ], |
| 3630 | 'group_id' => 112, |
| 3631 | 'group_name' => 'Test Group', |
| 3632 | 'group_description' => 'Test Group Description', |
| 3633 | ]; |
| 3634 | $context['response_type'] = 'sample'; |
| 3635 | } |
| 3636 | |
| 3637 | return $context; |
| 3638 | } |
| 3639 | |
| 3640 | /** |
| 3641 | * Search complete courses. |
| 3642 | * |
| 3643 | * @param array $data data. |
| 3644 | * @return array |
| 3645 | */ |
| 3646 | public function search_pluggables_complete_course( $data ) { |
| 3647 | global $wpdb; |
| 3648 | $context = []; |
| 3649 | |
| 3650 | if ( isset( $data['filter']['sfwd_course_id']['value'] ) ) { |
| 3651 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 3652 | } |
| 3653 | if ( -1 === $course_id ) { |
| 3654 | $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='course' AND activity.activity_status= %d AND activity.course_id= %d", 1, $course_id ) ); |
| 3655 | } else { |
| 3656 | $courses = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='course' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d", 1, $course_id, $course_id ) ); |
| 3657 | } |
| 3658 | |
| 3659 | if ( ! empty( $courses ) ) { |
| 3660 | $course = $courses[0]; |
| 3661 | $course_data['course_name'] = $course->post_title; |
| 3662 | $course_data['sfwd_course_id'] = $course->ID; |
| 3663 | $course_data['course_url'] = get_permalink( $course->ID ); |
| 3664 | $course_data['course_featured_image_id'] = get_post_meta( $course->ID, '_thumbnail_id', true ); |
| 3665 | $course_data['course_featured_image_url'] = get_the_post_thumbnail_url( $course->ID ); |
| 3666 | $context['response_type'] = 'live'; |
| 3667 | } else { |
| 3668 | $course_data['course_name'] = 'Test Course'; |
| 3669 | $course_data['sfwd_course_id'] = 112; |
| 3670 | $course_data['course_url'] = 'https://abc.com/test-course'; |
| 3671 | $course_data['course_featured_image_id'] = 113; |
| 3672 | $course_data['course_featured_image_url'] = 'https://pqr.com/test-course-img'; |
| 3673 | $context['response_type'] = 'sample'; |
| 3674 | } |
| 3675 | |
| 3676 | $users_data = $this->search_pluggables_add_user_role( [] ); |
| 3677 | $user_data = $users_data['pluggable_data']; |
| 3678 | |
| 3679 | $context['pluggable_data'] = array_merge( $course_data, $user_data ); |
| 3680 | return $context; |
| 3681 | } |
| 3682 | |
| 3683 | /** |
| 3684 | * Search lessons. |
| 3685 | * |
| 3686 | * @param array $data data. |
| 3687 | * @return array |
| 3688 | */ |
| 3689 | public function search_pluggables_complete_lesson( $data ) { |
| 3690 | global $wpdb; |
| 3691 | $context = []; |
| 3692 | |
| 3693 | if ( isset( $data['filter']['sfwd_lesson_id']['value'] ) ) { |
| 3694 | $lesson_id = $data['filter']['sfwd_lesson_id']['value']; |
| 3695 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 3696 | } |
| 3697 | $course = get_post( $course_id ); |
| 3698 | $pluggable_data = LearnDash::get_course_context( $course ); |
| 3699 | |
| 3700 | if ( -1 === $lesson_id ) { |
| 3701 | $lessons = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='lesson' AND activity.activity_status= %d AND activity.course_id= %d", 1, $course_id ) ); |
| 3702 | } else { |
| 3703 | $lessons = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='lesson' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d", 1, $lesson_id, $course_id ) ); |
| 3704 | } |
| 3705 | |
| 3706 | if ( ! empty( $lessons ) ) { |
| 3707 | $lesson = $lessons[0]; |
| 3708 | |
| 3709 | $pluggable_data['lesson_name'] = $lesson->post_title; |
| 3710 | $pluggable_data['sfwd_lesson_id'] = $lesson->ID; |
| 3711 | $pluggable_data['lesson_url'] = get_permalink( $lesson->ID ); |
| 3712 | $pluggable_data['lesson_featured_image_id'] = get_post_meta( $lesson->ID, '_thumbnail_id', true ); |
| 3713 | $pluggable_data['lesson_featured_image_url'] = get_the_post_thumbnail_url( $lesson->ID ); |
| 3714 | $context['response_type'] = 'live'; |
| 3715 | } else { |
| 3716 | $pluggable_data['lesson_name'] = 'Test Lesson'; |
| 3717 | $pluggable_data['sfwd_lesson_id'] = 114; |
| 3718 | $pluggable_data['lesson_url'] = 'https://abc.com/test-lesson'; |
| 3719 | $pluggable_data['lesson_featured_image_id'] = 116; |
| 3720 | $pluggable_data['lesson_featured_image_url'] = 'https://pqr.com/test-lesson-img'; |
| 3721 | $context['response_type'] = 'sample'; |
| 3722 | } |
| 3723 | |
| 3724 | $context['pluggable_data'] = $pluggable_data; |
| 3725 | return $context; |
| 3726 | } |
| 3727 | |
| 3728 | /** |
| 3729 | * Search topics. |
| 3730 | * |
| 3731 | * @param array $data data. |
| 3732 | * @return array |
| 3733 | */ |
| 3734 | public function search_pluggables_complete_topic( $data ) { |
| 3735 | global $wpdb; |
| 3736 | $context = []; |
| 3737 | |
| 3738 | if ( isset( $data['filter']['sfwd_topic_id']['value'] ) ) { |
| 3739 | $topic_id = $data['filter']['sfwd_topic_id']['value']; |
| 3740 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 3741 | } |
| 3742 | $course = get_post( $course_id ); |
| 3743 | $pluggable_data = LearnDash::get_course_context( $course ); |
| 3744 | |
| 3745 | if ( -1 === $topic_id ) { |
| 3746 | $topics = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='topic' AND activity.activity_status= %d AND activity.course_id= %d", 1, $course_id ) ); |
| 3747 | } else { |
| 3748 | $topics = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learndash_user_activity as activity JOIN {$wpdb->prefix}posts as post ON activity.post_id=post.ID WHERE activity.activity_type ='topic' AND activity.activity_status= %d AND activity.post_id= %d AND activity.course_id= %d", 1, $topic_id, $course_id ) ); |
| 3749 | } |
| 3750 | |
| 3751 | if ( ! empty( $topics ) ) { |
| 3752 | $topic = $topics[0]; |
| 3753 | |
| 3754 | $pluggable_data['topic_name'] = $topic->post_title; |
| 3755 | $pluggable_data['sfwd_topic_id'] = $topic->ID; |
| 3756 | $pluggable_data['topic_url'] = get_permalink( $topic->ID ); |
| 3757 | $pluggable_data['topic_featured_image_id'] = get_post_meta( $topic->ID, '_thumbnail_id', true ); |
| 3758 | $pluggable_data['topic_featured_image_url'] = get_the_post_thumbnail_url( $topic->ID ); |
| 3759 | $context['response_type'] = 'live'; |
| 3760 | } else { |
| 3761 | $pluggable_data['topic_name'] = 'Test Topic'; |
| 3762 | $pluggable_data['sfwd_topic_id'] = 117; |
| 3763 | $pluggable_data['topic_url'] = 'https://abc.com/test-topic'; |
| 3764 | $pluggable_data['topic_featured_image_id'] = 118; |
| 3765 | $pluggable_data['topic_featured_image_url'] = 'https://pqr.com/test-topic-img'; |
| 3766 | $context['response_type'] = 'sample'; |
| 3767 | } |
| 3768 | |
| 3769 | $context['pluggable_data'] = $pluggable_data; |
| 3770 | return $context; |
| 3771 | } |
| 3772 | |
| 3773 | /** |
| 3774 | * Search purchase courses. |
| 3775 | * |
| 3776 | * @param array $data data. |
| 3777 | * @return array |
| 3778 | */ |
| 3779 | public function search_pluggables_purchase_course( $data ) { |
| 3780 | $context = []; |
| 3781 | $context['response_type'] = 'sample'; |
| 3782 | |
| 3783 | $purchase_data = [ |
| 3784 | 'course_product_id' => '1', |
| 3785 | 'course_product_name' => 'Sample Course', |
| 3786 | 'currency' => 'USD', |
| 3787 | 'total_amount' => '100', |
| 3788 | 'first_name' => 'John', |
| 3789 | 'last_name' => 'Doe', |
| 3790 | 'email' => 'john_doe@bsf.io', |
| 3791 | 'phone' => '+923007626541', |
| 3792 | ]; |
| 3793 | |
| 3794 | $product_id = (int) ( isset( $data['filter']['course_product_id']['value'] ) ? $data['filter']['course_product_id']['value'] : '-1' ); |
| 3795 | $order_id = 0; |
| 3796 | |
| 3797 | if ( -1 !== $product_id ) { |
| 3798 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 3799 | |
| 3800 | if ( count( $order_ids ) > 0 ) { |
| 3801 | $order_id = $order_ids[0]; |
| 3802 | } |
| 3803 | } else { |
| 3804 | $orders = wc_get_orders( [] ); |
| 3805 | if ( count( $orders ) > 0 ) { |
| 3806 | foreach ( $orders as $order ) { |
| 3807 | $items = $order->get_items(); |
| 3808 | |
| 3809 | if ( count( $items ) > 1 ) { |
| 3810 | continue; |
| 3811 | } |
| 3812 | |
| 3813 | foreach ( $items as $item ) { |
| 3814 | if ( ! empty( get_post_meta( $item->get_product_id(), '_related_course', true ) ) ) { |
| 3815 | $order_id = $order->get_id(); |
| 3816 | break; |
| 3817 | } |
| 3818 | } |
| 3819 | } |
| 3820 | } |
| 3821 | } |
| 3822 | |
| 3823 | if ( 0 !== $order_id ) { |
| 3824 | $order = wc_get_order( $order_id ); |
| 3825 | |
| 3826 | if ( $order ) { |
| 3827 | |
| 3828 | $purchase_data = LearnDash::get_purchase_course_context( $order ); |
| 3829 | |
| 3830 | $context['response_type'] = 'live'; |
| 3831 | } |
| 3832 | } |
| 3833 | |
| 3834 | $context['pluggable_data'] = $purchase_data; |
| 3835 | |
| 3836 | return $context; |
| 3837 | } |
| 3838 | |
| 3839 | /** |
| 3840 | * Fetch BB templates. |
| 3841 | * |
| 3842 | * @return array |
| 3843 | */ |
| 3844 | public function get_beaver_builder_templates() { |
| 3845 | $allowed_types = [ 'subscribe-form', 'contact-form' ]; |
| 3846 | $templates = []; |
| 3847 | $all_templates = get_posts( |
| 3848 | [ |
| 3849 | 'post_type' => 'fl-builder-template', |
| 3850 | 'meta_key' => '_fl_builder_data', |
| 3851 | 'posts_per_page' => -1, |
| 3852 | ] |
| 3853 | ); |
| 3854 | $posts = get_posts( |
| 3855 | [ |
| 3856 | 'post_type' => 'any', |
| 3857 | 'meta_key' => '_fl_builder_data', |
| 3858 | 'posts_per_page' => -1, |
| 3859 | ] |
| 3860 | ); |
| 3861 | $posts = array_merge( $all_templates, $posts ); |
| 3862 | |
| 3863 | if ( ! empty( $posts ) ) { |
| 3864 | foreach ( $posts as $post ) { |
| 3865 | $meta = get_post_meta( $post->ID, '_fl_builder_data', true ); |
| 3866 | foreach ( (array) $meta as $node_id => $node ) { |
| 3867 | if ( isset( $node->type ) && 'module' === $node->type ) { |
| 3868 | $settings = $node->settings; |
| 3869 | if ( in_array( $settings->type, $allowed_types, true ) ) { |
| 3870 | $label = $post->post_title; |
| 3871 | if ( '' !== $settings->node_label ) { |
| 3872 | $label .= ' - ' . $settings->node_label; |
| 3873 | } |
| 3874 | $templates[] = [ |
| 3875 | 'label' => $label, |
| 3876 | 'value' => $node_id, |
| 3877 | ]; |
| 3878 | } |
| 3879 | } |
| 3880 | } |
| 3881 | } |
| 3882 | } |
| 3883 | return $templates; |
| 3884 | } |
| 3885 | |
| 3886 | /** |
| 3887 | * Search beaver builder forms. |
| 3888 | * |
| 3889 | * @param array $data data. |
| 3890 | * @return array |
| 3891 | */ |
| 3892 | public function search_beaver_builder_forms( $data ) { |
| 3893 | $templates = $this->get_beaver_builder_templates(); |
| 3894 | return [ |
| 3895 | 'options' => $templates, |
| 3896 | 'hasMore' => false, |
| 3897 | ]; |
| 3898 | } |
| 3899 | |
| 3900 | /** |
| 3901 | * Search fluentcrm fields. |
| 3902 | * |
| 3903 | * @param array $data data. |
| 3904 | * @return array |
| 3905 | */ |
| 3906 | public function search_fluentcrm_custom_fields( $data ) { |
| 3907 | $context = []; |
| 3908 | $custom_fields = ( new CustomContactField() )->getGlobalFields()['fields']; |
| 3909 | $context['fields'] = $custom_fields; |
| 3910 | return $context; |
| 3911 | } |
| 3912 | |
| 3913 | /** |
| 3914 | * Fetch WP JOB Manager Last Data. |
| 3915 | * |
| 3916 | * @param array $data data. |
| 3917 | * @return array |
| 3918 | */ |
| 3919 | public function search_wp_job_manger_last_data( $data ) { |
| 3920 | global $wpdb; |
| 3921 | $job_type = $data['filter']['job_type']['value']; |
| 3922 | $args = [ |
| 3923 | 'posts_per_page' => 1, |
| 3924 | 'post_type' => 'job_listing', |
| 3925 | 'orderby' => 'id', |
| 3926 | 'order' => 'DESC', |
| 3927 | ]; |
| 3928 | |
| 3929 | if ( -1 !== $job_type ) { |
| 3930 | $args['tax_query'] = [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query |
| 3931 | [ |
| 3932 | 'taxonomy' => 'job_listing_type', |
| 3933 | 'field' => 'term_id', |
| 3934 | 'terms' => $job_type, |
| 3935 | ], |
| 3936 | ]; |
| 3937 | } |
| 3938 | $posts = get_posts( $args ); |
| 3939 | if ( empty( $posts ) ) { |
| 3940 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"ID":145,"wpjob_author":"1","wpjob_date":"2023-01-22 17:38:03","wpjob_date_gmt":"2023-01-22 17:38:03","wpjob_content":"","wpjob_title":"PHP Developer","wpjob_excerpt":"","wpjob_status":"publish","comment_status":"closed","ping_status":"closed","wpjob_password":"","wpjob_name":"project-manager","to_ping":"","pinged":"","wpjob_modified":"2023-01-23 03:23:35","wpjob_modified_gmt":"2023-01-23 03:23:35","wpjob_content_filtered":"","wpjob_parent":0,"guid":"http:\/\/connector.com\/?post_type=job_listing&p=145","menu_order":-1,"wpjob_type":"job_listing","wpjob_mime_type":"","comment_count":"0","filter":"raw","_filled":["0"],"_featured":["1"],"_tribe_ticket_capacity":["0"],"_tribe_ticket_version":["5.5.6"],"_edit_lock":["1674444219:1"],"_job_expires":["2023-02-21"],"_tracked_submitted":["1674409083"],"_edit_last":["1"],"_job_location":[""],"_application":["johnsmith@bexample.com"],"_company_name":["test"],"_company_website":[""],"_company_tagline":[""],"_company_twitter":[""],"_company_video":[""],"_remote_position":["1"],"_llms_reviews_enabled":[""],"_llms_display_reviews":[""],"_llms_num_reviews":["0"],"_llms_multiple_reviews_disabled":[""],"wp_user_id":1,"user_login":"john","display_name":"john","user_firstname":"john","user_lastname":"smith","user_email":"johnsmith@bexample.com","user_role":["administrator","subscriber","tutor_instructor"]}}', true ); |
| 3941 | return $context; |
| 3942 | } |
| 3943 | |
| 3944 | $post = $posts[0]; |
| 3945 | $post_content = WordPress::get_post_context( $post->ID ); |
| 3946 | $post_meta = WordPress::get_post_meta( $post->ID ); |
| 3947 | $job_data = array_merge( $post_content, $post_meta, WordPress::get_user_context( $post->post_author ) ); |
| 3948 | foreach ( $job_data as $key => $job ) { |
| 3949 | $newkey = str_replace( 'post', 'wpjob', $key ); |
| 3950 | unset( $job_data[ $key ] ); |
| 3951 | $job_data[ $newkey ] = $job; |
| 3952 | } |
| 3953 | $context['response_type'] = 'live'; |
| 3954 | $context['pluggable_data'] = $job_data; |
| 3955 | return $context; |
| 3956 | |
| 3957 | } |
| 3958 | |
| 3959 | /** |
| 3960 | * Get Amelia Appointment Category. |
| 3961 | * |
| 3962 | * @param array $data data. |
| 3963 | * |
| 3964 | * @return array |
| 3965 | */ |
| 3966 | public function search_amelia_category_list( $data ) { |
| 3967 | |
| 3968 | global $wpdb; |
| 3969 | |
| 3970 | $page = $data['page']; |
| 3971 | $limit = Utilities::get_search_page_limit(); |
| 3972 | $offset = $limit * ( $page - 1 ); |
| 3973 | |
| 3974 | $categories = $wpdb->get_results( |
| 3975 | $wpdb->prepare( |
| 3976 | "SELECT SQL_CALC_FOUND_ROWS id, name FROM {$wpdb->prefix}amelia_categories WHERE status = %s ORDER BY name ASC LIMIT %d OFFSET %d", |
| 3977 | [ 'visible', $limit, $offset ] |
| 3978 | ), |
| 3979 | OBJECT |
| 3980 | ); |
| 3981 | |
| 3982 | $categories_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 3983 | |
| 3984 | $options = []; |
| 3985 | if ( ! empty( $categories ) ) { |
| 3986 | foreach ( $categories as $category ) { |
| 3987 | $options[] = [ |
| 3988 | 'label' => $category->name, |
| 3989 | 'value' => $category->id, |
| 3990 | ]; |
| 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | return [ |
| 3995 | 'options' => $options, |
| 3996 | 'hasMore' => $categories_count > $limit && $categories_count > $offset, |
| 3997 | ]; |
| 3998 | |
| 3999 | } |
| 4000 | |
| 4001 | /** |
| 4002 | * Get Amelia Appointment Services. |
| 4003 | * |
| 4004 | * @param array $data data. |
| 4005 | * |
| 4006 | * @return array |
| 4007 | */ |
| 4008 | public function search_amelia_service_list( $data ) { |
| 4009 | |
| 4010 | global $wpdb; |
| 4011 | |
| 4012 | $page = $data['page']; |
| 4013 | $limit = Utilities::get_search_page_limit(); |
| 4014 | $offset = $limit * ( $page - 1 ); |
| 4015 | |
| 4016 | $services = $wpdb->get_results( |
| 4017 | $wpdb->prepare( |
| 4018 | "SELECT SQL_CALC_FOUND_ROWS id, name FROM {$wpdb->prefix}amelia_services |
| 4019 | WHERE categoryId = %d AND status = %s |
| 4020 | ORDER BY name ASC LIMIT %d OFFSET %d", |
| 4021 | [ $data['dynamic'], 'visible', $limit, $offset ] |
| 4022 | ), |
| 4023 | OBJECT |
| 4024 | ); |
| 4025 | |
| 4026 | $services_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 4027 | |
| 4028 | $options = []; |
| 4029 | if ( ! empty( $services ) ) { |
| 4030 | foreach ( $services as $category ) { |
| 4031 | $options[] = [ |
| 4032 | 'label' => $category->name, |
| 4033 | 'value' => $category->id, |
| 4034 | ]; |
| 4035 | } |
| 4036 | } |
| 4037 | |
| 4038 | return [ |
| 4039 | 'options' => $options, |
| 4040 | 'hasMore' => $services_count > $limit && $services_count > $offset, |
| 4041 | ]; |
| 4042 | |
| 4043 | } |
| 4044 | |
| 4045 | /** |
| 4046 | * Get Amelia Events. |
| 4047 | * |
| 4048 | * @param array $data data. |
| 4049 | * |
| 4050 | * @return array |
| 4051 | */ |
| 4052 | public function search_amelia_events_list( $data ) { |
| 4053 | |
| 4054 | global $wpdb; |
| 4055 | |
| 4056 | $page = $data['page']; |
| 4057 | $limit = Utilities::get_search_page_limit(); |
| 4058 | $offset = $limit * ( $page - 1 ); |
| 4059 | |
| 4060 | $events = $wpdb->get_results( |
| 4061 | $wpdb->prepare( |
| 4062 | "SELECT SQL_CALC_FOUND_ROWS id, name from {$wpdb->prefix}amelia_events WHERE status = %s ORDER BY name ASC LIMIT %d OFFSET %d", |
| 4063 | [ 'approved', $limit, $offset ] |
| 4064 | ), |
| 4065 | OBJECT |
| 4066 | ); |
| 4067 | |
| 4068 | $list_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 4069 | |
| 4070 | $options = []; |
| 4071 | if ( ! empty( $events ) ) { |
| 4072 | foreach ( $events as $event ) { |
| 4073 | $options[] = [ |
| 4074 | 'label' => $event->name, |
| 4075 | 'value' => $event->id, |
| 4076 | ]; |
| 4077 | } |
| 4078 | } |
| 4079 | |
| 4080 | return [ |
| 4081 | 'options' => $options, |
| 4082 | 'hasMore' => $list_count > $limit && $list_count > $offset, |
| 4083 | ]; |
| 4084 | |
| 4085 | } |
| 4086 | |
| 4087 | /** |
| 4088 | * Get last data for trigger. |
| 4089 | * |
| 4090 | * @param array $data data. |
| 4091 | * @return array |
| 4092 | */ |
| 4093 | public function search_amelia_appointment_booked_triggers_last_data( $data ) { |
| 4094 | global $wpdb; |
| 4095 | |
| 4096 | $context = []; |
| 4097 | |
| 4098 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 4099 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 4100 | |
| 4101 | if ( -1 === $appointment_service ) { |
| 4102 | // If service exists as per category selected. |
| 4103 | $service_exist = $wpdb->get_row( |
| 4104 | $wpdb->prepare( |
| 4105 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 4106 | [ $appointment_category ] |
| 4107 | ), |
| 4108 | ARRAY_A |
| 4109 | ); |
| 4110 | |
| 4111 | if ( empty( $service_exist ) ) { |
| 4112 | $result = []; |
| 4113 | } else { |
| 4114 | $result = $wpdb->get_row( |
| 4115 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments )', |
| 4116 | ARRAY_A |
| 4117 | ); |
| 4118 | } |
| 4119 | } else { |
| 4120 | $result = $wpdb->get_row( |
| 4121 | $wpdb->prepare( |
| 4122 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments ) AND appointments.serviceId = %d', |
| 4123 | [ $appointment_service ] |
| 4124 | ), |
| 4125 | ARRAY_A |
| 4126 | ); |
| 4127 | } |
| 4128 | |
| 4129 | if ( ! empty( $result ) ) { |
| 4130 | |
| 4131 | $payment_result = $wpdb->get_row( |
| 4132 | $wpdb->prepare( |
| 4133 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 4134 | [ $result['id'] ] |
| 4135 | ), |
| 4136 | ARRAY_A |
| 4137 | ); |
| 4138 | |
| 4139 | $customer_result = $wpdb->get_row( |
| 4140 | $wpdb->prepare( |
| 4141 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 4142 | [ $result['customerId'] ] |
| 4143 | ), |
| 4144 | ARRAY_A |
| 4145 | ); |
| 4146 | |
| 4147 | $service_result = $wpdb->get_row( |
| 4148 | $wpdb->prepare( |
| 4149 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 4150 | [ $result['serviceId'] ] |
| 4151 | ), |
| 4152 | ARRAY_A |
| 4153 | ); |
| 4154 | |
| 4155 | $category_result = $wpdb->get_row( |
| 4156 | $wpdb->prepare( |
| 4157 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 4158 | [ $service_result['categoryId'] ] |
| 4159 | ), |
| 4160 | ARRAY_A |
| 4161 | ); |
| 4162 | |
| 4163 | if ( $result['couponId'] ) { |
| 4164 | $coupon_result = $wpdb->get_row( |
| 4165 | $wpdb->prepare( |
| 4166 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 4167 | [ $result['couponId'] ] |
| 4168 | ), |
| 4169 | ARRAY_A |
| 4170 | ); |
| 4171 | } else { |
| 4172 | $coupon_result = []; |
| 4173 | } |
| 4174 | |
| 4175 | $context['pluggable_data'] = array_merge( $result, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 4176 | $context['response_type'] = 'live'; |
| 4177 | } else { |
| 4178 | |
| 4179 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id":"1","status":"visible","bookingStart":"2023-02-28 13:00:00","bookingEnd":"2023-02-28 14:00:00","notifyParticipants":"1","serviceId":"4","packageId":null,"providerId":"2","locationId":null,"internalNotes":"","googleCalendarEventId":null,"googleMeetUrl":null,"outlookCalendarEventId":null,"zoomMeeting":null,"lessonSpace":null,"parentId":null,"appointmentId":"1","customerId":"1","price":"15","persons":"1","couponId":null,"token":"02cf0988c6","customFields":null,"info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"1 (234) 789\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":"3600","created":"2023-02-08 11:16:03","actionsCompleted":"1","customerBookingId":"103","amount":"0","dateTime":"2023-02-28 13:00:00","gateway":"onSite","gatewayTitle":"","data":"","packageCustomerId":null,"entity":"appointment","wcOrderId":null,"type":"customer","externalId":"89","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"1 (234) 789","gender":null,"note":null,"description":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"zoomUserId":null,"countryPhoneIso":"us","translations":"{\"defaultLanguage\":\"en_US\"}","timeZone":null,"serviceName":"demo service","serviceDescription":"","categoryId":"2","categoryName":"New Category1"}}', true ); |
| 4180 | } |
| 4181 | |
| 4182 | return $context; |
| 4183 | } |
| 4184 | |
| 4185 | /** |
| 4186 | * Get last data for trigger. |
| 4187 | * |
| 4188 | * @param array $data data. |
| 4189 | * @return array |
| 4190 | */ |
| 4191 | public function search_amelia_new_event_attendee_triggers_last_data( $data ) { |
| 4192 | global $wpdb; |
| 4193 | |
| 4194 | $context = []; |
| 4195 | |
| 4196 | $event_selected = $data['filter']['amelia_events_list']['value']; |
| 4197 | |
| 4198 | if ( -1 === $event_selected ) { |
| 4199 | $result = $wpdb->get_row( |
| 4200 | 'SELECT * |
| 4201 | FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer |
| 4202 | INNER JOIN ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods as event_period |
| 4203 | ON customer.id = event_period.customerBookingId |
| 4204 | WHERE event_period.customerBookingId = ( Select max(customerBookingId) From ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods )', |
| 4205 | ARRAY_A |
| 4206 | ); |
| 4207 | } else { |
| 4208 | $result = $wpdb->get_row( |
| 4209 | $wpdb->prepare( |
| 4210 | 'SELECT * |
| 4211 | FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer |
| 4212 | INNER JOIN ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods as event_period |
| 4213 | ON customer.id = event_period.customerBookingId |
| 4214 | WHERE event_period.customerBookingId = ( Select max(customerBookingId) From ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods ) AND eventPeriodId = %d', |
| 4215 | [ $event_selected ] |
| 4216 | ), |
| 4217 | ARRAY_A |
| 4218 | ); |
| 4219 | } |
| 4220 | |
| 4221 | if ( ! empty( $result ) ) { |
| 4222 | |
| 4223 | $event = $wpdb->get_row( |
| 4224 | $wpdb->prepare( |
| 4225 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_events WHERE id = %d', |
| 4226 | [ $result['eventPeriodId'] ] |
| 4227 | ), |
| 4228 | ARRAY_A |
| 4229 | ); |
| 4230 | |
| 4231 | $customer_result = $wpdb->get_row( |
| 4232 | $wpdb->prepare( |
| 4233 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 4234 | [ $result['customerId'] ] |
| 4235 | ), |
| 4236 | ARRAY_A |
| 4237 | ); |
| 4238 | |
| 4239 | if ( $result['couponId'] ) { |
| 4240 | $coupon_result = $wpdb->get_row( |
| 4241 | $wpdb->prepare( |
| 4242 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 4243 | [ $result['couponId'] ] |
| 4244 | ), |
| 4245 | ARRAY_A |
| 4246 | ); |
| 4247 | } else { |
| 4248 | $coupon_result = []; |
| 4249 | } |
| 4250 | |
| 4251 | $context['pluggable_data'] = array_merge( $result, $event, $customer_result, $coupon_result ); |
| 4252 | $context['response_type'] = 'live'; |
| 4253 | } else { |
| 4254 | |
| 4255 | $context = json_decode( '{"response_type":"sample","pluggable_data":{""id":"1","appointmentId":null,"customerId":"1","status":"visible","price":"10","persons":"1","couponId":null,"token":"6485b07ce9","customFields":null,"info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"+213551223123\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":null,"created":"2023-02-02 06:35:18","actionsCompleted":"1","customerBookingId":"105","eventPeriodId":"5","parentId":null,"name":"Testing Event 5","bookingOpens":null,"bookingCloses":"2023-02-09 08:00:00","bookingOpensRec":"same","bookingClosesRec":"same","ticketRangeRec":"calculate","recurringCycle":null,"recurringOrder":null,"recurringInterval":null,"recurringMonthly":null,"monthlyDate":null,"monthlyOnRepeat":null,"monthlyOnDay":null,"recurringUntil":null,"maxCapacity":"12","maxCustomCapacity":null,"maxExtraPeople":null,"locationId":null,"customLocation":"test","description":null,"color":"#1788FB","show":"1","notifyParticipants":"1","settings":"{\"payments\":{\"onSite\":true,\"payPal\":{\"enabled\":false},\"stripe\":{\"enabled\":false},\"mollie\":{\"enabled\":false},\"razorpay\":{\"enabled\":false}},\"general\":{\"minimumTimeRequirementPriorToCanceling\":null,\"redirectUrlAfterAppointment\":null},\"zoom\":{\"enabled\":false},\"lessonSpace\":{\"enabled\":false}}","zoomUserId":null,"bringingAnyone":"1","bookMultipleTimes":"1","translations":"{\"defaultLanguage\":\"en_US\"}","depositPayment":"disabled","depositPerPerson":"1","fullPayment":"0","deposit":"0","customPricing":"0","organizerId":"2","closeAfterMin":null,"closeAfterMinBookings":"0","type":"customer","externalId":"91","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"+213551223123","gender":null,"note":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"countryPhoneIso":"dz","timeZone":null}}', true ); |
| 4256 | } |
| 4257 | |
| 4258 | return $context; |
| 4259 | } |
| 4260 | |
| 4261 | /** |
| 4262 | * Get last data for trigger. |
| 4263 | * |
| 4264 | * @param array $data data. |
| 4265 | * @return array |
| 4266 | */ |
| 4267 | public function search_amelia_appointment_rescheduled_triggers_last_data( $data ) { |
| 4268 | global $wpdb; |
| 4269 | |
| 4270 | $context = []; |
| 4271 | |
| 4272 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 4273 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 4274 | |
| 4275 | if ( -1 === $appointment_service ) { |
| 4276 | // If service exists as per category selected. |
| 4277 | $service_exist = $wpdb->get_row( |
| 4278 | $wpdb->prepare( |
| 4279 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 4280 | [ $appointment_category ] |
| 4281 | ), |
| 4282 | ARRAY_A |
| 4283 | ); |
| 4284 | |
| 4285 | if ( empty( $service_exist ) ) { |
| 4286 | $result = []; |
| 4287 | } else { |
| 4288 | $result = $wpdb->get_row( |
| 4289 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments )', |
| 4290 | ARRAY_A |
| 4291 | ); |
| 4292 | } |
| 4293 | } else { |
| 4294 | $result = $wpdb->get_row( |
| 4295 | $wpdb->prepare( |
| 4296 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE customer.appointmentId = ( SELECT max(id) FROM ' . $wpdb->prefix . 'amelia_appointments ) AND appointments.serviceId = %d', |
| 4297 | [ $appointment_service ] |
| 4298 | ), |
| 4299 | ARRAY_A |
| 4300 | ); |
| 4301 | } |
| 4302 | |
| 4303 | if ( ! empty( $result ) ) { |
| 4304 | |
| 4305 | $payment_result = $wpdb->get_row( |
| 4306 | $wpdb->prepare( |
| 4307 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 4308 | [ $result['id'] ] |
| 4309 | ), |
| 4310 | ARRAY_A |
| 4311 | ); |
| 4312 | |
| 4313 | $customer_result = $wpdb->get_row( |
| 4314 | $wpdb->prepare( |
| 4315 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 4316 | [ $result['customerId'] ] |
| 4317 | ), |
| 4318 | ARRAY_A |
| 4319 | ); |
| 4320 | |
| 4321 | $service_result = $wpdb->get_row( |
| 4322 | $wpdb->prepare( |
| 4323 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 4324 | [ $result['serviceId'] ] |
| 4325 | ), |
| 4326 | ARRAY_A |
| 4327 | ); |
| 4328 | |
| 4329 | $category_result = $wpdb->get_row( |
| 4330 | $wpdb->prepare( |
| 4331 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 4332 | [ $service_result['categoryId'] ] |
| 4333 | ), |
| 4334 | ARRAY_A |
| 4335 | ); |
| 4336 | |
| 4337 | if ( $result['couponId'] ) { |
| 4338 | $coupon_result = $wpdb->get_row( |
| 4339 | $wpdb->prepare( |
| 4340 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 4341 | [ $result['couponId'] ] |
| 4342 | ), |
| 4343 | ARRAY_A |
| 4344 | ); |
| 4345 | } else { |
| 4346 | $coupon_result = []; |
| 4347 | } |
| 4348 | |
| 4349 | $appointment_data['isRescheduled'] = '1'; |
| 4350 | $context['pluggable_data'] = array_merge( $result, $appointment_data, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 4351 | $context['response_type'] = 'live'; |
| 4352 | } else { |
| 4353 | |
| 4354 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id":"1","status":"visible","bookingStart":"2023-02-28 15:30:00","bookingEnd":"2023-02-28 16:30:00","notifyParticipants":"1","serviceId":"4","packageId":null,"providerId":"2","locationId":null,"internalNotes":"","googleCalendarEventId":null,"googleMeetUrl":null,"outlookCalendarEventId":null,"zoomMeeting":null,"lessonSpace":null,"parentId":null,"appointmentId":"54","customerId":"1","price":"15","persons":"1","couponId":null,"token":"02cf0988c6","customFields":"{}","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"1 (234) 789\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":"3600","created":"2023-02-08 11:16:03","actionsCompleted":"1","isRescheduled":"1","customerBookingId":"103","amount":"0","dateTime":"2023-02-28 15:30:00","gateway":"onSite","gatewayTitle":"","data":"","packageCustomerId":null,"entity":"appointment","wcOrderId":null,"type":"customer","externalId":"89","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"1 (234) 789","gender":null,"note":null,"description":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"zoomUserId":null,"countryPhoneIso":"us","translations":"{\"defaultLanguage\":\"en_US\"}","timeZone":null,"serviceName":"demo service","serviceDescription":"","categoryId":"2","categoryName":"New Category1"}}', true ); |
| 4355 | } |
| 4356 | |
| 4357 | return $context; |
| 4358 | } |
| 4359 | |
| 4360 | |
| 4361 | /** |
| 4362 | * Get last data for trigger. |
| 4363 | * |
| 4364 | * @param array $data data. |
| 4365 | * @return array |
| 4366 | */ |
| 4367 | public function search_amelia_appointment_cancelled_triggers_last_data( $data ) { |
| 4368 | global $wpdb; |
| 4369 | |
| 4370 | $context = []; |
| 4371 | |
| 4372 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 4373 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 4374 | |
| 4375 | if ( -1 === $appointment_service ) { |
| 4376 | // If service exists as per category selected. |
| 4377 | $service_exist = $wpdb->get_row( |
| 4378 | $wpdb->prepare( |
| 4379 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 4380 | [ $appointment_category ] |
| 4381 | ), |
| 4382 | ARRAY_A |
| 4383 | ); |
| 4384 | |
| 4385 | if ( empty( $service_exist ) ) { |
| 4386 | $result = []; |
| 4387 | } else { |
| 4388 | $result = $wpdb->get_row( |
| 4389 | $wpdb->prepare( |
| 4390 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE appointments.status = %s order by RAND() DESC LIMIT 1', |
| 4391 | [ 'canceled' ] |
| 4392 | ), |
| 4393 | ARRAY_A |
| 4394 | ); |
| 4395 | } |
| 4396 | } else { |
| 4397 | $result = $wpdb->get_row( |
| 4398 | $wpdb->prepare( |
| 4399 | 'SELECT appointments.*, customer.* FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer INNER JOIN ' . $wpdb->prefix . 'amelia_appointments as appointments ON customer.appointmentId=appointments.id WHERE appointments.status = %s AND appointments.serviceId = %d order by RAND() DESC LIMIT 1', |
| 4400 | [ 'canceled', $appointment_service ] |
| 4401 | ), |
| 4402 | ARRAY_A |
| 4403 | ); |
| 4404 | } |
| 4405 | |
| 4406 | if ( ! empty( $result ) ) { |
| 4407 | |
| 4408 | $payment_result = $wpdb->get_row( |
| 4409 | $wpdb->prepare( |
| 4410 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 4411 | [ $result['id'] ] |
| 4412 | ), |
| 4413 | ARRAY_A |
| 4414 | ); |
| 4415 | |
| 4416 | $customer_result = $wpdb->get_row( |
| 4417 | $wpdb->prepare( |
| 4418 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 4419 | [ $result['customerId'] ] |
| 4420 | ), |
| 4421 | ARRAY_A |
| 4422 | ); |
| 4423 | |
| 4424 | $service_result = $wpdb->get_row( |
| 4425 | $wpdb->prepare( |
| 4426 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 4427 | [ $result['serviceId'] ] |
| 4428 | ), |
| 4429 | ARRAY_A |
| 4430 | ); |
| 4431 | |
| 4432 | $category_result = $wpdb->get_row( |
| 4433 | $wpdb->prepare( |
| 4434 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 4435 | [ $service_result['categoryId'] ] |
| 4436 | ), |
| 4437 | ARRAY_A |
| 4438 | ); |
| 4439 | |
| 4440 | if ( $result['couponId'] ) { |
| 4441 | $coupon_result = $wpdb->get_row( |
| 4442 | $wpdb->prepare( |
| 4443 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 4444 | [ $result['couponId'] ] |
| 4445 | ), |
| 4446 | ARRAY_A |
| 4447 | ); |
| 4448 | } else { |
| 4449 | $coupon_result = []; |
| 4450 | } |
| 4451 | |
| 4452 | $context['pluggable_data'] = array_merge( $result, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 4453 | $context['response_type'] = 'live'; |
| 4454 | } else { |
| 4455 | |
| 4456 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id":"1","status":"visible","bookingStart":"2023-02-28 15:30:00","bookingEnd":"2023-02-28 16:30:00","notifyParticipants":"1","serviceId":"4","packageId":null,"providerId":"2","locationId":null,"internalNotes":"","googleCalendarEventId":null,"googleMeetUrl":null,"outlookCalendarEventId":null,"zoomMeeting":null,"lessonSpace":null,"parentId":null,"appointmentId":"54","customerId":"1","price":"15","persons":"1","couponId":null,"token":"02cf0988c6","customFields":"{}","info":"{\"firstName\":\"test\",\"lastName\":\"test\",\"phone\":\"1 (234) 789\",\"locale\":\"en_US\",\"timeZone\":\"Asia\\\/Kolkata\",\"urlParams\":null}","utcOffset":null,"aggregatedPrice":"1","packageCustomerServiceId":null,"duration":"3600","created":"2023-02-08 11:16:03","actionsCompleted":"1","customerBookingId":"103","amount":"0","dateTime":"2023-02-28 15:30:00","gateway":"onSite","gatewayTitle":"","data":"","packageCustomerId":null,"entity":"appointment","wcOrderId":null,"type":"customer","externalId":"89","firstName":"test","lastName":"test","email":"test@test.com","birthday":null,"phone":"1 (234) 789","gender":null,"note":null,"description":null,"pictureFullPath":null,"pictureThumbPath":null,"password":null,"usedTokens":null,"zoomUserId":null,"countryPhoneIso":"us","translations":"{\"defaultLanguage\":\"en_US\"}","timeZone":null,"serviceName":"demo service","serviceDescription":"","categoryId":"2","categoryName":"New Category1"}}', true ); |
| 4457 | } |
| 4458 | |
| 4459 | return $context; |
| 4460 | } |
| 4461 | |
| 4462 | /** |
| 4463 | * Get MailPoet Forms. |
| 4464 | * |
| 4465 | * @param array $data data. |
| 4466 | * |
| 4467 | * @return array |
| 4468 | */ |
| 4469 | public function search_mailpoet_forms( $data ) { |
| 4470 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 4471 | return; |
| 4472 | } |
| 4473 | |
| 4474 | global $wpdb; |
| 4475 | |
| 4476 | $page = $data['page']; |
| 4477 | $limit = Utilities::get_search_page_limit(); |
| 4478 | $offset = $limit * ( $page - 1 ); |
| 4479 | |
| 4480 | $forms = $wpdb->get_results( |
| 4481 | $wpdb->prepare( |
| 4482 | 'SELECT SQL_CALC_FOUND_ROWS * FROM ' . $wpdb->prefix . 'mailpoet_forms WHERE `deleted_at` IS NULL AND `status` = %s ORDER BY id LIMIT %d OFFSET %d', |
| 4483 | [ 'enabled', $limit, $offset ] |
| 4484 | ) |
| 4485 | ); |
| 4486 | |
| 4487 | $form_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 4488 | |
| 4489 | $options = []; |
| 4490 | |
| 4491 | if ( ! empty( $forms ) ) { |
| 4492 | if ( is_array( $forms ) ) { |
| 4493 | foreach ( $forms as $form ) { |
| 4494 | $options[] = [ |
| 4495 | 'label' => $form->name, |
| 4496 | 'value' => $form->id, |
| 4497 | ]; |
| 4498 | } |
| 4499 | } |
| 4500 | } |
| 4501 | |
| 4502 | return [ |
| 4503 | 'options' => $options, |
| 4504 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 4505 | ]; |
| 4506 | |
| 4507 | } |
| 4508 | |
| 4509 | /** |
| 4510 | * Get MailPoet List. |
| 4511 | * |
| 4512 | * @param array $data data. |
| 4513 | * |
| 4514 | * @return array |
| 4515 | */ |
| 4516 | public function search_mailpoet_list( $data ) { |
| 4517 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 4518 | return; |
| 4519 | } |
| 4520 | |
| 4521 | $mailpoet = \MailPoet\API\API::MP( 'v1' ); |
| 4522 | $lists = $mailpoet->getLists(); |
| 4523 | |
| 4524 | $options = []; |
| 4525 | |
| 4526 | if ( ! empty( $lists ) ) { |
| 4527 | if ( is_array( $lists ) ) { |
| 4528 | foreach ( $lists as $list ) { |
| 4529 | $options[] = [ |
| 4530 | 'label' => $list['name'], |
| 4531 | 'value' => $list['id'], |
| 4532 | ]; |
| 4533 | } |
| 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | return [ |
| 4538 | 'options' => $options, |
| 4539 | 'hasMore' => false, |
| 4540 | ]; |
| 4541 | } |
| 4542 | |
| 4543 | /** |
| 4544 | * Get MailPoet Subscriber Status. |
| 4545 | * |
| 4546 | * @param array $data data. |
| 4547 | * |
| 4548 | * @return array |
| 4549 | */ |
| 4550 | public function search_mailpoet_subscriber_status( $data ) { |
| 4551 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 4552 | return; |
| 4553 | } |
| 4554 | |
| 4555 | $subscriber_status = [ |
| 4556 | 'subscribed' => 'Subscribed', |
| 4557 | 'unconfirmed' => 'Unconfirmed', |
| 4558 | 'unsubscribed' => 'Unsubscribed', |
| 4559 | 'inactive' => 'Inactive', |
| 4560 | 'bounced' => 'Bounced', |
| 4561 | ]; |
| 4562 | |
| 4563 | $options = []; |
| 4564 | foreach ( $subscriber_status as $key => $status ) { |
| 4565 | $options[] = [ |
| 4566 | 'label' => $status, |
| 4567 | 'value' => $key, |
| 4568 | ]; |
| 4569 | } |
| 4570 | |
| 4571 | return [ |
| 4572 | 'options' => $options, |
| 4573 | 'hasMore' => false, |
| 4574 | ]; |
| 4575 | } |
| 4576 | |
| 4577 | /** |
| 4578 | * Get MailPoet Subscribers. |
| 4579 | * |
| 4580 | * @param array $data data. |
| 4581 | * |
| 4582 | * @return array |
| 4583 | */ |
| 4584 | public function search_mailpoet_subscribers( $data ) { |
| 4585 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 4586 | return; |
| 4587 | } |
| 4588 | |
| 4589 | global $wpdb; |
| 4590 | |
| 4591 | $page = $data['page']; |
| 4592 | $limit = Utilities::get_search_page_limit(); |
| 4593 | $offset = $limit * ( $page - 1 ); |
| 4594 | |
| 4595 | $subscribers = $wpdb->get_results( |
| 4596 | $wpdb->prepare( |
| 4597 | 'SELECT SQL_CALC_FOUND_ROWS id,email FROM ' . $wpdb->prefix . 'mailpoet_subscribers ORDER BY id DESC LIMIT %d OFFSET %d', |
| 4598 | [ $limit, $offset ] |
| 4599 | ) |
| 4600 | ); |
| 4601 | |
| 4602 | $subscribers_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 4603 | |
| 4604 | $options = []; |
| 4605 | |
| 4606 | if ( ! empty( $subscribers ) ) { |
| 4607 | if ( is_array( $subscribers ) ) { |
| 4608 | foreach ( $subscribers as $subscriber ) { |
| 4609 | $options[] = [ |
| 4610 | 'label' => $subscriber->email, |
| 4611 | 'value' => $subscriber->id, |
| 4612 | ]; |
| 4613 | } |
| 4614 | } |
| 4615 | } |
| 4616 | |
| 4617 | return [ |
| 4618 | 'options' => $options, |
| 4619 | 'hasMore' => $subscribers_count > $limit && $subscribers_count > $offset, |
| 4620 | ]; |
| 4621 | } |
| 4622 | |
| 4623 | /** |
| 4624 | * Get ConvertPro Forms. |
| 4625 | * |
| 4626 | * @param array $data data. |
| 4627 | * |
| 4628 | * @return array |
| 4629 | */ |
| 4630 | public function search_convertpro_form_list( $data ) { |
| 4631 | if ( ! class_exists( '\Cp_V2_Loader' ) ) { |
| 4632 | return; |
| 4633 | } |
| 4634 | |
| 4635 | $cp_popups_inst = CP_V2_Popups::get_instance(); |
| 4636 | $popups = $cp_popups_inst->get_all(); |
| 4637 | |
| 4638 | $form_count = count( $popups ); |
| 4639 | |
| 4640 | $page = $data['page']; |
| 4641 | $limit = Utilities::get_search_page_limit(); |
| 4642 | $offset = $limit * ( $page - 1 ); |
| 4643 | |
| 4644 | $options = []; |
| 4645 | |
| 4646 | if ( ! empty( $popups ) ) { |
| 4647 | if ( is_array( $popups ) ) { |
| 4648 | foreach ( $popups as $form ) { |
| 4649 | $options[] = [ |
| 4650 | 'label' => $form->post_title, |
| 4651 | 'value' => $form->ID, |
| 4652 | ]; |
| 4653 | } |
| 4654 | } |
| 4655 | } |
| 4656 | |
| 4657 | return [ |
| 4658 | 'options' => $options, |
| 4659 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 4660 | ]; |
| 4661 | |
| 4662 | } |
| 4663 | |
| 4664 | } |
| 4665 | |
| 4666 | GlobalSearchController::get_instance(); |
| 4667 |