I am using simple PHP language so that anyone with a basic knowledge of PHP can follow the logic.
Code: Select all
$zip = new ZipArchive;
if ($zip->open('fhfiles.zip') === TRUE) {
//unzip
$zip->extractTo('./');
$zip->close();
//process index.html
//- modify links
$targetIndex = $_SERVER['DOCUMENT_ROOT'] . "/fhfiles/index.html";
$homepage = file_get_contents($targetIndex);
$homepage = str_ireplace("_nameindex.html","/fhsearch.php", $homepage);
if (stripos($homepage, "/fhfiles/index.html")===false) {
$homepage = str_ireplace("index.html","/fhfiles/index.html", $homepage);
}
$homepage = str_ireplace("fhsearch.php\">Index</a>","fhsearch.php\">Search</a>", $homepage);
$saveFile = file_put_contents($targetIndex,$homepage);
//- extract header+menu from index.html. Save as fhheader.bin. For fhwebeditor.php+fhsearch.php+new created pages as header+menu. Need to add <!--[endmenu]--> in "below menu" in configuration in Family Historian.
$findStop = stripos($homepage, "<!--[endmenu]-->")+17;
$findHeader = substr($homepage,0,$findStop);
if (stripos($findHeader, "/fhfiles/fhstyle.css")===false) {
$findHeader = str_ireplace("fhstyle.css","/fhfiles/fhstyle.css", $findHeader);
}
if (stripos($findHeader, "/fhfiles/lytebox.js")===false) {
$findHeader = str_ireplace("lytebox.js","/fhfiles/lytebox.js", $findHeader);
}
if (stripos($findHeader, "/fhfiles/lytebox.css")===false) {
$findHeader = str_ireplace("lytebox.css","/fhfiles/lytebox.css", $findHeader);
}
if (stripos($findHeader, "/fhfiles/_contact.html")===false) {
$findHeader = str_ireplace("_contact.html","/fhfiles/_contact.html", $findHeader);
}
if (stripos($findHeader, "/fhfiles/_statistics.html")===false) {
$findHeader = str_ireplace("_statistics.html","/fhfiles/_statistics.html", $findHeader);
}
if (stripos($findHeader, "/fhfiles/_torindex.html")===false) {
$findHeader = str_ireplace("_torindex.html","/fhfiles/_torindex.html", $findHeader);
}
if (stripos($findHeader, "/fhfiles/logo.jpg")===false) {
$findHeader = str_ireplace("logo.jpg","/fhfiles/logo.jpg", $findHeader);
}
$targetIndex = $_SERVER['DOCUMENT_ROOT'] . "/fhheader.bin";
$saveFile = file_put_contents($targetIndex,$findHeader);
echo $findHeader;
//- copy the original index.html as familyhistorian.html as template in fhuploads directory. Need to add <!--[endpage]--> in "end of Body" in configuration in Family Historian.
$targetFHuploadIndex = $_SERVER['DOCUMENT_ROOT'] . "/fhuploads/familyhistorian.html";
$findStart = stripos($homepage, "<!--[endmenu]-->")+16;
$findStop = stripos($homepage, "<!--[endpage]-->")-1;
$findLen = $findStop - $findStart;
$findIndexContent = substr($homepage,$findStart,$findLen);
//need to replace single quotes as HTML coding. Remove line breaks and line feeds so Javascript variables and Form $_POST works without problems.
$findIndexContent = str_ireplace("\n","", $findIndexContent);
$findIndexContent = str_ireplace("\r","", $findIndexContent);
$findIndexContent = str_ireplace("'","'", $findIndexContent);
$saveFile = file_put_contents($targetFHuploadIndex,$findIndexContent);
fclose($homepage);
//process _contact.html if exist
$targetIndex = $_SERVER['DOCUMENT_ROOT'] . "/fhfiles/_contact.html";
if (file_exists($targetIndex)) {
$homepage = file_get_contents($targetIndex);
$homepage = str_ireplace("_nameindex.html","/fhsearch.php", $homepage);
if (stripos($homepage, "/fhfiles/index.html")===false) {
$homepage = str_ireplace("index.html","/fhfiles/index.html", $homepage);
}
if (stripos($homepage, "/fhfiles/_contact.html")===false) {
$homepage = str_ireplace("_contact.html","/fhfiles/_contact.html", $homepage);
}
if (stripos($homepage, "/fhfiles/logo.jpg")===false) {
$homepage = str_ireplace("logo.jpg","/fhfiles/logo.jpg", $homepage);
}
$homepage = str_ireplace("fhsearch.php\">Index</a>","fhsearch.php\">Search</a>", $homepage);
$saveFile = file_put_contents($targetIndex,$homepage);
fclose($homepage);
}
//process _statistics.html if exist
$targetIndex = $_SERVER['DOCUMENT_ROOT'] . "/fhfiles/_statistics.html";
if (file_exists($targetIndex)) {
$homepage = file_get_contents($targetIndex);
$homepage = str_ireplace("_nameindex.html","/fhsearch.php", $homepage);
if (stripos($homepage, "/fhfiles/index.html")===false) {
$homepage = str_ireplace("index.html","/fhfiles/index.html", $homepage);
}
if (stripos($homepage, "/fhfiles/_statistics.html")===false) {
$homepage = str_ireplace("_statistics.html","/fhfiles/_statistics.html", $homepage);
}
if (stripos($homepage, "/fhfiles/logo.jpg")===false) {
$homepage = str_ireplace("logo.jpg","/fhfiles/logo.jpg", homepage);
}
$homepage = str_ireplace("fhsearch.php\">Index</a>","fhsearch.php\">Search</a>", $homepage);
$saveFile = file_put_contents($targetIndex,$homepage);
fclose($homepage);
}
//process _torindex.html if exist
$targetIndex = $_SERVER['DOCUMENT_ROOT'] . "/fhfiles/_torindex.html";
if (file_exists($targetIndex)) {
$homepage = file_get_contents($targetIndex);
$homepage = str_ireplace("_nameindex.html","/fhsearch.php", $homepage);
if (stripos($homepage, "/fhfiles/index.html")===false) {
$homepage = str_ireplace("index.html","/fhfiles/index.html", $homepage);
}
if (stripos($homepage, "/fhfiles/_torindex.html")===false) {
$homepage = str_ireplace("_torindex.html","/fhfiles/_torindex.html", $homepage);
}
if (stripos($homepage, "/fhfiles/logo.jpg")===false) {
$homepage = str_ireplace("logo.jpg","/fhfiles/logo.jpg", $$homepage);
}
$homepage = str_ireplace("fhsearch.php\">Index</a>","fhsearch.php\">Search</a>", $homepage);
$saveFile = file_put_contents($targetIndex,$homepage);
fclose($homepage);
}
} else {
echo 'Unzipped Process failed';
}