| [ Index ] |
PHP Cross Reference of MyBB 1.6.5 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * "Inline" diff renderer. 4 * 5 * $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.4.10.14 2008/01/04 10:37:27 jan Exp $ 6 * 7 * Copyright 2004-2008 The Horde Project (http://www.horde.org/) 8 * 9 * See the enclosed file COPYING for license information (LGPL). If you did 10 * not receive this file, see http://opensource.org/licenses/lgpl-license.php. 11 * 12 * @author Ciprian Popovici 13 * @package Text_Diff 14 */ 15 16 // Disallow direct access to this file for security reasons 17 if(!defined("IN_MYBB")) 18 { 19 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 20 } 21 22 /** Text_Diff_Renderer */ 23 require_once MYBB_ROOT.'inc/3rdparty/diff/Diff/Renderer.php'; 24 25 /** 26 * "Inline" diff renderer. 27 * 28 * This class renders diffs in the Wiki-style "inline" format. 29 * 30 * @author Ciprian Popovici 31 * @package Text_Diff 32 */ 33 class Text_Diff_Renderer_inline extends Text_Diff_Renderer { 34 35 /** 36 * Number of leading context "lines" to preserve. 37 */ 38 var $_leading_context_lines = 10000; 39 40 /** 41 * Number of trailing context "lines" to preserve. 42 */ 43 var $_trailing_context_lines = 10000; 44 45 /** 46 * Prefix for inserted text. 47 */ 48 var $_ins_prefix = '<ins>'; 49 50 /** 51 * Suffix for inserted text. 52 */ 53 var $_ins_suffix = '</ins>'; 54 55 /** 56 * Prefix for deleted text. 57 */ 58 var $_del_prefix = '<del>'; 59 60 /** 61 * Suffix for deleted text. 62 */ 63 var $_del_suffix = '</del>'; 64 65 /** 66 * Header for each change block. 67 */ 68 var $_block_header = ''; 69 70 /** 71 * What are we currently splitting on? Used to recurse to show word-level 72 * changes. 73 */ 74 var $_split_level = 'lines'; 75 76 function _blockHeader($xbeg, $xlen, $ybeg, $ylen) 77 { 78 return $this->_block_header; 79 } 80 81 function _startBlock($header) 82 { 83 return $header; 84 } 85 86 function _lines($lines, $prefix = ' ', $encode = true) 87 { 88 if ($encode) { 89 array_walk($lines, array(&$this, '_encode')); 90 } 91 92 if ($this->_split_level == 'words') { 93 return implode('', $lines); 94 } else { 95 return implode("\n", $lines) . "\n"; 96 } 97 } 98 99 function _added($lines) 100 { 101 array_walk($lines, array(&$this, '_encode')); 102 $lines[0] = $this->_ins_prefix . $lines[0]; 103 $lines[count($lines) - 1] .= $this->_ins_suffix; 104 return $this->_lines($lines, ' ', false); 105 } 106 107 function _deleted($lines, $words = false) 108 { 109 array_walk($lines, array(&$this, '_encode')); 110 $lines[0] = $this->_del_prefix . $lines[0]; 111 $lines[count($lines) - 1] .= $this->_del_suffix; 112 return $this->_lines($lines, ' ', false); 113 } 114 115 function _changed($orig, $final) 116 { 117 /* If we've already split on words, don't try to do so again - just 118 * display. */ 119 if ($this->_split_level == 'words') { 120 $prefix = ''; 121 while ($orig[0] !== false && $final[0] !== false && 122 substr($orig[0], 0, 1) == ' ' && 123 substr($final[0], 0, 1) == ' ') { 124 $prefix .= substr($orig[0], 0, 1); 125 $orig[0] = substr($orig[0], 1); 126 $final[0] = substr($final[0], 1); 127 } 128 return $prefix . $this->_deleted($orig) . $this->_added($final); 129 } 130 131 $text1 = implode("\n", $orig); 132 $text2 = implode("\n", $final); 133 134 /* Non-printing newline marker. */ 135 $nl = "\0"; 136 137 /* We want to split on word boundaries, but we need to 138 * preserve whitespace as well. Therefore we split on words, 139 * but include all blocks of whitespace in the wordlist. */ 140 $diff = new Text_Diff($this->_splitOnWords($text1, $nl), 141 $this->_splitOnWords($text2, $nl)); 142 143 /* Get the diff in inline format. */ 144 $renderer = new Text_Diff_Renderer_inline(array_merge($this->getParams(), 145 array('split_level' => 'words'))); 146 147 /* Run the diff and get the output. */ 148 return str_replace($nl, "\n", $renderer->render($diff)) . "\n"; 149 } 150 151 function _splitOnWords($string, $newlineEscape = "\n") 152 { 153 // Ignore \0; otherwise the while loop will never finish. 154 $string = str_replace("\0", '', $string); 155 156 $words = array(); 157 $length = strlen($string); 158 $pos = 0; 159 160 while ($pos < $length) { 161 // Eat a word with any preceding whitespace. 162 $spaces = strspn(substr($string, $pos), " \n"); 163 $nextpos = strcspn(substr($string, $pos + $spaces), " \n"); 164 $words[] = str_replace("\n", $newlineEscape, substr($string, $pos, $spaces + $nextpos)); 165 $pos += $spaces + $nextpos; 166 } 167 168 return $words; 169 } 170 171 function _encode(&$string) 172 { 173 $string = htmlspecialchars($string); 174 } 175 176 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Dec 11 14:16:27 2011 | Cross-referenced by PHPXref 0.7.1 |