PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Modules / Bricks / widget.php

widget.php in Depicter — Popup & Slider Builder trunk, at app/src/Modules/Bricks/widget.php

100 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Modules\Bricks;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 class Widget extends \Bricks\Element {
9
10 // Element properties
11 public $category = 'general';
12
13 public $name = 'depicter';
14
15 public $icon = 'ti-layout-slider-alt';
16
17 public $css_selector = '.depicter';
18
19 public $scripts = []; // Script(s) run when element is rendered on frontend or updated in builder
20
21 // Return localised element label
22 public function get_label() {
23 return esc_html__( 'Depicter', 'depicter' );
24 }
25
26 // Set builder control groups
27 public function set_control_groups() {
28
29 $this->control_groups['sliders_list'] = [
30 'title' => esc_html__( 'Sliders List', 'depicter' ),
31 'tab' => 'content',
32 ];
33 }
34
35 // Set builder controls
36 public function set_controls() {
37
38 $this->controls['slider_id'] = [
39 'tab' => 'content',
40 'group' => 'sliders_list',
41 'label' => esc_html__( 'Select Slider', 'depicter' ),
42 'type' => 'select',
43 'options' => $this->getSlidersList(),
44 'inline' => true,
45 'clearable' => false,
46 'pasteStyles' => false,
47 'default' => '0',
48 'rerender' => true,
49 ];
50 }
51
52 // Enqueue element styles and scripts
53 public function enqueue_scripts() {
54
55 $styles = \Depicter::front()->assets()->enqueueStyles();
56 foreach ( $styles as $key => $style ) {
57 wp_enqueue_style( $key );
58 }
59
60 if ( ( defined('REST_REQUEST') && REST_REQUEST ) || ( isset( $_GET['bricks'] ) && $_GET['bricks'] == 'run' ) ) {
61 $scripts = \Depicter::front()->assets()->enqueueScripts(['player', 'iframe-resizer']);
62 } else {
63 $scripts = \Depicter::front()->assets()->enqueueScripts();
64 }
65
66 foreach ( $scripts as $key => $script ) {
67 wp_enqueue_script( $key );
68 }
69 }
70
71 public function getSlidersList() {
72 $list = [
73 '0' => __( 'Select Slider', 'depicter' )
74 ];
75 $documents = \Depicter::documentRepository()->select( ['id', 'name'] )->orderBy('modified_at', 'DESC')->findAll()->get();
76 $documents = $documents ? $documents->toArray() : [];
77 foreach( $documents as $document ) {
78 $list[ "#" . $document['id'] ] = "[#{$document['id']}]: " . $document['name'];
79 }
80 return $list;
81 }
82
83 // Render element HTML
84 public function render() {
85 if ( $this->settings['slider_id'] ) {
86 $sliderID = ltrim( $this->settings['slider_id'], '#' );
87 if ( ( defined('REST_REQUEST') && REST_REQUEST ) || ( isset( $_GET['bricks'] ) && $_GET['bricks'] == 'run' ) ) {
88 $iframeID = "sliderIframe-" . $sliderID;
89 $iframeURL = admin_url('admin-ajax.php') . '?action=depicter-document-preview&depicter-csrf=' . \Depicter::csrf()->getToken( \Depicter\Security\CSRF::EDITOR_ACTION ) . '&ID=' . $sliderID . '&status=draft|publish&gutenberg=true';
90 echo '<iframe id="' . esc_attr( $iframeID ) . '" style="width: 1px;min-width: 100%;" src="' . esc_url( $iframeURL ) . '"></iframe>';
91 echo "<script>iFrameResize({}, '#sliderIframe-" . esc_js( $sliderID ) . "')</script>";
92 } else {
93 echo \Depicter::front()->render()->document( $sliderID );
94 }
95 } else {
96 echo esc_html__('Please select a Depicter slider','depicter' );
97 }
98 }
99 }
100