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.

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