några sidor på nätet om PHP programmering

Sök efter  
Börja här Uppgifter Testa dig själv Tips Sidokarta mm. Länkar Sök

links.php compat.php settings.php source.php main.txt Typisk sida

5.2.1 links.php

Denna fil hanterar navigeringen och nästan allt annat i denna site.

<?php
# Skulle gärna få vara rock'n'roll men är väl mest quick'n'dirty
# Skit samma, den fungerar... Mångfald är bättre än enfald.



include_once( dirname__FILE__ ) . "/compat.php" );
include_once( 
dirname__FILE__ ) . "/settings.php" );

set_time_limit 120 );

# klassen för (nästan) allt
class linkList
{
        var 
$fcontents;        # styrfilens innehåll i en array
        
var $fname;                # länkfilens namn
        
var $thisfile;        # nuvarande fils namn
        
var $currInd ;        # nuvarande index
        
var $nextInd ;        # nästa rads index
        
var $prevInd ;        # föregående rads index
        
var $count ;         # antal rader
        # var $fn;

        
var $lastCurrInd1;
        var 
$lastCurrInd2;
        var 
$lastCurrInd3;
        var 
$lastCurrInd4;
        var 
$lastCurrInd5;
        var 
$lastCurrInd1Count;
        var 
$lastCurrInd2Count;
        var 
$lastCurrInd3Count;
        var 
$currLev;
        var 
$bgrnd ;

        
# constructor
        # Indata:
        # $linkFile - namnet på styrfilen
        
function linkList$linkFile )
        {

                
$this->fname $linkFile;
                
$this->thisfile _ServerData"PHP_SELF" );

                
# läser in hela styrfilen i en array
                
$this->fcontents file $linkFile );
                
$this->currInd $this->GetListIndex ( ) ;
                
$this->count $this->GetListCount( ) - 1;

                
$this->nextInd $this->currInd == $this->count ?
                                                
:
                                                
$this->currInd ;
                if ( 
trim$this->GetNthURL$this->nextInd ) ) == "" )
                {
                        
$this->nextInd $this->nextInd == $this->count ?
                                                
:
                                                
$this->nextInd ;
                }
                
$this->prevInd $this->currInd == ?
                        
$this->count :
                        
$this->currInd ;

                if ( 
trim$this->GetNthURL$this->prevInd ) ) == "" )
                {
                        
$this->prevInd $this->prevInd == ?
                                
$this->count :
                                
$this->prevInd ;
                }
                
$this->CheckAllLevels( );
        }

        
# vilken fil i ordningen är nu aktuell
        
function GetListIndex( )
        {
                
$retval 0;
                
$curr basename$this->thisfile );
                while ( list ( 
$line_num$line ) = each $this->fcontents ) )
                {
                        if ( 
trimstrtolowersubstr$line0strpos$line"\t" ) ) ) )
                                == 
$curr )
                        {
                                
$retval $line_num 1;
                                break;
                        }
                }
                
reset$this->fcontents );
                return 
$retval;
        }

        function 
GetNthUrl$rowNo )
        {
                if ( 
$rowNo <= count$this->fcontents ) && $rowNo )
                {
                        
$theValue $this->fcontents$rowNo -];
                        return 
trimsubstr$theValue0strpos$theValue"\t" ) ) );
                }
                else
                {
                        return 
"N/A";
                }
        }
        function 
GetNthDescription$rowNo )
        {
                if ( 
$rowNo <= count$this->fcontents ) && $rowNo )
                {
                        
$theValue $this->fcontents$rowNo -];
                        return 
htmlentitiessubstr$theValuestrpos$theValue"\t" ) ) );
                }
                else
                {
                        return 
"N/A";
                }
        }

        function 
GetNthDescriptionRaw$rowNo )
        {
                if ( 
$rowNo <= count$this->fcontents ) && $rowNo )
                {
                        
$theValue $this->fcontents$rowNo -];
                        return 
substr$theValuestrpos$theValue"\t" ) );
                }
                else
                {
                        return 
"N/A";
                }
        }

        function 
GetCurUrl( )
        {
                
$theValue $this->fcontents$this->currInd -];
                return 
trimsubstr$theValue0strpos$theValue"\t" ) ) );
        }

        function 
GetNextUrl( )
        {
                
$theValue $this->fcontents$this->nextInd ];
                return 
trimsubstr$theValue0strpos$theValue"\t" ) ) );
        }

        function 
GetPrevUrl( )
        {
         
$theValue $this->fcontents$this->prevInd ];
         return 
trimsubstr$theValue0strpos$theValue"\t" ) ) );
        }

        function 
GetCurDescription( )
        {
                
$theValue $this->fcontents$this->currInd ];
                return 
htmlentitiessubstr$theValuestrpos$theValue"\t" ) ) );
        }

        function 
GetNextDescription( )
        {
                
$theValue $this->fcontents$this->nextInd ];
                return 
