PluginProbe
Depicter — Popup & Slider Builder / 1.6.2
Depicter — Popup & Slider Builder v1.6.2
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 / WPBakery / module.php

module.php in Depicter — Popup & Slider Builder 1.6.2, at app/src/Modules/WPBakery/module.php

178 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\Modules\WPBakery;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 class Module {
10
11 /**
12 * Class constructor
13 */
14 public function __construct() {
15 if ( function_exists( 'vc_map' ) ) {
16 $this->map_vc_shortcodes();
17
18 vc_add_shortcode_param( 'depicter_slider_buttons', [ $this, 'slider_buttons_markup' ] );
19 add_action( 'vc_edit_form_fields_after_render', [ $this, 'add_scripts' ] );
20 }
21 }
22
23 /**
24 * Add depicter shortcode to wpbakery
25 *
26 * @return void
27 */
28 public function map_vc_shortcodes() {
29
30 vc_map([
31 'name' => __( 'Depicter', 'depicter' ),
32 'base' => 'depicter',
33 'category' => __( 'Content', 'depicter' ),
34 'description' => __( 'Make animated and interactive slider', 'depicter' ),
35 'icon' => \Depicter::core()->assets()->getUrl() . '/resources/images/svg/logo-without-text.svg',
36 'params' => $this->get_fields()
37 ]);
38 }
39
40 /**
41 * get fields
42 *
43 * @return array
44 * @throws \Exception
45 */
46 public function get_fields() {
47
48 $list = [
49 __( 'Select Slider', 'depicter' ) => 0
50 ];
51 $documents = \Depicter::documentRepository()->select( ['id', 'name', 'status'] )->orderBy('modified_at', 'DESC')->findAll()->get();
52 $documents = $documents ? $documents->toArray() : [];
53 foreach( $documents as $document ) {
54 $list[ "[#{$document['id']}]: " . $document['name'] ] = $document['id'];
55 }
56
57 $fields = [
58 [
59 'type' => 'dropdown',
60 'class' => '',
61 'admin_label' => true,
62 'heading' => __( 'Select Slider', 'depicter' ),
63 'param_name' => 'id',
64 'value' => $list,
65 ]
66 ];
67
68 foreach( $documents as $document ) {
69
70 $fields[] = [
71 'type' => 'depicter_slider_buttons',
72 'class' => '',
73 'param_name' => 'slider_control_buttons_' . $document['id'],
74 'isPublishedBefore' => \Depicter::documentRepository()->isPublishedBefore( $document['id'] ),
75 'documentStatus' => $document['status'],
76 'documentID' => $document['id'],
77 'dependency' => [
78 'element' => 'id',
79 'value' => 18
80 ]
81 ];
82 }
83
84 return $fields;
85 }
86
87 /**
88 * Add script to the end of editor fields after render
89 *
90 * @return void
91 */
92 public function add_scripts() {
93 if ( empty( $_POST['tag'] ) || $_POST['tag'] != 'depicter' ) {
94 return;
95 }
96
97 echo '<script type="text/javascript">
98 var $sliderButtons = document.querySelectorAll(\'[data-param_type="depicter_slider_buttons"]\');
99 document.querySelector(\'[data-vc-shortcode="depicter"]\').querySelector("select").addEventListener( "change", function(){
100 if ( this.value != 0 ) {
101 $sliderButtons.forEach(function(el, index){ el.style.display = \'none\';});
102 document.querySelector(\'[data-vc-shortcode-param-name="slider_control_buttons_\' +this.value+ \'"]\').style.display = "block";
103 }
104 });
105 $sliderButtons.forEach(function(el, index){ el.style.display = \'none\';});
106 var id = document.querySelector(\'[data-vc-shortcode="depicter"]\').querySelector("select").value;
107 if ( id != "0" ) {
108 document.querySelector(\'[data-vc-shortcode-param-name="slider_control_buttons_\' +id+ \'"]\').style.display = "block";
109 }
110
111 document.querySelectorAll(".depicter-edit-slider").forEach(function(el, index){
112 el.addEventListener( "click", function(){
113 var id = document.querySelector(\'[data-vc-shortcode="depicter"]\').querySelector("select").value;
114 var editorUrl = depicterParams.editorUrl.replace( \'document=1\', \'document=\' + id );
115 window.open(editorUrl);
116 });
117 });
118
119 $sliderButtons.forEach(function(el, index){
120 var $publishButton = el.querySelector(".depicter-publish-slider:not([disabled])");
121 if ( $publishButton ) {
122 $publishButton.addEventListener( "click", function(event){
123 event.target.querySelector(".btn-label").style.display = "none";
124 event.target.querySelector(".depicter-state-icon").style.display = "inline-block";
125
126 var id = document.querySelector(\'[data-vc-shortcode="depicter"]\').querySelector("select").value;
127 var data = new FormData();
128 data.append(\'ID\', id);
129 data.append(\'status\', \'published\');
130
131 fetch( depicterParams.ajaxUrl + "?action=depicter/document/store", {
132 method: \'post\',
133 body: data,
134 headers: {
135 \'X-DEPICTER-CSRF\': depicterParams.token
136 }
137 })
138 .then((response) => response.json())
139 .then((data) => {
140 if (data.hits) {
141 event.target.disabled = "true";
142 event.target.querySelector(".btn-label").innerHTML = depicterParams.publishedText;
143 var $depicterNoticeWrapper = document.querySelector(".depicter-notice-wrapper");
144 if ( $depicterNoticeWrapper ) {
145 $depicterNoticeWrapper.style.display = "none";
146 }
147 }
148 event.target.querySelector(".btn-label").style.display = "inline-block";
149 event.target.querySelector(".depicter-state-icon").style.display = "none";
150 el.querySelector(".depicter-notice-txts").style.display = "none";
151 }).catch((error) => {
152 console.error(error);
153 });
154 });
155
156 el.querySelector(".btn-label").addEventListener( "click", function(event) {
157 event.target.parentNode.click();
158 });
159 }
160 });
161
162 </script>';
163 }
164
165 /**
166 * Get slider buttons control field markup
167 *
168 * @param array $settings
169 * @param string $value
170 * @return string
171 */
172 public function slider_buttons_markup( $settings, $value ) {
173 return \Depicter::view('admin/notices/builders-draft-notice')->with('view_args', $settings)->toString();
174 }
175 }
176
177 new Module();
178