wp/wp-includes/wp-diff.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Diff bastard child of old MediaWiki Diff Formatter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * Basically all that remains is the table structure and some method names.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @subpackage Diff
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
if ( !class_exists( 'Text_Diff' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
	/** Text_Diff class */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
	require( dirname(__FILE__).'/Text/Diff.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
	/** Text_Diff_Renderer class */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
	require( dirname(__FILE__).'/Text/Diff/Renderer.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
	/** Text_Diff_Renderer_inline class */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
	require( dirname(__FILE__).'/Text/Diff/Renderer/inline.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 * Table renderer to display the diff lines.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 * @uses Text_Diff_Renderer Extends
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	 * @see Text_Diff_Renderer::_leading_context_lines
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 * @var int
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
	public $_leading_context_lines  = 10000;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	 * @see Text_Diff_Renderer::_trailing_context_lines
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	 * @var int
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
	public $_trailing_context_lines = 10000;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
	 * Threshold for when a diff should be saved or omitted.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	 * @var float
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	 * @access protected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
	protected $_diff_threshold = 0.6;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	 * Inline display helper object name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	 * @access protected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
	protected $inline_diff_renderer = 'WP_Text_Diff_Renderer_inline';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	 * Should we show the split view or not
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	 * @access protected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
	protected $_show_split_view = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
	protected $compat_fields = array( '_show_split_view', 'inline_diff_renderer', '_diff_threshold' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	 * Constructor - Call parent constructor with params array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	 * This will set class properties based on the key value pairs in the array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	 * @param array $params
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
	public function __construct( $params = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
		parent::__construct( $params );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		if ( isset( $params[ 'show_split_view' ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
			$this->_show_split_view = $params[ 'show_split_view' ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	 * @ignore
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	 * @param string $header
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
	public function _startBlock( $header ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	 * @ignore
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	 * @param array $lines
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	 * @param string $prefix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
	public function _lines( $lines, $prefix=' ' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	 * @ignore
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	 * @param string $line HTML-escape the value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
	public function addedLine( $line ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		return "<td class='diff-addedline'>{$line}</td>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
	 * @ignore
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
	 * @param string $line HTML-escape the value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
	public function deletedLine( $line ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
		return "<td class='diff-deletedline'>{$line}</td>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	 * @ignore
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	 * @param string $line HTML-escape the value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
	public function contextLine( $line ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		return "<td class='diff-context'>{$line}</td>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
	 * @ignore
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
	public function emptyLine() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
		return '<td>&nbsp;</td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	 * @ignore
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	 * @param array $lines
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
	 * @param bool $encode
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
	public function _added( $lines, $encode = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
		$r = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
		foreach ($lines as $line) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
			if ( $encode ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
				$processed_line = htmlspecialchars( $line );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
				 * Contextually filter a diffed line.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   163
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
				 * Filters TextDiff processing of diffed line. By default, diffs are processed with
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
				 * htmlspecialchars. Use this filter to remove or change the processing. Passes a context
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
				 * indicating if the line is added, deleted or unchanged.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
				 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
				 * @param String $processed_line The processed diffed line.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
				 * @param String $line           The unprocessed diffed line.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
		 		 * @param string null            The line context. Values are 'added', 'deleted' or 'unchanged'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
				$line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'added' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
			if ( $this->_show_split_view ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
				$r .= '<tr>' . $this->emptyLine() . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
				$r .= '<tr>' . $this->addedLine( $line ) . "</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
		return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
	 * @ignore
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
	 * @param array $lines
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
	 * @param bool $encode
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
	public function _deleted( $lines, $encode = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
		$r = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
		foreach ($lines as $line) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
			if ( $encode ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
				$processed_line = htmlspecialchars( $line );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
				/** This filter is documented in wp-includes/wp-diff.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
				$line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'deleted' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
			if ( $this->_show_split_view ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
				$r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . $this->emptyLine() . "</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
				$r .= '<tr>' . $this->deletedLine( $line ) . "</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
	 * @ignore
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
	 * @param array $lines
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
	 * @param bool $encode
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
	public function _context( $lines, $encode = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		$r = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
		foreach ($lines as $line) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
			if ( $encode ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
				$processed_line = htmlspecialchars( $line );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
				/** This filter is documented in wp-includes/wp-diff.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
				$line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'unchanged' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
			if (  $this->_show_split_view ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
				$r .= '<tr>' . $this->contextLine( $line ) . $this->emptyLine() . $this->contextLine( $line )  . "</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
				$r .= '<tr>' . $this->contextLine( $line ) . "</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
		return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
	 * Process changed lines to do word-by-word diffs for extra highlighting.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
	 * (TRAC style) sometimes these lines can actually be deleted or added rows.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
	 * We do additional processing to figure that out
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
	 * @param array $orig
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	 * @param array $final
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
	public function _changed( $orig, $final ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
		$r = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		// Does the aforementioned additional processing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		// *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
		//	match is numeric: an index in other column
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
		//	match is 'X': no match. It is a new row
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
		// *_rows are column vectors for the orig column and the final column.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
		//	row >= 0: an indix of the $orig or $final array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
		//	row  < 0: a blank row for that column
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
		list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
		// These will hold the word changes as determined by an inline diff
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
		$orig_diffs  = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
		$final_diffs = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		// Compute word diffs for each matched pair using the inline diff
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
		foreach ( $orig_matches as $o => $f ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
			if ( is_numeric($o) && is_numeric($f) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
				$text_diff = new Text_Diff( 'auto', array( array($orig[$o]), array($final[$f]) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
				$renderer = new $this->inline_diff_renderer;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
				$diff = $renderer->render( $text_diff );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
				// If they're too different, don't include any <ins> or <dels>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
				if ( preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
					// length of all text between <ins> or <del>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
					$stripped_matches = strlen(strip_tags( join(' ', $diff_matches[0]) ));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
					// since we count lengith of text between <ins> or <del> (instead of picking just one),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
					//	we double the length of chars not in those tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
					$stripped_diff = strlen(strip_tags( $diff )) * 2 - $stripped_matches;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
					$diff_ratio = $stripped_matches / $stripped_diff;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
					if ( $diff_ratio > $this->_diff_threshold )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
						continue; // Too different. Don't save diffs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
				// Un-inline the diffs by removing del or ins
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
				$orig_diffs[$o]  = preg_replace( '|<ins>.*?</ins>|', '', $diff );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
				$final_diffs[$f] = preg_replace( '|<del>.*?</del>|', '', $diff );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
		foreach ( array_keys($orig_rows) as $row ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
			// Both columns have blanks. Ignore them.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
			if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
			// If we have a word based diff, use it. Otherwise, use the normal line.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
			if ( isset( $orig_diffs[$orig_rows[$row]] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
				$orig_line = $orig_diffs[$orig_rows[$row]];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
			elseif ( isset( $orig[$orig_rows[$row]] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
				$orig_line = htmlspecialchars($orig[$orig_rows[$row]]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
				$orig_line = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
			if ( isset( $final_diffs[$final_rows[$row]] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
				$final_line = $final_diffs[$final_rows[$row]];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
			elseif ( isset( $final[$final_rows[$row]] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
				$final_line = htmlspecialchars($final[$final_rows[$row]]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
				$final_line = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
			if ( $orig_rows[$row] < 0 ) { // Orig is blank. This is really an added row.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
				$r .= $this->_added( array($final_line), false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
			} elseif ( $final_rows[$row] < 0 ) { // Final is blank. This is really a deleted row.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
				$r .= $this->_deleted( array($orig_line), false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
			} else { // A true changed row.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
				if ( $this->_show_split_view ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
					$r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->emptyLine() . $this->addedLine( $final_line ) . "</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
					$r .= '<tr>' . $this->deletedLine( $orig_line ) . "</tr><tr>" . $this->addedLine( $final_line ) . "</tr>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
	 * Takes changed blocks and matches which rows in orig turned into which rows in final.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
	 * Returns
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
	 *	*_matches ( which rows match with which )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	 *	*_rows ( order of rows in each column interleaved with blank rows as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	 *		necessary )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
	 * @param array $orig
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
	 * @param array $final
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
	 * @return array
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
	public function interleave_changed_lines( $orig, $final ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
		// Contains all pairwise string comparisons. Keys are such that this need only be a one dimensional array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
		$matches = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
		foreach ( array_keys($orig) as $o ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
			foreach ( array_keys($final) as $f ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
				$matches["$o,$f"] = $this->compute_string_distance( $orig[$o], $final[$f] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		asort($matches); // Order by string distance.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
		$orig_matches  = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
		$final_matches = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		foreach ( $matches as $keys => $difference ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
			list($o, $f) = explode(',', $keys);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
			$o = (int) $o;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
			$f = (int) $f;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
			// Already have better matches for these guys
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
			if ( isset($orig_matches[$o]) && isset($final_matches[$f]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
			// First match for these guys. Must be best match
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
			if ( !isset($orig_matches[$o]) && !isset($final_matches[$f]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
				$orig_matches[$o] = $f;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
				$final_matches[$f] = $o;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
			// Best match of this final is already taken?  Must mean this final is a new row.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
			if ( isset($orig_matches[$o]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
				$final_matches[$f] = 'x';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
			// Best match of this orig is already taken?  Must mean this orig is a deleted row.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
			elseif ( isset($final_matches[$f]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
				$orig_matches[$o] = 'x';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
		// We read the text in this order
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
		ksort($orig_matches);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
		ksort($final_matches);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
		// Stores rows and blanks for each column.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
		$orig_rows = $orig_rows_copy = array_keys($orig_matches);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
		$final_rows = array_keys($final_matches);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
		// Interleaves rows with blanks to keep matches aligned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
		// We may end up with some extraneous blank rows, but we'll just ignore them later.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
		foreach ( $orig_rows_copy as $orig_row ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
			$final_pos = array_search($orig_matches[$orig_row], $final_rows, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
			$orig_pos = (int) array_search($orig_row, $orig_rows, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
			if ( false === $final_pos ) { // This orig is paired with a blank final.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
				array_splice( $final_rows, $orig_pos, 0, -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
			} elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
				$diff_pos = $final_pos - $orig_pos;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
				while ( $diff_pos < 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
					array_splice( $final_rows, $orig_pos, 0, $diff_pos++ );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
			} elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
				$diff_pos = $orig_pos - $final_pos;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
				while ( $diff_pos < 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
					array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
		// Pad the ends with blank rows if the columns aren't the same length
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
		$diff_count = count($orig_rows) - count($final_rows);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
		if ( $diff_count < 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
			while ( $diff_count < 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
				array_push($orig_rows, $diff_count++);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
		} elseif ( $diff_count > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
			$diff_count = -1 * $diff_count;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
			while ( $diff_count < 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
				array_push($final_rows, $diff_count++);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
		return array($orig_matches, $final_matches, $orig_rows, $final_rows);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	 * Computes a number that is intended to reflect the "distance" between two strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	 * @param string $string1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	 * @param string $string2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
	 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
	public function compute_string_distance( $string1, $string2 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		// Vectors containing character frequency for all chars in each string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
		$chars1 = count_chars($string1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		$chars2 = count_chars($string2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
		// L1-norm of difference vector.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
		$difference = array_sum( array_map( array($this, 'difference'), $chars1, $chars2 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
		// $string1 has zero length? Odd. Give huge penalty by not dividing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
		if ( !$string1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
			return $difference;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
		// Return distance per character (of string1).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
		return $difference / strlen($string1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	 * @ignore
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	 * @param int $a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	 * @param int $b
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
	public function difference( $a, $b ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
		return abs( $a - $b );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
	 * Make private properties readable for backwards compatibility.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
	 * @param string $name Property to get.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
	 * @return mixed Property.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
	public function __get( $name ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
		if ( in_array( $name, $this->compat_fields ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
			return $this->$name;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
	 * Make private properties settable for backwards compatibility.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
	 * @param string $name  Property to check if set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
	 * @param mixed  $value Property value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
	 * @return mixed Newly-set property.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
	public function __set( $name, $value ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
		if ( in_array( $name, $this->compat_fields ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
			return $this->$name = $value;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
	 * Make private properties checkable for backwards compatibility.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
	 * @param string $name Property to check if set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
	 * @return bool Whether the property is set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   499
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
	public function __isset( $name ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
		if ( in_array( $name, $this->compat_fields ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
			return isset( $this->$name );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
	 * Make private properties un-settable for backwards compatibility.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   511
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
	 * @param string $name Property to unset.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
	public function __unset( $name ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
		if ( in_array( $name, $this->compat_fields ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
			unset( $this->$name );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
 * Better word splitting than the PEAR package provides.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
 * @uses Text_Diff_Renderer_inline Extends
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
class WP_Text_Diff_Renderer_inline extends Text_Diff_Renderer_inline {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
	 * @ignore
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
	 * @param string $string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	 * @param string $newlineEscape
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
	public function _splitOnWords($string, $newlineEscape = "\n") {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
		$string = str_replace("\0", '', $string);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
		$words  = preg_split( '/([^\w])/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
		$words  = str_replace( "\n", $newlineEscape, $words );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
		return $words;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
}