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.

230 lines
7.7 KiB

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