PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.5.4
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.5.4
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Elementor / Embedpress_Elementor_Integration.php
embedpress / EmbedPress / Elementor Last commit date
Widgets 1 month ago Elementor_Upsale.php 3 months ago Embedpress_Elementor_Integration.php 1 month ago
Embedpress_Elementor_Integration.php
1177 lines
1 <?php
2
3 namespace EmbedPress\Elementor;
4
5
6 (defined('ABSPATH')) or die("No direct script access allowed.");
7
8 use EmbedPress\Compatibility;
9 use EmbedPress\Elementor\Widgets\Embedpress_Calendar;
10 use EmbedPress\Elementor\Widgets\Embedpress_Document;
11 use EmbedPress\Elementor\Widgets\Embedpress_Elementor;
12 use EmbedPress\Elementor\Widgets\Embedpress_Pdf;
13 use EmbedPress\Elementor\Widgets\Embedpress_Pdf_Gallery;
14 use EmbedPress\Includes\Classes\Helper;
15
16 class Embedpress_Elementor_Integration
17 {
18
19 /**
20 * @since 2.4.2
21 */
22 public function init()
23 {
24 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
25 $e_blocks = isset($elements['elementor']) ? (array) $elements['elementor'] : [];
26 if (!empty($e_blocks['embedpress']) || !empty($e_blocks['embedpress-document']) || !empty($e_blocks['embedpress-pdf']) || !empty($e_blocks['embedpress-pdf-gallery'])) {
27 // Asset enqueuing now handled by AssetManager
28 add_action('elementor/elements/categories_registered', array($this, 'register_widget_categories'));
29 add_action('elementor/widgets/widgets_registered', array($this, 'register_widget'));
30 add_action('elementor/widgets/register', array($this, 'register_widget'));
31 add_filter('oembed_providers', [$this, 'addOEmbedProviders']);
32
33
34 //Just disabled rating and feedback
35 // if (Helper::get_options_value('turn_off_rating_help') || !is_plugin_active('embedpress-pro/embedpress-pro.php')) {
36 // add_action('elementor/editor/after_enqueue_scripts', [$this, 'elementor_upsale']);
37 // }
38 add_action('elementor/editor/after_enqueue_scripts', [$this, 'elementor_upsale']);
39 }
40
41 // AJAX handler for PDF Gallery thumbnail generation (must register early for admin-ajax.php)
42 // Uses Pdf_Thumbnail_Handler (no Elementor dependency) to avoid "Class Elementor\Widget_Base not found" fatal
43 if (!empty($e_blocks['embedpress-pdf-gallery']) || !isset($e_blocks['embedpress-pdf-gallery'])) {
44 add_action('wp_ajax_ep_generate_pdf_thumbnail', ['EmbedPress\Includes\Classes\Pdf_Thumbnail_Handler', 'ajax_generate_pdf_thumbnail']);
45 add_action('wp_ajax_ep_upload_pdf_thumbnail', ['EmbedPress\Includes\Classes\Pdf_Thumbnail_Handler', 'ajax_upload_pdf_thumbnail']);
46 }
47 }
48
49 /**
50 * Add elementor category
51 *
52 * @since 2.4.3
53 */
54 public function register_widget_categories($elements_manager)
55 {
56 $elements_manager->add_category(
57 'embedpress',
58 [
59 'title' => __('EmbedPress', 'embedpress'),
60 'icon' => 'font',
61 ],
62 1
63 );
64 }
65
66 /**
67 * Load elementor widget
68 *
69 * @param $widgets_manager
70 * @throws \Exception
71 * @since 2.4.2
72 */
73 public function register_widget($widgets_manager)
74 {
75 if (
76 did_action('elementor/widgets/widgets_registered') &&
77 did_action('elementor/widgets/register') // doing action
78 ) {
79 return;
80 }
81
82 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
83 $e_blocks = isset($elements['elementor']) ? (array) $elements['elementor'] : [];
84
85 if (method_exists($widgets_manager, 'register')) {
86 if (!empty($e_blocks['embedpress'])) {
87 $widgets_manager->register(new Embedpress_Elementor);
88 }
89 if (!empty($e_blocks['embedpress-document'])) {
90 $widgets_manager->register(new Embedpress_Document);
91 }
92
93 if (!empty($e_blocks['embedpress-pdf'])) {
94 $widgets_manager->register(new Embedpress_Pdf);
95 }
96 if (!isset($e_blocks['embedpress-pdf-gallery']) || !empty($e_blocks['embedpress-pdf-gallery'])) {
97 $widgets_manager->register(new Embedpress_Pdf_Gallery);
98 }
99 if (!empty($e_blocks['embedpress-calendar'])) {
100 $widgets_manager->register(new Embedpress_Calendar);
101 }
102 } else {
103 if (!empty($e_blocks['embedpress'])) {
104 $widgets_manager->register_widget_type(new Embedpress_Elementor);
105 }
106 if (!empty($e_blocks['embedpress-document'])) {
107 $widgets_manager->register_widget_type(new Embedpress_Document);
108 }
109
110 if (!empty($e_blocks['embedpress-pdf'])) {
111 $widgets_manager->register_widget_type(new Embedpress_Pdf);
112 }
113 if (!isset($e_blocks['embedpress-pdf-gallery']) || !empty($e_blocks['embedpress-pdf-gallery'])) {
114 $widgets_manager->register_widget_type(new Embedpress_Pdf_Gallery);
115 }
116 if (!empty($e_blocks['embedpress-calendar'])) {
117 $widgets_manager->register_widget_type(new Embedpress_Calendar);
118 }
119 }
120 }
121
122 /**
123 * Enqueue elementor assets
124 * @since 2.4.3
125 * Now handled by AssetManager
126 */
127 public function embedpress_enqueue_style()
128 {
129 // Assets are now handled by the centralized AssetManager
130 // This method is kept for backward compatibility
131 }
132
133 public function editor_enqueue_style()
134 {
135 // Assets are now handled by the centralized AssetManager
136 // This method is kept for backward compatibility
137 }
138
139 public function editor_enqueue_scripts() {}
140
141 public function addOEmbedProviders($providers)
142 {
143 if (Compatibility::isWordPress5() && !Compatibility::isClassicalEditorActive()) {
144 unset($providers['#https?://(.+\.)?wistia\.com/medias/.+#i'], $providers['#https?://(.+\.)?fast\.wistia\.com/embed/medias/.+#i\.jsonp']);
145 }
146
147 return $providers;
148 }
149
150 public function elementor_upsale()
151 {
152 ?>
153 <style>
154 :root {
155 /* Light Mode Variables */
156 --background-color: #FDFAFF;
157 --text-color: #0C0D0E;
158 --secondary-text-color: #5f6c7f;
159 --description-text-color: #5f6c7f;
160 --border-color: #ECEFF5;
161 --button-bg: #5b4e96;
162 --button-text: #ffffff;
163 --upgrade-bg: linear-gradient(181.32deg, #fffbf8 1.12%, #ffffff 98.95%);
164 --star-color: #b1b8c2;
165 --placeholder-text-color: #5f6c7f;
166 --submit-button-color: #5b4e96;
167 --form-control-backgound: #fff;
168 --upgrade-box-title-color: #1d2939;
169 }
170
171 @media (prefers-color-scheme: light) {
172 :root {
173 /* Light Mode Variables */
174 --background-color: #FDFAFF;
175 --text-color: #0C0D0E;
176 --secondary-text-color: #5f6c7f;
177 --description-text-color: #5f6c7f;
178 --border-color: #ECEFF5;
179 --button-bg: #5b4e96;
180 --button-text: #ffffff;
181 --upgrade-bg: linear-gradient(181.32deg, #fffbf8 1.12%, #ffffff 98.95%);
182 --star-color: #b1b8c2;
183 --placeholder-text-color: #5f6c7f;
184 --submit-button-color: #5b4e96;
185 --form-control-backgound: #fff;
186 --upgrade-box-title-color: #1d2939;
187
188 }
189 }
190
191 @media (prefers-color-scheme: dark) {
192 :root {
193 /* Dark Mode Variables */
194 --background-color: #1A1C1F;
195 --text-color: #ffffff;
196 --secondary-text-color: #CBCBD0;
197 --description-text-color: #fff;
198 --border-color: #272A2F;
199 --button-bg: #4b3293;
200 --button-text: #ffffff;
201 --upgrade-bg: linear-gradient(181.32deg, #1F2023 1.12%, #18191B 98.95%);
202 --star-color: #676D76;
203 --placeholder-text-color: #CBCBD0;
204 --submit-button-color: #fff;
205 --form-control-backgound: #1F2124;
206 --upgrade-box-title-color: #fff;
207
208
209 }
210 }
211
212 /* .elementor-panel .plugin-rating {
213 border-top: 2px solid #e6e8ea;
214 } */
215
216 /* Applying Variables */
217 .elementor-panel .rating-chat-content {
218 /* background-color: var(--background-color); */
219 /* border: 0.6px solid var(--border-color); */
220 color: var(--text-color);
221 }
222
223 .elementor-panel .plugin-rating h4 {
224 color: var(--text-color);
225 }
226
227 .elementor-panel .plugin-rating .chat-button {
228 background-color: var(--button-bg);
229 color: var(--button-text);
230 }
231
232 .elementor-panel .plugin-rating .upgrade-box {
233 background: var(--upgrade-bg);
234 border: 0.6px solid var(--border-color);
235 }
236
237 .elementor-panel p.thank-you-message {
238 color: var(--secondary-text-color);
239 }
240
241 .elementor-panel .plugin-rating .stars .star {
242 color: var(--star-color);
243 }
244
245
246 .elementor-panel .plugin-rating {
247 font-family: system-ui;
248 padding: 15px;
249 padding-top: 0;
250 }
251
252 .elementor-panel .rating-chat-content {
253 border-radius: 4px;
254 border-width: 0.6px;
255 gap: 12px;
256 padding: 15px 5px;
257 position: relative;
258 display: flex;
259 flex-direction: column;
260 overflow: hidden;
261 /* margin-top: 15px; */
262 }
263
264 /* .rating-chat-content::after {
265 content: "";
266 position: absolute;
267 top: -65px;
268 right: -65px;
269 width: 120px;
270 height: 120px;
271 background: radial-gradient(circle, rgb(121 62 255 / 14%) 20%, transparent 70%);
272 border-radius: 50%;
273 } */
274
275
276 /* .rating-chat-content::after{
277 content: '';
278 background: linear-gradient(175.54deg, rgba(81, 241, 255, 0.117) 19.13%, rgba(71, 58, 217, 0.132319) 22.57%, rgba(127, 22, 255, 0.2085) 39.66%, rgba(17, 1, 35, 0.3) 60.19%);
279 transform: rotate(60deg);
280 top: 0;
281 right: 0;
282 z-index: 1212;
283 width: 118.63550843535211px;
284 height: 208.14842708207777px;
285 position: absolute;
286 transform: rotate(60deg);
287 backdrop-filter: blur(20px);
288 } */
289
290
291 .elementor-panel .plugin-rating h4 {
292 font-size: 15px;
293 font-weight: 500;
294 }
295
296 .elementor-panel .plugin-rating .stars {
297 display: flex;
298 gap: 5px;
299 margin-bottom: 10px;
300 color: #FFFFFF;
301 }
302
303 .elementor-panel .plugin-rating .stars .star {
304 cursor: pointer;
305 width: 20px;
306 height: 20px;
307 }
308
309 .elementor-panel .plugin-rating .thank-you-msg-container {
310 padding: 15px;
311 border-radius: 8px;
312 text-align: left;
313 background: linear-gradient(181.32deg, #f5f3ff 1.12%, #ffffff 98.95%);
314 border: 0.6px solid #f4efec;
315 position: relative;
316 }
317
318 .elementor-panel .plugin-rating .thank-you-msg-container span.close-icon {
319 position: absolute;
320 top: 8px;
321 right: 8px;
322 }
323
324 .elementor-panel .plugin-rating .thank-you-msg-container span.close-icon svg {
325 height: 12px;
326 width: 12px;
327 cursor: pointer;
328 }
329
330 /* .elementor-panel .plugin-rating .thankyou-msg-container span.close-icon {
331 position: absolute;
332 top: 8px;
333 right: 8px;
334 } */
335
336 .elementor-panel .plugin-rating .thank-you-msg-container p.thank-you-message {
337 font-weight: 400;
338 color: #232c39;
339 margin-bottom: 8px;
340 font-size: 12px;
341 }
342
343 .elementor-panel .plugin-rating .thank-you-msg-container span.undo-review {
344 color: #5b4e96;
345 font-weight: 400;
346 text-decoration: none;
347 cursor: pointer !important;
348 }
349
350 .elementor-panel .plugin-rating .chat-button {
351 color: white;
352 border: none;
353 padding: 10px 20px;
354 border-radius: 5px;
355 cursor: pointer;
356 font-size: 14px;
357 display: flex;
358 align-items: center;
359 justify-content: center;
360 gap: 5px;
361 font-weight: 400;
362 width: 100%;
363 }
364
365 .elementor-panel .plugin-rating .chat-button svg {
366 width: 18px;
367 height: 18px;
368 }
369
370 .elementor-panel .plugin-rating .chat-button:hover {
371 background-color: #4b3293;
372 }
373
374 .elementor-panel .plugin-rating .upgrade-box {
375 padding: 15px;
376 margin-top: 15px;
377 border-radius: 8px;
378 text-align: left;
379 }
380
381 .elementor-panel .plugin-rating .upgrade-box h5 {
382 font-size: 14px;
383 margin-top: 0;
384 margin-bottom: 10px;
385 color: #1d2939;
386 color: #fff;
387 color: var(--upgrade-box-title-color);
388 font-weight: 600;
389 }
390
391 .elementor-panel .plugin-rating .upgrade-box p {
392 font-size: 12px;
393 color: var(--secondary-text-color);
394 margin-bottom: 12px;
395 font-weight: 400;
396 line-height: 1.6;
397 }
398
399 .elementor-panel .plugin-rating .upgrade-box .upgrade-link {
400 color: #ec6e00;
401 font-weight: 400;
402 text-decoration: none;
403 }
404
405 .elementor-panel .plugin-rating .upgrade-box .upgrade-link:hover {
406 text-decoration: underline;
407 }
408
409
410
411 .elementor-panel .thankyou-msg-container,
412 .elementor-panel .feedback-submit-container {
413 border-radius: 8px;
414 text-align: left;
415 position: relative;
416 margin-bottom: 10px;
417 }
418
419 .elementor-panel .thankyou-msg-container textarea.form-control,
420 .elementor-panel .feedback-submit-container textarea.form-control {
421 width: 100%;
422 background: var(--form-control-backgound);
423 outline: 1px solid var(--border-color);
424 margin-bottom: 10px;
425 border: none;
426 font-weight: 400;
427 font-size: 14px;
428 line-height: 1.6;
429 font-family: system-ui;
430 padding: 8px 8px;
431 }
432
433 .elementor-panel .thankyou-msg-container textarea.form-control::placeholder,
434 .elementor-panel .feedback-submit-container textarea.form-control::placeholder {
435 font-weight: 400;
436 font-size: 14px;
437 line-height: 1.6;
438 color: var(--placeholder-text-color);
439 font-family: system-ui;
440 }
441
442 .elementor-panel .thankyou-msg-container textarea:focus,
443 .elementor-panel .feedback-submit-container textarea:focus {
444 outline-color: #5b4e96;
445 box-shadow: none !important;
446 outline: 1px solid #5b4e96;
447 }
448
449 .elementor-panel .submit-button,
450 .elementor-panel .rating-button {
451 border-radius: 4px;
452 border-width: 1px;
453 width: 100%;
454 border: 1px solid #5b4e96;
455 color: var(--submit-button-color);
456 background: transparent;
457 cursor: pointer;
458 display: flex;
459 align-items: center;
460 justify-content: center;
461 padding: 12px 8px;
462
463 }
464
465 .elementor-panel .submit-button svg,
466 .elementor-panel .rating-button svg {
467 height: 18px;
468 width: 18px;
469 }
470
471 .elementor-panel .help-message {
472 font-weight: 500;
473 font-size: 15px;
474 line-height: 1.6;
475 letter-spacing: 0%;
476 margin-bottom: 10px;
477 margin-top: 0;
478 color: var(--text-color);
479 }
480
481 .elementor-panel p.form-description {
482 font-size: 14px;
483 margin-bottom: 12px;
484 font-family: system-ui;
485 color: var(--description-text-color);
486 line-height: 1.4;
487 }
488
489 .elementor-panel span.close-icon {
490 position: absolute;
491 top: 8px;
492 right: 8px;
493 }
494
495 .elementor-panel span.close-icon svg {
496 height: 12px;
497 width: 12px;
498 cursor: pointer;
499 }
500
501 .elementor-panel span.undo-review {
502 color: #5b4e96;
503 font-weight: 400;
504 text-decoration: none;
505 cursor: pointer;
506 }
507
508 .elementor-panel p.thank-you-message {
509 font-weight: 400;
510 color: var(--secondary-text-color);
511 font-size: 14px;
512 line-height: 1.6;
513 }
514
515 .elementor-panel .chat-button {
516 background-color: #5b4e96;
517 color: white;
518 border: none;
519 padding: 10px 20px;
520 border-radius: 5px;
521 cursor: pointer;
522 font-size: 12px;
523 display: flex;
524 align-items: center;
525 justify-content: center;
526 gap: 5px;
527 font-weight: 500;
528 width: 100%;
529 }
530
531 .elementor-panel .chat-button {
532 background-color: transparent;
533 border: 1px solid #5B4E96;
534 color: #fff;
535 }
536
537 .elementor-panel .rating-button {
538 background-color: transparent;
539 border: 1px solid #5B4E96;
540 color: var(--submit-button-color);
541 margin-top: 20px;
542 }
543
544 .elementor-panel .chat-button svg {
545 width: 18px;
546 height: 18px;
547 }
548
549 .elementor-panel .chat-button:hover {
550 background-color: #4b3293;
551 }
552
553 /* Analytics Section Styles */
554 .elementor-panel .analytics-section {
555 padding: 12px 20px;
556 background: linear-gradient(180deg, #ffffff 28.76%, #fff9fd 66.19%, #faedff 85.34%);
557 border-radius: 8px;
558 margin-bottom: 0;
559 display: flex;
560 gap: 10px;
561 border-top: 1px solid var(--border-color);
562 overflow: visible;
563 width: calc(100% + 30px);
564 margin-left: -15px;
565 border: none;
566 border-radius: 0;
567 margin-top: 0;
568 }
569
570 @media (prefers-color-scheme: dark) {
571 .elementor-panel .analytics-section {
572 background: linear-gradient(180deg, #1F2023 28.76%, #1A1C1F 66.19%, #1F2124 85.34%);
573 }
574 }
575
576 .elementor-panel .analytics-section .analytics-chart {
577 display: flex;
578 align-items: center;
579 gap: 5px;
580 overflow: visible;
581 position: relative;
582 z-index: 10;
583 }
584
585 .elementor-panel .analytics-section .analytics-content {
586 flex: 1;
587 }
588
589 .elementor-panel .analytics-section .analytics-content h3 {
590 font-size: 12px;
591 font-weight: 600;
592 color: var(--text-color);
593 margin: 0 0 6px 0;
594 }
595
596 .elementor-panel .analytics-section .analytics-content p {
597 font-size: 11px;
598 color: var(--secondary-text-color);
599 margin: 0 0 8px 0;
600 line-height: 1.4;
601 }
602
603 .elementor-panel .analytics-section .view-analytics-link {
604 display: inline-flex;
605 align-items: center;
606 gap: 4px;
607 color: #5b4e96;
608 text-decoration: none;
609 font-size: 11px;
610 font-weight: 500;
611 }
612
613 @media (prefers-color-scheme: dark) {
614 .elementor-panel .analytics-section .view-analytics-link {
615 color: #8C73FA;
616 }
617 }
618
619 .elementor-panel .analytics-section .view-analytics-link:hover {
620 color: #4b3293;
621 }
622
623 @media (prefers-color-scheme: dark) {
624 .elementor-panel .analytics-section .view-analytics-link:hover {
625 color: #A89BFF;
626 }
627 }
628
629 .elementor-panel .mini-pie-chart {
630 width: 70px;
631 height: 70px;
632 overflow: visible;
633 position: relative;
634 z-index: 10;
635 }
636 </style>
637
638 <script>
639 document.addEventListener("DOMContentLoaded", function() {
640 if (typeof jQuery === 'undefined') {
641 console.error("❌ jQuery is not loaded!");
642 return;
643 }
644
645 jQuery(document).ready(function($) {
646
647 let message = ""; // Store the thank-you message state
648 let rating = 0; // Store rating state
649 let showThank = localStorage.getItem("feedbackSubmitted") ? 1 : 0; // Store rating state
650 let targetNode = null; // Store reference to the Elementor controls section
651
652 const currentUser = <?php echo json_encode(wp_get_current_user()->data); ?>;
653 const isProActive = <?php echo json_encode(is_plugin_active('embedpress-pro/embedpress-pro.php')); ?>;
654 const isEmbedpressFeedbackSubmited = <?php echo json_encode(get_option('embedpress_feedback_submited')); ?>;
655
656 const turnOffRattingHelp = <?php echo json_encode(Helper::get_options_value('turn_off_rating_help')); ?>;
657
658 function handleRating(selectedRating) {
659
660 rating = selectedRating;
661
662 $(".star").each(function() {
663 const starValue = $(this).data("rating");
664 $(this).attr("fill", starValue <= rating ? "#FFD700" : "#B1B8C2"); // Gold for selected, Grey for unselected
665 });
666
667 if (rating == 5) {
668 // Only send the rating, don't show thank you message yet
669 // Thank you message will be shown after successful API response
670 sendFiveStarRating();
671 } else {
672 // For ratings less than 5, show the form
673 setTimeout(() => {
674 message = "Please describe your issue in details.";
675 renderUpsellSection();
676 }, 500);
677 }
678
679 }
680
681 function setMessage(value) {
682 message = value;
683 renderUpsellSection();
684 }
685
686 function handleSubmit(event) {
687 event.preventDefault();
688
689 const submitButton = event.target.querySelector('.submit-button');
690 submitButton.disabled = true; // Disable the button
691 submitButton.textContent = 'Sending...'; // Update button text
692
693 const formData = new FormData(event.target);
694 const data = {
695 name: currentUser.display_name,
696 email: currentUser.user_email,
697 rating: rating,
698 message: formData.get('message')
699 };
700
701 fetch('<?php echo esc_url_raw(rest_url('embedpress/v1/send-feedback')); ?>', {
702 method: 'POST',
703 headers: {
704 'Content-Type': 'application/json',
705 'X-WP-Nonce': wpApiSettings.nonce
706 },
707 body: JSON.stringify(data)
708 })
709 .then(response => {
710 // Check if response is ok (status 200-299)
711 if (!response.ok) {
712 return response.json().then(errorData => {
713 throw new Error(errorData.message || 'HTTP error! status: ' + response.status);
714 });
715 }
716 return response.json();
717 })
718 .then(data => {
719 // Success - show thank you message
720 submitButton.disabled = false; // Re-enable the button
721 submitButton.textContent = 'Send'; // Reset button text
722 showThank = 1;
723
724 localStorage.setItem("feedbackSubmitted", "true");
725 renderUpsellSection();
726
727 setTimeout(() => {
728 $(".thankyou-msg-container").fadeOut(500, function() {
729 $(this).remove();
730 });
731 }, 3000); // Disappear after 3 seconds
732
733 })
734 .catch(error => {
735 console.error('Error:', error);
736 submitButton.disabled = false; // Re-enable the button
737 submitButton.textContent = 'Send'; // Reset button text
738
739 // Show user-friendly error message
740 const errorMessage = error.message || 'Failed to send feedback. Please try again.';
741 alert(errorMessage);
742 });
743 };
744
745 function sendFiveStarRating() {
746 const data = {
747 name: currentUser.display_name,
748 email: currentUser.user_email,
749 rating: '5',
750 message: ''
751 };
752
753 fetch('<?php echo esc_url_raw(rest_url('embedpress/v1/send-feedback')); ?>', {
754 method: 'POST',
755 headers: {
756 'Content-Type': 'application/json',
757 'X-WP-Nonce': wpApiSettings.nonce
758 },
759 body: JSON.stringify(data)
760 })
761 .then(response => {
762 // Check if response is ok (status 200-299)
763 if (!response.ok) {
764 return response.json().then(errorData => {
765 throw new Error(errorData.message || 'HTTP error! status: ' + response.status);
766 });
767 }
768 return response.json();
769 })
770 .then(data => {
771 // Success - show thank you message only on successful response
772 showThank = 1;
773 localStorage.setItem("feedbackSubmitted", "true");
774 renderUpsellSection();
775
776 })
777 .catch(error => {
778 console.error('Error:', error);
779
780 // Show user-friendly error message
781 const errorMessage = error.message || 'Failed to send feedback. Please try again.';
782 alert(errorMessage);
783 });
784 }
785
786 function renderUpsellSection() {
787 if (!targetNode) return;
788
789 $(".plugin-rating").remove(); // Remove previous upsell section
790
791
792 const thnkMsgHeading = rating < 5 ? 'We appreciate it!' : 'We’re glad that you liked us! 😍';
793 const thnkMsgDsc = rating < 5 ? 'A heartfelt gratitude for managing the time to share your thoughts with us' : 'If you don’t mind, could you take 30 seconds to review us on WordPress? Your feedback will help us improve and grow. Thank you in advance! 🙏';
794
795 let upsellHtml = `
796 <div class="plugin-rating">
797
798 <!-- Advanced Analytics Section -->
799 <div class="analytics-section">
800 <div class="analytics-chart">
801 <div id="mini-pie-chart-elementor" class="mini-pie-chart"></div>
802 </div>
803 <div class="analytics-content">
804 <h3>Advanced Analytics</h3>
805 <p>Get full analytics on how your embeds are performing.</p>
806 <a href="<?php echo admin_url('admin.php?page=embedpress-analytics'); ?>" class="view-analytics-link">
807 View Analytics
808 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
809 <path d="M6 12L10 8L6 4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
810 </svg>
811 </a>
812 </div>
813 </div>
814
815 ${turnOffRattingHelp && false ? `
816 <div class="rating-chat-content">
817 ${!isEmbedpressFeedbackSubmited ? `
818 ${((rating && rating == 5) || showThank) ? `
819 <div class="thankyou-msg-container">
820
821 <h5 class="help-message">${thnkMsgHeading}</h5>
822 <p class="thank-you-message">${thnkMsgDsc}</p>
823
824 ${rating == 5 ? `
825 <button class="rating-button">
826 Rate the Plugin
827 <svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
828 <path d="M3.75 2.083 6.25 5l-2.5 2.917" stroke="#5B4E96" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round" />
829 </svg>
830 </button>
831 ` : ''}
832 </div>
833 ` : rating && rating < 5 ? `
834 <div class="feedback-submit-container">
835 <h5 class="help-message">Help us make it better!</h5>
836 <p class="form-description">Please share what went wrong with The EmbedPress so that we can improve further*</p>
837 <form id="feedback-form">
838 <div class="form-group">
839 <textarea name="message" placeholder="Describe your issue in details" type="text" rows="4" class="form-control" required></textarea>
840 </div>
841 <div class="form-group">
842 <button class="submit-button" type="submit">Send</button>
843 </div>
844 </form>
845 </div>
846 ` : `
847 <h4>Rate EmbedPress</h4>
848 <div class="stars">
849 ${[1, 2, 3, 4, 5].map(i => `
850 <svg class="star" data-rating="${i}" width="20" height="18.667" viewBox="0 0 20 18.667" fill="none" xmlns="http://www.w3.org/2000/svg"
851 style={{ cursor: "pointer", transition: "fill 0.2s ease-in-out" }}>
852 <g clip-path="url(#a)">
853 <path d="m7.3 5.709-4.963.72-.087.017a.777.777 0 0 0-.343 1.309l3.595 3.499-.848 4.943-.009.087a.777.777 0 0 0 1.139.733l4.437-2.333 4.428 2.333.077.036a.777.777 0 0 0 1.053-.855l-.849-4.944 3.596-3.5.061-.067a.777.777 0 0 0-.493-1.259l-4.961-.72-2.218-4.495a.777.777 0 0 0-1.396 0z"/>
854 </g>
855 <defs><clipPath id="a"><path fill="#fff" d="M.888 0h18.667v18.667H.888z"/></clipPath></defs>
856 </svg>
857 `).join('')}
858 </div>
859 `}
860 ` : ''}
861
862 <p style="font-weight: 500">Need help? We're here</p>
863 <a href="https://embedpress.com/?support=chat" target="_blank" class="chat-button">
864 <svg width="13" height="12" viewBox="0 0 13 12" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#a)" fill="#fff"><path d="M7.93.727H1.555C.97.727.5 1.198.5 1.782V6c0 .584.471 1.055 1.055 1.055h.351V8.11c0 .254.263.438.52.31.008-.008.022-.008.029-.015 1.934-1.297 1.5-1.008 1.933-1.294a.35.35 0 0 1 .19-.056H7.93c.583 0 1.054-.47 1.054-1.055V1.782c0-.584-.47-1.055-1.054-1.055M5.117 4.946h-2.86c-.463 0-.465-.703 0-.703h2.86c.464 0 .466.703 0 .703m2.11-1.406h-4.97c-.463 0-.465-.704 0-.704h4.97c.463 0 .465.704 0 .704" /><path d="M11.445 3.54H9.687V6c0 .97-.787 1.758-1.757 1.758H4.684l-.668.443v.612c0 .584.47 1.055 1.054 1.055h3.457l2.018 1.35c.276.153.549-.033.549-.296V9.868h.351c.584 0 1.055-.471 1.055-1.055V4.594c0-.583-.471-1.054-1.055-1.054" /></g><defs><clipPath id="a"><path fill="#fff" d="M.5 0h12v12H.5z" /></clipPath></defs></svg>
865 Let’s Chat
866 </a>
867 </div>` : ''}
868
869 <div class="rating-chat-content">
870 <p style="font-weight: 500">Need help? We're here</p>
871 <a href="https://embedpress.com/?support=chat" target="_blank" class="chat-button">
872 <svg width="13" height="12" viewBox="0 0 13 12" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#a)" fill="#fff"><path d="M7.93.727H1.555C.97.727.5 1.198.5 1.782V6c0 .584.471 1.055 1.055 1.055h.351V8.11c0 .254.263.438.52.31.008-.008.022-.008.029-.015 1.934-1.297 1.5-1.008 1.933-1.294a.35.35 0 0 1 .19-.056H7.93c.583 0 1.054-.47 1.054-1.055V1.782c0-.584-.47-1.055-1.054-1.055M5.117 4.946h-2.86c-.463 0-.465-.703 0-.703h2.86c.464 0 .466.703 0 .703m2.11-1.406h-4.97c-.463 0-.465-.704 0-.704h4.97c.463 0 .465.704 0 .704" /><path d="M11.445 3.54H9.687V6c0 .97-.787 1.758-1.757 1.758H4.684l-.668.443v.612c0 .584.47 1.055 1.054 1.055h3.457l2.018 1.35c.276.153.549-.033.549-.296V9.868h.351c.584 0 1.055-.471 1.055-1.055V4.594c0-.583-.471-1.054-1.055-1.054" /></g><defs><clipPath id="a"><path fill="#fff" d="M.5 0h12v12H.5z" /></clipPath></defs></svg>
873 Let’s Chat
874 </a>
875 </div>
876
877 ${!isProActive ? `
878 <div class="upgrade-box">
879 <h5>Want to explore more?</h5>
880 <p>Dive in and discover all the premium features</p>
881 <a href="https://embedpress.com/in/unlock-elementor-contorls" target="_blank" class="upgrade-link">Upgrade to PRO</a>
882 </div>` : ''}
883 </div>
884 `;
885
886 $(upsellHtml).insertAfter(targetNode);
887
888
889
890 let currentRating = 0; // Store the selected rating
891 $(".star").attr("fill", "#FFD700");
892
893 $(".star").on("mouseenter", function() {
894 let hoverRating = $(this).data("rating");
895
896 $(".star").each(function() {
897 $(this).attr("fill", $(this).data("rating") <= hoverRating ? "#FFD700" : "#B1B8C2");
898 });
899 });
900
901 $(".star").on("mouseleave", function() {
902 $(".star").each(function() {
903 $(this).attr("fill", $(this).data("rating") <= currentRating ? "#FFD700" : "#B1B8C2");
904 });
905 });
906
907 $(".star").on("click", function() {
908 currentRating = $(this).data("rating");
909
910 $(".star").each(function() {
911 $(this).attr("fill", $(this).data("rating") <= currentRating ? "#FFD700" : "#B1B8C2");
912 });
913
914 handleRating(currentRating);
915 });
916
917
918
919 $(".rating-button").on("click", function() {
920 window.open('https://wordpress.org/support/plugin/embedpress/reviews/#new-post')
921 });
922
923 $("#feedback-form").on("submit", handleSubmit);
924
925 // Initialize Mini Pie Chart
926 initMiniPieChart();
927 }
928
929 function initMiniPieChart() {
930 const chartContainer = document.getElementById('mini-pie-chart-elementor');
931 if (!chartContainer || typeof am5 === 'undefined') {
932
933 // Load amCharts library
934 const script1 = document.createElement('script');
935 script1.src = 'https://cdn.amcharts.com/lib/5/index.js';
936 script1.onload = function() {
937 const script2 = document.createElement('script');
938 script2.src = 'https://cdn.amcharts.com/lib/5/percent.js';
939 script2.onload = function() {
940 const script3 = document.createElement('script');
941 script3.src = 'https://cdn.amcharts.com/lib/5/themes/Animated.js';
942 script3.onload = function() {
943 renderMiniPieChart();
944 };
945 document.head.appendChild(script3);
946 };
947 document.head.appendChild(script2);
948 };
949 document.head.appendChild(script1);
950 } else {
951 renderMiniPieChart();
952 }
953 }
954
955 function renderMiniPieChart() {
956 const chartContainer = document.getElementById('mini-pie-chart-elementor');
957 if (!chartContainer) return;
958
959 // Detect dark mode
960 const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
961
962 // Function to render chart with given data
963 function renderChartWithData(overview) {
964 const chartContainer = document.getElementById('mini-pie-chart-elementor');
965 if (!chartContainer) return;
966
967 // Get raw values
968 const totalEmbeds = parseInt(overview.total_embeds) || 0;
969 const totalViews = parseInt(overview.total_views) || 0;
970 const totalClicks = parseInt(overview.total_clicks) || 0;
971 const totalImpressions = parseInt(overview.total_impressions) || 0;
972
973 // Check if there's any real data
974 const hasRealData = totalEmbeds > 0 || totalViews > 0 || totalClicks > 0 || totalImpressions > 0;
975
976 // Always show at least 1 for each metric to avoid blank chart
977 const chartData = [{
978 category: 'Views',
979 value: hasRealData ? (totalViews || 1) : 1
980 },
981 {
982 category: 'Clicks',
983 value: hasRealData ? (totalClicks || 1) : 1
984 },
985 {
986 category: 'Impr',
987 value: hasRealData ? (totalImpressions || 1) : 1
988 }
989 ];
990
991 // Create chart
992 const root = am5.Root.new(chartContainer);
993 root._logo.dispose();
994 root.setThemes([am5themes_Animated.new(root)]);
995 root.animationThemesEnabled = false;
996
997 const chart = root.container.children.push(
998 am5percent.PieChart.new(root, {
999 layout: root.verticalLayout,
1000 innerRadius: am5.percent(75),
1001 radius: am5.percent(100),
1002 })
1003 );
1004
1005 const series = chart.series.push(
1006 am5percent.PieSeries.new(root, {
1007 valueField: 'value',
1008 categoryField: 'category',
1009 alignLabels: false,
1010 sequencedInterpolation: false,
1011 })
1012 );
1013
1014 series.slices.template.set("toggleKey", "none");
1015 series.labels.template.set("visible", false);
1016 series.ticks.template.set("visible", false);
1017
1018 // Tooltip colors based on theme
1019 const tooltipBg = isDarkMode ? "#1F2124" : "#fff";
1020 const tooltipText = isDarkMode ? "#CBCBD0" : "#333";
1021 const tooltipBorder = isDarkMode ? "#272A2F" : "#e0e0e0";
1022
1023 const tooltip = am5.Tooltip.new(root, {
1024 getFillFromSprite: false,
1025 labelText: `[${tooltipText}]{category}:\{value}[/]`,
1026 paddingTop: 6,
1027 paddingBottom: 6,
1028 paddingLeft: 8,
1029 paddingRight: 8,
1030 autoTextColor: false,
1031 pointerOrientation: "horizontal",
1032 centerX: am5.p50,
1033 centerY: am5.p50,
1034 background: am5.RoundedRectangle.new(root, {
1035 fill: am5.color(tooltipBg),
1036 cornerRadius: 4,
1037 strokeOpacity: 1,
1038 stroke: am5.color(tooltipBorder),
1039 strokeWidth: 1,
1040 shadowColor: am5.color("#000"),
1041 shadowBlur: 4,
1042 shadowOpacity: isDarkMode ? 0.3 : 0.1,
1043 shadowOffsetX: 0,
1044 shadowOffsetY: 2,
1045 }),
1046 });
1047
1048 tooltip.label.setAll({
1049 fill: am5.color(tooltipText),
1050 fontSize: 10,
1051 fontWeight: "400",
1052 textAlign: "center",
1053 oversizedBehavior: "wrap",
1054 maxWidth: 100,
1055 });
1056
1057 // Slice stroke color based on theme
1058 const sliceStroke = isDarkMode ? "#1A1C1F" : "#fff";
1059
1060 series.slices.template.setAll({
1061 tooltip: tooltip,
1062 stroke: am5.color(sliceStroke),
1063 strokeWidth: 1,
1064 cornerRadius: 4,
1065 interactive: true,
1066 hoverable: true,
1067 });
1068
1069 series.slices.template.states.create("hover", {
1070 scale: 1,
1071 });
1072
1073 const colors = ["#5B4E96", "#8C73FA", "#C4B5E8"];
1074 series.get('colors').set('colors', colors.map(c => am5.color(c)));
1075
1076 series.data.setAll(chartData);
1077
1078 // Center text colors based on theme
1079 const centerNumberColor = isDarkMode ? "#ffffff" : "#092161";
1080 const centerLabelColor = isDarkMode ? "#CBCBD0" : "#666";
1081
1082 // Add total embeds number
1083 // Show 1 instead of 0 to avoid blank display
1084 const displayEmbeds = hasRealData ? totalEmbeds : 1;
1085 chart.seriesContainer.children.push(
1086 am5.Label.new(root, {
1087 text: displayEmbeds.toLocaleString(),
1088 centerX: am5.p50,
1089 centerY: am5.p50,
1090 textAlign: "center",
1091 fontSize: 14,
1092 fontWeight: "700",
1093 fill: am5.color(centerNumberColor),
1094 dy: -8,
1095 })
1096 );
1097
1098 // Add "Total Embeds" label
1099 chart.seriesContainer.children.push(
1100 am5.Label.new(root, {
1101 text: "Total Embeds",
1102 centerX: am5.p50,
1103 centerY: am5.p50,
1104 textAlign: "center",
1105 fontSize: 7,
1106 fontWeight: "400",
1107 fill: am5.color(centerLabelColor),
1108 dy: 6,
1109 })
1110 );
1111 }
1112
1113 // Fetch analytics data
1114 const nonce = (typeof wpApiSettings !== 'undefined' && wpApiSettings.nonce) ? wpApiSettings.nonce : '<?php echo wp_create_nonce('wp_rest'); ?>';
1115 fetch('<?php echo esc_url_raw(rest_url('embedpress/v1/analytics/overview')); ?>?date_range=30', {
1116 headers: {
1117 'X-WP-Nonce': nonce
1118 }
1119 })
1120 .then(response => response.json())
1121 .then(result => {
1122 const overview = result.overview || result;
1123 renderChartWithData(overview);
1124 })
1125 .catch(error => {
1126
1127 // Render chart with default values when API fails
1128 renderChartWithData({
1129 total_embeds: 0,
1130 total_views: 0,
1131 total_clicks: 0,
1132 total_impressions: 0
1133 });
1134 });
1135 }
1136
1137 function addUpsellSection(node) {
1138 if (!node) return;
1139
1140 targetNode = node; // Store reference to the correct node
1141 if (!$(".plugin-rating").length) {
1142 renderUpsellSection();
1143 }
1144 }
1145
1146 // MutationObserver to detect Elementor panel changes
1147 const observer = new MutationObserver((mutations) => {
1148 mutations.forEach((mutation) => {
1149 mutation.addedNodes.forEach((node) => {
1150 if ($(node).hasClass("elementor-controls-stack")) {
1151 const elementorControls = node.querySelector("#elementor-controls:has(.elementor-control-embedpress_elementor_content_settings, .elementor-control-embedpress_pdf_content_settings, .elementor-control-embedpress_document_content_settings, .elementor-control-embedpress_calendar_content_settings)");
1152
1153 if (elementorControls) {
1154 addUpsellSection(elementorControls);
1155 }
1156 }
1157 });
1158 });
1159 });
1160
1161 // Start observing Elementor panel for changes
1162 const elementorPanel = document.querySelector(".elementor-panel");
1163 if (elementorPanel) {
1164 observer.observe(elementorPanel, {
1165 childList: true,
1166 subtree: true,
1167 });
1168 } else {
1169 }
1170 });
1171 });
1172 </script>
1173
1174 <?php
1175 }
1176 }
1177