Mirror of Quill
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.

238 lines
8.0 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_location"><code>location</code></label>
  22. <input type="checkbox" id="note_location_chk" value="">
  23. <img src="/images/spinner.gif" id="note_location_loading" style="display: none;">
  24. <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
  25. <input type="hidden" id="note_location">
  26. <input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
  27. <div id="note_location_img" style="display: none;">
  28. <img src="" height="180" id="note_location_img_wide" class="img-responsive">
  29. <img src="" height="320" id="note_location_img_small" class="img-responsive">
  30. </div>
  31. </div>
  32. <button class="btn btn-success" id="btn_post">Post</button>
  33. </form>
  34. <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>
  35. <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>
  36. <?php if($this->test_response): ?>
  37. <h4>Last response from your Micropub endpoint <span id="last_response_date">(<?= relative_time($this->response_date) ?>)</span></h4>
  38. <?php endif; ?>
  39. <pre id="test_response" style="width: 100%; min-height: 240px;"><?= htmlspecialchars($this->test_response) ?></pre>
  40. <div class="callout">
  41. <p>Clicking "Post" will post this note to your Micropub endpoint. Below is some information about the request that will be made.</p>
  42. <table class="table table-condensed">
  43. <tr>
  44. <td>me</td>
  45. <td><code><?= session('me') ?></code> (should be your URL)</td>
  46. </tr>
  47. <tr>
  48. <td>scope</td>
  49. <td><code><?= $this->micropub_scope ?></code> (should be a space-separated list of permissions including "post")</td>
  50. </tr>
  51. <tr>
  52. <td>micropub endpoint</td>
  53. <td><code><?= $this->micropub_endpoint ?></code> (should be a URL)</td>
  54. </tr>
  55. <tr>
  56. <td>access token</td>
  57. <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>
  58. </tr>
  59. </table>
  60. </div>
  61. </div>
  62. <script>
  63. $(function(){
  64. $("#btn_post").click(function(){
  65. $.post("/micropub/post", {
  66. content: $("#note_content").val(),
  67. in_reply_to: $("#note_in_reply_to").val(),
  68. location: $("#note_location").val(),
  69. category: $("#note_category").val(),
  70. slug: $("#note_slug").val()
  71. }, function(data){
  72. var response = JSON.parse(data);
  73. if(response.location != false) {
  74. $("#note_form").slideUp();
  75. $("#test_success").removeClass('hidden');
  76. $("#test_error").addClass('hidden');
  77. $("#post_href").attr("href", response.location);
  78. $("#note_content").val("");
  79. $("#note_in_reply_to").val("");
  80. $("#note_category").val("");
  81. $("#note_slug").val("");
  82. } else {
  83. $("#test_success").addClass('hidden');
  84. $("#test_error").removeClass('hidden');
  85. }
  86. $("#last_response_date").html("(just now)");
  87. $("#test_response").html(response.response);
  88. })
  89. });
  90. function location_error(msg) {
  91. $("#note_location_msg").val(msg);
  92. $("#note_location_chk").removeAttr("checked");
  93. $("#note_location_loading").hide();
  94. $("#note_location_img").hide();
  95. $("#note_location_msg").removeClass("img-visible");
  96. }
  97. var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>";
  98. var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>";
  99. function fetch_location() {
  100. $("#note_location_loading").show();
  101. navigator.geolocation.getCurrentPosition(function(position){
  102. $("#note_location_loading").hide();
  103. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  104. $("#note_location_msg").val(geo);
  105. $("#note_location").val(geo);
  106. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  107. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  108. $("#note_location_img").show();
  109. $("#note_location_msg").addClass("img-visible");
  110. }, function(err){
  111. if(err.code == 1) {
  112. location_error("The website was not able to get permission");
  113. } else if(err.code == 2) {
  114. location_error("Location information was unavailable");
  115. } else if(err.code == 3) {
  116. location_error("Timed out getting location");
  117. }
  118. });
  119. }
  120. $("#note_location_chk").click(function(){
  121. if($(this).attr("checked") == "checked") {
  122. if(navigator.geolocation) {
  123. $.post("/prefs", {
  124. enabled: 1
  125. });
  126. fetch_location();
  127. } else {
  128. location_error("Browser location is not supported");
  129. }
  130. } else {
  131. $("#note_location_img").hide();
  132. $("#note_location_msg").removeClass("img-visible");
  133. $("#note_location_msg").val('');
  134. $("#note_location").val('');
  135. $.post("/prefs", {
  136. enabled: 0
  137. });
  138. }
  139. });
  140. if($("#location_enabled").val() == 1) {
  141. $("#note_location_chk").attr("checked","checked");
  142. fetch_location();
  143. }
  144. });
  145. </script>
  146. <style type="text/css">
  147. #last_response_date {
  148. font-size: 80%;
  149. font-weight: normal;
  150. }
  151. #btn_post {
  152. margin-bottom: 10px;
  153. }
  154. @media all and (max-width: 480px) {
  155. #note_location_img_wide {
  156. display: none;
  157. }
  158. #note_location_img_small {
  159. display: block;
  160. }
  161. }
  162. @media all and (min-width: 480px) {
  163. #note_location_img_wide {
  164. display: block;
  165. }
  166. #note_location_img_small {
  167. display: none;
  168. }
  169. }
  170. .img-visible {
  171. -webkit-border-bottom-right-radius: 0;
  172. -webkit-border-bottom-left-radius: 0;
  173. -moz-border-radius-bottomright: 0;
  174. -moz-border-radius-bottomleft: 0;
  175. border-bottom-right-radius: 0;
  176. border-bottom-left-radius: 0;
  177. }
  178. #note_location_img img {
  179. margin-top: -1px;
  180. border: 1px solid #ccc;
  181. -webkit-border-bottom-right-radius: 4px;
  182. -webkit-border-bottom-left-radius: 4px;
  183. -moz-border-radius-bottomright: 4px;
  184. -moz-border-radius-bottomleft: 4px;
  185. border-bottom-right-radius: 4px;
  186. border-bottom-left-radius: 4px;
  187. }
  188. .callout {
  189. border-left: 4px #5bc0de solid;
  190. background-color: #f4f8fa;
  191. padding: 20px;
  192. margin-top: 10px;
  193. }
  194. .callout table {
  195. margin-bottom: 0;
  196. }
  197. </style>