<?php
//
// phpWebDesk include file
//
// for HTML, WML and similar languages at the moment.
//
// Simply include at the TOP of your page and it'll convert all the images, markup
// etc.
//
# include the functions
require_once "functions.inc.php";
# include the config page
require_once "config.inc.php";
# Find out the page's filename
$if = $root_folder.$HTTP_SERVER_VARS['PHP_SELF'];
# Get the page
$content = file_get_contents($if);
# Cycle through HTML & WML <img> tags and direct them to the image converter
$content=stri_replace("<img src=\"", "<img src=\"convert_img.php?mode=".$imgmode."&if=", $content);
$content=stri_replace("<img src='", "<img src='convert_img.php?mode=".$imgmode."&if=", $content);
# Cycle through links to downloadable files and redirect them to the compresser
$filepos = 0;
while(stristr(substr($content, $filepos), "<a")) {
$compressit = false;
$nextbitpos = stripos(substr($content, $filepos), "<a");
$nextbit = stristr(substr($content, $filepos), "<a");
# See if we have a correct extension in there...
$end = stripos($nextbit, ">")+1;
$linkbit = substr($nextbit, 0, $end);
foreach($exts2cp as $ext2cp) {
if(stristr($linkbit, $ext2cp)) { $compressit = true;}
}
foreach($exts2ovrcp as $ext2ovrcp) {
if(stristr($linkbit, $ext2ovrcp)) { $compressit = false;}
}
if ($compressit) {
$startofhref = stripos($linkbit, "href=\"")+6;
if($startofhref===FALSE) { $startofhref = stripos($linkbit, "href='")+6;}
$splitpoint = $filepos+$nextbitpos+$startofhref;
$pieces = array(substr($content, 0, $splitpoint), "compress_f.php?filename=", substr($content, $splitpoint));
$content = join("", $pieces);
}
$filepos = ($filepos+$nextbitpos+$end);
}
// Take out any PHP code in there
while(strstr($content,"<?php")) {
$start=strpos($content, "<?php");
$end=strpos($content, "?".">")+2;
$tochop=substr($content, $start, ($end-$start));
$content = str_replace($tochop, "", $content);
}
# Find out what type of page to cough up. I can't rely on browscap.ini files; many people
# can't (or won't) change them. Here's my detection. Any errors, PLEASE tell me about it.
# Mind you, this file'll probably be more up to date than most people's browscap.ini...
# Grab the user_agent
$bc = $_SERVER['HTTP_USER_AGENT'];
# Do we use browscap.ini or the inbuilt recogniser?
if ($usebrowscap) {
$ba = get_browser();
if ($ba->wap) { $mode=1;} else { $mode=0; }
if ($ba->win16) { $imgmode=1; }
} else {
include "browscap.inc.php";
}
# If we need to, convert page to WML.
if($mode==1) {
include "templates/html2wml.inc.php";
}
// echo the content
echo $content;
// die to prevent the content on the page we're included in being displayed (i.e. repeated)
die();
?>