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.

116 lines
3.7 KiB

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