| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Core\Common\Modules\Finder; |
| 4 |
|
| 5 |
use Elementor\Core\Base\Module as BaseModule; |
| 6 |
use Elementor\Core\Common\Modules\Ajax\Module as Ajax; |
| 7 |
use Elementor\Plugin; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Finder Module |
| 15 |
* |
| 16 |
* Responsible for initializing Elementor Finder functionality |
| 17 |
*/ |
| 18 |
class Module extends BaseModule { |
| 19 |
|
| 20 |
/** |
| 21 |
* Categories manager. |
| 22 |
* |
| 23 |
* @access private |
| 24 |
* |
| 25 |
* @var Categories_Manager |
| 26 |
*/ |
| 27 |
private $categories_manager; |
| 28 |
|
| 29 |
/** |
| 30 |
* Module constructor. |
| 31 |
* |
| 32 |
* @since 2.3.0 |
| 33 |
* @access public |
| 34 |
*/ |
| 35 |
public function __construct() { |
| 36 |
$this->categories_manager = new Categories_Manager(); |
| 37 |
|
| 38 |
$this->add_template(); |
| 39 |
|
| 40 |
add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Get name. |
| 45 |
* |
| 46 |
* @since 2.3.0 |
| 47 |
* @access public |
| 48 |
* |
| 49 |
* @return string |
| 50 |
*/ |
| 51 |
public function get_name() { |
| 52 |
return 'finder'; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Add template. |
| 57 |
* |
| 58 |
* @since 2.3.0 |
| 59 |
* @access public |
| 60 |
*/ |
| 61 |
public function add_template() { |
| 62 |
Plugin::$instance->common->add_template( __DIR__ . '/template.php' ); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Register ajax actions. |
| 67 |
* |
| 68 |
* @since 2.3.0 |
| 69 |
* @access public |
| 70 |
* |
| 71 |
* @param Ajax $ajax |
| 72 |
*/ |
| 73 |
public function register_ajax_actions( Ajax $ajax ) { |
| 74 |
$ajax->register_ajax_action( 'finder_get_category_items', [ $this, 'ajax_get_category_items' ] ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Ajax get category items. |
| 79 |
* |
| 80 |
* @since 2.3.0 |
| 81 |
* @access public |
| 82 |
* |
| 83 |
* @param array $data |
| 84 |
* |
| 85 |
* @return array |
| 86 |
*/ |
| 87 |
public function ajax_get_category_items( array $data ) { |
| 88 |
$category = $this->categories_manager->get_categories( $data['category'] ); |
| 89 |
|
| 90 |
return $category->get_category_items( $data ); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Get init settings. |
| 95 |
* |
| 96 |
* @since 2.3.0 |
| 97 |
* @access protected |
| 98 |
* |
| 99 |
* @return array |
| 100 |
*/ |
| 101 |
protected function get_init_settings() { |
| 102 |
$categories = $this->categories_manager->get_categories(); |
| 103 |
|
| 104 |
$categories_data = []; |
| 105 |
|
| 106 |
foreach ( $categories as $category_name => $category ) { |
| 107 |
$categories_data[ $category_name ] = array_merge( $category->get_settings(), [ 'name' => $category_name ] ); |
| 108 |
} |
| 109 |
|
| 110 |
$categories_data = apply_filters( 'elementor/finder/categories', $categories_data ); |
| 111 |
|
| 112 |
return [ |
| 113 |
'data' => $categories_data, |
| 114 |
'i18n' => [ |
| 115 |
'finder' => __( 'Finder', 'elementor' ), |
| 116 |
], |
| 117 |
]; |
| 118 |
} |
| 119 |
} |
| 120 |
|