[Phpcvsview-cvs-updates] phpcvsview footer.php,NONE,1.1 header.php,NONE,1.1 cvsview.php,NONE,1.1
Status: Pre-Alpha
Brought to you by:
bcheesem
From: <bch...@us...> - 2003-04-06 08:06:22
|
Update of /cvsroot/phpcvsview/phpcvsview In directory sc8-pr-cvs1:/tmp/cvs-serv19487 Added Files: footer.php header.php cvsview.php Log Message: Added a "REAL" frontend to the CVS viewer class. --- NEW FILE: footer.php --- <?php /** * Purpose: To provide the HTML page footer code * * @author Brian A Cheeseman <br...@bc...> * @version $Id: footer.php,v 1.1 2003/04/06 08:06:14 bcheesem Exp $ * @copyright 2003 Brian A Cheeseman **/ function GetPageFooter() { // Here we will generate the HTML page footer. global $StartTime; $EndTime = microtime(); $PageFoot = "This page was created in ".number_format(microtime_diff($StartTime, $EndTime), 3)." seconds."; $PageFoot .= "</BODY></HTML>"; return $PageFoot; } ?> --- NEW FILE: header.php --- <?php /** * Purpose: To provide the HTML page header code * * @author Brian A Cheeseman <br...@bc...> * @version $Id: header.php,v 1.1 2003/04/06 08:06:16 bcheesem Exp $ * @copyright 2003 Brian A Cheeseman **/ function GetPageHeader($Title="", $Heading="") { global $StartTime; $StartTime = microtime(); // Here we will generate the HTML page header. $PageHead = "<HTML>"; if (isset($Title)) { $PageHead .= "<HEAD><TITLE>$Title</TITLE></HEAD>"; } $PageHead .= "<BODY>"; if (isset($Heading)) { $PageHead .= "<DIV ALIGN=\"center\"><H1>$Heading</H1></DIV>"; } $PageHead .= "Welcome to our CVS Repository viewer. This page has been dynamically"; $PageHead .= " created with '<a href=\"http://phpcvsview.sourceforge.net/\">phpCVS"; $PageHead .= "Viewer</a>' created by <a href=\"mailto:bcheesem@us"; $PageHead .= "ers.sourceforge.net\">Brian Cheeseman</a>. <BR><BR>Please feel free"; $PageHead .= " to browse our source code.<BR><BR>"; return $PageHead; } ?> --- NEW FILE: cvsview.php --- <?php /** * Purpose: To provide the main entry point in accessing a CVS repository * * @author Brian A Cheeseman <br...@bc...> * @version $Id: cvsview.php,v 1.1 2003/04/06 08:06:18 bcheesem Exp $ * @copyright 2003 Brian A Cheeseman **/ $REPOS = ""; $CVSROOT = "/cvsroot/d/de/denet/"; //$CVSROOT = "/cvsroot/p/ph/phpcvsview/"; $PServer = "cvs.sourceforge.net"; $UserName = "anonymous"; $Password = ""; $ScriptName = $_SERVER['PHP_SELF']; include("phpcvs.php"); include("phpcvsmime.php"); include("header.php"); include("footer.php"); function microtime_diff($a, $b) { list($a_dec, $a_sec) = explode(" ", $a); list($b_dec, $b_sec) = explode(" ", $b); return $b_sec - $a_sec + $b_dec - $a_dec; } function DisplayDirListing () { global $REPOS, $CVSROOT, $PServer, $UserName, $Password, $ScriptName; $CVSServer = new phpcvs($CVSROOT, $PServer, $UserName, $Password); echo GetPageHeader("phpCVSView CVS Repository", "phpCVSView CVS Repository"); if ($CVSServer->ConnectTcpAndLogon()) { $CVSServer->SendRoot(); $CVSServer->SendValidResponses(); $CVSServer->SendValidRequests(); $Elements = $CVSServer->RLOGDir($REPOS); $FileOut = ""; echo "<HR>\n"; echo "<TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"1\" WIDTH=\"100%\">\n"; echo " <TR BGCOLOR=\"#CCFFCC\">\n <TH>File</TH>\n <TH>Rev.</TH>\n <TH>Age</TH>\n <TH>Author</TH>\n <TH>Last Log Entry</TH>\n </TR>\n"; $BGColor = "#FFFFFF"; if (strcmp($REPOS, "/") != 0) { echo " <TR BGCOLOR=\"$BGColor\" COLSPAN=\"5\">\n <TD><A HREF=\"$ScriptName?CVSROOT="; $UpDirPath = substr($REPOS, 0, strlen($REPOS)-1); echo strrev(strchr(strrev($UpDirPath), "/")); echo "\"><IMG SRC=\"/icons/back.gif\" border=\"0\"> Parent Directory</A> </TD>\n"; $BGColor="#CCCCFF"; } // End of if (strcmp($REPOS, "/") != 0) while(list($key, $val) = each($Elements)){ if ($val == "DIR") { echo " <TR BGCOLOR=\"$BGColor\">\n"; echo " <TD><A HREF=\"$ScriptName?CVSROOT=$REPOS".substr($key, 0, strlen($key))."\">"; echo "<IMG SRC=\"/icons/dir.gif\" WIDTH=\"20\" HEIGHT=\"22\" border=\"0\"> ".$key."</A></TD>\n"; echo " <TD> </TD>\n <TD> </TD>\n <TD> </TD>\n <TD> </TD>\n"; echo " </TR>\n"; if (strcmp($BGColor, "#FFFFFF") == 0) { $BGColor = "#CCCCFF"; } else { $BGColor = "#FFFFFF"; } // End of if (strcmp($BGColor, "#FFFFFF") == 0) } // End of if ($val == "DIR") } // End of while(list($key, $val) = each($Elements)) reset($Elements); while(list($key, $val) = each($Elements)){ if ($val != "DIR") { $FileOut .= " <TR BGCOLOR=\"$BGColor\">\n"; $FileOut .= " <TD><A HREF=\"$ScriptName?CVSROOT=$REPOS&ShowHist=".$val["FILENAME"]."\">"; $FileOut .= "<IMG SRC=\"/icons/text.gif\" WIDTH=\"20\" HEIGHT=\"22\" border=\"0\"> ".$val["FILENAME"]."</A> </TD>\n"; $FileOut .= " <TD> <A HREF=\"$ScriptName?CVSROOT=$REPOS&ShowFile=".$val["FILENAME"]."&Rev=".$val["HEAD"]."\">".$val["HEAD"]."</A> </TD>\n"; $FileOut .= " <TD> ".str_replace(" ", " ", strftime("%d %b %Y %H:%M:%S", $val["DATE"]))." </TD>\n"; $FileOut .= " <TD> ".$val["AUTHOR"]." </TD>\n"; $FileOut .= " <TD>".str_replace("\n", "<BR>", substr($val["LOG"], 0, strlen($val["LOG"])-1))."</TD>\n"; $FileOut .= " </TR>\n"; if (strcmp($BGColor, "#FFFFFF") == 0) { $BGColor = "#CCCCFF"; } else { $BGColor = "#FFFFFF"; } // End of if (strcmp($BGColor, "#FFFFFF") == 0) } // End of if ($val != "DIR" } // End of while(list($key, $val) = each($Elements)) echo $FileOut." </TABLE>\n"; echo "<HR>"; $CVSServer->DisconnectTcp(); } else { echo "Connection Failed."; } // End of if ($CVSServer->ConnectTcpAndLogon()) echo GetPageFooter(); } // End of function DisplayDirListing() function DisplayFileHistory($FileName) { global $REPOS, $CVSROOT, $PServer, $UserName, $Password, $ScriptName; $CVSServer = new phpcvs($CVSROOT, $PServer, $UserName, $Password); echo GetPageHeader("phpCVSView CVS Repository", "phpCVSView CVS Repository"); if ($CVSServer->ConnectTcpAndLogon()) { $CVSServer->SendRoot(); $CVSServer->SendValidResponses(); $CVSServer->SendValidRequests(); $Elements = $CVSServer->RLOGFile($FileName, $REPOS); echo "<H3>Revision History for '".$REPOS.$_GET["ShowHist"]."'</H3>"; // List each revision with a HorizRule between them. for ($i = 1; $i <= $Elements[0]["TotalRevisions"]; $i++) { echo "<HR>\n"; echo "Revision: ".$Elements[$i]["Revision"]." "; echo "[<A HREF=\"$ScriptName?CVSROOT=$REPOS&ShowFile=".$FileName."&Rev=".$Elements[$i]["Revision"]."\">View"; echo "</a>] "; echo "[<A HREF=\"$ScriptName?CVSROOT=$REPOS&DownloadFile=".$FileName."&Rev=".$Elements[$i]["Revision"]."\">Download"; echo "</a>]"; echo "<BR>\n"; echo "Branch: Yet to identify.<BR>\n"; echo "Date: ".$Elements[$i]["Date"]."<BR>\n"; echo "Time: ".$Elements[$i]["Time"]."<BR>\n"; echo "Author: ".$Elements[$i]["Author"]."<BR>\n"; echo "State: ".$Elements[$i]["State"]."<BR>\n"; if (($i + 1) < $Elements[0]["TotalRevisions"]) { echo "Changes since ".$Elements[$i+1]["Revision"].": "; echo "+".$Elements[$i]["LinesAdd"]." -".$Elements[$i]["LinesSub"]."<br>\n"; } echo "<pre>".str_replace("\n", "<BR>", $Elements[$i]["Log"])."</pre>"; } echo "<HR>\n"; $CVSServer->DisconnectTcp(); } else { echo "ERROR: Unable to connect to the CVS PServer.<BR>"; } // End of if ($CVSServer->ConnectTcpAndLogon()) echo GetPageFooter(); } // End of function DisplayFileHistory() function DisplayFile() { global $REPOS, $CVSROOT, $PServer, $UserName, $Password, $FileToView, $FileRev; $CVSServer = new phpcvs($CVSROOT, $PServer, $UserName, $Password); echo GetPageHeader("phpCVSView CVS Repository", "phpCVSView CVS Repository"); if ($CVSServer->ConnectTcpAndLogon()) { $CVSServer->SendRoot(); $CVSServer->SendValidResponses(); $CVSServer->SendValidRequests(); echo "<H3>File Contents for Revision ".$FileRev." of '".$REPOS.$FileToView."'</H3>"; $Elements = $CVSServer->ViewFile($FileToView, $FileRev, $REPOS); // Format and Display the output. if (strpos($FileToView, ".php")) { $OutText = highlight_string($Elements["CONTENT"], true); $OutText = str_replace("<code>", "<pre>", $OutText); $OutText = str_replace("</code>", "</pre>", $OutText); echo $OutText; } else { $Find = array("\r", "\n", " ", "\t"); $Repl = array("", "<BR>", " ", " "); echo "<pre>".str_replace($Find, $Repl, $Elements["CONTENT"])."</pre>"; } $CVSServer->DisconnectTcp(); } echo GetPageFooter(); } function DownloadFile() { global $REPOS, $CVSROOT, $PServer, $UserName, $Password, $FileToDownload, $FileRev, $MIME_TYPE; $CVSServer = new phpcvs($CVSROOT, $PServer, $UserName, $Password); if ($CVSServer->ConnectTcpAndLogon()) { $CVSServer->SendRoot(); $CVSServer->SendValidResponses(); $CVSServer->SendValidRequests(); $Elements = $CVSServer->ViewFile($FileToDownload, $FileRev, $REPOS); // Send the file to the client. // $Elements["CONTENT"]; $PeriodPos = strrchr($FileToDownload, "."); $FileExt = substr($FileToDownload, $PeriodPos, strlen($FileToDownload)-$PeriodPos); if (isset($MIME_TYPE["$FileExt"])) { $ContentType = $MIME_TYPE["$FileExt"]; } else { $ContentType = "text/plain"; } header("content-type: ".$ContentType); echo $Elements["CONTENT"]; $CVSServer->DisconnectTcp(); } } if (isset($_GET["CVSROOT"])) { $REPOS = $_GET["CVSROOT"]; } else { $REPOS = "/"; } $REPOS = str_replace("//", "/", $REPOS); if (isset($_GET["ShowFile"])) { // Here we will show the contents of a file. $FileToView = $_GET["ShowFile"]; $FileRev = $_GET["Rev"]; DisplayFile(); } else { if (isset($_GET["ShowHist"])) { // Here we will show the Revision History of a given file. DisplayFileHistory($_GET["ShowHist"]); } else { if (isset($_GET["DownloadFile"])) { $FileToDownload = $_GET["DownloadFile"]; $FileRev = $_GET["Rev"]; DownloadFile(); } else { // Here we will just show the current file listing. DisplayDirListing(); } } } ?> |