function DAProcessDirectory($ReposLoc, $BasePath) { global $env; // Create our CVS connection object and set the required properties. $CVSServer = new CVS_PServer($env['CVSSettings']['cvsroot'], $env['CVSSettings']['server'], $env['CVSSettings']['username'], $env['CVSSettings']['passwd']); // Connect to the CVS server. if ($CVSServer->Connect() === true) { // Authenticate against the server. $Response = $CVSServer->Authenticate(); if ($Response !== true) { return; } // Create the folder for the BasePath. @mkdir($BasePath, 0700); // Get a RLOG of the module path specified in $ReposLoc. $CVSServer->RLog($ReposLoc); $Folders = $CVSServer->FOLDERS; $Files = $CVSServer->FILES; foreach ($Folders as $folder) { if ($folder["Name"] != "Attic") { DAProcessDirectory($ReposLoc . $folder["Name"] . "/", $BasePath . "/" . $folder["Name"]); set_time_limit(30); } } foreach ($Files as $file) { $CVSServer->ExportFile($ReposLoc . $file["Name"], time()); $filehandle = fopen($BasePath . "/" . $file["Name"], "wb"); fwrite($filehandle, $CVSServer->FILECONTENTS); fclose($filehandle); set_time_limit(30); } $CVSServer->Disconnect(); // When we leave this function the contents should be in the File System. } }
/** * This source code is distributed under the terms as layed out in the * GNU General Public License. * * Purpose: To provide File Download capability. * * Based on phpcvsview * @author Brian A Cheeseman <*****@*****.**> * @copyright 2003-2005 Brian A Cheeseman * * Ported to bitweaver framework by Lester Caine 2006-12-29 * @version $Id$ **/ function DownloadFile($File, $Revision = "") { global $env, $MIME_TYPES; // Create our CVS connection object and set the required properties. $CVSServer = new CVS_PServer($env['CVSSettings']['cvsroot'], $env['CVSSettings']['server'], $env['CVSSettings']['username'], $env['CVSSettings']['passwd']); // Connect to the CVS server. if ($CVSServer->Connect() === true) { // Authenticate against the server. $Response = $CVSServer->Authenticate(); if ($Response !== true) { return; } // Get a RLOG of the module path specified in $env['mod_path']. $CVSServer->RLog($env['mod_path']); // "Export" the file. $Response = $CVSServer->ExportFile($File, $Revision); if ($Response !== true) { return; } // Get the mime type for the file. $FileExt = substr($File, strrpos($File, '.') + 1); $MimeType = $MIME_TYPES[$FileExt]; if ($MimeType == '') { $MimeType = 'text/plain'; } // Send the appropriate http header. header('Content-Type: ' . $MimeType); // Send the file contents. echo $CVSServer->FILECONTENTS; echo '<br />File Extension: ' . $FileExt; echo '<br />Mime Type is: ' . $MimeType; // Close the connection. $CVSServer->Disconnect(); } else { echo '<h2>ERROR: Could not connect to the PServer.</h2>'; } }
function DisplayFileContents($File, $Revision = "") { global $gBitSmarty, $config, $env; // Create our CVS connection object and set the required properties. $CVSServer = new CVS_PServer($env['CVSSettings']['cvsroot'], $env['CVSSettings']['server'], $env['CVSSettings']['username'], $env['CVSSettings']['passwd']); // Check and see if this file and version has already been viewed and exists in the cache. $CachedFileName = $config['Cache']['Location']; if ($config['Cache']['Enable']) { if (!file_exists($CachedFileName)) { mkdir($CachedFileName, 0750); } $CachedFileName .= "/" . str_replace("/", "_", $File) . ",{$Revision}"; } if (file_exists($CachedFileName) && $config['Cache']['Enable']) { $fd = fopen($CachedFileName, "r"); if ($fd !== false) { fpassthru($fd); fclose($fd); } } else { // Connect to the CVS server. if ($CVSServer->Connect() === true) { // Authenticate against the server. $Response = $CVSServer->Authenticate(); if ($Response !== true) { return; } // Get a RLOG of the module path specified in $env['mod_path']. $CVSServer->RLog($env['mod_path']); // "Export" the file. $Response = $CVSServer->ExportFile($File, $Revision); if ($Response !== true) { return; } /* if ($config['GeSHi']['Enable']) { // Create the GeSHi instance and parse the output. // TODO: setup code to auto identify the highlighting class to use for current file. $FileExt = substr($File, strrpos($File, '.')+1); $Language = guess_highlighter($FileExt); if (is_array($Language)) { $Language = $Language[0]; } $geshi = new GeSHi($CVSServer->FILECONTENTS, $Language, $config['GeSHi']['HighlightersPath']); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_line_style('background: #fcfcfc;'); $geshi->set_tab_width(4); $hlcontent = $geshi->parse_code(); // Store in the current cache. if ($config['Cache']['Enable']) { $fd = fopen($CachedFileName, "w"); if ($fd !== false) { fwrite($fd, '<p class="source">'.$hlcontent.'</p>'); fclose($fd); } } // Display the file contents. echo '<p class="source">'; echo $hlcontent; echo '</p>'; } else { $search = array('<', '>', '\n', '\t'); $replace = array('<', '>', '', ' '); $content = str_replace($search, $replace, $CVSServer->FILECONTENTS); $source = explode('\n', $content); $soure_size = sizeof($source); if ($config['Cache']['Enable']) { $fd = fopen($CachedFileName, "w"); if ($fd !== false) { fwrite($fd, "<pre>\n"); } } else { $fd = false; } echo "<pre>\n"; for($i = 1; $i <= $soure_size; $i++) { $line = '<a name="'.$i.'" class="numberedLine"> '.str_repeat(' ', strlen($soure_size) - strlen($i)). $i.'.</a> ' . $source[$i-1] . "\n"; if ($fd !== false) { fwrite($fd, $line); } echo $line; } if ($fd !== false) { fwrite($fd, "</pre>\n"); } echo "</pre>\n"; } */ // Close the connection. $CVSServer->Disconnect(); } else { $gBitSmarty->assign('error', "ERROR: Could not connect to the PServer."); } } }
/** * This source code is distributed under the terms as layed out in the * GNU General Public License. * * Purpose: To provide File Diff Page. * * Based on phpcvsview * @author Brian A Cheeseman <*****@*****.**> * @copyright 2003-2005 Brian A Cheeseman * * Ported to bitweaver framework by Lester Caine 2006-12-29 * @version $Id$ **/ function DisplayFileDiff($Rev1, $Rev2) { global $env; // Create our CVS connection object and set the required properties. $CVSServer = new CVS_PServer($env['CVSSettings']['cvsroot'], $env['CVSSettings']['server'], $env['CVSSettings']['username'], $env['CVSSettings']['passwd']); // Connect to the CVS server. if ($CVSServer->Connect() === true) { // Authenticate against the server. $Response = $CVSServer->Authenticate(); if ($Response !== true) { return; } echo '<hr />' . "\n"; echo '<div id="filediff">' . "\n"; // Get the DIFF from the server. $DiffLines = explode("\n", $CVSServer->getFileDiff($env['mod_path'], $Rev1, $Rev2)); // echo "<pre>".implode("\n", $DiffLines)."</pre>"; // Get a RLOG of the module path specified in $env['mod_path']. $CVSServer->RLog($env['mod_path']); $DateOfFile = 0; foreach ($CVSServer->FILES[0]["Revisions"] as $Revision) { if ($Revision["Revision"] == $Rev1) { $DateOfFile = strtotime($Revision["date"]); } } $CVSServer->Disconnect(); $CVSServer = new CVS_PServer($env['CVSSettings']['cvsroot'], $env['CVSSettings']['server'], $env['CVSSettings']['username'], $env['CVSSettings']['passwd']); $CVSServer->Connect(); $CVSServer->Authenticate(); if ($CVSServer->ExportFile($env['mod_path'], $DateOfFile) !== true) { return; } $FilePatching = array(); $FileContents = $CVSServer->FILECONTENTS; if ($FileContents === false) { echo '<h3>ERROR: Getting Revision for file:</h3>' . '<h3>' . $Rev1 . '</h3>'; } $Lines = explode("\n", $FileContents); foreach ($Lines as $Line) { $FilePatching[] = array('mode' => "o", 'text' => $Line); } $linenumber = 0; while (strpos($DiffLines[$linenumber], "diff") === false) { $linenumber++; } // while $linenumber++; // We now have the line which starts the diff output. $LineOffset = 0; while ($linenumber < count($DiffLines)) { if (strpos($DiffLines[$linenumber], "a") !== false) { // We have added a line or lines. $Parts = explode("a", $DiffLines[$linenumber]); $InsertLocation = explode(",", $Parts[0]); $NewLineLocation = explode(",", $Parts[1]); $InsertLength = count($NewLineLocation) == 2 ? $NewLineLocation[1] - $NewLineLocation[0] + 1 : 1; for ($LineCounter = 0; $LineCounter < $InsertLength; $LineCounter++) { $TempLine = array('mode' => "+", 'text' => substr($DiffLines[++$linenumber], 2)); $FilePatching = InsertIntoArray($FilePatching, $TempLine, $InsertLocation[0] + $LineCounter + 1); $LineOffset++; } } else { if (strpos($DiffLines[$linenumber], "c") !== false) { // We have changed a line or lines. $Parts = explode("c", $DiffLines[$linenumber]); $InsertLocation = explode(",", $Parts[0]); $InsertLength = count($InsertLocation) == 2 ? $InsertLocation[1] - $InsertLocation[0] + 1 : 1; $linenumber += $InsertLength + 1; $NewFileLocation = explode(",", $Parts[1]); $NewLineLength = count($NewFileLocation) == 2 ? $NewFileLocation[1] - $NewFileLocation[0] + 1 : 1; for ($LineCounter = 0; $LineCounter < $InsertLength; $LineCounter++) { if ($LineCounter < $NewLineLength) { $linenumber++; $TempLine = array('mode' => "+", 'text' => substr($DiffLines[$linenumber], 2)); $FilePatching = InsertIntoArray($FilePatching, $TempLine, $InsertLocation[0] + $LineCounter + $LineOffset); $LineOffset++; } $FilePatching[$InsertLocation[0] - 2 + $LineCounter + $LineOffset]['mode'] = '-'; } for ($LineCounter = $InsertLength; $LineCounter < $NewLineLength; $LineCounter++) { $linenumber++; $TempLine = array('mode' => "+", 'text' => substr($DiffLines[$linenumber], 2)); $FilePatching = InsertIntoArray($FilePatching, $TempLine, $InsertLocation[0] + $LineCounter + $LineOffset); } } else { if (strpos($DiffLines[$linenumber], "d") !== false) { // we have removed a line or lines. $Parts = explode("d", $DiffLines[$linenumber]); $DeleteLocation = explode(",", $Parts[0]); $OldLineLocation = explode(",", $Parts[1]); $DeleteLength = count($DeleteLocation) == 2 ? $DeleteLocation[1] - $DeleteLocation[0] + 1 : 1; for ($LineCounter = 0; $LineCounter < $DeleteLength; $LineCounter++) { $FilePatching[$OldLineLocation[0] + $LineCounter + $LineOffset]['mode'] = '-'; $LineOffset++; $linenumber++; } } } } $linenumber++; } // while $search = array("<", ">", "\n", "\t", " "); $replace = array("<", ">", "", " ", " "); foreach ($FilePatching as $Line) { echo ' <p class="'; switch ($Line['mode']) { case '+': echo "added"; break; case '-': echo "removed"; break; default: echo "normal"; } // switch echo '">' . str_replace($search, $replace, $Line['text']) . '</p>' . "\n"; } echo '</div>' . "\n"; echo '<hr />' . "\n"; $CVSServer->Disconnect(); } else { echo '<h2>ERROR: Could not connect to the PServer.</h2>'; } }