images
6 years ago
javascript
5 years ago
stylesheet
5 years ago
admin.php
5 years ago
connect.php
5 years ago
dashboard.php
5 years ago
diag.php
5 years ago
help.php
6 years ago
connect.php
112 lines
| 1 | <div id="nitropack-container" class="wrap"> |
| 2 | <div class="row"> |
| 3 | <div class="col-md-12"> |
| 4 | <div id="login-container"> |
| 5 | <h3>Welcome to NitroPack for WordPress!</h3> |
| 6 | <p>This page will help you to connect your WordPress site with NitroPack in few steps.</p> |
| 7 | <img src="<?= plugin_dir_url(__FILE__) ?>/images/nitropackwp.jpg" alt="NitroPack"/> |
| 8 | <hr /> |
| 9 | <h3>Let's Get Started!</h3> |
| 10 | <p>In order to connect NitroPack with WordPress you need to configure your API details. More information how to obtain these values can be found <a href="https://nitropack.io/blog/post/how-to-get-your-site-id-and-site-secret" target="_blank">here <i class="fa fa-external-link"></i></a></p> |
| 11 | <form class="form-default" action="options.php" method="post" id="api-details-form"> |
| 12 | <?php settings_fields( NITROPACK_OPTION_GROUP ); |
| 13 | do_settings_sections( NITROPACK_OPTION_GROUP ); ?> |
| 14 | <div id="submitdiv" class="postbox "> |
| 15 | <h3>Welcome!</h3> |
| 16 | <div id="manual-connect-fields" style="display:none;"> |
| 17 | <h2>Enter site ID and site secret to start using NitroPack</h2> |
| 18 | <input id="nitropack-siteid-input" name="nitropack-siteId" type="text" class="form-control" placeholder="Site ID"> |
| 19 | <input id="nitropack-sitesecret-input" name="nitropack-siteSecret" type="text" class="form-control" placeholder="Site Secret"> |
| 20 | </div> |
| 21 | <div class="e-submit"> |
| 22 | <a class="btn btn-primary white" id="api-details-form-submit" href="javascript:void(0);"> |
| 23 | <i id="connect-spinner" class="fa fa-spinner fa-spin white" style="display:none;"></i> |
| 24 | <span id="connect-text">Connect to NitroPack</span> |
| 25 | </a> |
| 26 | <h1 id="connect-success" style="display:none;margin-bottom:auto;font-size:36px;"><i class="fa fa-check-circle"></i></h1> |
| 27 | </div> |
| 28 | <div class="clearfix"></div> |
| 29 | <a onclick="jQuery('#manual-connect-fields').show(); jQuery(this).hide();" id="reveal-manual-connect"><small>Enter details manually</small></a> |
| 30 | </div> |
| 31 | </form> |
| 32 | <p>Email at <a href="mailto:sales@nitropack.io?subject=Questions on NitroPack for WordPress">sales@nitropack.io</a>, if you have any problems, questions or you just want to thank us for the good service.</p> |
| 33 | </div> |
| 34 | </div> |
| 35 | </div> |
| 36 | </div> |
| 37 | |
| 38 | <script> |
| 39 | (function($) { |
| 40 | let connectPopup = null; |
| 41 | let homePageUrl = "<?php echo get_home_url(); ?>"; |
| 42 | |
| 43 | window.addEventListener("message", function(e) { |
| 44 | if (e.data.messageType == "nitropack-connect") { |
| 45 | $("#nitropack-siteid-input").val(e.data.api.key); |
| 46 | $("#nitropack-sitesecret-input").val(e.data.api.secret); |
| 47 | $("#api-details-form-submit").click(); |
| 48 | connectPopup.close(); |
| 49 | connectPopup = null; |
| 50 | } |
| 51 | }); |
| 52 | |
| 53 | $("#api-details-form-submit").on("click", function(e) { |
| 54 | let siteId = $("#nitropack-siteid-input").val(); |
| 55 | let siteSecret = $("#nitropack-sitesecret-input").val(); |
| 56 | let isManualConnect = $("#manual-connect-fields").is(":visible"); |
| 57 | |
| 58 | if (isManualConnect || (siteId && siteSecret)) { |
| 59 | e.preventDefault(); |
| 60 | $("#connect-spinner").show(); |
| 61 | $("#connect-text").hide(); |
| 62 | jQuery.post(ajaxurl, { |
| 63 | action: 'nitropack_verify_connect', |
| 64 | siteId: siteId, |
| 65 | siteSecret: siteSecret |
| 66 | }, function(response) { |
| 67 | $("#connect-spinner").hide(); |
| 68 | |
| 69 | var resp = JSON.parse(response); |
| 70 | if (resp.status == "success") { |
| 71 | location.reload(); |
| 72 | $("#connect-success").show(); |
| 73 | $("#api-details-form-submit").hide(); |
| 74 | //$("#api-details-form").ajaxSubmit({ |
| 75 | // complete: function() { |
| 76 | // location.reload(); |
| 77 | // } |
| 78 | //}); |
| 79 | return; |
| 80 | } else { |
| 81 | if (!isManualConnect) { |
| 82 | $("#nitropack-siteid-input").val(""); |
| 83 | $("#nitropack-sitesecret-input").val(""); |
| 84 | } |
| 85 | if (resp.message) { |
| 86 | jQuery('#submitdiv').prepend('<div class="notice notice-error is-dismissible"><p style="word-break: break-word;">' + resp.message + '</p></div>'); |
| 87 | } else { |
| 88 | jQuery('#submitdiv').prepend('<div class="notice notice-error is-dismissible"><p style="word-break: break-word;">Api details verification failed! Please check whether you entered correct details.</p></div>'); |
| 89 | } |
| 90 | loadDismissibleNotices(); |
| 91 | } |
| 92 | $("#connect-text").show(); |
| 93 | }); |
| 94 | } else if (!isManualConnect) { |
| 95 | if (!connectPopup || !connectPopup.window) { |
| 96 | let screenWidth = window.screen.availWidth; |
| 97 | let screenHeight = window.screen.availHeight; |
| 98 | let windowWidth = 500; |
| 99 | let windowHeight = 700; |
| 100 | let leftPos = window.top.outerWidth / 2 + window.top.screenX - ( windowWidth / 2); |
| 101 | let topPos = window.top.outerHeight / 2 + window.top.screenY - ( windowHeight / 2); |
| 102 | |
| 103 | connectPopup = window.open("https://nitropack.io/auth?website=" + homePageUrl, "Site Selector", "width=" + windowWidth + ",height=" + windowHeight + ",left=" + leftPos + ",top=" + topPos); |
| 104 | } else if (connectPopup && connectPopup.window) { |
| 105 | connectPopup.focus(); |
| 106 | } |
| 107 | } |
| 108 | }); |
| 109 | })(jQuery); |
| 110 | </script> |
| 111 | |
| 112 |