AuthController.php
2 years ago
AutomationController.php
3 years ago
EventController.php
3 years ago
EventHelperController.php
3 years ago
GlobalSearchController.php
2 years ago
IntegrationsController.php
3 years ago
OptionController.php
3 years ago
RestController.php
3 years ago
RoutesController.php
3 years ago
SettingsController.php
3 years ago
GlobalSearchController.php
7937 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 memberpress\courses\lib as lib; |
| 21 | use memberpress\courses\models as models; |
| 22 | use FluentCrm\Framework\Support\Arr; |
| 23 | use GFCommon; |
| 24 | use GFFormsModel; |
| 25 | use Give_Payment; |
| 26 | use MeprBaseRealGateway; |
| 27 | use MeprOptions; |
| 28 | use PrestoPlayer\Models\Video; |
| 29 | use RGFormsModel; |
| 30 | use SureTriggers\Integrations\AffiliateWP\AffiliateWP; |
| 31 | use SureTriggers\Integrations\EDD\EDD; |
| 32 | use SureTriggers\Integrations\FunnelKitAutomations\FunnelKitAutomations; |
| 33 | use SureTriggers\Integrations\JetpackCRM\JetpackCRM; |
| 34 | use SureTriggers\Integrations\LearnDash\LearnDash; |
| 35 | use SureTriggers\Integrations\LifterLMS\LifterLMS; |
| 36 | use SureTriggers\Integrations\MemberPress\MemberPress; |
| 37 | use SureTriggers\Integrations\MemberPressCourse\MemberPressCourse; |
| 38 | use SureTriggers\Integrations\PeepSo\PeepSo; |
| 39 | use SureTriggers\Integrations\RestrictContent\RestrictContent; |
| 40 | use SureTriggers\Integrations\TheEventCalendar\TheEventCalendar; |
| 41 | use SureTriggers\Integrations\WishlistMember\WishlistMember; |
| 42 | use SureTriggers\Integrations\WooCommerce\WooCommerce; |
| 43 | use SureTriggers\Integrations\WordPress\WordPress; |
| 44 | use SureTriggers\Models\Utilities; |
| 45 | use SureTriggers\Traits\SingletonLoader; |
| 46 | use Tribe__Tickets__Tickets_Handler; |
| 47 | use WC_Subscription; |
| 48 | use WC_Subscriptions_Product; |
| 49 | use WP_Query; |
| 50 | use WP_Comment_Query; |
| 51 | use WP_REST_Request; |
| 52 | use WP_REST_Response; |
| 53 | use WPForms_Form_Handler; |
| 54 | use CP_V2_Popups; |
| 55 | use Project_Huddle; |
| 56 | use FrmForm; |
| 57 | use Forminator_API; |
| 58 | use SureTriggers\Integrations\LearnPress\LearnPress; |
| 59 | |
| 60 | /** |
| 61 | * GlobalSearchController- Add ajax related functions here. |
| 62 | * |
| 63 | * @category GlobalSearchController |
| 64 | * @package SureTriggers |
| 65 | * @author BSF <username@example.com> |
| 66 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 67 | * @link https://www.brainstormforce.com/ |
| 68 | * @since 1.0.0 |
| 69 | * |
| 70 | * @psalm-suppress UndefinedTrait |
| 71 | */ |
| 72 | class GlobalSearchController { |
| 73 | |
| 74 | use SingletonLoader; |
| 75 | |
| 76 | /** |
| 77 | * Search post by post type. |
| 78 | * |
| 79 | * @param array $data Search Params. |
| 80 | * |
| 81 | * @since 1.0.0 |
| 82 | * |
| 83 | * @return array |
| 84 | */ |
| 85 | public function search_post( $data ) { |
| 86 | $result = []; |
| 87 | $posts = Utilities::find_posts_by_title( $data ); |
| 88 | |
| 89 | foreach ( $posts['results'] as $post ) { |
| 90 | $result[] = [ |
| 91 | 'label' => $post['post_title'], |
| 92 | 'value' => $post['ID'], |
| 93 | ]; |
| 94 | } |
| 95 | |
| 96 | return [ |
| 97 | 'options' => $result, |
| 98 | 'hasMore' => $posts['has_more'], |
| 99 | ]; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Search Course. |
| 104 | * |
| 105 | * @param array $data quesry params. |
| 106 | * |
| 107 | * @return array |
| 108 | * @since 1.0.0 |
| 109 | */ |
| 110 | public function search_ld_course( $data ) { |
| 111 | $courses = get_posts( |
| 112 | [ |
| 113 | |
| 114 | 'post_type' => 'product', |
| 115 | 'meta_key' => '_related_course', |
| 116 | 'post_status' => 'publish', |
| 117 | ] |
| 118 | ); |
| 119 | $options = []; |
| 120 | foreach ( $courses as $course ) { |
| 121 | $options[] = [ |
| 122 | 'label' => $course->post_title, |
| 123 | 'value' => $course->ID, |
| 124 | ]; |
| 125 | } |
| 126 | |
| 127 | return [ |
| 128 | 'options' => $options, |
| 129 | 'hasMore' => false, |
| 130 | ]; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Search achievement by post type. |
| 135 | * |
| 136 | * @param array $data Search Params. |
| 137 | * |
| 138 | * @since 1.0.0 |
| 139 | * |
| 140 | * @return array |
| 141 | */ |
| 142 | public function search_achievements( $data ) { |
| 143 | $post = get_post( $data['dynamic'] ); |
| 144 | $slug = $post->post_name; |
| 145 | |
| 146 | $achievements = get_posts( |
| 147 | [ |
| 148 | 'post_type' => $slug, |
| 149 | 'post_status' => 'publish', |
| 150 | ] |
| 151 | ); |
| 152 | $options = []; |
| 153 | foreach ( $achievements as $achievement ) { |
| 154 | $options[] = [ |
| 155 | 'label' => $achievement->post_title, |
| 156 | 'value' => (string) $achievement->ID, |
| 157 | ]; |
| 158 | } |
| 159 | |
| 160 | return [ |
| 161 | 'options' => $options, |
| 162 | 'hasMore' => false, |
| 163 | ]; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Search Course. |
| 168 | * |
| 169 | * @param array $data quesry params. |
| 170 | * |
| 171 | * @return array |
| 172 | * @since 1.0.0 |
| 173 | */ |
| 174 | public function search_tutor_course( $data ) { |
| 175 | $courses = get_posts( |
| 176 | [ |
| 177 | 'post_type' => tutor()->course_post_type, |
| 178 | 'post_status' => 'publish', |
| 179 | 'numberposts' => '-1', |
| 180 | ] |
| 181 | ); |
| 182 | $options = []; |
| 183 | foreach ( $courses as $course ) { |
| 184 | $options[] = [ |
| 185 | 'label' => $course->post_title, |
| 186 | 'value' => $course->ID, |
| 187 | ]; |
| 188 | } |
| 189 | |
| 190 | return [ |
| 191 | 'options' => $options, |
| 192 | 'hasMore' => false, |
| 193 | ]; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Search Products. |
| 198 | * |
| 199 | * @param array $data quesry params. |
| 200 | * |
| 201 | * @return array |
| 202 | * @since 1.0.0 |
| 203 | */ |
| 204 | public function search_product( $data ) { |
| 205 | $result = []; |
| 206 | $posts = Utilities::find_posts_by_title( $data ); |
| 207 | |
| 208 | foreach ( $posts['results'] as $post ) { |
| 209 | $result[] = [ |
| 210 | 'label' => $post['post_title'], |
| 211 | 'value' => $post['post_title'], |
| 212 | ]; |
| 213 | } |
| 214 | |
| 215 | return [ |
| 216 | 'options' => $result, |
| 217 | 'hasMore' => $posts['has_more'], |
| 218 | ]; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Search Product Categories. |
| 223 | * |
| 224 | * @param array $data Search Params. |
| 225 | * |
| 226 | * @since 1.0.0 |
| 227 | */ |
| 228 | public function search_product_category( $data ) { |
| 229 | if ( ! empty( $data['dynamic'] ) ) { |
| 230 | $taxonomy = $data['dynamic']; |
| 231 | } else { |
| 232 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 233 | } |
| 234 | |
| 235 | $term = $data['term']; |
| 236 | $result = []; |
| 237 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 238 | foreach ( $terms['result'] as $tax_term ) { |
| 239 | $result[] = [ |
| 240 | 'label' => $tax_term->name, |
| 241 | 'value' => $tax_term->name, |
| 242 | ]; |
| 243 | } |
| 244 | |
| 245 | return [ |
| 246 | 'options' => $result, |
| 247 | 'hasMore' => $terms['has_more'], |
| 248 | ]; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Search Product Tags. |
| 253 | * |
| 254 | * @param array $data Search Params. |
| 255 | * |
| 256 | * @since 1.0.0 |
| 257 | */ |
| 258 | public function search_product_tags( $data ) { |
| 259 | if ( ! empty( $data['dynamic'] ) ) { |
| 260 | $taxonomy = $data['dynamic']; |
| 261 | } else { |
| 262 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 263 | } |
| 264 | |
| 265 | $term = $data['term']; |
| 266 | $result = []; |
| 267 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 268 | |
| 269 | foreach ( $terms['result'] as $tax_term ) { |
| 270 | $result[] = [ |
| 271 | 'label' => $tax_term->name, |
| 272 | 'value' => $tax_term->name, |
| 273 | ]; |
| 274 | } |
| 275 | |
| 276 | return [ |
| 277 | 'options' => $result, |
| 278 | 'hasMore' => $terms['has_more'], |
| 279 | ]; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Global ajax search. |
| 284 | * Here you need to add the field action name to work. |
| 285 | * |
| 286 | * @param WP_REST_Request $request Request data. |
| 287 | * |
| 288 | * @return WP_REST_Response |
| 289 | * @since 1.0.0 |
| 290 | */ |
| 291 | public function global_search( $request ) { |
| 292 | $post_type = $request->get_param( 'post_type' ); |
| 293 | $dynamic = $request->get_param( 'dynamic' ); |
| 294 | $search_term = $request->get_param( 'term' ); |
| 295 | $identifier = $request->get_param( 'field_identifier' ); |
| 296 | $page = max( 1, $request->get_param( 'page' ) ); |
| 297 | $taxonomy = $request->get_param( 'taxonomy' ) ? $request->get_param( 'taxonomy' ) : []; |
| 298 | |
| 299 | $filter = $request->get_param( 'filter' ) ? json_decode( stripslashes( $request->get_param( 'filter' ) ), true ) : []; |
| 300 | |
| 301 | $data = [ |
| 302 | 'dynamic' => $dynamic, |
| 303 | 'search_term' => $search_term, |
| 304 | 'page' => $page, |
| 305 | 'taxonomy' => $taxonomy, |
| 306 | 'filter' => $filter, |
| 307 | 'post_type' => $post_type, |
| 308 | ]; |
| 309 | $response = [ |
| 310 | 'hasMore' => false, |
| 311 | 'options' => [], |
| 312 | ]; |
| 313 | |
| 314 | $method_name = 'search_' . $identifier; |
| 315 | |
| 316 | if ( method_exists( $this, $method_name ) ) { |
| 317 | $response = $this->{$method_name}( $data ); |
| 318 | } else { |
| 319 | return RestController::error_message( 'Invalid field Identifier param.' ); |
| 320 | } |
| 321 | |
| 322 | return RestController::success_message( $response ); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Search Taxonomy Terms. |
| 327 | * |
| 328 | * @param array $data Search Params. |
| 329 | * |
| 330 | * @since 1.0.0 |
| 331 | * |
| 332 | * @return array |
| 333 | */ |
| 334 | public function search_term( $data ) { |
| 335 | if ( ! empty( $data['dynamic'] ) ) { |
| 336 | $taxonomy = $data['dynamic']; |
| 337 | } else { |
| 338 | $taxonomy = isset( $data['taxonomy'] ) ? $data['taxonomy'] : ''; |
| 339 | } |
| 340 | |
| 341 | $term = $data['term']; |
| 342 | $result = []; |
| 343 | $terms = Utilities::get_terms( $term, $data['page'], $taxonomy ); |
| 344 | foreach ( $terms['result'] as $tax_term ) { |
| 345 | $result[] = [ |
| 346 | 'label' => $tax_term->name, |
| 347 | 'value' => $tax_term->term_id, |
| 348 | ]; |
| 349 | } |
| 350 | |
| 351 | return [ |
| 352 | 'options' => $result, |
| 353 | 'hasMore' => $terms['has_more'], |
| 354 | ]; |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Search users. |
| 359 | * |
| 360 | * @param array $data Search Params. |
| 361 | * |
| 362 | * @since 1.0.0 |
| 363 | * |
| 364 | * @return array |
| 365 | */ |
| 366 | public function search_user( $data ) { |
| 367 | $result = []; |
| 368 | $page = $data['page']; |
| 369 | $users = Utilities::get_users( $data, $page ); |
| 370 | |
| 371 | if ( is_array( $users['results'] ) ) { |
| 372 | foreach ( $users['results'] as $user ) { |
| 373 | $result[] = [ |
| 374 | 'label' => $user->user_login, |
| 375 | 'value' => $user->ID, |
| 376 | ]; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | return [ |
| 381 | 'options' => $result, |
| 382 | 'hasMore' => $users['has_more'], |
| 383 | ]; |
| 384 | |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Search WPForm fields. |
| 389 | * |
| 390 | * @param array $data Search Params. |
| 391 | * |
| 392 | * @since 1.0.0 |
| 393 | * |
| 394 | * @return array |
| 395 | */ |
| 396 | public function search_pluggable_wpform_fields( $data ) { |
| 397 | $result = []; |
| 398 | $page = $data['page']; |
| 399 | $form_id = absint( $data['dynamic'] ); |
| 400 | $wpform_fields = Utilities::get_wpform_fields( $data['search_term'], $page, $form_id ); |
| 401 | |
| 402 | if ( is_array( $wpform_fields['results'] ) ) { |
| 403 | foreach ( $wpform_fields['results'] as $field ) { |
| 404 | $result[] = [ |
| 405 | 'label' => $field['label'], |
| 406 | 'value' => '{' . $field['id'] . '}', |
| 407 | ]; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | return [ |
| 412 | 'options' => $result, |
| 413 | 'hasMore' => $wpform_fields['has_more'], |
| 414 | ]; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Prepare variable products. |
| 419 | * |
| 420 | * @param array $data data. |
| 421 | * |
| 422 | * @return array |
| 423 | */ |
| 424 | public function search_variable_products( $data ) { |
| 425 | $products = Utilities::get_variable_products( $data['search_term'], $data['page'] ); |
| 426 | $options = []; |
| 427 | |
| 428 | foreach ( $products['result'] as $product ) { |
| 429 | $options[] = [ |
| 430 | 'label' => $product->get_title(), |
| 431 | 'value' => (string) $product->get_id(), |
| 432 | ]; |
| 433 | } |
| 434 | |
| 435 | return [ |
| 436 | 'options' => $options, |
| 437 | 'hasMore' => $products['has_more'], |
| 438 | ]; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Prepare variable products. |
| 443 | * |
| 444 | * @param array $data data. |
| 445 | * |
| 446 | * @return array |
| 447 | */ |
| 448 | public function search_product_variations( $data ) { |
| 449 | $variations = Utilities::get_product_variations( $data['dynamic'] ); |
| 450 | $options = []; |
| 451 | |
| 452 | foreach ( $variations['result'] as $product ) { |
| 453 | $options[] = [ |
| 454 | 'label' => ! empty( $product->post_excerpt ) ? $product->post_excerpt : $product->post_title, |
| 455 | 'value' => (string) $product->ID, |
| 456 | ]; |
| 457 | } |
| 458 | |
| 459 | return [ |
| 460 | 'options' => $options, |
| 461 | 'hasMore' => $variations['has_more'], |
| 462 | ]; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Search WooCommerce Subscriptions. |
| 467 | * |
| 468 | * @param array $data Search Params. |
| 469 | * |
| 470 | * @since 1.0.0 |
| 471 | * |
| 472 | * @return array |
| 473 | */ |
| 474 | public function search_subscription_variation( $data ) { |
| 475 | $subscription_products = Utilities::get_subscription_variation( $data['search_term'], $data['page'] ); |
| 476 | $result = []; |
| 477 | |
| 478 | if ( ! function_exists( 'wc_get_products' ) ) { |
| 479 | return $result; |
| 480 | } |
| 481 | |
| 482 | foreach ( $subscription_products['result'] as $post ) { |
| 483 | if ( $data['search_term'] ) { |
| 484 | if ( false !== stripos( $post->get_title(), $data['search_term'] ) ) { |
| 485 | $result[] = [ |
| 486 | 'label' => $post->get_title(), |
| 487 | 'value' => (string) $post->get_id(), |
| 488 | ]; |
| 489 | } |
| 490 | } else { |
| 491 | $result[] = [ |
| 492 | 'label' => $post->get_title(), |
| 493 | 'value' => (string) $post->get_id(), |
| 494 | ]; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | return [ |
| 499 | 'options' => $result, |
| 500 | 'hasMore' => $subscription_products['has_more'], |
| 501 | ]; |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Prepare WooCommerce Payment Methods. |
| 506 | * |
| 507 | * @param array $data Search Params. |
| 508 | * @return array[] |
| 509 | */ |
| 510 | public function search_woo_payment_methods( $data ) { |
| 511 | $payment_methods = WC()->payment_gateways->get_available_payment_gateways(); |
| 512 | $options = []; |
| 513 | |
| 514 | if ( ! empty( $payment_methods ) ) { |
| 515 | foreach ( $payment_methods as $payment ) { |
| 516 | $options[] = [ |
| 517 | 'label' => $payment->title, |
| 518 | 'value' => $payment->id, |
| 519 | ]; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | return [ |
| 524 | 'options' => $options, |
| 525 | 'hasMore' => false, |
| 526 | ]; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Prepare WooCommerce Order Status List. |
| 531 | * |
| 532 | * @param array $data Search Params. |
| 533 | * @return array[] |
| 534 | */ |
| 535 | public function search_woo_order_status_list( $data ) { |
| 536 | $order_status = wc_get_order_statuses(); |
| 537 | $options = []; |
| 538 | |
| 539 | if ( ! empty( $order_status ) ) { |
| 540 | foreach ( $order_status as $key => $status ) { |
| 541 | $options[] = [ |
| 542 | 'label' => $status, |
| 543 | 'value' => $key, |
| 544 | ]; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | return [ |
| 549 | 'options' => $options, |
| 550 | 'hasMore' => false, |
| 551 | ]; |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * Prepare WooCommerce Country List. |
| 556 | * |
| 557 | * @param array $data Search Params. |
| 558 | * @return array[] |
| 559 | */ |
| 560 | public function search_woo_country_list( $data ) { |
| 561 | $countries = WC()->countries->get_countries(); |
| 562 | $options = []; |
| 563 | |
| 564 | if ( ! empty( $countries ) ) { |
| 565 | foreach ( $countries as $key => $country ) { |
| 566 | $options[] = [ |
| 567 | 'label' => $country, |
| 568 | 'value' => $key, |
| 569 | ]; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | return [ |
| 574 | 'options' => $options, |
| 575 | 'hasMore' => false, |
| 576 | ]; |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Prepare WooCommerce Country States List. |
| 581 | * |
| 582 | * @param array $data Search Params. |
| 583 | * @return array[] |
| 584 | */ |
| 585 | public function search_woo_country_state_list( $data ) { |
| 586 | if ( ! empty( $data['dynamic']['shipping_country'] ) ) { |
| 587 | $cc = $data['dynamic']['shipping_country']; |
| 588 | } else { |
| 589 | $cc = $data['dynamic']; |
| 590 | } |
| 591 | |
| 592 | $states = WC()->countries->get_states( $cc ); |
| 593 | |
| 594 | $options = []; |
| 595 | if ( ! empty( $states ) ) { |
| 596 | foreach ( $states as $key => $state ) { |
| 597 | $options[] = [ |
| 598 | 'label' => $state, |
| 599 | 'value' => $key, |
| 600 | ]; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | return [ |
| 605 | 'options' => $options, |
| 606 | 'hasMore' => false, |
| 607 | ]; |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Get Memberpress gatways (payment methods) for subscription. |
| 612 | * |
| 613 | * @param array $data QueryParams. |
| 614 | * |
| 615 | * @return array |
| 616 | * @since 1.0.0 |
| 617 | */ |
| 618 | public function search_memberpress_gayways( $data ) { |
| 619 | $mp_options = MeprOptions::fetch(); |
| 620 | |
| 621 | $pms = array_keys( $mp_options->integrations ); |
| 622 | $gateways = []; |
| 623 | |
| 624 | foreach ( $pms as $pm_id ) { |
| 625 | $obj = $mp_options->payment_method( $pm_id ); |
| 626 | if ( $obj instanceof MeprBaseRealGateway ) { |
| 627 | $gateways[] = [ |
| 628 | 'label' => sprintf( '%1$s (%2$s)', $obj->label, $obj->name ), |
| 629 | 'value' => $obj->id, |
| 630 | ]; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | return [ |
| 635 | 'options' => $gateways, |
| 636 | 'hasMore' => false, |
| 637 | ]; |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Prepare roles. |
| 642 | * |
| 643 | * @param array $data data. |
| 644 | * |
| 645 | * @return array |
| 646 | */ |
| 647 | public function search_roles( $data ) { |
| 648 | if ( function_exists( 'get_editable_roles' ) ) { |
| 649 | $roles = get_editable_roles(); |
| 650 | } else { |
| 651 | $roles = wp_roles()->roles; |
| 652 | $roles = apply_filters( 'editable_roles', $roles ); |
| 653 | } |
| 654 | |
| 655 | $options = []; |
| 656 | foreach ( $roles as $role => $details ) { |
| 657 | |
| 658 | $options[] = [ |
| 659 | 'label' => $details['name'], |
| 660 | 'value' => $role, |
| 661 | ]; |
| 662 | |
| 663 | } |
| 664 | |
| 665 | return [ |
| 666 | 'options' => $options, |
| 667 | 'hasMore' => false, |
| 668 | ]; |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * Fetch operators. |
| 673 | * |
| 674 | * @return array |
| 675 | */ |
| 676 | public function search_condition_operators() { |
| 677 | return [ |
| 678 | 'options' => EventHelperController::get_instance()->prepare_operators(), |
| 679 | 'hasMore' => false, |
| 680 | ]; |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Prepare post types. |
| 685 | * |
| 686 | * @param array $data data. |
| 687 | * |
| 688 | * @return array |
| 689 | */ |
| 690 | public function search_post_types( $data ) { |
| 691 | $post_types = get_post_types( [ 'public' => true ], 'object' ); |
| 692 | $post_types = apply_filters( 'suretriggers_post_types', $post_types ); |
| 693 | if ( isset( $post_types['attachment'] ) ) { |
| 694 | unset( $post_types['attachment'] ); |
| 695 | } |
| 696 | |
| 697 | $options = []; |
| 698 | foreach ( $post_types as $post_type => $details ) { |
| 699 | $options[] = [ |
| 700 | 'label' => $details->label, |
| 701 | 'value' => $post_type, |
| 702 | ]; |
| 703 | } |
| 704 | |
| 705 | return [ |
| 706 | 'options' => $options, |
| 707 | 'hasMore' => false, |
| 708 | ]; |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Get post statuses. |
| 713 | * |
| 714 | * @param array $data data. |
| 715 | * |
| 716 | * @return array |
| 717 | */ |
| 718 | public function search_post_statuses( $data ) { |
| 719 | $post_statuses = get_post_stati( [], 'objects' ); |
| 720 | $post_statuses = apply_filters( 'suretriggers_post_types', $post_statuses ); |
| 721 | $options = []; |
| 722 | |
| 723 | foreach ( $post_statuses as $post_status => $details ) { |
| 724 | if ( 'woocommerce' === $details->label_count['domain'] ) { |
| 725 | $options[] = [ |
| 726 | 'label' => 'WooCommerce - ' . $details->label, |
| 727 | 'value' => $post_status, |
| 728 | ]; |
| 729 | } else { |
| 730 | $options[] = [ |
| 731 | 'label' => $details->label, |
| 732 | 'value' => $post_status, |
| 733 | ]; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | return [ |
| 738 | 'options' => $options, |
| 739 | 'hasMore' => false, |
| 740 | ]; |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Get Taxonomies. |
| 745 | * |
| 746 | * @param array $data data. |
| 747 | * |
| 748 | * @return array |
| 749 | */ |
| 750 | public function search_taxonomy_list( $data ) { |
| 751 | $taxonomies = get_taxonomies( [ 'public' => true ], 'objects' ); |
| 752 | $options = []; |
| 753 | $options[0] = [ |
| 754 | 'label' => 'Any Taxonomy', |
| 755 | 'value' => -1, |
| 756 | ]; |
| 757 | |
| 758 | foreach ( $taxonomies as $taxonomy => $taxonomy_obj ) { |
| 759 | $options[] = [ |
| 760 | 'label' => $taxonomy_obj->label, |
| 761 | 'value' => $taxonomy_obj->name, |
| 762 | ]; |
| 763 | } |
| 764 | |
| 765 | return [ |
| 766 | 'options' => $options, |
| 767 | 'hasMore' => false, |
| 768 | ]; |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * Get WPForms. |
| 773 | * |
| 774 | * @param array $data data. |
| 775 | * |
| 776 | * @return array |
| 777 | */ |
| 778 | public function search_wp_forms( $data ) { |
| 779 | if ( ! class_exists( 'WPForms_Form_Handler' ) ) { |
| 780 | return; |
| 781 | } |
| 782 | |
| 783 | $wpforms = new WPForms_Form_Handler(); |
| 784 | $forms = $wpforms->get( '', [ 'orderby' => 'title' ] ); |
| 785 | $options = []; |
| 786 | |
| 787 | if ( ! empty( $forms ) ) { |
| 788 | foreach ( $forms as $form ) { |
| 789 | $options[] = [ |
| 790 | 'label' => $form->post_title, |
| 791 | 'value' => $form->ID, |
| 792 | ]; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | return [ |
| 797 | 'options' => $options, |
| 798 | 'hasMore' => false, |
| 799 | ]; |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * Get Gravity Forms. |
| 804 | * |
| 805 | * @param array $data data. |
| 806 | * |
| 807 | * @return array |
| 808 | */ |
| 809 | public function search_gravity_forms( $data ) { |
| 810 | if ( ! class_exists( 'GFFormsModel' ) ) { |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | $forms = GFFormsModel::get_forms(); |
| 815 | $options = []; |
| 816 | |
| 817 | if ( ! empty( $forms ) ) { |
| 818 | foreach ( $forms as $form ) { |
| 819 | $options[] = [ |
| 820 | 'label' => $form->title, |
| 821 | 'value' => $form->id, |
| 822 | ]; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | return [ |
| 827 | 'options' => $options, |
| 828 | 'hasMore' => false, |
| 829 | ]; |
| 830 | } |
| 831 | |
| 832 | /** |
| 833 | * Get tag & contact details. |
| 834 | * |
| 835 | * @param array $data data. |
| 836 | * |
| 837 | * @return array |
| 838 | */ |
| 839 | public function search_pluggables_fluentcrm_contact_added_to_tags( $data ) { |
| 840 | $context = []; |
| 841 | $pluggable_data = []; |
| 842 | $tag_id = $data['filter']; |
| 843 | |
| 844 | if ( $tag_id > 0 ) { |
| 845 | $tags = Tag::where( 'id', $tag_id )->first(); |
| 846 | } else { |
| 847 | $tags = Tag::orderBy( 'id', 'DESC' )->first(); |
| 848 | } |
| 849 | $contact = Subscriber::orderBy( 'id', 'DESC' )->first(); |
| 850 | if ( $contact ) { |
| 851 | $pluggable_data['contact'] = $contact; |
| 852 | $context['tag_id'] = $tag_id; |
| 853 | $pluggable_data['tag'] = $tags; |
| 854 | $context['response_type'] = 'live'; |
| 855 | } else { |
| 856 | $pluggable_data['conatct']['full_name'] = 'Test User'; |
| 857 | $pluggable_data['conatct']['first_name'] = 'Test'; |
| 858 | $pluggable_data['conatct']['last_name'] = 'User'; |
| 859 | $pluggable_data['conatct']['company_id'] = 112; |
| 860 | $pluggable_data['conatct']['email'] = 'testuser@gmail.com'; |
| 861 | $pluggable_data['conatct']['address_line_1'] = '33, Vincent Road'; |
| 862 | $pluggable_data['conatct']['address_line_2'] = 'Chicago Street'; |
| 863 | $pluggable_data['conatct']['postal_code'] = '212342'; |
| 864 | $pluggable_data['conatct']['city'] = 'New York City'; |
| 865 | $pluggable_data['conatct']['state'] = 'New York'; |
| 866 | $pluggable_data['conatct']['country'] = 'USA'; |
| 867 | $pluggable_data['conatct']['phone'] = '9992191911'; |
| 868 | $pluggable_data['conatct']['status'] = 'subscribed'; |
| 869 | $pluggable_data['conatct']['contact_type'] = 'lead'; |
| 870 | $pluggable_data['conatct']['source'] = ''; |
| 871 | $pluggable_data['conatct']['date_of_birth'] = '2022-11-09'; |
| 872 | $context['tag_id'] = 1; |
| 873 | $pluggable_data['tag'] = |
| 874 | [ |
| 875 | 'id' => '1', |
| 876 | 'title' => 'new', |
| 877 | 'slug' => 'new', |
| 878 | 'description' => null, |
| 879 | 'created_at' => '2023-01-19 10:23:23', |
| 880 | 'updated_at' => '2023-01-19 10:23:23', |
| 881 | 'pivot' => [ |
| 882 | 'subscriber_id' => '1', |
| 883 | 'object_id' => '1', |
| 884 | 'object_type' => 'FluentCrm\\App\\Models\\Tag', |
| 885 | 'created_at' => '2023-01-19 10:42:55', |
| 886 | 'updated_at' => '2023-01-19 10:42:55', |
| 887 | |
| 888 | ], |
| 889 | ]; |
| 890 | $context['response_type'] = 'sample'; |
| 891 | } |
| 892 | |
| 893 | $context['pluggable_data'] = $pluggable_data; |
| 894 | return $context; |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Get FluentCRM contact details. |
| 899 | * |
| 900 | * @param array $data data. |
| 901 | * |
| 902 | * @return array |
| 903 | */ |
| 904 | public function search_pluggables_fluentcrm_contact_added( $data ) { |
| 905 | $context = []; |
| 906 | $pluggable_data = []; |
| 907 | |
| 908 | $contact = Subscriber::orderBy( 'id', 'DESC' )->first(); |
| 909 | if ( $contact ) { |
| 910 | /** |
| 911 | * |
| 912 | * Ignore line |
| 913 | * |
| 914 | * @phpstan-ignore-next-line |
| 915 | */ |
| 916 | $subscriber = Subscriber::with( [ 'tags', 'lists' ] )->find( $contact->id ); |
| 917 | $customer_fields = $subscriber->custom_fields(); |
| 918 | $pluggable_data['contact']['details'] = $subscriber; |
| 919 | $pluggable_data['contact']['custom'] = $customer_fields; |
| 920 | $context['response_type'] = 'live'; |
| 921 | } else { |
| 922 | $pluggable_data['contact']['details']['full_name'] = 'Test User'; |
| 923 | $pluggable_data['contact']['details']['first_name'] = 'Test'; |
| 924 | $pluggable_data['contact']['details']['last_name'] = 'User'; |
| 925 | $pluggable_data['contact']['details']['company_id'] = 112; |
| 926 | $pluggable_data['contact']['details']['email'] = 'testuser@gmail.com'; |
| 927 | $pluggable_data['contact']['details']['address_line_1'] = '33, Vincent Road'; |
| 928 | $pluggable_data['contact']['details']['address_line_2'] = 'Chicago Street'; |
| 929 | $pluggable_data['contact']['details']['postal_code'] = '212342'; |
| 930 | $pluggable_data['contact']['details']['city'] = 'New York City'; |
| 931 | $pluggable_data['contact']['details']['state'] = 'New York'; |
| 932 | $pluggable_data['contact']['details']['country'] = 'USA'; |
| 933 | $pluggable_data['contact']['details']['phone'] = '9992191911'; |
| 934 | $pluggable_data['contact']['details']['status'] = 'subscribed'; |
| 935 | $pluggable_data['contact']['details']['contact_type'] = 'lead'; |
| 936 | $pluggable_data['contact']['details']['source'] = ''; |
| 937 | $pluggable_data['contact']['details']['date_of_birth'] = '2022-11-09'; |
| 938 | $context['response_type'] = 'sample'; |
| 939 | } |
| 940 | |
| 941 | $context['pluggable_data'] = $pluggable_data; |
| 942 | return $context; |
| 943 | } |
| 944 | |
| 945 | /** |
| 946 | * Get Divi Forms. |
| 947 | * |
| 948 | * @param array $data data. |
| 949 | * |
| 950 | * @return array |
| 951 | */ |
| 952 | public function search_divi_forms( $data ) { |
| 953 | $form_posts = Utilities::get_divi_forms(); |
| 954 | $options = []; |
| 955 | |
| 956 | if ( empty( $form_posts ) ) { |
| 957 | return [ |
| 958 | 'options' => [], |
| 959 | 'hasMore' => false, |
| 960 | ]; |
| 961 | } |
| 962 | |
| 963 | foreach ( $form_posts as $form_post ) { |
| 964 | $pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/'; |
| 965 | preg_match_all( $pattern_regex, $form_post['post_content'], $forms, PREG_SET_ORDER ); |
| 966 | if ( empty( $forms ) ) { |
| 967 | continue; |
| 968 | } |
| 969 | |
| 970 | $count = 0; |
| 971 | |
| 972 | foreach ( $forms as $form ) { |
| 973 | $pattern_form = get_shortcode_regex( [ 'et_pb_contact_form' ] ); |
| 974 | preg_match_all( "/$pattern_form/", $form[0], $forms_extracted, PREG_SET_ORDER ); |
| 975 | |
| 976 | if ( empty( $forms_extracted ) ) { |
| 977 | continue; |
| 978 | } |
| 979 | |
| 980 | foreach ( $forms_extracted as $form_extracted ) { |
| 981 | $form_attrs = shortcode_parse_atts( $form_extracted[3] ); |
| 982 | $form_id = isset( $form_attrs['_unique_id'] ) ? $form_attrs['_unique_id'] : ''; |
| 983 | if ( empty( $form_id ) ) { |
| 984 | continue; |
| 985 | } |
| 986 | $form_id = sprintf( '%d-%s', $form_post['ID'], $form_id ); |
| 987 | $form_title = isset( $form_attrs['title'] ) ? $form_attrs['title'] : ''; |
| 988 | $form_title = sprintf( '%s %s', $form_post['post_title'], $form_title ); |
| 989 | $options[] = [ |
| 990 | 'label' => $form_title, |
| 991 | 'value' => $form_id, |
| 992 | ]; |
| 993 | } |
| 994 | $count++; |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | return [ |
| 999 | 'options' => $options, |
| 1000 | 'hasMore' => false, |
| 1001 | ]; |
| 1002 | } |
| 1003 | |
| 1004 | /** |
| 1005 | * Get Comment Pluggable data. |
| 1006 | * |
| 1007 | * @param array $data data. |
| 1008 | * |
| 1009 | * @return array |
| 1010 | */ |
| 1011 | public function search_pluggables_wp_insert_comment( $data ) { |
| 1012 | $context = []; |
| 1013 | $post_data = []; |
| 1014 | $args = [ |
| 1015 | 'number' => '1', |
| 1016 | 'status' => 'approve', |
| 1017 | ]; |
| 1018 | |
| 1019 | if ( isset( $data['filter']['post']['value'] ) ) { |
| 1020 | $post_id = $data['filter']['post']['value']; |
| 1021 | if ( $post_id > 0 ) { |
| 1022 | $args['post_id'] = $post_id; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | $comments = get_comments( $args ); |
| 1027 | if ( empty( $comments ) ) { |
| 1028 | unset( $args['post_id'] ); |
| 1029 | $comments = get_comments( $args ); |
| 1030 | } |
| 1031 | $context['context_data'] = $data; |
| 1032 | $context['context_args'] = $args; |
| 1033 | if ( ! empty( $comments ) ) { |
| 1034 | foreach ( $comments as $comment ) : |
| 1035 | if ( is_object( $comment ) ) { |
| 1036 | $comment = get_object_vars( $comment ); |
| 1037 | } |
| 1038 | if ( is_array( $comment ) && isset( $comment['comment_post_ID'] ) ) { |
| 1039 | $post = get_post( absint( $comment['comment_post_ID'] ) ); |
| 1040 | if ( is_object( $post ) ) { |
| 1041 | if ( property_exists( $post, 'ID' ) || property_exists( $post, 'post_author' ) || property_exists( $post, 'post_title' ) ) { |
| 1042 | $post_id = $post->ID; |
| 1043 | $postauthor = (int) $post->post_author; |
| 1044 | if ( is_array( $comment ) ) { |
| 1045 | $context['pluggable_data'] = [ |
| 1046 | 'post' => $post_id, |
| 1047 | 'post_title' => $post->post_title, |
| 1048 | 'post_author' => get_the_author_meta( 'display_name', $postauthor ), |
| 1049 | 'post_link' => get_the_permalink( $post_id ), |
| 1050 | 'comment_id' => $comment['comment_ID'], |
| 1051 | 'comment' => $comment['comment_content'], |
| 1052 | 'comment_author' => $comment['comment_author'], |
| 1053 | 'comment_author_email' => $comment['comment_author_email'], |
| 1054 | 'comment_date' => $comment['comment_date'], |
| 1055 | ]; |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | if ( is_array( $comment ) && isset( $comment['comment_author_email'] ) ) { |
| 1061 | $user_email = $comment['comment_author_email']; |
| 1062 | /** |
| 1063 | * |
| 1064 | * Ignore line |
| 1065 | * |
| 1066 | * @phpstan-ignore-next-line |
| 1067 | */ |
| 1068 | $user = get_user_by( 'email', $user_email ); |
| 1069 | if ( $user ) { |
| 1070 | $context['pluggable_data']['wp_user_id'] = $user->ID; |
| 1071 | $context['pluggable_data']['user_login'] = $user->user_login; |
| 1072 | $context['pluggable_data']['display_name'] = $user->display_name; |
| 1073 | $context['pluggable_data']['user_firstname'] = $user->user_firstname; |
| 1074 | $context['pluggable_data']['user_lastname'] = $user->user_lastname; |
| 1075 | $context['pluggable_data']['user_email'] = $user->user_email; |
| 1076 | $context['pluggable_data']['user_role'] = $user->roles; |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | $context['response_type'] = 'live'; |
| 1081 | endforeach; |
| 1082 | } else { |
| 1083 | $sample_comment = [ |
| 1084 | 'post' => 100, |
| 1085 | 'post_title' => 'Sample Post', |
| 1086 | 'comment_id' => 101, |
| 1087 | 'comment' => 'Sample Comment', |
| 1088 | ]; |
| 1089 | $sample_comment['wp_user_id'] = 7; |
| 1090 | $sample_comment['user_login'] = 'testuser@gmail.com'; |
| 1091 | $sample_comment['display_name'] = 'Test User'; |
| 1092 | $sample_comment['user_firstname'] = 'Test'; |
| 1093 | $sample_comment['user_lastname'] = 'User'; |
| 1094 | $sample_comment['user_email'] = 'testuser@gmail.com'; |
| 1095 | $sample_comment['user_role'] = [ 'Subscriber' ]; |
| 1096 | |
| 1097 | $context['pluggable_data'] = $sample_comment; |
| 1098 | $context['response_type'] = 'sample'; |
| 1099 | } |
| 1100 | return $context; |
| 1101 | } |
| 1102 | |
| 1103 | /** |
| 1104 | * User reset password. |
| 1105 | * |
| 1106 | * @param array $data data. |
| 1107 | * @return array |
| 1108 | */ |
| 1109 | public function search_pluggables_user_reset_password( $data ) { |
| 1110 | $user_context = $this->search_pluggables_add_user_role( $data ); |
| 1111 | $user_context['pluggable_data']['new_password'] = '***password***'; |
| 1112 | return $user_context; |
| 1113 | } |
| 1114 | |
| 1115 | /** |
| 1116 | * User pluggable data. |
| 1117 | * |
| 1118 | * @param array $data data. |
| 1119 | * @return array |
| 1120 | */ |
| 1121 | public function search_pluggables_add_user_role( $data ) { |
| 1122 | $context = []; |
| 1123 | $args = [ |
| 1124 | 'order' => 'DESC', |
| 1125 | 'number' => 1, |
| 1126 | 'orderby' => 'ID', |
| 1127 | ]; |
| 1128 | |
| 1129 | if ( isset( $data['filter']['role']['value'] ) ) { |
| 1130 | $role = $data['filter']['role']['value']; |
| 1131 | $args['role'] = $role; |
| 1132 | } |
| 1133 | if ( isset( $data['filter']['new_role']['value'] ) ) { |
| 1134 | $role = $data['filter']['new_role']['value']; |
| 1135 | $args['role'] = $role; |
| 1136 | } |
| 1137 | |
| 1138 | $users = get_users( $args ); |
| 1139 | |
| 1140 | if ( isset( $data['filter']['meta_key']['value'] ) ) { |
| 1141 | $meta_key = $data['filter']['meta_key']['value']; |
| 1142 | $args['st_meta_key'] = $meta_key; |
| 1143 | } |
| 1144 | |
| 1145 | if ( isset( $data['filter']['profile_field']['value'] ) ) { |
| 1146 | $meta_key = $data['filter']['profile_field']['value']; |
| 1147 | $args['profile_field'] = $meta_key; |
| 1148 | } |
| 1149 | |
| 1150 | if ( ! empty( $users ) ) { |
| 1151 | $user = $users[0]; |
| 1152 | $pluggable_data = []; |
| 1153 | $pluggable_data['wp_user_id'] = $user->ID; |
| 1154 | $pluggable_data['user_login'] = $user->user_login; |
| 1155 | $pluggable_data['display_name'] = $user->display_name; |
| 1156 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 1157 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 1158 | $pluggable_data['user_email'] = $user->user_email; |
| 1159 | $pluggable_data['user_role'] = $user->roles; |
| 1160 | |
| 1161 | if ( isset( $args['st_meta_key'] ) ) { |
| 1162 | $pluggable_data['meta_key'] = $args['st_meta_key']; |
| 1163 | $pluggable_data['meta_value'] = get_user_meta( $user->ID, $args['st_meta_key'], true ); |
| 1164 | } |
| 1165 | if ( isset( $args['profile_field'] ) ) { |
| 1166 | $userdata = get_userdata( $user->ID ); |
| 1167 | $userdata = json_decode( wp_json_encode( $userdata->data ), true ); |
| 1168 | |
| 1169 | $pluggable_data['profile_field'] = $args['profile_field']; |
| 1170 | $pluggable_data['profile_field_value'] = $userdata[ $args['profile_field'] ]; |
| 1171 | } |
| 1172 | $context['pluggable_data'] = $pluggable_data; |
| 1173 | $context['response_type'] = 'live'; |
| 1174 | } else { |
| 1175 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 1176 | $context['pluggable_data'] = [ |
| 1177 | 'wp_user_id' => 1, |
| 1178 | 'user_login' => 'admin', |
| 1179 | 'display_name' => 'Test User', |
| 1180 | 'user_firstname' => 'Test', |
| 1181 | 'user_lastname' => 'User', |
| 1182 | 'user_email' => 'testuser@gmail.com', |
| 1183 | 'user_role' => [ $role ], |
| 1184 | ]; |
| 1185 | if ( isset( $args['st_meta_key'] ) ) { |
| 1186 | $context['pluggable_data']['meta_key'] = $args['st_meta_key']; |
| 1187 | $context['pluggable_data']['meta_value'] = 'test meta value'; |
| 1188 | } |
| 1189 | if ( isset( $args['profile_field'] ) ) { |
| 1190 | $context['pluggable_data']['profile_field'] = $args['profile_field']; |
| 1191 | $context['pluggable_data']['profile_field_value'] = 'Profile Field Value'; |
| 1192 | } |
| 1193 | $context['response_type'] = 'sample'; |
| 1194 | } |
| 1195 | return $context; |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * User pluggable data. |
| 1200 | * |
| 1201 | * @param array $data data. |
| 1202 | * @return array |
| 1203 | */ |
| 1204 | public function search_pluggables_last_user_login( $data ) { |
| 1205 | $context = []; |
| 1206 | $args = [ |
| 1207 | 'orderby' => 'meta_value', |
| 1208 | 'meta_key' => 'st_last_login', |
| 1209 | 'order' => 'DESC', |
| 1210 | 'number' => 1, |
| 1211 | ]; |
| 1212 | $users = get_users( $args ); |
| 1213 | |
| 1214 | if ( ! empty( $users ) ) { |
| 1215 | $user = $users[0]; |
| 1216 | $pluggable_data = []; |
| 1217 | $pluggable_data['wp_user_id'] = $user->ID; |
| 1218 | $pluggable_data['user_login'] = $user->user_login; |
| 1219 | $pluggable_data['display_name'] = $user->display_name; |
| 1220 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 1221 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 1222 | $pluggable_data['user_email'] = $user->user_email; |
| 1223 | $pluggable_data['user_role'] = $user->roles; |
| 1224 | |
| 1225 | $context['pluggable_data'] = $pluggable_data; |
| 1226 | $context['response_type'] = 'live'; |
| 1227 | } else { |
| 1228 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 1229 | $context['pluggable_data'] = [ |
| 1230 | 'wp_user_id' => 1, |
| 1231 | 'user_login' => 'admin', |
| 1232 | 'display_name' => 'Test User', |
| 1233 | 'user_firstname' => 'Test', |
| 1234 | 'user_lastname' => 'User', |
| 1235 | 'user_email' => 'testuser@gmail.com', |
| 1236 | 'user_role' => [ $role ], |
| 1237 | ]; |
| 1238 | $context['response_type'] = 'sample'; |
| 1239 | } |
| 1240 | return $context; |
| 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * Donation pluggable data. |
| 1245 | * |
| 1246 | * @param array $data data. |
| 1247 | * @return array |
| 1248 | */ |
| 1249 | public function search_pluggables_wordpress_post( $data ) { |
| 1250 | $context = []; |
| 1251 | $args = [ |
| 1252 | 'post_type' => 'any', |
| 1253 | 'posts_per_page' => 1, |
| 1254 | 'orderby' => 'modified', |
| 1255 | 'order' => 'DESC', |
| 1256 | ]; |
| 1257 | |
| 1258 | if ( isset( $data['filter']['post_type']['value'] ) ) { |
| 1259 | $post_type = $data['filter']['post_type']['value']; |
| 1260 | $args['post_type'] = $post_type; |
| 1261 | } |
| 1262 | |
| 1263 | if ( isset( $data['filter']['status']['value'] ) ) { |
| 1264 | $post_status = $data['filter']['status']['value']; |
| 1265 | $args['post_status'] = $post_status; |
| 1266 | } |
| 1267 | |
| 1268 | if ( isset( $data['filter']['post_status']['value'] ) ) { |
| 1269 | $post_status = $data['filter']['post_status']['value']; |
| 1270 | $args['post_status'] = $post_status; |
| 1271 | } |
| 1272 | |
| 1273 | if ( isset( $data['filter']['post']['value'] ) ) { |
| 1274 | $post_id = $data['filter']['post']['value']; |
| 1275 | if ( $post_id > 0 ) { |
| 1276 | $args['p'] = $post_id; |
| 1277 | unset( $args['post_status'] ); |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | $posts = get_posts( $args ); |
| 1282 | if ( ! empty( $posts ) ) { |
| 1283 | $context['pluggable_data'] = $posts[0]; |
| 1284 | $custom_metas = get_post_meta( $posts[0]->ID ); |
| 1285 | if ( property_exists( $context['pluggable_data'], 'post' ) ) { |
| 1286 | $context['pluggable_data']->post = $posts[0]->ID; |
| 1287 | } |
| 1288 | if ( is_object( $context['pluggable_data'] ) ) { |
| 1289 | $context['pluggable_data'] = get_object_vars( $context['pluggable_data'] ); |
| 1290 | } |
| 1291 | $context['pluggable_data']['custom_metas'] = $custom_metas; |
| 1292 | $context['response_type'] = 'live'; |
| 1293 | } else { |
| 1294 | $context['pluggable_data'] = [ |
| 1295 | 'ID' => 557, |
| 1296 | 'post' => 557, |
| 1297 | 'post_author' => 1, |
| 1298 | 'post_date' => '2022-11-18 12:18:14', |
| 1299 | 'post_date_gmt' => '2022-11-18 12:18:14', |
| 1300 | 'post_content' => 'Test Post Content', |
| 1301 | 'post_title' => 'Test Post', |
| 1302 | 'post_excerpt' => '', |
| 1303 | 'post_status' => $args['post_status'], |
| 1304 | 'comment_status' => 'open', |
| 1305 | 'ping_status' => 'open', |
| 1306 | 'post_password' => '', |
| 1307 | 'post_name' => 'test-post', |
| 1308 | 'to_ping' => '', |
| 1309 | 'pinged' => '', |
| 1310 | 'post_modified' => '2022-11-18 12:18:14', |
| 1311 | 'post_modified_gmt' => '2022-11-18 12:18:14', |
| 1312 | 'post_content_filtered' => '', |
| 1313 | 'post_parent' => 0, |
| 1314 | 'guid' => 'https://abc.com/test-post/', |
| 1315 | 'menu_order' => 0, |
| 1316 | 'post_type' => 'post', |
| 1317 | 'post_mime_type' => '', |
| 1318 | 'comment_count' => 0, |
| 1319 | 'filter' => 'raw', |
| 1320 | ]; |
| 1321 | $context['response_type'] = 'sample'; |
| 1322 | } |
| 1323 | |
| 1324 | return $context; |
| 1325 | } |
| 1326 | |
| 1327 | /** |
| 1328 | * Donation pluggable data |
| 1329 | * |
| 1330 | * @param array $data data. |
| 1331 | * @return array |
| 1332 | */ |
| 1333 | public function search_pluggables_givewp_donation_via_form( $data ) { |
| 1334 | global $wpdb; |
| 1335 | $context = []; |
| 1336 | $pluggable_data = []; |
| 1337 | |
| 1338 | $payment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type=%s ORDER BY id DESC LIMIT 1", 'give_payment' ) ); |
| 1339 | |
| 1340 | if ( ! empty( $payment ) ) { |
| 1341 | $payment = new Give_Payment( $payment->ID ); |
| 1342 | $address_data = $payment->address; |
| 1343 | |
| 1344 | $pluggable_data['first_name'] = $payment->first_name; |
| 1345 | $pluggable_data['last_name'] = $payment->last_name; |
| 1346 | $pluggable_data['email'] = $payment->email; |
| 1347 | $pluggable_data['currency'] = $payment->currency; |
| 1348 | $pluggable_data['donated_amount'] = $payment->subtotal; |
| 1349 | $pluggable_data['donation_amount'] = $payment->subtotal; |
| 1350 | $pluggable_data['form_id'] = (int) $payment->form_id; |
| 1351 | $pluggable_data['form_title'] = $payment->form_title; |
| 1352 | $pluggable_data['name_title_prefix'] = $payment->title_prefix; |
| 1353 | $pluggable_data['date'] = $payment->date; |
| 1354 | |
| 1355 | if ( is_array( $address_data ) ) { |
| 1356 | $pluggable_data['address_line_1'] = $address_data['line1']; |
| 1357 | $pluggable_data['address_line_2'] = $address_data['line2']; |
| 1358 | $pluggable_data['city'] = $address_data['city']; |
| 1359 | $pluggable_data['state'] = $address_data['state']; |
| 1360 | $pluggable_data['zip'] = $address_data['zip']; |
| 1361 | $pluggable_data['country'] = $address_data['country']; |
| 1362 | } |
| 1363 | $donor_comment = give_get_donor_donation_comment( $payment->ID, $payment->donor_id ); |
| 1364 | $pluggable_data['comment'] = isset( $doner['comment_content'] ) ? $donor_comment : ''; |
| 1365 | $context['response_type'] = 'live'; |
| 1366 | } else { |
| 1367 | $pluggable_data['first_name'] = 'Test'; |
| 1368 | $pluggable_data['last_name'] = 'User'; |
| 1369 | $pluggable_data['email'] = 'testuser@gmail.com'; |
| 1370 | $pluggable_data['currency'] = 'USD'; |
| 1371 | $pluggable_data['donated_amount'] = 100; |
| 1372 | $pluggable_data['donation_amount'] = 100; |
| 1373 | $pluggable_data['form_id'] = 23; |
| 1374 | $pluggable_data['form_title'] = 'Test Donation'; |
| 1375 | $pluggable_data['name_title_prefix'] = 'Mr'; |
| 1376 | $pluggable_data['date'] = '2022-11-07 16:06:05'; |
| 1377 | $pluggable_data['address_line_1'] = '33, Vincent Road'; |
| 1378 | $pluggable_data['address_line_2'] = 'Chicago Street'; |
| 1379 | $pluggable_data['city'] = 'New York City'; |
| 1380 | $pluggable_data['state'] = 'New York'; |
| 1381 | $pluggable_data['zip'] = '223131'; |
| 1382 | $pluggable_data['country'] = 'USA'; |
| 1383 | $pluggable_data['comment'] = 'Test Comment'; |
| 1384 | $context['response_type'] = 'sample'; |
| 1385 | } |
| 1386 | |
| 1387 | $context['pluggable_data'] = $pluggable_data; |
| 1388 | return $context; |
| 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | * Search Divi Form fields. |
| 1393 | * |
| 1394 | * @param array $data Search Params. |
| 1395 | * |
| 1396 | * @since 1.0.0 |
| 1397 | * |
| 1398 | * @return array |
| 1399 | */ |
| 1400 | public function search_pluggable_divi_form_fields( $data ) { |
| 1401 | $result = []; |
| 1402 | $form_id = absint( $data['dynamic'] ); |
| 1403 | $form_posts = Utilities::get_divi_forms(); |
| 1404 | |
| 1405 | if ( empty( $form_posts ) ) { |
| 1406 | return [ |
| 1407 | 'options' => [], |
| 1408 | 'hasMore' => false, |
| 1409 | ]; |
| 1410 | } |
| 1411 | $fields = []; |
| 1412 | foreach ( $form_posts as $form_post ) { |
| 1413 | $pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/'; |
| 1414 | preg_match_all( $pattern_regex, $form_post['post_content'], $forms, PREG_SET_ORDER ); |
| 1415 | if ( empty( $forms ) ) { |
| 1416 | continue; |
| 1417 | } |
| 1418 | |
| 1419 | $count = 0; |
| 1420 | |
| 1421 | foreach ( $forms as $form ) { |
| 1422 | $pattern = get_shortcode_regex( [ 'et_pb_contact_field' ] ); |
| 1423 | |
| 1424 | preg_match_all( "/$pattern/", $form[0], $contact_fields, PREG_SET_ORDER ); |
| 1425 | |
| 1426 | if ( empty( $contact_fields ) ) { |
| 1427 | return $fields; |
| 1428 | } |
| 1429 | |
| 1430 | foreach ( $contact_fields as $contact_field ) { |
| 1431 | $contact_field_attrs = shortcode_parse_atts( $contact_field[3] ); |
| 1432 | $field_id = strtolower( self::array_get( $contact_field_attrs, 'field_id' ) ); |
| 1433 | $fields[] = [ |
| 1434 | 'field_title' => self::array_get( $contact_field_attrs, 'field_title', __( 'No title', 'suretriggers' ) ), |
| 1435 | 'field_id' => $field_id, |
| 1436 | ]; |
| 1437 | } |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | if ( ! empty( $fields ) ) { |
| 1442 | foreach ( $fields as $field ) { |
| 1443 | $result[] = [ |
| 1444 | 'label' => $field['field_title'], |
| 1445 | 'value' => '{' . $field['field_id'] . '}', |
| 1446 | ]; |
| 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | return [ |
| 1451 | 'options' => $result, |
| 1452 | 'hasMore' => false, |
| 1453 | ]; |
| 1454 | } |
| 1455 | |
| 1456 | /** |
| 1457 | * Pseudo function copied from Divi |
| 1458 | * |
| 1459 | * @param array $array An array which contains value located at `$address`. |
| 1460 | * @param string|array $address The location of the value within `$array` (dot notation). |
| 1461 | * @param mixed $default Value to return if not found. Default is an empty string. |
| 1462 | * |
| 1463 | * @return mixed The value, if found, otherwise $default. |
| 1464 | */ |
| 1465 | public static function array_get( $array, $address, $default = '' ) { |
| 1466 | $keys = is_array( $address ) ? $address : explode( '.', $address ); |
| 1467 | $value = $array; |
| 1468 | |
| 1469 | foreach ( $keys as $key ) { |
| 1470 | if ( ! empty( $key ) && isset( $key[0] ) && '[' === $key[0] ) { |
| 1471 | $index = substr( $key, 1, -1 ); |
| 1472 | |
| 1473 | if ( is_numeric( $index ) ) { |
| 1474 | $key = (int) $index; |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | if ( ! isset( $value[ $key ] ) ) { |
| 1479 | return $default; |
| 1480 | } |
| 1481 | |
| 1482 | $value = $value[ $key ]; |
| 1483 | } |
| 1484 | |
| 1485 | return $value; |
| 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * Get UAG Forms. |
| 1490 | * |
| 1491 | * @param array $data data. |
| 1492 | * |
| 1493 | * @return array |
| 1494 | */ |
| 1495 | public function search_spectra_forms( $data ) { |
| 1496 | $form_posts = Utilities::get_uag_forms(); |
| 1497 | |
| 1498 | $options = []; |
| 1499 | if ( empty( $form_posts ) ) { |
| 1500 | return [ |
| 1501 | 'options' => [], |
| 1502 | 'hasMore' => false, |
| 1503 | ]; |
| 1504 | } |
| 1505 | |
| 1506 | foreach ( $form_posts as $form_post ) { |
| 1507 | $blocks = parse_blocks( $form_post['post_content'] ); |
| 1508 | $i = 1; |
| 1509 | foreach ( $blocks as $key => $block ) { |
| 1510 | if ( 'uagb/forms' === $block['blockName'] ) { |
| 1511 | $options[] = [ |
| 1512 | 'label' => $form_post['post_title'] . ' (Form ' . ( $i ) . ')', |
| 1513 | 'value' => $block['attrs']['block_id'], |
| 1514 | ]; |
| 1515 | $i++; |
| 1516 | } elseif ( 'uagb/forms' !== $block['blockName'] && isset( $block['innerBlocks'] ) ) { |
| 1517 | $container_key = self::get_column_by_value( $block['innerBlocks'], 'uagb/container' ); |
| 1518 | if ( isset( $container_key ) && '' !== $container_key ) { |
| 1519 | $options[] = [ |
| 1520 | 'label' => $form_post['post_title'] . ' (Form ' . ( $i ) . ')', |
| 1521 | 'value' => $block['innerBlocks'][ $container_key ]['attrs']['block_id'], |
| 1522 | ]; |
| 1523 | $i++; |
| 1524 | } |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | return [ |
| 1530 | 'options' => $options, |
| 1531 | 'hasMore' => false, |
| 1532 | ]; |
| 1533 | } |
| 1534 | |
| 1535 | /** |
| 1536 | * Check array recursive. |
| 1537 | * |
| 1538 | * @param array $array Array. |
| 1539 | * @param string $value search params. |
| 1540 | * @since 1.0.0 |
| 1541 | * |
| 1542 | * @return array|void |
| 1543 | */ |
| 1544 | public static function get_column_by_value( $array, $value ) { |
| 1545 | |
| 1546 | foreach ( $array as $key => $sub_array ) { |
| 1547 | |
| 1548 | if ( is_array( $sub_array ) ) { |
| 1549 | $result = self::get_column_by_value( $sub_array, $value ); |
| 1550 | if ( null !== $result ) { |
| 1551 | return $key; |
| 1552 | } |
| 1553 | } else { |
| 1554 | return $key; |
| 1555 | } |
| 1556 | } |
| 1557 | return null; |
| 1558 | |
| 1559 | } |
| 1560 | |
| 1561 | |
| 1562 | /** |
| 1563 | * Search UAG Form fields. |
| 1564 | * |
| 1565 | * @param array $data Search Params. |
| 1566 | * |
| 1567 | * @since 1.0.0 |
| 1568 | * |
| 1569 | * @return array |
| 1570 | */ |
| 1571 | public function search_spectraform_fields( $data ) { |
| 1572 | $result = []; |
| 1573 | $form_id = absint( $data['dynamic'] ); |
| 1574 | $form_posts = Utilities::get_uag_forms(); |
| 1575 | |
| 1576 | if ( empty( $form_posts ) ) { |
| 1577 | return [ |
| 1578 | 'options' => [], |
| 1579 | 'hasMore' => false, |
| 1580 | ]; |
| 1581 | } |
| 1582 | |
| 1583 | foreach ( $form_posts as $form_post ) { |
| 1584 | $blocks = parse_blocks( $form_post['post_content'] ); |
| 1585 | |
| 1586 | foreach ( $blocks as $block ) { |
| 1587 | if ( (int) $block['attrs']['block_id'] === $form_id ) { |
| 1588 | $doc = new DOMDocument(); |
| 1589 | $rendered_block = render_block( $block ); |
| 1590 | $doc->loadHTML( $rendered_block ); |
| 1591 | $child_node_list = $doc->getElementsByTagName( 'div' ); |
| 1592 | for ( $i = 0; $i < $child_node_list->length; $i++ ) { |
| 1593 | $temp = $child_node_list->item( $i ); |
| 1594 | if ( $temp && stripos( $temp->getAttribute( 'class' ), 'uagb-forms-input-label' ) !== false ) { |
| 1595 | $nodes[] = $temp; |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | foreach ( $nodes as $node ) { |
| 1600 | $result[] = [ |
| 1601 | 'label' => $node->textContent, //phpcs:ignore |
| 1602 | 'value' => $node->textContent, //phpcs:ignore |
| 1603 | ]; |
| 1604 | } |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | return [ |
| 1610 | 'options' => $result, |
| 1611 | 'hasMore' => false, |
| 1612 | ]; |
| 1613 | } |
| 1614 | |
| 1615 | /** |
| 1616 | * Search forms of MetForms. |
| 1617 | * |
| 1618 | * @param array $data data. |
| 1619 | * @return array |
| 1620 | */ |
| 1621 | public function search_met_forms( $data ) { |
| 1622 | $args = [ |
| 1623 | 'post_type' => 'metform-form', |
| 1624 | 'post_status' => 'publish', |
| 1625 | 'numberposts' => -1, |
| 1626 | ]; |
| 1627 | |
| 1628 | $forms = get_posts( $args ); |
| 1629 | |
| 1630 | $options = []; |
| 1631 | |
| 1632 | if ( ! empty( $forms ) ) { |
| 1633 | foreach ( $forms as $form ) { |
| 1634 | $options[] = [ |
| 1635 | 'label' => $form->post_title, |
| 1636 | 'value' => $form->ID, |
| 1637 | ]; |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | return [ |
| 1642 | 'options' => $options, |
| 1643 | 'hasMore' => false, |
| 1644 | ]; |
| 1645 | } |
| 1646 | |
| 1647 | /** |
| 1648 | * Search forms of Ninja Forms. |
| 1649 | * |
| 1650 | * @param array $data data. |
| 1651 | * @return array |
| 1652 | */ |
| 1653 | public function search_ninja_forms( $data ) { |
| 1654 | $options = []; |
| 1655 | |
| 1656 | if ( function_exists( 'Ninja_Forms' ) ) { |
| 1657 | foreach ( Ninja_Forms()->form()->get_forms() as $form ) { |
| 1658 | $options[] = [ |
| 1659 | 'label' => $form->get_setting( 'title' ), |
| 1660 | 'value' => $form->get_id(), |
| 1661 | ]; |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | return [ |
| 1666 | 'options' => $options, |
| 1667 | 'hasMore' => false, |
| 1668 | ]; |
| 1669 | } |
| 1670 | |
| 1671 | /** |
| 1672 | * Search forms of Pie Forms. |
| 1673 | * |
| 1674 | * @param array $data data. |
| 1675 | * @return array |
| 1676 | */ |
| 1677 | public function search_pie_forms( $data ) { |
| 1678 | global $wpdb; |
| 1679 | $options = []; |
| 1680 | |
| 1681 | if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'pf_forms' ) ) ) { |
| 1682 | |
| 1683 | $results = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'pf_forms WHERE post_status = "published"' ); |
| 1684 | |
| 1685 | if ( $results ) { |
| 1686 | foreach ( $results as $result ) { |
| 1687 | $options[] = [ |
| 1688 | 'label' => $result->form_title, |
| 1689 | 'value' => $result->id, |
| 1690 | ]; |
| 1691 | } |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | return [ |
| 1696 | 'options' => $options, |
| 1697 | 'hasMore' => false, |
| 1698 | ]; |
| 1699 | } |
| 1700 | |
| 1701 | /** |
| 1702 | * Get Fluent Forms. |
| 1703 | * |
| 1704 | * @param array $data data. |
| 1705 | * |
| 1706 | * @return array |
| 1707 | */ |
| 1708 | public function search_fluent_forms( $data ) { |
| 1709 | |
| 1710 | if ( ! function_exists( 'wpFluent' ) ) { |
| 1711 | return [ |
| 1712 | 'options' => [], |
| 1713 | 'hasMore' => false, |
| 1714 | ]; |
| 1715 | } |
| 1716 | |
| 1717 | $forms = wpFluent()->table( 'fluentform_forms' ) |
| 1718 | ->select( [ 'id', 'title' ] ) |
| 1719 | ->orderBy( 'id', 'DESC' ) |
| 1720 | ->get(); |
| 1721 | |
| 1722 | $options = []; |
| 1723 | if ( ! empty( $forms ) ) { |
| 1724 | foreach ( $forms as $form ) { |
| 1725 | $options[] = [ |
| 1726 | 'label' => $form->title, |
| 1727 | 'value' => $form->id, |
| 1728 | ]; |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | return [ |
| 1733 | 'options' => $options, |
| 1734 | 'hasMore' => false, |
| 1735 | ]; |
| 1736 | |
| 1737 | } |
| 1738 | |
| 1739 | /** |
| 1740 | * Get Fluent Forms. |
| 1741 | * |
| 1742 | * @param array $data data. |
| 1743 | * |
| 1744 | * @return array |
| 1745 | */ |
| 1746 | public function search_bricks_builder_forms( $data ) { |
| 1747 | $bricks_theme = wp_get_theme( 'bricks' ); |
| 1748 | if ( ! $bricks_theme->exists() ) { |
| 1749 | return [ |
| 1750 | 'options' => [], |
| 1751 | 'hasMore' => false, |
| 1752 | ]; |
| 1753 | } |
| 1754 | |
| 1755 | $args = [ |
| 1756 | 'post_type' => 'bricks_template', |
| 1757 | 'post_status' => 'publish', |
| 1758 | 'posts_per_page' => -1, |
| 1759 | ]; |
| 1760 | |
| 1761 | $templates = get_posts( $args ); |
| 1762 | |
| 1763 | $options = []; |
| 1764 | if ( ! empty( $templates ) ) { |
| 1765 | foreach ( $templates as $template ) { |
| 1766 | $fetch_content = get_post_meta( $template->ID, BRICKS_DB_PAGE_CONTENT, true ); |
| 1767 | if ( is_array( $fetch_content ) ) { |
| 1768 | foreach ( $fetch_content as $content ) { |
| 1769 | if ( 'form' === $content['name'] ) { |
| 1770 | $options[] = [ |
| 1771 | 'label' => $template->post_title . ' - ' . ( isset( $content['label'] ) ? $content['label'] : 'Form' ), |
| 1772 | 'value' => $content['id'], |
| 1773 | ]; |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | return [ |
| 1781 | 'options' => $options, |
| 1782 | 'hasMore' => false, |
| 1783 | ]; |
| 1784 | |
| 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * Bricks builder form fields. |
| 1789 | * |
| 1790 | * @param array $data data. |
| 1791 | * @return array |
| 1792 | */ |
| 1793 | public function search_pluggable_bricks_builder_form_fields( $data ) { |
| 1794 | $result = []; |
| 1795 | $fields = []; |
| 1796 | $form_id_str = $data['dynamic']; |
| 1797 | $ids = explode( '_', $form_id_str ); |
| 1798 | $post_id = $ids[0]; |
| 1799 | $form_id = $ids[1]; |
| 1800 | $fetch_content = get_post_meta( $post_id, BRICKS_DB_PAGE_CONTENT, true ); |
| 1801 | if ( is_array( $fetch_content ) ) { |
| 1802 | foreach ( $fetch_content as $content ) { |
| 1803 | if ( 'form' === $content['name'] && $form_id === $content['id'] ) { |
| 1804 | $fields = $content['settings']['fields']; |
| 1805 | break; |
| 1806 | } |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | if ( ! empty( $fields ) ) { |
| 1811 | foreach ( $fields as $field ) { |
| 1812 | $result[] = [ |
| 1813 | 'label' => $field['label'], |
| 1814 | 'value' => '{' . strtolower( $field['label'] ) . '}', |
| 1815 | ]; |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | return [ |
| 1820 | 'options' => $result, |
| 1821 | 'hasMore' => false, |
| 1822 | ]; |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * Get fluent form fields |
| 1827 | * |
| 1828 | * @param array $data Data array. |
| 1829 | * |
| 1830 | * @return array |
| 1831 | */ |
| 1832 | public function search_pluggable_fluent_form_fields( $data ) { |
| 1833 | $result = []; |
| 1834 | $form_id = absint( $data['dynamic'] ); |
| 1835 | |
| 1836 | $fluentform_fields = Utilities::get_fluentform_fields( $data['search_term'], -1, $form_id ); |
| 1837 | |
| 1838 | if ( is_array( $fluentform_fields['results'] ) ) { |
| 1839 | foreach ( $fluentform_fields['results'] as $field ) { |
| 1840 | $result[] = [ |
| 1841 | 'label' => $field['text'], |
| 1842 | 'value' => "{{$field['value']}}", |
| 1843 | ]; |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | $result[] = [ |
| 1848 | 'value' => '{form_id}', |
| 1849 | 'label' => 'Form ID', |
| 1850 | ]; |
| 1851 | |
| 1852 | $result[] = [ |
| 1853 | 'value' => '{form_title}', |
| 1854 | 'label' => 'Form Title', |
| 1855 | ]; |
| 1856 | $result[] = [ |
| 1857 | 'value' => '{entry_id}', |
| 1858 | 'label' => 'Entry ID', |
| 1859 | ]; |
| 1860 | |
| 1861 | $result[] = [ |
| 1862 | 'value' => '{entry_source_url}', |
| 1863 | 'label' => 'Entry Source URL', |
| 1864 | ]; |
| 1865 | |
| 1866 | $result[] = [ |
| 1867 | 'value' => '{submission_date}', |
| 1868 | 'label' => 'Submission Date', |
| 1869 | ]; |
| 1870 | |
| 1871 | $result[] = [ |
| 1872 | 'value' => '{user_ip}', |
| 1873 | 'label' => 'User IP', |
| 1874 | ]; |
| 1875 | |
| 1876 | return [ |
| 1877 | 'options' => $result, |
| 1878 | 'hasMore' => false, |
| 1879 | ]; |
| 1880 | } |
| 1881 | |
| 1882 | /** |
| 1883 | * Search Gravity Form fields. |
| 1884 | * |
| 1885 | * @param array $data Search Params. |
| 1886 | * |
| 1887 | * @since 1.0.0 |
| 1888 | */ |
| 1889 | public function search_gform_fields( $data ) { |
| 1890 | if ( ! class_exists( 'RGFormsModel' ) ) { |
| 1891 | return [ |
| 1892 | 'options' => [], |
| 1893 | 'hasMore' => false, |
| 1894 | ]; |
| 1895 | } |
| 1896 | $result = []; |
| 1897 | $page = $data['page']; |
| 1898 | $form_id = absint( $data['dynamic'] ); |
| 1899 | |
| 1900 | $form = RGFormsModel::get_form_meta( $form_id ); |
| 1901 | |
| 1902 | if ( is_array( $form['fields'] ) ) { |
| 1903 | foreach ( $form['fields'] as $field ) { |
| 1904 | if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { |
| 1905 | foreach ( $field['inputs'] as $input ) { |
| 1906 | if ( ! isset( $input['isHidden'] ) || ( isset( $input['isHidden'] ) && ! $input['isHidden'] ) ) { |
| 1907 | $result[] = [ |
| 1908 | 'value' => $input['id'], |
| 1909 | 'label' => GFCommon::get_label( $field, $input['id'] ), |
| 1910 | ]; |
| 1911 | } |
| 1912 | } |
| 1913 | } elseif ( ! rgar( $field, 'displayOnly' ) ) { |
| 1914 | $result[] = [ |
| 1915 | 'value' => $field['id'], |
| 1916 | 'label' => GFCommon::get_label( $field ), |
| 1917 | ]; |
| 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | return [ |
| 1923 | 'options' => $result, |
| 1924 | 'hasMore' => false, |
| 1925 | ]; |
| 1926 | |
| 1927 | } |
| 1928 | |
| 1929 | /** |
| 1930 | * Search Gravity Form fields. |
| 1931 | * |
| 1932 | * @param array $data Search Params. |
| 1933 | * |
| 1934 | * @since 1.0.0 |
| 1935 | */ |
| 1936 | public function search_pluggable_gravity_form_fields( $data ) { |
| 1937 | if ( ! class_exists( 'RGFormsModel' ) ) { |
| 1938 | return [ |
| 1939 | 'options' => [], |
| 1940 | 'hasMore' => false, |
| 1941 | ]; |
| 1942 | } |
| 1943 | $result = []; |
| 1944 | $form_id = absint( $data['dynamic'] ); |
| 1945 | |
| 1946 | $form = RGFormsModel::get_form_meta( $form_id ); |
| 1947 | |
| 1948 | if ( is_array( $form['fields'] ) ) { |
| 1949 | foreach ( $form['fields'] as $field ) { |
| 1950 | if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { |
| 1951 | foreach ( $field['inputs'] as $input ) { |
| 1952 | if ( ! isset( $input['isHidden'] ) || ( isset( $input['isHidden'] ) && ! $input['isHidden'] ) ) { |
| 1953 | $result[] = [ |
| 1954 | 'value' => '{' . $input['id'] . '}', |
| 1955 | 'label' => GFCommon::get_label( $field, $input['id'] ), |
| 1956 | ]; |
| 1957 | } |
| 1958 | } |
| 1959 | } elseif ( ! rgar( $field, 'displayOnly' ) ) { |
| 1960 | $result[] = [ |
| 1961 | 'value' => '{' . $field['id'] . '}', |
| 1962 | 'label' => GFCommon::get_label( $field ), |
| 1963 | ]; |
| 1964 | } |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | $result[] = [ |
| 1969 | 'value' => '{gravity_form}', |
| 1970 | 'label' => 'Form ID', |
| 1971 | ]; |
| 1972 | $result[] = [ |
| 1973 | 'value' => '{form_title}', |
| 1974 | 'label' => 'Form Title', |
| 1975 | ]; |
| 1976 | $result[] = [ |
| 1977 | 'value' => '{entry_id}', |
| 1978 | 'label' => 'Entry ID', |
| 1979 | ]; |
| 1980 | $result[] = [ |
| 1981 | 'value' => '{user_ip}', |
| 1982 | 'label' => 'User IP', |
| 1983 | ]; |
| 1984 | $result[] = [ |
| 1985 | 'value' => '{entry_source_url}', |
| 1986 | 'label' => 'Entry Source URL', |
| 1987 | ]; |
| 1988 | $result[] = [ |
| 1989 | 'value' => '{entry_submission_date}', |
| 1990 | 'label' => 'Entry Submission Date', |
| 1991 | ]; |
| 1992 | |
| 1993 | return [ |
| 1994 | 'options' => $result, |
| 1995 | 'hasMore' => false, |
| 1996 | ]; |
| 1997 | |
| 1998 | } |
| 1999 | |
| 2000 | /** |
| 2001 | * Prepare fluentcrm lists. |
| 2002 | * |
| 2003 | * @param array $data Search Params. |
| 2004 | * |
| 2005 | * @return array[] |
| 2006 | */ |
| 2007 | public function search_fluentcrm_lists( $data ) { |
| 2008 | |
| 2009 | $list_api = FluentCrmApi( 'lists' ); |
| 2010 | $all_lists = $list_api->all(); |
| 2011 | $options = []; |
| 2012 | |
| 2013 | if ( ! empty( $all_lists ) ) { |
| 2014 | foreach ( $all_lists as $list ) { |
| 2015 | $options[] = [ |
| 2016 | 'label' => $list->title, |
| 2017 | 'value' => $list->id, |
| 2018 | ]; |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | return [ |
| 2023 | 'options' => $options, |
| 2024 | 'hasMore' => false, |
| 2025 | ]; |
| 2026 | } |
| 2027 | |
| 2028 | /** |
| 2029 | * Prepare fluentcrm contact status. |
| 2030 | * |
| 2031 | * @param array $data Search Params. |
| 2032 | * |
| 2033 | * @return array[] |
| 2034 | */ |
| 2035 | public function search_fluentcrm_contact_status( $data ) { |
| 2036 | |
| 2037 | $options = [ |
| 2038 | [ |
| 2039 | 'label' => __( 'Subscribed', 'suretriggers' ), |
| 2040 | 'value' => 'subscribed', |
| 2041 | ], |
| 2042 | [ |
| 2043 | 'label' => __( 'Pending', 'suretriggers' ), |
| 2044 | 'value' => 'pending', |
| 2045 | ], |
| 2046 | [ |
| 2047 | 'label' => __( 'Unsubscribed', 'suretriggers' ), |
| 2048 | 'value' => 'unsubscribed', |
| 2049 | ], |
| 2050 | [ |
| 2051 | 'label' => __( 'Bounced', 'suretriggers' ), |
| 2052 | 'value' => 'bounced', |
| 2053 | ], |
| 2054 | [ |
| 2055 | 'label' => __( 'Complained', 'suretriggers' ), |
| 2056 | 'value' => 'complained', |
| 2057 | ], |
| 2058 | ]; |
| 2059 | |
| 2060 | return [ |
| 2061 | 'options' => $options, |
| 2062 | 'hasMore' => false, |
| 2063 | ]; |
| 2064 | } |
| 2065 | |
| 2066 | /** |
| 2067 | * Prepare fluentcrm contact status. |
| 2068 | * |
| 2069 | * @param array $data Search Params. |
| 2070 | * |
| 2071 | * @return array[] |
| 2072 | */ |
| 2073 | public function search_fluentcrm_fetch_custom_fields( $data ) { |
| 2074 | |
| 2075 | $options = [ |
| 2076 | [ |
| 2077 | 'label' => __( 'Yes', 'suretriggers' ), |
| 2078 | 'value' => 'true', |
| 2079 | ], |
| 2080 | [ |
| 2081 | 'label' => __( 'No', 'suretriggers' ), |
| 2082 | 'value' => 'false', |
| 2083 | ], |
| 2084 | ]; |
| 2085 | |
| 2086 | return [ |
| 2087 | 'options' => $options, |
| 2088 | 'hasMore' => false, |
| 2089 | ]; |
| 2090 | } |
| 2091 | |
| 2092 | /** |
| 2093 | * Prepare fluentcrm tags. |
| 2094 | * |
| 2095 | * @param array $data Search Params. |
| 2096 | * |
| 2097 | * @return array[] |
| 2098 | */ |
| 2099 | public function search_fluentcrm_tags( $data ) { |
| 2100 | |
| 2101 | $tag_api = FluentCrmApi( 'tags' ); |
| 2102 | $all_tags = $tag_api->all(); |
| 2103 | $options = []; |
| 2104 | |
| 2105 | if ( ! empty( $all_tags ) ) { |
| 2106 | foreach ( $all_tags as $tag ) { |
| 2107 | $options[] = [ |
| 2108 | 'label' => $tag->title, |
| 2109 | 'value' => $tag->id, |
| 2110 | ]; |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | return [ |
| 2115 | 'options' => $options, |
| 2116 | 'hasMore' => false, |
| 2117 | ]; |
| 2118 | } |
| 2119 | |
| 2120 | /** |
| 2121 | * Prepare JetpackCRM Contact tags. |
| 2122 | * |
| 2123 | * @param array $data Search Params. |
| 2124 | * |
| 2125 | * @return array |
| 2126 | */ |
| 2127 | public function search_jetpack_crm_contact_tags( $data ) { |
| 2128 | |
| 2129 | if ( ! function_exists( 'zeroBSCRM_getCustomerTags' ) ) { |
| 2130 | return []; |
| 2131 | } |
| 2132 | |
| 2133 | $all_tags = zeroBSCRM_getCustomerTags(); |
| 2134 | $options = []; |
| 2135 | |
| 2136 | if ( ! empty( $all_tags ) ) { |
| 2137 | foreach ( $all_tags as $tag ) { |
| 2138 | $options[] = [ |
| 2139 | 'label' => $tag['name'], |
| 2140 | 'value' => $tag['id'], |
| 2141 | ]; |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | return [ |
| 2146 | 'options' => $options, |
| 2147 | 'hasMore' => false, |
| 2148 | ]; |
| 2149 | } |
| 2150 | |
| 2151 | /** |
| 2152 | * Prepare JetpackCRM Company tags. |
| 2153 | * |
| 2154 | * @param array $data Search Params. |
| 2155 | * |
| 2156 | * @return array |
| 2157 | */ |
| 2158 | public function search_jetpack_crm_company_tags( $data ) { |
| 2159 | |
| 2160 | if ( ! defined( 'ZBS_TYPE_COMPANY' ) ) { |
| 2161 | return []; |
| 2162 | } |
| 2163 | |
| 2164 | global $wpdb; |
| 2165 | $all_tags = $wpdb->get_results( $wpdb->prepare( "SELECT `ID`,`zbstag_name` FROM `{$wpdb->prefix}zbs_tags` WHERE zbstag_objtype = %d", ZBS_TYPE_COMPANY ) ); |
| 2166 | |
| 2167 | $options = []; |
| 2168 | if ( ! empty( $all_tags ) ) { |
| 2169 | foreach ( $all_tags as $tag ) { |
| 2170 | $options[] = [ |
| 2171 | 'label' => $tag->zbstag_name, |
| 2172 | 'value' => $tag->ID, |
| 2173 | ]; |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | return [ |
| 2178 | 'options' => $options, |
| 2179 | 'hasMore' => false, |
| 2180 | ]; |
| 2181 | } |
| 2182 | |
| 2183 | /** |
| 2184 | * Prepare JetpackCRM Companies list. |
| 2185 | * |
| 2186 | * @param array $data Search Params. |
| 2187 | * |
| 2188 | * @return array |
| 2189 | */ |
| 2190 | public function search_jetpack_crm_companies_list( $data ) { |
| 2191 | |
| 2192 | if ( ! function_exists( 'zeroBS_getCompanies' ) ) { |
| 2193 | return []; |
| 2194 | } |
| 2195 | |
| 2196 | $all_companies = zeroBS_getCompanies(); |
| 2197 | $options = []; |
| 2198 | |
| 2199 | if ( ! empty( $all_companies ) ) { |
| 2200 | foreach ( $all_companies as $company ) { |
| 2201 | $options[] = [ |
| 2202 | 'label' => $company['name'], |
| 2203 | 'value' => $company['id'], |
| 2204 | ]; |
| 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | return [ |
| 2209 | 'options' => $options, |
| 2210 | 'hasMore' => false, |
| 2211 | ]; |
| 2212 | } |
| 2213 | |
| 2214 | /** |
| 2215 | * Prepare JetpackCRM contact status. |
| 2216 | * |
| 2217 | * @param array $data Search Params. |
| 2218 | * |
| 2219 | * @return array |
| 2220 | */ |
| 2221 | public function search_jetpack_crm_contact_statuses( $data ) { |
| 2222 | |
| 2223 | $options = [ |
| 2224 | [ |
| 2225 | 'label' => __( 'Lead', 'suretriggers' ), |
| 2226 | 'value' => 'Lead', |
| 2227 | ], |
| 2228 | [ |
| 2229 | 'label' => __( 'Customer', 'suretriggers' ), |
| 2230 | 'value' => 'Customer', |
| 2231 | ], |
| 2232 | [ |
| 2233 | 'label' => __( 'Refused', 'suretriggers' ), |
| 2234 | 'value' => 'Refused', |
| 2235 | ], |
| 2236 | [ |
| 2237 | 'label' => __( 'Blacklisted', 'suretriggers' ), |
| 2238 | 'value' => 'Blacklisted', |
| 2239 | ], |
| 2240 | [ |
| 2241 | 'label' => __( 'Cancelled by Customer', 'suretriggers' ), |
| 2242 | 'value' => 'Cancelled by Customer', |
| 2243 | ], |
| 2244 | [ |
| 2245 | 'label' => __( 'Cancelled by Us (Pre-Quote)', 'suretriggers' ), |
| 2246 | 'value' => 'Cancelled by Us (Pre-Quote)', |
| 2247 | ], |
| 2248 | [ |
| 2249 | 'label' => __( 'Cancelled by Us (Post-Quote)', 'suretriggers' ), |
| 2250 | 'value' => 'Cancelled by Us (Post-Quote)', |
| 2251 | ], |
| 2252 | ]; |
| 2253 | |
| 2254 | return [ |
| 2255 | 'options' => $options, |
| 2256 | 'hasMore' => false, |
| 2257 | ]; |
| 2258 | } |
| 2259 | |
| 2260 | /** |
| 2261 | * Prepare FunnelKit Automations' lists. |
| 2262 | * |
| 2263 | * @param array $data Search Params. |
| 2264 | * |
| 2265 | * @return array |
| 2266 | */ |
| 2267 | public function search_funnel_kit_automations_lists( $data ) { |
| 2268 | |
| 2269 | if ( ! class_exists( 'BWFCRM_Lists' ) ) { |
| 2270 | return []; |
| 2271 | } |
| 2272 | |
| 2273 | $bwfcrm_lists = \BWFCRM_Lists::get_lists(); |
| 2274 | |
| 2275 | $options = []; |
| 2276 | |
| 2277 | foreach ( $bwfcrm_lists as $list ) { |
| 2278 | $options[] = [ |
| 2279 | 'label' => $list['name'], |
| 2280 | 'value' => $list['ID'], |
| 2281 | ]; |
| 2282 | } |
| 2283 | |
| 2284 | return [ |
| 2285 | 'options' => $options, |
| 2286 | 'hasMore' => false, |
| 2287 | ]; |
| 2288 | } |
| 2289 | |
| 2290 | /** |
| 2291 | * Prepare FunnelKit Automations' tags. |
| 2292 | * |
| 2293 | * @param array $data Search Params. |
| 2294 | * |
| 2295 | * @return array |
| 2296 | */ |
| 2297 | public function search_funnel_kit_automations_tags( $data ) { |
| 2298 | |
| 2299 | if ( ! class_exists( 'BWFCRM_Tag' ) ) { |
| 2300 | return []; |
| 2301 | } |
| 2302 | |
| 2303 | $bwfcrm_tags = \BWFCRM_Tag::get_tags(); |
| 2304 | |
| 2305 | $options = []; |
| 2306 | |
| 2307 | foreach ( $bwfcrm_tags as $tag ) { |
| 2308 | $options[] = [ |
| 2309 | 'label' => $tag['name'], |
| 2310 | 'value' => $tag['ID'], |
| 2311 | ]; |
| 2312 | } |
| 2313 | |
| 2314 | return [ |
| 2315 | 'options' => $options, |
| 2316 | 'hasMore' => false, |
| 2317 | ]; |
| 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * Prepare Wishlist Memberlists level. |
| 2322 | * |
| 2323 | * @param array $data Search Params. |
| 2324 | * |
| 2325 | * @return array[] |
| 2326 | */ |
| 2327 | public function search_wishlistmember_lists( $data ) { |
| 2328 | |
| 2329 | $wlm_levels = wlmapi_get_levels(); |
| 2330 | $options = []; |
| 2331 | |
| 2332 | if ( ! empty( $wlm_levels ) ) { |
| 2333 | foreach ( $wlm_levels['levels']['level'] as $list ) { |
| 2334 | $options[] = [ |
| 2335 | 'label' => $list['name'], |
| 2336 | 'value' => (string) $list['id'], |
| 2337 | ]; |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | return [ |
| 2342 | 'options' => $options, |
| 2343 | 'hasMore' => false, |
| 2344 | ]; |
| 2345 | } |
| 2346 | |
| 2347 | /** |
| 2348 | * Prepare elementor popups. |
| 2349 | * |
| 2350 | * @param array $data Search Params. |
| 2351 | * |
| 2352 | * @return array[] |
| 2353 | */ |
| 2354 | public function search_elementor_popups( $data ) { |
| 2355 | |
| 2356 | $posts = get_posts( |
| 2357 | [ |
| 2358 | 'post_type' => 'elementor_library', |
| 2359 | 'orderby' => 'title', |
| 2360 | 'order' => 'ASC', |
| 2361 | 'post_status' => 'publish', |
| 2362 | 'meta_query' => [ |
| 2363 | [ |
| 2364 | 'key' => '_elementor_template_type', |
| 2365 | 'value' => 'popup', |
| 2366 | 'compare' => '=', |
| 2367 | ], |
| 2368 | ], |
| 2369 | ] |
| 2370 | ); |
| 2371 | |
| 2372 | $options = []; |
| 2373 | if ( ! empty( $posts ) ) { |
| 2374 | foreach ( $posts as $post ) { |
| 2375 | $options[] = [ |
| 2376 | 'label' => $post->post_title, |
| 2377 | 'value' => $post->ID, |
| 2378 | ]; |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | return [ |
| 2383 | 'options' => $options, |
| 2384 | 'hasMore' => false, |
| 2385 | ]; |
| 2386 | } |
| 2387 | |
| 2388 | /** |
| 2389 | * Prepare givewp forms. |
| 2390 | * |
| 2391 | * @param array $data Search Params. |
| 2392 | * |
| 2393 | * @return array[] |
| 2394 | */ |
| 2395 | public function search_givewp_forms( $data ) { |
| 2396 | |
| 2397 | $posts = get_posts( |
| 2398 | [ |
| 2399 | 'post_type' => 'give_forms', |
| 2400 | 'orderby' => 'title', |
| 2401 | 'order' => 'ASC', |
| 2402 | 'post_status' => 'publish', |
| 2403 | ] |
| 2404 | ); |
| 2405 | |
| 2406 | $options = []; |
| 2407 | if ( ! empty( $posts ) ) { |
| 2408 | foreach ( $posts as $post ) { |
| 2409 | $options[] = [ |
| 2410 | 'label' => $post->post_title, |
| 2411 | 'value' => $post->ID, |
| 2412 | ]; |
| 2413 | } |
| 2414 | } |
| 2415 | |
| 2416 | return [ |
| 2417 | 'options' => $options, |
| 2418 | 'hasMore' => false, |
| 2419 | ]; |
| 2420 | } |
| 2421 | |
| 2422 | /** |
| 2423 | * Prepare buddyboss group users. |
| 2424 | * |
| 2425 | * @param array $data Search Params. |
| 2426 | * |
| 2427 | * @return array[] |
| 2428 | */ |
| 2429 | public function search_bb_group_users( $data ) { |
| 2430 | $options = []; |
| 2431 | |
| 2432 | $group_id = $data['dynamic']; |
| 2433 | $admins = groups_get_group_admins( $group_id ); |
| 2434 | |
| 2435 | if ( ! empty( $admins ) ) { |
| 2436 | foreach ( $admins as $admin ) { |
| 2437 | $admin_user = get_user_by( 'id', $admin->user_id ); |
| 2438 | $options[] = [ |
| 2439 | 'label' => $admin_user->display_name, |
| 2440 | 'value' => $admin_user->ID, |
| 2441 | ]; |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | $members = groups_get_group_members( [ 'group_id' => $group_id ] ); |
| 2446 | |
| 2447 | if ( isset( $members['members'] ) && ! empty( $members['members'] ) ) { |
| 2448 | foreach ( $members['members'] as $member ) { |
| 2449 | $options[] = [ |
| 2450 | 'label' => $member->display_name, |
| 2451 | 'value' => $member->ID, |
| 2452 | ]; |
| 2453 | } |
| 2454 | } |
| 2455 | return [ |
| 2456 | 'options' => $options, |
| 2457 | 'hasMore' => false, |
| 2458 | ]; |
| 2459 | } |
| 2460 | |
| 2461 | /** |
| 2462 | * Prepare buddyboss groups. |
| 2463 | * |
| 2464 | * @param array $data Search Params. |
| 2465 | * |
| 2466 | * @return array[] |
| 2467 | */ |
| 2468 | public function search_buddyboss_groups( $data ) { |
| 2469 | global $wpdb; |
| 2470 | |
| 2471 | $options = []; |
| 2472 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups" ); |
| 2473 | if ( ! empty( $groups ) ) { |
| 2474 | foreach ( $groups as $group ) { |
| 2475 | $options[] = [ |
| 2476 | 'label' => $group->name, |
| 2477 | 'value' => $group->id, |
| 2478 | ]; |
| 2479 | } |
| 2480 | } |
| 2481 | return [ |
| 2482 | 'options' => $options, |
| 2483 | 'hasMore' => false, |
| 2484 | ]; |
| 2485 | } |
| 2486 | |
| 2487 | /** |
| 2488 | * Prepare buddyboss public groups. |
| 2489 | * |
| 2490 | * @param array $data Search Params. |
| 2491 | * |
| 2492 | * @return array[] |
| 2493 | */ |
| 2494 | public function search_buddyboss_public_groups( $data ) { |
| 2495 | $options = []; |
| 2496 | $groups = groups_get_groups(); |
| 2497 | if ( isset( $groups['groups'] ) && ! empty( $groups['groups'] ) ) { |
| 2498 | foreach ( $groups['groups'] as $group ) { |
| 2499 | if ( 'public' === $group->status ) { |
| 2500 | $options[] = [ |
| 2501 | 'label' => $group->name, |
| 2502 | 'value' => $group->id, |
| 2503 | ]; |
| 2504 | } |
| 2505 | } |
| 2506 | } |
| 2507 | return [ |
| 2508 | 'options' => $options, |
| 2509 | 'hasMore' => false, |
| 2510 | ]; |
| 2511 | } |
| 2512 | |
| 2513 | /** |
| 2514 | * Prepare buddyboss profile types list. |
| 2515 | * |
| 2516 | * @param array $data Search Params. |
| 2517 | * |
| 2518 | * @return array[] |
| 2519 | */ |
| 2520 | public function search_bb_profile_type_list( $data ) { |
| 2521 | $options = []; |
| 2522 | |
| 2523 | if ( function_exists( 'bp_get_active_member_types' ) ) { |
| 2524 | $types = bp_get_active_member_types( |
| 2525 | [ |
| 2526 | 'fields' => '*', |
| 2527 | ] |
| 2528 | ); |
| 2529 | if ( $types ) { |
| 2530 | foreach ( $types as $type ) { |
| 2531 | $options[] = [ |
| 2532 | 'label' => $type->post_title, |
| 2533 | 'value' => $type->ID, |
| 2534 | ]; |
| 2535 | } |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | /** |
| 2540 | * |
| 2541 | * Ignore line |
| 2542 | * |
| 2543 | * @phpstan-ignore-next-line |
| 2544 | */ |
| 2545 | return [ |
| 2546 | 'options' => $options, |
| 2547 | 'hasMore' => false, |
| 2548 | ]; |
| 2549 | } |
| 2550 | |
| 2551 | /** |
| 2552 | * Prepare elementor forms. |
| 2553 | * |
| 2554 | * @param array $data Search Params. |
| 2555 | * |
| 2556 | * @return array[] |
| 2557 | */ |
| 2558 | public function search_elementor_forms( $data ) { |
| 2559 | |
| 2560 | $elementor_forms = Utilities::get_elementor_forms(); |
| 2561 | |
| 2562 | $options = []; |
| 2563 | if ( ! empty( $elementor_forms ) ) { |
| 2564 | foreach ( $elementor_forms as $key => $value ) { |
| 2565 | $options[] = [ |
| 2566 | 'label' => $value, |
| 2567 | 'value' => $key, |
| 2568 | ]; |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | return [ |
| 2573 | 'options' => $options, |
| 2574 | 'hasMore' => false, |
| 2575 | ]; |
| 2576 | } |
| 2577 | |
| 2578 | /** |
| 2579 | * Prepare elementor forms. |
| 2580 | * |
| 2581 | * @param array $data Search Params. |
| 2582 | * |
| 2583 | * @return array[] |
| 2584 | */ |
| 2585 | public function search_new_elementor_forms( $data ) { |
| 2586 | |
| 2587 | global $wpdb; |
| 2588 | $elementor_forms = []; |
| 2589 | $post_metas = $wpdb->get_results( |
| 2590 | $wpdb->prepare( |
| 2591 | "SELECT pm.post_id, pm.meta_value |
| 2592 | FROM $wpdb->postmeta pm |
| 2593 | LEFT JOIN $wpdb->posts p |
| 2594 | ON p.ID = pm.post_id |
| 2595 | WHERE p.post_type IS NOT NULL |
| 2596 | AND p.post_status = %s |
| 2597 | AND pm.meta_key = %s |
| 2598 | AND pm.`meta_value` LIKE %s", |
| 2599 | 'publish', |
| 2600 | '_elementor_data', |
| 2601 | '%%form_fields%%' |
| 2602 | ) |
| 2603 | ); |
| 2604 | |
| 2605 | if ( ! empty( $post_metas ) ) { |
| 2606 | foreach ( $post_metas as $post_meta ) { |
| 2607 | /** |
| 2608 | * |
| 2609 | * Ignore line |
| 2610 | * |
| 2611 | * @phpstan-ignore-next-line |
| 2612 | */ |
| 2613 | $inner_forms = Utilities::search_elementor_forms( json_decode( $post_meta->meta_value ) ); |
| 2614 | if ( ! empty( $inner_forms ) ) { |
| 2615 | foreach ( $inner_forms as $form ) { |
| 2616 | /** |
| 2617 | * |
| 2618 | * Ignore line |
| 2619 | * |
| 2620 | * @phpstan-ignore-next-line |
| 2621 | */ |
| 2622 | $elementor_forms[ $post_meta->post_id . '_' . $form->id ] = $form->settings->form_name . ' (' . $form->id . ')'; |
| 2623 | } |
| 2624 | } |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | $options = []; |
| 2629 | if ( ! empty( $elementor_forms ) ) { |
| 2630 | foreach ( $elementor_forms as $key => $value ) { |
| 2631 | $options[] = [ |
| 2632 | 'label' => $value, |
| 2633 | 'value' => $key, |
| 2634 | ]; |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | /** |
| 2639 | * |
| 2640 | * Ignore line |
| 2641 | * |
| 2642 | * @phpstan-ignore-next-line |
| 2643 | */ |
| 2644 | return [ |
| 2645 | 'options' => $options, |
| 2646 | 'hasMore' => false, |
| 2647 | ]; |
| 2648 | } |
| 2649 | |
| 2650 | /** |
| 2651 | * Prepare elementor form fields. |
| 2652 | * |
| 2653 | * @param array $data Search Params. |
| 2654 | * |
| 2655 | * @return array[] |
| 2656 | */ |
| 2657 | public function search_pluggable_elementor_form_fields( $data ) { |
| 2658 | $result = []; |
| 2659 | $form_id = absint( $data['dynamic'] ); |
| 2660 | $elementor_form_fields = ( new Utilities() )->get_elementor_form_fields( $data ); |
| 2661 | $options = []; |
| 2662 | if ( ! empty( $elementor_form_fields ) ) { |
| 2663 | foreach ( $elementor_form_fields as $key => $value ) { |
| 2664 | $options[] = [ |
| 2665 | 'label' => $value, |
| 2666 | 'value' => '{' . $key . '}', |
| 2667 | ]; |
| 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | return [ |
| 2672 | 'options' => $options, |
| 2673 | 'hasMore' => false, |
| 2674 | ]; |
| 2675 | } |
| 2676 | |
| 2677 | /** |
| 2678 | * Get all events |
| 2679 | * |
| 2680 | * @param array $data Data array. |
| 2681 | * |
| 2682 | * @return array |
| 2683 | */ |
| 2684 | public function search_event_calendar_event( $data ) { |
| 2685 | $page = $data['page']; |
| 2686 | $limit = Utilities::get_search_page_limit(); |
| 2687 | $offset = $limit * ( $page - 1 ); |
| 2688 | |
| 2689 | $posts = get_posts( |
| 2690 | [ |
| 2691 | 'post_type' => 'tribe_events', |
| 2692 | 'orderby' => 'title', |
| 2693 | 'order' => 'ASC', |
| 2694 | 'post_status' => 'publish', |
| 2695 | 'posts_per_page' => $limit, |
| 2696 | 'offset' => $offset, |
| 2697 | ] |
| 2698 | ); |
| 2699 | |
| 2700 | $options = []; |
| 2701 | if ( ! empty( $posts ) ) { |
| 2702 | foreach ( $posts as $post ) { |
| 2703 | $options[] = [ |
| 2704 | 'label' => $post->post_title, |
| 2705 | 'value' => $post->ID, |
| 2706 | ]; |
| 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | $count = count( $options ); |
| 2711 | |
| 2712 | return [ |
| 2713 | 'options' => $options, |
| 2714 | 'hasMore' => $count > $limit && $count > $offset, |
| 2715 | ]; |
| 2716 | } |
| 2717 | |
| 2718 | /** |
| 2719 | * Prepare rsvp event calendar events. |
| 2720 | * |
| 2721 | * @param array $data Search Params. |
| 2722 | * |
| 2723 | * @return array[] |
| 2724 | */ |
| 2725 | public function search_event_calendar_rsvp_event( $data ) { |
| 2726 | |
| 2727 | $posts = get_posts( |
| 2728 | [ |
| 2729 | 'post_type' => 'tribe_events', |
| 2730 | 'orderby' => 'title', |
| 2731 | 'order' => 'ASC', |
| 2732 | 'post_status' => 'publish', |
| 2733 | ] |
| 2734 | ); |
| 2735 | |
| 2736 | $options = []; |
| 2737 | if ( ! empty( $posts ) ) { |
| 2738 | $ticket_handler = new Tribe__Tickets__Tickets_Handler(); |
| 2739 | foreach ( $posts as $post ) { |
| 2740 | |
| 2741 | $get_rsvp_ticket = $ticket_handler->get_event_rsvp_tickets( $post->ID ); |
| 2742 | |
| 2743 | if ( ! empty( $get_rsvp_ticket ) ) { |
| 2744 | $options[] = [ |
| 2745 | 'label' => $post->post_title, |
| 2746 | 'value' => $post->ID, |
| 2747 | ]; |
| 2748 | } |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | return [ |
| 2753 | 'options' => $options, |
| 2754 | 'hasMore' => false, |
| 2755 | ]; |
| 2756 | } |
| 2757 | |
| 2758 | /** |
| 2759 | * Prepare Restrict Content Membership Level. |
| 2760 | * |
| 2761 | * @param array $data Search Params. |
| 2762 | * |
| 2763 | * @return array[] |
| 2764 | */ |
| 2765 | public function search_restrictcontent_membership_level( $data ) { |
| 2766 | |
| 2767 | $rcp_memberships = rcp_get_membership_levels(); |
| 2768 | $options = []; |
| 2769 | |
| 2770 | if ( ! empty( $rcp_memberships ) ) { |
| 2771 | foreach ( $rcp_memberships as $list ) { |
| 2772 | $options[] = [ |
| 2773 | 'label' => ucfirst( $list->name ), |
| 2774 | 'value' => $list->id, |
| 2775 | ]; |
| 2776 | } |
| 2777 | } |
| 2778 | |
| 2779 | return [ |
| 2780 | 'options' => $options, |
| 2781 | 'hasMore' => false, |
| 2782 | ]; |
| 2783 | } |
| 2784 | |
| 2785 | /** |
| 2786 | * Prepare Restrict Content Customer. |
| 2787 | * |
| 2788 | * @param array $data Search Params. |
| 2789 | * |
| 2790 | * @return array[] |
| 2791 | */ |
| 2792 | public function search_restrictcontent_customer( $data ) { |
| 2793 | |
| 2794 | $rcp_users = rcp_get_memberships(); |
| 2795 | $options = []; |
| 2796 | |
| 2797 | if ( ! empty( $rcp_users ) ) { |
| 2798 | foreach ( $rcp_users as $list ) { |
| 2799 | $user = get_user_by( 'ID', $list->get_user_id() ); |
| 2800 | $user_label = $user->user_email; |
| 2801 | |
| 2802 | if ( $user->display_name !== $user->user_email ) { |
| 2803 | $user_label .= ' (' . $user->display_name . ')'; |
| 2804 | } |
| 2805 | |
| 2806 | $options[] = [ |
| 2807 | 'label' => $user_label, |
| 2808 | 'value' => $list->get_customer_id(), |
| 2809 | ]; |
| 2810 | } |
| 2811 | } |
| 2812 | |
| 2813 | return [ |
| 2814 | 'options' => $options, |
| 2815 | 'hasMore' => false, |
| 2816 | ]; |
| 2817 | } |
| 2818 | |
| 2819 | |
| 2820 | /** |
| 2821 | * Fetch the Presto Player video List. |
| 2822 | * |
| 2823 | * @param array $data Search Params. |
| 2824 | * |
| 2825 | * @return array[] |
| 2826 | */ |
| 2827 | public function search_ap_presto_player_video_list( $data ) { |
| 2828 | |
| 2829 | $videos = ( new Video() )->all(); |
| 2830 | $options = []; |
| 2831 | if ( ! empty( $videos ) ) { |
| 2832 | foreach ( $videos as $video ) { |
| 2833 | $options[] = [ |
| 2834 | 'label' => $video->__get( 'title' ), |
| 2835 | 'value' => (string) $video->__get( 'id' ), |
| 2836 | ]; |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | return [ |
| 2841 | 'options' => $options, |
| 2842 | 'hasMore' => false, |
| 2843 | ]; |
| 2844 | } |
| 2845 | |
| 2846 | /** |
| 2847 | * Presto Player Video percentage. |
| 2848 | * |
| 2849 | * @param array $data Search Params. |
| 2850 | * |
| 2851 | * @return array[] |
| 2852 | */ |
| 2853 | public function search_prestoplayer_video_percent( $data ) { |
| 2854 | |
| 2855 | $percents = [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]; |
| 2856 | $options = []; |
| 2857 | |
| 2858 | foreach ( $percents as $percent ) { |
| 2859 | $options[] = [ |
| 2860 | 'label' => $percent . '%', |
| 2861 | 'value' => (string) $percent, |
| 2862 | ]; |
| 2863 | } |
| 2864 | |
| 2865 | return [ |
| 2866 | 'options' => $options, |
| 2867 | 'hasMore' => false, |
| 2868 | ]; |
| 2869 | } |
| 2870 | |
| 2871 | /** |
| 2872 | * Get user profile field options. |
| 2873 | * |
| 2874 | * @return array |
| 2875 | * @since 1.0.0 |
| 2876 | */ |
| 2877 | public function search_user_field_options() { |
| 2878 | |
| 2879 | $options = apply_filters( |
| 2880 | 'sure_trigger_get_user_field_options', |
| 2881 | [ |
| 2882 | [ |
| 2883 | 'label' => __( 'User Name', 'suretriggers' ), |
| 2884 | 'value' => 'user_login', |
| 2885 | ], |
| 2886 | [ |
| 2887 | 'label' => __( 'User Email', 'suretriggers' ), |
| 2888 | 'value' => 'user_email', |
| 2889 | ], |
| 2890 | [ |
| 2891 | 'label' => __( 'Display Name', 'suretriggers' ), |
| 2892 | 'value' => 'display_name', |
| 2893 | ], |
| 2894 | [ |
| 2895 | 'label' => __( 'User Password', 'suretriggers' ), |
| 2896 | 'value' => 'user_pass', |
| 2897 | ], |
| 2898 | [ |
| 2899 | 'label' => __( 'Website', 'suretriggers' ), |
| 2900 | 'value' => 'user_url', |
| 2901 | ], |
| 2902 | ] |
| 2903 | ); |
| 2904 | |
| 2905 | return [ |
| 2906 | 'options' => $options, |
| 2907 | 'hasMore' => false, |
| 2908 | ]; |
| 2909 | } |
| 2910 | |
| 2911 | /** |
| 2912 | * Get user post field options. |
| 2913 | * |
| 2914 | * @return array |
| 2915 | * @since 1.0.0 |
| 2916 | */ |
| 2917 | public function search_post_field_options() { |
| 2918 | |
| 2919 | return [ |
| 2920 | 'options' => [ |
| 2921 | [ |
| 2922 | 'label' => __( 'Type', 'suretriggers' ), |
| 2923 | 'value' => 'post_type', |
| 2924 | 'dynamic_field' => [ |
| 2925 | 'type' => 'select-creatable', |
| 2926 | 'ajaxIdentifier' => 'post_types', |
| 2927 | ], |
| 2928 | ], |
| 2929 | [ |
| 2930 | 'label' => __( 'Status', 'suretriggers' ), |
| 2931 | 'value' => 'post_status', |
| 2932 | 'dynamic_field' => [ |
| 2933 | 'type' => 'select-async', |
| 2934 | 'ajaxIdentifier' => 'post_statuses', |
| 2935 | ], |
| 2936 | ], |
| 2937 | [ |
| 2938 | 'label' => __( 'Author', 'suretriggers' ), |
| 2939 | 'value' => 'post_author', |
| 2940 | 'dynamic_field' => [ |
| 2941 | 'type' => 'select-async', |
| 2942 | 'ajaxIdentifier' => 'user', |
| 2943 | ], |
| 2944 | ], |
| 2945 | [ |
| 2946 | 'label' => __( 'Title', 'suretriggers' ), |
| 2947 | 'value' => 'post_title', |
| 2948 | 'dynamic_field' => [ |
| 2949 | 'type' => 'select-creatable', |
| 2950 | ], |
| 2951 | ], |
| 2952 | [ |
| 2953 | 'label' => __( 'Slug', 'suretriggers' ), |
| 2954 | 'value' => 'post_slug', |
| 2955 | 'dynamic_field' => [ |
| 2956 | 'type' => 'select-creatable', |
| 2957 | ], |
| 2958 | ], |
| 2959 | [ |
| 2960 | 'label' => __( 'Content', 'suretriggers' ), |
| 2961 | 'value' => 'post_content', |
| 2962 | 'dynamic_field' => [ |
| 2963 | 'type' => 'html-editor', |
| 2964 | ], |
| 2965 | ], |
| 2966 | ], |
| 2967 | 'hasMore' => false, |
| 2968 | ]; |
| 2969 | } |
| 2970 | |
| 2971 | /** |
| 2972 | * Bricksbuilder grouped data. |
| 2973 | * |
| 2974 | * @param array $data data. |
| 2975 | * @return array |
| 2976 | */ |
| 2977 | public function search_bb_groups( $data ) { |
| 2978 | |
| 2979 | global $wpdb; |
| 2980 | $options = []; |
| 2981 | |
| 2982 | if ( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'bp_groups' ) ) ) { |
| 2983 | |
| 2984 | $results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s', $wpdb->prefix . 'bp_groups' ) ); |
| 2985 | |
| 2986 | if ( $results ) { |
| 2987 | foreach ( $results as $result ) { |
| 2988 | $options[] = [ |
| 2989 | 'label' => $result->name, |
| 2990 | 'value' => $result->id, |
| 2991 | ]; |
| 2992 | } |
| 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | return [ |
| 2997 | 'options' => $options, |
| 2998 | 'hasMore' => false, |
| 2999 | ]; |
| 3000 | } |
| 3001 | |
| 3002 | /** |
| 3003 | * Search forms. |
| 3004 | * |
| 3005 | * @return array |
| 3006 | */ |
| 3007 | public function search_bb_forums() { |
| 3008 | $options = []; |
| 3009 | $allowed_atatus = [ 'publish', 'private' ]; |
| 3010 | $forum_args = [ |
| 3011 | 'post_type' => bbp_get_forum_post_type(), |
| 3012 | 'posts_per_page' => -1, |
| 3013 | 'orderby' => 'title', |
| 3014 | 'order' => 'ASC', |
| 3015 | 'post_status' => 'any', |
| 3016 | ]; |
| 3017 | $forums = get_posts( $forum_args ); |
| 3018 | |
| 3019 | if ( ! empty( $forums ) ) { |
| 3020 | foreach ( $forums as $forum ) { |
| 3021 | if ( in_array( $forum->post_status, $allowed_atatus, true ) ) { |
| 3022 | $options[] = [ |
| 3023 | 'label' => $forum->post_title, |
| 3024 | 'value' => $forum->ID, |
| 3025 | ]; |
| 3026 | } |
| 3027 | } |
| 3028 | } |
| 3029 | return [ |
| 3030 | 'options' => $options, |
| 3031 | 'hasMore' => false, |
| 3032 | ]; |
| 3033 | } |
| 3034 | |
| 3035 | /** |
| 3036 | * Get last data for trigger. |
| 3037 | * |
| 3038 | * @param array $data data. |
| 3039 | * @return array |
| 3040 | */ |
| 3041 | public function search_affiliate_wp_triggers_last_data( $data ) { |
| 3042 | global $wpdb; |
| 3043 | |
| 3044 | $context = []; |
| 3045 | $context['response_type'] = 'sample'; |
| 3046 | |
| 3047 | $user_data = WordPress::get_sample_user_context(); |
| 3048 | |
| 3049 | $affiliate_data = [ |
| 3050 | 'affiliate_id' => 1, |
| 3051 | 'rest_id' => '', |
| 3052 | 'user_id' => 1, |
| 3053 | 'rate' => '', |
| 3054 | 'rate_type' => '', |
| 3055 | 'flat_rate_basis' => '', |
| 3056 | 'payment_email' => 'admin@bsf.io', |
| 3057 | 'status' => 'active', |
| 3058 | 'earnings' => 0, |
| 3059 | 'unpaid_earnings' => 0, |
| 3060 | 'referrals' => 0, |
| 3061 | 'visits' => 0, |
| 3062 | 'date_registered' => '2023-01-18 13:35:22', |
| 3063 | 'dynamic_coupon' => 'KDJSKS', |
| 3064 | ]; |
| 3065 | |
| 3066 | $referral_data = [ |
| 3067 | 'referral_id' => 1, |
| 3068 | 'affiliate_id' => 1, |
| 3069 | 'visit_id' => 0, |
| 3070 | 'rest_id' => '', |
| 3071 | 'customer_id' => 0, |
| 3072 | 'parent_id' => 0, |
| 3073 | 'description' => 'Testing', |
| 3074 | 'status' => 'unpaid', |
| 3075 | 'amount' => '12.00', |
| 3076 | 'currency' => '', |
| 3077 | 'custom' => 'custom', |
| 3078 | 'context' => '', |
| 3079 | 'campaign' => '', |
| 3080 | 'reference' => 'Reference', |
| 3081 | 'products' => '', |
| 3082 | 'date' => '2023-01-18 16:36:59', |
| 3083 | 'type' => 'opt-in', |
| 3084 | 'payout_id' => 0, |
| 3085 | ]; |
| 3086 | |
| 3087 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3088 | |
| 3089 | if ( in_array( $term, [ 'affiliate_approved', 'affiliate_awaiting_approval' ], true ) ) { |
| 3090 | $status = 'affiliate_approved' === $term ? 'active' : 'pending'; |
| 3091 | $affiliate = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_affiliates WHERE affiliate_id = ( SELECT max(affiliate_id) FROM {$wpdb->prefix}affiliate_wp_affiliates )" ); |
| 3092 | |
| 3093 | if ( ! empty( $affiliate ) ) { |
| 3094 | $affiliate = affwp_get_affiliate( $affiliate->affiliate_id ); |
| 3095 | $affiliate_data = get_object_vars( $affiliate ); |
| 3096 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 3097 | $context['response_type'] = 'live'; |
| 3098 | } |
| 3099 | $affiliate_data['status'] = $status; |
| 3100 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data ); |
| 3101 | |
| 3102 | } else { |
| 3103 | $referral = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}affiliate_wp_referrals WHERE referral_id = ( SELECT max(referral_id) FROM {$wpdb->prefix}affiliate_wp_referrals )" ); |
| 3104 | |
| 3105 | if ( ! empty( $referral ) ) { |
| 3106 | $referral = affwp_get_referral( $referral->referral_id ); |
| 3107 | $affiliate = affwp_get_affiliate( $referral->affiliate_id ); |
| 3108 | $affiliate_data = get_object_vars( $affiliate ); |
| 3109 | $user_data = WordPress::get_user_context( $affiliate->user_id ); |
| 3110 | $referral_data = get_object_vars( $referral ); |
| 3111 | $context['response_type'] = 'live'; |
| 3112 | } |
| 3113 | $context['pluggable_data'] = array_merge( $user_data, $affiliate_data, $referral_data ); |
| 3114 | } |
| 3115 | |
| 3116 | return $context; |
| 3117 | } |
| 3118 | |
| 3119 | /** |
| 3120 | * Get last data for trigger. |
| 3121 | * |
| 3122 | * @param array $data data. |
| 3123 | * @return array |
| 3124 | */ |
| 3125 | public function search_jetpack_crm_triggers_last_data( $data ) { |
| 3126 | |
| 3127 | if ( ! function_exists( 'zeroBS_getCompanyCount' ) || ! function_exists( 'zeroBS_getCustomerCount' ) || ! function_exists( 'zeroBS_getQuoteCount' ) ) { |
| 3128 | return []; |
| 3129 | } |
| 3130 | |
| 3131 | global $wpdb; |
| 3132 | |
| 3133 | $context = []; |
| 3134 | $context['response_type'] = 'sample'; |
| 3135 | |
| 3136 | $company_id = [ 'company_id' => 1 ]; |
| 3137 | $contact_id = [ 'contact_id' => 1 ]; |
| 3138 | $quote_id = [ 'quote_id' => 1 ]; |
| 3139 | $event_id = [ 'event_id' => 1 ]; |
| 3140 | $invoice_id = [ 'invoice_id' => 1 ]; |
| 3141 | $transaction_id = [ 'transaction_id' => 1 ]; |
| 3142 | |
| 3143 | $company = [ |
| 3144 | 'company_id' => 1, |
| 3145 | 'company_status' => 'Lead', |
| 3146 | 'company_name' => 'Example Company', |
| 3147 | 'company_email' => 'info@example.com', |
| 3148 | 'main_address_line_1' => '123 Main Street', |
| 3149 | 'main_address_line_2' => 'Suite 456', |
| 3150 | 'main_address_city' => 'New York', |
| 3151 | 'main_address_state' => 'NY', |
| 3152 | 'main_address_postal_code' => '10001', |
| 3153 | 'main_address_country' => 'United States', |
| 3154 | 'second_address_line_1' => '789 Second Avenue', |
| 3155 | 'second_address_line_2' => 'Floor 10', |
| 3156 | 'second_address_city' => 'Los Angeles', |
| 3157 | 'second_address_state' => 'CA', |
| 3158 | 'second_address_postal_code' => '90001', |
| 3159 | 'second_address_country' => 'United States', |
| 3160 | 'main_telephone' => '+1 123-456-7890', |
| 3161 | 'secondary_telephone' => '+1 987-654-3210', |
| 3162 | ]; |
| 3163 | |
| 3164 | $contact = [ |
| 3165 | 'contact_id' => 1, |
| 3166 | 'status' => 'Lead', |
| 3167 | 'prefix' => 'Mr.', |
| 3168 | 'full_name' => 'John Doe', |
| 3169 | 'first_name' => 'John', |
| 3170 | 'last_name' => 'Doe', |
| 3171 | 'email' => 'johndoe@example.com', |
| 3172 | 'main_address_line_1' => '123 Main Street', |
| 3173 | 'main_address_line_2' => 'Suite 456', |
| 3174 | 'main_address_city' => 'New York', |
| 3175 | 'main_address_state' => 'NY', |
| 3176 | 'main_address_postal_code' => '10001', |
| 3177 | 'main_address_country' => 'United States', |
| 3178 | 'second_address_line_1' => '789 Second Avenue', |
| 3179 | 'second_address_line_2' => 'Floor 10', |
| 3180 | 'second_address_city' => 'Los Angeles', |
| 3181 | 'second_address_state' => 'CA', |
| 3182 | 'second_address_postal_code' => '90001', |
| 3183 | 'second_address_country' => 'United States', |
| 3184 | 'home_telephone' => '+1 123-456-7890', |
| 3185 | 'work_telephone' => '+1 987-654-3210', |
| 3186 | 'mobile_telephone' => '+1 555-555-5555', |
| 3187 | ]; |
| 3188 | |
| 3189 | $quote = [ |
| 3190 | 'quote_id' => 1, |
| 3191 | 'contact_id' => 2, |
| 3192 | 'contact_email' => 'john@example.com', |
| 3193 | 'contact_name' => 'John Doe', |
| 3194 | 'status' => '<strong>Created, not yet accepted</strong>', |
| 3195 | 'title' => 'Sample Quote', |
| 3196 | 'value' => 1000, |
| 3197 | 'date' => '2023-05-23', |
| 3198 | 'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', |
| 3199 | 'notes' => 'Additional notes about the quote.', |
| 3200 | ]; |
| 3201 | |
| 3202 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3203 | |
| 3204 | switch ( $term ) { |
| 3205 | case 'company_created': |
| 3206 | if ( zeroBS_getCompanyCount() > 0 ) { |
| 3207 | $company_data = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}zbs_companies WHERE ID = ( SELECT max(ID) FROM {$wpdb->prefix}zbs_companies )" ); |
| 3208 | $company = JetpackCRM::get_company_context( $company_data->ID ); |
| 3209 | $context['response_type'] = 'live'; |
| 3210 | } |
| 3211 | $context['pluggable_data'] = $company; |
| 3212 | break; |
| 3213 | case 'company_deleted': |
| 3214 | $context['pluggable_data'] = $company_id; |
| 3215 | break; |
| 3216 | case 'contact_created': |
| 3217 | if ( zeroBS_getCustomerCount() > 0 ) { |
| 3218 | $contact_data = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}zbs_contacts WHERE ID = ( SELECT max(ID) FROM {$wpdb->prefix}zbs_contacts )" ); |
| 3219 | $contact = JetpackCRM::get_contact_context( $contact_data->ID ); |
| 3220 | $context['response_type'] = 'live'; |
| 3221 | } |
| 3222 | $context['pluggable_data'] = $contact; |
| 3223 | break; |
| 3224 | case 'contact_deleted': |
| 3225 | $context['pluggable_data'] = $contact_id; |
| 3226 | break; |
| 3227 | case 'event_deleted': |
| 3228 | $context['pluggable_data'] = $event_id; |
| 3229 | break; |
| 3230 | case 'invoice_deleted': |
| 3231 | $context['pluggable_data'] = $invoice_id; |
| 3232 | break; |
| 3233 | case 'quote_accepted': |
| 3234 | case 'quote_created': |
| 3235 | if ( zeroBS_getQuoteCount() > 0 ) { |
| 3236 | $quote_data = $wpdb->get_row( "SELECT ID FROM {$wpdb->prefix}zbs_quotes WHERE ID = ( SELECT max(ID) FROM {$wpdb->prefix}zbs_quotes )" ); |
| 3237 | $quote = JetpackCRM::get_quote_context( $quote_data->ID ); |
| 3238 | $context['response_type'] = 'live'; |
| 3239 | } |
| 3240 | $context['pluggable_data'] = $quote; |
| 3241 | break; |
| 3242 | case 'quote_deleted': |
| 3243 | $context['pluggable_data'] = $quote_id; |
| 3244 | break; |
| 3245 | case 'transaction_deleted': |
| 3246 | $context['pluggable_data'] = $transaction_id; |
| 3247 | break; |
| 3248 | } |
| 3249 | |
| 3250 | return $context; |
| 3251 | } |
| 3252 | |
| 3253 | /** |
| 3254 | * Get last data for trigger. |
| 3255 | * |
| 3256 | * @param array $data data. |
| 3257 | * @return array |
| 3258 | */ |
| 3259 | public function search_funnel_kit_automations_triggers_last_data( $data ) { |
| 3260 | |
| 3261 | if ( ! class_exists( 'BWFCRM_Contact' ) || ! class_exists( 'BWFCRM_Lists' ) || ! class_exists( 'BWFCRM_Tag' ) ) { |
| 3262 | return []; |
| 3263 | } |
| 3264 | |
| 3265 | $context = []; |
| 3266 | $context['response_type'] = 'sample'; |
| 3267 | |
| 3268 | $contact = [ |
| 3269 | 'contact_id' => '1', |
| 3270 | 'wpid' => '0', |
| 3271 | 'uid' => '9e74246335fd81b1c4a9123842c12549', |
| 3272 | 'email' => 'johndoe@example.com', |
| 3273 | 'first_name' => 'John', |
| 3274 | 'last_name' => 'Doe', |
| 3275 | 'contact_no' => '+1 555-555-5555', |
| 3276 | 'state' => 'NY', |
| 3277 | 'country' => 'United States', |
| 3278 | 'timezone' => 'New York', |
| 3279 | 'creation_date' => '2023-05-29 15:26:03', |
| 3280 | 'last_modified' => '2023-05-29 17:08:30', |
| 3281 | 'source' => '', |
| 3282 | 'type' => 'Los Angeles', |
| 3283 | 'status' => '0', |
| 3284 | 'tags' => '["1"]', |
| 3285 | 'lists' => '["2","1"]', |
| 3286 | ]; |
| 3287 | |
| 3288 | $list = [ |
| 3289 | 'list_id' => 1, |
| 3290 | 'list_name' => 'Sample List', |
| 3291 | ]; |
| 3292 | |
| 3293 | $tag = [ |
| 3294 | 'tag_id' => 1, |
| 3295 | 'tag_name' => 'Sample Tag', |
| 3296 | ]; |
| 3297 | |
| 3298 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3299 | |
| 3300 | $recent_contacts = \BWFCRM_Contact::get_recent_contacts( 0, 1, [] ); |
| 3301 | $contact_email = count( $recent_contacts['contacts'] ) > 0 && isset( $recent_contacts['contacts'][0]['email'] ) ? $recent_contacts['contacts'][0]['email'] : ''; |
| 3302 | |
| 3303 | $real_contact = false; |
| 3304 | if ( ! empty( $contact_email ) ) { |
| 3305 | $contact_obj = \BWFCRM_Contact::get_contacts( $contact_email, 0, 1, [], [], OBJECT ); |
| 3306 | |
| 3307 | if ( isset( $contact_obj['contacts'][0] ) ) { |
| 3308 | $contact = FunnelKitAutomations::get_contact_context( $contact_obj['contacts'][0]->contact ); |
| 3309 | $real_contact = true; |
| 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | if ( 'contact_added_to_list' === $term || 'contact_removed_from_list' === $term ) { |
| 3314 | $list_id = (int) ( isset( $data['filter']['list_id']['value'] ) ? $data['filter']['list_id']['value'] : '-1' ); |
| 3315 | |
| 3316 | if ( -1 === $list_id ) { |
| 3317 | $lists = \BWFCRM_Lists::get_lists( [], '', 0, 1 ); |
| 3318 | $list_id = count( $lists ) > 0 ? $lists[0]['ID'] : -1; |
| 3319 | } |
| 3320 | |
| 3321 | |
| 3322 | if ( -1 !== $list_id ) { |
| 3323 | $list = FunnelKitAutomations::get_list_context( $list_id ); |
| 3324 | $context['response_type'] = $real_contact ? 'live' : 'sample'; |
| 3325 | } |
| 3326 | |
| 3327 | $context['pluggable_data'] = array_merge( $list, $contact ); |
| 3328 | } else { |
| 3329 | $tag_id = (int) ( isset( $data['filter']['tag_id']['value'] ) ? $data['filter']['tag_id']['value'] : '-1' ); |
| 3330 | |
| 3331 | if ( -1 === $tag_id ) { |
| 3332 | $tags = \BWFCRM_Tag::get_tags( [], '', 0, 1 ); |
| 3333 | $tag_id = count( $tags ) > 0 ? $tags[0]['ID'] : -1; |
| 3334 | } |
| 3335 | |
| 3336 | |
| 3337 | if ( -1 !== $tag_id ) { |
| 3338 | $tag = FunnelKitAutomations::get_tag_context( $tag_id ); |
| 3339 | $context['response_type'] = $real_contact ? 'live' : 'sample'; |
| 3340 | } |
| 3341 | |
| 3342 | $context['pluggable_data'] = array_merge( $tag, $contact ); |
| 3343 | } |
| 3344 | |
| 3345 | return $context; |
| 3346 | } |
| 3347 | |
| 3348 | /** |
| 3349 | * Get last data for trigger. |
| 3350 | * |
| 3351 | * @param array $data data. |
| 3352 | * @return array |
| 3353 | */ |
| 3354 | public function search_edd_triggers_last_data( $data ) { |
| 3355 | |
| 3356 | global $wpdb; |
| 3357 | $context = []; |
| 3358 | $context['response_type'] = 'sample'; |
| 3359 | |
| 3360 | $order_data = [ |
| 3361 | 'order_id' => '1', |
| 3362 | 'customer_email' => 'john_doe@bsf.io', |
| 3363 | 'customer_first_name' => 'John', |
| 3364 | 'customer_last_name' => 'Doe', |
| 3365 | 'ordered_items' => 'Any Sample Book', |
| 3366 | 'currency' => 'USD', |
| 3367 | 'status' => 'complete', |
| 3368 | 'discount_codes' => 'KDJSKS', |
| 3369 | 'order_discounts' => '2.00', |
| 3370 | 'order_subtotal' => '48.00', |
| 3371 | 'order_tax' => '0.00', |
| 3372 | 'order_total' => '48.00', |
| 3373 | 'payment_method' => 'stripe', |
| 3374 | ]; |
| 3375 | |
| 3376 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3377 | $download_id = (int) ( isset( $data['filter']['download_id']['value'] ) ? $data['filter']['download_id]']['value'] : '-1' ); |
| 3378 | |
| 3379 | if ( 'order_created' === $term ) { |
| 3380 | $order_data['purchase_key'] = '06d3b7d923ca922dc889354f9bc33fbb'; |
| 3381 | |
| 3382 | $args = [ |
| 3383 | 'number' => 1, |
| 3384 | 'status' => [ 'complete', 'refunded', 'partially_refunded' ], |
| 3385 | ]; |
| 3386 | $payments = edd_get_payments( $args ); |
| 3387 | |
| 3388 | if ( count( $payments ) > 0 ) { |
| 3389 | $order_data = EDD::get_product_purchase_context( $payments[0] ); |
| 3390 | $context['response_type'] = 'live'; |
| 3391 | } |
| 3392 | } elseif ( 'edd_triggers_last_data' === $term ) { |
| 3393 | $args = [ |
| 3394 | 'number' => 1, |
| 3395 | 'status' => 'complete', |
| 3396 | 'type' => 'refund', |
| 3397 | ]; |
| 3398 | $payments = edd_get_payments( $args ); |
| 3399 | |
| 3400 | if ( count( $payments ) > 0 ) { |
| 3401 | $order_data = EDD::get_purchase_refund_context( $payments[0] ); |
| 3402 | $context['response_type'] = 'live'; |
| 3403 | } |
| 3404 | } else { |
| 3405 | $status = isset( $data['post_type'] ) ? $data['post_type'] : ''; |
| 3406 | if ( ! empty( $status ) ) { |
| 3407 | if ( $download_id > 0 ) { |
| 3408 | $licesnses = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE status= %s AND download_id=%d ORDER BY id DESC", $status, $download_id ) ); |
| 3409 | } else { |
| 3410 | $licesnses = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE status= %s ORDER BY id DESC", $status ) ); |
| 3411 | } |
| 3412 | } else { |
| 3413 | if ( $download_id > 0 ) { |
| 3414 | $licesnses = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE download_id=%d ORDER BY id DESC", $download_id ) ); |
| 3415 | } else { |
| 3416 | $licesnses = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}edd_licenses ORDER BY id DESC" ); |
| 3417 | } |
| 3418 | } |
| 3419 | if ( ! empty( $licesnses ) ) { |
| 3420 | $order_data = EDD::edd_get_license_data( $licesnses->id, $licesnses->download_id, $licesnses->payment_id ); |
| 3421 | $context['response_type'] = 'live'; |
| 3422 | } else { |
| 3423 | $order_data = [ |
| 3424 | 'ID' => 1, |
| 3425 | 'key' => '23232323232', |
| 3426 | 'customer_email' => 'suretest@example.com', |
| 3427 | 'customer_name' => 'Sure Test', |
| 3428 | 'product_id' => 1, |
| 3429 | 'download_id' => 1, |
| 3430 | 'product_name' => 'Test', |
| 3431 | 'activation_limit' => 2, |
| 3432 | 'activation_count' => 1, |
| 3433 | 'activated_urls' => 'https://example.com', |
| 3434 | 'expiration' => '1686297914', |
| 3435 | 'is_lifetime' => '0', |
| 3436 | 'status' => $status, |
| 3437 | ]; |
| 3438 | |
| 3439 | } |
| 3440 | } |
| 3441 | |
| 3442 | $context['pluggable_data'] = $order_data; |
| 3443 | return $context; |
| 3444 | } |
| 3445 | |
| 3446 | /** |
| 3447 | * Get last data for trigger. |
| 3448 | * |
| 3449 | * @param array $data data. |
| 3450 | * @return array |
| 3451 | */ |
| 3452 | public function search_presto_player_triggers_last_data( $data ) { |
| 3453 | $context = []; |
| 3454 | $context['response_type'] = 'sample'; |
| 3455 | |
| 3456 | $user_data = WordPress::get_sample_user_context(); |
| 3457 | |
| 3458 | $video_data = [ |
| 3459 | 'pp_video' => '1', |
| 3460 | 'pp_video_percentage' => '100', |
| 3461 | 'video_id' => '1', |
| 3462 | 'video_title' => 'SureTriggers Is Here 🎉 The Easiest Automation Builder WordPress Websites & Apps', |
| 3463 | 'video_type' => 'youtube', |
| 3464 | 'video_external_id' => '-cYbNYgylLs', |
| 3465 | 'video_attachment_id' => '0', |
| 3466 | 'video_post_id' => '127', |
| 3467 | 'video_src' => 'https://www.youtube.com/watch?v=-cYbNYgylLs', |
| 3468 | 'video_created_by' => '1', |
| 3469 | 'video_created_at' => '2022-11-10 00:28:25', |
| 3470 | 'video_updated_at' => '2022-11-10 00:34:40', |
| 3471 | 'video_deleted_at' => '', |
| 3472 | ]; |
| 3473 | |
| 3474 | $videos = ( new Video() )->all(); |
| 3475 | |
| 3476 | if ( count( $videos ) > 0 ) { |
| 3477 | $video_id = '-1' === $data['filter']['pp_video']['value'] ? $videos[0]->id : $data['filter']['pp_video']['value']; |
| 3478 | $video_data = ( new Video( $video_id ) )->toArray(); |
| 3479 | $video_data['pp_video'] = $video_id; |
| 3480 | $video_data['pp_video_percentage'] = isset( $data['filter']['pp_video_percentage']['value'] ) ? $data['filter']['pp_video_percentage']['value'] : '100'; |
| 3481 | $user_data = WordPress::get_user_context( $video_data['created_by'] ); |
| 3482 | |
| 3483 | $context['response_type'] = 'live'; |
| 3484 | } |
| 3485 | |
| 3486 | $context['pluggable_data'] = array_merge( $user_data, $video_data ); |
| 3487 | |
| 3488 | return $context; |
| 3489 | } |
| 3490 | |
| 3491 | /** |
| 3492 | * Get last data for trigger. |
| 3493 | * |
| 3494 | * @param array $data data. |
| 3495 | * @return array |
| 3496 | */ |
| 3497 | public function search_member_press_triggers_last_data( $data ) { |
| 3498 | global $wpdb; |
| 3499 | |
| 3500 | $context = []; |
| 3501 | $context['response_type'] = 'sample'; |
| 3502 | |
| 3503 | $user_data = WordPress::get_sample_user_context(); |
| 3504 | |
| 3505 | $membership_data = [ |
| 3506 | 'membership_id' => '190', |
| 3507 | 'membership_title' => 'Sample Membership', |
| 3508 | 'amount' => '12.00', |
| 3509 | 'total' => '12.00', |
| 3510 | 'tax_amount' => '0.00', |
| 3511 | 'tax_rate' => '0.00', |
| 3512 | 'trans_num' => 't_63a03f3334f44', |
| 3513 | 'status' => 'complete', |
| 3514 | 'subscription_id' => '0', |
| 3515 | 'membership_url' => site_url() . '/register/premium/', |
| 3516 | 'membership_featured_image_id' => '521', |
| 3517 | 'membership_featured_image_url' => SURE_TRIGGERS_URL . 'assets/images/sample.svg', |
| 3518 | ]; |
| 3519 | |
| 3520 | $membership_id = (int) ( isset( $data['filter']['membership_id']['value'] ) ? $data['filter']['membership_id']['value'] : '-1' ); |
| 3521 | |
| 3522 | if ( $membership_id > 0 ) { |
| 3523 | |
| 3524 | $subscription = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mepr_transactions WHERE product_id= %s ORDER BY id DESC LIMIT 1", $membership_id ) ); |
| 3525 | } else { |
| 3526 | $subscription = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}mepr_transactions ORDER BY id DESC LIMIT 1" ); |
| 3527 | } |
| 3528 | |
| 3529 | if ( ! empty( $subscription ) ) { |
| 3530 | $membership_data = MemberPress::get_membership_context( $subscription ); |
| 3531 | $user_data = WordPress::get_user_context( $subscription->user_id ); |
| 3532 | |
| 3533 | $context['response_type'] = 'live'; |
| 3534 | } |
| 3535 | |
| 3536 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 3537 | |
| 3538 | return $context; |
| 3539 | } |
| 3540 | |
| 3541 | /** |
| 3542 | * Get last data for trigger. |
| 3543 | * |
| 3544 | * @param array $data data. |
| 3545 | * @return array |
| 3546 | */ |
| 3547 | public function search_wishlist_member_triggers_last_data( $data ) { |
| 3548 | global $wpdb; |
| 3549 | |
| 3550 | $context = []; |
| 3551 | $context['response_type'] = 'sample'; |
| 3552 | |
| 3553 | $user_data = WordPress::get_sample_user_context(); |
| 3554 | |
| 3555 | $membership_data = [ |
| 3556 | 'membership_level_id' => '1', |
| 3557 | 'membership_level_name' => 'Sample Membership Level', |
| 3558 | ]; |
| 3559 | |
| 3560 | $membership_level_id = (int) ( isset( $data['filter']['membership_level_id']['value'] ) ? $data['filter']['membership_level_id']['value'] : '-1' ); |
| 3561 | |
| 3562 | if ( $membership_level_id > 0 ) { |
| 3563 | $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 ) ); |
| 3564 | } else { |
| 3565 | $membership = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}wlm_userlevels ORDER BY id DESC LIMIT 1" ); |
| 3566 | } |
| 3567 | if ( ! empty( $membership ) ) { |
| 3568 | $membership_data = WishlistMember::get_membership_detail_context( (int) $membership->level_id ); |
| 3569 | $user_data = WordPress::get_user_context( $membership->user_id ); |
| 3570 | |
| 3571 | $context['response_type'] = 'live'; |
| 3572 | } |
| 3573 | |
| 3574 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 3575 | |
| 3576 | return $context; |
| 3577 | } |
| 3578 | |
| 3579 | /** |
| 3580 | * Get last data for trigger. |
| 3581 | * |
| 3582 | * @param array $data data. |
| 3583 | * @return array |
| 3584 | */ |
| 3585 | public function search_peepso_triggers_last_data( $data ) { |
| 3586 | global $wpdb; |
| 3587 | |
| 3588 | $context = []; |
| 3589 | $context['response_type'] = 'sample'; |
| 3590 | |
| 3591 | $user_data = WordPress::get_sample_user_context(); |
| 3592 | |
| 3593 | $post_data = [ |
| 3594 | 'post_id' => '1', |
| 3595 | 'activity_id' => '2', |
| 3596 | 'post_author' => '1', |
| 3597 | 'post_content' => 'New sample post...!', |
| 3598 | 'post_title' => 'Sample Post', |
| 3599 | 'post_excerpt' => 'sample', |
| 3600 | 'post_status' => 'publish', |
| 3601 | 'post_type' => 'peepso-post', |
| 3602 | ]; |
| 3603 | |
| 3604 | $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" ); |
| 3605 | |
| 3606 | if ( ! empty( $post ) ) { |
| 3607 | $post_data = PeepSo::get_pp_activity_context( (int) $post->act_external_id, (int) $post->act_id ); |
| 3608 | $user_data = WordPress::get_user_context( $post->act_owner_id ); |
| 3609 | |
| 3610 | $context['response_type'] = 'live'; |
| 3611 | } |
| 3612 | |
| 3613 | $context['pluggable_data'] = array_merge( $user_data, $post_data ); |
| 3614 | |
| 3615 | return $context; |
| 3616 | } |
| 3617 | |
| 3618 | /** |
| 3619 | * Get last data for trigger |
| 3620 | * |
| 3621 | * @param array $data data. |
| 3622 | * @return array |
| 3623 | */ |
| 3624 | public function search_restrict_content_pro_triggers_last_data( $data ) { |
| 3625 | $context = []; |
| 3626 | $context['response_type'] = 'sample'; |
| 3627 | |
| 3628 | $user_data = WordPress::get_sample_user_context(); |
| 3629 | |
| 3630 | $membership_data = [ |
| 3631 | 'membership_level_id' => '190', |
| 3632 | 'membership_level' => 'Sample Membership', |
| 3633 | 'membership_initial_payment' => '0.00', |
| 3634 | 'membership_recurring_payment' => '0.00', |
| 3635 | 'membership_expiry_date' => 'January 22, 2023', |
| 3636 | ]; |
| 3637 | |
| 3638 | $customer_id = (int) ( isset( $data['filter']['membership_customer_id']['value'] ) ? $data['filter']['membership_customer_id']['value'] : '-1' ); |
| 3639 | $membership_id = (int) ( isset( $data['filter']['membership_level_id']['value'] ) ? $data['filter']['membership_level_id']['value'] : '-1' ); |
| 3640 | |
| 3641 | $args = [ |
| 3642 | 'status' => 'expired', |
| 3643 | 'number' => 1, |
| 3644 | 'orderby' => 'id', |
| 3645 | ]; |
| 3646 | |
| 3647 | if ( -1 !== $customer_id ) { |
| 3648 | $args['customer_id'] = $customer_id; |
| 3649 | } |
| 3650 | |
| 3651 | if ( -1 !== $membership_id ) { |
| 3652 | $args['object_id'] = $membership_id; |
| 3653 | } |
| 3654 | |
| 3655 | $memberships = rcp_get_memberships( $args ); |
| 3656 | if ( count( $memberships ) > 0 ) { |
| 3657 | $membership_data = RestrictContent::get_rcp_membership_detail_context( $memberships[0] ); |
| 3658 | $user_data = WordPress::get_user_context( $memberships[0]->get_user_id() ); |
| 3659 | |
| 3660 | $context['response_type'] = 'live'; |
| 3661 | } |
| 3662 | |
| 3663 | $context['pluggable_data'] = array_merge( $user_data, $membership_data ); |
| 3664 | |
| 3665 | return $context; |
| 3666 | } |
| 3667 | |
| 3668 | /** |
| 3669 | * Get last data for trigger |
| 3670 | * |
| 3671 | * @param array $data data. |
| 3672 | * @return array |
| 3673 | */ |
| 3674 | public function search_events_calendar_triggers_last_data( $data ) { |
| 3675 | $context = []; |
| 3676 | $context['response_type'] = 'sample'; |
| 3677 | |
| 3678 | $event_data = [ |
| 3679 | 'event' => [ |
| 3680 | 'ID' => 58, |
| 3681 | 'post_author' => 1, |
| 3682 | 'post_date' => '2023-01-19 09:27:58', |
| 3683 | 'post_date_gmt' => '2023-01-19 09:27:58', |
| 3684 | 'post_content' => '', |
| 3685 | 'post_title' => 'New event', |
| 3686 | 'post_excerpt' => '', |
| 3687 | 'post_status' => 'publish', |
| 3688 | 'comment_status' => 'open', |
| 3689 | 'ping_status' => 'closed', |
| 3690 | 'post_password' => '', |
| 3691 | 'post_name' => 'new-event', |
| 3692 | 'to_ping' => '', |
| 3693 | 'pinged' => '', |
| 3694 | 'post_modified' => '2023-01-19 09:44:25', |
| 3695 | 'post_modified_gmt' => '2023-01-19 09:44:25', |
| 3696 | 'post_content_filtered' => '', |
| 3697 | 'post_parent' => 0, |
| 3698 | 'guid' => 'http://connector.com/?post_type=tribe_events&p=58', |
| 3699 | 'menu_order' => -1, |
| 3700 | 'post_type' => 'tribe_events', |
| 3701 | 'post_mime_type' => '', |
| 3702 | 'comment_count' => 0, |
| 3703 | 'filter' => 'raw', |
| 3704 | ], |
| 3705 | 'attendies' => [ |
| 3706 | 'order_id' => 68, |
| 3707 | 'purchaser_name' => 'sapna Rana', |
| 3708 | 'purchaser_email' => 'sapnar@bsf.io', |
| 3709 | 'provider' => 'Tribe__Tickets__RSVP', |
| 3710 | 'provider_slug' => 'rsvp', |
| 3711 | 'purchase_time' => '2023-01-19 09:48:43', |
| 3712 | 'optout' => 1, |
| 3713 | 'ticket' => 'Prime', |
| 3714 | 'attendee_id' => 68, |
| 3715 | 'security' => '2cefc3b53e', |
| 3716 | 'product_id' => 65, |
| 3717 | 'check_in' => '', |
| 3718 | 'order_status' => 'yes', |
| 3719 | 'order_status_label' => 'Going', |
| 3720 | 'user_id' => 1, |
| 3721 | 'ticket_sent' => 1, |
| 3722 | 'event_id' => 58, |
| 3723 | 'ticket_name' => 'Prime', |
| 3724 | 'holder_name' => 'sapna Rana', |
| 3725 | 'holder_email' => 'sapnar@bsf.io', |
| 3726 | 'ticket_id' => 68, |
| 3727 | 'qr_ticket_id' => 68, |
| 3728 | 'security_code' => '2cefc3b53e', |
| 3729 | 'attendee_meta' => '', |
| 3730 | 'is_subscribed' => '', |
| 3731 | 'is_purchaser' => 1, |
| 3732 | 'ticket_exists' => 1, |
| 3733 | ], |
| 3734 | ]; |
| 3735 | |
| 3736 | $event_id = (int) ( isset( $data['filter']['event_id']['value'] ) ? $data['filter']['event_id']['value'] : '-1' ); |
| 3737 | |
| 3738 | $args = [ |
| 3739 | 'post_type' => 'tribe_rsvp_attendees', |
| 3740 | 'orderby' => 'ID', |
| 3741 | 'order' => 'DESC', |
| 3742 | 'post_status' => 'publish', |
| 3743 | 'numberposts' => 1, |
| 3744 | ]; |
| 3745 | |
| 3746 | if ( -1 !== $event_id ) { |
| 3747 | $args['meta_query'] = [ |
| 3748 | [ |
| 3749 | 'key' => '_tribe_rsvp_event', |
| 3750 | 'value' => $event_id, |
| 3751 | ], |
| 3752 | ]; |
| 3753 | } |
| 3754 | |
| 3755 | $attendees = get_posts( $args ); |
| 3756 | |
| 3757 | if ( count( $attendees ) > 0 ) { |
| 3758 | $attendee = $attendees[0]; |
| 3759 | $attendee_id = $attendee->ID; |
| 3760 | |
| 3761 | $product_id = get_post_meta( $attendee_id, '_tribe_rsvp_product', true ); |
| 3762 | $order_id = get_post_meta( $attendee_id, '_tribe_rsvp_order', true ); |
| 3763 | |
| 3764 | $event_data = TheEventCalendar::get_event_context( $product_id, $order_id ); |
| 3765 | $context['response_type'] = 'live'; |
| 3766 | } |
| 3767 | |
| 3768 | $context['pluggable_data'] = $event_data; |
| 3769 | |
| 3770 | return $context; |
| 3771 | } |
| 3772 | |
| 3773 | /** |
| 3774 | * Get last data for trigger |
| 3775 | * |
| 3776 | * @param array $data data. |
| 3777 | * @return array |
| 3778 | */ |
| 3779 | public function search_woo_commerce_triggers_last_data( $data ) { |
| 3780 | $context = []; |
| 3781 | $context['response_type'] = 'sample'; |
| 3782 | $user_data = WordPress::get_sample_user_context(); |
| 3783 | |
| 3784 | $product_data['product'] = [ |
| 3785 | 'id' => '169', |
| 3786 | 'name' => 'Sample Product', |
| 3787 | 'description' => 'This is description of sample product.', |
| 3788 | 'short_description' => 'This is short description of sample product.', |
| 3789 | 'image_url' => SURE_TRIGGERS_URL . 'assets/images/sample.svg', |
| 3790 | 'slug' => 'sample-product', |
| 3791 | 'status' => 'publish', |
| 3792 | 'type' => 'simple', |
| 3793 | 'price' => '89', |
| 3794 | 'featured' => '0', |
| 3795 | 'sku' => 'hoodie-blue-sm', |
| 3796 | 'regular_price' => '90', |
| 3797 | 'sale_price' => '89', |
| 3798 | 'total_sales' => '21', |
| 3799 | 'category' => 'Uncategorized', |
| 3800 | 'tags' => 'sample, new, 2022', |
| 3801 | ]; |
| 3802 | |
| 3803 | $comment_data = [ |
| 3804 | 'comment_id' => '1', |
| 3805 | 'comment' => 'This is a sample comment..!', |
| 3806 | 'comment_author' => 'testsure', |
| 3807 | 'comment_date' => '2023-06-23 10:10:40', |
| 3808 | 'comment_author_email' => 'testsure@example.com', |
| 3809 | ]; |
| 3810 | |
| 3811 | $order_data = [ |
| 3812 | 'order_id' => '500', |
| 3813 | 'total_order_value' => '45', |
| 3814 | 'currency' => 'USD', |
| 3815 | 'shipping_total' => '5', |
| 3816 | 'order_payment_method' => 'cod', |
| 3817 | 'billing_firstname' => 'John', |
| 3818 | 'billing_lastname' => 'Doe', |
| 3819 | 'billing_company' => 'BSF', |
| 3820 | 'billing_address_1' => '1004 Beaumont', |
| 3821 | 'billing_address_2' => '', |
| 3822 | 'billing_city' => 'Casper', |
| 3823 | 'billing_state' => 'Wyoming', |
| 3824 | 'billing_postcode' => '82601', |
| 3825 | 'billing_country' => 'US', |
| 3826 | 'billing_email' => 'john_doe@bsf.io', |
| 3827 | 'billing_phone' => '(307) 7626541', |
| 3828 | 'shipping_firstname' => 'John', |
| 3829 | 'shipping_lastname' => 'Doe', |
| 3830 | 'shipping_company' => 'BSF', |
| 3831 | 'shipping_address_1' => '1004 Beaumont', |
| 3832 | 'shipping_address_2' => '', |
| 3833 | 'shipping_city' => 'Casper', |
| 3834 | 'shipping_state' => 'Wyoming', |
| 3835 | 'shipping_postcode' => '82601', |
| 3836 | 'shipping_country' => 'US', |
| 3837 | 'coupon_codes' => 'e3mstekq, f24sjakb', |
| 3838 | 'total_items_in_order' => '1', |
| 3839 | 'user_id' => '1', |
| 3840 | ]; |
| 3841 | |
| 3842 | $variation_data = [ |
| 3843 | 'product_variation_id' => '626', |
| 3844 | 'product_variation' => 'Color: Silver', |
| 3845 | ]; |
| 3846 | |
| 3847 | $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 |
| 3848 | |
| 3849 | $product_id = (int) ( isset( $data['filter']['product_id']['value'] ) ? $data['filter']['product_id']['value'] : -1 ); |
| 3850 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 3851 | |
| 3852 | if ( in_array( $term, [ 'product_added_to_cart', 'product_viewed' ], true ) ) { |
| 3853 | if ( -1 === $product_id ) { |
| 3854 | $args = [ |
| 3855 | 'post_type' => 'product', |
| 3856 | 'orderby' => 'ID', |
| 3857 | 'order' => 'DESC', |
| 3858 | 'post_status' => 'publish', |
| 3859 | 'numberposts' => 1, |
| 3860 | ]; |
| 3861 | $products = get_posts( $args ); |
| 3862 | |
| 3863 | if ( count( $products ) > 0 ) { |
| 3864 | $product_id = $products[0]->ID; |
| 3865 | } |
| 3866 | } |
| 3867 | |
| 3868 | if ( -1 !== $product_id ) { |
| 3869 | $post = get_post( $product_id ); |
| 3870 | $user_data = WordPress::get_user_context( $post->post_author ); |
| 3871 | $product_data['product_id'] = $product_id; |
| 3872 | $product_data['product'] = WooCommerce::get_product_context( $product_id ); |
| 3873 | $terms = get_the_terms( $product_id, 'product_cat' ); |
| 3874 | if ( ! empty( $terms ) && is_array( $terms ) && isset( $terms[0] ) ) { |
| 3875 | $cat_name = []; |
| 3876 | foreach ( $terms as $cat ) { |
| 3877 | $cat_name[] = $cat->name; |
| 3878 | } |
| 3879 | $product_data['product']['category'] = implode( ', ', $cat_name ); |
| 3880 | } |
| 3881 | $terms_tags = get_the_terms( $product_id, 'product_tag' ); |
| 3882 | if ( ! empty( $terms_tags ) && is_array( $terms_tags ) && isset( $terms_tags[0] ) ) { |
| 3883 | $tag_name = []; |
| 3884 | foreach ( $terms_tags as $tag ) { |
| 3885 | $tag_name[] = $tag->name; |
| 3886 | } |
| 3887 | $product_data['product']['tag'] = implode( ', ', $tag_name ); |
| 3888 | } |
| 3889 | unset( $product_data['product']['id'] ); //phpcs:ignore |
| 3890 | $context['response_type'] = 'live'; |
| 3891 | } |
| 3892 | |
| 3893 | if ( 'product_added_to_cart' === $term ) { |
| 3894 | $product_data['product_quantity'] = 1; |
| 3895 | } |
| 3896 | |
| 3897 | $context['pluggable_data'] = array_merge( $product_data, $user_data ); |
| 3898 | |
| 3899 | } elseif ( 'product_reviewed' === $term ) { |
| 3900 | $comment_args = [ |
| 3901 | 'number' => 1, |
| 3902 | 'type' => 'review', |
| 3903 | 'orderby' => 'comment_ID', |
| 3904 | 'post_id' => -1 !== $product_id ? $product_id : 0, |
| 3905 | ]; |
| 3906 | |
| 3907 | $comments = get_comments( $comment_args ); |
| 3908 | |
| 3909 | if ( count( $comments ) > 0 ) { |
| 3910 | $comment = $comments[0]; |
| 3911 | $comment_data = [ |
| 3912 | 'comment_id' => $comment->comment_ID, |
| 3913 | 'comment' => $comment->comment_content, |
| 3914 | 'comment_author' => $comment->comment_author, |
| 3915 | 'comment_date' => $comment->comment_date, |
| 3916 | 'comment_author_email' => $comment->comment_author_email, |
| 3917 | ]; |
| 3918 | $product_data = WooCommerce::get_product_context( $comment->comment_post_ID ); |
| 3919 | if ( is_object( $comment ) ) { |
| 3920 | $terms = get_the_terms( (int) $comment->comment_post_ID, 'product_cat' ); |
| 3921 | if ( ! empty( $terms ) && is_array( $terms ) && isset( $terms[0] ) ) { |
| 3922 | $cat_name = []; |
| 3923 | foreach ( $terms as $cat ) { |
| 3924 | $cat_name[] = $cat->name; |
| 3925 | } |
| 3926 | $product_data['product']['category'] = implode( ', ', $cat_name ); |
| 3927 | } |
| 3928 | $terms_tags = get_the_terms( (int) $comment->comment_post_ID, 'product_tag' ); |
| 3929 | if ( ! empty( $terms_tags ) && is_array( $terms_tags ) && isset( $terms_tags[0] ) ) { |
| 3930 | $tag_name = []; |
| 3931 | foreach ( $terms_tags as $tag ) { |
| 3932 | $tag_name[] = $tag->name; |
| 3933 | } |
| 3934 | $product_data['product']['tag'] = implode( ', ', $tag_name ); |
| 3935 | } |
| 3936 | } |
| 3937 | $user_data = WordPress::get_user_context( $comment->user_id ); |
| 3938 | $context['response_type'] = 'live'; |
| 3939 | } |
| 3940 | |
| 3941 | $context['pluggable_data'] = array_merge( $product_data, $user_data, $comment_data ); |
| 3942 | |
| 3943 | } elseif ( 'product_purchased' === $term ) { |
| 3944 | $order_id = 0; |
| 3945 | $product_data['quantity'] = '1'; |
| 3946 | if ( -1 !== $product_id ) { |
| 3947 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 3948 | if ( count( $order_ids ) > 0 ) { |
| 3949 | $order_id = $order_ids[0]; |
| 3950 | } |
| 3951 | } else { |
| 3952 | $orders = wc_get_orders( [ 'numberposts' => 1 ] ); |
| 3953 | if ( count( $orders ) > 0 ) { |
| 3954 | $order_id = $orders[0]->get_id(); |
| 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | if ( 0 !== $order_id ) { |
| 3959 | $order = wc_get_order( $order_id ); |
| 3960 | |
| 3961 | if ( $order ) { |
| 3962 | $user_id = $order->get_customer_id(); |
| 3963 | $items = $order->get_items(); |
| 3964 | |
| 3965 | $product_ids = []; |
| 3966 | |
| 3967 | $iteration = 0; |
| 3968 | foreach ( $items as $item ) { |
| 3969 | if ( method_exists( $item, 'get_product_id' ) ) { |
| 3970 | $item_id = $item->get_product_id(); |
| 3971 | if ( -1 === $product_id && 0 === $iteration ) { |
| 3972 | $product_ids[] = $item_id; |
| 3973 | break; |
| 3974 | } elseif ( $item_id === $product_id ) { |
| 3975 | $product_ids[] = $item_id; |
| 3976 | break; |
| 3977 | } |
| 3978 | } |
| 3979 | |
| 3980 | $iteration++; |
| 3981 | } |
| 3982 | $order_data = WooCommerce::get_order_context( $order_id ); |
| 3983 | $user_data = WordPress::get_user_context( $user_id ); |
| 3984 | $order_data['total_items_in_order'] = count( $product_ids ); |
| 3985 | $product_data = []; |
| 3986 | foreach ( $product_ids as $key => $product_id ) { |
| 3987 | $product_data[ 'product' . $key ] = WooCommerce::get_product_context( $product_id ); |
| 3988 | $terms = get_the_terms( $product_id, 'product_cat' ); |
| 3989 | if ( ! empty( $terms ) && is_array( $terms ) && isset( $terms[0] ) ) { |
| 3990 | $cat_name = []; |
| 3991 | foreach ( $terms as $cat ) { |
| 3992 | $cat_name[] = $cat->name; |
| 3993 | } |
| 3994 | $product_data[ 'product' . $key ]['category'] = implode( ', ', $cat_name ); |
| 3995 | } |
| 3996 | $terms_tags = get_the_terms( $product_id, 'product_tag' ); |
| 3997 | if ( ! empty( $terms_tags ) && is_array( $terms_tags ) && isset( $terms_tags[0] ) ) { |
| 3998 | $tag_name = []; |
| 3999 | foreach ( $terms_tags as $tag ) { |
| 4000 | $tag_name[] = $tag->name; |
| 4001 | } |
| 4002 | $product_data[ 'product' . $key ]['tag'] = implode( ', ', $tag_name ); |
| 4003 | } |
| 4004 | $product = wc_get_product( $product_id ); |
| 4005 | /** |
| 4006 | * |
| 4007 | * Ignore line |
| 4008 | * |
| 4009 | * @phpstan-ignore-next-line |
| 4010 | */ |
| 4011 | if ( $product->is_downloadable() ) { |
| 4012 | /** |
| 4013 | * |
| 4014 | * Ignore line |
| 4015 | * |
| 4016 | * @phpstan-ignore-next-line |
| 4017 | */ |
| 4018 | foreach ( $product->get_downloads() as $key_download_id => $download ) { |
| 4019 | $download_name = $download->get_name(); |
| 4020 | $download_link = $download->get_file(); |
| 4021 | $download_id = $download->get_id(); |
| 4022 | $download_type = $download->get_file_type(); |
| 4023 | $download_ext = $download->get_file_extension(); |
| 4024 | $product_data[ 'product' . $key ]['download'] = [ |
| 4025 | 'download_name' => $download_name, |
| 4026 | 'download_link' => $download_link, |
| 4027 | 'download_id' => $download_id, |
| 4028 | 'download_type' => $download_type, |
| 4029 | 'download_ext' => $download_ext, |
| 4030 | ]; |
| 4031 | } |
| 4032 | } |
| 4033 | } |
| 4034 | $context['response_type'] = 'live'; |
| 4035 | } |
| 4036 | } |
| 4037 | |
| 4038 | $context['pluggable_data'] = array_merge( $order_data, $product_data, $user_data ); |
| 4039 | |
| 4040 | } elseif ( 'variable_product_purchased' === $term ) { |
| 4041 | $product_variation_id = (int) ( isset( $data['filter']['product_variation_id']['value'] ) ? $data['filter']['product_variation_id']['value'] : -1 ); |
| 4042 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 4043 | |
| 4044 | foreach ( $order_ids as $order_id ) { |
| 4045 | $order = wc_get_order( $order_id ); |
| 4046 | |
| 4047 | if ( $order ) { |
| 4048 | $user_id = $order->get_customer_id(); |
| 4049 | $items = $order->get_items(); |
| 4050 | $product_variations = []; |
| 4051 | |
| 4052 | $iteration = 0; |
| 4053 | foreach ( $items as $item ) { |
| 4054 | if ( method_exists( $item, 'get_variation_id' ) ) { |
| 4055 | $variation_id = $item->get_variation_id(); |
| 4056 | if ( -1 === $product_variation_id && 0 === $iteration ) { |
| 4057 | $product_variations[] = $variation_id; |
| 4058 | break; |
| 4059 | } elseif ( $variation_id === $product_variation_id ) { |
| 4060 | $product_variations[] = $variation_id; |
| 4061 | break; |
| 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | $iteration++; |
| 4066 | } |
| 4067 | |
| 4068 | if ( count( $product_variations ) > 0 ) { |
| 4069 | $product_data = WooCommerce::get_product_context( $product_variation_id ); |
| 4070 | $order_data = WooCommerce::get_order_context( $order_id ); |
| 4071 | $user_data = WordPress::get_user_context( $user_id ); |
| 4072 | $variation_data = [ |
| 4073 | 'product_variation_id' => $product_variations[0], |
| 4074 | 'product_variation' => get_the_excerpt( $product_variations[0] ), |
| 4075 | ]; |
| 4076 | |
| 4077 | $context['response_type'] = 'live'; |
| 4078 | break; |
| 4079 | } |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | $context['pluggable_data'] = array_merge( $order_data, $user_data, $variation_data ); |
| 4084 | |
| 4085 | } elseif ( 'variable_subscription_purchased' === $term ) { |
| 4086 | $product_data['quantity'] = '1'; |
| 4087 | $product_data['product_name'] = 'Sample Product'; |
| 4088 | $product_data['billing_period'] = '2021-2022'; |
| 4089 | |
| 4090 | $context['pluggable_data'] = array_merge( $order_data, $product_data, $user_data ); |
| 4091 | |
| 4092 | $subscription_order_id = 0; |
| 4093 | $order_ids = []; |
| 4094 | |
| 4095 | if ( -1 !== $product_id ) { |
| 4096 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 4097 | |
| 4098 | } else { |
| 4099 | $orders = wc_get_orders( [] ); |
| 4100 | if ( count( $orders ) > 0 ) { |
| 4101 | $order_ids[] = $orders[0]->get_id(); |
| 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | foreach ( $order_ids as $order_id ) { |
| 4106 | $query_args = [ |
| 4107 | 'post_type' => 'shop_subscription', |
| 4108 | 'orderby' => 'ID', |
| 4109 | 'order' => 'DESC', |
| 4110 | 'post_status' => 'wc-active', |
| 4111 | 'posts_per_page' => 1, |
| 4112 | 'post_parent' => $order_id, |
| 4113 | ]; |
| 4114 | $query_result = new WP_Query( $query_args ); |
| 4115 | $subscription_orders = $query_result->get_posts(); |
| 4116 | |
| 4117 | if ( count( $subscription_orders ) > 0 ) { |
| 4118 | $subscription_order_id = $subscription_orders[0]->ID; |
| 4119 | break; |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | if ( 0 !== $subscription_order_id ) { |
| 4124 | $subscription = wcs_get_subscription( $subscription_order_id ); |
| 4125 | if ( $subscription instanceof WC_Subscription ) { |
| 4126 | $last_order_id = $subscription->get_last_order(); |
| 4127 | if ( ! empty( $last_order_id ) && $last_order_id === $subscription->get_parent_id() ) { |
| 4128 | $user_id = wc_get_order( $last_order_id )->get_customer_id(); |
| 4129 | $items = $subscription->get_items(); |
| 4130 | |
| 4131 | foreach ( $items as $item ) { |
| 4132 | $product = $item->get_product(); |
| 4133 | if ( class_exists( '\WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) { |
| 4134 | if ( $product->is_type( [ 'subscription', 'subscription_variation', 'variable-subscription' ] ) ) { |
| 4135 | |
| 4136 | $product_data = WooCommerce::get_variable_subscription_product_context( $item, $last_order_id ); |
| 4137 | $user_data = WordPress::get_user_context( $user_id ); |
| 4138 | |
| 4139 | $context['response_type'] = 'live'; |
| 4140 | $context['pluggable_data'] = array_merge( $product_data, $user_data ); |
| 4141 | } |
| 4142 | } |
| 4143 | } |
| 4144 | } |
| 4145 | } |
| 4146 | } |
| 4147 | } elseif ( 'order_created' === $term ) { |
| 4148 | $orders = wc_get_orders( [ 'numberposts' => 1 ] ); |
| 4149 | $order_id = ''; |
| 4150 | if ( count( $orders ) > 0 ) { |
| 4151 | $order_id = $orders[0]->get_id(); |
| 4152 | $order = wc_get_order( $order_id ); |
| 4153 | $user_id = $order->get_customer_id(); |
| 4154 | $order_sample_data = array_merge( |
| 4155 | WooCommerce::get_order_context( $order_id ), |
| 4156 | WordPress::get_user_context( $user_id ) |
| 4157 | ); |
| 4158 | $context['response_type'] = 'live'; |
| 4159 | } |
| 4160 | |
| 4161 | $context['pluggable_data'] = $order_sample_data; |
| 4162 | |
| 4163 | } |
| 4164 | |
| 4165 | return $context; |
| 4166 | } |
| 4167 | |
| 4168 | /** |
| 4169 | * Search LMS data. |
| 4170 | * |
| 4171 | * @param array $data data. |
| 4172 | * @return array |
| 4173 | */ |
| 4174 | public function search_lifter_lms_last_data( $data ) { |
| 4175 | global $wpdb; |
| 4176 | $post_type = $data['post_type']; |
| 4177 | $meta_key = '_is_complete'; |
| 4178 | $trigger = $data['search_term']; |
| 4179 | $context = []; |
| 4180 | if ( 'lifterlms_purchase_course' === $trigger ) { |
| 4181 | $product_type = 'course'; |
| 4182 | $post_id = $data['filter']['course_id']['value']; |
| 4183 | } elseif ( 'lifterlms_purchase_membership' === $trigger ) { |
| 4184 | $product_type = 'membership'; |
| 4185 | $post_id = $data['filter']['membership_id']['value']; |
| 4186 | } elseif ( 'lifterlms_lesson_completed' === $trigger ) { |
| 4187 | $post_id = $data['filter']['lesson']['value']; |
| 4188 | } elseif ( 'lifterlms_course_completed' === $trigger ) { |
| 4189 | $post_id = $data['filter']['course']['value']; |
| 4190 | } |
| 4191 | |
| 4192 | $where = 'postmeta.post_id = "' . $post_id . '" AND'; |
| 4193 | |
| 4194 | if ( 'llms_order' === $post_type ) { |
| 4195 | if ( -1 === $post_id ) { |
| 4196 | $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 ) ); |
| 4197 | } else { |
| 4198 | $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 ) ); |
| 4199 | } |
| 4200 | } else { |
| 4201 | if ( -1 === $post_id ) { |
| 4202 | $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 ) ); |
| 4203 | } else { |
| 4204 | $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 ) ); |
| 4205 | } |
| 4206 | } |
| 4207 | |
| 4208 | $response = []; |
| 4209 | if ( ! empty( $result ) ) { |
| 4210 | $result_post_id = $result[0]->post_id; |
| 4211 | $result_user_id = $result[0]->user_id; |
| 4212 | |
| 4213 | switch ( $trigger ) { |
| 4214 | case 'lifterlms_lesson_completed': |
| 4215 | $context = array_merge( |
| 4216 | WordPress::get_user_context( $result_user_id ), |
| 4217 | LifterLMS::get_lms_lesson_context( $result_post_id ) |
| 4218 | ); |
| 4219 | |
| 4220 | $context['course'] = get_the_title( get_post_meta( $result_post_id, '_llms_parent_course', true ) ); |
| 4221 | if ( '' !== ( get_post_meta( $result_post_id, '_llms_parent_section', true ) ) ) { |
| 4222 | $context['parent_section'] = get_the_title( get_post_meta( $result_post_id, '_llms_parent_section', true ) ); |
| 4223 | } |
| 4224 | break; |
| 4225 | case 'lifterlms_course_completed': |
| 4226 | $context = array_merge( |
| 4227 | WordPress::get_user_context( $result_user_id ), |
| 4228 | LifterLMS::get_lms_course_context( $result_post_id ) |
| 4229 | ); |
| 4230 | break; |
| 4231 | case 'lifterlms_purchase_course': |
| 4232 | $user_id = get_post_meta( $result_post_id, '_llms_user_id', true ); |
| 4233 | $context['course_id'] = get_post_meta( $result_post_id, '_llms_product_id', true ); |
| 4234 | $context['course_name'] = get_post_meta( $result_post_id, '_llms_product_title', true ); |
| 4235 | $context['course_amount'] = get_post_meta( $result_post_id, '_llms_original_total', true ); |
| 4236 | $context['currency'] = get_post_meta( $result_post_id, '_llms_currency', true ); |
| 4237 | $context ['order'] = WordPress::get_post_context( $result_post_id ); |
| 4238 | $context['order_type'] = get_post_meta( $result_post_id, '_llms_order_type', true ); |
| 4239 | $context['trial_offer'] = get_post_meta( $result_post_id, '_llms_trial_offer', true ); |
| 4240 | $context['billing_frequency'] = get_post_meta( $result_post_id, '_llms_billing_frequency', true ); |
| 4241 | $context = array_merge( $context, WordPress::get_user_context( $user_id ) ); |
| 4242 | break; |
| 4243 | case 'lifterlms_purchase_membership': |
| 4244 | $user_id = get_post_meta( $result_post_id, '_llms_user_id', true ); |
| 4245 | $context['membership_id'] = get_post_meta( $result_post_id, '_llms_product_id', true ); |
| 4246 | $context['membership_name'] = get_post_meta( $result_post_id, '_llms_product_title', true ); |
| 4247 | $context['membership_amount'] = get_post_meta( $result_post_id, '_llms_original_total', true ); |
| 4248 | $context['currency'] = get_post_meta( $result_post_id, '_llms_currency', true ); |
| 4249 | $context ['order'] = WordPress::get_post_context( $result_post_id ); |
| 4250 | $context['order_type'] = get_post_meta( $result_post_id, '_llms_order_type', true ); |
| 4251 | $context['trial_offer'] = get_post_meta( $result_post_id, '_llms_trial_offer', true ); |
| 4252 | $context['billing_frequency'] = get_post_meta( $result_post_id, '_llms_billing_frequency', true ); |
| 4253 | $context = array_merge( $context, WordPress::get_user_context( $user_id ) ); |
| 4254 | break; |
| 4255 | default: |
| 4256 | return; |
| 4257 | |
| 4258 | } |
| 4259 | $response['pluggable_data'] = $context; |
| 4260 | $response['response_type'] = 'live'; |
| 4261 | |
| 4262 | } |
| 4263 | |
| 4264 | return $response; |
| 4265 | |
| 4266 | } |
| 4267 | |
| 4268 | /** |
| 4269 | * Search SM data. |
| 4270 | * |
| 4271 | * @param array $data data. |
| 4272 | * @return array |
| 4273 | */ |
| 4274 | public function search_suremember_last_data( $data ) { |
| 4275 | global $wpdb; |
| 4276 | $post_type = $data['post_type']; |
| 4277 | $meta_key = '_is_complete'; |
| 4278 | $trigger = $data['search_term']; |
| 4279 | $post_id = $data['filter']['group_id']['value']; |
| 4280 | |
| 4281 | if ( 'suremember_updated_group' === $trigger ) { |
| 4282 | if ( -1 === $post_id ) { |
| 4283 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts as posts WHERE posts.post_type=%s", $post_type ) ); |
| 4284 | } else { |
| 4285 | $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 ) ); |
| 4286 | } |
| 4287 | } else { |
| 4288 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usermeta as usermeta WHERE usermeta.meta_key = %s", 'suremembers_user_access_group_' . $post_id ) ); |
| 4289 | } |
| 4290 | |
| 4291 | $response = []; |
| 4292 | |
| 4293 | if ( ! empty( $result ) ) { |
| 4294 | $context = []; |
| 4295 | switch ( $trigger ) { |
| 4296 | case 'suremember_updated_group': |
| 4297 | $group_id = $result[0]->ID; |
| 4298 | $suremembers_post['rules'] = get_post_meta( $group_id, 'suremembers_plan_include', true ); |
| 4299 | $suremembers_post['exclude'] = get_post_meta( $group_id, 'suremembers_plan_exclude', true ); //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude |
| 4300 | $suremembers_post['suremembers_user_roles'] = get_post_meta( $group_id, 'suremembers_user_roles', true ); |
| 4301 | $suremembers_post['title'] = get_the_title( $group_id ); |
| 4302 | $suremembers_post['restrict'] = get_post_meta( $group_id, 'suremembers_plan_rules', true )['restrict']; |
| 4303 | $context['group'] = array_merge( WordPress::get_post_context( $group_id ), $suremembers_post ); |
| 4304 | $context['group_id'] = $group_id; |
| 4305 | unset( $context['group']['ID'] ); |
| 4306 | $response['pluggable_data'] = $context; |
| 4307 | $response['response_type'] = 'live'; |
| 4308 | break; |
| 4309 | case 'suremember_user_added_in_group': |
| 4310 | foreach ( $result as $res ) { |
| 4311 | $meta_value = unserialize( $res->meta_value ); |
| 4312 | if ( 'active' === $meta_value['status'] ) { |
| 4313 | $context = WordPress::get_user_context( $res->user_id ); |
| 4314 | $context['group'] = WordPress::get_post_context( $post_id ); |
| 4315 | $response['pluggable_data'] = $context; |
| 4316 | $response['response_type'] = 'live'; |
| 4317 | } |
| 4318 | } |
| 4319 | break; |
| 4320 | case 'suremember_user_removed_from_group': |
| 4321 | foreach ( $result as $res ) { |
| 4322 | $meta_value = unserialize( $res->meta_value ); |
| 4323 | if ( 'revoked' === $meta_value['status'] ) { |
| 4324 | $context = WordPress::get_user_context( $res->user_id ); |
| 4325 | $context['group'] = WordPress::get_post_context( $post_id ); |
| 4326 | $response['pluggable_data'] = $context; |
| 4327 | $response['response_type'] = 'live'; |
| 4328 | } |
| 4329 | } |
| 4330 | break; |
| 4331 | default: |
| 4332 | return; |
| 4333 | |
| 4334 | } |
| 4335 | } |
| 4336 | |
| 4337 | return $response; |
| 4338 | |
| 4339 | } |
| 4340 | |
| 4341 | /** |
| 4342 | * Search CartFlows data. |
| 4343 | * |
| 4344 | * @param array $data data. |
| 4345 | * @return array |
| 4346 | */ |
| 4347 | public function search_cartflows_last_data( $data ) { |
| 4348 | global $wpdb; |
| 4349 | $trigger = $data['search_term']; |
| 4350 | $context = []; |
| 4351 | if ( 'cartflows_offer_accepted' === $trigger ) { |
| 4352 | $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'" ); |
| 4353 | } |
| 4354 | $response = []; |
| 4355 | if ( ! empty( $result ) ) { |
| 4356 | $context = []; |
| 4357 | $order_upsell_id = $result[0]->post_id; |
| 4358 | $step_id = get_post_meta( $order_upsell_id, '_cartflows_offer_step_id', true ); |
| 4359 | $order_id = get_post_meta( $order_upsell_id, '_cartflows_offer_parent_id', true ); |
| 4360 | $order = wc_get_order( $order_id ); |
| 4361 | $upsell_order = wc_get_order( $order_upsell_id ); |
| 4362 | $variation_id = $upsell_order->get_items()[0]['product_id']; |
| 4363 | $input_qty = $upsell_order->get_items()[0]['quantity']; |
| 4364 | $offer_product = wcf_pro()->utils->get_offer_data( $step_id, $variation_id, $input_qty, $order_id ); |
| 4365 | $user_id = get_post_meta( $order_upsell_id, '_customer_user', true ); |
| 4366 | $context = WordPress::get_user_context( $user_id ); |
| 4367 | $context['order'] = $order->get_data(); |
| 4368 | $context['upsell'] = $offer_product; |
| 4369 | $response['pluggable_data'] = $context; |
| 4370 | $response['response_type'] = 'live'; |
| 4371 | } |
| 4372 | |
| 4373 | return $response; |
| 4374 | |
| 4375 | } |
| 4376 | |
| 4377 | |
| 4378 | /** |
| 4379 | * Fetch user context. |
| 4380 | * |
| 4381 | * @param int $initiator_id initiator id. |
| 4382 | * @param int $friend_id friend id. |
| 4383 | * @return array |
| 4384 | */ |
| 4385 | public function get_user_context( $initiator_id, $friend_id ) { |
| 4386 | $context = WordPress::get_user_context( $initiator_id ); |
| 4387 | |
| 4388 | $friend_context = WordPress::get_user_context( $friend_id ); |
| 4389 | |
| 4390 | $avatar = get_avatar_url( $initiator_id ); |
| 4391 | |
| 4392 | $context['avatar_url'] = ( $avatar ) ? $avatar : ''; |
| 4393 | |
| 4394 | $context['friend_id'] = $friend_id; |
| 4395 | $context['friend_first_name'] = $friend_context['user_firstname']; |
| 4396 | $context['friend_last_name'] = $friend_context['user_lastname']; |
| 4397 | $context['friend_email'] = $friend_context['user_email']; |
| 4398 | |
| 4399 | $friend_avatar = get_avatar_url( $friend_id ); |
| 4400 | $context['friend_avatar_url'] = $friend_avatar; |
| 4401 | return $context; |
| 4402 | } |
| 4403 | |
| 4404 | /** |
| 4405 | * Search BP data. |
| 4406 | * |
| 4407 | * @param array $data data. |
| 4408 | * @return array |
| 4409 | */ |
| 4410 | public function search_pluggables_bp_friendships( $data ) { |
| 4411 | global $wpdb, $bp; |
| 4412 | $context = []; |
| 4413 | $sample['pluggable_data'] = [ |
| 4414 | 'wp_user_id' => 4, |
| 4415 | 'user_login' => 'katy1ßßßß', |
| 4416 | 'display_name' => 'Katy Smith', |
| 4417 | 'user_firstname' => 'Katy', |
| 4418 | 'user_lastname' => 'Smith', |
| 4419 | 'user_email' => 'katy1@gmail.com', |
| 4420 | 'user_role' => [ 'subscriber' ], |
| 4421 | 'avatar_url' => 'http://pqr.com/avatar', |
| 4422 | 'friend_id' => 1, |
| 4423 | 'friend_first_name' => 'John', |
| 4424 | 'friend_last_name' => 'Wick', |
| 4425 | 'friend_email' => 'john@gmail.com', |
| 4426 | 'friend_avatar_url' => 'http://abc.com/avatar', |
| 4427 | ]; |
| 4428 | $sample['response_type'] = 'sample'; |
| 4429 | |
| 4430 | $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}bp_friends'" ); |
| 4431 | if ( $table_exists ) { |
| 4432 | $friendships = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_friends LIMIT 1" ); |
| 4433 | if ( ! empty( $friendships ) ) { |
| 4434 | $friendship = $friendships[0]; |
| 4435 | $initiator_id = $friendship->initiator_user_id; |
| 4436 | $friend_user_id = $friendship->friend_user_id; |
| 4437 | $context['pluggable_data'] = $this->get_user_context( $initiator_id, $friend_user_id ); |
| 4438 | $context['response_type'] = 'live'; |
| 4439 | } else { |
| 4440 | $context = $sample; |
| 4441 | } |
| 4442 | } else { |
| 4443 | $context = $sample; |
| 4444 | } |
| 4445 | |
| 4446 | |
| 4447 | return $context; |
| 4448 | } |
| 4449 | |
| 4450 | /** |
| 4451 | * Search Buddyboss profile types data. |
| 4452 | * |
| 4453 | * @param array $data data. |
| 4454 | * @return array |
| 4455 | */ |
| 4456 | public function search_pluggables_bp_profile_types( $data ) { |
| 4457 | global $wpdb, $bp; |
| 4458 | $context = []; |
| 4459 | $sample['pluggable_data'] = [ |
| 4460 | 'wp_user_id' => 4, |
| 4461 | 'user_login' => 'katy1ßßßß', |
| 4462 | 'display_name' => 'Katy Smith', |
| 4463 | 'user_firstname' => 'Katy', |
| 4464 | 'user_lastname' => 'Smith', |
| 4465 | 'user_email' => 'katy1@gmail.com', |
| 4466 | 'user_role' => [ 'subscriber' ], |
| 4467 | 'bb_profile_type' => '10', |
| 4468 | 'bb_profile_type_name' => 'student', |
| 4469 | ]; |
| 4470 | $sample['response_type'] = 'sample'; |
| 4471 | |
| 4472 | $post_id = $data['filter']['bb_profile_type']['value']; |
| 4473 | $get_existing = get_post_meta( $post_id, '_bp_member_type_key', true ); |
| 4474 | |
| 4475 | $type_term = get_term_by( |
| 4476 | 'name', |
| 4477 | /** |
| 4478 | * |
| 4479 | * Ignore line |
| 4480 | * |
| 4481 | * @phpstan-ignore-next-line |
| 4482 | */ |
| 4483 | $get_existing, |
| 4484 | 'bp_member_type' |
| 4485 | ); |
| 4486 | |
| 4487 | $results = $wpdb->get_results( |
| 4488 | $wpdb->prepare( |
| 4489 | "SELECT u.ID FROM {$wpdb->prefix}users u INNER JOIN {$wpdb->prefix}term_relationships r |
| 4490 | ON u.ID = r.object_id WHERE u.user_status = 0 AND |
| 4491 | r.term_taxonomy_id = %d ORDER BY RAND() LIMIT 1", |
| 4492 | /** |
| 4493 | * |
| 4494 | * Ignore line |
| 4495 | * |
| 4496 | * @phpstan-ignore-next-line |
| 4497 | */ |
| 4498 | $type_term->term_id |
| 4499 | ) |
| 4500 | ); |
| 4501 | |
| 4502 | if ( ! empty( $results ) ) { |
| 4503 | $user = $results[0]; |
| 4504 | $context['pluggable_data'] = WordPress::get_user_context( $user->ID ); |
| 4505 | $context['pluggable_data']['bb_profile_type'] = $post_id; |
| 4506 | $context['pluggable_data']['bb_profile_type_name'] = get_post_meta( $post_id, '_bp_member_type_label_singular_name', true ); |
| 4507 | $context['response_type'] = 'live'; |
| 4508 | } else { |
| 4509 | $context = $sample; |
| 4510 | } |
| 4511 | |
| 4512 | return $context; |
| 4513 | } |
| 4514 | /** |
| 4515 | * Search BP data. |
| 4516 | * |
| 4517 | * @param array $data data. |
| 4518 | * @return array |
| 4519 | */ |
| 4520 | public function search_pluggables_bp_groups( $data ) { |
| 4521 | global $wpdb, $bp; |
| 4522 | $context = []; |
| 4523 | $group_data = []; |
| 4524 | $args = [ |
| 4525 | 'orderby' => 'user_nicename', |
| 4526 | 'order' => 'ASC', |
| 4527 | 'number' => 1, |
| 4528 | ]; |
| 4529 | |
| 4530 | $users = get_users( $args ); |
| 4531 | |
| 4532 | if ( isset( $data['filter']['group_id']['value'] ) ) { |
| 4533 | $group_id = $data['filter']['group_id']['value']; |
| 4534 | $args['group_id'] = $group_id; |
| 4535 | if ( $group_id > 0 ) { |
| 4536 | $group = groups_get_group( $group_id ); |
| 4537 | $group_data['group_id'] = ( property_exists( $group, 'id' ) ) ? (int) $group->id : ''; |
| 4538 | $group_data['group_name'] = ( property_exists( $group, 'name' ) ) ? $group->name : ''; |
| 4539 | $group_data['group_description'] = ( property_exists( $group, 'description' ) ) ? $group->description : ''; |
| 4540 | } else { |
| 4541 | $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}bp_groups'" ); |
| 4542 | if ( $table_exists ) { |
| 4543 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups LIMIT 1" ); |
| 4544 | $context['groups'] = $groups; |
| 4545 | if ( ! empty( $groups ) ) { |
| 4546 | foreach ( $groups as $group ) { |
| 4547 | $group_data['group_id'] = $group->id; |
| 4548 | $group_data['group_name'] = $group->name; |
| 4549 | $group_data['group_description'] = $group->description; |
| 4550 | } |
| 4551 | } |
| 4552 | } |
| 4553 | } |
| 4554 | } |
| 4555 | |
| 4556 | if ( ! empty( $users ) ) { |
| 4557 | $user = $users[0]; |
| 4558 | $pluggable_data = $group_data; |
| 4559 | |
| 4560 | $avatar = get_avatar_url( $user->ID ); |
| 4561 | $pluggable_data['wp_user_id'] = $user->ID; |
| 4562 | $pluggable_data['avatar_url'] = ( $avatar ) ? $avatar : ''; |
| 4563 | $pluggable_data['user_login'] = $user->user_login; |
| 4564 | $pluggable_data['display_name'] = $user->display_name; |
| 4565 | $pluggable_data['user_firstname'] = $user->user_firstname; |
| 4566 | $pluggable_data['user_lastname'] = $user->user_lastname; |
| 4567 | $pluggable_data['user_email'] = $user->user_email; |
| 4568 | $pluggable_data['user_role'] = $user->roles; |
| 4569 | $context['pluggable_data'] = $pluggable_data; |
| 4570 | $context['response_type'] = 'live'; |
| 4571 | } else { |
| 4572 | $context['pluggable_data'] = [ |
| 4573 | 'wp_user_id' => 1, |
| 4574 | 'user_login' => 'admin', |
| 4575 | 'display_name' => 'Test User', |
| 4576 | 'user_firstname' => 'Test', |
| 4577 | 'user_lastname' => 'User', |
| 4578 | 'user_email' => 'testuser@gmail.com', |
| 4579 | 'user_role' => [ 'subscriber' ], |
| 4580 | 'group_id' => 112, |
| 4581 | 'group_name' => 'Test Group', |
| 4582 | 'group_description' => 'Test Group Description', |
| 4583 | ]; |
| 4584 | $context['response_type'] = 'sample'; |
| 4585 | } |
| 4586 | |
| 4587 | return $context; |
| 4588 | } |
| 4589 | |
| 4590 | /** |
| 4591 | * Search complete courses. |
| 4592 | * |
| 4593 | * @param array $data data. |
| 4594 | * @return array |
| 4595 | */ |
| 4596 | public function search_pluggables_complete_course( $data ) { |
| 4597 | global $wpdb; |
| 4598 | $context = []; |
| 4599 | |
| 4600 | if ( isset( $data['filter']['sfwd_course_id']['value'] ) ) { |
| 4601 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 4602 | } |
| 4603 | if ( -1 === $course_id ) { |
| 4604 | $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 ) ); |
| 4605 | } else { |
| 4606 | $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 ) ); |
| 4607 | } |
| 4608 | |
| 4609 | if ( ! empty( $courses ) ) { |
| 4610 | $course = $courses[0]; |
| 4611 | $course_data['course_name'] = $course->post_title; |
| 4612 | $course_data['sfwd_course_id'] = $course->ID; |
| 4613 | $course_data['course_url'] = get_permalink( $course->ID ); |
| 4614 | $course_data['course_featured_image_id'] = get_post_meta( $course->ID, '_thumbnail_id', true ); |
| 4615 | $course_data['course_featured_image_url'] = get_the_post_thumbnail_url( $course->ID ); |
| 4616 | $context['response_type'] = 'live'; |
| 4617 | } else { |
| 4618 | $course_data['course_name'] = 'Test Course'; |
| 4619 | $course_data['sfwd_course_id'] = 112; |
| 4620 | $course_data['course_url'] = 'https://abc.com/test-course'; |
| 4621 | $course_data['course_featured_image_id'] = 113; |
| 4622 | $course_data['course_featured_image_url'] = 'https://pqr.com/test-course-img'; |
| 4623 | $context['response_type'] = 'sample'; |
| 4624 | } |
| 4625 | |
| 4626 | $users_data = $this->search_pluggables_add_user_role( [] ); |
| 4627 | $user_data = $users_data['pluggable_data']; |
| 4628 | |
| 4629 | $context['pluggable_data'] = array_merge( $course_data, $user_data ); |
| 4630 | return $context; |
| 4631 | } |
| 4632 | |
| 4633 | /** |
| 4634 | * Search lessons. |
| 4635 | * |
| 4636 | * @param array $data data. |
| 4637 | * @return array |
| 4638 | */ |
| 4639 | public function search_pluggables_complete_lesson( $data ) { |
| 4640 | global $wpdb; |
| 4641 | $context = []; |
| 4642 | |
| 4643 | if ( isset( $data['filter']['sfwd_lesson_id']['value'] ) ) { |
| 4644 | $lesson_id = $data['filter']['sfwd_lesson_id']['value']; |
| 4645 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 4646 | } |
| 4647 | $course = get_post( $course_id ); |
| 4648 | $pluggable_data = LearnDash::get_course_context( $course ); |
| 4649 | |
| 4650 | if ( -1 === $lesson_id ) { |
| 4651 | $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 ) ); |
| 4652 | } else { |
| 4653 | $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 ) ); |
| 4654 | } |
| 4655 | |
| 4656 | if ( ! empty( $lessons ) ) { |
| 4657 | $lesson = $lessons[0]; |
| 4658 | |
| 4659 | $pluggable_data = WordPress::get_user_context( $lesson->user_id ); |
| 4660 | $pluggable_data['lesson_name'] = $lesson->post_title; |
| 4661 | $pluggable_data['sfwd_lesson_id'] = $lesson->ID; |
| 4662 | $pluggable_data['lesson_url'] = get_permalink( $lesson->ID ); |
| 4663 | $pluggable_data['lesson_featured_image_id'] = get_post_meta( $lesson->ID, '_thumbnail_id', true ); |
| 4664 | $pluggable_data['lesson_featured_image_url'] = get_the_post_thumbnail_url( $lesson->ID ); |
| 4665 | $context['response_type'] = 'live'; |
| 4666 | } else { |
| 4667 | $pluggable_data = WordPress::get_sample_user_context(); |
| 4668 | $pluggable_data['lesson_name'] = 'Test Lesson'; |
| 4669 | $pluggable_data['sfwd_lesson_id'] = 114; |
| 4670 | $pluggable_data['lesson_url'] = 'https://abc.com/test-lesson'; |
| 4671 | $pluggable_data['lesson_featured_image_id'] = 116; |
| 4672 | $pluggable_data['lesson_featured_image_url'] = 'https://pqr.com/test-lesson-img'; |
| 4673 | $context['response_type'] = 'sample'; |
| 4674 | } |
| 4675 | |
| 4676 | $context['pluggable_data'] = $pluggable_data; |
| 4677 | return $context; |
| 4678 | } |
| 4679 | |
| 4680 | /** |
| 4681 | * Search topics. |
| 4682 | * |
| 4683 | * @param array $data data. |
| 4684 | * @return array |
| 4685 | */ |
| 4686 | public function search_pluggables_complete_topic( $data ) { |
| 4687 | global $wpdb; |
| 4688 | $context = []; |
| 4689 | |
| 4690 | if ( isset( $data['filter']['sfwd_topic_id']['value'] ) ) { |
| 4691 | $topic_id = $data['filter']['sfwd_topic_id']['value']; |
| 4692 | $course_id = $data['filter']['sfwd_course_id']['value']; |
| 4693 | } |
| 4694 | $course = get_post( $course_id ); |
| 4695 | $pluggable_data = LearnDash::get_course_context( $course ); |
| 4696 | |
| 4697 | if ( -1 === $topic_id ) { |
| 4698 | $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 ) ); |
| 4699 | } else { |
| 4700 | $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 ) ); |
| 4701 | } |
| 4702 | |
| 4703 | if ( ! empty( $topics ) ) { |
| 4704 | $topic = $topics[0]; |
| 4705 | $pluggable_data = WordPress::get_user_context( $topics[0]->user_id ); |
| 4706 | $pluggable_data['topic_name'] = $topic->post_title; |
| 4707 | $pluggable_data['sfwd_topic_id'] = $topic->ID; |
| 4708 | $pluggable_data['topic_url'] = get_permalink( $topic->ID ); |
| 4709 | $pluggable_data['topic_featured_image_id'] = get_post_meta( $topic->ID, '_thumbnail_id', true ); |
| 4710 | $pluggable_data['topic_featured_image_url'] = get_the_post_thumbnail_url( $topic->ID ); |
| 4711 | $context['response_type'] = 'live'; |
| 4712 | } else { |
| 4713 | $pluggable_data = WordPress::get_sample_user_context(); |
| 4714 | $pluggable_data['topic_name'] = 'Test Topic'; |
| 4715 | $pluggable_data['sfwd_topic_id'] = 117; |
| 4716 | $pluggable_data['topic_url'] = 'https://abc.com/test-topic'; |
| 4717 | $pluggable_data['topic_featured_image_id'] = 118; |
| 4718 | $pluggable_data['topic_featured_image_url'] = 'https://pqr.com/test-topic-img'; |
| 4719 | $context['response_type'] = 'sample'; |
| 4720 | } |
| 4721 | |
| 4722 | $context['pluggable_data'] = $pluggable_data; |
| 4723 | return $context; |
| 4724 | } |
| 4725 | |
| 4726 | /** |
| 4727 | * Search purchase courses. |
| 4728 | * |
| 4729 | * @param array $data data. |
| 4730 | * @return array |
| 4731 | */ |
| 4732 | public function search_pluggables_purchase_course( $data ) { |
| 4733 | $context = []; |
| 4734 | $context['response_type'] = 'sample'; |
| 4735 | |
| 4736 | $purchase_data = [ |
| 4737 | 'course_product_id' => '1', |
| 4738 | 'course_product_name' => 'Sample Course', |
| 4739 | 'currency' => 'USD', |
| 4740 | 'total_amount' => '100', |
| 4741 | 'first_name' => 'John', |
| 4742 | 'last_name' => 'Doe', |
| 4743 | 'email' => 'john_doe@bsf.io', |
| 4744 | 'phone' => '+923007626541', |
| 4745 | ]; |
| 4746 | |
| 4747 | $product_id = (int) ( isset( $data['filter']['course_product_id']['value'] ) ? $data['filter']['course_product_id']['value'] : '-1' ); |
| 4748 | $order_id = 0; |
| 4749 | |
| 4750 | if ( -1 !== $product_id ) { |
| 4751 | $order_ids = ( new Utilities() )->get_orders_ids_by_product_id( $product_id ); |
| 4752 | |
| 4753 | if ( count( $order_ids ) > 0 ) { |
| 4754 | $order_id = $order_ids[0]; |
| 4755 | } |
| 4756 | } else { |
| 4757 | $orders = wc_get_orders( [] ); |
| 4758 | if ( count( $orders ) > 0 ) { |
| 4759 | foreach ( $orders as $order ) { |
| 4760 | $items = $order->get_items(); |
| 4761 | |
| 4762 | if ( count( $items ) > 1 ) { |
| 4763 | continue; |
| 4764 | } |
| 4765 | |
| 4766 | foreach ( $items as $item ) { |
| 4767 | if ( method_exists( $item, 'get_product_id' ) ) { |
| 4768 | $product_id = $item->get_product_id(); |
| 4769 | if ( ! empty( get_post_meta( $item->get_product_id(), '_related_course', true ) ) ) { |
| 4770 | $order_id = $order->get_id(); |
| 4771 | break; |
| 4772 | } |
| 4773 | } |
| 4774 | } |
| 4775 | } |
| 4776 | } |
| 4777 | } |
| 4778 | |
| 4779 | if ( 0 !== $order_id ) { |
| 4780 | $order = wc_get_order( $order_id ); |
| 4781 | |
| 4782 | if ( $order ) { |
| 4783 | |
| 4784 | $purchase_data = LearnDash::get_purchase_course_context( $order ); |
| 4785 | |
| 4786 | $context['response_type'] = 'live'; |
| 4787 | } |
| 4788 | } |
| 4789 | |
| 4790 | $context['pluggable_data'] = $purchase_data; |
| 4791 | |
| 4792 | return $context; |
| 4793 | } |
| 4794 | |
| 4795 | /** |
| 4796 | * Fetch BB templates. |
| 4797 | * |
| 4798 | * @return array |
| 4799 | */ |
| 4800 | public function get_beaver_builder_templates() { |
| 4801 | $allowed_types = [ 'subscribe-form', 'contact-form' ]; |
| 4802 | $templates = []; |
| 4803 | $all_templates = get_posts( |
| 4804 | [ |
| 4805 | 'post_type' => 'fl-builder-template', |
| 4806 | 'meta_key' => '_fl_builder_data', |
| 4807 | 'posts_per_page' => -1, |
| 4808 | ] |
| 4809 | ); |
| 4810 | $posts = get_posts( |
| 4811 | [ |
| 4812 | 'post_type' => 'any', |
| 4813 | 'meta_key' => '_fl_builder_data', |
| 4814 | 'posts_per_page' => -1, |
| 4815 | ] |
| 4816 | ); |
| 4817 | $posts = array_merge( $all_templates, $posts ); |
| 4818 | |
| 4819 | if ( ! empty( $posts ) ) { |
| 4820 | foreach ( $posts as $post ) { |
| 4821 | $meta = get_post_meta( $post->ID, '_fl_builder_data', true ); |
| 4822 | foreach ( (array) $meta as $node_id => $node ) { |
| 4823 | if ( isset( $node->type ) && 'module' === $node->type ) { |
| 4824 | $settings = $node->settings; |
| 4825 | if ( in_array( $settings->type, $allowed_types, true ) ) { |
| 4826 | $label = $post->post_title; |
| 4827 | if ( '' !== $settings->node_label ) { |
| 4828 | $label .= ' - ' . $settings->node_label; |
| 4829 | } |
| 4830 | $templates[] = [ |
| 4831 | 'label' => $label, |
| 4832 | 'value' => $node_id, |
| 4833 | ]; |
| 4834 | } |
| 4835 | } |
| 4836 | } |
| 4837 | } |
| 4838 | } |
| 4839 | return $templates; |
| 4840 | } |
| 4841 | |
| 4842 | /** |
| 4843 | * Search beaver builder forms. |
| 4844 | * |
| 4845 | * @param array $data data. |
| 4846 | * @return array |
| 4847 | */ |
| 4848 | public function search_beaver_builder_forms( $data ) { |
| 4849 | $templates = $this->get_beaver_builder_templates(); |
| 4850 | return [ |
| 4851 | 'options' => $templates, |
| 4852 | 'hasMore' => false, |
| 4853 | ]; |
| 4854 | } |
| 4855 | |
| 4856 | /** |
| 4857 | * Search fluentcrm fields. |
| 4858 | * |
| 4859 | * @param array $data data. |
| 4860 | * @return array |
| 4861 | */ |
| 4862 | public function search_fluentcrm_custom_fields( $data ) { |
| 4863 | $context = []; |
| 4864 | $custom_fields = ( new CustomContactField() )->getGlobalFields()['fields']; |
| 4865 | $context['fields'] = $custom_fields; |
| 4866 | return $context; |
| 4867 | } |
| 4868 | |
| 4869 | /** |
| 4870 | * Fetch WP JOB Manager Last Data. |
| 4871 | * |
| 4872 | * @param array $data data. |
| 4873 | * @return array |
| 4874 | */ |
| 4875 | public function search_wp_job_manger_last_data( $data ) { |
| 4876 | global $wpdb; |
| 4877 | $job_type = $data['filter']['job_type']['value']; |
| 4878 | $args = [ |
| 4879 | 'posts_per_page' => 1, |
| 4880 | 'post_type' => 'job_listing', |
| 4881 | 'orderby' => 'id', |
| 4882 | 'order' => 'DESC', |
| 4883 | ]; |
| 4884 | |
| 4885 | if ( -1 !== $job_type ) { |
| 4886 | $args['tax_query'] = [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query |
| 4887 | [ |
| 4888 | 'taxonomy' => 'job_listing_type', |
| 4889 | 'field' => 'term_id', |
| 4890 | 'terms' => $job_type, |
| 4891 | ], |
| 4892 | ]; |
| 4893 | } |
| 4894 | $posts = get_posts( $args ); |
| 4895 | if ( empty( $posts ) ) { |
| 4896 | $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 ); |
| 4897 | return $context; |
| 4898 | } |
| 4899 | |
| 4900 | $post = $posts[0]; |
| 4901 | $post_content = WordPress::get_post_context( $post->ID ); |
| 4902 | $post_meta = WordPress::get_post_meta( $post->ID ); |
| 4903 | $job_data = array_merge( $post_content, $post_meta, WordPress::get_user_context( $post->post_author ) ); |
| 4904 | foreach ( $job_data as $key => $job ) { |
| 4905 | $newkey = str_replace( 'post', 'wpjob', $key ); |
| 4906 | unset( $job_data[ $key ] ); |
| 4907 | $job_data[ $newkey ] = $job; |
| 4908 | } |
| 4909 | $context['response_type'] = 'live'; |
| 4910 | $context['pluggable_data'] = $job_data; |
| 4911 | return $context; |
| 4912 | |
| 4913 | } |
| 4914 | |
| 4915 | /** |
| 4916 | * Get Amelia Appointment Category. |
| 4917 | * |
| 4918 | * @param array $data data. |
| 4919 | * |
| 4920 | * @return array |
| 4921 | */ |
| 4922 | public function search_amelia_category_list( $data ) { |
| 4923 | |
| 4924 | global $wpdb; |
| 4925 | |
| 4926 | $page = $data['page']; |
| 4927 | $limit = Utilities::get_search_page_limit(); |
| 4928 | $offset = $limit * ( $page - 1 ); |
| 4929 | |
| 4930 | $categories = $wpdb->get_results( |
| 4931 | $wpdb->prepare( |
| 4932 | "SELECT SQL_CALC_FOUND_ROWS id, name FROM {$wpdb->prefix}amelia_categories WHERE status = %s ORDER BY name ASC LIMIT %d OFFSET %d", |
| 4933 | [ 'visible', $limit, $offset ] |
| 4934 | ), |
| 4935 | OBJECT |
| 4936 | ); |
| 4937 | |
| 4938 | $categories_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 4939 | |
| 4940 | $options = []; |
| 4941 | if ( ! empty( $categories ) ) { |
| 4942 | foreach ( $categories as $category ) { |
| 4943 | $options[] = [ |
| 4944 | 'label' => $category->name, |
| 4945 | 'value' => $category->id, |
| 4946 | ]; |
| 4947 | } |
| 4948 | } |
| 4949 | |
| 4950 | return [ |
| 4951 | 'options' => $options, |
| 4952 | 'hasMore' => $categories_count > $limit && $categories_count > $offset, |
| 4953 | ]; |
| 4954 | |
| 4955 | } |
| 4956 | |
| 4957 | /** |
| 4958 | * Get Amelia Appointment Services. |
| 4959 | * |
| 4960 | * @param array $data data. |
| 4961 | * |
| 4962 | * @return array |
| 4963 | */ |
| 4964 | public function search_amelia_service_list( $data ) { |
| 4965 | |
| 4966 | global $wpdb; |
| 4967 | |
| 4968 | $page = $data['page']; |
| 4969 | $limit = Utilities::get_search_page_limit(); |
| 4970 | $offset = $limit * ( $page - 1 ); |
| 4971 | |
| 4972 | $services = $wpdb->get_results( |
| 4973 | $wpdb->prepare( |
| 4974 | "SELECT SQL_CALC_FOUND_ROWS id, name FROM {$wpdb->prefix}amelia_services |
| 4975 | WHERE categoryId = %d AND status = %s |
| 4976 | ORDER BY name ASC LIMIT %d OFFSET %d", |
| 4977 | [ $data['dynamic'], 'visible', $limit, $offset ] |
| 4978 | ), |
| 4979 | OBJECT |
| 4980 | ); |
| 4981 | |
| 4982 | $services_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 4983 | |
| 4984 | $options = []; |
| 4985 | if ( ! empty( $services ) ) { |
| 4986 | foreach ( $services as $category ) { |
| 4987 | $options[] = [ |
| 4988 | 'label' => $category->name, |
| 4989 | 'value' => $category->id, |
| 4990 | ]; |
| 4991 | } |
| 4992 | } |
| 4993 | |
| 4994 | return [ |
| 4995 | 'options' => $options, |
| 4996 | 'hasMore' => $services_count > $limit && $services_count > $offset, |
| 4997 | ]; |
| 4998 | |
| 4999 | } |
| 5000 | |
| 5001 | /** |
| 5002 | * Get Amelia Events. |
| 5003 | * |
| 5004 | * @param array $data data. |
| 5005 | * |
| 5006 | * @return array |
| 5007 | */ |
| 5008 | public function search_amelia_events_list( $data ) { |
| 5009 | |
| 5010 | global $wpdb; |
| 5011 | |
| 5012 | $page = $data['page']; |
| 5013 | $limit = Utilities::get_search_page_limit(); |
| 5014 | $offset = $limit * ( $page - 1 ); |
| 5015 | |
| 5016 | $events = $wpdb->get_results( |
| 5017 | $wpdb->prepare( |
| 5018 | "SELECT SQL_CALC_FOUND_ROWS id, name from {$wpdb->prefix}amelia_events WHERE status = %s ORDER BY name ASC LIMIT %d OFFSET %d", |
| 5019 | [ 'approved', $limit, $offset ] |
| 5020 | ), |
| 5021 | OBJECT |
| 5022 | ); |
| 5023 | |
| 5024 | $list_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5025 | |
| 5026 | $options = []; |
| 5027 | if ( ! empty( $events ) ) { |
| 5028 | foreach ( $events as $event ) { |
| 5029 | $options[] = [ |
| 5030 | 'label' => $event->name, |
| 5031 | 'value' => $event->id, |
| 5032 | ]; |
| 5033 | } |
| 5034 | } |
| 5035 | |
| 5036 | return [ |
| 5037 | 'options' => $options, |
| 5038 | 'hasMore' => $list_count > $limit && $list_count > $offset, |
| 5039 | ]; |
| 5040 | |
| 5041 | } |
| 5042 | |
| 5043 | /** |
| 5044 | * Get last data for trigger. |
| 5045 | * |
| 5046 | * @param array $data data. |
| 5047 | * @return array |
| 5048 | */ |
| 5049 | public function search_amelia_appointment_booked_triggers_last_data( $data ) { |
| 5050 | global $wpdb; |
| 5051 | |
| 5052 | $context = []; |
| 5053 | |
| 5054 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 5055 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 5056 | |
| 5057 | if ( -1 === $appointment_service ) { |
| 5058 | // If service exists as per category selected. |
| 5059 | $service_exist = $wpdb->get_row( |
| 5060 | $wpdb->prepare( |
| 5061 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 5062 | [ $appointment_category ] |
| 5063 | ), |
| 5064 | ARRAY_A |
| 5065 | ); |
| 5066 | |
| 5067 | if ( empty( $service_exist ) ) { |
| 5068 | $result = []; |
| 5069 | } else { |
| 5070 | $result = $wpdb->get_row( |
| 5071 | '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 )', |
| 5072 | ARRAY_A |
| 5073 | ); |
| 5074 | } |
| 5075 | } else { |
| 5076 | $result = $wpdb->get_row( |
| 5077 | $wpdb->prepare( |
| 5078 | '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', |
| 5079 | [ $appointment_service ] |
| 5080 | ), |
| 5081 | ARRAY_A |
| 5082 | ); |
| 5083 | } |
| 5084 | |
| 5085 | if ( ! empty( $result ) ) { |
| 5086 | |
| 5087 | $payment_result = $wpdb->get_row( |
| 5088 | $wpdb->prepare( |
| 5089 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 5090 | [ $result['id'] ] |
| 5091 | ), |
| 5092 | ARRAY_A |
| 5093 | ); |
| 5094 | |
| 5095 | $customer_result = $wpdb->get_row( |
| 5096 | $wpdb->prepare( |
| 5097 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 5098 | [ $result['customerId'] ] |
| 5099 | ), |
| 5100 | ARRAY_A |
| 5101 | ); |
| 5102 | |
| 5103 | $service_result = $wpdb->get_row( |
| 5104 | $wpdb->prepare( |
| 5105 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 5106 | [ $result['serviceId'] ] |
| 5107 | ), |
| 5108 | ARRAY_A |
| 5109 | ); |
| 5110 | |
| 5111 | $category_result = $wpdb->get_row( |
| 5112 | $wpdb->prepare( |
| 5113 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 5114 | [ $service_result['categoryId'] ] |
| 5115 | ), |
| 5116 | ARRAY_A |
| 5117 | ); |
| 5118 | |
| 5119 | if ( $result['couponId'] ) { |
| 5120 | $coupon_result = $wpdb->get_row( |
| 5121 | $wpdb->prepare( |
| 5122 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 5123 | [ $result['couponId'] ] |
| 5124 | ), |
| 5125 | ARRAY_A |
| 5126 | ); |
| 5127 | } else { |
| 5128 | $coupon_result = []; |
| 5129 | } |
| 5130 | |
| 5131 | if ( ! empty( $result['customFields'] ) ) { |
| 5132 | $custom_fields = json_decode( $result['customFields'], true ); |
| 5133 | |
| 5134 | $fields_arr = []; |
| 5135 | foreach ( (array) $custom_fields as $fields ) { |
| 5136 | if ( is_array( $fields ) ) { |
| 5137 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 5138 | } |
| 5139 | } |
| 5140 | unset( $result['customFields'] ); |
| 5141 | } else { |
| 5142 | $fields_arr = []; |
| 5143 | } |
| 5144 | |
| 5145 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 5146 | $context['response_type'] = 'live'; |
| 5147 | } else { |
| 5148 | |
| 5149 | $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","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","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","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 ); |
| 5150 | } |
| 5151 | |
| 5152 | return $context; |
| 5153 | } |
| 5154 | |
| 5155 | /** |
| 5156 | * Get last data for trigger. |
| 5157 | * |
| 5158 | * @param array $data data. |
| 5159 | * @return array |
| 5160 | */ |
| 5161 | public function search_amelia_new_event_attendee_triggers_last_data( $data ) { |
| 5162 | global $wpdb; |
| 5163 | |
| 5164 | $context = []; |
| 5165 | |
| 5166 | $event_selected = $data['filter']['amelia_events_list']['value']; |
| 5167 | |
| 5168 | if ( -1 === $event_selected ) { |
| 5169 | $result = $wpdb->get_row( |
| 5170 | 'SELECT * |
| 5171 | FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer |
| 5172 | INNER JOIN ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods as event_period |
| 5173 | ON customer.id = event_period.customerBookingId |
| 5174 | WHERE event_period.customerBookingId = ( Select max(customerBookingId) From ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods )', |
| 5175 | ARRAY_A |
| 5176 | ); |
| 5177 | } else { |
| 5178 | $result = $wpdb->get_row( |
| 5179 | $wpdb->prepare( |
| 5180 | 'SELECT * |
| 5181 | FROM ' . $wpdb->prefix . 'amelia_customer_bookings as customer |
| 5182 | INNER JOIN ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods as event_period |
| 5183 | ON customer.id = event_period.customerBookingId |
| 5184 | WHERE event_period.customerBookingId = ( Select max(customerBookingId) From ' . $wpdb->prefix . 'amelia_customer_bookings_to_events_periods ) AND eventPeriodId = %d', |
| 5185 | [ $event_selected ] |
| 5186 | ), |
| 5187 | ARRAY_A |
| 5188 | ); |
| 5189 | } |
| 5190 | |
| 5191 | if ( ! empty( $result ) ) { |
| 5192 | |
| 5193 | $event = $wpdb->get_row( |
| 5194 | $wpdb->prepare( |
| 5195 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_events WHERE id = %d', |
| 5196 | [ $result['eventPeriodId'] ] |
| 5197 | ), |
| 5198 | ARRAY_A |
| 5199 | ); |
| 5200 | |
| 5201 | $customer_result = $wpdb->get_row( |
| 5202 | $wpdb->prepare( |
| 5203 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 5204 | [ $result['customerId'] ] |
| 5205 | ), |
| 5206 | ARRAY_A |
| 5207 | ); |
| 5208 | |
| 5209 | if ( $result['couponId'] ) { |
| 5210 | $coupon_result = $wpdb->get_row( |
| 5211 | $wpdb->prepare( |
| 5212 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 5213 | [ $result['couponId'] ] |
| 5214 | ), |
| 5215 | ARRAY_A |
| 5216 | ); |
| 5217 | } else { |
| 5218 | $coupon_result = []; |
| 5219 | } |
| 5220 | |
| 5221 | if ( ! empty( $result['customFields'] ) ) { |
| 5222 | $custom_fields = json_decode( $result['customFields'], true ); |
| 5223 | |
| 5224 | $fields_arr = []; |
| 5225 | foreach ( (array) $custom_fields as $fields ) { |
| 5226 | if ( is_array( $fields ) ) { |
| 5227 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 5228 | } |
| 5229 | } |
| 5230 | unset( $result['customFields'] ); |
| 5231 | } else { |
| 5232 | $fields_arr = []; |
| 5233 | } |
| 5234 | |
| 5235 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $event, $customer_result, $coupon_result ); |
| 5236 | $context['response_type'] = 'live'; |
| 5237 | } else { |
| 5238 | |
| 5239 | $context = json_decode( '{"response_type":"sample","pluggable_data":{""id":"1","appointmentId":null,"customerId":"1","status":"visible","price":"10","persons":"1","couponId":null,"token":"6485b07ce9","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","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","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 ); |
| 5240 | } |
| 5241 | |
| 5242 | return $context; |
| 5243 | } |
| 5244 | |
| 5245 | /** |
| 5246 | * Get last data for trigger. |
| 5247 | * |
| 5248 | * @param array $data data. |
| 5249 | * @return array |
| 5250 | */ |
| 5251 | public function search_amelia_appointment_rescheduled_triggers_last_data( $data ) { |
| 5252 | global $wpdb; |
| 5253 | |
| 5254 | $context = []; |
| 5255 | |
| 5256 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 5257 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 5258 | |
| 5259 | if ( -1 === $appointment_service ) { |
| 5260 | // If service exists as per category selected. |
| 5261 | $service_exist = $wpdb->get_row( |
| 5262 | $wpdb->prepare( |
| 5263 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 5264 | [ $appointment_category ] |
| 5265 | ), |
| 5266 | ARRAY_A |
| 5267 | ); |
| 5268 | |
| 5269 | if ( empty( $service_exist ) ) { |
| 5270 | $result = []; |
| 5271 | } else { |
| 5272 | $result = $wpdb->get_row( |
| 5273 | '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 )', |
| 5274 | ARRAY_A |
| 5275 | ); |
| 5276 | } |
| 5277 | } else { |
| 5278 | $result = $wpdb->get_row( |
| 5279 | $wpdb->prepare( |
| 5280 | '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', |
| 5281 | [ $appointment_service ] |
| 5282 | ), |
| 5283 | ARRAY_A |
| 5284 | ); |
| 5285 | } |
| 5286 | |
| 5287 | if ( ! empty( $result ) ) { |
| 5288 | |
| 5289 | $payment_result = $wpdb->get_row( |
| 5290 | $wpdb->prepare( |
| 5291 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 5292 | [ $result['id'] ] |
| 5293 | ), |
| 5294 | ARRAY_A |
| 5295 | ); |
| 5296 | |
| 5297 | $customer_result = $wpdb->get_row( |
| 5298 | $wpdb->prepare( |
| 5299 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 5300 | [ $result['customerId'] ] |
| 5301 | ), |
| 5302 | ARRAY_A |
| 5303 | ); |
| 5304 | |
| 5305 | $service_result = $wpdb->get_row( |
| 5306 | $wpdb->prepare( |
| 5307 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 5308 | [ $result['serviceId'] ] |
| 5309 | ), |
| 5310 | ARRAY_A |
| 5311 | ); |
| 5312 | |
| 5313 | $category_result = $wpdb->get_row( |
| 5314 | $wpdb->prepare( |
| 5315 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 5316 | [ $service_result['categoryId'] ] |
| 5317 | ), |
| 5318 | ARRAY_A |
| 5319 | ); |
| 5320 | |
| 5321 | if ( $result['couponId'] ) { |
| 5322 | $coupon_result = $wpdb->get_row( |
| 5323 | $wpdb->prepare( |
| 5324 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 5325 | [ $result['couponId'] ] |
| 5326 | ), |
| 5327 | ARRAY_A |
| 5328 | ); |
| 5329 | } else { |
| 5330 | $coupon_result = []; |
| 5331 | } |
| 5332 | |
| 5333 | if ( ! empty( $result['customFields'] ) ) { |
| 5334 | $custom_fields = json_decode( $result['customFields'], true ); |
| 5335 | |
| 5336 | $fields_arr = []; |
| 5337 | foreach ( (array) $custom_fields as $fields ) { |
| 5338 | if ( is_array( $fields ) ) { |
| 5339 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 5340 | } |
| 5341 | } |
| 5342 | unset( $result['customFields'] ); |
| 5343 | } else { |
| 5344 | $fields_arr = []; |
| 5345 | } |
| 5346 | |
| 5347 | $appointment_data['isRescheduled'] = '1'; |
| 5348 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $appointment_data, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 5349 | $context['response_type'] = 'live'; |
| 5350 | } else { |
| 5351 | |
| 5352 | $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","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","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","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 ); |
| 5353 | } |
| 5354 | |
| 5355 | return $context; |
| 5356 | } |
| 5357 | |
| 5358 | |
| 5359 | /** |
| 5360 | * Get last data for trigger. |
| 5361 | * |
| 5362 | * @param array $data data. |
| 5363 | * @return array |
| 5364 | */ |
| 5365 | public function search_amelia_appointment_cancelled_triggers_last_data( $data ) { |
| 5366 | global $wpdb; |
| 5367 | |
| 5368 | $context = []; |
| 5369 | |
| 5370 | $appointment_category = $data['filter']['amelia_category_list']['value']; |
| 5371 | $appointment_service = $data['filter']['amelia_service_list']['value']; |
| 5372 | |
| 5373 | if ( -1 === $appointment_service ) { |
| 5374 | // If service exists as per category selected. |
| 5375 | $service_exist = $wpdb->get_row( |
| 5376 | $wpdb->prepare( |
| 5377 | 'SELECT id, name, description FROM ' . $wpdb->prefix . 'amelia_services WHERE categoryId = %d', |
| 5378 | [ $appointment_category ] |
| 5379 | ), |
| 5380 | ARRAY_A |
| 5381 | ); |
| 5382 | |
| 5383 | if ( empty( $service_exist ) ) { |
| 5384 | $result = []; |
| 5385 | } else { |
| 5386 | $result = $wpdb->get_row( |
| 5387 | $wpdb->prepare( |
| 5388 | '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', |
| 5389 | [ 'canceled' ] |
| 5390 | ), |
| 5391 | ARRAY_A |
| 5392 | ); |
| 5393 | } |
| 5394 | } else { |
| 5395 | $result = $wpdb->get_row( |
| 5396 | $wpdb->prepare( |
| 5397 | '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', |
| 5398 | [ 'canceled', $appointment_service ] |
| 5399 | ), |
| 5400 | ARRAY_A |
| 5401 | ); |
| 5402 | } |
| 5403 | |
| 5404 | if ( ! empty( $result ) ) { |
| 5405 | |
| 5406 | $payment_result = $wpdb->get_row( |
| 5407 | $wpdb->prepare( |
| 5408 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_payments WHERE customerBookingId = %d', |
| 5409 | [ $result['id'] ] |
| 5410 | ), |
| 5411 | ARRAY_A |
| 5412 | ); |
| 5413 | |
| 5414 | $customer_result = $wpdb->get_row( |
| 5415 | $wpdb->prepare( |
| 5416 | 'SELECT * FROM ' . $wpdb->prefix . 'amelia_users WHERE id = %d', |
| 5417 | [ $result['customerId'] ] |
| 5418 | ), |
| 5419 | ARRAY_A |
| 5420 | ); |
| 5421 | |
| 5422 | $service_result = $wpdb->get_row( |
| 5423 | $wpdb->prepare( |
| 5424 | 'SELECT name AS serviceName, description AS serviceDescription, categoryId FROM ' . $wpdb->prefix . 'amelia_services WHERE id = %d', |
| 5425 | [ $result['serviceId'] ] |
| 5426 | ), |
| 5427 | ARRAY_A |
| 5428 | ); |
| 5429 | |
| 5430 | $category_result = $wpdb->get_row( |
| 5431 | $wpdb->prepare( |
| 5432 | 'SELECT name AS categoryName FROM ' . $wpdb->prefix . 'amelia_categories WHERE id = %d', |
| 5433 | [ $service_result['categoryId'] ] |
| 5434 | ), |
| 5435 | ARRAY_A |
| 5436 | ); |
| 5437 | |
| 5438 | if ( $result['couponId'] ) { |
| 5439 | $coupon_result = $wpdb->get_row( |
| 5440 | $wpdb->prepare( |
| 5441 | 'SELECT code AS couponCode, expirationDate AS couponExpirationDate FROM ' . $wpdb->prefix . 'amelia_coupons WHERE id = %d', |
| 5442 | [ $result['couponId'] ] |
| 5443 | ), |
| 5444 | ARRAY_A |
| 5445 | ); |
| 5446 | } else { |
| 5447 | $coupon_result = []; |
| 5448 | } |
| 5449 | |
| 5450 | if ( ! empty( $result['customFields'] ) ) { |
| 5451 | $custom_fields = json_decode( $result['customFields'], true ); |
| 5452 | |
| 5453 | $fields_arr = []; |
| 5454 | foreach ( (array) $custom_fields as $fields ) { |
| 5455 | if ( is_array( $fields ) ) { |
| 5456 | $fields_arr[ $fields['label'] ] = $fields['value']; |
| 5457 | } |
| 5458 | } |
| 5459 | unset( $result['customFields'] ); |
| 5460 | } else { |
| 5461 | $fields_arr = []; |
| 5462 | } |
| 5463 | |
| 5464 | $context['pluggable_data'] = array_merge( $result, $fields_arr, $payment_result, $customer_result, $service_result, $category_result, $coupon_result ); |
| 5465 | $context['response_type'] = 'live'; |
| 5466 | } else { |
| 5467 | |
| 5468 | $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","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","Do You Know Automation?":"Yes","When Are You Coming?":"2023-04-20","Upload Something":"","Tell Us About You!":"Hey there!","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 ); |
| 5469 | } |
| 5470 | |
| 5471 | return $context; |
| 5472 | } |
| 5473 | |
| 5474 | /** |
| 5475 | * Get MailPoet Forms. |
| 5476 | * |
| 5477 | * @param array $data data. |
| 5478 | * |
| 5479 | * @return array |
| 5480 | */ |
| 5481 | public function search_mailpoet_forms( $data ) { |
| 5482 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5483 | return; |
| 5484 | } |
| 5485 | |
| 5486 | global $wpdb; |
| 5487 | |
| 5488 | $page = $data['page']; |
| 5489 | $limit = Utilities::get_search_page_limit(); |
| 5490 | $offset = $limit * ( $page - 1 ); |
| 5491 | |
| 5492 | $forms = $wpdb->get_results( |
| 5493 | $wpdb->prepare( |
| 5494 | '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', |
| 5495 | [ 'enabled', $limit, $offset ] |
| 5496 | ) |
| 5497 | ); |
| 5498 | |
| 5499 | $form_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5500 | |
| 5501 | $options = []; |
| 5502 | |
| 5503 | if ( ! empty( $forms ) ) { |
| 5504 | if ( is_array( $forms ) ) { |
| 5505 | foreach ( $forms as $form ) { |
| 5506 | $options[] = [ |
| 5507 | 'label' => $form->name, |
| 5508 | 'value' => $form->id, |
| 5509 | ]; |
| 5510 | } |
| 5511 | } |
| 5512 | } |
| 5513 | |
| 5514 | return [ |
| 5515 | 'options' => $options, |
| 5516 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 5517 | ]; |
| 5518 | |
| 5519 | } |
| 5520 | |
| 5521 | /** |
| 5522 | * Get MailPoet List. |
| 5523 | * |
| 5524 | * @param array $data data. |
| 5525 | * |
| 5526 | * @return array |
| 5527 | */ |
| 5528 | public function search_mailpoet_list( $data ) { |
| 5529 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5530 | return; |
| 5531 | } |
| 5532 | |
| 5533 | $mailpoet = \MailPoet\API\API::MP( 'v1' ); |
| 5534 | $lists = $mailpoet->getLists(); |
| 5535 | |
| 5536 | $options = []; |
| 5537 | |
| 5538 | if ( ! empty( $lists ) ) { |
| 5539 | if ( is_array( $lists ) ) { |
| 5540 | foreach ( $lists as $list ) { |
| 5541 | $options[] = [ |
| 5542 | 'label' => $list['name'], |
| 5543 | 'value' => $list['id'], |
| 5544 | ]; |
| 5545 | } |
| 5546 | } |
| 5547 | } |
| 5548 | |
| 5549 | return [ |
| 5550 | 'options' => $options, |
| 5551 | 'hasMore' => false, |
| 5552 | ]; |
| 5553 | } |
| 5554 | |
| 5555 | /** |
| 5556 | * Get MailPoet Subscriber Status. |
| 5557 | * |
| 5558 | * @param array $data data. |
| 5559 | * |
| 5560 | * @return array |
| 5561 | */ |
| 5562 | public function search_mailpoet_subscriber_status( $data ) { |
| 5563 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5564 | return; |
| 5565 | } |
| 5566 | |
| 5567 | $subscriber_status = [ |
| 5568 | 'subscribed' => 'Subscribed', |
| 5569 | 'unconfirmed' => 'Unconfirmed', |
| 5570 | 'unsubscribed' => 'Unsubscribed', |
| 5571 | 'inactive' => 'Inactive', |
| 5572 | 'bounced' => 'Bounced', |
| 5573 | ]; |
| 5574 | |
| 5575 | $options = []; |
| 5576 | foreach ( $subscriber_status as $key => $status ) { |
| 5577 | $options[] = [ |
| 5578 | 'label' => $status, |
| 5579 | 'value' => $key, |
| 5580 | ]; |
| 5581 | } |
| 5582 | |
| 5583 | return [ |
| 5584 | 'options' => $options, |
| 5585 | 'hasMore' => false, |
| 5586 | ]; |
| 5587 | } |
| 5588 | |
| 5589 | /** |
| 5590 | * Get MailPoet Subscribers. |
| 5591 | * |
| 5592 | * @param array $data data. |
| 5593 | * |
| 5594 | * @return array |
| 5595 | */ |
| 5596 | public function search_mailpoet_subscribers( $data ) { |
| 5597 | if ( ! class_exists( '\MailPoet\API\API' ) ) { |
| 5598 | return; |
| 5599 | } |
| 5600 | |
| 5601 | global $wpdb; |
| 5602 | |
| 5603 | $page = $data['page']; |
| 5604 | $limit = Utilities::get_search_page_limit(); |
| 5605 | $offset = $limit * ( $page - 1 ); |
| 5606 | |
| 5607 | $subscribers = $wpdb->get_results( |
| 5608 | $wpdb->prepare( |
| 5609 | 'SELECT SQL_CALC_FOUND_ROWS id,email FROM ' . $wpdb->prefix . 'mailpoet_subscribers ORDER BY id DESC LIMIT %d OFFSET %d', |
| 5610 | [ $limit, $offset ] |
| 5611 | ) |
| 5612 | ); |
| 5613 | |
| 5614 | $subscribers_count = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); |
| 5615 | |
| 5616 | $options = []; |
| 5617 | |
| 5618 | if ( ! empty( $subscribers ) ) { |
| 5619 | if ( is_array( $subscribers ) ) { |
| 5620 | foreach ( $subscribers as $subscriber ) { |
| 5621 | $options[] = [ |
| 5622 | 'label' => $subscriber->email, |
| 5623 | 'value' => $subscriber->id, |
| 5624 | ]; |
| 5625 | } |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | return [ |
| 5630 | 'options' => $options, |
| 5631 | 'hasMore' => $subscribers_count > $limit && $subscribers_count > $offset, |
| 5632 | ]; |
| 5633 | } |
| 5634 | |
| 5635 | /** |
| 5636 | * Get ConvertPro Forms. |
| 5637 | * |
| 5638 | * @param array $data data. |
| 5639 | * |
| 5640 | * @return array |
| 5641 | */ |
| 5642 | public function search_convertpro_form_list( $data ) { |
| 5643 | if ( ! class_exists( '\Cp_V2_Loader' ) ) { |
| 5644 | return; |
| 5645 | } |
| 5646 | |
| 5647 | $cp_popups_inst = CP_V2_Popups::get_instance(); |
| 5648 | $popups = $cp_popups_inst->get_all(); |
| 5649 | |
| 5650 | $form_count = count( $popups ); |
| 5651 | |
| 5652 | $page = $data['page']; |
| 5653 | $limit = Utilities::get_search_page_limit(); |
| 5654 | $offset = $limit * ( $page - 1 ); |
| 5655 | |
| 5656 | $options = []; |
| 5657 | |
| 5658 | if ( ! empty( $popups ) ) { |
| 5659 | if ( is_array( $popups ) ) { |
| 5660 | foreach ( $popups as $form ) { |
| 5661 | $options[] = [ |
| 5662 | 'label' => $form->post_title, |
| 5663 | 'value' => $form->ID, |
| 5664 | ]; |
| 5665 | } |
| 5666 | } |
| 5667 | } |
| 5668 | |
| 5669 | return [ |
| 5670 | 'options' => $options, |
| 5671 | 'hasMore' => $form_count > $limit && $form_count > $offset, |
| 5672 | ]; |
| 5673 | |
| 5674 | } |
| 5675 | |
| 5676 | /** |
| 5677 | * Get ProjectHuddle Websites. |
| 5678 | * |
| 5679 | * @param array $data data. |
| 5680 | * |
| 5681 | * @return array |
| 5682 | */ |
| 5683 | public function search_project_huddle_websites( $data ) { |
| 5684 | |
| 5685 | $sites = new WP_Query( |
| 5686 | [ |
| 5687 | 'post_type' => 'ph-website', |
| 5688 | 'posts_per_page' => - 1, |
| 5689 | 'fields' => 'ids', |
| 5690 | ] |
| 5691 | ); |
| 5692 | |
| 5693 | $site_ids = (array) $sites->posts; |
| 5694 | |
| 5695 | $options = []; |
| 5696 | if ( ! empty( $site_ids ) ) { |
| 5697 | if ( is_array( $site_ids ) ) { |
| 5698 | foreach ( $site_ids as $site_id ) { |
| 5699 | $options[] = [ |
| 5700 | 'label' => get_the_title( $site_id ), |
| 5701 | 'value' => $site_id, |
| 5702 | ]; |
| 5703 | } |
| 5704 | } |
| 5705 | } |
| 5706 | return [ |
| 5707 | 'options' => $options, |
| 5708 | 'hasMore' => false, |
| 5709 | ]; |
| 5710 | |
| 5711 | } |
| 5712 | |
| 5713 | /** |
| 5714 | * Get last data for trigger. |
| 5715 | * |
| 5716 | * @param array $data data. |
| 5717 | * @return mixed |
| 5718 | */ |
| 5719 | public function search_project_huddle_comment_triggers_last_data( $data ) { |
| 5720 | global $wpdb; |
| 5721 | |
| 5722 | $context = []; |
| 5723 | |
| 5724 | if ( -1 !== $data['dynamic'] ) { |
| 5725 | $threads = get_posts( |
| 5726 | [ |
| 5727 | 'post_type' => 'phw_comment_loc', |
| 5728 | 'posts_per_page' => 1, |
| 5729 | 'meta_value' => $data['dynamic'], |
| 5730 | 'meta_key' => 'project_id', |
| 5731 | 'orderby' => 'asc', |
| 5732 | ] |
| 5733 | ); |
| 5734 | } else { |
| 5735 | $threads = []; |
| 5736 | } |
| 5737 | |
| 5738 | if ( ! empty( $threads ) ) { |
| 5739 | $comment_result = $wpdb->get_row( |
| 5740 | $wpdb->prepare( |
| 5741 | 'SELECT ' . $wpdb->prefix . 'comments.comment_ID |
| 5742 | FROM ' . $wpdb->prefix . 'comments |
| 5743 | WHERE ( ( comment_approved = "0" OR comment_approved = "1" ) ) AND comment_type IN ("ph_comment") AND comment_post_ID = %d |
| 5744 | ORDER BY ' . $wpdb->prefix . 'comments.comment_date_gmt DESC |
| 5745 | LIMIT 0,1', |
| 5746 | $threads[0]->ID |
| 5747 | ), |
| 5748 | ARRAY_A |
| 5749 | ); |
| 5750 | |
| 5751 | if ( ! empty( $comment_result ) ) { |
| 5752 | $comment_id = get_comment( $comment_result['comment_ID'], ARRAY_A ); |
| 5753 | $comments['comment_ID'] = isset( $comment_id['comment_ID'] ) ? $comment_id['comment_ID'] : ''; |
| 5754 | $comments['comment_post_ID'] = isset( $comment_id['comment_post_ID'] ) ? $comment_id['comment_post_ID'] : ''; |
| 5755 | |
| 5756 | $comments['comment_author'] = isset( $comment_id['comment_author'] ) ? $comment_id['comment_author'] : ''; |
| 5757 | |
| 5758 | $comments['comment_author_email'] = isset( $comment_id['comment_author_email'] ) ? $comment_id['comment_author_email'] : ''; |
| 5759 | |
| 5760 | $comments['comment_date'] = isset( $comment_id['comment_date'] ) ? $comment_id['comment_date'] : ''; |
| 5761 | |
| 5762 | $comments['comment_content'] = isset( $comment_id['comment_content'] ) ? $comment_id['comment_content'] : ''; |
| 5763 | |
| 5764 | $comments['comment_type'] = isset( $comment_id['comment_type'] ) ? $comment_id['comment_type'] : ''; |
| 5765 | |
| 5766 | $context['pluggable_data'] = $comments; |
| 5767 | $context['response_type'] = 'live'; |
| 5768 | } else { |
| 5769 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"comment_ID":"1","comment_post_ID":"1","comment_author":"test","comment_author_email":"test@test.com","comment_date":"2023-03-27 13:44:26","comment_content":"<p>Leave comment<\/p>","comment_type":"ph_comment"}}', true ); |
| 5770 | } |
| 5771 | } else { |
| 5772 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"comment_ID":"1","comment_post_ID":"1","comment_author":"test","comment_author_email":"test@test.com","comment_date":"2023-03-27 13:44:26","comment_content":"<p>Leave comment<\/p>","comment_type":"ph_comment"}}', true ); |
| 5773 | } |
| 5774 | |
| 5775 | return $context; |
| 5776 | } |
| 5777 | |
| 5778 | /** |
| 5779 | * Get last data for trigger. |
| 5780 | * |
| 5781 | * @param array $data data. |
| 5782 | * @return mixed |
| 5783 | */ |
| 5784 | public function search_project_huddle_resolved_comment_triggers_last_data( $data ) { |
| 5785 | global $wpdb; |
| 5786 | |
| 5787 | $context = []; |
| 5788 | |
| 5789 | $get_comments = $wpdb->get_row( |
| 5790 | 'SELECT ' . $wpdb->prefix . 'comments.comment_ID, ' . $wpdb->prefix . 'comments.comment_content |
| 5791 | FROM ' . $wpdb->prefix . 'comments |
| 5792 | WHERE ( ( comment_approved = "0" OR comment_approved = "1" ) ) AND comment_type IN ("ph_status") AND comment_content = "Resolved" |
| 5793 | ORDER BY ' . $wpdb->prefix . 'comments.comment_date_gmt DESC |
| 5794 | LIMIT 0,1' |
| 5795 | ); |
| 5796 | |
| 5797 | if ( ! empty( $get_comments ) ) { |
| 5798 | $comment_id = get_comment( $get_comments->comment_ID, ARRAY_A ); |
| 5799 | $comment_result = $wpdb->get_row( |
| 5800 | $wpdb->prepare( |
| 5801 | 'SELECT ' . $wpdb->prefix . 'comments.comment_ID |
| 5802 | FROM ' . $wpdb->prefix . 'comments |
| 5803 | WHERE ( ( comment_approved = "0" OR comment_approved = "1" ) ) AND comment_type IN ("ph_comment") AND comment_post_ID = %d |
| 5804 | ORDER BY ' . $wpdb->prefix . 'comments.comment_date_gmt DESC |
| 5805 | LIMIT 0,1', |
| 5806 | isset( $comment_id['comment_post_ID'] ) ? $comment_id['comment_post_ID'] : '' |
| 5807 | ), |
| 5808 | ARRAY_A |
| 5809 | ); |
| 5810 | |
| 5811 | $actual_comment = get_comment( $comment_result['comment_ID'], ARRAY_A ); |
| 5812 | $comments['comment_ID'] = isset( $actual_comment['comment_ID'] ) ? $actual_comment['comment_ID'] : ''; |
| 5813 | $comments['comment_post_ID'] = isset( $actual_comment['comment_post_ID'] ) ? $actual_comment['comment_post_ID'] : ''; |
| 5814 | $comments['comment_author'] = isset( $actual_comment['comment_author'] ) ? $actual_comment['comment_author'] : ''; |
| 5815 | $comments['comment_author_email'] = isset( $actual_comment['comment_author_email'] ) ? $actual_comment['comment_author_email'] : ''; |
| 5816 | $comments['comment_date'] = isset( $actual_comment['comment_date'] ) ? $actual_comment['comment_date'] : ''; |
| 5817 | $comments['comment_content'] = isset( $actual_comment['comment_content'] ) ? $actual_comment['comment_content'] : ''; |
| 5818 | $comments['comment_type'] = isset( $actual_comment['comment_type'] ) ? $actual_comment['comment_type'] : ''; |
| 5819 | $comments['comment_status'] = $get_comments->comment_content; |
| 5820 | $context['pluggable_data'] = $comments; |
| 5821 | $context['response_type'] = 'live'; |
| 5822 | } else { |
| 5823 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"comment_ID":"1","comment_post_ID":"1","comment_author":"test","comment_author_email":"test@test.com","comment_date":"2023-03-27 13:44:26","comment_content":"<p>Leave comment<\/p>","comment_type":"ph_comment","comment_status":"Resolved"}}', true ); |
| 5824 | } |
| 5825 | |
| 5826 | return $context; |
| 5827 | } |
| 5828 | |
| 5829 | /** |
| 5830 | * Get MasterStudy LMS Courses. |
| 5831 | * |
| 5832 | * @param array $data data. |
| 5833 | * |
| 5834 | * @return array |
| 5835 | */ |
| 5836 | public function search_ms_lms_courses( $data ) { |
| 5837 | |
| 5838 | $page = $data['page']; |
| 5839 | $limit = Utilities::get_search_page_limit(); |
| 5840 | $offset = $limit * ( $page - 1 ); |
| 5841 | |
| 5842 | $args = [ |
| 5843 | 'post_type' => 'stm-courses', |
| 5844 | 'posts_per_page' => $limit, |
| 5845 | 'offset' => $offset, |
| 5846 | 'orderby' => 'title', |
| 5847 | 'order' => 'ASC', |
| 5848 | 'post_status' => 'publish', |
| 5849 | ]; |
| 5850 | |
| 5851 | $courses = get_posts( $args ); |
| 5852 | |
| 5853 | $course_count = count( $courses ); |
| 5854 | |
| 5855 | $options = []; |
| 5856 | if ( ! empty( $courses ) ) { |
| 5857 | if ( is_array( $courses ) ) { |
| 5858 | foreach ( $courses as $course ) { |
| 5859 | $options[] = [ |
| 5860 | 'label' => $course->post_title, |
| 5861 | 'value' => $course->ID, |
| 5862 | ]; |
| 5863 | } |
| 5864 | } |
| 5865 | } |
| 5866 | return [ |
| 5867 | 'options' => $options, |
| 5868 | 'hasMore' => $course_count > $limit && $course_count > $offset, |
| 5869 | ]; |
| 5870 | |
| 5871 | } |
| 5872 | |
| 5873 | /** |
| 5874 | * Get MasterStudy LMS Lessons. |
| 5875 | * |
| 5876 | * @param array $data data. |
| 5877 | * |
| 5878 | * @return array |
| 5879 | */ |
| 5880 | public function search_ms_lms_lessons( $data ) { |
| 5881 | |
| 5882 | global $wpdb; |
| 5883 | $page = $data['page']; |
| 5884 | $limit = Utilities::get_search_page_limit(); |
| 5885 | $offset = $limit * ( $page - 1 ); |
| 5886 | |
| 5887 | $course_id = $data['dynamic']; |
| 5888 | |
| 5889 | $lessons = $wpdb->get_results( |
| 5890 | $wpdb->prepare( |
| 5891 | "SELECT ID, post_title |
| 5892 | FROM $wpdb->posts |
| 5893 | WHERE FIND_IN_SET( |
| 5894 | ID, |
| 5895 | (SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'curriculum') |
| 5896 | ) |
| 5897 | AND post_type = 'stm-lessons' |
| 5898 | ORDER BY post_title ASC", |
| 5899 | absint( $course_id ) |
| 5900 | ) |
| 5901 | ); |
| 5902 | |
| 5903 | if ( '-1' === $course_id ) { |
| 5904 | $lessons = $wpdb->get_results( |
| 5905 | $wpdb->prepare( |
| 5906 | "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = %s ORDER BY post_title ASC", |
| 5907 | 'stm-lessons' |
| 5908 | ) |
| 5909 | ); |
| 5910 | } |
| 5911 | |
| 5912 | $lessons_count = count( $lessons ); |
| 5913 | |
| 5914 | $options = []; |
| 5915 | if ( ! empty( $lessons ) ) { |
| 5916 | if ( is_array( $lessons ) ) { |
| 5917 | foreach ( $lessons as $lesson ) { |
| 5918 | $options[] = [ |
| 5919 | 'label' => $lesson->post_title, |
| 5920 | 'value' => $lesson->ID, |
| 5921 | ]; |
| 5922 | } |
| 5923 | } |
| 5924 | } |
| 5925 | return [ |
| 5926 | 'options' => $options, |
| 5927 | 'hasMore' => $lessons_count > $limit && $lessons_count > $offset, |
| 5928 | ]; |
| 5929 | |
| 5930 | } |
| 5931 | |
| 5932 | /** |
| 5933 | * Get MasterStudy LMS Quiz. |
| 5934 | * |
| 5935 | * @param array $data data. |
| 5936 | * |
| 5937 | * @return array |
| 5938 | */ |
| 5939 | public function search_ms_lms_quiz( $data ) { |
| 5940 | |
| 5941 | global $wpdb; |
| 5942 | $page = $data['page']; |
| 5943 | $limit = Utilities::get_search_page_limit(); |
| 5944 | $offset = $limit * ( $page - 1 ); |
| 5945 | |
| 5946 | $course_id = $data['dynamic']; |
| 5947 | |
| 5948 | $quizzes = $wpdb->get_results( |
| 5949 | $wpdb->prepare( |
| 5950 | "SELECT ID, post_title |
| 5951 | FROM $wpdb->posts |
| 5952 | WHERE FIND_IN_SET( |
| 5953 | ID, |
| 5954 | (SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'curriculum') |
| 5955 | ) |
| 5956 | AND post_type = 'stm-quizzes' |
| 5957 | ORDER BY post_title ASC |
| 5958 | ", |
| 5959 | absint( $course_id ) |
| 5960 | ) |
| 5961 | ); |
| 5962 | |
| 5963 | if ( '-1' === $course_id ) { |
| 5964 | $quizzes = $wpdb->get_results( |
| 5965 | $wpdb->prepare( |
| 5966 | "SELECT ID, post_title |
| 5967 | FROM $wpdb->posts |
| 5968 | WHERE post_type = %s |
| 5969 | ORDER BY post_title ASC", |
| 5970 | 'stm-quizzes' |
| 5971 | ) |
| 5972 | ); |
| 5973 | } |
| 5974 | |
| 5975 | $quizzes_count = count( $quizzes ); |
| 5976 | |
| 5977 | $options = []; |
| 5978 | if ( ! empty( $quizzes ) ) { |
| 5979 | if ( is_array( $quizzes ) ) { |
| 5980 | foreach ( $quizzes as $quiz ) { |
| 5981 | $options[] = [ |
| 5982 | 'label' => $quiz->post_title, |
| 5983 | 'value' => $quiz->ID, |
| 5984 | ]; |
| 5985 | } |
| 5986 | } |
| 5987 | } |
| 5988 | return [ |
| 5989 | 'options' => $options, |
| 5990 | 'hasMore' => $quizzes_count > $limit && $quizzes_count > $offset, |
| 5991 | ]; |
| 5992 | |
| 5993 | } |
| 5994 | |
| 5995 | /** |
| 5996 | * Search MasterStudy LMS data. |
| 5997 | * |
| 5998 | * @param array $data data. |
| 5999 | * @return array|void |
| 6000 | */ |
| 6001 | public function search_ms_lms_last_data( $data ) { |
| 6002 | global $wpdb; |
| 6003 | $post_type = $data['post_type']; |
| 6004 | $trigger = $data['search_term']; |
| 6005 | $context = []; |
| 6006 | |
| 6007 | if ( 'stm_lms_course_completed' === $trigger ) { |
| 6008 | $post_id = $data['filter']['course']['value']; |
| 6009 | if ( -1 === $post_id ) { |
| 6010 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.progress_percent=100 AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_type ) ); |
| 6011 | } else { |
| 6012 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.course_id = %s AND postmeta.progress_percent=100 AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6013 | } |
| 6014 | } elseif ( 'stm_lesson_passed' === $trigger ) { |
| 6015 | $post_id = $data['filter']['lesson']['value']; |
| 6016 | if ( -1 === $post_id ) { |
| 6017 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_lessons as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.lesson_id WHERE posts.post_type=%s order by postmeta.user_lesson_id DESC LIMIT 1", $post_type ) ); |
| 6018 | } else { |
| 6019 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_lessons as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.lesson_id WHERE postmeta.lesson_id=%s AND posts.post_type=%s order by postmeta.user_lesson_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6020 | } |
| 6021 | } elseif ( 'stm_quiz_passed' === $trigger ) { |
| 6022 | $post_id = $data['filter']['quiz']['value']; |
| 6023 | if ( -1 === $post_id ) { |
| 6024 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.status='passed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_type ) ); |
| 6025 | } else { |
| 6026 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.quiz_id=%s AND postmeta.status='passed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6027 | } |
| 6028 | } elseif ( 'stm_quiz_failed' === $trigger ) { |
| 6029 | $post_id = $data['filter']['quiz']['value']; |
| 6030 | if ( -1 === $post_id ) { |
| 6031 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.status='failed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_type ) ); |
| 6032 | } else { |
| 6033 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_quizzes as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.quiz_id WHERE postmeta.quiz_id=%s AND postmeta.status='failed' AND posts.post_type=%s order by postmeta.user_quiz_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6034 | } |
| 6035 | } elseif ( 'stm_lms_user_enroll_course' === $trigger ) { |
| 6036 | $post_id = $data['filter']['course']['value']; |
| 6037 | if ( -1 === $post_id ) { |
| 6038 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.status='enrolled' AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_type ) ); |
| 6039 | } else { |
| 6040 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}stm_lms_user_courses as postmeta JOIN {$wpdb->prefix}posts as posts ON posts.ID=postmeta.course_id WHERE postmeta.course_id=%s AND postmeta.status='enrolled' AND posts.post_type=%s order by postmeta.user_course_id DESC LIMIT 1", $post_id, $post_type ) ); |
| 6041 | } |
| 6042 | } |
| 6043 | |
| 6044 | if ( ! empty( $result ) ) { |
| 6045 | |
| 6046 | switch ( $trigger ) { |
| 6047 | case 'stm_lms_course_completed': |
| 6048 | $result_course_id = $result[0]->course_id; |
| 6049 | $result_user_id = $result[0]->user_id; |
| 6050 | $course = get_the_title( $result_course_id ); |
| 6051 | $course_link = get_the_permalink( $result_course_id ); |
| 6052 | $featured_image = get_the_post_thumbnail_url( $result_course_id ); |
| 6053 | |
| 6054 | $data = [ |
| 6055 | 'course_id' => $result_course_id, |
| 6056 | 'course_title' => $course, |
| 6057 | 'course_link' => $course_link, |
| 6058 | 'course_featured_image' => $featured_image, |
| 6059 | 'course_progress' => $result[0]->progress_percent, |
| 6060 | ]; |
| 6061 | $context_data = array_merge( |
| 6062 | WordPress::get_user_context( $result_user_id ), |
| 6063 | $data |
| 6064 | ); |
| 6065 | break; |
| 6066 | case 'stm_lesson_passed': |
| 6067 | $result_lesson_id = $result[0]->lesson_id; |
| 6068 | $result_user_id = $result[0]->user_id; |
| 6069 | $lesson = get_the_title( $result_lesson_id ); |
| 6070 | $lesson_link = get_the_permalink( $result_lesson_id ); |
| 6071 | |
| 6072 | $data = [ |
| 6073 | 'lesson_id' => $result_lesson_id, |
| 6074 | 'lesson_title' => $lesson, |
| 6075 | 'lesson_link' => $lesson_link, |
| 6076 | ]; |
| 6077 | $context_data = array_merge( |
| 6078 | WordPress::get_user_context( $result_user_id ), |
| 6079 | $data |
| 6080 | ); |
| 6081 | break; |
| 6082 | case 'stm_quiz_passed': |
| 6083 | $result_quiz_id = $result[0]->quiz_id; |
| 6084 | $result_user_id = $result[0]->user_id; |
| 6085 | $quiz_title = get_the_title( $result_quiz_id ); |
| 6086 | $quiz_link = get_the_permalink( $result_quiz_id ); |
| 6087 | |
| 6088 | $data = [ |
| 6089 | 'quiz_id' => $result_quiz_id, |
| 6090 | 'quiz_title' => $quiz_title, |
| 6091 | 'quiz_link' => $quiz_link, |
| 6092 | 'quiz_score' => $result[0]->progress, |
| 6093 | 'result' => 'passed', |
| 6094 | ]; |
| 6095 | $context_data = array_merge( |
| 6096 | WordPress::get_user_context( $result_user_id ), |
| 6097 | $data |
| 6098 | ); |
| 6099 | break; |
| 6100 | case 'stm_quiz_failed': |
| 6101 | $result_quiz_id = $result[0]->quiz_id; |
| 6102 | $result_user_id = $result[0]->user_id; |
| 6103 | $quiz_title = get_the_title( $result_quiz_id ); |
| 6104 | $quiz_link = get_the_permalink( $result_quiz_id ); |
| 6105 | |
| 6106 | $data = [ |
| 6107 | 'quiz_id' => $result_quiz_id, |
| 6108 | 'quiz_title' => $quiz_title, |
| 6109 | 'quiz_link' => $quiz_link, |
| 6110 | 'quiz_score' => $result[0]->progress, |
| 6111 | 'result' => 'failed', |
| 6112 | ]; |
| 6113 | $context_data = array_merge( |
| 6114 | WordPress::get_user_context( $result_user_id ), |
| 6115 | $data |
| 6116 | ); |
| 6117 | break; |
| 6118 | case 'stm_lms_user_enroll_course': |
| 6119 | $result_course_id = $result[0]->course_id; |
| 6120 | $result_user_id = $result[0]->user_id; |
| 6121 | |
| 6122 | $course = get_the_title( $result_course_id ); |
| 6123 | $course_link = get_the_permalink( $result_course_id ); |
| 6124 | $featured_image = get_the_post_thumbnail_url( $result_course_id ); |
| 6125 | |
| 6126 | $data = [ |
| 6127 | 'course_id' => $result_course_id, |
| 6128 | 'course_title' => $course, |
| 6129 | 'course_link' => $course_link, |
| 6130 | 'course_featured_image' => $featured_image, |
| 6131 | ]; |
| 6132 | $context_data = array_merge( |
| 6133 | WordPress::get_user_context( $result_user_id ), |
| 6134 | $data |
| 6135 | ); |
| 6136 | break; |
| 6137 | default: |
| 6138 | return; |
| 6139 | } |
| 6140 | $context['pluggable_data'] = $context_data; |
| 6141 | $context['response_type'] = 'live'; |
| 6142 | } |
| 6143 | |
| 6144 | return $context; |
| 6145 | |
| 6146 | } |
| 6147 | |
| 6148 | |
| 6149 | /** |
| 6150 | * Get last data for trigger. |
| 6151 | * |
| 6152 | * @param array $data data. |
| 6153 | * @return array |
| 6154 | */ |
| 6155 | public function search_fluent_support_triggers_last_data( $data ) { |
| 6156 | $context = []; |
| 6157 | $context['response_type'] = 'sample'; |
| 6158 | |
| 6159 | $ticket_data = [ |
| 6160 | 'id' => '1', |
| 6161 | 'customer_id' => '2', |
| 6162 | 'agent_id' => '3', |
| 6163 | 'product_id' => '5', |
| 6164 | 'product_source' => 'local', |
| 6165 | 'privacy' => 'private', |
| 6166 | 'priority' => 'normal', |
| 6167 | 'client_priority' => 'medium', |
| 6168 | 'status' => 'active', |
| 6169 | 'title' => 'Sample Ticket Title', |
| 6170 | 'slug' => 'sample-ticket-title', |
| 6171 | 'hash' => 'f8a8cfb946', |
| 6172 | 'content_hash' => 'd65500d62621be8b493c22b1d888052c', |
| 6173 | 'content' => '<p>Sample content.</p>', |
| 6174 | 'last_customer_response' => '2023-04-27 07:30:46', |
| 6175 | 'waiting_since' => '2023-04-27 07:30:46', |
| 6176 | 'response_count' => '2', |
| 6177 | 'total_close_time' => '7042', |
| 6178 | 'resolved at' => '2023-04-27 09:28:08', |
| 6179 | 'closed_by' => '1', |
| 6180 | 'created_at' => '2023-04-27 07:30:46', |
| 6181 | 'updated_at' => '2023-04-27 10:28:08', |
| 6182 | 'mailbox_id' => '1', |
| 6183 | 'mailbox_name' => 'SureTriggers', |
| 6184 | 'mailbox_slug' => 'suretriggers', |
| 6185 | 'mailbox_box_type' => 'web', |
| 6186 | 'mailbox email' => 'john_doe@sample.com', |
| 6187 | 'mailbox_settings_admin_email_address' => 'john_doe@sample.com', |
| 6188 | 'mailbox_created_by' => '1', |
| 6189 | 'mailbox_is_default' => 'yes', |
| 6190 | 'mailbox_created_at' => '2023-04-26 06:29:01', |
| 6191 | 'mailbox_updated_at' => '2023-04-26 06:29:01', |
| 6192 | ]; |
| 6193 | |
| 6194 | $customer_data = [ |
| 6195 | 'id' => '1', |
| 6196 | 'first_name' => 'John', |
| 6197 | 'last_name' => 'Doe', |
| 6198 | 'email' => 'john_doe@sample.com', |
| 6199 | 'person_type' => 'agent', |
| 6200 | 'status' => 'active', |
| 6201 | 'hash' => '3b2b5f0432561cb81b1302b8a16b93a0', |
| 6202 | 'user_id' => '1', |
| 6203 | 'created_at' => '2023-04-27 07:30:46', |
| 6204 | 'updated_at' => '2023-04-27 10:28:08', |
| 6205 | 'full_name' => 'John Doe', |
| 6206 | 'photo' => 'https://www.gravatar.com/avatar/c2b06ae950033b392998ada50767b50e?s=128', |
| 6207 | ]; |
| 6208 | |
| 6209 | $reply_data = [ |
| 6210 | 'ticket_id' => '1', |
| 6211 | 'conversation_type' => 'response', |
| 6212 | 'content' => '<p>Sample content.</p>', |
| 6213 | 'source' => 'web', |
| 6214 | 'content_hash' => '2cc0e35d8fb92a0675d67999b073b3a4', |
| 6215 | 'created_at' => '2023-04-27 07:30:46', |
| 6216 | 'updated_at' => '2023-04-27 10:28:08', |
| 6217 | 'id' => '1', |
| 6218 | 'person_id' => '2', |
| 6219 | 'person_first_name' => 'John', |
| 6220 | 'person_last_name' => 'Doe', |
| 6221 | 'person_email' => 'john_doe@sample.com', |
| 6222 | 'person_person_type' => 'agent', |
| 6223 | 'person_status' => 'active', |
| 6224 | 'person_hash' => '3b2b5f0432561cb81b1302b8a16b93a0', |
| 6225 | 'person_user_id' => '1', |
| 6226 | 'person_created_at' => '2023-04-27 07:30:46', |
| 6227 | 'person_updated_at' => '2023-04-27 10:28:08', |
| 6228 | 'person_full_name' => 'John Doe', |
| 6229 | 'person_photo' => 'https://www.gravatar.com/avatar/c2b06ae950033b392998ada50767b50e?s=128', |
| 6230 | ]; |
| 6231 | |
| 6232 | $term = isset( $data['search_term'] ) ? $data['search_term'] : ''; |
| 6233 | |
| 6234 | if ( in_array( $term, [ 'response_added_by_agent', 'response_added_by_customer' ], true ) ) { |
| 6235 | $context['pluggable_data'] = array_merge( |
| 6236 | [ |
| 6237 | 'reply' => $reply_data, |
| 6238 | 'ticket' => $ticket_data, |
| 6239 | 'customer' => $customer_data, |
| 6240 | ] |
| 6241 | ); |
| 6242 | } else { |
| 6243 | $context['pluggable_data'] = array_merge( |
| 6244 | [ |
| 6245 | 'ticket' => $ticket_data, |
| 6246 | 'customer' => $customer_data, |
| 6247 | ] |
| 6248 | ); |
| 6249 | } |
| 6250 | |
| 6251 | return $context; |
| 6252 | } |
| 6253 | |
| 6254 | /** |
| 6255 | * Prepare Ultimate Member user_roles. |
| 6256 | * |
| 6257 | * @param array $data data. |
| 6258 | * |
| 6259 | * @return array |
| 6260 | */ |
| 6261 | public function search_um_user_roles( $data ) { |
| 6262 | if ( function_exists( 'get_editable_roles' ) ) { |
| 6263 | $roles = get_editable_roles(); |
| 6264 | } else { |
| 6265 | $roles = wp_roles()->roles; |
| 6266 | $roles = apply_filters( 'editable_roles', $roles ); |
| 6267 | } |
| 6268 | |
| 6269 | $options = []; |
| 6270 | foreach ( $roles as $role => $details ) { |
| 6271 | |
| 6272 | $options[] = [ |
| 6273 | 'label' => $details['name'], |
| 6274 | 'value' => $role, |
| 6275 | ]; |
| 6276 | |
| 6277 | } |
| 6278 | |
| 6279 | return [ |
| 6280 | 'options' => $options, |
| 6281 | 'hasMore' => false, |
| 6282 | ]; |
| 6283 | } |
| 6284 | |
| 6285 | /** |
| 6286 | * Prepare Ultimate Member forms_list. |
| 6287 | * |
| 6288 | * @param array $data data. |
| 6289 | * |
| 6290 | * @return array |
| 6291 | */ |
| 6292 | public function search_um_forms_list( $data ) { |
| 6293 | |
| 6294 | $page = $data['page']; |
| 6295 | $limit = Utilities::get_search_page_limit(); |
| 6296 | $offset = $limit * ( $page - 1 ); |
| 6297 | |
| 6298 | $args = [ |
| 6299 | 'posts_per_page' => $limit, |
| 6300 | 'offset' => $offset, |
| 6301 | 'orderby' => 'title', |
| 6302 | 'order' => 'ASC', |
| 6303 | 'post_type' => 'um_form', |
| 6304 | 'post_status' => 'publish', |
| 6305 | 'fields' => 'ids', |
| 6306 | ]; |
| 6307 | |
| 6308 | $forms_list = get_posts( $args ); |
| 6309 | |
| 6310 | $forms_list_count = count( $forms_list ); |
| 6311 | |
| 6312 | $options = []; |
| 6313 | if ( ! empty( $forms_list ) ) { |
| 6314 | foreach ( $forms_list as $form ) { |
| 6315 | $options[] = [ |
| 6316 | 'label' => get_the_title( $form ), |
| 6317 | 'value' => $form, |
| 6318 | ]; |
| 6319 | } |
| 6320 | } |
| 6321 | |
| 6322 | return [ |
| 6323 | 'options' => $options, |
| 6324 | 'hasMore' => $forms_list_count > $limit && $forms_list_count > $offset, |
| 6325 | ]; |
| 6326 | } |
| 6327 | |
| 6328 | /** |
| 6329 | * Get last data for Ultimate Member Login trigger. |
| 6330 | * |
| 6331 | * @param array $data data. |
| 6332 | * @return mixed |
| 6333 | */ |
| 6334 | public function search_ultimate_member_user_logsin( $data ) { |
| 6335 | $context = []; |
| 6336 | $args = [ |
| 6337 | 'orderby' => 'meta_value', |
| 6338 | 'meta_key' => '_um_last_login', |
| 6339 | 'order' => 'DESC', |
| 6340 | 'number' => 1, |
| 6341 | ]; |
| 6342 | $users = get_users( $args ); |
| 6343 | |
| 6344 | if ( ! empty( $users ) ) { |
| 6345 | $user = $users[0]; |
| 6346 | $pluggable_data = WordPress::get_user_context( $user->ID ); |
| 6347 | $context['pluggable_data'] = $pluggable_data; |
| 6348 | $context['response_type'] = 'live'; |
| 6349 | } else { |
| 6350 | $role = 'subscriber'; |
| 6351 | $context['pluggable_data'] = [ |
| 6352 | 'wp_user_id' => 1, |
| 6353 | 'user_login' => 'test', |
| 6354 | 'display_name' => 'Test User', |
| 6355 | 'user_firstname' => 'Test', |
| 6356 | 'user_lastname' => 'User', |
| 6357 | 'user_email' => 'testuser@gmail.com', |
| 6358 | 'user_role' => [ $role ], |
| 6359 | ]; |
| 6360 | $context['response_type'] = 'sample'; |
| 6361 | } |
| 6362 | return $context; |
| 6363 | } |
| 6364 | |
| 6365 | /** |
| 6366 | * Get last data for Ultimate Member Register trigger. |
| 6367 | * |
| 6368 | * @param array $data data. |
| 6369 | * @return mixed |
| 6370 | */ |
| 6371 | public function search_ultimate_member_user_registers( $data ) { |
| 6372 | $context = []; |
| 6373 | $args = [ |
| 6374 | 'orderby' => 'meta_value', |
| 6375 | 'meta_key' => 'um_user_profile_url_slug_user_login', |
| 6376 | 'order' => 'DESC', |
| 6377 | 'number' => 1, |
| 6378 | ]; |
| 6379 | $users = get_users( $args ); |
| 6380 | |
| 6381 | if ( ! empty( $users ) ) { |
| 6382 | $user = $users[0]; |
| 6383 | $pluggable_data = WordPress::get_user_context( $user->ID ); |
| 6384 | $context['pluggable_data'] = $pluggable_data; |
| 6385 | $context['response_type'] = 'live'; |
| 6386 | } else { |
| 6387 | $role = 'subscriber'; |
| 6388 | $context['pluggable_data'] = [ |
| 6389 | 'wp_user_id' => 1, |
| 6390 | 'user_login' => 'test', |
| 6391 | 'display_name' => 'Test User', |
| 6392 | 'user_firstname' => 'Test', |
| 6393 | 'user_lastname' => 'User', |
| 6394 | 'user_email' => 'testuser@gmail.com', |
| 6395 | 'user_role' => [ $role ], |
| 6396 | ]; |
| 6397 | $context['response_type'] = 'sample'; |
| 6398 | } |
| 6399 | return $context; |
| 6400 | } |
| 6401 | |
| 6402 | /** |
| 6403 | * Get last data for Ultimate Member Register trigger. |
| 6404 | * |
| 6405 | * @param array $data data. |
| 6406 | * @return mixed |
| 6407 | */ |
| 6408 | public function search_ultimate_member_user_inactive( $data ) { |
| 6409 | $context = []; |
| 6410 | $args = [ |
| 6411 | 'orderby' => 'user_id', |
| 6412 | 'meta_key' => 'account_status', |
| 6413 | 'meta_value' => 'inactive', |
| 6414 | 'order' => 'ASC', |
| 6415 | 'number' => 1, |
| 6416 | ]; |
| 6417 | $users = get_users( $args ); |
| 6418 | |
| 6419 | if ( ! empty( $users ) ) { |
| 6420 | $user = $users[0]; |
| 6421 | $pluggable_data = []; |
| 6422 | $pluggable_data[] = WordPress::get_user_context( $user->ID ); |
| 6423 | $pluggable_data['user_account_status'] = 'inactive'; |
| 6424 | $context['pluggable_data'] = $pluggable_data; |
| 6425 | $context['response_type'] = 'live'; |
| 6426 | } else { |
| 6427 | $role = 'subscriber'; |
| 6428 | $context['pluggable_data'] = [ |
| 6429 | 'wp_user_id' => 1, |
| 6430 | 'user_login' => 'test', |
| 6431 | 'display_name' => 'Test User', |
| 6432 | 'user_firstname' => 'Test', |
| 6433 | 'user_lastname' => 'User', |
| 6434 | 'user_email' => 'testuser@gmail.com', |
| 6435 | 'user_role' => [ $role ], |
| 6436 | 'user_account_status' => 'inactive', |
| 6437 | ]; |
| 6438 | $context['response_type'] = 'sample'; |
| 6439 | } |
| 6440 | return $context; |
| 6441 | } |
| 6442 | |
| 6443 | /** |
| 6444 | * Get last data for Ultimate Member Change Role trigger. |
| 6445 | * |
| 6446 | * @param array $data data. |
| 6447 | * @return mixed |
| 6448 | */ |
| 6449 | public function search_ultimate_member_user_role_change( $data ) { |
| 6450 | $context = []; |
| 6451 | |
| 6452 | $role = $data['filter']['role']['value']; |
| 6453 | |
| 6454 | $args = [ |
| 6455 | 'number' => 1, |
| 6456 | 'role' => $role, |
| 6457 | ]; |
| 6458 | $users = get_users( $args ); |
| 6459 | shuffle( $users ); |
| 6460 | if ( ! empty( $users ) ) { |
| 6461 | $user = $users[0]; |
| 6462 | $pluggable_data = WordPress::get_user_context( $user->ID ); |
| 6463 | $context['pluggable_data'] = $pluggable_data; |
| 6464 | $context['response_type'] = 'live'; |
| 6465 | } else { |
| 6466 | $role = isset( $args['role'] ) ? $args['role'] : 'subscriber'; |
| 6467 | $context['pluggable_data'] = [ |
| 6468 | 'wp_user_id' => 1, |
| 6469 | 'user_login' => 'test', |
| 6470 | 'display_name' => 'Test User', |
| 6471 | 'user_firstname' => 'Test', |
| 6472 | 'user_lastname' => 'User', |
| 6473 | 'user_email' => 'testuser@gmail.com', |
| 6474 | 'user_role' => [ $role ], |
| 6475 | 'user_account_status' => 'inactive', |
| 6476 | ]; |
| 6477 | $context['response_type'] = 'sample'; |
| 6478 | } |
| 6479 | return $context; |
| 6480 | } |
| 6481 | |
| 6482 | /** |
| 6483 | * Get JetEngine WP Posttypes. |
| 6484 | * |
| 6485 | * @param array $data data. |
| 6486 | * |
| 6487 | * @return array |
| 6488 | */ |
| 6489 | public function search_je_posttype_list( $data ) { |
| 6490 | |
| 6491 | $post_types = get_post_types( [ 'public' => true ], 'object' ); |
| 6492 | $post_types = apply_filters( 'suretriggers_post_types', $post_types ); |
| 6493 | if ( isset( $post_types['attachment'] ) ) { |
| 6494 | unset( $post_types['attachment'] ); |
| 6495 | } |
| 6496 | |
| 6497 | $options = []; |
| 6498 | foreach ( $post_types as $post_type => $details ) { |
| 6499 | $options[] = [ |
| 6500 | 'label' => $details->label, |
| 6501 | 'value' => $post_type, |
| 6502 | ]; |
| 6503 | } |
| 6504 | |
| 6505 | return [ |
| 6506 | 'options' => $options, |
| 6507 | 'hasMore' => false, |
| 6508 | ]; |
| 6509 | } |
| 6510 | |
| 6511 | /** |
| 6512 | * Get JetEngine WP fields. |
| 6513 | * |
| 6514 | * @param array $data data. |
| 6515 | * |
| 6516 | * @return array |
| 6517 | */ |
| 6518 | public function search_je_field_list( $data ) { |
| 6519 | |
| 6520 | $post_type = $data['dynamic']; |
| 6521 | |
| 6522 | $metaboxes = (array) get_option( 'jet_engine_meta_boxes', [] ); |
| 6523 | |
| 6524 | $post_fields = array_filter( |
| 6525 | $metaboxes, |
| 6526 | function( $metabox ) { |
| 6527 | /** |
| 6528 | * |
| 6529 | * Ignore line |
| 6530 | * |
| 6531 | * @phpstan-ignore-next-line |
| 6532 | */ |
| 6533 | return 'post' === $metabox['args']['object_type']; |
| 6534 | } |
| 6535 | ); |
| 6536 | |
| 6537 | $post_fields_count = count( $post_fields ); |
| 6538 | |
| 6539 | $options = []; |
| 6540 | if ( ! empty( $post_fields ) ) { |
| 6541 | if ( is_array( $post_fields ) ) { |
| 6542 | foreach ( $post_fields as $post_field ) { |
| 6543 | if ( in_array( $post_type, $post_field['args']['allowed_post_type'], true ) ) { |
| 6544 | foreach ( $post_field['meta_fields'] as $meta_field ) { |
| 6545 | $options[] = [ |
| 6546 | 'label' => $meta_field['title'], |
| 6547 | 'value' => $meta_field['name'], |
| 6548 | ]; |
| 6549 | } |
| 6550 | } |
| 6551 | } |
| 6552 | } |
| 6553 | } |
| 6554 | return [ |
| 6555 | 'options' => $options, |
| 6556 | 'hasMore' => false, |
| 6557 | ]; |
| 6558 | } |
| 6559 | |
| 6560 | /** |
| 6561 | * Search Last Updated Field Data. |
| 6562 | * |
| 6563 | * @param array $data data. |
| 6564 | * @return array |
| 6565 | */ |
| 6566 | public function search_jet_engine_field_data( $data ) { |
| 6567 | global $wpdb; |
| 6568 | |
| 6569 | $context = []; |
| 6570 | |
| 6571 | $field = (int) ( isset( $data['filter']['field_id']['value'] ) ? $data['filter']['field_id']['value'] : -1 ); |
| 6572 | |
| 6573 | $post_type = $data['filter']['wp_post_type']['value']; |
| 6574 | |
| 6575 | if ( -1 === $field ) { |
| 6576 | $metaboxes = (array) get_option( 'jet_engine_meta_boxes', [] ); |
| 6577 | |
| 6578 | $post_fields = array_filter( |
| 6579 | $metaboxes, |
| 6580 | function( $metabox ) { |
| 6581 | /** |
| 6582 | * |
| 6583 | * Ignore line |
| 6584 | * |
| 6585 | * @phpstan-ignore-next-line |
| 6586 | */ |
| 6587 | return 'post' === $metabox['args']['object_type']; |
| 6588 | } |
| 6589 | ); |
| 6590 | |
| 6591 | $options = []; |
| 6592 | if ( ! empty( $post_fields ) ) { |
| 6593 | if ( is_array( $post_fields ) ) { |
| 6594 | foreach ( $post_fields as $post_field ) { |
| 6595 | if ( in_array( $post_type, $post_field['args']['allowed_post_type'], true ) ) { |
| 6596 | foreach ( $post_field['meta_fields'] as $meta_field ) { |
| 6597 | $options[] = $meta_field['name']; |
| 6598 | } |
| 6599 | } |
| 6600 | } |
| 6601 | } |
| 6602 | } |
| 6603 | $random_key = array_rand( $options ); |
| 6604 | $random_value = $options[ $random_key ]; |
| 6605 | $string = '%' . $random_value . '%'; |
| 6606 | } else { |
| 6607 | $string = '%' . $data['filter']['field_id']['value'] . '%'; |
| 6608 | } |
| 6609 | |
| 6610 | $result = $wpdb->get_results( |
| 6611 | $wpdb->prepare( |
| 6612 | 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key LIKE %s', |
| 6613 | [ $string ] |
| 6614 | ), |
| 6615 | ARRAY_A |
| 6616 | ); |
| 6617 | |
| 6618 | $ids = []; |
| 6619 | |
| 6620 | if ( ! empty( $result ) ) { |
| 6621 | foreach ( $result as $val ) { |
| 6622 | $ids[] = $val['post_id']; |
| 6623 | } |
| 6624 | } |
| 6625 | |
| 6626 | $lastupdated_args = [ |
| 6627 | 'post_type' => $post_type, |
| 6628 | 'orderby' => 'modified', |
| 6629 | 'post__in' => $ids, |
| 6630 | 'posts_per_page' => 1, |
| 6631 | ]; |
| 6632 | $lastupdated_loop = get_posts( $lastupdated_args ); |
| 6633 | |
| 6634 | $response = []; |
| 6635 | if ( ! empty( $result ) ) { |
| 6636 | $context['post'] = $lastupdated_loop[0]; |
| 6637 | |
| 6638 | $meta_value = get_post_meta( $lastupdated_loop[0]->ID, sprintf( '%s', $data['filter']['field_id']['value'] ), true ); |
| 6639 | $meta_key = sprintf( '%s', $data['filter']['field_id']['value'] ); |
| 6640 | |
| 6641 | $context[ $meta_key ] = $meta_value; |
| 6642 | |
| 6643 | $response['pluggable_data'] = $context; |
| 6644 | $response['response_type'] = 'live'; |
| 6645 | } else { |
| 6646 | $response = json_decode( '{"response_type":"sample","pluggable_data":{"post":{"ID":198,"post_author":"1","post_date":"2023-02-08 13:31:13","post_date_gmt":"2023-02-08 13:31:13","post_content":"New Category1 - content","post_title":"jennjennn - Post - jenn","post_excerpt":"","post_status":"publish","comment_status":"open","ping_status":"open","post_password":"","post_name":"jennjennn-post-jenn","to_ping":"","pinged":"","post_modified":"2023-04-10 06:23:40","post_modified_gmt":"2023-04-10 06:23:40","post_content_filtered":"","post_parent":0,"guid":"https:\/\/suretriggerswp.local\/jennjennn-post-jenn\/","menu_order":0,"post_type":"post","post_mime_type":"","comment_count":"0","filter":"raw"},"enter-post-extra-content-title":"dummy"}}', true ); |
| 6647 | } |
| 6648 | |
| 6649 | return $response; |
| 6650 | |
| 6651 | } |
| 6652 | |
| 6653 | /** |
| 6654 | * Get Formidable Forms. |
| 6655 | * |
| 6656 | * @param array $data data. |
| 6657 | * |
| 6658 | * @return array|void |
| 6659 | */ |
| 6660 | public function search_formidable_form_list( $data ) { |
| 6661 | if ( ! class_exists( 'FrmForm' ) ) { |
| 6662 | return; |
| 6663 | } |
| 6664 | |
| 6665 | $query = [ |
| 6666 | [ |
| 6667 | 'or' => 1, |
| 6668 | 'parent_form_id' => null, |
| 6669 | 'parent_form_id <' => 1, |
| 6670 | ], |
| 6671 | ]; |
| 6672 | $query['is_template'] = 0; |
| 6673 | $query['status !'] = 'trash'; |
| 6674 | $forms_list = FrmForm::getAll( $query, '', ' 0, 10' ); |
| 6675 | |
| 6676 | $options = []; |
| 6677 | |
| 6678 | if ( ! empty( $forms_list ) ) { |
| 6679 | if ( is_array( $forms_list ) ) { |
| 6680 | foreach ( $forms_list as $form ) { |
| 6681 | $options[] = [ |
| 6682 | 'label' => $form->name, |
| 6683 | 'value' => $form->id, |
| 6684 | ]; |
| 6685 | } |
| 6686 | } |
| 6687 | } |
| 6688 | |
| 6689 | return [ |
| 6690 | 'options' => $options, |
| 6691 | 'hasMore' => false, |
| 6692 | ]; |
| 6693 | } |
| 6694 | |
| 6695 | /** |
| 6696 | * Get JetFormBuilder Form List. |
| 6697 | * |
| 6698 | * @param array $data data. |
| 6699 | * |
| 6700 | * @return array|void |
| 6701 | */ |
| 6702 | public function search_jetform_list( $data ) { |
| 6703 | if ( ! class_exists( '\Jet_Form_Builder\Classes\Tools' ) ) { |
| 6704 | return; |
| 6705 | } |
| 6706 | |
| 6707 | $forms = \Jet_Form_Builder\Classes\Tools::get_forms_list_for_js(); |
| 6708 | |
| 6709 | $options = []; |
| 6710 | foreach ( $forms as $form ) { |
| 6711 | |
| 6712 | if ( ! empty( $form['value'] ) ) { |
| 6713 | $options[] = [ |
| 6714 | 'label' => esc_html( $form['label'] ), |
| 6715 | 'value' => esc_attr( $form['value'] ), |
| 6716 | ]; |
| 6717 | } |
| 6718 | } |
| 6719 | |
| 6720 | return [ |
| 6721 | 'options' => $options, |
| 6722 | 'hasMore' => false, |
| 6723 | ]; |
| 6724 | } |
| 6725 | |
| 6726 | /** |
| 6727 | * Get Forminator Form List. |
| 6728 | * |
| 6729 | * @param array $data data. |
| 6730 | * |
| 6731 | * @return array|void |
| 6732 | */ |
| 6733 | public function search_forminator_form_list( $data ) { |
| 6734 | if ( ! class_exists( 'Forminator_API' ) ) { |
| 6735 | return; |
| 6736 | } |
| 6737 | |
| 6738 | $forms = Forminator_API::get_forms( null, 1, 10 ); |
| 6739 | |
| 6740 | $options = []; |
| 6741 | foreach ( $forms as $form ) { |
| 6742 | $options[] = [ |
| 6743 | 'label' => isset( $form->settings ) && isset( $form->settings['form_name'] ) ? $form->settings['form_name'] : $form->name, |
| 6744 | 'value' => $form->id, |
| 6745 | ]; |
| 6746 | } |
| 6747 | |
| 6748 | return [ |
| 6749 | 'options' => $options, |
| 6750 | 'hasMore' => false, |
| 6751 | ]; |
| 6752 | } |
| 6753 | |
| 6754 | |
| 6755 | /** |
| 6756 | * Get BbPress topics list. |
| 6757 | * |
| 6758 | * @param array $data data. |
| 6759 | * |
| 6760 | * @return array|void |
| 6761 | */ |
| 6762 | public function search_bbp_topic_list( $data ) { |
| 6763 | $page = $data['page']; |
| 6764 | $forum_id = $data['dynamic']; |
| 6765 | $limit = Utilities::get_search_page_limit(); |
| 6766 | $offset = $limit * ( $page - 1 ); |
| 6767 | $args = [ |
| 6768 | 'post_type' => 'topic', |
| 6769 | 'offset' => $offset, |
| 6770 | 'meta_query' => [ |
| 6771 | [ |
| 6772 | 'key' => '_bbp_forum_id', |
| 6773 | 'value' => $forum_id, |
| 6774 | 'compare' => '==', |
| 6775 | ], |
| 6776 | ], |
| 6777 | ]; |
| 6778 | |
| 6779 | $topics = get_posts( $args ); |
| 6780 | $topics_count = count( $topics ); |
| 6781 | |
| 6782 | $options = []; |
| 6783 | if ( ! empty( $topics ) ) { |
| 6784 | if ( is_array( $topics ) ) { |
| 6785 | foreach ( $topics as $topic ) { |
| 6786 | $options[] = [ |
| 6787 | 'label' => $topic->post_title, |
| 6788 | 'value' => $topic->ID, |
| 6789 | ]; |
| 6790 | } |
| 6791 | } |
| 6792 | } |
| 6793 | return [ |
| 6794 | 'options' => $options, |
| 6795 | 'hasMore' => $topics_count > $limit && $topics_count > $offset, |
| 6796 | ]; |
| 6797 | } |
| 6798 | |
| 6799 | |
| 6800 | /** |
| 6801 | * Search Last Updated Field Data. |
| 6802 | * |
| 6803 | * @param array $data data. |
| 6804 | * @return array |
| 6805 | */ |
| 6806 | public function search_bbp_last_data( $data ) { |
| 6807 | global $wpdb; |
| 6808 | |
| 6809 | $post_type = $data['post_type']; |
| 6810 | $trigger = $data['search_term']; |
| 6811 | $context = []; |
| 6812 | |
| 6813 | if ( 'topic' === $post_type ) { |
| 6814 | $post_id = $data['filter']['forum']['value']; |
| 6815 | if ( -1 === $post_id ) { |
| 6816 | $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 = 'topic' AND postmeta.meta_key= '_bbp_forum_id' ORDER BY posts.ID DESC LIMIT 1" ); |
| 6817 | |
| 6818 | } else { |
| 6819 | $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 ='topic' AND postmeta.meta_key= '_bbp_forum_id' AND postmeta.meta_value=%s ORDER BY posts.ID DESC LIMIT 1", $post_id ) ); |
| 6820 | |
| 6821 | } |
| 6822 | } elseif ( 'reply' === $post_type ) { |
| 6823 | $post_id = $data['filter']['topic']['value']; |
| 6824 | |
| 6825 | if ( -1 === $post_id ) { |
| 6826 | $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 = 'reply' AND postmeta.meta_key= '_bbp_topic_id' ORDER BY posts.ID DESC LIMIT 1" ); |
| 6827 | |
| 6828 | } else { |
| 6829 | $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 ='reply' AND postmeta.meta_key= '_bbp_topic_id' AND postmeta.meta_value=%s ORDER BY posts.ID DESC LIMIT 1", $post_id ) ); |
| 6830 | } |
| 6831 | } |
| 6832 | |
| 6833 | |
| 6834 | $response = []; |
| 6835 | if ( ! empty( $result ) ) { |
| 6836 | if ( 'bbpress_topic_created' === $trigger ) { |
| 6837 | $topic_id = $result[0]->post_id; |
| 6838 | $forum_id = $result[0]->meta_value; |
| 6839 | $topic = get_the_title( $topic_id ); |
| 6840 | $topic_link = get_the_permalink( $topic_id ); |
| 6841 | $topic_description = get_the_content( $topic_id ); |
| 6842 | $topic_status = get_post_status( $topic_id ); |
| 6843 | |
| 6844 | $forum = get_the_title( $forum_id ); |
| 6845 | $forum_link = get_the_permalink( $forum_id ); |
| 6846 | $forum_description = get_the_content( $forum_id ); |
| 6847 | $forum_status = get_post_status( $forum_id ); |
| 6848 | |
| 6849 | $forum = [ |
| 6850 | 'forum' => $forum_id, |
| 6851 | 'forum_title' => $forum, |
| 6852 | 'forum_link' => $forum_link, |
| 6853 | 'forum_description' => $forum_description, |
| 6854 | 'forum_status' => $forum_status, |
| 6855 | ]; |
| 6856 | |
| 6857 | $topic = [ |
| 6858 | 'topic_title' => $topic, |
| 6859 | 'topic_link' => $topic_link, |
| 6860 | 'topic_description' => $topic_description, |
| 6861 | 'topic_status' => $topic_status, |
| 6862 | ]; |
| 6863 | |
| 6864 | $user_id = $result[0]->post_author; |
| 6865 | $context = array_merge( |
| 6866 | WordPress::get_user_context( $user_id ), |
| 6867 | $forum, |
| 6868 | $topic |
| 6869 | ); |
| 6870 | |
| 6871 | $response['pluggable_data'] = $context; |
| 6872 | $response['response_type'] = 'live'; |
| 6873 | } else { |
| 6874 | $reply_id = $result[0]->post_id; |
| 6875 | $topic_id = $result[0]->meta_value; |
| 6876 | $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true ); |
| 6877 | $forum_id = intval( '"' . $forum_id . '"' ); |
| 6878 | $reply = get_the_title( $reply_id ); |
| 6879 | $reply_link = get_the_permalink( $reply_id ); |
| 6880 | $reply_description = get_the_content( $reply_id ); |
| 6881 | $reply_status = get_post_status( $reply_id ); |
| 6882 | |
| 6883 | |
| 6884 | $topic = get_the_title( $topic_id ); |
| 6885 | $topic_link = get_the_permalink( $topic_id ); |
| 6886 | $topic_description = get_the_content( $topic_id ); |
| 6887 | $topic_status = get_post_status( $topic_id ); |
| 6888 | |
| 6889 | $forum = get_the_title( $forum_id ); |
| 6890 | $forum_link = get_the_permalink( $forum_id ); |
| 6891 | $forum_description = get_the_content( null, false, $forum_id ); |
| 6892 | $forum_status = get_post_status( $forum_id ); |
| 6893 | |
| 6894 | $forum = [ |
| 6895 | 'forum' => $forum_id, |
| 6896 | 'forum_title' => $forum, |
| 6897 | 'forum_link' => $forum_link, |
| 6898 | 'forum_description' => $forum_description, |
| 6899 | 'forum_status' => $forum_status, |
| 6900 | ]; |
| 6901 | |
| 6902 | $topic = [ |
| 6903 | 'topic_title' => $topic, |
| 6904 | 'topic_link' => $topic_link, |
| 6905 | 'topic_description' => $topic_description, |
| 6906 | 'topic_status' => $topic_status, |
| 6907 | ]; |
| 6908 | |
| 6909 | $reply = [ |
| 6910 | 'reply_title' => $reply, |
| 6911 | 'reply_link' => $reply_link, |
| 6912 | 'reply_description' => $reply_description, |
| 6913 | 'reply_status' => $reply_status, |
| 6914 | ]; |
| 6915 | $user_id = $result[0]->post_author; |
| 6916 | $context = array_merge( |
| 6917 | WordPress::get_user_context( $user_id ), |
| 6918 | $forum, |
| 6919 | $topic, |
| 6920 | $reply |
| 6921 | ); |
| 6922 | |
| 6923 | $response['pluggable_data'] = $context; |
| 6924 | $response['response_type'] = 'live'; |
| 6925 | } |
| 6926 | } |
| 6927 | |
| 6928 | return $response; |
| 6929 | } |
| 6930 | |
| 6931 | /** |
| 6932 | * Search Last Updated Field Data. |
| 6933 | * |
| 6934 | * @param array $data data. |
| 6935 | * @return array|void |
| 6936 | */ |
| 6937 | public function search_happyform_list( $data ) { |
| 6938 | if ( ! function_exists( 'happyforms_get_form_controller' ) ) { |
| 6939 | return; |
| 6940 | } |
| 6941 | |
| 6942 | $form_controller = happyforms_get_form_controller(); |
| 6943 | |
| 6944 | $forms = $form_controller->do_get(); |
| 6945 | $options = []; |
| 6946 | if ( ! empty( $forms ) ) { |
| 6947 | foreach ( $forms as $form ) { |
| 6948 | $options[] = [ |
| 6949 | 'label' => $form['post_title'], |
| 6950 | 'value' => $form['ID'], |
| 6951 | ]; |
| 6952 | } |
| 6953 | } |
| 6954 | |
| 6955 | return [ |
| 6956 | 'options' => $options, |
| 6957 | 'hasMore' => false, |
| 6958 | ]; |
| 6959 | } |
| 6960 | |
| 6961 | /** |
| 6962 | * Get Memberpress Course List. |
| 6963 | * |
| 6964 | * @param array $data data. |
| 6965 | * |
| 6966 | * @return array|void |
| 6967 | */ |
| 6968 | public function search_mpc_lessons_list( $data ) { |
| 6969 | if ( ! class_exists( '\memberpress\courses\models\Lesson' ) ) { |
| 6970 | return; |
| 6971 | } |
| 6972 | global $wpdb; |
| 6973 | $options = []; |
| 6974 | $course_id = $data['dynamic']; |
| 6975 | $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mpcs_sections WHERE course_id =%s", $course_id ) ); |
| 6976 | $sections = []; |
| 6977 | foreach ( $result as $rec ) { |
| 6978 | $sections[] = [ |
| 6979 | 'id' => $rec->id, |
| 6980 | 'title' => $rec->title, |
| 6981 | ]; |
| 6982 | } |
| 6983 | if ( is_array( $sections ) && count( $sections ) > 0 ) { |
| 6984 | foreach ( $sections as $section ) { |
| 6985 | $post_types_string = \memberpress\courses\models\Lesson::lesson_cpts(); |
| 6986 | $post_types_string = implode( "','", $post_types_string ); |
| 6987 | |
| 6988 | $query = $wpdb->prepare( |
| 6989 | "SELECT * FROM {$wpdb->posts} AS p |
| 6990 | JOIN {$wpdb->postmeta} AS pm |
| 6991 | ON p.ID = pm.post_id |
| 6992 | AND pm.meta_key = %s |
| 6993 | AND pm.meta_value = %s |
| 6994 | JOIN {$wpdb->postmeta} AS pm_order |
| 6995 | ON p.ID = pm_order.post_id |
| 6996 | AND pm_order.meta_key = %s |
| 6997 | WHERE p.post_type in ( %s ) AND p.post_status <> 'trash' |
| 6998 | ORDER BY pm_order.meta_value * 1", |
| 6999 | models\Lesson::$section_id_str, |
| 7000 | $section['id'], |
| 7001 | models\Lesson::$lesson_order_str, |
| 7002 | stripcslashes( $post_types_string ) |
| 7003 | ); |
| 7004 | |
| 7005 | $db_lessons = $wpdb->get_results( stripcslashes( $query ) ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 7006 | foreach ( $db_lessons as $lesson ) { |
| 7007 | $options[] = [ |
| 7008 | 'label' => $section['title'] . '->' . $lesson->post_title, |
| 7009 | 'value' => $lesson->ID, |
| 7010 | ]; |
| 7011 | } |
| 7012 | } |
| 7013 | } |
| 7014 | return [ |
| 7015 | 'options' => $options, |
| 7016 | 'hasMore' => false, |
| 7017 | ]; |
| 7018 | } |
| 7019 | |
| 7020 | /** |
| 7021 | * Get Memberpress Course List. |
| 7022 | * |
| 7023 | * @param array $data data. |
| 7024 | * |
| 7025 | * @return array|void |
| 7026 | */ |
| 7027 | public function search_gp_rank_type_list( $data ) { |
| 7028 | global $wpdb; |
| 7029 | |
| 7030 | $posts = $wpdb->get_results( |
| 7031 | "SELECT ID, post_name, post_title, post_type |
| 7032 | FROM $wpdb->posts |
| 7033 | WHERE post_type LIKE 'rank-type' AND post_status = 'publish' ORDER BY post_title ASC" |
| 7034 | ); |
| 7035 | |
| 7036 | $posts_count = count( $posts ); |
| 7037 | |
| 7038 | $options = []; |
| 7039 | if ( $posts ) { |
| 7040 | foreach ( $posts as $post ) { |
| 7041 | $options[] = [ |
| 7042 | 'label' => $post->post_title, |
| 7043 | 'value' => $post->post_name, |
| 7044 | ]; |
| 7045 | } |
| 7046 | } |
| 7047 | |
| 7048 | return [ |
| 7049 | 'options' => $options, |
| 7050 | 'hasMore' => false, |
| 7051 | ]; |
| 7052 | } |
| 7053 | |
| 7054 | /** |
| 7055 | * Get MPC last data. |
| 7056 | * |
| 7057 | * @param array $data data. |
| 7058 | * |
| 7059 | * @return array |
| 7060 | */ |
| 7061 | public function search_mpc_last_data( $data ) { |
| 7062 | global $wpdb; |
| 7063 | $trigger = $data['search_term']; |
| 7064 | $course_data = []; |
| 7065 | $lesson_data = []; |
| 7066 | $context = []; |
| 7067 | |
| 7068 | if ( 'mpc_course_completed' === $trigger ) { |
| 7069 | $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course]']['value'] : '-1' ); |
| 7070 | if ( $course_id > 0 ) { |
| 7071 | |
| 7072 | $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE ID= %s ORDER BY id DESC LIMIT 1", $course_id ) ); |
| 7073 | } else { |
| 7074 | $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}posts where post_type = 'mpcs-course' ORDER BY id DESC LIMIT 1" ); |
| 7075 | } |
| 7076 | |
| 7077 | if ( ! empty( $course ) ) { |
| 7078 | $course_data = [ |
| 7079 | 'course_id' => $course->ID, |
| 7080 | 'course_title' => get_the_title( $course_id ), |
| 7081 | 'course_url' => get_permalink( $course_id ), |
| 7082 | 'course_featured_image_id' => get_post_meta( $course_id, '_thumbnail_id', true ), |
| 7083 | 'course_featured_image_url' => get_the_post_thumbnail_url( $course_id ), |
| 7084 | ]; |
| 7085 | } |
| 7086 | $user_progress = $wpdb->get_row( $wpdb->prepare( "SELECT user_id FROM {$wpdb->prefix}mpcs_user_progress WHERE course_id=%s", $course_id ) ); |
| 7087 | if ( ! empty( $user_progress ) ) { |
| 7088 | $context['response_type'] = 'live'; |
| 7089 | $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_progress->user_id ), $course_data, $lesson_data ); |
| 7090 | } else { |
| 7091 | $sample_data = '{"pluggable_data":{"wp_user_id":1,"user_login":"suretriggers","display_name":"suretriggers","user_firstname":"suretriggers","user_lastname":"suretriggers","user_email":"hello@suretriggers.io","user_role":["administrator","subscriber","tutor_instructor","bbp_keymaster"],"course_id":617,"course_title":"Course One","course_url":"https:\/\/connector.com\/courses\/course-one\/","course_featured_image_id":"","course_featured_image_url":false} |
| 7092 | ,"response_type":"sample"} '; |
| 7093 | $context = json_decode( $sample_data, true ); |
| 7094 | } |
| 7095 | } elseif ( 'mpc_lesson_completed' === $trigger ) { |
| 7096 | $lesson_id = (int) ( isset( $data['filter']['lesson']['value'] ) ? $data['filter']['lesson']['value'] : '-1' ); |
| 7097 | $course_id = (int) $data['filter']['course']['value']; |
| 7098 | if ( $lesson_id > 0 ) { |
| 7099 | |
| 7100 | $lesson = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE ID= %s ORDER BY id DESC LIMIT 1", $lesson_id ) ); |
| 7101 | } else { |
| 7102 | $lesson = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}posts where post_type = 'mpcs-lesson' ORDER BY id DESC LIMIT 1" ); |
| 7103 | } |
| 7104 | |
| 7105 | if ( ! empty( $lesson ) ) { |
| 7106 | $lesson_data = [ |
| 7107 | 'lesson_id' => $lesson->ID, |
| 7108 | 'lesson_title' => get_the_title( $lesson_id ), |
| 7109 | 'lesson_url' => get_permalink( $lesson_id ), |
| 7110 | 'lesson_featured_image_id' => get_post_meta( $lesson_id, '_thumbnail_id', true ), |
| 7111 | 'lesson_featured_image_url' => get_the_post_thumbnail_url( $lesson_id ), |
| 7112 | ]; |
| 7113 | |
| 7114 | $lesson_section_id = get_post_meta( $lesson->ID, '_mpcs_lesson_section_id', true ); |
| 7115 | |
| 7116 | $section = $wpdb->get_row( $wpdb->prepare( "SELECT course_id FROM {$wpdb->prefix}mpcs_sections WHERE ID= %s", $lesson_section_id ) ); |
| 7117 | |
| 7118 | $course_data = [ |
| 7119 | 'course_id' => $course_id, |
| 7120 | 'course_title' => get_the_title( $course_id ), |
| 7121 | 'course_url' => get_permalink( $course_id ), |
| 7122 | 'course_featured_image_id' => get_post_meta( $course_id, '_thumbnail_id', true ), |
| 7123 | 'course_featured_image_url' => get_the_post_thumbnail_url( $section->course_id ), |
| 7124 | ]; |
| 7125 | } |
| 7126 | |
| 7127 | $user_progress = $wpdb->get_row( $wpdb->prepare( "SELECT user_id FROM {$wpdb->prefix}mpcs_user_progress WHERE lesson_id= %s AND course_id=%s", $lesson_id, $course_id ) ); |
| 7128 | if ( ! empty( $user_progress ) ) { |
| 7129 | $context['response_type'] = 'live'; |
| 7130 | $context['pluggable_data'] = array_merge( WordPress::get_user_context( $user_progress->user_id ), $course_data, $lesson_data ); |
| 7131 | } else { |
| 7132 | $sample_data = '{"pluggable_data":{"wp_user_id":1,"user_login":"suretriggers","display_name":"suretriggers","user_firstname":"suretriggers","user_lastname":"dev","user_email":"hello@suretriggers.com","user_role":["administrator","subscriber","tutor_instructor","bbp_keymaster"],"lesson_id":620,"lesson_title":"second section","lesson_url":"https:\/\/connector.com\/courses\/course-one\/lessons\/second-section\/","lesson_featured_image_id":"","lesson_featured_image_url":false,"course_id":617,"course_title":"Course One","course_url":"https:\/\/connector.com\/courses\/course-one\/","course_featured_image_id":"","course_featured_image_url":false},"response_type":"sample"}'; |
| 7133 | $context = json_decode( $sample_data, true ); |
| 7134 | } |
| 7135 | } |
| 7136 | |
| 7137 | |
| 7138 | return $context; |
| 7139 | } |
| 7140 | |
| 7141 | /** Get GamiPress Rank List. |
| 7142 | * |
| 7143 | * @param array $data data. |
| 7144 | * |
| 7145 | * @return array|void |
| 7146 | */ |
| 7147 | public function search_gp_rank_list( $data ) { |
| 7148 | global $wpdb; |
| 7149 | |
| 7150 | $page = $data['page']; |
| 7151 | $limit = Utilities::get_search_page_limit(); |
| 7152 | $offset = $limit * ( $page - 1 ); |
| 7153 | |
| 7154 | $args = [ |
| 7155 | 'post_type' => $data['dynamic']['rank_type'], |
| 7156 | 'posts_per_page' => $limit, |
| 7157 | 'offset' => $offset, |
| 7158 | 'orderby' => 'title', |
| 7159 | 'order' => 'ASC', |
| 7160 | 'post_status' => 'publish', |
| 7161 | 's' => $data['search_term'], |
| 7162 | ]; |
| 7163 | |
| 7164 | $rank_type = get_posts( $args ); |
| 7165 | |
| 7166 | $count_args = [ |
| 7167 | 'post_type' => $data['dynamic']['rank_type'], |
| 7168 | 'posts_per_page' => -1, |
| 7169 | 'post_status' => 'publish', |
| 7170 | 's' => $data['search_term'], |
| 7171 | ]; |
| 7172 | |
| 7173 | $rank_posts = get_posts( $count_args ); |
| 7174 | $rank_type_count = count( $rank_posts ); |
| 7175 | |
| 7176 | $options = []; |
| 7177 | if ( $rank_type ) { |
| 7178 | foreach ( $rank_type as $rank ) { |
| 7179 | $options[] = [ |
| 7180 | 'label' => $rank->post_title, |
| 7181 | 'value' => $rank->ID, |
| 7182 | ]; |
| 7183 | } |
| 7184 | } |
| 7185 | |
| 7186 | return [ |
| 7187 | 'options' => $options, |
| 7188 | 'hasMore' => $rank_type_count > $limit && $rank_type_count > $offset, |
| 7189 | ]; |
| 7190 | } |
| 7191 | |
| 7192 | /** |
| 7193 | * Get GamiPress PointType List. |
| 7194 | * |
| 7195 | * @param array $data data. |
| 7196 | * |
| 7197 | * @return array|void |
| 7198 | */ |
| 7199 | public function search_gp_point_type_list( $data ) { |
| 7200 | global $wpdb; |
| 7201 | |
| 7202 | $page = $data['page']; |
| 7203 | $limit = Utilities::get_search_page_limit(); |
| 7204 | $offset = $limit * ( $page - 1 ); |
| 7205 | |
| 7206 | $args = [ |
| 7207 | 'post_type' => 'points-type', |
| 7208 | 'posts_per_page' => $limit, |
| 7209 | 'offset' => $offset, |
| 7210 | 'orderby' => 'title', |
| 7211 | 'order' => 'ASC', |
| 7212 | 'post_status' => 'publish', |
| 7213 | 's' => $data['search_term'], |
| 7214 | ]; |
| 7215 | |
| 7216 | $point_type = get_posts( $args ); |
| 7217 | |
| 7218 | $count_args = [ |
| 7219 | 'post_type' => 'points-type', |
| 7220 | 'posts_per_page' => -1, |
| 7221 | 'post_status' => 'publish', |
| 7222 | 's' => $data['search_term'], |
| 7223 | ]; |
| 7224 | |
| 7225 | $count_point_type = get_posts( $count_args ); |
| 7226 | $point_type_count = count( $count_point_type ); |
| 7227 | |
| 7228 | $options = []; |
| 7229 | if ( $point_type ) { |
| 7230 | foreach ( $point_type as $point ) { |
| 7231 | $options[] = [ |
| 7232 | 'label' => $point->post_title, |
| 7233 | 'value' => $point->ID, |
| 7234 | ]; |
| 7235 | } |
| 7236 | } |
| 7237 | |
| 7238 | return [ |
| 7239 | 'options' => $options, |
| 7240 | 'hasMore' => $point_type_count > $limit && $point_type_count > $offset, |
| 7241 | ]; |
| 7242 | } |
| 7243 | |
| 7244 | /** |
| 7245 | * Get GamiPress AchievementType List. |
| 7246 | * |
| 7247 | * @param array $data data. |
| 7248 | * |
| 7249 | * @return array|void |
| 7250 | */ |
| 7251 | public function search_gp_achivement_type_list( $data ) { |
| 7252 | global $wpdb; |
| 7253 | |
| 7254 | $posts = $wpdb->get_results( |
| 7255 | "SELECT ID, post_name, post_title, post_type |
| 7256 | FROM $wpdb->posts |
| 7257 | WHERE post_type LIKE 'achievement-type' AND post_status = 'publish' ORDER BY post_title ASC" |
| 7258 | ); |
| 7259 | |
| 7260 | $posts_count = count( $posts ); |
| 7261 | |
| 7262 | $options = []; |
| 7263 | if ( $posts ) { |
| 7264 | foreach ( $posts as $post ) { |
| 7265 | $options[] = [ |
| 7266 | 'label' => $post->post_title, |
| 7267 | 'value' => $post->post_name, |
| 7268 | ]; |
| 7269 | } |
| 7270 | } |
| 7271 | |
| 7272 | $options[] = [ |
| 7273 | 'label' => 'Points awards', |
| 7274 | 'value' => 'points-award', |
| 7275 | ]; |
| 7276 | $options[] = [ |
| 7277 | 'label' => 'Step', |
| 7278 | 'value' => 'step', |
| 7279 | ]; |
| 7280 | $options[] = [ |
| 7281 | 'label' => 'Rank requirement', |
| 7282 | 'value' => 'rank-requirement', |
| 7283 | ]; |
| 7284 | |
| 7285 | return [ |
| 7286 | 'options' => $options, |
| 7287 | 'hasMore' => false, |
| 7288 | ]; |
| 7289 | } |
| 7290 | |
| 7291 | /** |
| 7292 | * Get GamiPress Award List. |
| 7293 | * |
| 7294 | * @param array $data data. |
| 7295 | * |
| 7296 | * @return array|void |
| 7297 | */ |
| 7298 | public function search_gp_award_list( $data ) { |
| 7299 | global $wpdb; |
| 7300 | |
| 7301 | $page = $data['page']; |
| 7302 | $limit = Utilities::get_search_page_limit(); |
| 7303 | $offset = $limit * ( $page - 1 ); |
| 7304 | |
| 7305 | $args = [ |
| 7306 | 'post_type' => $data['dynamic']['achivement_type'], |
| 7307 | 'posts_per_page' => $limit, |
| 7308 | 'offset' => $offset, |
| 7309 | 'orderby' => 'title', |
| 7310 | 'order' => 'ASC', |
| 7311 | 'post_status' => 'publish', |
| 7312 | 's' => $data['search_term'], |
| 7313 | ]; |
| 7314 | |
| 7315 | $award_type = get_posts( $args ); |
| 7316 | $count_args = [ |
| 7317 | 'post_type' => $data['dynamic']['achivement_type'], |
| 7318 | 'posts_per_page' => -1, |
| 7319 | 'post_status' => 'publish', |
| 7320 | 's' => $data['search_term'], |
| 7321 | ]; |
| 7322 | |
| 7323 | $count_award_type = get_posts( $count_args ); |
| 7324 | $award_type_count = count( $count_award_type ); |
| 7325 | $options = []; |
| 7326 | if ( $award_type ) { |
| 7327 | foreach ( $award_type as $award ) { |
| 7328 | $options[] = [ |
| 7329 | 'label' => $award->post_title, |
| 7330 | 'value' => $award->ID, |
| 7331 | ]; |
| 7332 | } |
| 7333 | } |
| 7334 | |
| 7335 | return [ |
| 7336 | 'options' => $options, |
| 7337 | 'hasMore' => $award_type_count > $limit && $award_type_count > $offset, |
| 7338 | ]; |
| 7339 | } |
| 7340 | |
| 7341 | /** |
| 7342 | * Get Woocommerce Subscription Product List. |
| 7343 | * |
| 7344 | * @param array $data data. |
| 7345 | * |
| 7346 | * @return array|void |
| 7347 | */ |
| 7348 | public function search_wc_subscription_product_list( $data ) { |
| 7349 | global $wpdb; |
| 7350 | |
| 7351 | $subscriptions = $wpdb->get_results( |
| 7352 | $wpdb->prepare( |
| 7353 | "SELECT posts.ID, posts.post_title FROM $wpdb->posts as posts |
| 7354 | LEFT JOIN $wpdb->term_relationships as rel ON (posts.ID = rel.object_id) |
| 7355 | WHERE rel.term_taxonomy_id IN (SELECT term_id FROM $wpdb->terms WHERE slug IN ('subscription','variable-subscription')) |
| 7356 | AND posts.post_type = %s |
| 7357 | AND posts.post_status = %s |
| 7358 | UNION ALL |
| 7359 | SELECT ID, post_title FROM $wpdb->posts |
| 7360 | WHERE post_type = %s |
| 7361 | AND post_status = %s |
| 7362 | ORDER BY post_title", |
| 7363 | 'product', |
| 7364 | 'publish', |
| 7365 | 'shop_subscription', |
| 7366 | 'publish' |
| 7367 | ) |
| 7368 | ); |
| 7369 | |
| 7370 | $options = []; |
| 7371 | if ( $subscriptions ) { |
| 7372 | foreach ( $subscriptions as $post ) { |
| 7373 | $options[] = [ |
| 7374 | 'label' => $post->post_title, |
| 7375 | 'value' => $post->ID, |
| 7376 | ]; |
| 7377 | } |
| 7378 | } |
| 7379 | |
| 7380 | return [ |
| 7381 | 'options' => $options, |
| 7382 | 'hasMore' => false, |
| 7383 | ]; |
| 7384 | } |
| 7385 | |
| 7386 | /** |
| 7387 | * Get Woocommerce Subscriptions Variation list. |
| 7388 | * |
| 7389 | * @param array $data data. |
| 7390 | * |
| 7391 | * @return array|void |
| 7392 | */ |
| 7393 | public function search_wc_variable_subscription_list( $data ) { |
| 7394 | global $wpdb; |
| 7395 | |
| 7396 | $page = $data['page']; |
| 7397 | $limit = Utilities::get_search_page_limit(); |
| 7398 | $offset = $limit * ( $page - 1 ); |
| 7399 | |
| 7400 | if ( ! function_exists( 'wc_get_products' ) ) { |
| 7401 | return; |
| 7402 | } |
| 7403 | $subscription_products = wc_get_products( |
| 7404 | [ |
| 7405 | 'type' => [ 'variable-subscription' ], |
| 7406 | 'posts_per_page' => $limit, |
| 7407 | 'offset' => $offset, |
| 7408 | 'orderby' => 'date', |
| 7409 | 'order' => 'DESC', |
| 7410 | ] |
| 7411 | ); |
| 7412 | |
| 7413 | $subscription_products_count = count( (array) $subscription_products ); |
| 7414 | |
| 7415 | $options = []; |
| 7416 | if ( $subscription_products ) { |
| 7417 | foreach ( (array) $subscription_products as $product ) { |
| 7418 | $options[] = [ |
| 7419 | 'label' => $product->get_title(), |
| 7420 | 'value' => $product->get_id(), |
| 7421 | ]; |
| 7422 | } |
| 7423 | } |
| 7424 | |
| 7425 | return [ |
| 7426 | 'options' => $options, |
| 7427 | 'hasMore' => $subscription_products_count > $limit && $subscription_products_count > $offset, |
| 7428 | ]; |
| 7429 | } |
| 7430 | |
| 7431 | /** |
| 7432 | * Get Woocommerce Variation list. |
| 7433 | * |
| 7434 | * @param array $data data. |
| 7435 | * |
| 7436 | * @return array|void |
| 7437 | */ |
| 7438 | public function search_wc_variation_list( $data ) { |
| 7439 | global $wpdb; |
| 7440 | |
| 7441 | $page = $data['page']; |
| 7442 | $limit = Utilities::get_search_page_limit(); |
| 7443 | $offset = $limit * ( $page - 1 ); |
| 7444 | |
| 7445 | $args = [ |
| 7446 | 'post_type' => 'product_variation', |
| 7447 | 'post_parent' => $data['dynamic']['variable_subscription'], |
| 7448 | 'posts_per_page' => $limit, |
| 7449 | 'offset' => $offset, |
| 7450 | 'orderby' => 'ID', |
| 7451 | 'order' => 'ASC', |
| 7452 | 'post_status' => 'publish', |
| 7453 | ]; |
| 7454 | |
| 7455 | $variation = get_posts( $args ); |
| 7456 | $variation_count = count( $variation ); |
| 7457 | |
| 7458 | $options = []; |
| 7459 | if ( $variation ) { |
| 7460 | foreach ( $variation as $product ) { |
| 7461 | $options[] = [ |
| 7462 | 'label' => ! empty( $product->post_excerpt ) ? $product->post_excerpt : $product->post_title, |
| 7463 | 'value' => $product->ID, |
| 7464 | ]; |
| 7465 | } |
| 7466 | } |
| 7467 | |
| 7468 | return [ |
| 7469 | 'options' => $options, |
| 7470 | 'hasMore' => $variation_count > $limit && $variation_count > $offset, |
| 7471 | ]; |
| 7472 | } |
| 7473 | |
| 7474 | /** |
| 7475 | * Get Membership List. |
| 7476 | * |
| 7477 | * @param array $data data. |
| 7478 | * |
| 7479 | * @return array |
| 7480 | */ |
| 7481 | public function search_membership_list( $data ) { |
| 7482 | global $wpdb; |
| 7483 | |
| 7484 | $levels = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}pmpro_membership_levels ORDER BY id ASC" ); |
| 7485 | $options = []; |
| 7486 | if ( $levels ) { |
| 7487 | foreach ( $levels as $level ) { |
| 7488 | $options[] = [ |
| 7489 | 'label' => $level->name, |
| 7490 | 'value' => $level->id, |
| 7491 | ]; |
| 7492 | } |
| 7493 | } |
| 7494 | |
| 7495 | return [ |
| 7496 | 'options' => $options, |
| 7497 | 'hasMore' => false, |
| 7498 | ]; |
| 7499 | } |
| 7500 | |
| 7501 | /** |
| 7502 | |
| 7503 | * Get EventsManager last data. |
| 7504 | * |
| 7505 | * @param array $data data. |
| 7506 | * |
| 7507 | * @return array |
| 7508 | */ |
| 7509 | public function search_events_manager_data( $data ) { |
| 7510 | global $wpdb; |
| 7511 | $trigger = $data['search_term']; |
| 7512 | $context = []; |
| 7513 | |
| 7514 | $post_id = (int) ( isset( $data['filter']['post_id']['value'] ) ? $data['filter']['post_id']['value'] : '-1' ); |
| 7515 | if ( 'em_user_register_in_event' === $trigger ) { |
| 7516 | if ( $post_id > 0 ) { |
| 7517 | $event_id_id = get_post_meta( $post_id, '_event_id', true ); |
| 7518 | $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status NOT IN (2,3) AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); |
| 7519 | } else { |
| 7520 | $all_bookings = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status NOT IN (2,3) AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1" ); |
| 7521 | |
| 7522 | } |
| 7523 | |
| 7524 | if ( ! empty( $all_bookings ) ) { |
| 7525 | $user_id = $all_bookings->person_id; |
| 7526 | $location = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_locations as b WHERE b.location_id = %s", $all_bookings->location_id ) ); |
| 7527 | $context['pluggable_data'] = array_merge( |
| 7528 | WordPress::get_user_context( $user_id ), |
| 7529 | json_decode( wp_json_encode( $all_bookings ), true ) |
| 7530 | ); |
| 7531 | if ( ! empty( $location ) ) { |
| 7532 | $context['pluggable_data'] = array_merge( $context['pluggable_data'], json_decode( wp_json_encode( $location ), true ) ); |
| 7533 | } |
| 7534 | |
| 7535 | $context['response_type'] = 'live'; |
| 7536 | } |
| 7537 | } elseif ( 'em_user_unregister_from_event' === $trigger ) { |
| 7538 | |
| 7539 | if ( $post_id > 0 ) { |
| 7540 | $event_id_id = get_post_meta( $post_id, '_event_id', true ); |
| 7541 | $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status IN (2,3) AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); |
| 7542 | } else { |
| 7543 | $all_bookings = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status IN (2,3) AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1" ); |
| 7544 | |
| 7545 | } |
| 7546 | |
| 7547 | if ( ! empty( $all_bookings ) ) { |
| 7548 | $user_id = $all_bookings->person_id; |
| 7549 | $context['pluggable_data'] = array_merge( |
| 7550 | WordPress::get_user_context( $user_id ), |
| 7551 | json_decode( wp_json_encode( $all_bookings ), true ) |
| 7552 | ); |
| 7553 | $context['response_type'] = 'live'; |
| 7554 | } |
| 7555 | } elseif ( 'em_user_booking_approved' === $trigger ) { |
| 7556 | |
| 7557 | if ( $post_id > 0 ) { |
| 7558 | $event_id_id = get_post_meta( $post_id, '_event_id', true ); |
| 7559 | $all_bookings = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status=1 AND b.event_id = %s AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1", $event_id_id ) ); |
| 7560 | } else { |
| 7561 | $all_bookings = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}em_bookings as b INNER JOIN {$wpdb->prefix}em_events as e ON b.event_id = e.event_id WHERE e.event_status = 1 AND b.booking_status=1 AND e.event_end_date >= CURRENT_DATE ORDER BY b.booking_id DESC LIMIT 1" ); |
| 7562 | |
| 7563 | } |
| 7564 | |
| 7565 | if ( ! empty( $all_bookings ) ) { |
| 7566 | $user_id = $all_bookings->person_id; |
| 7567 | $location = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}em_locations as b WHERE b.location_id = %s", $all_bookings->location_id ) ); |
| 7568 | $context['pluggable_data'] = array_merge( |
| 7569 | WordPress::get_user_context( $user_id ), |
| 7570 | json_decode( wp_json_encode( $all_bookings ), true ) |
| 7571 | ); |
| 7572 | if ( ! empty( $location ) ) { |
| 7573 | $context['pluggable_data'] = array_merge( $context['pluggable_data'], json_decode( wp_json_encode( $location ), true ) ); |
| 7574 | } |
| 7575 | |
| 7576 | $context['response_type'] = 'live'; |
| 7577 | |
| 7578 | } |
| 7579 | } |
| 7580 | return $context; |
| 7581 | } |
| 7582 | |
| 7583 | /** |
| 7584 | |
| 7585 | * Get learnpress last data. |
| 7586 | * |
| 7587 | * @param array $data data. |
| 7588 | * |
| 7589 | * @return array |
| 7590 | */ |
| 7591 | public function search_learnpress_lms_last_data( $data ) { |
| 7592 | global $wpdb; |
| 7593 | $trigger = $data['search_term']; |
| 7594 | $course_data = []; |
| 7595 | $lesson_data = []; |
| 7596 | $context = []; |
| 7597 | |
| 7598 | |
| 7599 | if ( 'learnpress_course_completed' === $trigger ) { |
| 7600 | $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course']['value'] : '-1' ); |
| 7601 | if ( $course_id > 0 ) { |
| 7602 | |
| 7603 | $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_id= %s && user_id>0 && status= 'finished' ORDER BY item_id DESC LIMIT 1", $course_id ) ); |
| 7604 | } else { |
| 7605 | |
| 7606 | $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_type= 'lp_course' && user_id>0 && status= 'finished' ORDER BY item_id DESC LIMIT 1" ); |
| 7607 | } |
| 7608 | |
| 7609 | if ( ! empty( $course ) ) { |
| 7610 | $course_data = array_merge( WordPress::get_user_context( $course->user_id ), LearnPress::get_lpc_course_context( $course->item_id ) ); |
| 7611 | $context['response_type'] = 'live'; |
| 7612 | $context['pluggable_data'] = $course_data; |
| 7613 | } |
| 7614 | } elseif ( 'learnpress_lesson_completed' === $trigger ) { |
| 7615 | $lesson_id = (int) ( isset( $data['filter']['lesson']['value'] ) ? $data['filter']['lesson']['value'] : '-1' ); |
| 7616 | if ( $lesson_id > 0 ) { |
| 7617 | |
| 7618 | $lesson = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_id= %s && user_id>0 && status= 'completed' ORDER BY item_id DESC LIMIT 1", $lesson_id ) ); |
| 7619 | } else { |
| 7620 | |
| 7621 | $lesson = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_type= 'lp_lesson' && user_id>0 && status= 'completed' ORDER BY item_id DESC LIMIT 1" ); |
| 7622 | } |
| 7623 | |
| 7624 | if ( ! empty( $lesson ) ) { |
| 7625 | $lesson_data = array_merge( WordPress::get_user_context( $lesson->user_id ), LearnPress::get_lpc_lesson_context( $lesson->item_id ), LearnPress::get_lpc_course_context( $lesson->ref_id ) ); |
| 7626 | $context['response_type'] = 'live'; |
| 7627 | $context['pluggable_data'] = $lesson_data; |
| 7628 | } |
| 7629 | } elseif ( 'learnpress_user_enrolled_in_course' === $trigger ) { |
| 7630 | $course_id = (int) ( isset( $data['filter']['course']['value'] ) ? $data['filter']['course']['value'] : '-1' ); |
| 7631 | if ( $course_id > 0 ) { |
| 7632 | |
| 7633 | $course = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_id= %s && status= 'enrolled' ORDER BY item_id DESC LIMIT 1", $course_id ) ); |
| 7634 | } else { |
| 7635 | |
| 7636 | $course = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}learnpress_user_items WHERE item_type= 'lp_course' && user_id>0 && status= 'enrolled' ORDER BY item_id DESC LIMIT 1" ); |
| 7637 | } |
| 7638 | |
| 7639 | if ( ! empty( $course ) ) { |
| 7640 | $course_data = array_merge( WordPress::get_user_context( $course->user_id ), LearnPress::get_lpc_course_context( $course->item_id ) ); |
| 7641 | $context['response_type'] = 'live'; |
| 7642 | $context['pluggable_data'] = $course_data; |
| 7643 | |
| 7644 | } |
| 7645 | } |
| 7646 | |
| 7647 | return $context; |
| 7648 | } |
| 7649 | |
| 7650 | /** |
| 7651 | * Get Woocommerce Memberships Plan List. |
| 7652 | * |
| 7653 | * @param array $data data. |
| 7654 | * |
| 7655 | * @return array|void |
| 7656 | */ |
| 7657 | public function search_wc_membership_plan_list( $data ) { |
| 7658 | global $wpdb; |
| 7659 | |
| 7660 | $page = $data['page']; |
| 7661 | $limit = Utilities::get_search_page_limit(); |
| 7662 | $offset = $limit * ( $page - 1 ); |
| 7663 | |
| 7664 | $args = [ |
| 7665 | 'post_type' => 'wc_membership_plan', |
| 7666 | 'posts_per_page' => $limit, |
| 7667 | 'offset' => $offset, |
| 7668 | 'orderby' => 'title', |
| 7669 | 'order' => 'ASC', |
| 7670 | 'post_status' => 'publish', |
| 7671 | 'fields' => 'ids', |
| 7672 | ]; |
| 7673 | $loop = new WP_Query( $args ); |
| 7674 | |
| 7675 | $plans = (array) $loop->posts; |
| 7676 | $plans_count = count( $plans ); |
| 7677 | |
| 7678 | $options = []; |
| 7679 | if ( ! empty( $plans ) ) { |
| 7680 | if ( is_array( $plans ) ) { |
| 7681 | foreach ( $plans as $plan_id ) { |
| 7682 | $options[] = [ |
| 7683 | 'label' => get_the_title( $plan_id ), |
| 7684 | 'value' => $plan_id, |
| 7685 | ]; |
| 7686 | } |
| 7687 | } |
| 7688 | } |
| 7689 | |
| 7690 | return [ |
| 7691 | 'options' => $options, |
| 7692 | 'hasMore' => $plans_count > $limit && $plans_count > $offset, |
| 7693 | ]; |
| 7694 | } |
| 7695 | |
| 7696 | /** |
| 7697 | * Get BuddyPress Private group. |
| 7698 | * |
| 7699 | * @param array $data data. |
| 7700 | * |
| 7701 | * @return array|void |
| 7702 | */ |
| 7703 | public function search_bp_private_group_list( $data ) { |
| 7704 | global $wpdb; |
| 7705 | |
| 7706 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups WHERE status = 'private'" ); |
| 7707 | |
| 7708 | $options = []; |
| 7709 | if ( $groups ) { |
| 7710 | foreach ( $groups as $group ) { |
| 7711 | $options[] = [ |
| 7712 | 'label' => $group->name, |
| 7713 | 'value' => $group->id, |
| 7714 | ]; |
| 7715 | } |
| 7716 | } |
| 7717 | |
| 7718 | return [ |
| 7719 | 'options' => $options, |
| 7720 | 'hasMore' => false, |
| 7721 | ]; |
| 7722 | } |
| 7723 | |
| 7724 | /** |
| 7725 | * Get BuddyPress Public group. |
| 7726 | * |
| 7727 | * @param array $data data. |
| 7728 | * |
| 7729 | * @return array|void |
| 7730 | */ |
| 7731 | public function search_bp_public_group_list( $data ) { |
| 7732 | global $wpdb; |
| 7733 | |
| 7734 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups WHERE status = 'public'" ); |
| 7735 | |
| 7736 | $options = []; |
| 7737 | if ( $groups ) { |
| 7738 | foreach ( $groups as $group ) { |
| 7739 | $options[] = [ |
| 7740 | 'label' => $group->name, |
| 7741 | 'value' => $group->id, |
| 7742 | ]; |
| 7743 | } |
| 7744 | } |
| 7745 | |
| 7746 | return [ |
| 7747 | 'options' => $options, |
| 7748 | 'hasMore' => false, |
| 7749 | ]; |
| 7750 | } |
| 7751 | |
| 7752 | /** |
| 7753 | * Get BuddyPress group. |
| 7754 | * |
| 7755 | * @param array $data data. |
| 7756 | * |
| 7757 | * @return array|void |
| 7758 | */ |
| 7759 | public function search_bp_group_list( $data ) { |
| 7760 | global $wpdb; |
| 7761 | |
| 7762 | $groups = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}bp_groups" ); |
| 7763 | |
| 7764 | $options = []; |
| 7765 | if ( $groups ) { |
| 7766 | foreach ( $groups as $group ) { |
| 7767 | $options[] = [ |
| 7768 | 'label' => $group->name, |
| 7769 | 'value' => $group->id, |
| 7770 | ]; |
| 7771 | } |
| 7772 | } |
| 7773 | |
| 7774 | return [ |
| 7775 | 'options' => $options, |
| 7776 | 'hasMore' => false, |
| 7777 | ]; |
| 7778 | } |
| 7779 | |
| 7780 | /** |
| 7781 | * Get BuddyPress field. |
| 7782 | * |
| 7783 | * @param array $data data. |
| 7784 | * |
| 7785 | * @return array|void |
| 7786 | */ |
| 7787 | public function search_bp_field_list( $data ) { |
| 7788 | global $wpdb; |
| 7789 | |
| 7790 | $base_group_id = 1; |
| 7791 | if ( function_exists( 'bp_xprofile_base_group_id' ) ) { |
| 7792 | $base_group_id = bp_xprofile_base_group_id(); |
| 7793 | } |
| 7794 | |
| 7795 | $xprofile_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}bp_xprofile_fields WHERE parent_id = 0 AND group_id = %d ORDER BY field_order ASC", $base_group_id ) ); |
| 7796 | |
| 7797 | $options = []; |
| 7798 | if ( ! empty( $xprofile_fields ) ) { |
| 7799 | foreach ( $xprofile_fields as $xprofile_field ) { |
| 7800 | $options[] = [ |
| 7801 | 'label' => $xprofile_field->name, |
| 7802 | 'value' => $xprofile_field->id, |
| 7803 | ]; |
| 7804 | } |
| 7805 | } |
| 7806 | |
| 7807 | return [ |
| 7808 | 'options' => $options, |
| 7809 | 'hasMore' => false, |
| 7810 | ]; |
| 7811 | } |
| 7812 | |
| 7813 | /** |
| 7814 | * Get BuddyPress member type. |
| 7815 | * |
| 7816 | * @param array $data data. |
| 7817 | * |
| 7818 | * @return array|void |
| 7819 | */ |
| 7820 | public function search_bp_member_type_list( $data ) { |
| 7821 | $options = []; |
| 7822 | if ( function_exists( 'bp_get_member_types' ) ) { |
| 7823 | $types = bp_get_member_types( [] ); |
| 7824 | if ( $types ) { |
| 7825 | foreach ( $types as $key => $type ) { |
| 7826 | $options[] = [ |
| 7827 | 'label' => $type, |
| 7828 | 'value' => $key, |
| 7829 | ]; |
| 7830 | } |
| 7831 | } |
| 7832 | } |
| 7833 | |
| 7834 | return [ |
| 7835 | 'options' => $options, |
| 7836 | 'hasMore' => false, |
| 7837 | ]; |
| 7838 | } |
| 7839 | |
| 7840 | /** |
| 7841 | * Get last data for WP All Import. |
| 7842 | * |
| 7843 | * @param array $data data. |
| 7844 | * @return mixed |
| 7845 | */ |
| 7846 | public function search_wp_all_import_last_data( $data ) { |
| 7847 | global $wpdb; |
| 7848 | $post_type = $data['filter']['post_type']['value']; |
| 7849 | $trigger = $data['search_term']; |
| 7850 | |
| 7851 | if ( 'wp_all_import_post_type_imported' === $trigger ) { |
| 7852 | if ( -1 == $post_type ) { |
| 7853 | $imports = $wpdb->get_row( "SELECT post_id FROM {$wpdb->prefix}pmxi_posts ORDER BY id DESC LIMIT 1", ARRAY_A ); |
| 7854 | $posts[0] = $imports['post_id']; |
| 7855 | } else { |
| 7856 | $imports = $wpdb->get_results( "SELECT post_id FROM {$wpdb->prefix}pmxi_posts", ARRAY_A ); |
| 7857 | $imports = array_column( $imports, 'post_id' ); |
| 7858 | $args = [ |
| 7859 | 'posts_per_page' => 1, |
| 7860 | 'post_type' => $post_type, |
| 7861 | 'post__in' => $imports, |
| 7862 | ]; |
| 7863 | $posts = get_posts( $args ); |
| 7864 | } |
| 7865 | } elseif ( 'wp_all_import_completed' === $trigger ) { |
| 7866 | $imports = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}pmxi_imports WHERE failed = 0 ORDER BY id DESC LIMIT 1", ARRAY_A ); |
| 7867 | } elseif ( 'wp_all_import_failed' === $trigger ) { |
| 7868 | $imports = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}pmxi_imports WHERE failed = 1 ORDER BY id DESC LIMIT 1", ARRAY_A ); |
| 7869 | } |
| 7870 | |
| 7871 | if ( 'wp_all_import_post_type_imported' === $trigger && empty( $imports ) ) { |
| 7872 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"ID": 1,"post_author": "1","post_date": "2023-07-12 06:31:35","post_date_gmt": "2023-07-12 06:31:35","post_content": "","post_title": "Test","post_excerpt": "","post_status": "publish","comment_status": "open","ping_status": "open","post_password": "","post_name": "test","to_ping": "","pinged": "","post_modified": "2023-07-12 06:31:35","post_modified_gmt": "2023-07-12 06:31:35","post_content_filtered": "","post_parent": 0,"guid": "https:\/\/example.com\/test\/","menu_order": 0,"post_type": "post","post_mime_type": "","comment_count": "0","filter": "raw"}}', true ); |
| 7873 | return $context; |
| 7874 | } elseif ( empty( $imports ) ) { |
| 7875 | $context = json_decode( '{"response_type":"sample","pluggable_data":{"id": "1","parent_import_id": "0","name": "demowpinstawpxyz.WordPress.2023_07_12.xml","friendly_name": "","type": "upload","feed_type": "","path": "\/wpallimport\/uploads\/ee8816eebf7a373454cdd1189c831241\/demowpinstawpxyz.WordPress.2023_07_12.xml","xpath": "\/rss","registered_on": "2023-07-12 05:10:29","root_element": "rss","processing": "0","executing": "0","triggered": "0","queue_chunk_number": "0","first_import": "2023-07-12 05:09:41","count": "1","imported": "0","created": "0","updated": "0","skipped": "1","deleted": "0","changed_missing": "0","canceled": "0","canceled_on": "0000-00-00 00:00:00","failed": "0","failed_on": "0000-00-00 00:00:00","settings_update_on": "0000-00-00 00:00:00","last_activity": "2023-07-12 05:10:24","iteration": "1"}}', true ); |
| 7876 | return $context; |
| 7877 | } |
| 7878 | |
| 7879 | $context['response_type'] = 'live'; |
| 7880 | if ( ! empty( $posts ) ) { |
| 7881 | $context['pluggable_data'] = WordPress::get_post_context( $posts[0] ); |
| 7882 | } else { |
| 7883 | $context['pluggable_data'] = $imports; |
| 7884 | } |
| 7885 | |
| 7886 | return $context; |
| 7887 | } |
| 7888 | |
| 7889 | /** |
| 7890 | * Get Wp Simple Pay Forms. |
| 7891 | * |
| 7892 | * @param array $data data. |
| 7893 | * |
| 7894 | * @return array |
| 7895 | */ |
| 7896 | public function search_wp_simple_pay_forms( $data ) { |
| 7897 | |
| 7898 | $page = $data['page']; |
| 7899 | $limit = Utilities::get_search_page_limit(); |
| 7900 | $offset = $limit * ( $page - 1 ); |
| 7901 | |
| 7902 | $forms = get_posts( |
| 7903 | [ |
| 7904 | 'post_type' => 'simple-pay', |
| 7905 | 'posts_per_page' => $limit, |
| 7906 | 'offset' => $offset, |
| 7907 | 'fields' => 'ids', |
| 7908 | ] |
| 7909 | ); |
| 7910 | |
| 7911 | $forms_count = count( $forms ); |
| 7912 | |
| 7913 | $options = []; |
| 7914 | |
| 7915 | if ( ! empty( $forms ) ) { |
| 7916 | foreach ( $forms as $form_id ) { |
| 7917 | if ( function_exists( 'simpay_get_form' ) ) { |
| 7918 | $form = simpay_get_form( $form_id ); |
| 7919 | $options[] = [ |
| 7920 | 'label' => null !== get_the_title( $form_id ) ? $form->company_name : get_the_title( $form_id ), |
| 7921 | 'value' => $form_id, |
| 7922 | ]; |
| 7923 | } |
| 7924 | } |
| 7925 | } |
| 7926 | |
| 7927 | return [ |
| 7928 | 'options' => $options, |
| 7929 | 'hasMore' => $forms_count > $limit && $forms_count > $offset, |
| 7930 | ]; |
| 7931 | } |
| 7932 | |
| 7933 | |
| 7934 | } |
| 7935 | |
| 7936 | GlobalSearchController::get_instance(); |
| 7937 |