config-unignore.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /*
  3. * Called by the TinyMCE plugin when Ignore Always is clicked (setup as an action through admin-ajax.php)
  4. */
  5. function AtD_ignore_call() {
  6. if ( ! AtD_is_allowed() )
  7. return;
  8. $user = wp_get_current_user();
  9. if ( ! $user || $user->ID == 0 )
  10. return;
  11. check_admin_referer( 'atd_ignore' );
  12. $ignores = explode( ',', AtD_get_setting( $user->ID, 'AtD_ignored_phrases') );
  13. array_push( $ignores, $_GET['phrase'] );
  14. $ignores = array_filter( array_map( 'strip_tags', $ignores ) );
  15. AtD_update_setting( $user->ID, 'AtD_ignored_phrases', implode( ',', $ignores ) );
  16. header( 'Content-Type: text/xml' );
  17. echo '<success></success>';
  18. die();
  19. }
  20. /*
  21. * Called when a POST occurs, used to save AtD ignored phrases
  22. */
  23. function AtD_process_unignore_update() {
  24. if ( ! AtD_is_allowed() )
  25. return;
  26. if ( ! isset( $_POST['AtD_ignored_phrases'] ) )
  27. return;
  28. $user = wp_get_current_user();
  29. if ( ! $user || $user->ID == 0 )
  30. return;
  31. $ignores = array_filter( array_map( 'strip_tags', explode( ',', $_POST['AtD_ignored_phrases'] ) ) );
  32. AtD_update_setting( $user->ID, 'AtD_ignored_phrases', join( ',', $ignores ) );
  33. }
  34. /*
  35. * Display the AtD unignore form on a page
  36. */
  37. function AtD_display_unignore_form() {
  38. if ( ! AtD_is_allowed() )
  39. return;
  40. $user = wp_get_current_user();
  41. if ( ! $user || $user->ID == 0 )
  42. return;
  43. $ignores = AtD_get_setting( $user->ID, 'AtD_ignored_phrases' );
  44. ?>
  45. <script>
  46. function atd_show_phrases( ignored )
  47. {
  48. var element = jQuery( '#atd_ignores' ),
  49. items = [],
  50. delLink;
  51. ignored.sort();
  52. element.empty();
  53. for ( var i = 0; i < ignored.length; i++ ) {
  54. if ( ignored[i].length > 0 ) {
  55. delLink = jQuery( '<span id="atd_' + i + '">&nbsp;</span>' );
  56. delLink
  57. .text( delLink.text() + ignored[i] )
  58. .prepend( jQuery( '<a class="ntdelbutton">X</a>' ).data( 'ignored', ignored[i] ) );
  59. element.append( delLink ).append( '<br />' );
  60. }
  61. }
  62. }
  63. function atd_unignore( phrase ) {
  64. /* get the ignored values and remove the unwanted phrase */
  65. var ignored = jQuery( '#AtD_ignored_phrases' ).val().split( /,/g );
  66. ignored = jQuery.map(ignored, function(value, index) { return value == phrase ? null : value; });
  67. jQuery( '#AtD_ignored_phrases' ).val( ignored.join(',') );
  68. /* update the UI */
  69. atd_show_phrases( ignored );
  70. /* show a nifty message to the user */
  71. jQuery( '#AtD_message' ).show();
  72. }
  73. function atd_ignore () {
  74. /* get the ignored values and update the hidden field */
  75. var ignored = jQuery( '#AtD_ignored_phrases' ).val().split( /,/g );
  76. jQuery.map(jQuery( '#AtD_add_ignore' ).val().split(/,\s*/g), function(value, index) { ignored.push(value); });
  77. jQuery( '#AtD_ignored_phrases' ).val( ignored.join(',') );
  78. /* update the UI */
  79. atd_show_phrases( ignored );
  80. jQuery( '#AtD_add_ignore' ).val('');
  81. /* show that nifteroo messaroo to the useroo */
  82. jQuery( '#AtD_message' ).show();
  83. }
  84. function atd_ignore_init() {
  85. jQuery( '#AtD_message' ).hide();
  86. jQuery( '#atd_ignores' ).on( 'click', 'a', function() {
  87. atd_unignore( jQuery(this).data( 'ignored' ) );
  88. return false;
  89. } );
  90. atd_show_phrases( jQuery( '#AtD_ignored_phrases' ).val().split( /,/g ) );
  91. }
  92. /* document.ready() does not execute in IE6 unless it's at the bottom of the page. oi! */
  93. if (navigator.appName == 'Microsoft Internet Explorer')
  94. setTimeout( atd_ignore_init, 2500 );
  95. else
  96. jQuery( document ).ready( atd_ignore_init );
  97. </script>
  98. <input type="hidden" name="AtD_ignored_phrases" id="AtD_ignored_phrases" value="<?php echo esc_attr( $ignores ); ?>">
  99. <p style="font-weight: bold"><?php _e( 'Ignored Phrases', 'jetpack' ); ?></p>
  100. <p><?php _e( 'Identify words and phrases to ignore while proofreading your posts and pages:', 'jetpack' ); ?></p>
  101. <p><input type="text" id="AtD_add_ignore" name="AtD_add_ignore"> <input type="button" value="<?php esc_attr_e( 'Add', 'jetpack' ); ?>" onclick="javascript:atd_ignore()"></p>
  102. <div class="tagchecklist" id="atd_ignores"></div>
  103. <div class="plugin-update-tr" id="AtD_message" style="display: none">
  104. <div class="update-message"><strong><?php _e( 'Be sure to click "Update Profile" at the bottom of the screen to save your changes.', 'jetpack' ); ?></strong></div>
  105. </div>
  106. </td>
  107. </tr>
  108. </table>
  109. <?php
  110. }