PluginProbe
Depicter — Popup & Slider Builder / 1.2.0
Depicter — Popup & Slider Builder v1.2.0
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 / Front / Assets.php

Assets.php in Depicter — Popup & Slider Builder 1.2.0, at app/src/Front/Assets.php

221 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Front;
3
4
5 use Averta\Core\Utility\Arr;
6
7
8 class Assets
9 {
10 /**
11 * @var string
12 */
13 private $baseAssetsUrl = '';
14
15
16 public function bootstrap()
17 {
18 $this->baseAssetsUrl = \Depicter::core()->assets()->getUrl();
19
20 add_action('wp_enqueue_scripts', [ $this, 'enqueueAssets' ]);
21 }
22
23 /**
24 * Retrieves a list of styles based on given group
25 *
26 * @param string|array $group A group name or list of groups in array
27 *
28 * @return array
29 */
30 public function getStyles( $group = 'common' )
31 {
32 $assets = $this->getStylesDictionary();
33 return $this->getAssetFromList( $group, $assets );
34 }
35
36 /**
37 * Retrieves a list of scripts based on given group
38 *
39 * @param string|array $group A group name or list of groups in array
40 *
41 * @return array
42 */
43 public function getScripts( $group = 'player' )
44 {
45 $assets = $this->getScriptsDictionary();
46 return $this->getAssetFromList( $group, $assets );
47 }
48
49 /**
50 * Enqueues required styles and scripts for a document
51 *
52 * @return void
53 */
54 public function enqueueAssets(){
55
56 if( ! apply_filters('depicter/font/enqueue/assets', true ) ){
57 return;
58 }
59
60 // Enqueue scripts.
61 $this->enqueueScripts('player');
62
63 // Enqueue styles.
64 $this->enqueueStyles('common');
65 }
66
67 /**
68 * Enqueues a list of styles based on given group
69 *
70 * @param string|array $group A group name or list of groups in array
71 *
72 * @return array
73 */
74 public function enqueueStyles( $group = 'common' )
75 {
76 $styleUrls = $this->getStyles( $group );
77
78 foreach ( $styleUrls as $styleId => $styleUrl ) {
79 \Depicter::core()->assets()->enqueueStyle( $styleId, $styleUrl );
80 }
81
82 return $styleUrls;
83 }
84
85 /**
86 * Enqueues a list of scripts based on given group
87 *
88 * @param string|array $group A group name or list of groups in array
89 *
90 * @return array
91 */
92 public function enqueueScripts( $group = 'player', $inFooter = true )
93 {
94 $scriptUrls = $this->getScripts( $group );
95 foreach ( $scriptUrls as $scriptId => $scriptUrl ){
96 \Depicter::core()->assets()->enqueueScript( $scriptId, $scriptUrl, [], $inFooter );
97 }
98
99 return $scriptUrls;
100 }
101
102 /**
103 * Registers a list of styles based on given group
104 *
105 * @param string|array $group A group name or list of groups in array
106 *
107 * @return array
108 */
109 public function registerStyles( $group = 'common' )
110 {
111 $styleUrls = $this->getStyles( $group );
112
113 foreach ( $styleUrls as $styleId => $styleUrl ) {
114 wp_enqueue_style( $styleId, $styleUrl, [], false, false );
115 }
116
117 return $styleUrls;
118 }
119
120 /**
121 * Registers a list of scripts based on given group
122 *
123 * @param string|array $group A group name or list of groups in array
124 *
125 * @return array
126 */
127 public function registerScripts( $group = 'player' )
128 {
129 $scriptUrls = $this->getScripts( $group );
130 foreach ( $scriptUrls as $scriptId => $scriptUrl ){
131 wp_enqueue_script( $scriptId, $scriptUrl, [], false,false );
132 }
133
134 return $scriptUrls;
135 }
136
137 /**
138 * Searches for group(s) in list of given assets and returns result in a list
139 *
140 * @param string|array $group A group name or list of groups in array
141 * @param array $assets
142 *
143 * @return array
144 */
145 protected function getAssetFromList( $group = 'common', $assets = [] )
146 {
147 if( empty( $group ) ){
148 return $assets;
149 }
150
151 if( is_array( $group ) ){
152 if( count( $group ) > 1 ){
153 $result = [];
154 foreach ( $group as $groupKey ){
155 if( $value = Arr::searchKeyDeep( $assets, $groupKey ) ){
156 if( is_string( $value ) ){
157 $result[ $groupKey ] = $value;
158 } else {
159 $result = $result + $value;
160 }
161 }
162 }
163 return $result;
164 }
165 }
166
167 $group = (string) $group;
168 $result = [];
169
170 if( $value = Arr::searchKeyDeep( $assets, $group ) ){
171 if( is_string( $value ) ){
172 $result = [ $group => $value ];
173 } elseif( is_array( $value ) ) {
174 $result = $value;
175 }
176 }
177
178 return $result;
179 }
180
181 /**
182 * Full list of front styles
183 *
184 * @return array
185 */
186 protected function getStylesDictionary()
187 {
188 $stylesDictionary = [
189 'situational' => [
190 'minireset' => $this->baseAssetsUrl . '/resources/styles/frontend/reset.min.css',
191 'depicter-preview-style' => $this->baseAssetsUrl . '/resources/styles/player/preview.css'
192 ],
193 'common' => [
194 'depicter-front-common' => $this->baseAssetsUrl . '/resources/styles/player/depicter.css'
195 ]
196 ];
197
198 return $stylesDictionary;
199 }
200
201 /**
202 * Full list of front scripts
203 *
204 * @return array
205 */
206 protected function getScriptsDictionary()
207 {
208 $scriptsDictionary = [
209 'player' => [
210 'depicter-player' => $this->baseAssetsUrl . '/resources/scripts/player/depicter.js'
211 ],
212 'widget' => [
213 'depicter-widget' => $this->baseAssetsUrl . '/resources/scripts/widgets/elementor-widget.js'
214 ]
215 ];
216
217 return $scriptsDictionary;
218 }
219
220 }
221