You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.3 KiB

  1. <?php $this->layout('layout-loggedin', ['title' => $title, 'accounts' => $accounts, 'user' => $user]); ?>
  2. <div class="ui main text container" style="margin-top: 80px;">
  3. <h2>Send Webmentions</h2>
  4. <table class="ui very basic fixed single line unstackable table" id="send-table">
  5. <thead>
  6. <th class="twelve wide">URL</th>
  7. <th class="four wide">Status</th>
  8. </thead>
  9. <tbody>
  10. <tr><td colspan="2">Looking for URLs...</td></tr>
  11. </tbody>
  12. </table>
  13. </div>
  14. <script>
  15. var source_url = "<?= $url ?>";
  16. var token = "<?= $role->token ?>";
  17. $(function(){
  18. $.post('/dashboard/get_outgoing_links.json', {
  19. url: source_url
  20. }, function(data) {
  21. $("#send-table tbody").html('<tr><td colspan="2"></td></tr>');
  22. for(var i in data.links) {
  23. $("#send-table tr:last").after('<tr data-url="'+data.links[i]+'">'
  24. +'<td class="target-url">'
  25. +'<div class="popup" data-content="'+data.links[i]+'"><span>'+data.links[i]+'<span></div>'
  26. +'</td>'
  27. +'<td class="send">'
  28. +'<div class="ui active mini inline loader"></div>'
  29. +'</td>'
  30. +'</tr>');
  31. }
  32. $("#send-table tbody tr:first").remove();
  33. // Enable popup on any values that overflowed the container
  34. $(".popup").each(function(i,el){
  35. if($(el).children("span").width() > $(el).width()) {
  36. $(el).popup();
  37. }
  38. });
  39. // Check for a webmention or pingback endpoint
  40. $("#send-table tr").each(function(i,el){
  41. discover_endpoint(el, false);
  42. });
  43. });
  44. });
  45. function discover_endpoint(row, ignore_cache) {
  46. $.post("/dashboard/discover_endpoint.json", {
  47. target: $(row).data("url"),
  48. ignore_cache: ignore_cache
  49. }, function(data){
  50. var html;
  51. if(data.status == 'none') {
  52. html = '<div class="ui yellow horizontal label">No endpoint found</div><br><button class="send-button check-again ui button">Check Again</button>';
  53. } else if(data.status == 'webmention') {
  54. html = '<button class="send-button send-now ui primary button">Send Webmention</button>';
  55. } else if(data.status == 'pingback') {
  56. html = '<button class="send-button send-now ui primary button">Send Pingback</button>';
  57. }
  58. $(row).children(".send").html(html);
  59. bind_send_buttons();
  60. });
  61. }
  62. function bind_send_buttons() {
  63. $(".send-button").unbind("click");
  64. $(".check-again").bind("click", function(){
  65. var row = $(this).parents("tr");
  66. $(row).find(".send-button").addClass('loading');
  67. discover_endpoint(row, true);
  68. });
  69. $(".send-now").bind("click", function(){
  70. var row = $(this).parents("tr");
  71. $(row).find(".send-button").addClass('loading');
  72. // Send to the API
  73. $.post("/webmention", {
  74. token: token,
  75. source: source_url,
  76. target: $(row).data("url")
  77. }, function(data){
  78. $(row).find(".send-button").removeClass('loading');
  79. if(data.status == 'queued') {
  80. $(row).find(".send").html('<a href="'+data.location+'/details" data-status="'+data.location+'"><i class="circular inverted orange wait icon"></i></a>');
  81. // TODO: check for status updates on a timer
  82. } else {
  83. $(row).find(".send").html('<i class="circular inverted red x icon"></i>');
  84. }
  85. });
  86. });
  87. }
  88. </script>
  89. <style type="text/css">
  90. .popup {
  91. word-wrap: break-word;
  92. }
  93. #send-table tr {
  94. height: 83px;
  95. }
  96. </style>