htmlentitiessubstr$theValuestrpos$theValue"\t" ) ) );
        }

        function 
GetPrevDescription( )
        {
                
$theValue $this->fcontents$this->prevInd ];
                return 
htmlentitiessubstr$theValuestrpos$theValue"\t" ) ) );
        }

        function 
GetListCount( )
        {
                return 
is_array($this->fcontents) ? count$this->fcontents ) + 0;;
        }

        function 
autoNum$rowNo  )
        {
                if( 
$this->currLev == )
                {
                        return 
$this->lastCurrInd1Count;
                }
                elseif( 
$this->currLev == )
                {
                        return 
$this->lastCurrInd1Count .
                                                        
"." .
                                                        (
$this->lastCurrInd2Count);
                }
                elseif( 
$this->currLev == )
                {

                                return 
$this->lastCurrInd1Count .
                                                        
"." .
                                                        (
$this->lastCurrInd2Count) .
                                                        
"." .
                                                        (
$this->lastCurrInd3Count) ;

                }

        }

        function 
theTitleAutoNum$rowNo )
        {
                return 
$this->autoNum$rowNo ) . " " $this->theTitle$rowNo );
        }

        function 
theTitle$rowNo )
        {
                
$description $this->GetNthDescription$rowNo );
                
$MyArray explode'|'$description );
                if ( 
count$MyArray ) > )
                {
                        return 
trim$MyArray] );
                }
                else
                {
                        return 
$this->theText$rowNo );
                }
        }

        function 
theText$rowNo )
        {
                
$description $this->GetNthDescription$rowNo );
                
$MyArray explode'|'$description );
                if ( 
count$MyArray) > )
                {
                        return 
trim$MyArray] );
                }
                else
                {
                        return 
"";
                }
        }

        function 
theTextAutoNum$rowNo )
        {
                static 
$c1$c2$c3;
                if( 
$this->theLevel$rowNo  ) == )
                {
                        
$c2 0;
                        
$c3 0;
                        return ++
$c1 " " $this->theText$rowNo ) ;
                }
                if( 
$this->theLevel$rowNo  ) == )
                {
                        
$c3 0;
                        return 
$c1 "." . ++$c2 " " $this->theText$rowNo ) ;
                }
                elseif( 
$this->theLevel$rowNo  ) == )
                {
                        return 
$c1 "." $c2 "." . ++$c3 " " $this->theText$rowNo );
                }

        }

        function 
theTextRaw$rowNo )
        {
                
$description $this->GetNthDescriptionRaw$rowNo );
                
$MyArray explode'|'$description );
                if (
count$MyArray) > )
                {
                        return 
trim$MyArray] );
                }
                else
                {
                        return 
"";
                }
        }

        function 
theLevel$rowNo )
        {
                
$description $this->GetNthDescription$rowNo );
                
$MyArray explode'|'$description );
                return 
trim$MyArray] );
        }

        
# söker senaste länken på nivå 1, 2, 3, 4, och 5
        # används bl.a av PutHistoryList funktionen
        
function CheckAllLevels( )
        {
                
$this->lastCurrInd1 0;
                
$this->lastCurrInd2 0;
                
$this->lastCurrInd3 0;
                
$this->lastCurrInd4 0;
                
$this->lastCurrInd5 0;
                
$this->lastCurrInd1Count 0;
                
$this->lastCurrInd2Count 0;
                
$this->lastCurrInd3Count 0;

                
$this->count $this->GetListCount( );
                
$count $this->count;
                
$currInd $this->currInd ;
                
$this->currLev $this->theLevel$currInd );
                for ( 
$row 1$row <= $currInd$row++ )
                {
                        
$level $this->theLevel$row );
                        if ( 
$level == && $row <= $count )
                        {
                                
$this->lastCurrInd1 $row ;
                                
$this->lastCurrInd1Count++;
                                
$this->lastCurrInd2Count 0;
                                
$this->lastCurrInd3Count 0;
                        }
                        if ( 
$level == && $row <= $count )
                        {
                                
$this->lastCurrInd2 $row ;
                                if ( 
trim $this->getNthURL$row ) ) != "" )
                                        
$this->lastCurrInd2Count++;
                                
$this->lastCurrInd3Count 0;
                        }
                        if ( 
$level == && $row <= $count )
                        {
                                
$this->lastCurrInd3 $row ;
                                if ( 
trim $this->getNthURL$row ) ) != "" )
                                        
