PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.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
← All changes | app/src/Front/Assets.php +86 -21 1.3.01.9.2 View file →
@@ -2,8 +2,9 @@
2 2 namespace Depicter\Front;
3 3
4 4
5 5 use Averta\Core\Utility\Arr;
6 +use Averta\WordPress\Utility\Sanitize;
6 7
7 8
8 9 class Assets
9 10 {
@@ -20,9 +21,8 @@
20 21
21 22 public function bootstrap()
22 23 {
23 24 $this->baseAssetsUrl = \Depicter::core()->assets()->getUrl();
24 - // add_action('wp_enqueue_scripts', [ $this, 'enqueueAssets' ]);
25 25 }
26 26
27 27 /**
28 28 * Retrieves a list of styles based on given group
@@ -50,26 +50,8 @@
50 50 return $this->getAssetFromList( $group, $assets );
51 51 }
52 52
53 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 54 * Enqueues a list of styles based on given group
73 55 *
74 56 * @param string|array $group A group name or list of groups in array
75 57 *
@@ -79,11 +61,13 @@
79 61 {
80 62 $styleUrls = $this->getStyles( $group );
81 63
82 64 foreach ( $styleUrls as $styleId => $styleUrl ) {
83 - wp_enqueue_style( $styleId, $styleUrl, [], $this->version );
65 + \Depicter::core()->assets()->enqueueStyle( $styleId, $styleUrl, [] );
84 66 }
85 67
68 + do_action( 'depicter/after/enqueue/styles', $styleUrls );
69 +
86 70 return $styleUrls;
87 71 }
88 72
89 73 /**
@@ -97,11 +81,13 @@
97 81 {
98 82 $scriptUrls = $this->getScripts( $group );
99 83
100 84 foreach ( $scriptUrls as $scriptId => $scriptUrl ){
101 - wp_enqueue_script( $scriptId, $scriptUrl, [], $this->version ,$inFooter );
85 + \Depicter::core()->assets()->enqueueScript( $scriptId, $scriptUrl, [], $inFooter );
102 86 }
103 87
88 + do_action( 'depicter/after/enqueue/scripts', $scriptUrls );
89 +
104 90 return $scriptUrls;
105 91 }
106 92
107 93 /**
@@ -171,8 +157,77 @@
171 157 return $cssLinksToEnqueue;
172 158 }
173 159
174 160 /**
161 + * Enqueues custom styles of a document
162 + *
163 + * @param int $documentID
164 + * @param bool $isPrivilegedUser
165 + *
166 + * @return void
167 + */
168 + public function enqueueCustomAssets( $documentID, $isPrivilegedUser = null ){
169 + $isPrivilegedUser = is_null( $isPrivilegedUser ) ? \Depicter::authorization()->currentUserCanPublishDocument() : $isPrivilegedUser;
170 +
171 + if ( $isPrivilegedUser ) {
172 + $this->enqueueCustomGoogleFonts( $documentID );
173 + } else {
174 + $this->enqueueCustomStyles( $documentID );
175 + }
176 +
177 + do_action( 'depicter/after/enqueue/styles/' . $documentID );
178 + }
179 +
180 + /**
181 + * Enqueues styles and scripts of a document
182 + *
183 + * @param int $documentID
184 + * @param bool $isPrivilegedUser
185 + *
186 + * @return void
187 + */
188 + public function enqueueAssets( $documentID, $isPrivilegedUser = null ){
189 + $isPrivilegedUser = is_null( $isPrivilegedUser ) ? \Depicter::authorization()->currentUserCanPublishDocument() : $isPrivilegedUser;
190 +
191 + if ( ! did_action( 'depicter/after/enqueue/styles' ) ) {
192 + $this->enqueueStyles();
193 + }
194 +
195 + if ( !did_action('depicter/after/enqueue/styles/' . $documentID ) ) {
196 + $this->enqueueCustomAssets( $documentID, $isPrivilegedUser );
197 + }
198 +
199 + if ( ! did_action( 'depicter/after/enqueue/scripts' ) ) {
200 + $this->enqueueScripts();
201 + }
202 + }
203 +
204 + /**
205 + * Print media preload tags of a document if exists
206 + *
207 + * @param int $documentID
208 + *
209 + * @return void
210 + */
211 + public function printPreloadTags( $documentID ) {
212 + if( false !== $preloadTags = \Depicter::cache('document')->get( $documentID . '_preload_tags' ) ){
213 + echo Sanitize::html( $preloadTags );
214 + }
215 + }
216 +
217 + /**
218 + *
219 + * @param int $documentID
220 + *
221 + * @return void
222 + */
223 + public function enqueuePreloadTags( $documentID ) {
224 + add_action( 'wp_head', function () use ( $documentID ) {
225 + $this->printPreloadTags( $documentID );
226 + }, 10 );
227 + }
228 +
229 + /**
175 230 * Searches for group(s) in list of given assets and returns result in a list
176 231 *
177 232 * @param string|array $group A group name or list of groups in array
178 233 * @param array $assets
@@ -227,8 +282,9 @@
227 282 'minireset' => $this->baseAssetsUrl . '/resources/styles/frontend/reset.min.css',
228 283 'depicter-preview-style' => $this->baseAssetsUrl . '/resources/styles/player/preview.css'
229 284 ],
230 285 'common' => [
286 + 'depicter-front-pre' => $this->baseAssetsUrl . '/resources/styles/player/depicter-pre.css',
231 287 'depicter--front-common' => $this->baseAssetsUrl . '/resources/styles/player/depicter.css'
232 288 ]
233 289 ];
234 290
@@ -242,13 +298,22 @@
242 298 */
243 299 protected function getScriptsDictionary()
244 300 {
245 301 $scriptsDictionary = [
302 + 'injector' => [
303 + 'depicter--injector' => $this->baseAssetsUrl . '/resources/scripts/player/injector.js'
304 + ],
246 305 'player' => [
247 306 'depicter--player' => $this->baseAssetsUrl . '/resources/scripts/player/depicter.js'
248 307 ],
249 308 'widget' => [
250 309 'depicter-widget' => $this->baseAssetsUrl . '/resources/scripts/widgets/elementor-widget.js'
310 + ],
311 + 'iframe-resizer' => [
312 + 'depicter-iframe-resizer' => $this->baseAssetsUrl . '/resources/scripts/admin/iframeResizer.min.js'
313 + ],
314 + 'iframe-resizer-content' => [
315 + 'depicter-iframe-resizer-content' => $this->baseAssetsUrl . '/resources/scripts/admin/iframeResizer.contentWindow.min.js'
251 316 ]
252 317 ];
253 318
254 319 return $scriptsDictionary;