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.

214 lines
7.4 KiB

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