$this->lastCurrInd3Count++;
                        }
                        if ( 
$level == && $row <= $count )
                        {
                                
$this->lastCurrInd4 $row ;
                        }
                        if ( 
$level == && $row <= $count )
                        {
                                
$this->lastCurrInd5 $row ;
                        }
                        if ( 
$this->lastCurrInd2 $this->lastCurrInd1 )
                        {
                                
$this->lastCurrInd2 $this->lastCurrInd1;
                        }
                        if ( 
$this->lastCurrInd3 $this->lastCurrInd2 )
                        {
                                
$this->lastCurrInd3 $this->lastCurrInd2;
                        }
                        if ( 
$this->lastCurrInd4 $this->lastCurrInd3 )
                        {
                                
$this->lastCurrInd4 $this->lastCurrInd3;
                        }
                        if ( 
$this->lastCurrInd5 $this->lastCurrInd4 )
                        {
                                
$this->lastCurrInd5 $this->lastCurrInd4;
                        }
                }
        }

        
# sätter ut en lista i stil med Yahoos i formen
        # PHP --> Introduktion --> Objekt och klasser
        # för att folk skall kunna veta hur de kommit till en sida
        
function PutHistoryList( )
        {
                echo 
"<a href=\"" $this->GetNthUrl $this->lastCurrInd1 ) . "\">" ;
                echo 
$this->theText$this->lastCurrInd1 );
                echo        
"</a>" ;
                if ( 
$this->currLev && $this->lastCurrInd2 <> $this->lastCurrInd1 )
                {
                        echo 
"<img src=\"./images/p.gif\">" ;
                        echo 
"<a href=\"" $this->GetNthUrl $this->lastCurrInd2 ) . "\">" ;
                        echo 
$this->theText$this->lastCurrInd2 );
                        echo 
"</a>" ;
                }
                if ( 
$this->currLev && $this->lastCurrInd3 <> $this->lastCurrInd2 )
                {
                        echo 
"<img src=\"./images/p.gif\">" ;
                        echo 
"<a href=\"" $this->GetNthUrl $this->lastCurrInd3 ) . "\">" ;
                        echo 
$this->theText$this->lastCurrInd3 ) ;
                        echo 
"</a>" ;
                }
                if ( 
$this->currLev && $this->lastCurrInd4 <> $this->lastCurrInd3 )
                {
                        echo 
" --> " ;
                        echo 
"<a href=\"" $this->GetNthUrl $this->lastCurrInd4 ). "\">" ;
                        echo 
$this->theText(        $this->lastCurrInd4 ) ;
                        echo 
"</a>" ;
                }
                if ( 
$this->currLev 4        and $this->lastCurrInd5 <> $this->lastCurrInd4)
                {
                        echo 
" --> " ;
                        echo 
"<a href=\"" $this->GetNthUrl $this->lastCurrInd5 ) . "\">" ;
                        echo 
$this->theText$this->lastCurrInd5 ) ;
                        echo 
"</a>" ;
                }
        }

        
# sätt ut alla länkar på nivå 1
        
function Putlevel1( )
        {
                
$count $this->count ;
                
$lastCurrInd1 $this->lastCurrInd1 ;

                
# hit sätter vi det som skall komma före länklistan, t.ex. <table><tr>...
                
echo "<table border=\"0\" valign=\"top\"><tr valign=\"top\">        ";
                for( 
$I $I <= $count$I++)
                {
                        if (
$this->theLevel$I ) == 1)
                        {
                                if( 
$lastCurrInd1 == $I )
                                {
                                        
# Denna plats kommer vi till om vi antingen har valt exakt
                                        # denna sida eller om den aktuella sidan hör under
                                        # denna nivå 1 sida
                                        
echo "<td><b><a href=\"" ;
                                        echo 
$this->GetNthURL $I ) ;
                                        echo 
"\">";
                                        echo 
$this->theText$I );
                                        echo 
"</a></b>\n";
                                        if ( 
$I $count -1)
                                        {
                                                echo 
"</td><td>";
                                                echo 
"<img src=\"../phpkurs/images/box.gif\"";
                                                echo 
" width=\"14\" height=\"14\">";
                                        }
                                        echo 
"</td>\n";
                                }
                                else
                                {
                                        
# hit kommer vi om aktuell sida inte hör till denna nivå 1 del
                                        
echo "<td><a href=\"" ;
                                        echo 
$this->GetNthURL $I ) ;
                                        echo 
"\">";
                                        echo 
$this->theText$I );
                                        echo 
"</a>\n";
                                        if ( 
$I $count -1)
                                        {
                                                echo 
"</td><td>";
                                                echo 
"<img src=\"../phpkurs/images/box.gif\"";
                                                echo 
" width=\"14\" height=\"14\">";
                                        }
                                        echo 
"</td>\n";
                                }
                        }
                }
                
# hit sätter vi det som skall komma efter länklistan,
                # t.ex. ...</tr></table>
                
echo "</tr></table>";
        }

        
# sätt ut alla länkar på nivå 2
        
