|
|
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 ?
1 :
$this->currInd + 1 ;
if ( trim( $this->GetNthURL( $this->nextInd ) ) == "" )
{
$this->nextInd = $this->nextInd == $this->count ?
1 :
$this->nextInd + 1 ;
}
$this->prevInd = $this->currInd == 1 ?
$this->count :
$this->currInd - 1 ;
if ( trim( $this->GetNthURL( $this->prevInd ) ) == "" )
{
$this->prevInd = $this->prevInd == 1 ?
$this->count :
$this->prevInd - 1 ;
}
$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 ( trim( strtolower( substr( $line, 0, strpos( $line, "\t" ) ) ) )
== $curr )
{
$retval = $line_num + 1;
break;
}
}
reset( $this->fcontents );
return $retval;
}
function GetNthUrl( $rowNo )
{
if ( $rowNo <= count( $this->fcontents ) && $rowNo > 0 )
{
$theValue = $this->fcontents[ $rowNo -1 ];
return trim( substr( $theValue, 0, strpos( $theValue, "\t" ) ) );
}
else
{
return "N/A";
}
}
function GetNthDescription( $rowNo )
{
if ( $rowNo <= count( $this->fcontents ) && $rowNo > 0 )
{
$theValue = $this->fcontents[ $rowNo -1 ];
return htmlentities( substr( $theValue, strpos( $theValue, "\t" ) ) );
}
else
{
return "N/A";
}
}
function GetNthDescriptionRaw( $rowNo )
{
if ( $rowNo <= count( $this->fcontents ) && $rowNo > 0 )
{
$theValue = $this->fcontents[ $rowNo -1 ];
return substr( $theValue, strpos( $theValue, "\t" ) );
}
else
{
return "N/A";
}
}
function GetCurUrl( )
{
$theValue = $this->fcontents[ $this->currInd -1 ];
return trim( substr( $theValue, 0, strpos( $theValue, "\t" ) ) );
}
function GetNextUrl( )
{
$theValue = $this->fcontents[ $this->nextInd ];
return trim( substr( $theValue, 0, strpos( $theValue, "\t" ) ) );
}
function GetPrevUrl( )
{
$theValue = $this->fcontents[ $this->prevInd ];
return trim( substr( $theValue, 0, strpos( $theValue, "\t" ) ) );
}
function GetCurDescription( )
{
$theValue = $this->fcontents[ $this->currInd ];
return htmlentities( substr( $theValue, strpos( $theValue, "\t" ) ) );
}
function GetNextDescription( )
{
$theValue = $this->fcontents[ $this->nextInd ];
return htmlentities( substr( $theValue, strpos( $theValue, "\t" ) ) );
}
function GetPrevDescription( )
{
$theValue = $this->fcontents[ $this->prevInd ];
return htmlentities( substr( $theValue, strpos( $theValue, "\t" ) ) );
}
function GetListCount( )
{
return count( $this->fcontents ) + 1;
}
function autoNum( $rowNo )
{
if( $this->currLev == 1 )
{
return $this->lastCurrInd1Count;
}
elseif( $this->currLev == 2 )
{
return $this->lastCurrInd1Count .
"." .
($this->lastCurrInd2Count);
}
elseif( $this->currLev == 3 )
{
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 = split( '[|]', $description );
if ( count( $MyArray ) > 2 )
{
return trim( $MyArray[ 2 ] );
}
else
{
return $this->theText( $rowNo );
}
}
function theText( $rowNo )
{
$description = $this->GetNthDescription( $rowNo );
$MyArray = split( '[|]', $description );
if ( count( $MyArray) > 1 )
{
return trim( $MyArray[ 1 ] );
}
else
{
return "";
}
}
function theTextAutoNum( $rowNo )
{
static $c1, $c2, $c3;
if( $this->theLevel( $rowNo ) == 1 )
{
$c2 = 0;
$c3 = 0;
return ++$c1 . " " . $this->theText( $rowNo ) ;
}
if( $this->theLevel( $rowNo ) == 2 )
{
$c3 = 0;
return $c1 . "." . ++$c2 . " " . $this->theText( $rowNo ) ;
}
elseif( $this->theLevel( $rowNo ) == 3 )
{
return $c1 . "." . $c2 . "." . ++$c3 . " " . $this->theText( $rowNo );
}
}
function theTextRaw( $rowNo )
{
$description = $this->GetNthDescriptionRaw( $rowNo );
$MyArray = split( '[|]', $description );
if (count( $MyArray) > 1 )
{
return trim( $MyArray[ 1 ] );
}
else
{
return "";
}
}
function theLevel( $rowNo )
{
$description = $this->GetNthDescription( $rowNo );
$MyArray = split( '[|]', $description );
return trim( $MyArray[ 0 ] );
}
# 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 == 1 && $row <= $count )
{
$this->lastCurrInd1 = $row ;
$this->lastCurrInd1Count++;
$this->lastCurrInd2Count = 0;
$this->lastCurrInd3Count = 0;
}
if ( $level == 2 && $row <= $count )
{
$this->lastCurrInd2 = $row ;
if ( trim ( $this->getNthURL( $row ) ) != "" )
$this->lastCurrInd2Count++;
$this->lastCurrInd3Count = 0;
}
if ( $level == 3 && $row <= $count )
{
$this->lastCurrInd3 = $row ;
if ( trim ( $this->getNthURL( $row ) ) != "" )
$this->lastCurrInd3Count++;
}
if ( $level == 4 && $row <= $count )
{
$this->lastCurrInd4 = $row ;
}
if ( $level == 5 && $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 > 1 && $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 > 2 && $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 > 3 && $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 = 1 ; $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 ) == 2 )
{
if ($I < $this->count && $this->theLevel( $I + 1 ) > 2)
{
$e = "<font size=\"1\" color=\"#BBBBBB\">></font>";
}
else
$e = " ";
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\"> </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 ) == 1 )
{
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+1 ) > 2)
{
for ($row = $this->lastCurrInd2+1; $row <= $this->count ; $row++)
{
$curLev = $this->thelevel( $row );
if ( $curLev < 5 || $row == $this->lastCurrInd2 )
{
if (
&
|