function appplyPatch($patchName, $diffPath, $rev)
 {
     $diffData = @file_get_contents($diffPath . $patchName . '.diff');
     if (!$diffData) {
         return 'Could not read ' . $patchName . '.diff';
     }
     $diffArray = pmkpatcher::parseDiff($diffData, $this->filePath, $rev);
     if (!is_array($diffArray)) {
         return 'No diff data found in ' . $patchName . '.diff';
     }
     $diffArray = pmkpatcher::applyDiff($diffArray, $this->filePath, $rev);
     if (!is_array($diffArray)) {
         return $diffArray;
     }
     foreach ($diffArray as $diffParts) {
         if (isset($diffParts['patcheddata'])) {
             $content .= '<h3>' . ($rev ? 'Unpatching' : 'Patching') . ' file "' . $diffParts['destinationfile'] . '"</h3>';
             $fileExt = strtolower(pathinfo($diffParts['destinationfile'], PATHINFO_EXTENSION));
             if ($fileExt == 'js' && $rev && $diffParts['sourcefile'] != $diffParts['destinationfile']) {
                 // If unpatch is selected, and the file is a javascript file,
                 // Then the .src file is just copied into the destination instead of unpatching.
                 // Unpatching of .js files is not possible due to the minifying of the javascripts.
                 $patchedData = @file_get_contents($this->filePath . $diffParts['sourcefile']);
                 $content .= '<p>File unpatched sucessfully.</p>';
             } else {
                 $patchedData = $diffParts['patcheddata'];
                 $content .= '<p>File ' . ($rev ? 'unpatched' : 'patched') . ' sucessfully.</p>';
             }
             if ($fileExt == 'js' && $diffParts['sourcefile'] != $diffParts['destinationfile'] && $diffParts['sourcefile'] != '/dev/null') {
                 // Minify data if extension is .js
                 $patchedData = JSMin::minify($patchedData);
             }
             @mkdir(dirname($this->filePath . $diffParts['destinationfile']), 0777, 1);
             file_put_contents($this->filePath . $diffParts['destinationfile'], $patchedData);
         } else {
             // Process custom marker for adding or removing binary files
             $type = $diffParts['type'];
             $content .= '<h3>' . ($rev ? 'Removing' : 'Adding') . ' file "' . ($rev && $type == 'binary-file' ? $diffParts['sourcefile'] : $diffParts['destinationfile']) . '"</h3>';
             if ($type == 'binary-file') {
                 if ($diffParts['sourcefile'] && $diffParts['destinationfile'] != '/dev/null') {
                     //make undo copy if file exists
                     if (file_exists($this->path . $diffParts['sourcefile']) || is_file($this->path . $diffParts['sourcefile'])) {
                         @mkdir(dirname($this->filePath . $diffParts['sourcefile']) . '/undo/', 0777, 1);
                         if (!@copy($this->filePath . $diffParts['destinationfile'], dirname($this->filePath . $diffParts['sourcefile']) . '/undo/' . basename($this->filePath . $diffParts['sourcefile']))) {
                             $content .= '<p>Failed to add undo file: ' . $diffParts['destinationfile'] . '</p>';
                         } else {
                             $content .= '<p>Undo file added sucessfully.</p>';
                         }
                     }
                     @mkdir(dirname($this->filePath . $diffParts['destinationfile']), 0777, 1);
                     if (!@copy($this->filePath . $diffParts['sourcefile'], $this->filePath . $diffParts['destinationfile'])) {
                         $content .= '<p>Failed to add file: ' . $diffParts['destinationfile'] . '</p>';
                     } else {
                         $content .= '<p>File added sucessfully.</p>';
                     }
                 } elseif ($diffParts['destinationfile'] == '/dev/null') {
                     if (!@unlink($this->filePath . $diffParts['sourcefile'])) {
                         $content .= '<p>Failed to remove file: ' . $diffParts['sourcefile'] . '</p>';
                     } else {
                         $content .= '<p>File removed sucessfully.</p>';
                     }
                 }
             }
             if (!$type) {
                 if ($diffParts['sourcefile'] == '/dev/null') {
                     if (!@unlink($this->filePath . $diffParts['destinationfile'])) {
                         $content .= '<p>Failed to remove file: ' . $diffParts['destinationfile'] . '</p>';
                     } else {
                         $content .= '<p>File removed sucessfully.</p>';
                     }
                 }
             }
         }
     }
     return $content;
 }