function Putlevel2( )
        {

                
# hit sätter vi det som skall komma före länklistan,
                # t.ex. <table><tr>...
                
echo "<table width=\"100%\" border=\"0\" ";
                echo 
"cellpadding=\"0\" cellspacing=\"0\" class=\"linklistCopy\">";

                for (
$I $this->lastCurrInd1 +1$I <= $this->count$I++)
                {
                        if ( 
$this->theLevel$I ) == )
                        {
                                if (
$I $this->count && $this->theLevel$I ) > 2)
                                {
                                        
$e "<font size=\"1\" color=\"#BBBBBB\">&gt;</font>";
                                }
                                else
                                        
$e "&nbsp;";
                                if( 
$this->lastCurrInd2 == $I )
                                {
                                        
# Denna plats kommer vi till om vi antingen har valt exakt
                                        # denna sida eller om den aktuella sidan hör under
                                        # denna nivå 2 sida
                                        
echo "<tr class=\"navSelected\"><td width=\"14\" >";
                                        echo 
"<img src=\"./images/pil.gif\" width=\"14\" ";
                                        echo 
" height=\"14\"></td><td>";

                                        echo 
"<a href=\"" ;
                                        echo 
$this->GetNthURL $I ) ;
                                        echo 
"\">";
                                        echo 
"<strong>";
                                        echo 
$this->theText$I );
                                        echo 
"</strong></a></td><td align=\"right\">";
                                        echo 
$e "</td></tr>\n";
                                }
                                else
                                {
                                        
# hit kommer vi om aktuell sida inte hör till denna
                                        # nivå 2 del

                                        
if (trim($this->GetNthURL $I )) != "")
                                        {
                                                echo 
"<tr><td width=\"14\" >";
                                                echo 
"<img src=\"./images/tom.gif\" width=\"14\" ";
                                                echo 
" height=\"14\"></td><td>";
                                                echo 
"<a href=\"" ;
                                                echo 
$this->GetNthURL $I ) ;
                                                echo 
"\">";
                                                echo 
$this->theText$I );
                                                echo 
"</a><td align=\"right\">"$e "</td>\n";
                                        }
                                        else
                                        {
                                                echo 
"<tr><td colspan=\"3\">&nbsp;</td></tr>";
                                                echo 
"<tr><td colspan=\"3\">";
                                                echo 
"<b>" $this->theText$I ) . "</b>";
                                                echo 
"</tr>\n";
                                        }
                                }
                        }
                        
# behöver inte loopa längre för vi kom till en nivå 1
                        
if ( $this->theLevel$I ) == )
                        {
                                break ;
                        }
                }
                
# hit sätter vi det som skall komma efter länklistan, t.ex. </tr>...
                
echo "</table>";
        }

        
# sätt ut alla länkar på nivå 3 och 4
        
function PutLevel3( )
        {
                
# hit sätter vi det som skall komma före länklistan,
                # t.ex. <table cellpadding=\"1\" cellspacing=\"1\"><tr>...
                
if( $this->theLevel$this->lastCurrInd2+) > 2)
                {

                        for (
$row $this->lastCurrInd2+1$row <= $this->count $row++)
                        {
                                
$curLev $this->thelevel$row );
                                if ( 
$curLev || $row == $this->lastCurrInd2 )
                                {
                                        if (
                                                        
$row == $this->lastCurrInd3 ||
                                                        
$row == $this->lastCurrInd4 )
                                        {
                                                
# nuvarande fil hör till denna sektion
                                                # sätter nu bara fetstil
                                                # hit kommer koden för nivå 3
                                                
if ( $curLev <= 3)
                                                {
                                                        echo 
"<img src=\"../phpkurs/images/box.gif\" ";
                                                        echo 
" width=\"14\" height=\"14\">";
                                                        echo 
"<a href=\"" $this->GetNthURL $row ) . "\">\n" ;
                                                        echo 
"<strong>";
                                                        echo 
$this->theText$row ) . "</strong></a>\n";
                                                }
                                                else
                                                {
                                                        
# och för nivå 4
                                                        
echo "<img src=\"../phpkurs/images/box.gif\" ";
                                                        echo 
" width=\"14\" height=\"14\">";
                                                        echo 
"<a href=\"" $this->GetNthURL $row ) . "\">\n" ;
                                                        echo 
"<strong>" ;
                                                        echo 
"  " $this->theText$row ) ;
                                                        echo 
"</strong></a>\n";
                                                }
                                        }
                                        else
                                        {
                                                
# hit kommer koden för nivå 3
                                                
if ( $curLev <= 3)
                                                {
                                                        echo 
"<img src=\"../phpkurs/images/box.gif\" ";
                                                        echo 
" width=\"14\" height=\"14\">";
                                                        echo 
"<a href=\"" $this->GetNthURL $row ) . "\">\n" ;
                                                        echo 
$this->theText$row ) . "</a>\n";
                                                }
                                                else
                                                {
                                                        
# och för nivå 4
                                                        
echo "<img src=\"../phpkurs/images/box.gif\" ";
                                                        echo 
" width=\"14\" height=\"14\">";
                                                        echo 
"<a href=\"" $this->GetNthURL $row ) . "\">\n" ;
                                                        echo 
