Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordfenc.../lib/Diff/Renderer/Html
File: Array.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Base renderer for rendering HTML based diffs for PHP DiffLib.
[2] Fix | Delete
*
[3] Fix | Delete
* PHP version 5
[4] Fix | Delete
*
[5] Fix | Delete
* Copyright (c) 2009 Chris Boulton <chris.boulton@interspire.com>
[6] Fix | Delete
*
[7] Fix | Delete
* All rights reserved.
[8] Fix | Delete
*
[9] Fix | Delete
* Redistribution and use in source and binary forms, with or without
[10] Fix | Delete
* modification, are permitted provided that the following conditions are met:
[11] Fix | Delete
*
[12] Fix | Delete
* - Redistributions of source code must retain the above copyright notice,
[13] Fix | Delete
* this list of conditions and the following disclaimer.
[14] Fix | Delete
* - Redistributions in binary form must reproduce the above copyright notice,
[15] Fix | Delete
* this list of conditions and the following disclaimer in the documentation
[16] Fix | Delete
* and/or other materials provided with the distribution.
[17] Fix | Delete
* - Neither the name of the Chris Boulton nor the names of its contributors
[18] Fix | Delete
* may be used to endorse or promote products derived from this software
[19] Fix | Delete
* without specific prior written permission.
[20] Fix | Delete
*
[21] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
[22] Fix | Delete
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
[23] Fix | Delete
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
[24] Fix | Delete
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
[25] Fix | Delete
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
[26] Fix | Delete
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
[27] Fix | Delete
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
[28] Fix | Delete
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
[29] Fix | Delete
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
[30] Fix | Delete
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
[31] Fix | Delete
* POSSIBILITY OF SUCH DAMAGE.
[32] Fix | Delete
*
[33] Fix | Delete
* @package DiffLib
[34] Fix | Delete
* @author Chris Boulton <chris.boulton@interspire.com>
[35] Fix | Delete
* @copyright (c) 2009 Chris Boulton
[36] Fix | Delete
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
[37] Fix | Delete
* @version 1.1
[38] Fix | Delete
* @link http://github.com/chrisboulton/php-diff
[39] Fix | Delete
*/
[40] Fix | Delete
[41] Fix | Delete
require_once(dirname(__FILE__) . '/../Abstract.php');
[42] Fix | Delete
[43] Fix | Delete
class Diff_Renderer_Html_Array extends Diff_Renderer_Abstract
[44] Fix | Delete
{
[45] Fix | Delete
/**
[46] Fix | Delete
* @var array Array of the default options that apply to this renderer.
[47] Fix | Delete
*/
[48] Fix | Delete
protected $defaultOptions = array(
[49] Fix | Delete
'tabSize' => 4
[50] Fix | Delete
);
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Render and return an array structure suitable for generating HTML
[54] Fix | Delete
* based differences. Generally called by subclasses that generate a
[55] Fix | Delete
* HTML based diff and return an array of the changes to show in the diff.
[56] Fix | Delete
*
[57] Fix | Delete
* @return array An array of the generated chances, suitable for presentation in HTML.
[58] Fix | Delete
*/
[59] Fix | Delete
public function render()
[60] Fix | Delete
{
[61] Fix | Delete
// As we'll be modifying a & b to include our change markers,
[62] Fix | Delete
// we need to get the contents and store them here. That way
[63] Fix | Delete
// we're not going to destroy the original data
[64] Fix | Delete
$a = $this->diff->getA();
[65] Fix | Delete
$b = $this->diff->getB();
[66] Fix | Delete
[67] Fix | Delete
$changes = array();
[68] Fix | Delete
$opCodes = $this->diff->getGroupedOpcodes();
[69] Fix | Delete
foreach($opCodes as $group) {
[70] Fix | Delete
$blocks = array();
[71] Fix | Delete
$lastTag = null;
[72] Fix | Delete
$lastBlock = 0;
[73] Fix | Delete
foreach($group as $code) {
[74] Fix | Delete
list($tag, $i1, $i2, $j1, $j2) = $code;
[75] Fix | Delete
[76] Fix | Delete
if($tag == 'replace' && $i2 - $i1 == $j2 - $j1) {
[77] Fix | Delete
for($i = 0; $i < ($i2 - $i1); ++$i) {
[78] Fix | Delete
$fromLine = $a[$i1 + $i];
[79] Fix | Delete
$toLine = $b[$j1 + $i];
[80] Fix | Delete
[81] Fix | Delete
list($start, $end) = $this->getChangeExtent($fromLine, $toLine);
[82] Fix | Delete
if($start != 0 || $end != 0) {
[83] Fix | Delete
$last = $end + strlen($fromLine);
[84] Fix | Delete
$fromLine = substr_replace($fromLine, "\0", $start, 0);
[85] Fix | Delete
$fromLine = substr_replace($fromLine, "\1", $last + 1, 0);
[86] Fix | Delete
$last = $end + strlen($toLine);
[87] Fix | Delete
$toLine = substr_replace($toLine, "\0", $start, 0);
[88] Fix | Delete
$toLine = substr_replace($toLine, "\1", $last + 1, 0);
[89] Fix | Delete
$a[$i1 + $i] = $fromLine;
[90] Fix | Delete
$b[$j1 + $i] = $toLine;
[91] Fix | Delete
}
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
if($tag != $lastTag) {
[96] Fix | Delete
$blocks[] = array(
[97] Fix | Delete
'tag' => $tag,
[98] Fix | Delete
'base' => array(
[99] Fix | Delete
'offset' => $i1,
[100] Fix | Delete
'lines' => array()
[101] Fix | Delete
),
[102] Fix | Delete
'changed' => array(
[103] Fix | Delete
'offset' => $j1,
[104] Fix | Delete
'lines' => array()
[105] Fix | Delete
)
[106] Fix | Delete
);
[107] Fix | Delete
$lastBlock = count($blocks)-1;
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
$lastTag = $tag;
[111] Fix | Delete
[112] Fix | Delete
if($tag == 'equal') {
[113] Fix | Delete
$lines = array_slice($a, $i1, ($i2 - $i1));
[114] Fix | Delete
$blocks[$lastBlock]['base']['lines'] += $this->formatLines($lines);
[115] Fix | Delete
$lines = array_slice($b, $j1, ($j2 - $j1));
[116] Fix | Delete
$blocks[$lastBlock]['changed']['lines'] += $this->formatLines($lines);
[117] Fix | Delete
}
[118] Fix | Delete
else {
[119] Fix | Delete
if($tag == 'replace' || $tag == 'delete') {
[120] Fix | Delete
$lines = array_slice($a, $i1, ($i2 - $i1));
[121] Fix | Delete
$lines = $this->formatLines($lines);
[122] Fix | Delete
$lines = str_replace(array("\0", "\1"), array('<del>', '</del>'), $lines);
[123] Fix | Delete
$blocks[$lastBlock]['base']['lines'] += $lines;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
if($tag == 'replace' || $tag == 'insert') {
[127] Fix | Delete
$lines = array_slice($b, $j1, ($j2 - $j1));
[128] Fix | Delete
$lines = $this->formatLines($lines);
[129] Fix | Delete
$lines = str_replace(array("\0", "\1"), array('<ins>', '</ins>'), $lines);
[130] Fix | Delete
$blocks[$lastBlock]['changed']['lines'] += $lines;
[131] Fix | Delete
}
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
$changes[] = $blocks;
[135] Fix | Delete
}
[136] Fix | Delete
return $changes;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Given two strings, determine where the changes in the two strings
[141] Fix | Delete
* begin, and where the changes in the two strings end.
[142] Fix | Delete
*
[143] Fix | Delete
* @param string $fromLine The first string.
[144] Fix | Delete
* @param string $toLine The second string.
[145] Fix | Delete
* @return array Array containing the starting position (0 by default) and the ending position (-1 by default)
[146] Fix | Delete
*/
[147] Fix | Delete
private function getChangeExtent($fromLine, $toLine)
[148] Fix | Delete
{
[149] Fix | Delete
$start = 0;
[150] Fix | Delete
$limit = min(strlen($fromLine), strlen($toLine));
[151] Fix | Delete
while($start < $limit && $fromLine[$start] == $toLine[$start]) {
[152] Fix | Delete
++$start;
[153] Fix | Delete
}
[154] Fix | Delete
$end = -1;
[155] Fix | Delete
$limit = $limit - $start;
[156] Fix | Delete
while(-$end <= $limit && substr($fromLine, $end, 1) == substr($toLine, $end, 1)) {
[157] Fix | Delete
--$end;
[158] Fix | Delete
}
[159] Fix | Delete
return array(
[160] Fix | Delete
$start,
[161] Fix | Delete
$end + 1
[162] Fix | Delete
);
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Format a series of lines suitable for output in a HTML rendered diff.
[167] Fix | Delete
* This involves replacing tab characters with spaces, making the HTML safe
[168] Fix | Delete
* for output, ensuring that double spaces are replaced with &nbsp; etc.
[169] Fix | Delete
*
[170] Fix | Delete
* @param array $lines Array of lines to format.
[171] Fix | Delete
* @return array Array of the formatted lines.
[172] Fix | Delete
*/
[173] Fix | Delete
private function formatLines($lines)
[174] Fix | Delete
{
[175] Fix | Delete
$lines = array_map(array($this, 'ExpandTabs'), $lines);
[176] Fix | Delete
$lines = array_map(array($this, 'HtmlSafe'), $lines);
[177] Fix | Delete
foreach($lines as &$line) {
[178] Fix | Delete
$line = preg_replace_callback('# ( +)|^ #', array($this, 'fixSpacesCallback'), $line);
[179] Fix | Delete
}
[180] Fix | Delete
return $lines;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* Using a callback here instead of the /e modifier in preg_replace (now deprecated).
[185] Fix | Delete
*
[186] Fix | Delete
* @param $matches
[187] Fix | Delete
* @return string
[188] Fix | Delete
*/
[189] Fix | Delete
private function fixSpacesCallback($matches)
[190] Fix | Delete
{
[191] Fix | Delete
$spaces = (isset($matches[1]) ? $matches[1] : '');
[192] Fix | Delete
return $this->fixSpaces($spaces);
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/**
[196] Fix | Delete
* Replace a string containing spaces with a HTML representation using &nbsp;.
[197] Fix | Delete
*
[198] Fix | Delete
* @param string $spaces The string of spaces.
[199] Fix | Delete
* @return string The HTML representation of the string.
[200] Fix | Delete
*/
[201] Fix | Delete
function fixSpaces($spaces='')
[202] Fix | Delete
{
[203] Fix | Delete
$count = strlen($spaces);
[204] Fix | Delete
if($count == 0) {
[205] Fix | Delete
return '';
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
$div = floor($count / 2);
[209] Fix | Delete
$mod = $count % 2;
[210] Fix | Delete
return str_repeat('&nbsp; ', $div).str_repeat('&nbsp;', $mod);
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Replace tabs in a single line with a number of spaces as defined by the tabSize option.
[215] Fix | Delete
*
[216] Fix | Delete
* @param string $line The containing tabs to convert.
[217] Fix | Delete
* @return string The line with the tabs converted to spaces.
[218] Fix | Delete
*/
[219] Fix | Delete
private function expandTabs($line)
[220] Fix | Delete
{
[221] Fix | Delete
return str_replace("\t", str_repeat(' ', $this->options['tabSize']), $line);
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Make a string containing HTML safe for output on a page.
[226] Fix | Delete
*
[227] Fix | Delete
* @param string $string The string.
[228] Fix | Delete
* @return string The string with the HTML characters replaced by entities.
[229] Fix | Delete
*/
[230] Fix | Delete
private function htmlSafe($string)
[231] Fix | Delete
{
[232] Fix | Delete
return @htmlspecialchars($string, ENT_NOQUOTES, 'UTF-8');
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function