示例#1
0
function applyPatch($text, $name, $rev = false)
{
    include_once "Lib/class.pmkpatcher.php";
    file_put_contents(_amoddir . "Data/{$name}.patch", $text);
    if ($text == "") {
        return 0;
    }
    if ($rev == true) {
        $x = pmkpatcher::unpatch($text, _amoddir . _apatdir);
    } else {
        $x = pmkpatcher::patch($text, _amoddir . _apatdir);
    }
    if (!is_string($x)) {
        foreach ($x['data'] as $file) {
            file_put_contents(_amoddir . _apatdir . $file['sourcefile'], $file['patcheddata']);
        }
        return 1;
    } else {
        return $x;
    }
}
    function displayDiffs($diffPath, $descKey)
    {
        $diffFiles = t3lib_div::getFilesInDir($diffPath, 'diff', 0, '1');
        if (!count($diffFiles)) {
            return false;
        }
        $content = '';
        foreach ($diffFiles as $diffFile) {
            $diffData = @file_get_contents($diffPath . $diffFile);
            if (!$diffData) {
                continue;
            }
            $diffArray = pmkpatcher::parseDiff($diffData, $this->filePath);
            if (!is_array($diffArray)) {
                return false;
            }
            $name = htmlspecialchars(pathinfo($diffPath . $diffFile, PATHINFO_FILENAME));
            $content .= '<dl class="typo3-tstemplate-ceditor-constant">
	<dt class="typo3-tstemplate-ceditor-label">' . implode('<br />', $diffArray[0]['comment']) . '</dt>
	<dt class="typo3-dimmed">[' . $name . ']</dt>';
            $files = array();
            foreach ($diffArray as $diffParts) {
                $files[] = $diffParts['destinationfile'];
            }
            $content .= '
	<dd>The following file' . (count($files) > 1 ? 's' : '') . ' will be modified:<br />' . implode('<br />', $files) . '</dd>';
            $content .= '
	<dd>
		<div class="typo3-tstemplate-ceditor-row">
			<select name="' . $descKey . 'patch[' . $name . ']">
				<option value="0" selected="selected">Do nothing</option>
				<option value="1">Patch file</option>
				<option value="2">Unpatch file</option>
			</select>
		</div>
	</dd>
</dl>';
        }
        if (!$content) {
            return false;
        }
        $content = '<div style="padding-top: 10px;"></div><h2 class="typo3-tstemplate-ceditor-subcat bgColor5">' . $this->desc[$descKey]['title'] . '</h2>' . '<div style="padding-bottom: 10px;">' . $this->desc[$descKey]['desc'] . '</div>' . $content . '<input type="button" name="patchall" value="Select Patch all" onclick="return difftoggle(1,\'' . $descKey . '\')" /> ' . '<input type="button" name="unpatchall" value="Select Unpatch all" onclick="return difftoggle(2,\'' . $descKey . '\')" /> ' . '<input type="button" name="resetall" value="Reset all" onclick="return difftoggle(0,\'' . $descKey . '\')" /> ' . '<input name="update" value="Update" type="submit" style="font-weight: bold;"/>
			<input type="hidden" name="desckey" value="' . $descKey . '" />';
        return '<form name="' . $descKey . '_form" action="' . htmlspecialchars(t3lib_div::linkThisScript()) . '" method="post">' . $content . '</form>';
    }
 public static function applyDiff($diffArray, $path = '', $rev = false)
 {
     $patcher = new pmkpatcher($path);
     $patchedData = $patcher->_applyDiff($diffArray, $rev);
     return is_array($patchedData) ? $patchedData : $patcher->errorMsg;
 }