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.

201 lines
7.2 KiB

  1. <div class="narrow">
  2. <?= partial('partials/header') ?>
  3. <form role="form" style="margin-top: 20px;" id="note_form" action="/post" method="post">
  4. <h3>Caffeine</h3>
  5. <ul class="caffeine">
  6. <?php foreach(caffeine_options() as $val): ?>
  7. <li><input type="submit" name="drank" class="btn btn-default" value="<?= $val ?>"></li>
  8. <?php endforeach; ?>
  9. <li>
  10. <input type="text" class="form-control" name="custom_caffeine" placeholder="Custom" style="width: 72%; float: left; margin-right: 2px;">
  11. <input type="submit" class="btn btn-default" value="Post" style="width: 26%; float: right;">
  12. </li>
  13. </ul>
  14. <br>
  15. <h3>Alcohol</h3>
  16. <ul class="alcohol">
  17. <?php foreach(alcohol_options() as $val): ?>
  18. <li><input type="submit" name="drank" class="btn btn-default" value="<?= $val ?>"></li>
  19. <?php endforeach; ?>
  20. <li>
  21. <input type="text" class="form-control" name="custom_alcohol" placeholder="Custom" style="width: 72%; float: left; margin-right: 2px;">
  22. <input type="submit" class="btn btn-default" value="Post" style="width: 26%; float: right;">
  23. </li>
  24. </ul>
  25. <br><br>
  26. <div class="form-group">
  27. <label for="note_location">Location</label>
  28. <input type="checkbox" id="note_location_chk" value="">
  29. <img src="/images/spinner.gif" id="note_location_loading" style="display: none;">
  30. <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
  31. <input type="hidden" id="note_location" name="location">
  32. <input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
  33. <div id="note_location_img" style="display: none;">
  34. <img src="" height="180" id="note_location_img_wide" class="img-responsive">
  35. <img src="" height="320" id="note_location_img_small" class="img-responsive">
  36. </div>
  37. </div>
  38. </form>
  39. <?php if($this->micropub_endpoint): ?>
  40. <?php if($this->test_response): ?>
  41. <h4>Last response from your Micropub endpoint <span id="last_response_date">(<?= relative_time($this->response_date) ?>)</span></h4>
  42. <?php endif; ?>
  43. <pre id="test_response" style="width: 100%; min-height: 240px;"><?= htmlspecialchars($this->test_response) ?></pre>
  44. <div class="callout">
  45. <p>Clicking "Post" will post this note to your Micropub endpoint. Below is some information about the request that will be made.</p>
  46. <table class="table table-condensed">
  47. <tr>
  48. <td>me</td>
  49. <td><code><?= session('me') ?></code> (should be your URL)</td>
  50. </tr>
  51. <tr>
  52. <td>scope</td>
  53. <td><code><?= $this->token_scope ?></code> (should be a space-separated list of permissions including "post")</td>
  54. </tr>
  55. <tr>
  56. <td>micropub endpoint</td>
  57. <td><code><?= $this->micropub_endpoint ?></code> (should be a URL)</td>
  58. </tr>
  59. <tr>
  60. <td>access token</td>
  61. <td>String of length <b><?= strlen($this->access_token) ?></b><?= (strlen($this->access_token) > 0) ? (', ending in <code>' . substr($this->access_token, -7) . '</code>') : '' ?> (should be greater than length 0)</td>
  62. </tr>
  63. </table>
  64. </div>
  65. <?php endif; ?>
  66. </div>
  67. <script>
  68. $(function(){
  69. // ctrl-s to save
  70. $(window).on('keydown', function(e){
  71. if(e.keyCode == 83 && e.ctrlKey){
  72. $("#btn_post").click();
  73. }
  74. });
  75. $("#btn_post").click(function(){
  76. var syndications = [];
  77. $("#syndication-container button.btn-info").each(function(i,btn){
  78. syndications.push($(btn).data('syndication'));
  79. });
  80. $.post("/micropub/post", {
  81. content: $("#note_content").val(),
  82. 'in-reply-to': $("#note_in_reply_to").val(),
  83. location: $("#note_location").val(),
  84. category: $("#note_category").val(),
  85. slug: $("#note_slug").val(),
  86. 'syndicate-to': syndications.join(',')
  87. }, function(data){
  88. var response = JSON.parse(data);
  89. if(response.location != false) {
  90. $("#note_form").slideUp(200, function(){
  91. $(window).scrollTop($("#test_success").position().top);
  92. });
  93. $("#test_success").removeClass('hidden');
  94. $("#test_error").addClass('hidden');
  95. $("#post_href").attr("href", response.location);
  96. $("#note_content").val("");
  97. $("#note_in_reply_to").val("");
  98. $("#note_category").val("");
  99. $("#note_slug").val("");
  100. } else {
  101. $("#test_success").addClass('hidden');
  102. $("#test_error").removeClass('hidden');
  103. }
  104. $("#last_response_date").html("(just now)");
  105. $("#test_request").html(response.request);
  106. $("#last_request_container").show();
  107. $("#test_response").html(response.response);
  108. });
  109. return false;
  110. });
  111. function location_error(msg) {
  112. $("#note_location_msg").val(msg);
  113. $("#note_location_chk").removeAttr("checked");
  114. $("#note_location_loading").hide();
  115. $("#note_location_img").hide();
  116. $("#note_location_msg").removeClass("img-visible");
  117. }
  118. var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>";
  119. var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>";
  120. function fetch_location() {
  121. $("#note_location_loading").show();
  122. navigator.geolocation.getCurrentPosition(function(position){
  123. $("#note_location_loading").hide();
  124. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  125. $("#note_location_msg").val(geo);
  126. $("#note_location").val(geo);
  127. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  128. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  129. $("#note_location_img").show();
  130. $("#note_location_msg").addClass("img-visible");
  131. }, function(err){
  132. if(err.code == 1) {
  133. location_error("The website was not able to get permission");
  134. } else if(err.code == 2) {
  135. location_error("Location information was unavailable");
  136. } else if(err.code == 3) {
  137. location_error("Timed out getting location");
  138. }
  139. });
  140. }
  141. $("#note_location_chk").click(function(){
  142. if($(this).attr("checked") == "checked") {
  143. if(navigator.geolocation) {
  144. $.post("/prefs", {
  145. enabled: 1
  146. });
  147. fetch_location();
  148. } else {
  149. location_error("Browser location is not supported");
  150. }
  151. } else {
  152. $("#note_location_img").hide();
  153. $("#note_location_msg").removeClass("img-visible");
  154. $("#note_location_msg").val('');
  155. $("#note_location").val('');
  156. $.post("/prefs", {
  157. enabled: 0
  158. });
  159. }
  160. });
  161. if($("#location_enabled").val() == 1) {
  162. $("#note_location_chk").attr("checked","checked");
  163. fetch_location();
  164. }
  165. });
  166. </script>