PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.15.2
Shortcodes and extra features for Phlox theme v2.15.2
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / elementor / modules / theme-builder / theme-page-document.php
auxin-elements / includes / elementor / modules / theme-builder Last commit date
classes 3 years ago module.php 3 years ago theme-page-document.php 4 years ago
theme-page-document.php
389 lines
1 <?php
2 namespace Auxin\Plugin\CoreElements\Elementor\Modules\ThemeBuilder;
3
4 use Elementor\Controls_Manager;
5 use Elementor\Core\DocumentTypes\Post;
6 use Elementor\Modules\PageTemplates\Module as Single;
7 use Elementor\TemplateLibrary\Source_Local;
8 use Elementor\Modules\Library\Documents\Library_Document;
9 use Auxin\Plugin\CoreElements\Elementor\Modules\ThemeBuilder\Module;
10 use Elementor\Plugin;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly
14 }
15
16 abstract class Theme_Document extends Library_Document {
17
18 const LOCATION_META_KEY = '_elementor_location';
19
20 public function get_location_label() {
21 $location = $this->get_location();
22 $locations_settings = Module::instance()->get_locations_manager()->get_location( $location );
23 $label = '';
24 $is_section_doc_type = 'section' === $this->get_name();
25
26 if ( $location ) {
27 if ( $is_section_doc_type ) {
28 $label .= isset( $locations_settings['label'] ) ? $locations_settings['label'] : $location;
29 }
30 }
31
32 $supported = true;
33
34 if ( $is_section_doc_type ) {
35 if ( $location && ! $locations_settings ) {
36 $supported = false;
37 }
38 } elseif ( ! $location || ! $locations_settings ) {
39 $supported = false;
40 }
41
42 if ( ! $supported ) {
43 $label .= ' (' . __( 'Unsupported', 'auxin-elements' ) . ')';
44 }
45
46 return $label;
47 }
48
49 public function before_get_content() {
50 $preview_manager = Module::instance()->get_preview_manager();
51 $preview_manager->switch_to_preview_query();
52 }
53
54 public function after_get_content() {
55 $preview_manager = Module::instance()->get_preview_manager();
56 $preview_manager->restore_current_query();
57 }
58
59 public function get_content( $with_css = false ) {
60 $this->before_get_content();
61 $content = parent::get_content( $with_css );
62 $this->after_get_content();
63
64 return $content;
65 }
66
67 public function print_content() {
68 $plugin = Plugin::instance();
69
70 if ( $plugin->preview->is_preview_mode( get_the_ID() ) ) {
71 echo $plugin->preview->builder_wrapper( '' );
72 } else {
73 echo $this->get_content();
74 }
75 }
76
77 public static function get_preview_as_default() {
78 return '';
79 }
80
81 public static function get_preview_as_options() {
82 return [];
83 }
84
85 public function get_container_attributes() {
86 $attributes = parent::get_container_attributes();
87
88 if ( is_singular() ) {
89 $post_classes = get_post_class( '', get_the_ID() );
90
91 $attributes['class'] .= ' ' . implode( ' ', $post_classes );
92 }
93
94 return $attributes;
95 }
96
97 /**
98 * @static
99 * @since 2.0.0
100 * @access public
101 *
102 * @return string
103 */
104 public function get_edit_url() {
105 $url = parent::get_edit_url();
106
107 if ( isset( $_GET['action'] ) && 'elementor_new_post' === $_GET['action'] ) {
108 $url .= '#library';
109 }
110
111 return $url;
112
113 }
114
115 protected function register_controls() {
116 parent::register_controls();
117
118 // $this->start_controls_section(
119 // 'preview_settings',
120 // [
121 // 'label' => __( 'Preview Settings', 'auxin-elements' ),
122 // 'tab' => Controls_Manager::TAB_SETTINGS,
123 // ]
124 // );
125
126 // $this->add_control(
127 // 'preview_type',
128 // [
129 // 'label' => __( 'Preview Dynamic Content as', 'auxin-elements' ),
130 // 'label_block' => true,
131 // 'type' => Controls_Manager::SELECT,
132 // 'default' => $this::get_preview_as_default(),
133 // 'groups' => $this::get_preview_as_options(),
134 // 'export' => false,
135 // ]
136 // );
137
138 // $this->add_control(
139 // 'preview_id',
140 // [
141 // 'type' => 'aux-query',
142 // 'label_block' => true,
143 // 'filter_type' => '',
144 // 'object_type' => '',
145 // 'separator' => 'none',
146 // 'export' => false,
147 // 'condition' => [
148 // 'preview_type!' => [
149 // '',
150 // 'search',
151 // ],
152 // ],
153 // ]
154 // );
155
156 // $this->add_control(
157 // 'preview_search_term',
158 // [
159 // 'label' => __( 'Search Term', 'auxin-elements' ),
160 // 'export' => false,
161 // 'condition' => [
162 // 'preview_type' => 'search',
163 // ],
164 // ]
165 // );
166
167 // $this->add_control(
168 // 'apply_preview',
169 // [
170 // 'type' => Controls_Manager::BUTTON,
171 // 'label' => __( 'Apply & Preview', 'auxin-elements' ),
172 // 'label_block' => true,
173 // 'show_label' => false,
174 // 'text' => __( 'Apply & Preview', 'auxin-elements' ),
175 // 'separator' => 'none',
176 // 'event' => 'elementorThemeBuilder:ApplyPreview',
177 // ]
178 // );
179
180 // $this->end_controls_section();
181 }
182
183 public function get_elements_raw_data( $data = null, $with_html_content = false ) {
184 $preview_manager = Module::instance()->get_preview_manager();
185
186 $preview_manager->switch_to_preview_query();
187
188 $editor_data = parent::get_elements_raw_data( $data, $with_html_content );
189
190 $preview_manager->restore_current_query();
191
192 return $editor_data;
193 }
194
195 public function render_element( $data ) {
196 $preview_manager = Module::instance()->get_preview_manager();
197
198 $preview_manager->switch_to_preview_query();
199
200 $render_html = parent::render_element( $data );
201
202 $preview_manager->restore_current_query();
203
204 return $render_html;
205 }
206
207 public function get_wp_preview_url() {
208 $preview_id = (int) $this->get_settings( 'preview_id' );
209 $post_id = $this->get_main_id();
210
211 list( $preview_category, $preview_object_type ) = array_pad( explode( '/', $this->get_settings( 'preview_type' ) ), 2, '' );
212
213 $home_url = trailingslashit( home_url() );
214
215 switch ( $preview_category ) {
216 case 'archive':
217 switch ( $preview_object_type ) {
218 case 'author':
219 if ( empty( $preview_id ) ) {
220 $preview_id = get_current_user_id();
221 }
222 $preview_url = get_author_posts_url( $preview_id );
223 break;
224 case 'date':
225 $preview_url = add_query_arg( 'year', date( 'Y' ), $home_url );
226 break;
227 }
228 break;
229 case 'search':
230 $preview_url = add_query_arg( 's', $this->get_settings( 'preview_search_term' ), $home_url );
231 break;
232 case 'taxonomy':
233 $term = get_term( $preview_id );
234
235 if ( $term && ! is_wp_error( $term ) ) {
236 $preview_url = get_term_link( $preview_id );
237 }
238
239 break;
240 case 'page':
241 switch ( $preview_object_type ) {
242 case 'home':
243 $preview_url = get_post_type_archive_link( 'post' );
244 break;
245 case 'front':
246 $preview_url = $home_url;
247 break;
248 case '404':
249 $preview_url = add_query_arg( 'p', '-1', $home_url );
250 break;
251 }
252 break;
253 case 'post_type_archive':
254 $post_type = $preview_object_type;
255 if ( post_type_exists( $post_type ) ) {
256 $preview_url = get_post_type_archive_link( $post_type );
257 }
258 break;
259 case 'single':
260 $post = get_post( $preview_id );
261 if ( $post ) {
262 $preview_url = get_permalink( $post );
263 }
264 break;
265 } // End switch().
266
267 if ( empty( $preview_url ) ) {
268 $preview_url = $this->get_permalink();
269 }
270
271 $query_args = [
272 'preview' => true,
273 'preview_nonce' => wp_create_nonce( 'post_preview_' . $post_id ),
274 'theme_template_id' => $post_id,
275 ];
276
277 $preview_url = set_url_scheme( add_query_arg( $query_args, $preview_url ) );
278 $preview_url = apply_filters( 'elementor/document/wp_preview_url', $preview_url, $this );
279
280 return $preview_url;
281 }
282
283 public function get_preview_as_query_args() {
284 $preview_id = (int) $this->get_settings( 'preview_id' );
285
286 list( $preview_category, $preview_object_type ) = array_pad( explode( '/', $this->get_settings( 'preview_type' ) ), 2, '' );
287
288 switch ( $preview_category ) {
289 case 'archive':
290 switch ( $preview_object_type ) {
291 case 'author':
292 if ( empty( $preview_id ) ) {
293 $preview_id = get_current_user_id();
294 }
295
296 $query_args = [
297 'author' => $preview_id,
298 ];
299 break;
300 case 'date':
301 $query_args = [
302 'year' => date( 'Y' ),
303 ];
304 break;
305 case 'recent_posts':
306 $query_args = [
307 'post_type' => 'post',
308 ];
309 break;
310 }
311 break;
312 case 'search':
313 $query_args = [
314 's' => $this->get_settings( 'preview_search_term' ),
315 ];
316 break;
317 case 'taxonomy':
318 $term = get_term( $preview_id );
319
320 if ( $term && ! is_wp_error( $term ) ) {
321 $query_args = [
322 'tax_query' => [
323 [
324 'taxonomy' => $term->taxonomy,
325 'terms' => [ $preview_id ],
326 'field' => 'id',
327 ],
328 ],
329 ];
330 }
331 break;
332 case 'page':
333 switch ( $preview_object_type ) {
334 case 'home':
335 $query_args = [];
336 break;
337 case 'front':
338 $query_args = [
339 'p' => get_option( 'page_on_front' ),
340 'post_type' => 'page',
341 ];
342 break;
343 case '404':
344 $query_args = [
345 'p' => -1,
346 ];
347 break;
348 }
349 break;
350 case 'post_type_archive':
351 $post_type = $preview_object_type;
352 if ( post_type_exists( $post_type ) ) {
353 $query_args = [
354 'post_type' => $post_type,
355 ];
356 }
357 break;
358 case 'single':
359 $post = get_post( $preview_id );
360 if ( ! $post ) {
361 break;
362 }
363
364 $query_args = [
365 'p' => $post->ID,
366 'post_type' => $post->post_type,
367 ];
368 } // End switch().
369
370 if ( empty( $query_args ) ) {
371 $query_args = [
372 'p' => $this->get_main_id(),
373 'post_type' => $this->get_main_post()->post_type,
374 ];
375 }
376
377 return $query_args;
378 }
379
380 public function get_location() {
381 $value = self::get_property( 'location' );
382 if ( ! $value ) {
383 $value = $this->get_main_meta( self::LOCATION_META_KEY );
384 }
385
386 return $value;
387 }
388 }
389