For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2007 > To Koncept: Followup - How to generate multiple web pages with one









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author To Koncept: Followup - How to generate multiple web pages with one
Maxim Heijndijk

2007-02-13, 7:59 am

Koncept wrote:

> Something like this should work for you. I hope I got the logic correct
> given your specs. I have to admit that I didn't really take a lot of
> time to figure out exactly what you were doing with the shell script:


Well, I now have modified the script so the end and startpages are there
too. Also the script reads the captions and the variables from
includefiles. But I want to simplify my site even more:

At the moment, the directory structure is as follows:

index.html

photo/rroma/index.php
photo/rroma/captions.txt
photo/rroma/vars.inc

photo/travel/spain/index.php
photo/travel/spain/captions.txt
photo/travel/spain/vars.inc

links in index.html point to the index.php files. But the index.php
files are exactly the same, as they read vars and captions from textfiles.

What I want is an index.html with links that point to a single index.php
file. The links in the html file should contain querystrings that will
be passed to the phpscript so that the script knows from which directory
to get the captions and vars. so the structure will look like this:

index.html
index.php

photo/rroma/captions.txt
photo/rroma/vars.inc

photo/travel/spain/captions.txt
photo/travel/spain/vars.inc

How do I do that??

This is the script with include files up to now:

## index.php

<?php

// Read config from file
include("vars.inc");

// Create path structure
$dirPath=str_repeat("../",$dirLevel);


// Get the page request from $_GET
if(isset($_GET['page'])&&is_numeric($_GET['page'])){
$_GP=$_GET['page']>0?$_GET['page']:1;
}else{
$_GP=1;
}


// Assign next, previous and current variables
if($_GP>1&&$_GP<$pages){
list($p,$n,$c)=array($_GP-1,$_GP+1,$_GP);
}elseif($_GP==1){
list($p,$n,$c)=array($pages,2,1);
}elseif($_GP==$pages){
list($p,$n,$c)=array($_GP-1,1,$_GP);
}


// Prefix variables with "0" if value is less than 10
$preName=$p<10?"0{$p}":$p;
$curName=$c<10?"0{$c}":$c;
$nxtName=$n<10?"0{$n}":$n;


// First and last page must point to $startPage
if($startPage!==0&$c==$pages){
$rootDir = dirname($_SERVER['PHP_SELF']);
$next="{$rootDir}/${dirPath}${startPage}";
}else{
$next="{$_SERVER['PHP_SELF']}?page={$n}";
}


if($startPage!==0&$c==1){
$rootDir = dirname($_SERVER['PHP_SELF']);
$prev="{$rootDir}/${dirPath}${startPage}";
}else{
$prev="{$_SERVER['PHP_SELF']}?page={$p}";
}


// Check for the the source image...
if(!is_file($curImg="{$jpgDir}/images/{$curName}.jpg")){
trigger_error("Missing image file $curImg",E_USER_ERROR);
}


// Get image properties
list($x,$y,$type,$attr)=getimagesize($cu
rImg);


// Get the photo caption for this image
$caption=$captions[$c-1];


// Send template to browser
echo <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$generalTitle} - Photo {$curName}</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="15;URL={$next}" />
<meta name="author" content="Fotografie & Webdesign: Maxim
Heijndijk" />
<meta name="copyright" content="Fotografie & Webdesign: Maxim
Heijndijk" />
<link rel="stylesheet" type="text/css" href="{$dirPath}../index.css" />
</head>
<body oncontextmenu="return false">
<table summary="{$generalTitle} - Photo {$curName}" align="center"
cellspacing="0" cellpadding="0" border="0" width="100%" class="caption">
<tr>

<!-- Previous -->
<td align="right" valign="bottom" width="10%">
<a href="{$prev}"><img alt="Previous"
src="{$dirPath}images/prev.gif" border="0" width="22" height="24" /></a>
</td>

<!-- Current -->
<td align="center" valign="bottom" width="80%">
<a href="{$next}"><img alt="{$imgAlt}" src="images/{$curName}.jpg"
border="0" {$attr} /></a>
</td>

<!-- Next -->
<td align="left" valign="bottom" width="10%">
<a href="{$next}"><img alt="Next" src="{$dirPath}images/next.gif"
border="0" width="22" height="24" /></a>
</td>
</tr>
<tr>

<td align="center" nowrap="nowrap" valign="top" width="100%"
height="10%" colspan="3">
<br />{$caption}<br /><br />
</td>
</tr>
</table>

</body>

</html>

HTML;
?>


## captions.txt

MONTSERRAT
MONTSERRAT - Wedding
MONTSERRAT
BARCELONA - Tibidabo
EL MASNOU - Fireworks, Ple de Riure del Masnou


## vars.inc
<?php

$jpgDir = dirname($_SERVER['SCRIPT_FILENAME']);
$subDir = "travel/spain";
$dirLevel = "2";
$generalTitle = "Spain";
$startPage = "travel.html";
$imgAlt = "© Maxim Heijndijk";
$captions = @file("captions.txt");
$pages = "47";

?>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com