Admin
1 month ago
Api
1 month ago
Blocks
2 months ago
Hooks
1 month ago
AjaxController.php
1 month ago
BlocksController.php
1 month ago
DiviController.php
1 year ago
ElementorController.php
1 year ago
GutenBergController.php
1 month ago
PageTemplateController.php
2 years ago
ScriptController.php
1 month ago
ShortcodeController.php
5 months ago
WidgetController.php
2 years ago
DiviController.php
135 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Elementor Controller class. |
| 4 | * |
| 5 | * @package RT_TPG |
| 6 | */ |
| 7 | |
| 8 | namespace RT\ThePostGrid\Controllers; |
| 9 | |
| 10 | // Do not allow directly accessing this file. |
| 11 | use RT\ThePostGrid\Helpers\DiviFns; |
| 12 | use RT\ThePostGrid\Helpers\Fns; |
| 13 | use RT\ThePostGrid\Divi\Mudules\GridLayout; |
| 14 | use RT\ThePostGrid\Divi\Mudules\GridHoverLayout; |
| 15 | use RT\ThePostGrid\Divi\Mudules\ListLayout; |
| 16 | use RT\ThePostGrid\Divi\Utils\DiviEditorCss; |
| 17 | use RT\ThePostGrid\Divi\Utils\DiviFrontEndCss; |
| 18 | |
| 19 | if (!defined('ABSPATH')) { |
| 20 | exit('This script cannot be accessed directly.'); |
| 21 | } |
| 22 | |
| 23 | if (!class_exists('DiviController')) : |
| 24 | /** |
| 25 | * Elementor Controller class. |
| 26 | */ |
| 27 | class DiviController |
| 28 | { |
| 29 | |
| 30 | protected $settings = []; |
| 31 | /** |
| 32 | * Version |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | private $version; |
| 37 | |
| 38 | /** |
| 39 | * Class constructor |
| 40 | */ |
| 41 | public function __construct() |
| 42 | { |
| 43 | $this->version = defined('WP_DEBUG') && WP_DEBUG ? time() : RT_THE_POST_GRID_VERSION; |
| 44 | add_action('wp_enqueue_scripts', [$this, 'front_end_script'], 999999999); |
| 45 | add_action('et_builder_ready', [$this, 'load_modules'], 20); |
| 46 | add_action('wp_enqueue_scripts', [$this, 'tpg_et_builder_editor_enqueue'], 999999999); |
| 47 | add_action('admin_head', [$this, 'tpg_et_builder_archive_enqueue'], 999999999); |
| 48 | add_action('wp_head', [$this, 'css_prop_for_editor_front_end']); |
| 49 | } |
| 50 | |
| 51 | public function load_modules() |
| 52 | { |
| 53 | if (!class_exists(\ET_Builder_Element::class)) { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | $modules = [ |
| 58 | GridLayout::class, |
| 59 | GridHoverLayout::class, |
| 60 | ListLayout::class, |
| 61 | ]; |
| 62 | |
| 63 | if (defined('RT_TPG_PRO_VERSION') && version_compare(RT_TPG_PRO_VERSION, '7.8.0', '>')) { |
| 64 | $modules = apply_filters('rttpg_divi_modules', $modules); |
| 65 | } |
| 66 | |
| 67 | foreach ($modules as $module_class) { |
| 68 | if (class_exists($module_class)) { |
| 69 | new $module_class(); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | public function front_end_script() |
| 75 | { |
| 76 | if (DiviFns::is_divi_builder_preview()) { |
| 77 | wp_enqueue_script( |
| 78 | 'rttpg-divi-modules', |
| 79 | rtTPG()->get_assets_uri('divi/divi-modules.js'), |
| 80 | [ |
| 81 | 'jquery', |
| 82 | 'react-dom', |
| 83 | 'react', |
| 84 | 'et_pb_media_library', |
| 85 | 'wp-element', |
| 86 | 'wp-i18n', |
| 87 | ], |
| 88 | $this->version, |
| 89 | true |
| 90 | ); |
| 91 | |
| 92 | wp_enqueue_style('rt-fontawsome'); |
| 93 | wp_enqueue_style('rt-flaticon'); |
| 94 | wp_enqueue_style('rt-tpg-block'); |
| 95 | wp_enqueue_style('swiper'); |
| 96 | wp_enqueue_script('rt-tpg'); |
| 97 | wp_enqueue_script('rttpg-block-pro'); |
| 98 | |
| 99 | do_action('rttpg_divi_frontend_scripts'); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Front-end tab css modify |
| 105 | * |
| 106 | * @return array |
| 107 | */ |
| 108 | public function tpg_et_builder_editor_enqueue() |
| 109 | { |
| 110 | if (wp_style_is('et-frontend-builder')) { |
| 111 | $custom_css = DiviEditorCss::editor_css(); |
| 112 | wp_add_inline_style('et-frontend-builder', $custom_css); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | public function tpg_et_builder_archive_enqueue() |
| 117 | { |
| 118 | $custom_css = DiviEditorCss::editor_css(); |
| 119 | if (DiviFns::is_divi_builder_preview()) { |
| 120 | echo "<style>{$custom_css}</style>"; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | public function css_prop_for_editor_front_end() |
| 125 | { |
| 126 | if (DiviFns::is_divi_builder_preview()) { |
| 127 | ?> |
| 128 | <script>window.tpgDiviLayoutCSS =<?php echo wp_json_encode(DiviFrontEndCss::css_collection()); ?></script> |
| 129 | <?php |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | } |
| 134 | endif; |
| 135 |