Plugin Directory

Changeset 2782901


Ignore:
Timestamp:
09/11/2022 05:11:43 AM (4 years ago)
Author:
jwz
Message:

Version 1.1

Location:
wysiwyg-comments-trix
Files:
2 edited
10 copied

Legend:

Unmodified
Added
Removed
  • wysiwyg-comments-trix/tags/1.1/readme.txt

    r2735982 r2782901  
    55Requires at least: 2.7
    66Tested up to: 6.0
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: MIT
    99License URI: https://github.com/basecamp/trix/blob/main/LICENSE
     
    3131* Created
    3232
     33= 1.1 =
     34* Reject comments that appear to have been typed using raw HTML. The elderly will get used to the new way eventually.
     35
  • wysiwyg-comments-trix/tags/1.1/trixcomments.php

    r2735978 r2782901  
    33Plugin Name: WYSIWYG Comments with Trix Editor
    44Plugin URI: https://www.jwz.org/wysiwyg-comments-trix/
    5 Version: 1.0
     5Version: 1.1
    66Description: Replaces the comment submission form with a WYSIWYG rich-text editor.
    77Author: Jamie Zawinski
     
    2222 */
    2323
    24 $trixcomments_plugin_version   = "1.0";
     24$trixcomments_plugin_version   = "1.1";
    2525$trixcomments_plugin_title     = 'WYSIWYG Comments with Trix Editor';
    2626$trixcomments_plugin_name      = 'trixcomments';
     
    189189
    190190  // If there is a DIV with no tags inside it, that can go too.
    191   $html = preg_replace ('@<div>([^<>]*)</div>@si', "$1", $html);
     191  // $html = preg_replace ('@<div>([^<>]*)</div>@si', "$1", $html);
     192
     193  // I think that any remaining <div> or </div> can be converted to a newline.
     194  // Trix does not emit <div style>.
     195  $html = preg_replace ('@\n</?div\b[^<>]*>@si',  "\n", $html);
     196  $html = preg_replace ('@</?div\b[^<>]*>\n?@si', "\n", $html);
    192197
    193198  // At most 2 consecutive blank lines.
     
    195200
    196201  // Remove trailing blank lines.
    197   $html = preg_replace ('@\n+((</div>)*)$@si', '$1', $html);
     202  // $html = preg_replace ('@\n+((</div>)*)$@si', '$1', $html);
     203
     204  // Remove leading and trailing blank lines.
     205  $html = preg_replace ('/^\n+|\n+$/si', '', $html);
    198206
    199207  return $html;
     208}
     209
     210
     211// If someone appears to be typing raw HTML, make them go back and try again.
     212// Many long-time readers are are in the habit of doing that...
     213//
     214add_filter ('preprocess_comment', 'trixcomments_forbid_raw_html');
     215function trixcomments_forbid_raw_html ($commentdata) {
     216  $body = $commentdata['comment_content'];
     217  $body = wp_kses_stripslashes ($body);
     218  $body = preg_replace ('/&nbsp;/', ' ', $body);
     219  if (preg_match ('@&amp;lt;@si', $body) ||             // Literal &lt;
     220      preg_match ('@&lt;\s*(A|IMG)\s+(HREF|SRC)\s*=@si', $body) ||  // <A HREF=
     221      preg_match ('@&lt;\s*(VIDEO|IFRAME)\s+@si', $body) ||         // <IFRAME
     222      preg_match (
     223        '@&lt;\s*(B|I|EM|STRONG|TT|PRE|CODE|P|BR|BLOCKQUOTE)\s*&@si', // <B>
     224                  $body)) {
     225    wp_die (__('It looks like you are typing raw HTML. ' .
     226               'Go back and format using the toolbar instead.'));
     227  }
     228  return $commentdata;
    200229}
    201230
  • wysiwyg-comments-trix/tags/1.1/trunk/readme.txt

    r2735982 r2782901  
    55Requires at least: 2.7
    66Tested up to: 6.0
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: MIT
    99License URI: https://github.com/basecamp/trix/blob/main/LICENSE
     
    3131* Created
    3232
     33= 1.1 =
     34* Reject comments that appear to have been typed using raw HTML. The elderly will get used to the new way eventually.
     35
  • wysiwyg-comments-trix/tags/1.1/trunk/trixcomments.php

    r2735978 r2782901  
    33Plugin Name: WYSIWYG Comments with Trix Editor
    44Plugin URI: https://www.jwz.org/wysiwyg-comments-trix/
    5 Version: 1.0
     5Version: 1.1
    66Description: Replaces the comment submission form with a WYSIWYG rich-text editor.
    77Author: Jamie Zawinski
     
    2222 */
    2323
    24 $trixcomments_plugin_version   = "1.0";
     24$trixcomments_plugin_version   = "1.1";
    2525$trixcomments_plugin_title     = 'WYSIWYG Comments with Trix Editor';
    2626$trixcomments_plugin_name      = 'trixcomments';
     
    189189
    190190  // If there is a DIV with no tags inside it, that can go too.
    191   $html = preg_replace ('@<div>([^<>]*)</div>@si', "$1", $html);
     191  // $html = preg_replace ('@<div>([^<>]*)</div>@si', "$1", $html);
     192
     193  // I think that any remaining <div> or </div> can be converted to a newline.
     194  // Trix does not emit <div style>.
     195  $html = preg_replace ('@\n</?div\b[^<>]*>@si',  "\n", $html);
     196  $html = preg_replace ('@</?div\b[^<>]*>\n?@si', "\n", $html);
    192197
    193198  // At most 2 consecutive blank lines.
     
    195200
    196201  // Remove trailing blank lines.
    197   $html = preg_replace ('@\n+((</div>)*)$@si', '$1', $html);
     202  // $html = preg_replace ('@\n+((</div>)*)$@si', '$1', $html);
     203
     204  // Remove leading and trailing blank lines.
     205  $html = preg_replace ('/^\n+|\n+$/si', '', $html);
    198206
    199207  return $html;
     208}
     209
     210
     211// If someone appears to be typing raw HTML, make them go back and try again.
     212// Many long-time readers are are in the habit of doing that...
     213//
     214add_filter ('preprocess_comment', 'trixcomments_forbid_raw_html');
     215function trixcomments_forbid_raw_html ($commentdata) {
     216  $body = $commentdata['comment_content'];
     217  $body = wp_kses_stripslashes ($body);
     218  $body = preg_replace ('/&nbsp;/', ' ', $body);
     219  if (preg_match ('@&amp;lt;@si', $body) ||             // Literal &lt;
     220      preg_match ('@&lt;\s*(A|IMG)\s+(HREF|SRC)\s*=@si', $body) ||  // <A HREF=
     221      preg_match ('@&lt;\s*(VIDEO|IFRAME)\s+@si', $body) ||         // <IFRAME
     222      preg_match (
     223        '@&lt;\s*(B|I|EM|STRONG|TT|PRE|CODE|P|BR|BLOCKQUOTE)\s*&@si', // <B>
     224                  $body)) {
     225    wp_die (__('It looks like you are typing raw HTML. ' .
     226               'Go back and format using the toolbar instead.'));
     227  }
     228  return $commentdata;
    200229}
    201230
  • wysiwyg-comments-trix/trunk/readme.txt

    r2735982 r2782901  
    55Requires at least: 2.7
    66Tested up to: 6.0
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: MIT
    99License URI: https://github.com/basecamp/trix/blob/main/LICENSE
     
    3131* Created
    3232
     33= 1.1 =
     34* Reject comments that appear to have been typed using raw HTML. The elderly will get used to the new way eventually.
     35
  • wysiwyg-comments-trix/trunk/trixcomments.php

    r2735978 r2782901  
    33Plugin Name: WYSIWYG Comments with Trix Editor
    44Plugin URI: https://www.jwz.org/wysiwyg-comments-trix/
    5 Version: 1.0
     5Version: 1.1
    66Description: Replaces the comment submission form with a WYSIWYG rich-text editor.
    77Author: Jamie Zawinski
     
    2222 */
    2323
    24 $trixcomments_plugin_version   = "1.0";
     24$trixcomments_plugin_version   = "1.1";
    2525$trixcomments_plugin_title     = 'WYSIWYG Comments with Trix Editor';
    2626$trixcomments_plugin_name      = 'trixcomments';
     
    189189
    190190  // If there is a DIV with no tags inside it, that can go too.
    191   $html = preg_replace ('@<div>([^<>]*)</div>@si', "$1", $html);
     191  // $html = preg_replace ('@<div>([^<>]*)</div>@si', "$1", $html);
     192
     193  // I think that any remaining <div> or </div> can be converted to a newline.
     194  // Trix does not emit <div style>.
     195  $html = preg_replace ('@\n</?div\b[^<>]*>@si',  "\n", $html);
     196  $html = preg_replace ('@</?div\b[^<>]*>\n?@si', "\n", $html);
    192197
    193198  // At most 2 consecutive blank lines.
     
    195200
    196201  // Remove trailing blank lines.
    197   $html = preg_replace ('@\n+((</div>)*)$@si', '$1', $html);
     202  // $html = preg_replace ('@\n+((</div>)*)$@si', '$1', $html);
     203
     204  // Remove leading and trailing blank lines.
     205  $html = preg_replace ('/^\n+|\n+$/si', '', $html);
    198206
    199207  return $html;
     208}
     209
     210
     211// If someone appears to be typing raw HTML, make them go back and try again.
     212// Many long-time readers are are in the habit of doing that...
     213//
     214add_filter ('preprocess_comment', 'trixcomments_forbid_raw_html');
     215function trixcomments_forbid_raw_html ($commentdata) {
     216  $body = $commentdata['comment_content'];
     217  $body = wp_kses_stripslashes ($body);
     218  $body = preg_replace ('/&nbsp;/', ' ', $body);
     219  if (preg_match ('@&amp;lt;@si', $body) ||             // Literal &lt;
     220      preg_match ('@&lt;\s*(A|IMG)\s+(HREF|SRC)\s*=@si', $body) ||  // <A HREF=
     221      preg_match ('@&lt;\s*(VIDEO|IFRAME)\s+@si', $body) ||         // <IFRAME
     222      preg_match (
     223        '@&lt;\s*(B|I|EM|STRONG|TT|PRE|CODE|P|BR|BLOCKQUOTE)\s*&@si', // <B>
     224                  $body)) {
     225    wp_die (__('It looks like you are typing raw HTML. ' .
     226               'Go back and format using the toolbar instead.'));
     227  }
     228  return $commentdata;
    200229}
    201230
Note: See TracChangeset for help on using the changeset viewer.