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