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.

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