"  " $this->theText$row ) . "</a>\n";
                                                }
                                        }
                                }
                                if (
$row $this->lastCurrInd2 && $this->theLevel$row+) < )
                                {
                                        break;
                                }
                        }
                        
# hit sätter vi det som skall komma efter länklistan, t.ex. </tr>...
                
}
        }

        
# sätt ut alla länkar till föregående och nästa samt sourcecode
        
function PutNextPrev( )
        {
                
# koden som sätter in föregående
                
echo "<a href=\"" $this->GetNthURL $this->prevInd ) . "\"";
                echo 
"title=\"" $this->TheText$this->prevInd ) . "\">" ;
                echo 
"<img src=\"./images/prev.gif\" width=\"20\" ";
                echo 
" height=\"14\" border=\"0\">" ;
                echo 
"</a>" ;

                
# koden som sätter in nästa
                
echo "<a href=\"" $this->GetNthURL $this->nextInd ) . "\" ";
                echo 
"title=\"" $this->TheText$this->nextInd ) . "\">";
                echo 
"<img src=\"./images/next.gif\" width=\"20\" ";
                echo 
" height=\"14\" border=\"0\">" ;
                echo 
"</a>\n" ;
        }

        
# sätt ut sidokartan
        
function PutSitemap()
        {
                
$filen file"./text/keywords2.txt" );
                
# kommer som en array - så jag föser ihop den
                
$filen implode$filen"" );
                
$keywords unserialize$filen );
                echo 
"<table border=\"0\" cellpadding=\"0\" ";
                echo 
"cellspacing=\"0\" width=\"100%\" >";
                echo 
"<tr bgcolor=\"#FFFFEE\"><td><b>";
                echo 
"<a href=\"sitemap.php\">Nr";

                if ( ! 
_RequestData"sort" ) )
                {
                        echo 
"<img src=\"./images/ner.gif\" ";
                        echo 
"width=\"10\" height=\"10\" border=\"0\">";
                }
                else
                {
                        echo 
"<img src=\"./images/tom.gif\" ";
                        echo 
"width=\"10\" height=\"10\" border=\"0\">";
                }
                echo 
"</a></b></td><td>";

                echo 
"<b><a href=\"sitemap.php?sort=heading\">Rubrik";

                if ( 
_RequestData"sort" ) == "heading" )
                {
                        echo 
"<img src=\"./images/ner.gif\" ";
                        echo 
"width=\"10\" height=\"10\" border=\"0\">";
                }
                else
                {
                        echo 
"<img src=\"./images/tom.gif\" ";
                        echo 
"width=\"10\" height=\"10\" border=\"0\">";
                }
                echo 
"</a></b></td>";
                echo 
"<td><b><a href=\"sitemap.php?sort=files\">Filnamn";

                if ( 
_RequestData"sort" ) == "files" )
                {
                        echo 
"<img src=\"./images/ner.gif\" ";
                        echo 
"width=\"10\" height=\"10\" border=\"0\">";
                }
                else
                {
                        echo 
"<img src=\"./images/tom.gif\" ";
                        echo 
"width=\"10\" height=\"10\" border=\"0\">";
                }

                echo 
"</a></b></td>";
                echo 
"<td><b><a href=\"sitemap.php?sort=date\">&Auml;ndrad";

                if ( 
_RequestData"sort" ) == "date" )
                {
                        echo 
"<img src=\"./images/ner.gif\" ";
                        echo 
"width=\"10\" height=\"10\" border=\"0\">";
                }
                else
                {
                        echo 
"<img src=\"./images/tom.gif\" ";
                        echo 
"width=\"10\" height=\"10\" border=\"0\">";
                }
                echo 
"</a></b></td></tr>";
                
$r 1;
                for ( 
$row 1$row $this->count$row++ )
                {
                        if ( 
$this->GetNthUrl$row ) != "" )
                        {
                                if ( 
_RequestData("sort") == "date" )
                                {
                                        
$files[$row] = $this->ShowFileAIS($this->GetNthUrl$row ));
                                }
                                elseif ( 
_RequestData("sort") == "files" )
                                {
                                        
$files[$row] = $this->GetNthUrl$row );
                                }
                                elseif ( 
_RequestData("sort") == "heading" )
                                {
                                        
$files[$row] = $this->theTextRaw$row );
                                }
                                else {
                                        
$files[$row] = $this->GetNthUrl$row );
                                }
                        }
                }
                if ( 
_RequestData"sort" ) == "date" )
                {
                        
arsort($files);
                }
                elseif ( 
_RequestData"sort" ) == "files" )
                {
                        
asort($files);
                }
                elseif ( 
_RequestData"sort" ) == "heading" )
                {
                        
asort($files);
                }
                else
                {
                        
//asort($files);
                
}
                
