Ignore:
Timestamp:
Aug 7, 2000, 8:22:47 AM (25 years ago)
Author:
bird
Message:

More complete than ever... But not quite finished.
PHP4 is 8+ timer faster than PHP3!!!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/database/www/cvs.php3

    r3953 r3965  
    77 */
    88$sCVSROOT = ".";
     9$sCVSROOT = "g:/cvsroot";
    910$sCVSROOT = "d:/odin32/cvs/cvsroot";
    10 $sCVSROOT = "g:/cvsroot";
    1111
    1212
     
    4141         *       We can't allow relative paths (ie. "..")
    4242         */
    43         if (strlen($sFilename) < 3 || substr($sFilename, strlen($sFilename)-2) != ",v")
     43        if (strlen($sFilename) < 3 || substr($sFilename, -2) != ",v")
    4444        {
    4545            $this->sError = "filename is invalid";
    4646            return 1;
    4747        }
     48        $sFilename = str_replace("\\", "/", $sFilename);
     49        if ((substr($sFilename, 0, 3) == "../")
     50            ||
     51            (substr($sFilename, -3) == "/..")
     52            ||
     53            (strpos($sFilename, "/../") > 0)
     54            )
     55            {
     56            $this->sError = "Invalid parameter: \$sFilename $sFilename";
     57            return 87;
     58            }
     59        if ($sFilename[0] == '/')
     60            $sFilename = ".".$sFilename;
     61        else if (substr($sFilename, 0, 2) != "./")
     62            $sFilename = "./".$sFilename;
    4863
    4964        /*
     
    98113         */
    99114        $Timer = Odin32DBTimerStart("CVS Parse");
    100         $this->fOk = $this->ParseFile2($hFile, 0);// $fNoDeltas);
     115        $this->fOk = $this->ParseFile($hFile, $fNoDeltas);
    101116        Odin32DBTimerStop($Timer);
    102117
     
    116131     */
    117132    function ParseFile($hFile, $fNoDeltas)
    118     {
    119 
    120         /*
    121          * Parse file.
    122          */
    123         $fAt    = 0;
    124         $fNewKey= 1;
    125         $sKey   = "";
    126         $sRev   = "";
    127         $fDesc  = 0;
    128 
    129         $iLine  = -1;
    130         $sLine  = "";
    131         $fStop  = 0;
    132         while (($sLine != "" || !feof($hFile)) && !$fStop)
    133         {
    134             /*
    135              * Left trim.
    136              * If empty line, get next and iterate.
    137              */
    138             $sLine = ltrim($sLine);
    139             if (!$sLine || $sLine == "" || $sLine == "\n" || $sLine == "\r")
    140             {
    141                 $iLine++;
    142                 $sLine = fgets($hFile, 0x1000);
    143                 continue;
    144             }
    145 
    146             /*
    147              * Are we looking for a new key word?
    148              */
    149             if ($fNewKey)
    150             {
    151                 //$sKey = CopyWord($sLine);
    152                 $cch = strlen($sLine);
    153                 for ($i = 0; $i < $cch; $i++)
    154                 {
    155                     $c = $sLine[$i];
    156                     if (!(
    157                           ($c >= 'a'  && $c <= 'z')
    158                           ||
    159                           ($c >= 'A'  && $c <= 'Z')
    160                           ||
    161                           ($c >= '0'  && $c <= '9')
    162                           ||
    163                           $c == '.'
    164                           ||
    165                           $c == '_'
    166                           )
    167                         )
    168                         break;
    169                 }
    170                 $sKey = substr($sLine, 0, $i);
    171 
    172                 $sLine = ltrim(SkipWord($sLine));
    173                 if ($sKey[0] >= "0" && $sKey[0] <= "9")
    174                     /* Revision number: delta or revision info */
    175                     $sRev = $sKey;
    176                 else
    177                     $fNewKey = 0;
    178                 continue;
    179             }
    180 
    181 
    182             /*
    183              * Extract value
    184              */
    185             $fNoSemicolon = ($sKey == "desc" || $sKey == "log" || $sKey == "desc");
    186             if ($fAt = ($sLine[0] == "@")) //check if the value is enclosed in '@'s
    187                 $sLine = substr($sLine, 1);
    188             $asValue = array();
    189             $fEnd = 0;
    190             while (!$fEnd)
    191             {
    192                 /* get new line? */
    193                 if (!$sLine || $sLine == "" || $sLine == "\n" || $sLine == "\r")
    194                 {
    195                     if (feof($hFile))
    196                         break;
    197                     /* Get next line and remove any EOF chars */
    198                     $iLine++;
    199                     $sLine = str_replace("\x1a", "", fgets($hFile, 0x1000));
    200                     continue;
    201                 }
    202 
    203                 //echo "debug line $iLine: $sLine";
    204 
    205                 /*
    206                  * Look for end char (either ; or @) and copy.
    207                  * If end of value then $sLine <- rest of line.
    208                  */
    209                 $fEnd = 0;
    210                 $cchLine = strlen($sLine);
    211                 if ($fAt)
    212                 {   /* terminated with @ */
    213                     //$iAt = 0;
    214                     //for ($iAt; $iAt+1 < $cchLine; $iAt++)
    215                     //    if ($sLine[$iAt] == '@' && ($fEnd = ($sLine[++$iAt] != '@')))
    216                     //        break;
    217                     if ($sLine[0] == '@' && $sLine[1] != '@')
    218                         $fEnd = $iAt = 1;
    219                     else
    220                     {
    221                         $iAt = 0;
    222                         while ($iAt = strpos($sLine, "@", $iAt+1))
    223                            if ($fEnd = ($sLine[++$iAt] != '@'))
    224                                 break;
    225                     }
    226 
    227                     if ($fEnd)
    228                     {
    229                         $asValue[] = str_replace("@@", "@", substr($sLine, 0, $iAt - 1));
    230                         /* if semicolon end, skip to it. ASSUMES: same line! */
    231                         if (!$fNoSemicolon && ($iAt = strpos($sLine, ";", $iAt)) >= 0)
    232                             $iAt++;
    233                         $sLine = (strlen($sLine) > $iAt && $iAt >= 0) ? substr($sLine, $iAt) : "";
    234                     }
    235                     else
    236                     {
    237                         $asValue[] = str_replace("@@", "@", $sLine);
    238                         $sLine = "";
    239                     }
    240                 }
    241                 else
    242                 {   /* terminated with ';' */
    243                     $i = strpos($sLine, ';');
    244                     if ($fEnd = ($i > 0 || $sLine[0] == ';'))
    245                     {
    246                         //$asValue[] = str_replace("@@", "@", substr($sLine, 0, $i));
    247                         $asValue[] = substr($sLine, 0, $i);
    248                         $sLine = (strlen($sLine) > $i+1) ? substr($sLine, $i+1) : "";
    249                     }
    250                     else
    251                     {
    252                         //$asValue[] = str_replace("@@", "@", $sLine);
    253                         $asValue[] = $sLine;
    254                         $sLine = "";
    255                     }
    256                 }
    257             }
    258 
    259 
    260             /*
    261              * Process the key.
    262              */
    263             switch ($sKey)
    264             {
    265                 /*
    266                  * This is normally the keyword separating
    267                  * revision info from log+text info.
    268                  */
    269                 case "desc":
    270                     $fDesc = 1;
    271                     $sRev = "";
    272                     break;
    273 
    274                 /*
    275                  * Stop after the first log entry.
    276                  */
    277                 case "log":
    278                     $fStop = $fNoDeltas;
    279                     break;
    280 
    281                 /*
    282                  * Don'r read deltas for archives with the expand tag set
    283                  */
    284                 case "expand":
    285                     $fNoDeltas = 1;//= $asValue[0] != "";
    286                     break;
    287             }
    288 
    289             /*
    290              * Save key and value in the appopriate place.
    291              */
    292             if ($sRev == "")
    293             {   /* Base keys */
    294                 if (sizeof($this->aasKeys) <= 0 //sanity check! head must come first and have a value!
    295                     && ($sKey != "head" || sizeof($asValue) <= 0 || $asValue[0] == ""))
    296                 {
    297                     $this->sError = "Invalid file format.";
    298                     fclose($hFile);
    299                     return 0;
    300                 }
    301                 $this->aasKeys[$sKey] = $asValue;
    302             }
    303             else if ($sKey != "text")
    304             {   /* Revision information keys  */
    305                 if (!isset($this->aaasRevs[$sRev]))
    306                     $this->aaasRevs[$sRev] = array($sKey => $asValue);
    307                 else
    308                     $this->aaasRevs[$sRev][$sKey] = $asValue;
    309             }
    310             else
    311             {   /* Delta (ie. 'text') key */
    312                 $this->aasDeltas[$sRev] = $asValue;
    313             }
    314 
    315             /*
    316              * Completed reading of this key, so next one.
    317              */
    318             $fNewKey = 1;
    319 
    320             /* debug */
    321             //echo "debug key: $sKey  value(".sizeof($asValue)."):".$asValue[0]."\n";
    322         }
    323 
    324         return 1;
    325     }
    326 
    327 
    328     /**
    329      * Parses the file.
    330      * (internal)
    331      */
    332     function ParseFile2($hFile, $fNoDeltas)
    333133    {
    334134
     
    489289
    490290                /*
     291                 * Reparse the value.
     292                 */
     293                case "symbols":
     294                    $asValue2 = $asValue;
     295                    $asValue = array();
     296                    while (list ($sIgnore, $sVal) = each ($asValue2))
     297                    {
     298                        if (($sVal = trim($sVal)) != "")
     299                        {
     300                            if ($iColon = strpos($sVal, ":"))
     301                                $asValue[substr($sVal, 0, $iColon-1)] = substr($sVal, $iColon+1);
     302                            else
     303                                echo "\n<!-- error in symbols parsing -->\n";
     304                        }
     305                    }
     306                    break;
     307
     308                /*
    491309                 * Don'r read deltas for archives with the expand tag set
    492310                 */
     
    612430
    613431        /*
     432         * Make header
     433         */
     434        echo "<table><tr><td bgcolor=#f0f0f0>\n<table>";
     435        //file info
     436        echo "<tr><td valign=top><font size=-1>File:</font></td>\n",
     437             "<td><font size=-1>", $this->getDirUrls(), " / <a href=\"cvs.php?sFile=$this->sDir/$this->sName,v\">$this->sName</a></font></td></tr>\n";
     438
     439        //revision info
     440        echo "<tr><td valign=top><font size=-1>Revision:</font></td>\n",
     441             "<td><font size=-1>$sRevision, ",
     442             CVSFormatDate($this->getDate($sRevision)),
     443             " (",CVSGetAge($this->getDate($sRevision), 6), ")",
     444             "<br>by ", $this->getAuthor($sRevision),
     445             "</font></td></tr>\n";
     446
     447        //branch info
     448        echo "<tr><td valign=top><font size=-1>Branch:</font></td>\n",
     449             "<td><font size=-1>", $this->getBranch($sRevision),
     450             "</font></td></tr>\n";
     451
     452        //tag info
     453        echo "<tr><td valign=top><font size=-1>Tags:</font></td>\n",
     454             "<td><font size=-1>", $this->getTags($sRevision),
     455             "</font></td></tr>\n";
     456
     457        //log info
     458        $asLog = $this->getLog($sRevision);
     459        echo "<tr><td valign=top><font size=-1>Log:</font></td>",
     460             "<td><font size=-1>\n";
     461        if (isset($asLog))
     462            while (list($sKey, $s) = each ($asLog))
     463                echo $s; //this should be <pre> but, that will need some line wrapping...
     464                //echo str_replace("\n", "<br>", $s), "\n"; //this should be <pre> but, that will need some line wrapping...
     465        echo "</font></td><tr>\n";
     466
     467        echo "</table>\n";//<hr noshade>\n";
     468
     469
     470        /*
    614471         * Initiate the color encoder.
    615472         */
    616473        switch (strtolower($this->sExt))
    617474        {
    618             case 'c':
    619             case 'cpp':
    620             case 'cxx':
    621             case 'h':
    622             case 'hpp':
     475            case "c":
     476            case "cpp":
     477            case "cxx":
     478            case "h":
     479            case "hpp":
    623480                C_ColorInit($aVariables);
    624481                $iColorEncoder = 1;
    625482                break;
    626483
    627             case 'asm':
    628             case 'inc':
    629             case 's':
     484            case "asm":
     485            case "inc":
     486            case "s":
    630487                ASM_ColorInit($aVariables);
    631488                $iColorEncoder = 2;
    632489                break;
    633490
    634             case 'mk':
    635             case 'mak':
     491            case "mk":
     492            case "mak":
    636493                Make_ColorInit($aVariables);
    637494                $iColorEncoder = 3;
     
    639496
    640497            default:
    641                 if (strtolower($this->sName) == "makefile");
     498                if (strtolower($this->sName) == "makefile")
    642499                {
    643500                    Make_ColorInit($aVariables);
     
    654511         */
    655512        $Timer = Odin32DBTimerStart("Write timer");
    656         echo "<table><tr><td bgcolor=#020286><pre><font size=-0 face=\"System VIO, System Monospaced\" color=#02FEFE>\n";
     513        echo "<tr><td bgcolor=#020286><pre><font size=-0 face=\"System VIO, System Monospaced\" color=#02FEFE>\n";
    657514
    658515        for ($cLines = sizeof($this->aasDeltas[$sRevision]), $iLine = 0;
     
    676533                    break;
    677534                default:
    678                     echo  htmlspecialchars($this->aasDeltas[$sRevision][$iLine]);
     535                    echo  str_replace("\t", "    ", htmlspecialchars($this->aasDeltas[$sRevision][$iLine]));
    679536            }
    680537            echo "</a>";
     
    727584    function getDate($sRev)
    728585    {
    729         return @$this->aaasRevs[$sRev]["date"][0];
    730     }
    731 
    732     /**
    733      * Get the age of the given revision.
    734      * @returns     Age string. (human readable)
    735      * @param       $sRev       Revision number to get age for.
    736      */
    737     function getAge($sRev)
    738     {
    739         if (!isset($this->aaasRevs[$sRev]["date"][0]))
    740             return "<i>error</i>";
    741 
    742         $sDate = $this->aaasRevs[$sRev]["date"][0];
    743         $sCurDate = date("Y.m.d.H.i.s");
    744         if ($sDate > $sCurDate)
    745             return "0 seconds"; //fixme?
    746 
    747         /* seconds */
    748         $i1 = substr($sCurDate, 17, 2);
    749         $i2 = substr($sDate, 17, 2);
    750         if ($fBorrow = ($i1 < $i2))
    751             $i1 += 60;
    752         $iSeconds = $i1 - $i2;
    753 
    754         /* minuttes */
    755         $i1 = substr($sCurDate, 14, 2);
    756         $i2 = substr($sDate, 14, 2);
    757         if ($fBorrow)
    758             $i1--;
    759         if ($fBorrow = ($i1 < $i2))
    760             $i1 += 60;
    761         $iMinuttes = $i1 - $i2;
    762 
    763         /* hours */
    764         $i1 = substr($sCurDate, 11, 2);
    765         $i2 = substr($sDate, 11, 2);
    766         if ($fBorrow)
    767             $i1--;
    768         if ($fBorrow = ($i1 < $i2))
    769             $i1 += 24;
    770         $iHours = $i1 - $i2;
    771 
    772         /* days */
    773         $i1 = substr($sCurDate, 8, 2);
    774         $i2 = substr($sDate, 8, 2);
    775         if ($fBorrow)
    776             $i1--;
    777         if ($fBorrow = ($i1 < $i2))
    778         {
    779             $iM = substr($sCurDate, 5, 2);
    780             $iY = substr($sCurDate, 0, 4);
    781             if ($iM == 1 || $iM == 3 || $iM == 5 || $iM == 7 || $iM == 8 || $iM == 10 || $iM == 12)
    782                 $i1 += 31;
    783             else if ($iM == 4 || $iM == 6 || $iM == 9 || $iM == 11)
    784                 $i1 += 30;
    785             else if (($iY % 4) != 0 || (($iY % 100) == 0 && ($iY % 1000) != 0))
    786                 $i1 += 28;
    787             else
    788                 $i1 += 29;
    789         }
    790         $iDays = $i1 - $i2;
    791 
    792         /* months */
    793         $i1 = substr($sCurDate, 5, 2);
    794         $i2 = substr($sDate, 5, 2);
    795         if ($fBorrow)
    796             $i1--;
    797         if ($fBorrow = ($i1 < $i2))
    798             $i1 += 12;
    799         $iMonths = $i1 - $i2;
    800 
    801         /* years */
    802         $i1 = substr($sCurDate, 0, 4);
    803         $i2 = substr($sDate, 0, 4);
    804         if ($fBorrow)
    805             $i1--;
    806         $iYears = $i1 - $i2;
    807 
    808         //printf("<!-- $sCurDate - $sDate = %04d.%02d.%02d.%02d.%02d.%02d -->\n", $iYears, $iMonths, $iDays, $iHours, $iMinuttes, $iSeconds);
    809 
    810         /* make output */
    811         if ($iYears > 0)
    812             return "$iYears year".($iYears > 1 ? "s" : "")." $iMonths month".($iMonths > 1 ? "s" : "");
    813         if ($iMonths > 0)
    814             return "$iMonths month".($iMonths > 1 ? "s" : "")." $iDays day".($iDays > 1 ? "s" : "");
    815         if ($iDays > 0)
    816             return "$iDays day".($iDays > 1 ? "s" : "")." $iHours hour".($iHours > 1 ? "s" : "");
    817         if ($iHours > 0)
    818             return "$iHours hour".($iHours > 1 ? "s" : "")." $iMinuttes min";
    819         if ($iMinuttes > 0)
    820             return "$iMinuttes min $iSeconds sec";
    821        return "$iSeconds seconds";
     586        if (($sDate = @$this->aaasRevs[$sRev]["date"][0]) != ""
     587            && $sDate[2] == "." //check for two digit date
     588            )
     589            return "19".$sDate;
     590        return $sDate;
    822591    }
    823592
     
    831600    }
    832601
    833 
    834602    /**
    835603     * Get the workfile extention.
     
    849617        return isset($this->aasKeys["expand"]);
    850618    }
     619
     620    /**
     621     * Get loginfo for the given revision.
     622     * @returns     Array of log info for the given revision.
     623     * @param       $sRev       Revision number to get loginfo for.
     624     */
     625    function getLog($sRev)
     626    {
     627        return @$this->aaasRevs[$sRev]["log"];
     628    }
     629
     630    /**
     631     * Get the branch name for the given revision.
     632     * @return      Branch name.
     633     * @param       $sRev       Revision number to get branchname for.
     634     */
     635    function getBranch($sRev)
     636    {
     637        if (strpos(strpos($sRev, "."), ".") <= 0)
     638            return "MAIN";
     639        return "<i>not implemented</i>"; //TODO FIXME
     640    }
     641
     642    /**
     643     * Get the tag names associated with the given revision.
     644     * @return      comma separated list of tag names.
     645     * @param       $sRev       Revision number to get tag names for.
     646     */
     647    function getTags($sRev)
     648    {
     649        //didn't find a search function, so we'll do a linear search.
     650        //thru the symbols. Correct this when/if a array search function
     651        //is found.
     652        $sTags = "";
     653        if (isset($this->aasKeys["symbols"]))
     654        {
     655            $asSymbols = $this->aasKeys["symbols"];
     656            while (list($sTag, $sTagRev) = each($asSymbols))
     657                if ($sTagRev == $sRev)
     658                    $sTags = ", $sTag";
     659        }
     660
     661        //check for head revision
     662        if ($sRev == $this->aasKeys["head"][0])
     663            $sTags = ", HEAD";
     664
     665        return substr($sTags, 2); //remove ", "
     666    }
     667
     668    /**
     669     * Get a directory string (for this file) where every level
     670     * is an URL to the page for it.
     671     * @return      URL directory string.
     672     */
     673    function getDirUrls()
     674    {
     675        return CVSGetDirUrls($this->sDir);
     676    }
     677
     678    /**
     679     * Get changes string for this revision.
     680     * (Won't work for the head revision!)
     681     * @return      Changes string: "+x -y lines".
     682     * @param       $sRev   Revision which we're to count changes for.
     683     */
     684    function getChanges($sRev)
     685    {
     686        if (!isset($this->aasDeltas[$sRev]))
     687            return "<i>error</i>";
     688        if ($sRev == $this->aasKeys["head"][0])
     689            return "+0 -0 lines";
     690        $cAdd = 0;
     691        $cDelete = 0;
     692
     693        for ($i = 0, $c = sizeof($this->aasDeltas[$sRev]); $i < $c; $i++)
     694        {
     695            $sLine = $this->aasDeltas[$sRev][$i];
     696            if ($sLine[0] == "d")
     697                $cDelete += (int)substr($sLine, strpos($sLine, " ") + 1);
     698            else if ($sLine[0] == "a")
     699            {
     700                $cAdd += (int)substr($sLine, strpos($sLine, " ") + 1);
     701                $i += $cLines;
     702            }
     703            else
     704                echo "<!-- hmm internal error in getChanges -->\n";
     705        }
     706
     707        return "+$cDelete -$cAdd lines"; //note the deltas is for going the other way...
     708    }
     709
     710    /**
     711     *
     712     * @return
     713     */
     714    function PrintAllInfo()
     715    {
     716
     717        //file info
     718        echo "<font size=-1>", $this->getDirUrls(), " / $this->sName</font><p>\n",
     719             "\n";
     720
     721        echo "<table>\n";
     722        //do we have to sort the array first? no...
     723        while (list($sRevision, $aasRev) = each($this->aaasRevs))
     724        {
     725            echo "<tr><td bgcolor=#d0dce0>Rev. <a href=\"cvs.php?sFile=$this->sDir/$this->sName,v&sRevision=$sRevision\"",
     726                 "<a name=\"$sRevision\">$sRevision</a></a> by ",
     727                 $this->getAuthor($sRevision) ,"</td></tr>\n",
     728                 "<tr><td bgcolor=#f0f0f0>";
     729
     730            echo "<table>";
     731            //revision date info
     732            echo "<tr><td valign=top><font size=-1>Date:</font></td>\n",
     733                 "<td><font size=-1>",CVSFormatDate($this->getDate($sRevision)),
     734                 "<br>(",CVSGetAge($this->getDate($sRevision), 6), ")",
     735                 "</font></td></tr>\n";
     736
     737            //branch info
     738            echo "<tr><td valign=top><font size=-1>Branch:</font></td>\n",
     739                 "<td><font size=-1>", $this->getBranch($sRevision),
     740                 "</font></td></tr>\n";
     741
     742            //tag info
     743            echo "<tr><td valign=top><font size=-1>Tags:</font></td>\n",
     744                 "<td><font size=-1>", $this->getTags($sRevision),
     745                 "</font></td></tr>\n";
     746
     747            //Changes info
     748            if (isset($aasRev["next"]) && ($sPrevRev = $aasRev["next"][0]) != "")
     749            {
     750                echo "<tr><td valign=top><font size=-1>Changes since $sPrevRev:</font></td>\n",
     751                     "<td><font size=-1>", $this->getChanges($sPrevRev),
     752                     "</font></td></tr>\n";
     753            }
     754
     755            //log info
     756            $asLog = $this->getLog($sRevision);
     757            echo "<tr><td valign=top><font size=-1>Log:</font></td><td><font size=-1>\n";
     758            if (isset($asLog))
     759                while (list($sKey, $s) = each ($asLog))
     760                    echo $s; //this should be <pre> but, that will need some line wrapping...
     761                    //echo str_replace("\n", "<br>", $s), "\n"; //this should be <pre> but, that will need some line wrapping...
     762            echo "</font></td></tr>\n";
     763
     764            echo "</table>\n";
     765
     766            echo "</td></tr>\n";
     767        }
     768
     769        echo "</table>\n";
     770    }
     771}
     772
     773
     774/**
     775 * Get a directory string where every level
     776 * is an URL to the page for it.
     777 * @return      URL directory string.
     778 * @param       Directory string to process.
     779 */
     780function CVSGetDirUrls($sDir)
     781{
     782    if ($sDir == "")
     783        $sDir = "./";
     784    else if (substr($sDir, -1) != "/")
     785        $sDir .= "/";
     786
     787    $iPrev = 2;
     788    $sRet = "<a href=\"cvs.php?sDir=.\">[root]</a>";
     789    while ($i = @strpos($sDir, "/", $iPrev))
     790    {
     791        $sRet .= " / <a href=\"cvs.php?sDir=".substr($sDir, 0, $i)."\">".
     792                    substr($sDir, $iPrev, $i - $iPrev)."</a>";
     793        $iPrev = $i + 1;
     794    }
     795
     796    return $sRet;
     797}
     798
     799
     800
     801/**
     802 * Get a understandable date string from a CVS date.
     803 * @returns     Date string (human readable)
     804 * @param       $sDate      CVS date string. (as returned by getDate())
     805 */
     806function CVSFormatDate($sDate)
     807{
     808    $Time = mktime( substr($sDate,11, 2), //hour
     809                    substr($sDate,14, 2), //minute
     810                    substr($sDate,17, 2), //second
     811                    substr($sDate, 5, 2), //month
     812                    substr($sDate, 8, 2), //day
     813                    substr($sDate, 0, 4));//year
     814    return date("D M d h:i:s Y", $Time);
     815}
     816
     817
     818/**
     819 * Calculate the period between $sDate and the current date.
     820 * @returns     Age string. (human readable)
     821 * @param       $sDate      CVS date string. (as returned by getDate())
     822 * @param       $cLevels    Number of levels to be specified.
     823 */
     824function CVSGetAge($sDate, $cLevels)
     825{
     826    $sCurDate = date("Y.m.d.H.i.s");
     827    if ($sDate > $sCurDate)
     828        return "0 seconds"; //fixme?
     829
     830    /* seconds */
     831    $i1 = substr($sCurDate, 17, 2);
     832    $i2 = substr($sDate, 17, 2);
     833    if ($fBorrow = ($i1 < $i2))
     834        $i1 += 60;
     835    $iSeconds = $i1 - $i2;
     836
     837    /* minutes */
     838    $i1 = substr($sCurDate, 14, 2);
     839    $i2 = substr($sDate, 14, 2);
     840    if ($fBorrow)
     841        $i1--;
     842    if ($fBorrow = ($i1 < $i2))
     843        $i1 += 60;
     844    $iMinutes = $i1 - $i2;
     845
     846    /* hours */
     847    $i1 = substr($sCurDate, 11, 2);
     848    $i2 = substr($sDate, 11, 2);
     849    if ($fBorrow)
     850        $i1--;
     851    if ($fBorrow = ($i1 < $i2))
     852        $i1 += 24;
     853    $iHours = $i1 - $i2;
     854
     855    /* days */
     856    $i1 = substr($sCurDate, 8, 2);
     857    $i2 = substr($sDate, 8, 2);
     858    if ($fBorrow)
     859        $i1--;
     860    if ($fBorrow = ($i1 < $i2))
     861    {
     862        $iM = substr($sCurDate, 5, 2);
     863        $iY = substr($sCurDate, 0, 4);
     864        if ($iM == 1 || $iM == 3 || $iM == 5 || $iM == 7 || $iM == 8 || $iM == 10 || $iM == 12)
     865            $i1 += 31;
     866        else if ($iM == 4 || $iM == 6 || $iM == 9 || $iM == 11)
     867            $i1 += 30;
     868        else if (($iY % 4) != 0 || (($iY % 100) == 0 && ($iY % 1000) != 0))
     869            $i1 += 28;
     870        else
     871            $i1 += 29;
     872    }
     873    $iDays = $i1 - $i2;
     874
     875    /* months */
     876    $i1 = substr($sCurDate, 5, 2);
     877    $i2 = substr($sDate, 5, 2);
     878    if ($fBorrow)
     879        $i1--;
     880    if ($fBorrow = ($i1 < $i2))
     881        $i1 += 12;
     882    $iMonths = $i1 - $i2;
     883
     884    /* years */
     885    $i1 = substr($sCurDate, 0, 4);
     886    $i2 = substr($sDate, 0, 4);
     887    if ($fBorrow)
     888        $i1--;
     889    $iYears = $i1 - $i2;
     890
     891    //printf("<!-- $sCurDate - $sDate = %04d.%02d.%02d.%02d.%02d.%02d -->\n", $iYears, $iMonths, $iDays, $iHours, $iMinutes, $iSeconds);
     892
     893
     894    /* make output */
     895    $sRet = "";
     896    if ($cLevels > 0 && $iYears > 0)
     897    {
     898        $cLevels--;
     899        $sRet .= "$iYears year".($iYears > 1 ? "s" : "");
     900    }
     901    if ($cLevels > 0 && $iMonths > 0)
     902    {
     903        $cLevels--;
     904        $sRet .= " $iMonths month".($iMonths > 1 ? "s" : "");
     905    }
     906    if ($cLevels > 0 && $iDays > 0)
     907    {
     908        $cLevels--;
     909        $sRet .= " $iDays day".($iDays > 1 ? "s" : "");
     910    }
     911    if ($cLevels > 0 && $iHours > 0)
     912    {
     913        $cLevels--;
     914        $sRet .= " $iHours hour".($iHours > 1 ? "s" : "");
     915    }
     916    if ($cLevels > 0 && $iMinutes > 0)
     917    {
     918        $cLevels--;
     919        $sRet .= " $iMinutes minute".($iHours > 1 ? "s" : "");
     920    }
     921    if ($cLevels > 0)
     922        $sRet .= " $iSeconds second".($iHours > 1 ? "s" : "");
     923    return ltrim($sRet);
    851924}
    852925
     
    869942    if ($sDir[0] == '/')
    870943        $sDir = substr($sDir, 1);
    871     if ($sDir[strlen($sDir)-1] == '/')
    872         $sDir = substr($sDir, 0, strlen($sDir) - 1);
     944    if (substr($sDir, -1) == '/')
     945        $sDir = substr($sDir, 0, - 1);
    873946    if ((strlen($sDir) == 2 && $sDir == "..")
    874947        ||
    875948        (substr($sDir, 0, 3) == "../")
    876949        ||
    877         (substr($sDir, strlen($sDir)-3) == "/..")
     950        (substr($sDir, -3) == "/..")
    878951        ||
    879952        (strpos($sDir, "/../") > 0)
     
    9651038        {
    9661039            $asRev[$sFile]    = $sRev = $obj->getHead();
    967             $asAge[$sFile]    = $obj->getAge($sRev);
     1040            $asDate[$sFile]   = $obj->getDate($sRev);
    9681041            $asAuthor[$sFile] = $obj->getAuthor($sRev);
    9691042            $asTmpLog         = $obj->getLog($sRev);
     
    9901063
    9911064    /*
     1065     * Write header
     1066     */
     1067    echo "<font size=-1>", CVSGetDirUrls(dirname($sDir)),
     1068         ($sDir != "." ? " / ".substr($sDir, strrpos($sDir, "/") + 1) : ""),
     1069         " /</font><p>\n";
     1070
     1071    /*
    9921072     * Sort the stuff.
    9931073     */
     
    9971077        case 0:     $asSorted = $asFiles; break;
    9981078        case 1:     $asSorted = $asRev; break;
    999         case 2:     $asSorted = $asAge; break;
     1079        case 2:     $asSorted = $asDate; break;
    10001080        case 3:     $asSorted = $asAuthor; break;
    10011081        case 4:     $asSorted = $asLog; break;
     
    10101090    $aColumnColors = array("#d0dce0","#d0dce0","#d0dce0","#d0dce0", "#d0dcff","#d0dce0","#d0dce0","#d0dce0","#d0dce0");
    10111091    echo "<table border=0 width=100% cellspacing=1 cellpadding=2>\n",
    1012          "  <hr NOSHADE>\n",
    1013          "    <th bgcolor=",$aColumnColors[4+0-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=0>Filename</a></b></font></th>\n",
    1014          "    <th bgcolor=",$aColumnColors[4+1-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=1>Rev</a></b></font></th>\n",
    1015          "    <th bgcolor=",$aColumnColors[4+2-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=2>Age</a></b></font></th>\n",
    1016          "    <th bgcolor=",$aColumnColors[4+3-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=3>Author</a></b></font></th>\n",
    1017          "    <th bgcolor=",$aColumnColors[4+4-$iSortColumn],"><font size=-1><b><a href=cvs.phtml?sDir=$sDir&iSortColumn=4>Last Log Entry</a></b></font></th>\n",
    1018          "  </hr>\n";
     1092         "  <tr>\n",
     1093         "    <th bgcolor=",$aColumnColors[4+0-$iSortColumn],"><font size=-1><b><a href=cvs.php?sDir=$sDir&iSortColumn=0>Filename</a></b></font></th>\n",
     1094         "    <th bgcolor=",$aColumnColors[4+1-$iSortColumn],"><font size=-1><b><a href=cvs.php?sDir=$sDir&iSortColumn=1>Rev</a></b></font></th>\n",
     1095         "    <th bgcolor=",$aColumnColors[4+2-$iSortColumn],"><font size=-1><b><a href=cvs.php?sDir=$sDir&iSortColumn=2>Age</a></b></font></th>\n",
     1096         "    <th bgcolor=",$aColumnColors[4+3-$iSortColumn],"><font size=-1><b><a href=cvs.php?sDir=$sDir&iSortColumn=3>Author</a></b></font></th>\n",
     1097         "    <th bgcolor=",$aColumnColors[4+4-$iSortColumn],"><font size=-1><b><a href=cvs.php?sDir=$sDir&iSortColumn=4>Last Log Entry</a></b></font></th>\n",
     1098         "  </tr>\n";
    10191099    $i = 0;
    10201100    /* directories */
     
    10281108        echo "<tr>\n",
    10291109             " <td", $sBgColor , ">",
    1030                "<font size=-1><a href=\"cvs.phtml?sDir=",$sParentDir,"\"><img src=\"/icons/back.gif\" border=0> Parent Directory</a></font></td>\n",
     1110               "<font size=-1><a href=\"cvs.php?sDir=",$sParentDir,"\"><img src=\"/icons/back.gif\" border=0> Parent Directory</a></font></td>\n",
    10311111             " <td$sBgColor>&nbsp;</td>\n",
    10321112             " <td$sBgColor>&nbsp;</td>\n",
     
    10391119        $sBgColor = ($i++ % 2) ? "" : " bgcolor=#f0f0f0";
    10401120        echo "<tr>\n",
    1041              " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sDir=$sDir/$sVal\"><img src=\"/icons/dir.gif\" border=0> $sVal</a></font></td>\n",
     1121             " <td$sBgColor><font size=-1><a href=\"cvs.php?sDir=$sDir/$sVal\"><img src=\"/icons/dir.gif\" border=0> $sVal</a></font></td>\n",
    10421122             " <td$sBgColor>&nbsp;</td>\n",
    10431123             " <td$sBgColor>&nbsp;</td>\n",
     
    10511131    {
    10521132        $sBgColor = ($i++ % 2) ? "" : " bgcolor=#f0f0f0";
    1053         $sRev   = isset($asRev[$sKey])  ? $asRev[$sKey]     : "<i> error </i>";
    1054         $sAge   = isset($asAge[$sKey])  ? $asAge[$sKey]    : "<i> error </i>";
    1055         $sAuthor= isset($asAuthor[$sKey])?$asAuthor[$sKey]  : "<i> error </i>";
    1056         $sLog   = isset($asLog[$sKey])  ? $asLog[$sKey]     : "<i> error </i>";
    1057         $sIcon  = isset($asIcon[$sKey]) ? $asIcon[$sKey]    : "<i> error </i>";
     1133        $sRev   = isset($asRev[$sKey])  ? $asRev[$sKey]             : "<i> error </i>";
     1134        $sAge   = isset($asDate[$sKey]) ? CVSGetAge($asDate[$sKey], 1) : "<i> error </i>";
     1135        $sAuthor= isset($asAuthor[$sKey])?$asAuthor[$sKey]          : "<i> error </i>";
     1136        $sLog   = isset($asLog[$sKey])  ? $asLog[$sKey]             : "<i> error </i>";
     1137        $sIcon  = isset($asIcon[$sKey]) ? $asIcon[$sKey]            : "<i> error </i>";
    10581138        echo "<tr>\n",
    1059              " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sFile=$sDir/$sKey\"><img src=\"/icons/$sIcon\" border=0>",substr($sKey, 0, -2),"</a></font></td>\n",
    1060              " <td$sBgColor><font size=-1><a href=\"cvs.phtml?sFile=$sDir/$sKey?sRev=$sRev\">$sRev</a></font></td>\n",
     1139             " <td$sBgColor><font size=-1><a href=\"cvs.php?sFile=$sDir/$sKey\"><img src=\"/icons/$sIcon\" border=0>",substr($sKey, 0, -2),"</a></font></td>\n",
     1140             " <td$sBgColor><font size=-1><a href=\"cvs.php?sFile=$sDir/$sKey&sRevision=$sRev\">$sRev</a></font></td>\n",
    10611141             " <td$sBgColor><font size=-1>$sAge</font></td>\n",
    10621142             " <td$sBgColor><font size=-1>$sAuthor</font></td>\n",
Note: See TracChangeset for help on using the changeset viewer.