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.

254 lines
9.8 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. <div id="note_content_remaining" class="pcheck206"><img src="/images/twitter.ico"> <span>140</span></div>
  6. <label for="note_content"><code>content</code></label>
  7. <textarea id="note_content" value="" class="form-control" style="height: 4em;"></textarea>
  8. </div>
  9. <div class="form-group">
  10. <label for="note_in_reply_to"><code>in-reply-to</code> (optional, a URL you are replying to)</label>
  11. <input type="text" id="note_in_reply_to" value="<?= $this->in_reply_to ?>" class="form-control">
  12. </div>
  13. <div class="form-group">
  14. <label for="note_category"><code>category</code> (optional, comma-separated list of tags)</label>
  15. <input type="text" id="note_category" value="" class="form-control" placeholder="e.g. web, personal">
  16. </div>
  17. <div class="form-group">
  18. <label for="note_slug"><code>slug</code> (optional)</label>
  19. <input type="text" id="note_slug" value="" class="form-control">
  20. </div>
  21. <div class="form-group">
  22. <label for="note_syndicate-to"><code>syndicate-to</code> <a href="javascript:reload_syndications()">(refresh)</a></label>
  23. <div id="syndication-container">
  24. <?php
  25. if($this->syndication_targets) {
  26. echo '<ul>';
  27. foreach($this->syndication_targets as $syn) {
  28. echo '<li><button data-syndication="'.$syn['target'].'" class="btn btn-default btn-block"><img src="'.$syn['favicon'].'" width="16" height="16"> '.$syn['target'].'</button></li>';
  29. }
  30. echo '</ul>';
  31. } else {
  32. ?><div class="bs-callout bs-callout-warning">No syndication targets were found on your site.
  33. You can provide a <a href="/docs#syndication">list of supported syndication targets</a> that will appear as checkboxes here.</div><?php
  34. }
  35. ?>
  36. </div>
  37. </div>
  38. <div class="form-group">
  39. <label for="note_location"><code>location</code></label>
  40. <input type="checkbox" id="note_location_chk" value="">
  41. <img src="/images/spinner.gif" id="note_location_loading" style="display: none;">
  42. <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
  43. <input type="hidden" id="note_location">
  44. <input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
  45. <div id="note_location_img" style="display: none;">
  46. <img src="" height="180" id="note_location_img_wide" class="img-responsive">
  47. <img src="" height="320" id="note_location_img_small" class="img-responsive">
  48. </div>
  49. </div>
  50. <button class="btn btn-success" id="btn_post">Post</button>
  51. </form>
  52. <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>
  53. <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>
  54. <div id="last_request_container" style="display: none;">
  55. <h4>Request made to your Micropub endpoint</h4>
  56. <pre id="test_request" style="width: 100%; min-height: 140px;"></pre>
  57. </div>
  58. <?php if($this->test_response): ?>
  59. <h4>Last response from your Micropub endpoint <span id="last_response_date">(<?= relative_time($this->response_date) ?>)</span></h4>
  60. <?php endif; ?>
  61. <pre id="test_response" style="width: 100%; min-height: 240px;"><?= htmlspecialchars($this->test_response) ?></pre>
  62. <div class="callout">
  63. <p>Clicking "Post" will post this note to your Micropub endpoint. Below is some information about the request that will be made.</p>
  64. <table class="table table-condensed">
  65. <tr>
  66. <td>me</td>
  67. <td><code><?= session('me') ?></code> (should be your URL)</td>
  68. </tr>
  69. <tr>
  70. <td>scope</td>
  71. <td><code><?= $this->micropub_scope ?></code> (should be a space-separated list of permissions including "post")</td>
  72. </tr>
  73. <tr>
  74. <td>micropub endpoint</td>
  75. <td><code><?= $this->micropub_endpoint ?></code> (should be a URL)</td>
  76. </tr>
  77. <tr>
  78. <td>access token</td>
  79. <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>
  80. </tr>
  81. </table>
  82. </div>
  83. <hr>
  84. <div style="text-align: right;">
  85. <a href="/add-to-home?start">Add to Home Screen</a>
  86. </div>
  87. </div>
  88. <style type="text/css">
  89. #note_content_remaining {
  90. float: right;
  91. font-size: 0.8em;
  92. font-weight: bold;
  93. }
  94. .pcheck206 { color: #6ba15c; } /* tweet fits within the limit even after adding RT @username */
  95. .pcheck207 { color: #c4b404; } /* danger zone, tweet will overflow when RT @username is added */
  96. .pcheck200,.pcheck208 { color: #59cb3a; } /* exactly fits 140 chars, both with or without RT */
  97. .pcheck413 { color: #a73b3b; } /* over max tweet length */
  98. </style>
  99. <script>
  100. $(function(){
  101. $("#note_content").on('change keyup', function(e){
  102. var text = $("#note_content").val();
  103. var tweet_length = tw_text_proxy(text).length;
  104. var tweet_check = tw_length_check(text, 140, "<?= $this->user->twitter_username ?>");
  105. var remaining = 140 - tweet_length;
  106. $("#note_content_remaining span").html(remaining);
  107. $("#note_content_remaining").removeClass("pcheck200 pcheck206 pcheck207 pcheck208 pcheck413");
  108. $("#note_content_remaining").addClass("pcheck"+tweet_check);
  109. });
  110. // ctrl-s to save
  111. $(window).on('keydown', function(e){
  112. if(e.keyCode == 83 && e.ctrlKey){
  113. $("#btn_post").click();
  114. }
  115. });
  116. $("#btn_post").click(function(){
  117. var syndications = [];
  118. $("#syndication-container button.btn-info").each(function(i,btn){
  119. syndications.push($(btn).data('syndication'));
  120. });
  121. $.post("/micropub/post", {
  122. content: $("#note_content").val(),
  123. 'in-reply-to': $("#note_in_reply_to").val(),
  124. location: $("#note_location").val(),
  125. category: csv_to_array($("#note_category").val()),
  126. slug: $("#note_slug").val(),
  127. 'syndicate-to': syndications
  128. }, function(data){
  129. var response = JSON.parse(data);
  130. if(response.location != false) {
  131. $("#note_form").slideUp(200, function(){
  132. $(window).scrollTop($("#test_success").position().top);
  133. });
  134. $("#test_success").removeClass('hidden');
  135. $("#test_error").addClass('hidden');
  136. $("#post_href").attr("href", response.location);
  137. $("#note_content").val("");
  138. $("#note_in_reply_to").val("");
  139. $("#note_category").val("");
  140. $("#note_slug").val("");
  141. } else {
  142. $("#test_success").addClass('hidden');
  143. $("#test_error").removeClass('hidden');
  144. }
  145. $("#last_response_date").html("(just now)");
  146. $("#test_request").html(response.request);
  147. $("#last_request_container").show();
  148. $("#test_response").html(response.response);
  149. });
  150. return false;
  151. });
  152. function location_error(msg) {
  153. $("#note_location_msg").val(msg);
  154. $("#note_location_chk").removeAttr("checked");
  155. $("#note_location_loading").hide();
  156. $("#note_location_img").hide();
  157. $("#note_location_msg").removeClass("img-visible");
  158. }
  159. var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>";
  160. var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>";
  161. function fetch_location() {
  162. $("#note_location_loading").show();
  163. navigator.geolocation.getCurrentPosition(function(position){
  164. $("#note_location_loading").hide();
  165. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  166. $("#note_location_msg").val(geo);
  167. $("#note_location").val(geo);
  168. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  169. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  170. $("#note_location_img").show();
  171. $("#note_location_msg").addClass("img-visible");
  172. }, function(err){
  173. if(err.code == 1) {
  174. location_error("The website was not able to get permission");
  175. } else if(err.code == 2) {
  176. location_error("Location information was unavailable");
  177. } else if(err.code == 3) {
  178. location_error("Timed out getting location");
  179. }
  180. });
  181. }
  182. $("#note_location_chk").click(function(){
  183. if($(this).attr("checked") == "checked") {
  184. if(navigator.geolocation) {
  185. $.post("/prefs", {
  186. enabled: 1
  187. });
  188. fetch_location();
  189. } else {
  190. location_error("Browser location is not supported");
  191. }
  192. } else {
  193. $("#note_location_img").hide();
  194. $("#note_location_msg").removeClass("img-visible");
  195. $("#note_location_msg").val('');
  196. $("#note_location").val('');
  197. $.post("/prefs", {
  198. enabled: 0
  199. });
  200. }
  201. });
  202. if($("#location_enabled").val() == 1) {
  203. $("#note_location_chk").attr("checked","checked");
  204. fetch_location();
  205. }
  206. bind_syndication_buttons();
  207. });
  208. <?= partial('partials/syndication-js') ?>
  209. </script>