$r 1;
                foreach ( 
$files as $row=>$date )
                {
                        if ( 
$r == )
                                
$c "#FFFFFF";
                        else
                                
$c "#F7F7F7";
                        if ( 
_RequestData"sort" ) )
                        {
                                echo 
"<tr bgcolor=\"" $c "\"><td>"$r "</td><td>\n";
                        }
                        else
                        {
                                echo 
"<tr bgcolor=\"" $c "\"><td>"$r "</td><td>\n";

                        }
                        echo 
"<a href=\"" $this->GetNthURL$row ) . "\"" ;
                        if ( @ 
count ($keywords$this->GetNthUrl$row ) ]) > )
                        {
                                
$title "";
                                
$tt $keywords$this->GetNthUrl$row ) ];
                                foreach( 
$tt as $data)
                                        
$title .= $data "\n";
                                echo 
" title=\"" trim$title ) . "\"";
                        }
                        echo 
">\n";
                        if ( ! 
_RequestData"sort" ) )
                                echo 
$this->TheTextAutoNum$row );
                        else
                                echo 
$this->TheText$row );
                        echo 
"</a>\n";
                        echo 
"</td><td>\n";
                        echo 
$this->GetNthURL$row );
                        echo 
"</td><td>\n";
                        if (
$this->GetNthUrl$row ) != "" )
                                echo 
$this->ShowFileAccessInfo$this->GetNthUrl$row ) );

                        echo 
"</td></tr>\n";
                        
$r++;
                }
                
$r--;
                echo 
"<tr><td>&nbsp;</td><td colspan=\"7\">";
                echo 
"Antal filer: <b>$r</b></td></tr>";
                echo 
"</table>";
        }

        
# filens modifikationstid
        
function ShowFileAccessInfo$f )
        {
                
$realFile dirname_ServerData"PATH_TRANSLATED" ) ) .
                                        
"/" basename$f ) ;
                return 
date"d.m.y H:i"filemtime $realFile ) );
        }

        
# samma fast YYYYMMDD som är enklare att sortera
        
function ShowFileAIS$f )
        {
                
$realFile dirname_ServerData"PATH_TRANSLATED" ) ) .
                                        
"/" basename$f ) ;
                return 
date"ymdhi"filemtime $realFile ) );
        }

        
# plockar ut body delen ur filerna (för sökning och nyckelord)
        
function GetBody$filename )
        {
                if ( !
file_exists$filename ) )
                {
                        echo 
"$filename does not exist";
                        exit;
                }

                
$fd fopen $this->toUrl$filename ), "r" );
        
$contents "";
        while (!
feof ($fd)) {
                    
$contents .= fgets($fd4096);
                }


        
# echo htmlentities( $contents );
                
fclose ($fd);
                
$reg_b '/<!--\s*#BeginEditable\s*\"body\"\s*-->';
                
$reg_b .= '([\w\W])';
                
$reg_b .= '<!--\s*#EndEditable\s*-->/';
                if ( 
preg_match$reg_b$contents$matches ) )
                {
                        return 
$matches];

                }
                else
                {
                        
$b "<!-- #BeginEditable \"body\" -->";
                        
$e "<!-- #EndEditable -->";
                        
$start strpos$contents$b ) + strlen$b );
                        
$stop strpos$contents$e ) - $start;

                }
                return 
substr$contents$start$stop );
        }

        
# sparar body delen
        
function SaveBody$text$filename )
        {
                
$back"&auml;" ] = "ä";
                
$back"&Auml;" ] = "Ä";
                
$back"&ouml;" ] = "ö";
                
$back"&Ouml;" ] = "Ö";
                
$back"&aring;" ] = "å";
                
$back"&Aring;" ] = "Å";
                
$back"<br />" ] = "";
                
$back"&amp;" ] = "&";
                
$back"&lt;" ] = "<";
                
$back"&gt;" ] = ">";
                
$back"&nbsp;" ] = " ";
                
$back"&quot;" ] = "\"";
                
$back"\r\n" ] = " ";
                
$back"\n" ] = " ";
                
$back"\r" ] = " ";

                
$newFile "./body/" .
                                
substr$filename0strrpos$filename"." ) ) . ".php";
                
$fd fopen $newFile"w" );
                
fwrite $fd$text );
                
fclose $fd );

                
$newFile2 "./text/" .
                                
substr$filename0strrpos$filename"." ) ) . ".txt";

                
$fd fopen $newFile2"w" );
                
$tt strip_tags$text );
                foreach ( 
$back as $gammal=>$ny )
                {
                        
$tt str_replace$gammal$ny$tt );
                }
                
$tt preg_replace"/\s\s+/"" "$tt );
                
# for( $i = 0; $i < 10; $i++ )
                # {
                #        $tt = str_replace( "  ", " ", $tt );
                # }
                
fwrite $fdtrim$tt ) );
                
