PluginProbe
Depicter — Popup & Slider Builder / 1.3.0
Depicter — Popup & Slider Builder v1.3.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.3.0, at app/src/Front/Assets.php

258 lines 5.5 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 * @var string
17 */
18 private $version = DEPICTER_VERSION;
19
20
21 public function bootstrap()
22 {
23 $this->baseAssetsUrl = \Depicter::core()->assets()->getUrl();
24 // add_action('wp_enqueue_scripts', [ $this, 'enqueueAssets' ]);
25 }
26
27 /**
28 * Retrieves a list of styles based on given group
29 *
30 * @param string|array $group A group name or list of groups in array
31 *
32 * @return array
33 */
34 public function getStyles( $group = 'common' )
35 {
36 $assets = $this->getStylesDictionary();
37 return $this->getAssetFromList( $group, $assets );
38 }
39
40 /**
41 * Retrieves a list of scripts based on given group
42 *
43 * @param string|array $group A group name or list of groups in array
44 *
45 * @return array
46 */
47 public function getScripts( $group = 'player' )
48 {
49 $assets = $this->getScriptsDictionary();
50 return $this->getAssetFromList( $group, $assets );
51 }
52
53 /**
54 * Enqueues required styles and scripts for a document
55 *
56 * @return void
57 */
58 public function enqueueAssets(){
59
60 if( ! apply_filters('depicter/font/enqueue/assets', true ) ){
61 return;
62 }
63
64 // Enqueue scripts.
65 $this->enqueueScripts('player');
66
67 // Enqueue styles.
68 $this->enqueueStyles('common');
69 }
70
71 /**
72 * Enqueues a list of styles based on given group
73 *
74 * @param string|array $group A group name or list of groups in array
75 *
76 * @return array
77 */
78 public function enqueueStyles( $group = 'common' )
79 {
80 $styleUrls = $this->getStyles( $group );
81
82 foreach ( $styleUrls as $styleId => $styleUrl ) {
83 wp_enqueue_style( $styleId, $styleUrl, [], $this->version );
84 }
85
86 return $styleUrls;
87 }
88
89 /**
90 * Enqueues a list of scripts based on given group
91 *
92 * @param string|array $group A group name or list of groups in array
93 *
94 * @return array
95 */
96 public function enqueueScripts( $group = 'player', $inFooter = true )
97 {
98 $scriptUrls = $this->getScripts( $group );
99
100 foreach ( $scriptUrls as $scriptId => $scriptUrl ){
101 wp_enqueue_script( $scriptId, $scriptUrl, [], $this->version ,$inFooter );
102 }
103
104 return $scriptUrls;
105 }
106
107 /**
108 * Retrieves a list of custom styles for given slider IDs
109 *
110 * @param string|array $documentIDs List of slider IDs for slugs
111 *
112 * @return array
113 */
114 public function getCustomStyles( $documentIDs )
115 {
116 if( empty( $documentIDs ) ){
117 return [];
118 }
119
120 if( $documentIDs = \Depicter::document()->getID( $documentIDs ) ){
121 $documentIDs = (array) $documentIDs;
122 $cssLinksToEnqueue = [];
123
124 foreach( $documentIDs as $documentID ){
125 if( false !== $cssLinkToEnqueue = \Depicter::cache('document')->get( $documentID . '_css_files' ) ){
126 $cssLinksToEnqueue = $cssLinksToEnqueue + $cssLinkToEnqueue;
127 }
128 }
129
130 return $cssLinksToEnqueue ;
131 }
132
133 return [];
134 }
135
136 /**
137 * Enqueues a list of custom styles based on given document IDs
138 *
139 * @param string|array $documentIDs List of slider IDs for slugs
140 *
141 * @return array
142 */
143 public function enqueueCustomStyles( $documentIDs )
144 {
145 $cssLinksToEnqueue = $this->getCustomStyles( $documentIDs );
146
147 foreach( $cssLinksToEnqueue as $cssId => $cssLink ){
148 \Depicter::core()->assets()->enqueueStyle( $cssId, $cssLink );
149 }
150
151 return $cssLinksToEnqueue;
152 }
153
154 /**
155 * Enqueues custom google fonts for given document IDs
156 *
157 * @param string|array $documentIDs List of slider IDs for slugs
158 *
159 * @return array
160 */
161 public function enqueueCustomGoogleFonts( $documentIDs )
162 {
163 $cssLinksToEnqueue = $this->getCustomStyles( $documentIDs );
164
165 foreach( $cssLinksToEnqueue as $cssId => $cssLink ){
166 if ( false !== strpos( $cssId, 'google-font' ) ) {
167 \Depicter::core()->assets()->enqueueStyle( $cssId, $cssLink );
168 }
169 }
170
171 return $cssLinksToEnqueue;
172 }
173
174 /**
175 * Searches for group(s) in list of given assets and returns result in a list
176 *
177 * @param string|array $group A group name or list of groups in array
178 * @param array $assets
179 *
180 * @return array
181 */
182 protected function getAssetFromList( $group = 'common', $assets = [] )
183 {
184 if( empty( $group ) ){
185 return $assets;
186 }
187
188 if( is_array( $group ) ){
189 if( count( $group ) > 1 ){
190 $result = [];
191 foreach ( $group as $groupKey ){
192 if( $value = Arr::searchKeyDeep( $assets, $groupKey ) ){
193 if( is_string( $value ) ){
194 $result[ $groupKey ] = $value;
195 } else {
196 $result = $result + $value;
197 }
198 }
199 }
200 return $result;
201 }
202 }
203
204 $group = (string) $group;
205 $result = [];
206
207 if( $value = Arr::searchKeyDeep( $assets, $group ) ){
208 if( is_string( $value ) ){
209 $result = [ $group => $value ];
210 } elseif( is_array( $value ) ) {
211 $result = $value;
212 }
213 }
214
215 return $result;
216 }
217
218 /**
219 * Full list of front styles
220 *
221 * @return array
222 */
223 protected function getStylesDictionary()
224 {
225 $stylesDictionary = [
226 'situational' => [
227 'minireset' => $this->baseAssetsUrl . '/resources/styles/frontend/reset.min.css',
228 'depicter-preview-style' => $this->baseAssetsUrl . '/resources/styles/player/preview.css'
229 ],
230 'common' => [
231 'depicter--front-common' => $this->baseAssetsUrl . '/resources/styles/player/depicter.css'
232 ]
233 ];
234
235 return $stylesDictionary;
236 }
237
238 /**
239 * Full list of front scripts
240 *
241 * @return array
242 */
243 protected function getScriptsDictionary()
244 {
245 $scriptsDictionary = [
246 'player' => [
247 'depicter--player' => $this->baseAssetsUrl . '/resources/scripts/player/depicter.js'
248 ],
249 'widget' => [
250 'depicter-widget' => $this->baseAssetsUrl . '/resources/scripts/widgets/elementor-widget.js'
251 ]
252 ];
253
254 return $scriptsDictionary;
255 }
256
257 }
258