| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | trait EPL_Elementor_Dynamic_Widget { |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | protected function is_dynamic_content(): bool { |
| 25: | return true; |
| 26: | } |
| 27: | } |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | class EPL_Elementor { |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | private static $instance = null; |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | const MINIMUM_ELEMENTOR_VERSION = '3.5.0'; |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | private $widgets_path; |
| 64: | |
| 65: | |
| 66: | private $loop_grid_queries = array(); |
| 67: | |
| 68: | |
| 69: | private $active_loop_grid_settings = array(); |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | public function __construct() { |
| 77: | $this->widgets_path = EPL_PATH_LIB . 'page-builders/elementor/widgets/'; |
| 78: | require_once EPL_PATH_LIB . 'page-builders/elementor/class-epl-elementor-agent-document.php'; |
| 79: | require_once EPL_PATH_LIB . 'page-builders/elementor/class-epl-elementor-listing-document.php'; |
| 80: | require_once EPL_PATH_LIB . 'page-builders/elementor/class-epl-elementor-single-document.php'; |
| 81: | require_once EPL_PATH_LIB . 'page-builders/elementor/class-epl-elementor-loop-card-document.php'; |
| 82: | require_once EPL_PATH_LIB . 'page-builders/elementor/class-epl-elementor-template-router.php'; |
| 83: | require_once EPL_PATH_LIB . 'page-builders/elementor/class-epl-elementor-template-seeder.php'; |
| 84: | |
| 85: | |
| 86: | if ( ! $this->is_compatible() ) { |
| 87: | add_action( 'admin_notices', array( $this, 'admin_notice_minimum_elementor_version' ) ); |
| 88: | return; |
| 89: | } |
| 90: | |
| 91: | |
| 92: | add_action( 'elementor/elements/categories_registered', array( $this, 'register_widget_categories' ) ); |
| 93: | |
| 94: | |
| 95: | |
| 96: | |
| 97: | add_action( 'elementor/widgets/register', array( $this, 'register_widgets' ), 100 ); |
| 98: | add_action( 'elementor/documents/register', array( $this, 'register_documents' ) ); |
| 99: | |
| 100: | |
| 101: | add_action( 'elementor/frontend/after_enqueue_styles', array( $this, 'frontend_styles' ) ); |
| 102: | add_action( 'elementor/editor/after_enqueue_scripts', array( $this, 'editor_scripts' ) ); |
| 103: | |
| 104: | |
| 105: | add_action( 'elementor/query/epl_listings', array( $this, 'elementor_listings_query' ), 10, 2 ); |
| 106: | add_action( 'elementor/query/epl_staff', array( $this, 'elementor_staff_query' ), 10, 2 ); |
| 107: | add_filter( 'elementor/query/query_args', array( $this, 'elementor_loop_query_args' ), 20, 2 ); |
| 108: | add_filter( 'elementor/query/get_query_args/current_query', array( $this, 'elementor_current_query_args' ), 20 ); |
| 109: | add_action( 'elementor/frontend/widget/before_render', array( $this, 'begin_loop_grid_render' ) ); |
| 110: | add_action( 'elementor/frontend/widget/after_render', array( $this, 'end_loop_grid_render' ) ); |
| 111: | add_action( 'elementor/query/query_results', array( $this, 'capture_loop_grid_query' ), 20, 2 ); |
| 112: | add_action( 'elementor/element/loop-grid/section_pagination/before_section_end', array( $this, 'register_loop_grid_pagination_provider' ) ); |
| 113: | add_filter( 'elementor/widget/render_content', array( $this, 'render_loop_grid_epl_pagination' ), 20, 2 ); |
| 114: | add_filter( 'pre_handle_404', array( $this, 'allow_epl_loop_grid_page' ), 20, 2 ); |
| 115: | add_filter( 'elementor/theme/need_override_location', array( $this, 'override_staff_directory_location' ), 20, 3 ); |
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | add_action( 'added_post_meta', array( $this, 'track_archive_conditions' ), 10, 4 ); |
| 121: | add_action( 'updated_post_meta', array( $this, 'track_archive_conditions' ), 10, 4 ); |
| 122: | add_action( 'deleted_post_meta', array( $this, 'track_archive_conditions' ), 10, 4 ); |
| 123: | |
| 124: | |
| 125: | |
| 126: | new EPL_Elementor_Template_Router(); |
| 127: | |
| 128: | |
| 129: | new EPL_Elementor_Template_Seeder(); |
| 130: | } |
| 131: | |
| 132: | |
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: | public function register_documents( $documents_manager ) { |
| 139: | $documents_manager->register_document_type( EPL_Elementor_Agent_Document::TYPE, EPL_Elementor_Agent_Document::get_class_full_name() ); |
| 140: | $documents_manager->register_document_type( EPL_Elementor_Single_Document::TYPE, EPL_Elementor_Single_Document::get_class_full_name() ); |
| 141: | $documents_manager->register_document_type( EPL_Elementor_Loop_Card_Document::TYPE, EPL_Elementor_Loop_Card_Document::get_class_full_name() ); |
| 142: | } |
| 143: | |
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: | |
| 149: | |
| 150: | public static function instance() { |
| 151: | if ( is_null( self::$instance ) ) { |
| 152: | self::$instance = new self(); |
| 153: | } |
| 154: | return self::$instance; |
| 155: | } |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | private function is_compatible() { |
| 164: | if ( ! defined( 'ELEMENTOR_VERSION' ) ) { |
| 165: | return false; |
| 166: | } |
| 167: | return version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ); |
| 168: | } |
| 169: | |
| 170: | |
| 171: | |
| 172: | |
| 173: | |
| 174: | |
| 175: | public function admin_notice_minimum_elementor_version() { |
| 176: | ?> |
| 177: | <div class="notice notice-warning is-dismissible"> |
| 178: | <p> |
| 179: | <?php |
| 180: | echo wp_kses( |
| 181: | sprintf( |
| 182: | |
| 183: | esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'easy-property-listings' ), |
| 184: | '<strong>' . esc_html__( 'Easy Property Listings - Elementor', 'easy-property-listings' ) . '</strong>', |
| 185: | '<strong>Elementor</strong>', |
| 186: | esc_html( self::MINIMUM_ELEMENTOR_VERSION ) |
| 187: | ), |
| 188: | array( 'strong' => array() ) |
| 189: | ); |
| 190: | ?> |
| 191: | </p> |
| 192: | </div> |
| 193: | <?php |
| 194: | } |
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: | |
| 201: | |
| 202: | public function register_widget_categories( $elements_manager ) { |
| 203: | $elements_manager->add_category( |
| 204: | 'epl-elements', |
| 205: | array( |
| 206: | 'title' => esc_html__( 'EPL Elements (Beta)', 'easy-property-listings' ), |
| 207: | 'icon' => 'eicon-apps', |
| 208: | ) |
| 209: | ); |
| 210: | |
| 211: | $elements_manager->add_category( |
| 212: | 'epl-archive', |
| 213: | array( |
| 214: | 'title' => esc_html__( 'EPL Archive (Beta)', 'easy-property-listings' ), |
| 215: | 'icon' => 'eicon-archive', |
| 216: | ) |
| 217: | ); |
| 218: | |
| 219: | $elements_manager->add_category( |
| 220: | 'epl-author', |
| 221: | array( |
| 222: | 'title' => esc_html__( 'EPL Author (Beta)', 'easy-property-listings' ), |
| 223: | 'icon' => 'eicon-person', |
| 224: | ) |
| 225: | ); |
| 226: | |
| 227: | $elements_manager->add_category( |
| 228: | 'epl-staff', |
| 229: | array( |
| 230: | 'title' => esc_html__( 'EPL Staff Directory (Beta)', 'easy-property-listings' ), |
| 231: | 'icon' => 'eicon-person', |
| 232: | ) |
| 233: | ); |
| 234: | } |
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: | |
| 241: | |
| 242: | public function register_widgets( $widgets_manager ) { |
| 243: | $this->include_widget_files(); |
| 244: | |
| 245: | |
| 246: | $element_widgets = array( |
| 247: | 'EPL_Elementor_Property_Title', |
| 248: | 'EPL_Elementor_Property_Heading', |
| 249: | 'EPL_Elementor_Property_Price', |
| 250: | 'EPL_Elementor_Property_Address', |
| 251: | 'EPL_Elementor_Property_Icons', |
| 252: | 'EPL_Elementor_Property_Image', |
| 253: | 'EPL_Elementor_Property_Content', |
| 254: | 'EPL_Elementor_Property_Excerpt', |
| 255: | 'EPL_Elementor_Property_Features', |
| 256: | 'EPL_Elementor_Property_Inspection', |
| 257: | 'EPL_Elementor_Agent_Box', |
| 258: | 'EPL_Elementor_Listing_Agents', |
| 259: | 'EPL_Elementor_Agent_Photo', |
| 260: | 'EPL_Elementor_Agent_Name', |
| 261: | 'EPL_Elementor_Agent_Position', |
| 262: | 'EPL_Elementor_Agent_Contact', |
| 263: | 'EPL_Elementor_Agent_Social', |
| 264: | 'EPL_Elementor_Agent_Bio', |
| 265: | 'EPL_Elementor_Staff_Listings', |
| 266: | 'EPL_Elementor_Property_Map', |
| 267: | 'EPL_Elementor_Property_Gallery', |
| 268: | 'EPL_Elementor_Property_Video', |
| 269: | 'EPL_Elementor_Property_Buttons', |
| 270: | 'EPL_Elementor_Property_Status', |
| 271: | 'EPL_Elementor_Property_Meta', |
| 272: | 'EPL_Elementor_Property_Taxonomy', |
| 273: | 'EPL_Elementor_Single_Extensions', |
| 274: | ); |
| 275: | |
| 276: | foreach ( $element_widgets as $widget_class ) { |
| 277: | if ( class_exists( $widget_class ) ) { |
| 278: | $widgets_manager->register( new $widget_class() ); |
| 279: | } |
| 280: | } |
| 281: | |
| 282: | |
| 283: | $archive_widgets = array( |
| 284: | 'EPL_Elementor_Listing_Advanced', |
| 285: | 'EPL_Elementor_Listing_Search', |
| 286: | 'EPL_Elementor_Listing_Results', |
| 287: | 'EPL_Elementor_Pagination', |
| 288: | ); |
| 289: | |
| 290: | |
| 291: | |
| 292: | if ( ! $this->has_elementor_loop_grid( $widgets_manager ) ) { |
| 293: | $archive_widgets[] = 'EPL_Elementor_Listings'; |
| 294: | } |
| 295: | |
| 296: | foreach ( $archive_widgets as $widget_class ) { |
| 297: | if ( class_exists( $widget_class ) ) { |
| 298: | $widgets_manager->register( new $widget_class() ); |
| 299: | } |
| 300: | } |
| 301: | } |
| 302: | |
| 303: | |
| 304: | |
| 305: | |
| 306: | |
| 307: | |
| 308: | private function include_widget_files() { |
| 309: | |
| 310: | $elements = array( |
| 311: | 'class-epl-elementor-property-title.php', |
| 312: | 'class-epl-elementor-property-heading.php', |
| 313: | 'class-epl-elementor-property-price.php', |
| 314: | 'class-epl-elementor-property-address.php', |
| 315: | 'class-epl-elementor-property-icons.php', |
| 316: | 'class-epl-elementor-property-image.php', |
| 317: | 'class-epl-elementor-property-content.php', |
| 318: | 'class-epl-elementor-property-excerpt.php', |
| 319: | 'class-epl-elementor-property-features.php', |
| 320: | 'class-epl-elementor-property-inspection.php', |
| 321: | 'class-epl-elementor-agent-box.php', |
| 322: | 'class-epl-elementor-agents-loop.php', |
| 323: | 'class-epl-elementor-agent-photo.php', |
| 324: | 'class-epl-elementor-agent-name.php', |
| 325: | 'class-epl-elementor-agent-position.php', |
| 326: | 'class-epl-elementor-agent-contact.php', |
| 327: | 'class-epl-elementor-agent-social.php', |
| 328: | 'class-epl-elementor-agent-bio.php', |
| 329: | 'class-epl-elementor-staff-listings.php', |
| 330: | 'class-epl-elementor-property-map.php', |
| 331: | 'class-epl-elementor-property-gallery.php', |
| 332: | 'class-epl-elementor-property-video.php', |
| 333: | 'class-epl-elementor-property-buttons.php', |
| 334: | 'class-epl-elementor-property-status.php', |
| 335: | 'class-epl-elementor-property-meta.php', |
| 336: | 'class-epl-elementor-property-taxonomy.php', |
| 337: | 'class-epl-elementor-single-extensions.php', |
| 338: | ); |
| 339: | |
| 340: | foreach ( $elements as $file ) { |
| 341: | $path = $this->widgets_path . 'elements/' . $file; |
| 342: | if ( file_exists( $path ) ) { |
| 343: | require_once $path; |
| 344: | } |
| 345: | } |
| 346: | |
| 347: | |
| 348: | $archives = array( |
| 349: | 'class-epl-elementor-listing-advanced.php', |
| 350: | 'class-epl-elementor-listings.php', |
| 351: | 'class-epl-elementor-listing-search.php', |
| 352: | 'class-epl-elementor-listing-results.php', |
| 353: | 'class-epl-elementor-pagination.php', |
| 354: | ); |
| 355: | |
| 356: | foreach ( $archives as $file ) { |
| 357: | $path = $this->widgets_path . 'archive/' . $file; |
| 358: | if ( file_exists( $path ) ) { |
| 359: | require_once $path; |
| 360: | } |
| 361: | } |
| 362: | } |
| 363: | |
| 364: | |
| 365: | |
| 366: | |
| 367: | |
| 368: | |
| 369: | |
| 370: | |
| 371: | |
| 372: | |
| 373: | |
| 374: | private function has_elementor_loop_grid( $widgets_manager ) { |
| 375: | $available = (bool) $widgets_manager->get_widget_types( 'loop-grid' ); |
| 376: | |
| 377: | return (bool) apply_filters( 'epl_elementor_has_loop_grid', $available, $widgets_manager ); |
| 378: | } |
| 379: | |
| 380: | |
| 381: | |
| 382: | |
| 383: | |
| 384: | |
| 385: | public function frontend_styles() { |
| 386: | wp_enqueue_style( |
| 387: | 'epl-elementor', |
| 388: | EPL_PLUGIN_URL . 'lib/assets/css/epl-elementor.css', |
| 389: | array(), |
| 390: | EPL_PROPERTY_VER |
| 391: | ); |
| 392: | |
| 393: | |
| 394: | |
| 395: | |
| 396: | |
| 397: | wp_register_script( 'epl-elementor-tabs', '', array(), EPL_PROPERTY_VER, true ); |
| 398: | wp_enqueue_script( 'epl-elementor-tabs' ); |
| 399: | wp_add_inline_script( |
| 400: | 'epl-elementor-tabs', |
| 401: | ' |
| 402: | document.addEventListener("click", function(e) { |
| 403: | var button = e.target.closest(".epl-agents-tabs .epl-tab-button"); |
| 404: | if (!button) { |
| 405: | return; |
| 406: | } |
| 407: | var container = button.closest(".epl-agents-tabs"); |
| 408: | var tabId = button.getAttribute("data-tab"); |
| 409: | |
| 410: | container.querySelectorAll(".epl-tab-button").forEach(function(btn) { |
| 411: | btn.classList.remove("active"); |
| 412: | }); |
| 413: | container.querySelectorAll(".epl-tab-content").forEach(function(content) { |
| 414: | content.classList.remove("active"); |
| 415: | }); |
| 416: | |
| 417: | button.classList.add("active"); |
| 418: | var content = container.querySelector("[id=\"" + tabId + "\"]") || document.getElementById(tabId); |
| 419: | if (content) { |
| 420: | content.classList.add("active"); |
| 421: | } |
| 422: | }); |
| 423: | ' |
| 424: | ); |
| 425: | |
| 426: | |
| 427: | |
| 428: | |
| 429: | |
| 430: | wp_add_inline_script( |
| 431: | 'epl-elementor-tabs', |
| 432: | ' |
| 433: | document.addEventListener("click", function(e) { |
| 434: | var toggle = e.target.closest(".epl-switch-view ul li[data-view]"); |
| 435: | if (!toggle) { |
| 436: | return; |
| 437: | } |
| 438: | var isList = "list" === toggle.getAttribute("data-view"); |
| 439: | document.querySelectorAll(".epl-elementor-advanced-grid.epl-ea-dual-view").forEach(function(grid) { |
| 440: | grid.classList.toggle("is-list-view", isList); |
| 441: | grid.classList.toggle("is-grid-view", !isList); |
| 442: | }); |
| 443: | }); |
| 444: | ' |
| 445: | ); |
| 446: | } |
| 447: | |
| 448: | |
| 449: | |
| 450: | |
| 451: | |
| 452: | |
| 453: | |
| 454: | |
| 455: | |
| 456: | |
| 457: | |
| 458: | |
| 459: | |
| 460: | |
| 461: | |
| 462: | |
| 463: | |
| 464: | |
| 465: | |
| 466: | |
| 467: | |
| 468: | |
| 469: | |
| 470: | |
| 471: | |
| 472: | |
| 473: | |
| 474: | public function editor_scripts() { |
| 475: | wp_register_script( 'epl-elementor-editor-fixes', '', array( 'elementor-editor' ), EPL_PROPERTY_VER, true ); |
| 476: | wp_enqueue_script( 'epl-elementor-editor-fixes' ); |
| 477: | wp_add_inline_script( |
| 478: | 'epl-elementor-editor-fixes', |
| 479: | ' |
| 480: | ( function () { |
| 481: | function isStuckHidden( el ) { |
| 482: | return el.style.display === "none" && ! el.classList.contains( "elementor-hidden-control" ); |
| 483: | } |
| 484: | |
| 485: | function sweep( root ) { |
| 486: | root.querySelectorAll( ".elementor-control" ).forEach( function ( el ) { |
| 487: | if ( isStuckHidden( el ) ) { |
| 488: | el.style.removeProperty( "display" ); |
| 489: | } |
| 490: | } ); |
| 491: | } |
| 492: | |
| 493: | function watch( panel ) { |
| 494: | sweep( panel ); |
| 495: | |
| 496: | new MutationObserver( function ( mutations ) { |
| 497: | mutations.forEach( function ( mutation ) { |
| 498: | if ( "attributes" === mutation.type ) { |
| 499: | if ( mutation.target.classList && mutation.target.classList.contains( "elementor-control" ) && isStuckHidden( mutation.target ) ) { |
| 500: | mutation.target.style.removeProperty( "display" ); |
| 501: | } |
| 502: | return; |
| 503: | } |
| 504: | |
| 505: | mutation.addedNodes.forEach( function ( node ) { |
| 506: | if ( 1 === node.nodeType ) { |
| 507: | sweep( node ); |
| 508: | } |
| 509: | } ); |
| 510: | } ); |
| 511: | } ).observe( panel, { |
| 512: | childList: true, |
| 513: | subtree: true, |
| 514: | attributes: true, |
| 515: | attributeFilter: [ "style", "class" ], |
| 516: | } ); |
| 517: | } |
| 518: | |
| 519: | elementor.on( "panel:init", function () { |
| 520: | var panel = document.getElementById( "elementor-panel" ); |
| 521: | if ( panel ) { |
| 522: | watch( panel ); |
| 523: | } |
| 524: | } ); |
| 525: | } )(); |
| 526: | |
| 527: | // An EPL Listing Card document is a single card, meant to sit |
| 528: | // narrow inside a grid — left alone it renders full page width in |
| 529: | // the editor, which makes it hard to judge how it will actually |
| 530: | // look. When editing this document type, narrow the preview |
| 531: | // canvas to the "Editing Preview Width" document setting |
| 532: | // (default 320px) and frame it like an isolated card on a grey |
| 533: | // backdrop. Purely an editor affordance — never touches front-end |
| 534: | // output, and every other document type renders full width as |
| 535: | // before. |
| 536: | ( function () { |
| 537: | function applyPreviewWidth() { |
| 538: | var config = elementor.config && elementor.config.document; |
| 539: | if ( ! config || "epl-loop-card" !== config.type ) { |
| 540: | return; |
| 541: | } |
| 542: | |
| 543: | var iframe = document.getElementById( "elementor-preview-iframe" ); |
| 544: | var doc = iframe && iframe.contentDocument; |
| 545: | if ( ! doc || ! doc.head ) { |
| 546: | return; |
| 547: | } |
| 548: | |
| 549: | var width = 320; |
| 550: | if ( elementor.settings && elementor.settings.page && elementor.settings.page.model ) { |
| 551: | var configured = parseInt( elementor.settings.page.model.get( "epl_card_preview_width" ), 10 ); |
| 552: | if ( configured ) { |
| 553: | width = configured; |
| 554: | } |
| 555: | } |
| 556: | |
| 557: | var style = doc.getElementById( "epl-card-preview-style" ); |
| 558: | if ( ! style ) { |
| 559: | style = doc.createElement( "style" ); |
| 560: | style.id = "epl-card-preview-style"; |
| 561: | doc.head.appendChild( style ); |
| 562: | } |
| 563: | |
| 564: | // The card document still renders through the active theme |
| 565: | // normal single-post wrapper (header, page title, footer) — |
| 566: | // there is no bare data-elementor-type directly under body |
| 567: | // to key off. Hide that surrounding chrome and narrow the |
| 568: | // actual Elementor wrapper wherever it sits in the tree |
| 569: | // instead. |
| 570: | style.textContent = ( |
| 571: | "body { background: #e4e4e4 !important; }" + |
| 572: | "#site-header, #site-footer, .page-header, .site-header, .site-footer { display: none !important; }" + |
| 573: | "[data-elementor-type] { max-width: " + width + "px !important; margin: 40px auto !important; float: none !important; " + |
| 574: | "background: #fff !important; box-shadow: 0 0 0 1px rgba(0,0,0,.08), 0 12px 28px rgba(0,0,0,.15) !important; }" |
| 575: | ); |
| 576: | } |
| 577: | |
| 578: | elementor.on( "preview:loaded", function () { |
| 579: | applyPreviewWidth(); |
| 580: | |
| 581: | if ( elementor.settings && elementor.settings.page && elementor.settings.page.model ) { |
| 582: | elementor.settings.page.model.on( "change:epl_card_preview_width", applyPreviewWidth ); |
| 583: | } |
| 584: | } ); |
| 585: | } )(); |
| 586: | ' |
| 587: | ); |
| 588: | } |
| 589: | |
| 590: | |
| 591: | |
| 592: | |
| 593: | |
| 594: | |
| 595: | |
| 596: | public static function get_post_types() { |
| 597: | $post_types = array(); |
| 598: | $epl_posts = epl_get_core_post_types(); |
| 599: | |
| 600: | foreach ( $epl_posts as $post_type ) { |
| 601: | $obj = get_post_type_object( $post_type ); |
| 602: | if ( $obj ) { |
| 603: | $post_types[ $post_type ] = $obj->labels->singular_name; |
| 604: | } |
| 605: | } |
| 606: | |
| 607: | return $post_types; |
| 608: | } |
| 609: | |
| 610: | |
| 611: | |
| 612: | |
| 613: | |
| 614: | |
| 615: | |
| 616: | public static function get_status_options() { |
| 617: | return array( |
| 618: | '' => esc_html__( 'All', 'easy-property-listings' ), |
| 619: | 'current' => esc_html__( 'Current', 'easy-property-listings' ), |
| 620: | 'sold' => esc_html__( 'Sold', 'easy-property-listings' ), |
| 621: | 'leased' => esc_html__( 'Leased', 'easy-property-listings' ), |
| 622: | 'withdrawn' => esc_html__( 'Withdrawn', 'easy-property-listings' ), |
| 623: | 'offmarket' => esc_html__( 'Off Market', 'easy-property-listings' ), |
| 624: | ); |
| 625: | } |
| 626: | |
| 627: | |
| 628: | |
| 629: | |
| 630: | |
| 631: | |
| 632: | |
| 633: | private static $context_stack = array(); |
| 634: | |
| 635: | |
| 636: | |
| 637: | |
| 638: | |
| 639: | |
| 640: | |
| 641: | |
| 642: | |
| 643: | |
| 644: | |
| 645: | |
| 646: | |
| 647: | |
| 648: | public static function setup_listing_context() { |
| 649: | global $property, $post, $epl_author, $epl_author_secondary, $epl_author_third, $epl_author_fourth; |
| 650: | |
| 651: | $frame = array( |
| 652: | 'post' => isset( $post ) ? $post : null, |
| 653: | 'property' => isset( $property ) ? $property : null, |
| 654: | 'epl_author' => isset( $epl_author ) ? $epl_author : null, |
| 655: | 'epl_author_secondary' => isset( $epl_author_secondary ) ? $epl_author_secondary : null, |
| 656: | 'epl_author_third' => isset( $epl_author_third ) ? $epl_author_third : null, |
| 657: | 'epl_author_fourth' => isset( $epl_author_fourth ) ? $epl_author_fourth : null, |
| 658: | ); |
| 659: | |
| 660: | |
| 661: | |
| 662: | if ( $post && is_epl_post( $post->post_type ) && ( ! $property || (int) $property->post->ID !== (int) $post->ID ) ) { |
| 663: | $property = new EPL_Property_Meta( $post ); |
| 664: | } |
| 665: | |
| 666: | |
| 667: | |
| 668: | |
| 669: | |
| 670: | if ( ( self::is_editor() || self::is_epl_elementor_document_context() ) && ( ! $post || ! is_epl_post( $post->post_type ) ) ) { |
| 671: | $preview = self::get_preview_property(); |
| 672: | |
| 673: | if ( $preview ) { |
| 674: | $property = $preview; |
| 675: | $post = $preview->post; |
| 676: | setup_postdata( $post ); |
| 677: | } |
| 678: | } |
| 679: | |
| 680: | self::$context_stack[] = $frame; |
| 681: | |
| 682: | return $property ? $property : false; |
| 683: | } |
| 684: | |
| 685: | |
| 686: | |
| 687: | |
| 688: | |
| 689: | |
| 690: | public static function restore_listing_context() { |
| 691: | global $property, $post, $epl_author, $epl_author_secondary, $epl_author_third, $epl_author_fourth; |
| 692: | |
| 693: | $frame = array_pop( self::$context_stack ); |
| 694: | |
| 695: | if ( null === $frame ) { |
| 696: | return; |
| 697: | } |
| 698: | |
| 699: | $post = $frame['post']; |
| 700: | $property = $frame['property']; |
| 701: | $epl_author = $frame['epl_author']; |
| 702: | $epl_author_secondary = $frame['epl_author_secondary']; |
| 703: | $epl_author_third = $frame['epl_author_third']; |
| 704: | $epl_author_fourth = $frame['epl_author_fourth']; |
| 705: | |
| 706: | if ( $post instanceof WP_Post ) { |
| 707: | setup_postdata( $post ); |
| 708: | } |
| 709: | } |
| 710: | |
| 711: | |
| 712: | |
| 713: | |
| 714: | |
| 715: | |
| 716: | |
| 717: | |
| 718: | public static function is_editor() { |
| 719: | $is_edit_mode = isset( \Elementor\Plugin::$instance->editor ) && \Elementor\Plugin::$instance->editor->is_edit_mode(); |
| 720: | $is_preview = isset( \Elementor\Plugin::$instance->preview ) && \Elementor\Plugin::$instance->preview->is_preview_mode(); |
| 721: | $is_preview_request = isset( $_GET['elementor-preview'] ); |
| 722: | $ajax_action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : ''; |
| 723: | $is_elementor_ajax = wp_doing_ajax() && 0 === strpos( $ajax_action, 'elementor' ); |
| 724: | |
| 725: | |
| 726: | if ( ( $is_preview_request || $is_elementor_ajax ) && ! current_user_can( 'edit_posts' ) ) { |
| 727: | $is_preview_request = false; |
| 728: | $is_elementor_ajax = false; |
| 729: | } |
| 730: | |
| 731: | return $is_edit_mode || $is_preview || $is_preview_request || $is_elementor_ajax; |
| 732: | } |
| 733: | |
| 734: | |
| 735: | |
| 736: | |
| 737: | |
| 738: | |
| 739: | |
| 740: | |
| 741: | |
| 742: | |
| 743: | |
| 744: | private static function is_epl_elementor_document_context() { |
| 745: | $document_ids = array(); |
| 746: | $current_post = get_post(); |
| 747: | |
| 748: | if ( $current_post && 'elementor_library' === $current_post->post_type ) { |
| 749: | $document_ids[] = (int) $current_post->ID; |
| 750: | } |
| 751: | |
| 752: | if ( isset( \Elementor\Plugin::$instance->documents ) ) { |
| 753: | $current_document = \Elementor\Plugin::$instance->documents->get_current(); |
| 754: | if ( $current_document ) { |
| 755: | $document_ids[] = (int) $current_document->get_main_id(); |
| 756: | } |
| 757: | } |
| 758: | |
| 759: | foreach ( array_unique( array_filter( $document_ids ) ) as $document_id ) { |
| 760: | $data = (string) get_post_meta( $document_id, '_elementor_data', true ); |
| 761: | if ( 'listing' === self::get_epl_template_context( $document_id ) ) { |
| 762: | return true; |
| 763: | } |
| 764: | |
| 765: | if ( preg_match_all( '/"template_id":(?:"?)(\d+)(?:"?)/', $data, $matches ) ) { |
| 766: | foreach ( $matches[1] as $template_id ) { |
| 767: | if ( 'listing' === self::get_epl_template_context( absint( $template_id ) ) ) { |
| 768: | return true; |
| 769: | } |
| 770: | } |
| 771: | } |
| 772: | } |
| 773: | |
| 774: | return false; |
| 775: | } |
| 776: | |
| 777: | |
| 778: | |
| 779: | |
| 780: | |
| 781: | |
| 782: | |
| 783: | |
| 784: | |
| 785: | public static function get_listing_agent( $property, $index = 0 ) { |
| 786: | if ( 0 === $index && isset( $property->post ) && 'directory' === $property->post->post_type ) { |
| 787: | return new EPL_Author_Loader( $property->post->ID ); |
| 788: | } |
| 789: | |
| 790: | $keys = array( 'property_agent', 'property_second_agent', 'property_third_agent', 'property_fourth_agent' ); |
| 791: | $key = isset( $keys[ $index ] ) ? $keys[ $index ] : $keys[0]; |
| 792: | $raw = $property->get_property_meta( $key ); |
| 793: | $id = 0; |
| 794: | |
| 795: | |
| 796: | if ( 'directory' === epl_get_option( 'epl_sd_staff_details_location', 'wp_user' ) && post_type_exists( 'directory' ) && ! empty( $raw ) ) { |
| 797: | $directory = self::get_directory_agent( $raw ); |
| 798: | $id = $directory instanceof WP_Post ? $directory->ID : 0; |
| 799: | } elseif ( ! empty( $raw ) ) { |
| 800: | $user = get_user_by( 'login', sanitize_user( (string) $raw ) ); |
| 801: | $id = $user ? $user->ID : ( is_numeric( $raw ) ? absint( $raw ) : 0 ); |
| 802: | } |
| 803: | |
| 804: | if ( 0 === $index && ! $id && isset( $property->post->post_author ) ) { |
| 805: | $id = absint( $property->post->post_author ); |
| 806: | } |
| 807: | |
| 808: | $id = absint( apply_filters( 'epl_elementor_agent_id', $id, $raw, $index, $property ) ); |
| 809: | return $id ? new EPL_Author_Loader( $id ) : null; |
| 810: | } |
| 811: | |
| 812: | |
| 813: | |
| 814: | |
| 815: | |
| 816: | |
| 817: | |
| 818: | |
| 819: | |
| 820: | |
| 821: | |
| 822: | |
| 823: | private static function get_directory_agent( $username ) { |
| 824: | $posts = get_posts( |
| 825: | array( |
| 826: | 'post_type' => 'directory', |
| 827: | 'post_status' => 'publish', |
| 828: | 'posts_per_page' => -1, |
| 829: | 'orderby' => 'ID', |
| 830: | 'order' => 'ASC', |
| 831: | 'meta_key' => 'property_staff_username', |
| 832: | 'meta_value' => sanitize_user( (string) $username ), |
| 833: | ) |
| 834: | ); |
| 835: | |
| 836: | if ( empty( $posts ) ) { |
| 837: | return null; |
| 838: | } |
| 839: | |
| 840: | foreach ( $posts as $directory ) { |
| 841: | if ( has_post_thumbnail( $directory ) ) { |
| 842: | return apply_filters( 'epl_elementor_directory_agent', $directory, $posts, $username ); |
| 843: | } |
| 844: | } |
| 845: | |
| 846: | return apply_filters( 'epl_elementor_directory_agent', reset( $posts ), $posts, $username ); |
| 847: | } |
| 848: | |
| 849: | |
| 850: | |
| 851: | |
| 852: | |
| 853: | |
| 854: | |
| 855: | |
| 856: | public static function get_listing_agents( $property ) { |
| 857: | $agents = array(); |
| 858: | $seen = array(); |
| 859: | |
| 860: | for ( $index = 0; $index < 4; $index++ ) { |
| 861: | $agent = self::get_listing_agent( $property, $index ); |
| 862: | if ( $agent && ! isset( $seen[ (string) $agent->author_id ] ) ) { |
| 863: | $seen[ (string) $agent->author_id ] = true; |
| 864: | $agents[] = $agent; |
| 865: | } |
| 866: | } |
| 867: | |
| 868: | return apply_filters( 'epl_elementor_listing_agents', $agents, $property ); |
| 869: | } |
| 870: | |
| 871: | |
| 872: | |
| 873: | |
| 874: | |
| 875: | |
| 876: | |
| 877: | |
| 878: | |
| 879: | |
| 880: | |
| 881: | |
| 882: | |
| 883: | |
| 884: | public static function get_agent_image( $agent, $size = 150 ) { |
| 885: | $size = max( 1, absint( $size ) ); |
| 886: | $image_html = get_avatar( $agent->email, $size ); |
| 887: | $directory = ! empty( $agent->directory ) && $agent->directory instanceof WP_Post ? $agent->directory : null; |
| 888: | |
| 889: | if ( $directory && 'directory' === $directory->post_type && 1 === (int) epl_get_option( 'epl_sd_staff_image_type', 0 ) ) { |
| 890: | $image_size = apply_filters( 'epl_sd_author_tab_image_size', epl_get_option( 'epl_sd_staff_image_size_box', 'thumbnail' ) ); |
| 891: | if ( has_post_thumbnail( $directory ) ) { |
| 892: | $image_html = wp_get_attachment_image( get_post_thumbnail_id( $directory ), $image_size ); |
| 893: | } elseif ( function_exists( 'epl_sd_has_fallback_featured_image' ) && epl_sd_has_fallback_featured_image() && function_exists( 'epl_sd_get_the_fallback_featured_image' ) ) { |
| 894: | $image_html = epl_sd_get_the_fallback_featured_image( $image_size, array( 'class' => 'epl-sd-fallback-image' ) ); |
| 895: | } |
| 896: | } |
| 897: | |
| 898: | $image_html = apply_filters( 'epl_author_tab_image', $image_html, $agent ); |
| 899: | return apply_filters( 'epl_elementor_agent_image', $image_html, $agent, $size ); |
| 900: | } |
| 901: | |
| 902: | |
| 903: | |
| 904: | |
| 905: | |
| 906: | |
| 907: | |
| 908: | |
| 909: | |
| 910: | public function elementor_listings_query( $query, $widget ) { |
| 911: | $post_type = $query->get( 'post_type' ); |
| 912: | if ( empty( $post_type ) || 'post' === $post_type ) { |
| 913: | $query->set( 'post_type', epl_get_core_post_types() ); |
| 914: | } |
| 915: | $query->set( 'epl_elementor_loop', true ); |
| 916: | do_action( 'epl_elementor_loop_query', $query, $widget ); |
| 917: | } |
| 918: | |
| 919: | |
| 920: | |
| 921: | |
| 922: | |
| 923: | |
| 924: | |
| 925: | |
| 926: | public function elementor_staff_query( $query, $widget ) { |
| 927: | $query->set( 'post_type', 'directory' ); |
| 928: | $query->set( 'epl_elementor_context', 'staff' ); |
| 929: | do_action( 'epl_elementor_staff_query', $query, $widget ); |
| 930: | } |
| 931: | |
| 932: | |
| 933: | |
| 934: | |
| 935: | |
| 936: | |
| 937: | |
| 938: | |
| 939: | |
| 940: | |
| 941: | |
| 942: | |
| 943: | |
| 944: | |
| 945: | |
| 946: | public function override_staff_directory_location( $override, $location, $locations_manager ) { |
| 947: | if ( 'single' === $location && is_singular( 'directory' ) ) { |
| 948: | return true; |
| 949: | } |
| 950: | if ( 'archive' === $location && ( is_post_type_archive( 'directory' ) || is_tax( 'department' ) ) ) { |
| 951: | return true; |
| 952: | } |
| 953: | return $override; |
| 954: | } |
| 955: | |
| 956: | |
| 957: | |
| 958: | |
| 959: | |
| 960: | |
| 961: | |
| 962: | |
| 963: | |
| 964: | |
| 965: | |
| 966: | public function elementor_loop_query_args( $query_args, $widget ) { |
| 967: | if ( ! $widget || 'loop-grid' !== $widget->get_name() ) { |
| 968: | return $query_args; |
| 969: | } |
| 970: | |
| 971: | $template_id = absint( $widget->get_settings( 'template_id' ) ); |
| 972: | $context = $template_id ? self::get_epl_template_context( $template_id ) : ''; |
| 973: | if ( ! $context ) { |
| 974: | return $query_args; |
| 975: | } |
| 976: | |
| 977: | $source = (string) $widget->get_settings( 'post_query_post_type' ); |
| 978: | $is_editor = self::is_editor(); |
| 979: | |
| 980: | |
| 981: | |
| 982: | |
| 983: | |
| 984: | if ( $is_editor && 'current_query' === $source ) { |
| 985: | $query_args = array( |
| 986: | 'post_type' => 'staff' === $context ? array( 'directory' ) : self::get_archive_preview_post_types(), |
| 987: | 'post_status' => 'publish', |
| 988: | 'posts_per_page' => max( 1, absint( $widget->get_settings( 'posts_per_page' ) ) ), |
| 989: | 'paged' => 1, |
| 990: | 'orderby' => 'date', |
| 991: | 'order' => 'DESC', |
| 992: | 'ignore_sticky_posts' => true, |
| 993: | ); |
| 994: | } |
| 995: | |
| 996: | $post_type = isset( $query_args['post_type'] ) ? $query_args['post_type'] : ''; |
| 997: | if ( empty( $post_type ) || 'post' === $post_type ) { |
| 998: | $query_args['post_type'] = 'staff' === $context ? array( 'directory' ) : self::get_archive_preview_post_types(); |
| 999: | } |
| 1000: | |
| 1001: | $query_args['epl_elementor_loop'] = true; |
| 1002: | $query_args['epl_elementor_context'] = $context; |
| 1003: | return apply_filters( 'epl_elementor_loop_query_args', $query_args, $widget, $template_id ); |
| 1004: | } |
| 1005: | |
| 1006: | |
| 1007: | |
| 1008: | |
| 1009: | |
| 1010: | |
| 1011: | |
| 1012: | |
| 1013: | |
| 1014: | |
| 1015: | |
| 1016: | |
| 1017: | public function elementor_current_query_args( $query_args ) { |
| 1018: | |
| 1019: | |
| 1020: | |
| 1021: | $loop_settings = $this->active_loop_grid_settings; |
| 1022: | if ( empty( $loop_settings ) ) { |
| 1023: | $loop_settings = self::get_current_epl_loop_grid_settings(); |
| 1024: | } |
| 1025: | if ( empty( $loop_settings ) ) { |
| 1026: | return $query_args; |
| 1027: | } |
| 1028: | |
| 1029: | $posts_per_page = isset( $loop_settings['posts_per_page'] ) ? absint( $loop_settings['posts_per_page'] ) : 3; |
| 1030: | $posts_per_page = max( 1, $posts_per_page ); |
| 1031: | |
| 1032: | |
| 1033: | |
| 1034: | |
| 1035: | |
| 1036: | |
| 1037: | if ( ! self::is_editor() ) { |
| 1038: | $query_args['posts_per_page'] = $posts_per_page; |
| 1039: | $query_args['epl_elementor_loop'] = true; |
| 1040: | if ( ! empty( $loop_settings['_epl_widget_id'] ) ) { |
| 1041: | $query_args['instance_id'] = 'elementor-' . sanitize_key( $loop_settings['_epl_widget_id'] ); |
| 1042: | $query_args['is_epl_shortcode'] = true; |
| 1043: | $query_args['epl_shortcode_name'] = 'listing_advanced'; |
| 1044: | } |
| 1045: | return $query_args; |
| 1046: | } |
| 1047: | |
| 1048: | return array( |
| 1049: | 'post_type' => self::get_archive_preview_post_types(), |
| 1050: | 'post_status' => 'publish', |
| 1051: | 'posts_per_page' => $posts_per_page, |
| 1052: | 'paged' => 1, |
| 1053: | 'orderby' => 'date', |
| 1054: | 'order' => 'DESC', |
| 1055: | 'ignore_sticky_posts' => true, |
| 1056: | 'epl_elementor_loop' => true, |
| 1057: | ); |
| 1058: | } |
| 1059: | |
| 1060: | |
| 1061: | |
| 1062: | |
| 1063: | |
| 1064: | |
| 1065: | |
| 1066: | public function begin_loop_grid_render( $widget ) { |
| 1067: | if ( ! $widget || 'loop-grid' !== $widget->get_name() ) { |
| 1068: | return; |
| 1069: | } |
| 1070: | $template_id = absint( $widget->get_settings( 'template_id' ) ); |
| 1071: | if ( $template_id && 'listing' === self::get_epl_template_context( $template_id ) ) { |
| 1072: | $this->active_loop_grid_settings = $widget->get_settings_for_display(); |
| 1073: | $this->active_loop_grid_settings['_epl_widget_id'] = $widget->get_id(); |
| 1074: | } |
| 1075: | } |
| 1076: | |
| 1077: | |
| 1078: | |
| 1079: | |
| 1080: | |
| 1081: | |
| 1082: | |
| 1083: | public function end_loop_grid_render( $widget ) { |
| 1084: | if ( $widget && 'loop-grid' === $widget->get_name() ) { |
| 1085: | $this->active_loop_grid_settings = array(); |
| 1086: | } |
| 1087: | } |
| 1088: | |
| 1089: | |
| 1090: | |
| 1091: | |
| 1092: | |
| 1093: | |
| 1094: | |
| 1095: | |
| 1096: | |
| 1097: | |
| 1098: | public function register_loop_grid_pagination_provider( $element ) { |
| 1099: | $element->add_control( |
| 1100: | 'epl_pagination_provider', |
| 1101: | array( |
| 1102: | 'label' => esc_html__( 'Pagination Renderer', 'easy-property-listings' ), |
| 1103: | 'type' => \Elementor\Controls_Manager::SELECT, |
| 1104: | 'default' => 'elementor', |
| 1105: | 'options' => array( |
| 1106: | 'elementor' => esc_html__( 'Elementor', 'easy-property-listings' ), |
| 1107: | 'epl' => esc_html__( 'EPL', 'easy-property-listings' ), |
| 1108: | ), |
| 1109: | 'condition' => array( |
| 1110: | 'pagination_type!' => array( '', 'load_more_on_click', 'load_more_infinite_scroll' ), |
| 1111: | ), |
| 1112: | ) |
| 1113: | ); |
| 1114: | $element->add_control( |
| 1115: | 'epl_pagination_style', |
| 1116: | array( |
| 1117: | 'label' => esc_html__( 'EPL Pagination Type', 'easy-property-listings' ), |
| 1118: | 'type' => \Elementor\Controls_Manager::SELECT, |
| 1119: | 'default' => 'default', |
| 1120: | 'options' => array( |
| 1121: | 'fancy' => esc_html__( 'Fancy', 'easy-property-listings' ), |
| 1122: | 'default' => esc_html__( 'WordPress Default', 'easy-property-listings' ), |
| 1123: | ), |
| 1124: | 'condition' => array( |
| 1125: | 'epl_pagination_provider' => 'epl', |
| 1126: | ), |
| 1127: | ) |
| 1128: | ); |
| 1129: | } |
| 1130: | |
| 1131: | |
| 1132: | |
| 1133: | |
| 1134: | |
| 1135: | |
| 1136: | |
| 1137: | |
| 1138: | public function capture_loop_grid_query( $query, $widget ) { |
| 1139: | if ( $query instanceof WP_Query && $widget && 'loop-grid' === $widget->get_name() ) { |
| 1140: | $this->loop_grid_queries[ $widget->get_id() ] = $query; |
| 1141: | } |
| 1142: | } |
| 1143: | |
| 1144: | |
| 1145: | |
| 1146: | |
| 1147: | |
| 1148: | |
| 1149: | |
| 1150: | |
| 1151: | |
| 1152: | public function render_loop_grid_epl_pagination( $content, $widget ) { |
| 1153: | if ( ! $widget || 'loop-grid' !== $widget->get_name() ) { |
| 1154: | return $content; |
| 1155: | } |
| 1156: | $integrated_epl = 'epl' === $widget->get_settings( 'epl_pagination_provider' ); |
| 1157: | $standalone_epl = self::current_document_has_epl_pagination_widget(); |
| 1158: | if ( ! $integrated_epl && ! $standalone_epl ) { |
| 1159: | return $content; |
| 1160: | } |
| 1161: | |
| 1162: | $query = $this->loop_grid_queries[ $widget->get_id() ] ?? null; |
| 1163: | if ( ! $query instanceof WP_Query ) { |
| 1164: | return $content; |
| 1165: | } |
| 1166: | |
| 1167: | |
| 1168: | |
| 1169: | $content = preg_replace( '#\s*<div class="e-load-more-anchor"[^>]*></div>\s*<nav class="elementor-pagination".*?</nav>#s', '', $content ); |
| 1170: | if ( $standalone_epl ) { |
| 1171: | return $content; |
| 1172: | } |
| 1173: | ob_start(); |
| 1174: | $pagination_style = $widget->get_settings( 'epl_pagination_style' ); |
| 1175: | self::render_loop_grid_epl_navigation( $query, $widget->get_id(), $pagination_style ? $pagination_style : 'default' ); |
| 1176: | return $content . ob_get_clean(); |
| 1177: | } |
| 1178: | |
| 1179: | |
| 1180: | |
| 1181: | |
| 1182: | |
| 1183: | |
| 1184: | |
| 1185: | private static function current_document_has_epl_pagination_widget() { |
| 1186: | $document_id = get_the_ID(); |
| 1187: | if ( isset( \Elementor\Plugin::$instance->documents ) ) { |
| 1188: | $document = \Elementor\Plugin::$instance->documents->get_current(); |
| 1189: | if ( $document ) { |
| 1190: | $document_id = $document->get_main_id(); |
| 1191: | } |
| 1192: | } |
| 1193: | $data = $document_id ? (string) get_post_meta( $document_id, '_elementor_data', true ) : ''; |
| 1194: | return false !== strpos( $data, '"widgetType":"epl-pagination"' ); |
| 1195: | } |
| 1196: | |
| 1197: | |
| 1198: | |
| 1199: | |
| 1200: | |
| 1201: | |
| 1202: | |
| 1203: | |
| 1204: | public static function render_loop_grid_epl_navigation( $query, $widget_id, $pagination_style = '' ) { |
| 1205: | if ( ! $query instanceof WP_Query || $query->max_num_pages < 2 ) { |
| 1206: | return; |
| 1207: | } |
| 1208: | $original = array( |
| 1209: | 'instance_id' => $query->get( 'instance_id' ), |
| 1210: | 'is_epl_shortcode' => $query->get( 'is_epl_shortcode' ), |
| 1211: | 'epl_shortcode_name' => $query->get( 'epl_shortcode_name' ), |
| 1212: | ); |
| 1213: | $query->set( 'instance_id', 'elementor-' . sanitize_key( $widget_id ) ); |
| 1214: | $query->set( 'is_epl_shortcode', true ); |
| 1215: | $query->set( 'epl_shortcode_name', 'listing_advanced' ); |
| 1216: | self::render_epl_pagination( $query, $pagination_style ); |
| 1217: | foreach ( $original as $key => $value ) { |
| 1218: | $query->set( $key, $value ); |
| 1219: | } |
| 1220: | } |
| 1221: | |
| 1222: | |
| 1223: | |
| 1224: | |
| 1225: | |
| 1226: | |
| 1227: | |
| 1228: | |
| 1229: | |
| 1230: | public static function render_epl_pagination( $query, $pagination_style = '' ) { |
| 1231: | $style_filter = null; |
| 1232: | if ( in_array( $pagination_style, array( 'fancy', 'default' ), true ) ) { |
| 1233: | $style_filter = static function () use ( $pagination_style ) { |
| 1234: | return 'fancy' === $pagination_style ? 1 : 0; |
| 1235: | }; |
| 1236: | add_filter( 'epl_get_option_use_fancy_navigation', $style_filter, PHP_INT_MAX ); |
| 1237: | } |
| 1238: | |
| 1239: | do_action( 'epl_pagination', array( 'query' => $query ) ); |
| 1240: | |
| 1241: | if ( $style_filter ) { |
| 1242: | remove_filter( 'epl_get_option_use_fancy_navigation', $style_filter, PHP_INT_MAX ); |
| 1243: | } |
| 1244: | } |
| 1245: | |
| 1246: | |
| 1247: | |
| 1248: | |
| 1249: | |
| 1250: | |
| 1251: | |
| 1252: | public function get_last_loop_grid_query() { |
| 1253: | if ( empty( $this->loop_grid_queries ) ) { |
| 1254: | return array(); |
| 1255: | } |
| 1256: | $widget_id = array_key_last( $this->loop_grid_queries ); |
| 1257: | return array( 'widget_id' => $widget_id, 'query' => $this->loop_grid_queries[ $widget_id ] ); |
| 1258: | } |
| 1259: | |
| 1260: | |
| 1261: | |
| 1262: | |
| 1263: | |
| 1264: | |
| 1265: | |
| 1266: | public function allow_epl_loop_grid_page( $preempt, $query ) { |
| 1267: | $instance_id = isset( $_GET['pagination_id'] ) ? sanitize_text_field( wp_unslash( $_GET['pagination_id'] ) ) : ''; |
| 1268: | if ( 0 !== strpos( $instance_id, 'elementor-' ) || ! is_post_type_archive( epl_get_core_post_types() ) ) { |
| 1269: | return $preempt; |
| 1270: | } |
| 1271: | return true; |
| 1272: | } |
| 1273: | |
| 1274: | |
| 1275: | |
| 1276: | |
| 1277: | |
| 1278: | |
| 1279: | |
| 1280: | private static function get_current_epl_loop_grid_settings() { |
| 1281: | $document_ids = array(); |
| 1282: | $current_post = get_post(); |
| 1283: | |
| 1284: | if ( $current_post && 'elementor_library' === $current_post->post_type ) { |
| 1285: | $document_ids[] = (int) $current_post->ID; |
| 1286: | } |
| 1287: | |
| 1288: | if ( isset( \Elementor\Plugin::$instance->documents ) ) { |
| 1289: | $current_document = \Elementor\Plugin::$instance->documents->get_current(); |
| 1290: | if ( $current_document ) { |
| 1291: | $document_ids[] = (int) $current_document->get_main_id(); |
| 1292: | } |
| 1293: | } |
| 1294: | |
| 1295: | foreach ( array_unique( array_filter( $document_ids ) ) as $document_id ) { |
| 1296: | $elements = json_decode( (string) get_post_meta( $document_id, '_elementor_data', true ), true ); |
| 1297: | $stack = is_array( $elements ) ? $elements : array(); |
| 1298: | |
| 1299: | while ( $stack ) { |
| 1300: | $element = array_pop( $stack ); |
| 1301: | if ( ! is_array( $element ) ) { |
| 1302: | continue; |
| 1303: | } |
| 1304: | |
| 1305: | if ( 'loop-grid' === ( $element['widgetType'] ?? '' ) ) { |
| 1306: | $settings = isset( $element['settings'] ) && is_array( $element['settings'] ) ? $element['settings'] : array(); |
| 1307: | $template_id = isset( $settings['template_id'] ) ? absint( $settings['template_id'] ) : 0; |
| 1308: | if ( $template_id && 'listing' === self::get_epl_template_context( $template_id ) ) { |
| 1309: | $settings['_epl_widget_id'] = isset( $element['id'] ) ? sanitize_key( $element['id'] ) : ''; |
| 1310: | return $settings; |
| 1311: | } |
| 1312: | } |
| 1313: | |
| 1314: | if ( ! empty( $element['elements'] ) && is_array( $element['elements'] ) ) { |
| 1315: | $stack = array_merge( $stack, $element['elements'] ); |
| 1316: | } |
| 1317: | } |
| 1318: | } |
| 1319: | |
| 1320: | return array(); |
| 1321: | } |
| 1322: | |
| 1323: | |
| 1324: | |
| 1325: | |
| 1326: | |
| 1327: | |
| 1328: | |
| 1329: | |
| 1330: | private static function get_epl_template_context( $template_id ) { |
| 1331: | $stored_context = (string) get_post_meta( $template_id, '_epl_elementor_template_context', true ); |
| 1332: | if ( in_array( $stored_context, array( 'listing', 'staff' ), true ) ) { |
| 1333: | return $stored_context; |
| 1334: | } |
| 1335: | |
| 1336: | |
| 1337: | |
| 1338: | |
| 1339: | $template_type = get_post_meta( $template_id, '_elementor_template_type', true ); |
| 1340: | if ( in_array( $template_type, array( EPL_Elementor_Single_Document::TYPE, EPL_Elementor_Loop_Card_Document::TYPE ), true ) ) { |
| 1341: | return 'listing'; |
| 1342: | } |
| 1343: | |
| 1344: | $data = (string) get_post_meta( $template_id, '_elementor_data', true ); |
| 1345: | if ( false !== strpos( $data, '"widgetType":"epl-property-' ) || false !== strpos( $data, '"widgetType":"epl-listing-agents"' ) ) { |
| 1346: | return 'listing'; |
| 1347: | } |
| 1348: | if ( false !== strpos( $data, '"widgetType":"epl-agent-' ) ) { |
| 1349: | return 'staff'; |
| 1350: | } |
| 1351: | return ''; |
| 1352: | } |
| 1353: | |
| 1354: | |
| 1355: | |
| 1356: | |
| 1357: | |
| 1358: | |
| 1359: | |
| 1360: | |
| 1361: | private static function get_archive_preview_post_types() { |
| 1362: | $post_types = epl_get_core_post_types(); |
| 1363: | $document_id = get_the_ID(); |
| 1364: | if ( isset( \Elementor\Plugin::$instance->documents ) ) { |
| 1365: | $current_document = \Elementor\Plugin::$instance->documents->get_current(); |
| 1366: | if ( $current_document ) { |
| 1367: | $document_id = $current_document->get_main_id(); |
| 1368: | } |
| 1369: | } |
| 1370: | $conditions = $document_id ? get_post_meta( $document_id, '_elementor_conditions', true ) : array(); |
| 1371: | |
| 1372: | if ( is_array( $conditions ) ) { |
| 1373: | foreach ( $conditions as $condition ) { |
| 1374: | $parts = explode( '/', (string) $condition ); |
| 1375: | $last = end( $parts ); |
| 1376: | if ( substr( $last, -8 ) === '_archive' ) { |
| 1377: | $candidate = substr( $last, 0, -8 ); |
| 1378: | if ( in_array( $candidate, $post_types, true ) ) { |
| 1379: | return array( $candidate ); |
| 1380: | } |
| 1381: | } |
| 1382: | } |
| 1383: | } |
| 1384: | |
| 1385: | return $post_types; |
| 1386: | } |
| 1387: | |
| 1388: | |
| 1389: | |
| 1390: | |
| 1391: | |
| 1392: | |
| 1393: | |
| 1394: | |
| 1395: | |
| 1396: | |
| 1397: | public function track_archive_conditions( $meta_id, $post_id, $meta_key, $meta_value ) { |
| 1398: | if ( '_elementor_conditions' !== $meta_key || 'archive' !== get_post_meta( $post_id, '_elementor_template_type', true ) ) { |
| 1399: | return; |
| 1400: | } |
| 1401: | |
| 1402: | if ( ! empty( $meta_value ) && is_array( $meta_value ) ) { |
| 1403: | update_post_meta( $post_id, '_epl_elementor_conditions_backup', $meta_value ); |
| 1404: | } |
| 1405: | |
| 1406: | self::$archive_condition_checks[ $post_id ] = true; |
| 1407: | if ( ! self::$archive_condition_shutdown_registered ) { |
| 1408: | self::$archive_condition_shutdown_registered = true; |
| 1409: | add_action( 'shutdown', array( $this, 'restore_archive_conditions' ), 1 ); |
| 1410: | } |
| 1411: | } |
| 1412: | |
| 1413: | |
| 1414: | |
| 1415: | |
| 1416: | |
| 1417: | |
| 1418: | private static $archive_condition_checks = array(); |
| 1419: | |
| 1420: | |
| 1421: | |
| 1422: | |
| 1423: | |
| 1424: | |
| 1425: | private static $archive_condition_shutdown_registered = false; |
| 1426: | |
| 1427: | |
| 1428: | |
| 1429: | |
| 1430: | |
| 1431: | public function restore_archive_conditions() { |
| 1432: | foreach ( array_keys( self::$archive_condition_checks ) as $post_id ) { |
| 1433: | $current = get_post_meta( $post_id, '_elementor_conditions', true ); |
| 1434: | $backup = get_post_meta( $post_id, '_epl_elementor_conditions_backup', true ); |
| 1435: | |
| 1436: | if ( empty( $current ) && ! empty( $backup ) && apply_filters( 'epl_elementor_restore_archive_conditions', true, $post_id, $backup ) ) { |
| 1437: | update_post_meta( $post_id, '_elementor_conditions', $backup ); |
| 1438: | } |
| 1439: | } |
| 1440: | } |
| 1441: | |
| 1442: | |
| 1443: | |
| 1444: | |
| 1445: | |
| 1446: | |
| 1447: | |
| 1448: | |
| 1449: | |
| 1450: | |
| 1451: | public static function get_preview_property() { |
| 1452: | static $preview_property = null; |
| 1453: | |
| 1454: | |
| 1455: | if ( null !== $preview_property ) { |
| 1456: | return $preview_property; |
| 1457: | } |
| 1458: | |
| 1459: | $requested_id = isset( $_GET['epl_elementor_preview_id'] ) ? absint( wp_unslash( $_GET['epl_elementor_preview_id'] ) ) : 0; |
| 1460: | $requested_id = absint( apply_filters( 'epl_elementor_preview_listing_id', $requested_id ) ); |
| 1461: | if ( $requested_id ) { |
| 1462: | $requested_post = get_post( $requested_id ); |
| 1463: | |
| 1464: | if ( $requested_post && is_epl_post( $requested_post->post_type ) && ( 'publish' === $requested_post->post_status || current_user_can( 'edit_post', $requested_id ) ) ) { |
| 1465: | $preview_property = new EPL_Property_Meta( $requested_post ); |
| 1466: | return $preview_property; |
| 1467: | } |
| 1468: | } |
| 1469: | |
| 1470: | |
| 1471: | |
| 1472: | |
| 1473: | $post_types = self::get_archive_preview_post_types(); |
| 1474: | |
| 1475: | if ( empty( $post_types ) ) { |
| 1476: | $preview_property = false; |
| 1477: | return false; |
| 1478: | } |
| 1479: | |
| 1480: | |
| 1481: | |
| 1482: | |
| 1483: | $args = array( |
| 1484: | 'post_type' => $post_types, |
| 1485: | 'post_status' => 'publish', |
| 1486: | 'posts_per_page' => 1, |
| 1487: | 'orderby' => 'date', |
| 1488: | 'order' => 'DESC', |
| 1489: | 'no_found_rows' => true, |
| 1490: | 'meta_query' => array( |
| 1491: | array( |
| 1492: | 'key' => '_thumbnail_id', |
| 1493: | 'compare' => 'EXISTS', |
| 1494: | ), |
| 1495: | ), |
| 1496: | ); |
| 1497: | |
| 1498: | $query = new WP_Query( $args ); |
| 1499: | if ( ! $query->have_posts() ) { |
| 1500: | unset( $args['meta_query'] ); |
| 1501: | $query = new WP_Query( $args ); |
| 1502: | } |
| 1503: | |
| 1504: | if ( $query->have_posts() ) { |
| 1505: | $preview_property = new EPL_Property_Meta( $query->posts[0] ); |
| 1506: | } else { |
| 1507: | $preview_property = false; |
| 1508: | } |
| 1509: | return $preview_property; |
| 1510: | } |
| 1511: | } |
| 1512: | |
| 1513: | |
| 1514: | add_action( 'elementor/loaded', array( 'EPL_Elementor', 'instance' ) ); |
| 1515: | |