Plugin Directory

Changeset 3139434


Ignore:
Timestamp:
08/22/2024 05:47:25 AM (19 months ago)
Author:
mdawaffe
Message:

Simplify diff generation.

Some extra escaping.

Location:
email-post-changes/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • email-post-changes/trunk/class.email-post-changes.php

    r3139338 r3139434  
    190190
    191191            // HTML
    192             $html_diff_head  = '<h2>' . sprintf( __( '%s changed' ), $post_type_label ) . "</h2>\n";
    193             $html_diff_head .= '<p>' . sprintf( $head_sprintf,
     192            $html_diff_head  = '<h2>' . sprintf( esc_html__( '%s changed' ), $post_type_label ) . "</h2>\n";
     193            $html_diff_head .= '<p>' . sprintf( esc_html( $head_sprintf ),
    194194                esc_html( $the_author ),
    195195                "<a href='$the_permalink'>" . esc_html( $the_title ) . '</a>',
    196                 "<a href='$the_edit_link'>" . __( '[edit]' ) . '</a>',
    197                 $post_type_label,
    198                 $the_date
     196                "<a href='$the_edit_link'>" . esc_html__( '[edit]' ) . '</a>',
     197                esc_html( $post_type_label ),
     198                esc_html( $the_date )
    199199            ) . "</p>\n\n";
    200200
     
    213213
    214214            // Replace classes with inline style
    215             $html_diff = str_replace( "class='diff'", 'style="width: 100%; border-collapse: collapse; border: none; white-space: pre-wrap; word-wrap: break-word; font-family: Consolas,Monaco,Courier,monospace;"', $html_diff );
    216             $html_diff = preg_replace( '#<col[^>]+/?>#i', '', $html_diff );
    217             $html_diff = str_replace( "class='diff-deletedline'", 'style="padding: 5px; width: 50%; background-color: #fdd;"', $html_diff );
    218             $html_diff = str_replace( "class='diff-addedline'", 'style="padding: 5px; width: 50%; background-color: #dfd;"', $html_diff );
    219             $html_diff = str_replace( "class='diff-context'", 'style="padding: 5px; width: 50%;"', $html_diff );
    220             $html_diff = str_replace( '<td>', '<td style="padding: 5px;">', $html_diff );
    221215            $html_diff = str_replace( '<del>', '<del style="text-decoration: none; background-color: #f99;">', $html_diff );
    222216            $html_diff = str_replace( '<ins>', '<ins style="text-decoration: none; background-color: #9f9;">', $html_diff );
     
    316310        $return['enable'] = ( empty( $options['enable'] ) ) ? 0 : 1;
    317311
    318         if ( empty( $options['users'] ) || !is_array( $options ) ) {
     312        if ( empty( $options['users'] ) || ! is_array( $options['users'] ) ) {
    319313            $return['users'] = $this->defaults['users'];
    320314        } else {
     
    358352        }
    359353
    360         if ( empty( $options['post_types'] ) || !is_array( $options ) ) {
     354        if ( empty( $options['post_types'] ) || ! is_array( $options['post_types'] ) ) {
    361355            $return['post_types'] = $this->defaults['post_types'];
    362356        } else {
     
    380374                sprintf(
    381375                    /* Translators: Comma-separated list of invalid email addresses. */
    382                     _n( 'Invalid Email: %s', 'Invalid Emails: %s', is_countable( $options['invalid_emails'] ) ? count( $options['invalid_emails'] ) : 0 ),
     376                    esc_html( _n( 'Invalid Email: %s', 'Invalid Emails: %s', is_countable( $options['invalid_emails'] ) ? count( $options['invalid_emails'] ) : 0 ) ),
    383377                    '<kbd>' . implode( '</kbd>, <kbd>', array_map( 'esc_html', $options['invalid_emails'] ) )
    384378                )
     
    515509            return '';
    516510
    517         $r  = "<table class='diff'>\n";
    518         $r .= "<col class='ltype' /><col class='content' /><col class='ltype' /><col class='content' />";
     511        $r  = "<table style='width: 100%; border-collapse: collapse; border: none; white-space: pre-wrap; word-wrap: break-word; font-family: Consolas,Monaco,Courier,monospace;'>\n";
    519512
    520513        if ( $args['title'] || $args['title_left'] || $args['title_right'] )
    521             $r .= "<thead>";
     514            $r .= "<thead>\n";
    522515        if ( $args['title'] )
    523             $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n";
     516            $r .= "<tr class='diff-title'><th colspan='4'>" . esc_html( $args['title'] ) . "</th></tr>\n";
    524517        if ( $args['title_left'] || $args['title_right'] ) {
    525518            $r .= "<tr class='diff-sub-title'>\n";
    526             $r .= "\t<td></td><th>$args[title_left]</th>\n";
    527             $r .= "\t<td></td><th>$args[title_right]</th>\n";
     519            $r .= "\t<td></td><th>" . esc_html( $args['title_left'] ) . "</th>\n";
     520            $r .= "\t<td></td><th>" . esc_html( $args['title_right'] ) . "</th>\n";
    528521            $r .= "</tr>\n";
    529522        }
     
    542535    var $_leading_context_lines  = 2;
    543536    var $_trailing_context_lines = 2;
     537
     538    /**
     539     * @ignore
     540     *
     541     * @param string $line HTML-escape the value.
     542     * @return string
     543     */
     544    public function addedLine( $line ) {
     545        return "<td style='padding: 5px; width: 1em; text-align: end;' aria-label='" . __( 'Added:' ) . "'><span aria-hidden='true'>+</span></td>"
     546            . "<td style='padding: 5px; width: 50%; width: calc( 50% - 1em - 10px ); background-color: #dfd;'>{$line}</td>";
     547    }
     548
     549    /**
     550     * @ignore
     551     *
     552     * @param string $line HTML-escape the value.
     553     * @return string
     554     */
     555    public function deletedLine( $line ) {
     556        return "<td style='padding: 5px; width: 1em; text-align: end;' aria-label='" . __( 'Deleted:' ) . "'><span aria-hidden='true'>-</span></td>"
     557            . "<td style='padding: 5px; width: 50%; width: calc( 50% - 1em - 10px ); background-color: #fdd;'>{$line}</td>";
     558    }
     559
     560    /**
     561     * @ignore
     562     *
     563     * @param string $line HTML-escape the value.
     564     * @return string
     565     */
     566    public function contextLine( $line ) {
     567        return "<td style='padding: 5px; width: 1em;' aria-label='" . __( 'Unchanged:' ) . "'><span aria-hidden='true'>&nbsp;</span></td>"
     568            . "<td style='padding: 5px; width: 50%; width: calc( 50% - 1em - 10px );'>{$line}</td>";
     569    }
     570
     571    /**
     572     * @ignore
     573     *
     574     * @return string
     575     */
     576    public function emptyLine() {
     577        return '<td colspan="2" style="padding: 5px;">&nbsp;</td>';
     578    }
    544579}
  • email-post-changes/trunk/email-post-changes.php

    r3139338 r3139434  
    55Description: Whenever a change to a post or page is made, those changes are emailed to the users and email addresses you specify.
    66Plugin URI: http://wordpress.org/extend/plugins/email-post-changes/
    7 Version: 1.7.2
     7Version: 1.8
    88Author: Michael D Adams
    99Author URI: http://blogwaffe.com/
Note: See TracChangeset for help on using the changeset viewer.