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.

219 lines
8.5 KiB

  1. <div class="narrow">
  2. <?= partial('partials/header') ?>
  3. <form role="form" style="margin-top: 20px;" id="note_form">
  4. <div class="form-group">
  5. <label for="note_content"><code>content</code></label>
  6. <textarea id="note_content" value="" class="form-control" style="height: 4em;"></textarea>
  7. </div>
  8. <div class="form-group">
  9. <label for="note_in_reply_to"><code>in-reply-to</code> (optional, a URL you are replying to)</label>
  10. <input type="text" id="note_in_reply_to" value="" class="form-control">
  11. </div>
  12. <div class="form-group">
  13. <label for="note_category"><code>category</code> (optional, comma-separated list of tags)</label>
  14. <input type="text" id="note_category" value="" class="form-control" placeholder="e.g. web, personal">
  15. </div>
  16. <div class="form-group">
  17. <label for="note_slug"><code>slug</code> (optional)</label>
  18. <input type="text" id="note_slug" value="" class="form-control">
  19. </div>
  20. <div class="form-group">
  21. <label for="note_syndicate-to"><code>syndicate-to</code> <a href="javascript:reload_syndications()">(refresh)</a></label>
  22. <div id="syndication-container">
  23. <?php
  24. if($this->syndication_targets) {
  25. echo '<ul>';
  26. foreach($this->syndication_targets as $syn) {
  27. echo '<li><button data-syndication="'.$syn['target'].'" class="btn btn-default btn-block"><img src="'.$syn['favicon'].'" width="16" height="16"> '.$syn['target'].'</button></li>';
  28. }
  29. echo '</ul>';
  30. } else {
  31. ?><div class="bs-callout bs-callout-warning">No syndication targets were found on your site.
  32. You can provide a <a href="/docs#syndication">list of supported syndication targets</a> that will appear as checkboxes here.</div><?php
  33. }
  34. ?>
  35. </div>
  36. </div>
  37. <div class="form-group">
  38. <label for="note_location"><code>location</code></label>
  39. <input type="checkbox" id="note_location_chk" value="">
  40. <img src="/images/spinner.gif" id="note_location_loading" style="display: none;">
  41. <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
  42. <input type="hidden" id="note_location">
  43. <input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
  44. <div id="note_location_img" style="display: none;">
  45. <img src="" height="180" id="note_location_img_wide" class="img-responsive">
  46. <img src="" height="320" id="note_location_img_small" class="img-responsive">
  47. </div>
  48. </div>
  49. <button class="btn btn-success" id="btn_post">Post</button>
  50. </form>
  51. <div class="alert alert-success hidden" id="test_success"><strong>Success! We found a Location header in the response!</strong><br>Your post should be on your website now!<br><a href="" id="post_href">View your post</a></div>
  52. <div class="alert alert-danger hidden" id="test_error"><strong>Your endpoint did not return a Location header.</strong><br>See <a href="/creating-a-micropub-endpoint">Creating a Micropub Endpoint</a> for more information.</div>
  53. <div id="last_request_container" style="display: none;">
  54. <h4>Request made to your Micropub endpoint</h4>
  55. <pre id="test_request" style="width: 100%; min-height: 140px;"></pre>
  56. </div>
  57. <?php if($this->test_response): ?>
  58. <h4>Last response from your Micropub endpoint <span id="last_response_date">(<?= relative_time($this->response_date) ?>)</span></h4>
  59. <?php endif; ?>
  60. <pre id="test_response" style="width: 100%; min-height: 240px;"><?= htmlspecialchars($this->test_response) ?></pre>
  61. <div class="callout">
  62. <p>Clicking "Post" will post this note to your Micropub endpoint. Below is some information about the request that will be made.</p>
  63. <table class="table table-condensed">
  64. <tr>
  65. <td>me</td>
  66. <td><code><?= session('me') ?></code> (should be your URL)</td>
  67. </tr>
  68. <tr>
  69. <td>scope</td>
  70. <td><code><?= $this->micropub_scope ?></code> (should be a space-separated list of permissions including "post")</td>
  71. </tr>
  72. <tr>
  73. <td>micropub endpoint</td>
  74. <td><code><?= $this->micropub_endpoint ?></code> (should be a URL)</td>
  75. </tr>
  76. <tr>
  77. <td>access token</td>
  78. <td>String of length <b><?= strlen($this->micropub_access_token) ?></b><?= (strlen($this->micropub_access_token) > 0) ? (', ending in <code>' . substr($this->micropub_access_token, -7) . '</code>') : '' ?> (should be greater than length 0)</td>
  79. </tr>
  80. </table>
  81. </div>
  82. </div>
  83. <script>
  84. $(function(){
  85. $("#btn_post").click(function(){
  86. var syndications = [];
  87. $("#syndication-container button.btn-info").each(function(i,btn){
  88. syndications.push($(btn).data('syndication'));
  89. });
  90. $.post("/micropub/post", {
  91. content: $("#note_content").val(),
  92. 'in-reply-to': $("#note_in_reply_to").val(),
  93. location: $("#note_location").val(),
  94. category: $("#note_category").val(),
  95. slug: $("#note_slug").val(),
  96. 'syndicate-to': syndications.join(',')
  97. }, function(data){
  98. var response = JSON.parse(data);
  99. if(response.location != false) {
  100. $("#note_form").slideUp(200, function(){
  101. $(window).scrollTop($("#test_success").position().top);
  102. });
  103. $("#test_success").removeClass('hidden');
  104. $("#test_error").addClass('hidden');
  105. $("#post_href").attr("href", response.location);
  106. $("#note_content").val("");
  107. $("#note_in_reply_to").val("");
  108. $("#note_category").val("");
  109. $("#note_slug").val("");
  110. } else {
  111. $("#test_success").addClass('hidden');
  112. $("#test_error").removeClass('hidden');
  113. }
  114. $("#last_response_date").html("(just now)");
  115. $("#test_request").html(response.request);
  116. $("#last_request_container").show();
  117. $("#test_response").html(response.response);
  118. });
  119. return false;
  120. });
  121. function location_error(msg) {
  122. $("#note_location_msg").val(msg);
  123. $("#note_location_chk").removeAttr("checked");
  124. $("#note_location_loading").hide();
  125. $("#note_location_img").hide();
  126. $("#note_location_msg").removeClass("img-visible");
  127. }
  128. var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>";
  129. var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>";
  130. function fetch_location() {
  131. $("#note_location_loading").show();
  132. navigator.geolocation.getCurrentPosition(function(position){
  133. $("#note_location_loading").hide();
  134. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  135. $("#note_location_msg").val(geo);
  136. $("#note_location").val(geo);
  137. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  138. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  139. $("#note_location_img").show();
  140. $("#note_location_msg").addClass("img-visible");
  141. }, function(err){
  142. if(err.code == 1) {
  143. location_error("The website was not able to get permission");
  144. } else if(err.code == 2) {
  145. location_error("Location information was unavailable");
  146. } else if(err.code == 3) {
  147. location_error("Timed out getting location");
  148. }
  149. });
  150. }
  151. $("#note_location_chk").click(function(){
  152. if($(this).attr("checked") == "checked") {
  153. if(navigator.geolocation) {
  154. $.post("/prefs", {
  155. enabled: 1
  156. });
  157. fetch_location();
  158. } else {
  159. location_error("Browser location is not supported");
  160. }
  161. } else {
  162. $("#note_location_img").hide();
  163. $("#note_location_msg").removeClass("img-visible");
  164. $("#note_location_msg").val('');
  165. $("#note_location").val('');
  166. $.post("/prefs", {
  167. enabled: 0
  168. });
  169. }
  170. });
  171. if($("#location_enabled").val() == 1) {
  172. $("#note_location_chk").attr("checked","checked");
  173. fetch_location();
  174. }
  175. bind_syndication_buttons();
  176. });
  177. <?= partial('partials/syndication-js') ?>
  178. </script>