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