fclose $fd );
                return 
$newFile;
        }

        
# konvertera en relativ path till en absolut URL
        
function toUrl$fileName )
        {
                return 
"http://www.enges.org/phpkurs/" .
                           
$fileName ;
        }

        
# lopa igenom alla filer och preparera för sökning
        
function PrepareBody( )
        {
                
ob_start();
                echo 
"Startar indexeringen<hr>";
                
$newFile "./print.php";
                
$fd fopen $newFile"w+" );
                
fwrite $fd"<head><title>N&auml;gra sidor om PHP (c) anders  enges, 2003</title>" );
                
fwrite $fd"<link rel=\"stylesheet\" ");
                
fwrite $fd" href=\"phpkurs.css\" ");
                
fwrite $fd" type=\"text/css\">" );
                
fwrite $fd"</head><body>" );
                
fwrite $fd'<table width="100%" height="100%"><tr><td align="right" valign="middle" style="font-family:monospace; font-size:28px;">n&aring;gra sidor om php<br />&copy anders enges, v&ouml;r&aring;, 2003</td></tr></table>' );
                
fwrite $fd"<?php include (\"./inc/source.php\" ); ?>\r\n" );
                for ( 
$row 1$row $this->count$row++ )
                {
                        
#ob_flush();
                        
flush();
                        if ( 
$this->GetNthUrl$row ) != ""
                                
&& $this->GetNthUrl$row ) != "seek.php" )
                        {
                                
$fil basename$this->GetNthUrl$row ) );
                                
$bod $this->GetBody$fil );
                                
$fn $this->SaveBody$bod$fil);
                                
fwrite $fd"<div align=\"right\">");
                                
fwrite $fd"<b>" .
                                                
basename$this->GetNthUrl$row ) ) .
                                                
"</b></div>" );

                                
fwrite $fd"<h3>" .
                                                
$this->TheTextAutoNum$row ) .
                                                
"</h3>" );
                                
fwrite $fd"<?php include (\"" $fn "\" ); ?>\r\n" );
                                echo 
"Indexerat : " $fn "<br />";
                                
# plocka ut nyckelorden
                                
$reg_b '/<a\s*name=\s*"([^"]*)"><\s*\/s*a\s*>/i';


                                if ( 
preg_match_all$reg_b$bod$matches ) )
                                {
                                        for (
$i=0$icount$matches] ); $i++)
                                        {
                                                
$keywords[  $matches][ $i ]  ][ ] = basename$fn );
                                                
$keywords2basename$fn ) ][] =
                                                                
preg_replace("/\s+/"" "$matches][ $i ] );
                                                
# echo "<br>" . $matches[ 1][ $i ] ;
                                        
}

                        
uksort$keywords ,"cmp" );
                                
reset$keywords );
                }
                        }
                }


                
fwrite $fd"</body></html>" );
                
fclose $fd );
                
$fd fopen "./text/keywords.txt""w+" );
                
fwrite $fdserialize$keywords ) );
                
fclose $fd );
                
$fd fopen "./text/keywords2.txt""w+" );
                
fwrite $fdserialize$keywords2 ) );
                
fclose $fd );
                
# echo "<a href=\"print.php\">Print</a>";
                
echo "Indexeringen klar";
        }

        
# lista med extraherade nyckelord
        
function putAllKeywords( )
        {
                
$filen file"./text/keywords.txt" );
                
# kommer som en array - så jag föser ihop den
                
$filen implode$filen"" );
                
$keywords unserialize$filen );
                echo 
"<table width=\"100%\" cellspacing=\"0\" ";
                echo 
" cellpadding=\"1\">\n";
                echo 
"<tr bgcolor=\"#F0F0F0\"><td><b>";
                echo 
"Nyckelord</b></td><td><b>Fil</b></td></tr>\n";
                
$annan false;
                foreach( 
$keywords as $k=>$f )
                {
                        if ( 
$annan )
                                echo 
"<tr bgcolor=\"#F5F5F5\">";
                        else
                                echo 
"<tr bgcolor=\"#FFFFFF\">";
                        echo 
"<td>$k</td><td>";
                        foreach( 
$f as $ff )
                                echo 
"<a href=\"$ff#$k\">[$ff]</a>&nbsp;&nbsp;";
                        echo 
"</td></tr>\n";
                        
$annan = ! $annan;
                }
                echo 
"</table>";
        }

        
# sökfunktionen
        
function mySearch$sök )
        {
                echo 
"<table border=\"0\" cellpadding=\"0\" ";
                echo 
"cellspacing=\"0\" width=\"100%\" >";
                
$hit 0;
                for ( 
$row 1$row $this->count$row++ )
                {
                        if ( 
$this->GetNthUrl$row ) != "" &&
                                        
$this->GetNthUrl$row ) != "seek.php" )
                        {
                                
$fil basename$this->GetNthUrl$row ) );
                                
