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.

226 lines
8.6 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->token_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->access_token) ?></b><?= (strlen($this->access_token) > 0) ? (', ending in <code>' . substr($this->access_token, -7) . '</code>') : '' ?> (should be greater than length 0)</td>
  79. </tr>
  80. </table>
  81. </div>
  82. </div>
  83. <script>
  84. $(function(){
  85. // ctrl-s to save
  86. $(window).on('keydown', function(e){
  87. if(e.keyCode == 83 && e.ctrlKey){
  88. $("#btn_post").click();
  89. }
  90. });
  91. $("#btn_post").click(function(){
  92. var syndications = [];
  93. $("#syndication-container button.btn-info").each(function(i,btn){
  94. syndications.push($(btn).data('syndication'));
  95. });
  96. $.post("/micropub/post", {
  97. content: $("#note_content").val(),
  98. 'in-reply-to': $("#note_in_reply_to").val(),
  99. location: $("#note_location").val(),
  100. category: $("#note_category").val(),
  101. slug: $("#note_slug").val(),
  102. 'syndicate-to': syndications.join(',')
  103. }, function(data){
  104. var response = JSON.parse(data);
  105. if(response.location != false) {
  106. $("#note_form").slideUp(200, function(){
  107. $(window).scrollTop($("#test_success").position().top);
  108. });
  109. $("#test_success").removeClass('hidden');
  110. $("#test_error").addClass('hidden');
  111. $("#post_href").attr("href", response.location);
  112. $("#note_content").val("");
  113. $("#note_in_reply_to").val("");
  114. $("#note_category").val("");
  115. $("#note_slug").val("");
  116. } else {
  117. $("#test_success").addClass('hidden');
  118. $("#test_error").removeClass('hidden');
  119. }
  120. $("#last_response_date").html("(just now)");
  121. $("#test_request").html(response.request);
  122. $("#last_request_container").show();
  123. $("#test_response").html(response.response);
  124. });
  125. return false;
  126. });
  127. function location_error(msg) {
  128. $("#note_location_msg").val(msg);
  129. $("#note_location_chk").removeAttr("checked");
  130. $("#note_location_loading").hide();
  131. $("#note_location_img").hide();
  132. $("#note_location_msg").removeClass("img-visible");
  133. }
  134. var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>";
  135. var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>";
  136. function fetch_location() {
  137. $("#note_location_loading").show();
  138. navigator.geolocation.getCurrentPosition(function(position){
  139. $("#note_location_loading").hide();
  140. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  141. $("#note_location_msg").val(geo);
  142. $("#note_location").val(geo);
  143. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  144. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  145. $("#note_location_img").show();
  146. $("#note_location_msg").addClass("img-visible");
  147. }, function(err){
  148. if(err.code == 1) {
  149. location_error("The website was not able to get permission");
  150. } else if(err.code == 2) {
  151. location_error("Location information was unavailable");
  152. } else if(err.code == 3) {
  153. location_error("Timed out getting location");
  154. }
  155. });
  156. }
  157. $("#note_location_chk").click(function(){
  158. if($(this).attr("checked") == "checked") {
  159. if(navigator.geolocation) {
  160. $.post("/prefs", {
  161. enabled: 1
  162. });
  163. fetch_location();
  164. } else {
  165. location_error("Browser location is not supported");
  166. }
  167. } else {
  168. $("#note_location_img").hide();
  169. $("#note_location_msg").removeClass("img-visible");
  170. $("#note_location_msg").val('');
  171. $("#note_location").val('');
  172. $.post("/prefs", {
  173. enabled: 0
  174. });
  175. }
  176. });
  177. if($("#location_enabled").val() == 1) {
  178. $("#note_location_chk").attr("checked","checked");
  179. fetch_location();
  180. }
  181. bind_syndication_buttons();
  182. });
  183. <?= partial('partials/syndication-js') ?>
  184. </script>