Diff
8 years ago
dashboard
7 years ago
rest-api
7 years ago
.htaccess
7 years ago
Diff.php
14 years ago
GeoLite2-Country.mmdb
7 years ago
IPTraf.php
8 years ago
IPTrafList.php
7 years ago
compat.php
8 years ago
conntest.php
7 years ago
cronview.php
8 years ago
dbview.php
8 years ago
diffResult.php
8 years ago
email_genericAlert.php
7 years ago
email_newIssues.php
7 years ago
email_unlockRequest.php
8 years ago
email_unsubscribeRequest.php
7 years ago
flags.php
7 years ago
live_activity.php
8 years ago
menu_dashboard.php
7 years ago
menu_dashboard_options.php
7 years ago
menu_firewall.php
7 years ago
menu_firewall_blocking.php
7 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
7 years ago
menu_firewall_waf_options.php
7 years ago
menu_options.php
7 years ago
menu_scanner.php
7 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
8 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
7 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
7 years ago
menu_tools_twoFactor.php
8 years ago
menu_tools_whois.php
8 years ago
menu_wordfence_central.php
7 years ago
sysinfo.php
8 years ago
unknownFiles.php
8 years ago
viewFullActivityLog.php
8 years ago
wf503.php
7 years ago
wfAPI.php
7 years ago
wfActivityReport.php
7 years ago
wfAdminNoticeQueue.php
8 years ago
wfArray.php
7 years ago
wfBrowscap.php
8 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
9 years ago
wfCentralAPI.php
7 years ago
wfConfig.php
7 years ago
wfCrawl.php
8 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
8 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
7 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
7 years ago
wfImportExportController.php
7 years ago
wfIssues.php
7 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
7 years ago
wfMD5BloomFilter.php
8 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
7 years ago
wfScan.php
7 years ago
wfScanEngine.php
7 years ago
wfSchema.php
7 years ago
wfStyle.php
7 years ago
wfSupportController.php
7 years ago
wfUnlockMsg.php
7 years ago
wfUpdateCheck.php
8 years ago
wfUtils.php
7 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
7 years ago
wordfenceConstants.php
7 years ago
wordfenceHash.php
7 years ago
wordfenceScanner.php
7 years ago
wordfenceURLHoover.php
7 years ago
Diff.php
177 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Diff |
| 4 | * |
| 5 | * A comprehensive library for generating differences between two strings |
| 6 | * in multiple formats (unified, side by side HTML etc) |
| 7 | * |
| 8 | * PHP version 5 |
| 9 | * |
| 10 | * Copyright (c) 2009 Chris Boulton <chris.boulton@interspire.com> |
| 11 | * |
| 12 | * All rights reserved. |
| 13 | * |
| 14 | * Redistribution and use in source and binary forms, with or without |
| 15 | * modification, are permitted provided that the following conditions are met: |
| 16 | * |
| 17 | * - Redistributions of source code must retain the above copyright notice, |
| 18 | * this list of conditions and the following disclaimer. |
| 19 | * - Redistributions in binary form must reproduce the above copyright notice, |
| 20 | * this list of conditions and the following disclaimer in the documentation |
| 21 | * and/or other materials provided with the distribution. |
| 22 | * - Neither the name of the Chris Boulton nor the names of its contributors |
| 23 | * may be used to endorse or promote products derived from this software |
| 24 | * without specific prior written permission. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | * POSSIBILITY OF SUCH DAMAGE. |
| 37 | * |
| 38 | * @package Diff |
| 39 | * @author Chris Boulton <chris.boulton@interspire.com> |
| 40 | * @copyright (c) 2009 Chris Boulton |
| 41 | * @license New BSD License http://www.opensource.org/licenses/bsd-license.php |
| 42 | * @version 1.1 |
| 43 | * @link http://github.com/chrisboulton/php-diff |
| 44 | */ |
| 45 | |
| 46 | class Diff |
| 47 | { |
| 48 | /** |
| 49 | * @var array The "old" sequence to use as the basis for the comparison. |
| 50 | */ |
| 51 | private $a = null; |
| 52 | |
| 53 | /** |
| 54 | * @var array The "new" sequence to generate the changes for. |
| 55 | */ |
| 56 | private $b = null; |
| 57 | |
| 58 | /** |
| 59 | * @var array Array containing the generated opcodes for the differences between the two items. |
| 60 | */ |
| 61 | private $groupedCodes = null; |
| 62 | |
| 63 | /** |
| 64 | * @var array Associative array of the default options available for the diff class and their default value. |
| 65 | */ |
| 66 | private $defaultOptions = array( |
| 67 | 'context' => 3, |
| 68 | 'ignoreNewLines' => false, |
| 69 | 'ignoreWhitespace' => false, |
| 70 | 'ignoreCase' => false |
| 71 | ); |
| 72 | |
| 73 | /** |
| 74 | * @var array Array of the options that have been applied for generating the diff. |
| 75 | */ |
| 76 | private $options = array(); |
| 77 | |
| 78 | /** |
| 79 | * The constructor. |
| 80 | * |
| 81 | * @param array $a Array containing the lines of the first string to compare. |
| 82 | * @param array $b Array containing the lines for the second string to compare. |
| 83 | */ |
| 84 | public function __construct($a, $b, $options=array()) |
| 85 | { |
| 86 | $this->a = $a; |
| 87 | $this->b = $b; |
| 88 | |
| 89 | $this->options = array_merge($this->defaultOptions, $options); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Render a diff using the supplied rendering class and return it. |
| 94 | * |
| 95 | * @param object $renderer An instance of the rendering object to use for generating the diff. |
| 96 | * @return mixed The generated diff. Exact return value depends on the rendered. |
| 97 | */ |
| 98 | public function render(Diff_Renderer_Abstract $renderer) |
| 99 | { |
| 100 | $renderer->diff = $this; |
| 101 | return $renderer->render(); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Get a range of lines from $start to $end from the first comparison string |
| 106 | * and return them as an array. If no values are supplied, the entire string |
| 107 | * is returned. It's also possible to specify just one line to return only |
| 108 | * that line. |
| 109 | * |
| 110 | * @param int $start The starting number. |
| 111 | * @param int $end The ending number. If not supplied, only the item in $start will be returned. |
| 112 | * @return array Array of all of the lines between the specified range. |
| 113 | */ |
| 114 | public function getA($start=0, $end=null) |
| 115 | { |
| 116 | if($start == 0 && $end === null) { |
| 117 | return $this->a; |
| 118 | } |
| 119 | |
| 120 | if($end === null) { |
| 121 | $length = 1; |
| 122 | } |
| 123 | else { |
| 124 | $length = $end - $start; |
| 125 | } |
| 126 | |
| 127 | return array_slice($this->a, $start, $length); |
| 128 | |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Get a range of lines from $start to $end from the second comparison string |
| 133 | * and return them as an array. If no values are supplied, the entire string |
| 134 | * is returned. It's also possible to specify just one line to return only |
| 135 | * that line. |
| 136 | * |
| 137 | * @param int $start The starting number. |
| 138 | * @param int $end The ending number. If not supplied, only the item in $start will be returned. |
| 139 | * @return array Array of all of the lines between the specified range. |
| 140 | */ |
| 141 | public function getB($start=0, $end=null) |
| 142 | { |
| 143 | if($start == 0 && $end === null) { |
| 144 | return $this->b; |
| 145 | } |
| 146 | |
| 147 | if($end === null) { |
| 148 | $length = 1; |
| 149 | } |
| 150 | else { |
| 151 | $length = $end - $start; |
| 152 | } |
| 153 | |
| 154 | return array_slice($this->b, $start, $length); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Generate a list of the compiled and grouped opcodes for the differences between the |
| 159 | * two strings. Generally called by the renderer, this class instantiates the sequence |
| 160 | * matcher and performs the actual diff generation and return an array of the opcodes |
| 161 | * for it. Once generated, the results are cached in the diff class instance. |
| 162 | * |
| 163 | * @return array Array of the grouped opcodes for the generated diff. |
| 164 | */ |
| 165 | public function getGroupedOpcodes() |
| 166 | { |
| 167 | if(!is_null($this->groupedCodes)) { |
| 168 | return $this->groupedCodes; |
| 169 | } |
| 170 | |
| 171 | require_once dirname(__FILE__).'/Diff/SequenceMatcher.php'; |
| 172 | $sequenceMatcher = new Diff_SequenceMatcher($this->a, $this->b, null, $this->options); |
| 173 | $this->groupedCodes = $sequenceMatcher->getGroupedOpcodes(); |
| 174 | return $this->groupedCodes; |
| 175 | } |
| 176 | } |
| 177 |