PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.2.7
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.2.7
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / ElementorController.php
the-post-grid / app / Controllers Last commit date
Admin 2 years ago Api 2 years ago Blocks 2 years ago Hooks 2 years ago AjaxController.php 2 years ago BlocksController.php 2 years ago ElementorController.php 2 years ago GutenBergController.php 2 years ago PageTemplateController.php 2 years ago ScriptController.php 2 years ago ShortcodeController.php 2 years ago WidgetController.php 2 years ago
ElementorController.php
336 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\Fns;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit( 'This script cannot be accessed directly.' );
15 }
16
17 if ( ! class_exists( 'ElementorController' ) ) :
18 /**
19 * Elementor Controller class.
20 */
21 class ElementorController {
22 /**
23 * Category ID
24 *
25 * @var string
26 */
27 public $el_cat_id;
28
29 /**
30 * Version
31 *
32 * @var string
33 */
34 private $version;
35
36 /**
37 * Class constructor
38 */
39 public function __construct() {
40 $this->version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RT_THE_POST_GRID_VERSION;
41 $this->el_cat_id = RT_THE_POST_GRID_PLUGIN_SLUG . '-elements';
42
43 if ( did_action( 'elementor/loaded' ) ) {
44 add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] );
45 add_action( 'elementor/elements/categories_registered', [ $this, 'widget_category' ] );
46 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'el_editor_script' ] );
47 add_action( 'wp_footer', [ $this, 'tpg_el_scripts' ] );
48 add_action( 'wp_enqueue_scripts', [ $this, 'tpg_el_style' ] );
49 add_filter( 'elementor/editor/localize_settings', [ $this, 'promotePremiumWidgets' ] );
50 }
51 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'editor_el_enqueue' ] );
52 add_action( 'wp_ajax_rttpg_get_el_layouts', [ $this, 'rttpg_get_el_layouts' ] );
53 add_action( 'wp_ajax_rttpg_el_layout_count', [ $this, 'rttpg_el_layout_count' ] );
54 }
55
56 //TODO Import
57
58 public function editor_el_enqueue() {
59
60
61 wp_enqueue_style(
62 'rttpg-elementor-edition',
63 rtTPG()->get_assets_uri( 'elementor/main.css' ) .
64 null,
65 $this->version
66 );
67
68
69 wp_enqueue_script(
70 'rttpg-elementor-import', rtTPG()->get_assets_uri( 'elementor/main.js' ),
71 [
72 'wp-block-editor',
73 'wp-blocks',
74 'wp-i18n',
75 'wp-element',
76 'wp-hooks',
77 'wp-util',
78 'wp-components',
79 'elementor-editor',
80 'jquery'
81 ],
82 $this->version,
83 true
84 );
85
86 wp_localize_script( 'rttpg-elementor-import', 'rttpgParams', [
87 'nonce' => wp_create_nonce( 'rttpg_nonce' ),
88 'hasPro' => rtTPG()->hasPro(),
89 'current_user_id' => get_current_user_id(),
90 'ajaxurl' => admin_url( 'admin-ajax.php' ),
91 'site_url' => site_url(),
92 'plugin_url' => RT_THE_POST_GRID_PLUGIN_URL,
93 'admin_url' => admin_url(),
94 'plugin_pro_url' => rtTPG()->getProPath(),
95 'post_type' => Fns::get_post_types(),
96 'all_term_list' => Fns::get_all_taxonomy_guten(),
97 ]
98 );
99
100 }
101
102 public function rttpg_el_layout_count() {
103
104 $BASE_URL = "https://www.radiustheme.com/demo/plugins/the-post-grid-elementor/wp-json/rttpgapi/v1/layoutinfo/";
105 // Verify the request.
106 check_ajax_referer( 'rttpg_nonce', 'nonce' );
107
108 // It's good let's do some capability check.
109 $user = wp_get_current_user();
110 $allowed_roles = [ 'editor', 'administrator', 'author' ];
111
112 if ( ! array_intersect( $allowed_roles, $user->roles ) ) {
113 wp_die( __( 'You don\'t have permission to perform this action', 'rttpg' ) );
114 }
115
116 // Cool, we're almost there, let's check the user authenticity a little bit, shall we!
117 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
118 wp_die( __( 'You don\'t have proper authorization to perform this action', 'rttpg' ) );
119 }
120
121 $status = $_REQUEST['status'] ?? '';
122 $layout_id = $_REQUEST['layout_id'] ?? '';
123
124 $post_args = [ 'timeout' => 120 ];
125 $post_args['body'] = [ 'status' => $status, 'layout_id' => $layout_id ];
126 $layoutRequest = wp_remote_post( $BASE_URL, $post_args );
127 if ( is_wp_error( $layoutRequest ) ) {
128 wp_send_json_error( [ 'messages' => $layoutRequest->get_error_messages() ] );
129 }
130 $layoutData = json_decode( $layoutRequest['body'], true );
131
132 wp_send_json_success( $layoutData );
133 }
134
135
136 /**
137 * @return void
138 */
139 public function rttpg_get_el_layouts() {
140
141 $BASE_URL = "https://www.radiustheme.com/demo/plugins/the-post-grid-elementor/wp-json/rttpgelapi/v1/layouts/";
142
143 // Verify the request.
144 check_ajax_referer( 'rttpg_nonce', 'nonce' );
145
146 // It's good let's do some capability check.
147 $user = wp_get_current_user();
148 $allowed_roles = [ 'editor', 'administrator', 'author' ];
149
150 if ( ! array_intersect( $allowed_roles, $user->roles ) ) {
151 wp_die( __( 'You don\'t have permission to perform this action', 'rttpg' ) );
152 }
153
154 // Cool, we're almost there, let's check the user authenticity a little bit, shall we!
155 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
156 wp_die( __( 'You don\'t have proper authorization to perform this action', 'rttpg' ) );
157 }
158
159 $status = isset( $_REQUEST['status'] ) ? $_REQUEST['status'] : '';
160 $post_args = [ 'timeout' => 120 ];
161 $post_args['body'] = [ 'status' => $status ];
162 $layoutRequest = wp_remote_post( $BASE_URL, $post_args );
163 if ( is_wp_error( $layoutRequest ) ) {
164 wp_send_json_error( [ 'messages' => $layoutRequest->get_error_messages() ] );
165 }
166 $layoutData = json_decode( $layoutRequest['body'], true );
167
168 wp_send_json_success( $layoutData );
169 }
170
171
172 /**
173 * Style
174 *
175 * @return void
176 */
177 public function tpg_el_style() {
178 // Custom CSS From Settings.
179 $css = isset( $settings['custom_css'] ) ? stripslashes( $settings['custom_css'] ) : null;
180 if ( $css ) {
181 wp_add_inline_style( 'rt-tpg-block', $css );
182 }
183 }
184
185 /**
186 * Scripts
187 *
188 * @return void
189 */
190 public function tpg_el_scripts() {
191 $ajaxurl = '';
192
193 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
194 $ajaxurl .= admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
195 } else {
196 $ajaxurl .= admin_url( 'admin-ajax.php' );
197 }
198
199 $variables = [
200 'nonceID' => esc_attr( rtTPG()->nonceId() ),
201 'nonce' => esc_attr( wp_create_nonce( rtTPG()->nonceText() ) ),
202 'ajaxurl' => esc_url( $ajaxurl ),
203 ];
204
205 wp_localize_script( 'rt-tpg', 'rttpg', $variables );
206 }
207
208 /**
209 * Editor Scripts
210 *
211 * @return void
212 */
213 public function el_editor_script() {
214 wp_enqueue_script( 'tgp-el-editor-scripts', rtTPG()->get_assets_uri( 'js/tpg-el-editor.js' ), [ 'jquery' ], $this->version, true );
215 wp_enqueue_style( 'tgp-el-editor-style', rtTPG()->get_assets_uri( 'css/admin/tpg-el-editor.css' ), [], $this->version );
216 }
217
218 /**
219 * Elementor widgets
220 *
221 * @param object $widgets_manager Manager.
222 *
223 * @return void
224 */
225 public function init_widgets( $widgets_manager ) {
226 require_once RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/base.php';
227 require_once RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/rtTPGElementorHelper.php';
228
229 // dir_name => class_name.
230 $widgets = [
231 'grid-layout' => '\TPGGridLayout',
232 'list-layout' => '\TPGListLayout',
233 'grid-hover-layout' => '\TPGGridHoverLayout',
234 'slider-layout' => '\TPGSliderLayout',
235 'category-block' => '\TPGCategoryBlock',
236 'section-title' => '\SectionTitle',
237 ];
238
239 if ( rtTPG()->hasPro() && defined( 'RT_THE_POST_GRID_PRO_PLUGIN_PATH' ) ) {
240 $proFileCheck = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/app/Widgets/elementor/category-block.php';
241 if ( file_exists( $proFileCheck ) ) {
242 unset( $widgets['category-block'] );
243 }
244 }
245
246 $widgets = apply_filters( 'tpg_el_widget_register', $widgets );
247
248 foreach ( $widgets as $file_name => $class ) {
249
250 if ( ! rtTPG()->hasPro() && in_array( $file_name, [ 'slider-layout', 'category-block' ] ) ) {
251 continue;
252 }
253
254 $template_name = 'the-post-grid/elementor/' . $file_name . '.php';
255
256 if ( file_exists( STYLESHEETPATH . $template_name ) ) {
257 $file = STYLESHEETPATH . $template_name;
258 } else if ( file_exists( TEMPLATEPATH . $template_name ) ) {
259 $file = TEMPLATEPATH . $template_name;
260 } else {
261 $file = RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/widgets/' . $file_name . '.php';
262 }
263
264 require_once $file;
265
266 $widgets_manager->register( new $class() );
267 }
268 }
269
270 /**
271 * Widget category
272 *
273 * @param object $elements_manager Manager.
274 *
275 * @return void
276 */
277 public function widget_category( $elements_manager ) {
278 $categories['tpg-block-builder-widgets'] = [
279 'title' => esc_html__( 'TPG Template Builder Element', 'the-post-grid' ),
280 'icon' => 'fa fa-plug',
281 ];
282
283 $categories[ RT_THE_POST_GRID_PLUGIN_SLUG . '-elements' ] = [
284 'title' => esc_html__( 'The Post Grid', 'the-post-grid' ),
285 'icon' => 'fa fa-plug',
286 ];
287
288 $get_all_categories = $elements_manager->get_categories();
289 $categories = array_merge( $categories, $get_all_categories );
290 $set_categories = function ( $categories ) {
291 $this->categories = $categories;
292 };
293
294 $set_categories->call( $elements_manager, $categories );
295 }
296
297 /**
298 * Promotion
299 *
300 * @param array $config Config.
301 *
302 * @return array
303 */
304 public function promotePremiumWidgets( $config ) {
305 if ( rtTPG()->hasPro() ) {
306 return $config;
307 }
308
309 if ( ! isset( $config['promotionWidgets'] ) || ! is_array( $config['promotionWidgets'] ) ) {
310 $config['promotionWidgets'] = [];
311 }
312
313 $pro_widgets = [
314 [
315 'name' => 'tpg-slider-layout',
316 'title' => esc_html__( 'TPG - Slider Layout', 'the-post-grid' ),
317 'description' => esc_html__( 'TPG - Slider Layout', 'the-post-grid' ),
318 'icon' => 'eicon-post-slider tpg-grid-icon tss-promotional-element',
319 'categories' => '[ "the-post-grid-elements" ]',
320 ],
321 [
322 'name' => 'tpg-category-block',
323 'title' => esc_html__( 'TPG - Category Block', 'the-post-grid' ),
324 'description' => esc_html__( 'TPG - Category Block', 'the-post-grid' ),
325 'icon' => 'eicon-folder-o tpg-grid-icon tss-promotional-element',
326 'categories' => '[ "the-post-grid-elements" ]',
327 ]
328 ];
329
330 $config['promotionWidgets'] = array_merge( $config['promotionWidgets'], $pro_widgets );
331
332 return $config;
333 }
334 }
335 endif;
336