$fil "./text/" substr$fil0strrpos$fil".") ) . ".txt";

                                
$fd = @fopen $fil"r" );
                                if ( ! 
$fd )
                                {
                                        echo 
"<b>OOPS!</b> Jag har tydligen gl&ouml;mt att indexera s&ouml;kmaskineriet efter att ha gjort &auml;ndringar<br>";
                                        echo 
"<a href=\"prep.php\">[ Klicka h&auml;r f&ouml;r att g&ouml;ra det &aring;t mig - tack ]</a><br /><br />\n";
                                        echo 
"</table>";
                                        return;
                                }
                                
$contents fread ($fdfilesize ($fil));
                                
$contents strip_tags($contents);
                                
fclose $fd );
                                if ( 
_RequestData"typ" ) )
                                        
$myseek "/\b" $sök "\b/i";
                                else
                                        
$myseek "/" $sök "/i";
                                if( 
preg_match$myseek ,$contents$matches) )
                                {
                                        
$hit++;
                                        
$po strpos$contents$matches] );
                                        
$co substr$contents,$po-1080 );
                                        
$co strip_tags$co );
                                        echo 
"<tr><td>"$hit "</td><td><a href=\"" .
                                                
$this->GetNthUrl$row ) . "\">" .
                                                
$this->TheTitle$row ) .
                                                
"</a></td><td>";
                                        echo 
basename$this->GetNthUrl$row ) ) .
                                                
"</td><td>" .
                                                
$this->ShowFileAccessInfo$this->GetNthUrl$row ) ).
                                                
"</tr>" ;

                                        echo 
"<tr><td>&nbsp;</td><td colspan=\"3\">" .
                                                         
$co  .
                                                        
"<br><br></td></tr>";
                                }
                        }
                }

                if ( 
$hit == )
                        echo 
"<tr><td>Kunde inte hitta något som matchade '<b>" .
                                        
$sök .
                                        
"</b>'</td></tr>";
                echo 
"</table>";
        }

        
# stt en simpel counter
        
function PutCounter()
        {
                if ( 
substr$_SERVER["HTTP_USER_AGENT"],0,3) == "PHP" )
                        return;
                echo 
"<hr size=\"1\" width=\"40%\" align=\"right\">";
                echo 
"<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";
                
# Jag använder en lätt modifierad TScounter 3.0
                #                by Thomas Schuster
                #                http://www.TSinter.net
                
include_once( dirname__FILE__ ) . "/class_counter.php" );

                
$counter = new TScounter$_SERVER["REMOTE_ADDR"], @ $_COOKIE["PHPSESSID"] );
                
$visitorLogged $counter->_logVisitors();
                
$v $this->formatCounterNo($counter->visitors);
                
$p $this->formatCounterNo($counter->pageImpressions);
                
$t $this->formatCounterNo($counter->thisPageImpressions);

                
#echo "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";
                
echo "<tr><td class=\"counter\" align=\"right\">" $v ."&nbsp;</td></tr>";
                echo 
"<tr><td class=\"counter\" align=\"right\">" $t ."&nbsp;</td></tr>";
                echo 
"<tr><td class=\"counter\" align=\"right\">" $p "&nbsp;</td></tr>";

                
#echo "<tr><td class=\"counter\" align=\"right\"><hr size=\"1\" width=\"92%\" align=\"right\"></td></tr>";
                
echo "</table>";
        }
        function 
PutShowSource()
        {
                        echo 
"<a href=\"./inc/code.php?source=" .
                                        
basename($_SERVER["PHP_SELF"]) .
                                        
"\"><img alt=\"Visa k&auml;llkoden\" src=\"./images/source.gif\" border=\"0\" hspace=\"4\"></a>";
        }
        function 
formatCounterNo$number )
        {
                return 
number_format($number,  0","" ") ;
        }
}

# hjälpfunktin för uksort sorteringen
function cmp $a$b )
{
        
$a strtolower$a );
        
$b strtolower$b );
        if (
$a == $b) return 0;
        return ( 
$a $b ) ? : -1;
}
# bara nåt tjafs
$currentCount  =0;
$countDate 0;

function 
count_it( )
{
    return 
0;
    
$rs "";
    if ( !isset( 
$_SESSION"counted" ] )  && !isset( $_COOKIE["NoCount"] ) )
    {
        
$viewss file"./count/counterlog.txt" );
        
$views $viewss[0];
        
$views++;
        
$_SESSION"counted" ] = $views;
        
$fp fopen("./count/counterlog.txt""w");
        
fwrite($fp$views);
        
fclose($fp);
        return 
$views ;
    }
    else
    {
        
$viewss file("./count/counterlog.txt");
        
$views $viewss];
        return 
$views ;
    }
}

?>
Listning 5.2.1.1 - inc/links.php

   Sidokarta mm.Källkoderlinks.php