<?php // $Id: newfunctions.php,v 1.11 2002/01/29 10:13:01 micha Exp $
// ----------------------------------------------------------------------
// BOOKS module
// Copyright (C) 2001, 2002 by IB Rahn, http://www.ib-rahn.de
// Written by Michael Schatz, hide@address.com
// get the newest version at http://www.bauphysik.com
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
/*--------------------------------------------------------------------------
* function FormatDate
*--------------------------------------------------------------------------
* purpose format a date for output
* input $aformat : date time formatstring for strfdat()
* $adatetime : datetimestring to format
* output formatted datetime string
* changes 2001-09-24 [MS] introduced this service function
*--------------------------------------------------------------------------*/
function FormatDateTime($aformat, $adatetime) {
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $adatetime, $tmpdate);
ereg ("([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $adatetime, $tmptime);
return strftime($aformat, mktime($tmptime[1],$tmptime[2],$tmptime[3],$tmpdate[2],$tmpdate[3],$tmpdate[1]));
}
/*--------------------------------------------------------------------------
* function DBDate2TimeStamp
*--------------------------------------------------------------------------
* purpose convert a date from nuke-db to timestamp
* input $dbdate = "yyyy-mm-dd hh:mm:ss"
* output unix timestamp
* changes 2001-11-08 [MS] introduced
*--------------------------------------------------------------------------*/
function DBDate2TimeStamp($dbdate) {
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $dbdate, $tmp);
return mktime($tmp[4],$tmp[5],$tmp[6],$tmp[2],$tmp[3],$tmp[1]);
}
/*--------------------------------------------------------------------------
* function detect_browser
*--------------------------------------------------------------------------
* purpose Detect which is the user browser
* input -
* output globals
* changes 2001-11-06 [MS] taken from de.php.net,
* posting by hide@address.com;
* 2001-11-07 [MS] fixed missing blank for MSIE;
* added support for Mozilla;
*--------------------------------------------------------------------------*/
/* setting global vars */
global $HTTP_USER_AGENT, $BName, $BVersion, $BPlatform;
/* the function itself */
function detect_browser() {
global $HTTP_USER_AGENT, $BName, $BVersion, $BPlatform;
// ---- Browser ----
if (eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}",$HTTP_USER_AGENT,$match) || eregi("(opera/)([0-9]{1,2}.[0-9]{1,3}){0,1}",$HTTP_USER_AGENT,$match)) {
$BName = "Opera"; $BVersion=$match[2];
} elseif (eregi("(konqueror)/([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) {
$BName = "Konqueror"; $BVersion=$match[2];
} elseif (eregi("(lynx)/([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})",$HTTP_USER_AGENT,$match)) {
$BName = "Lynx"; $BVersion=$match[2];
} elseif (eregi("(links)\(([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) {
$BName = "Links"; $BVersion=$match[2];
} elseif (eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) {
$BName = "MSIE"; $BVersion=$match[2];
} elseif (eregi("(netscape6)/(6.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) {
$BName = "Netscape"; $BVersion=$match[2];
} elseif (eregi("(mozilla/5)(.* rv:)([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) {
$BName = "Mozilla"; $BVersion=$match[3];
} elseif (eregi("(mozilla)/([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) {
$BName = "Netscape"; $BVersion=$match[2];
} elseif (eregi("w3m",$HTTP_USER_AGENT)) {
$BName = "w3m"; $BVersion=0;
} else {
$BName = "Unknown"; $BVersion=0;
}
// ---- System ----
if (eregi("linux",$HTTP_USER_AGENT)) {
$BPlatform = "Linux";
} elseif (eregi("win32",$HTTP_USER_AGENT)) {
$BPlatform = "Windows";
} elseif ((eregi("(win)([0-9]{2})",$HTTP_USER_AGENT,$match)) || (eregi("(windows) ([0-9]{2})",$HTTP_USER_AGENT,$match))) {
$BPlatform = "Windows $match[2]";
} elseif (eregi("(winnt)([0-9]{1,2}.[0-9]{1,2}){0,1}",$HTTP_USER_AGENT,$match)) {
$BPlatform = "Windows NT $match[2]";
} elseif (eregi("(windows nt)(){0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}",$HTTP_USER_AGENT,$match)) {
$BPlatform = "Windows NT $match[3]";
} elseif (eregi("mac",$HTTP_USER_AGENT)) {
$BPlatform = "Macintosh";
} elseif (eregi("(sunos) ([0-9]{1,2}.[0-9]{1,2}){0,1}",$HTTP_USER_AGENT,$match)) {
$BPlatform = "SunOS $match[2]";
} elseif (eregi("(beos) r([0-9]{1,2}.[0-9]{1,2}){0,1}",$HTTP_USER_AGENT,$match)) {
$BPlatform = "BeOS $match[2]";
} elseif (eregi("freebsd",$HTTP_USER_AGENT)) {
$BPlatform = "FreeBSD";
} elseif (eregi("openbsd",$HTTP_USER_AGENT)) {
$BPlatform = "OpenBSD";
} elseif (eregi("irix",$HTTP_USER_AGENT)) {
$BPlatform = "IRIX";
} elseif (eregi("os/2",$HTTP_USER_AGENT)) {
$BPlatform = "OS/2";
} elseif (eregi("plan9",$HTTP_USER_AGENT)) {
$BPlatform = "Plan9";
} elseif(eregi("unix",$HTTP_USER_AGENT) || eregi("hp-ux",$HTTP_USER_AGENT)) {
$BPlatform = "Unix";
} elseif (eregi("osf",$HTTP_USER_AGENT)) {
$BPlatform = "OSF";
} else {
$BPlatform = "Unknown";
}
}
/*--------------------------------------------------------------------------
* function modules_settings_enh
*--------------------------------------------------------------------------
* purpose set module helper variables
* input $modulename
* $index
* output record
* changes 2001-12-14 [MS] taken from mainfile.php to be standard compliant
* added baseurl3
* 2002-01-14 [MS] added adminpath
*--------------------------------------------------------------------------*/
function modules_settings_enh($modulename, $index = false)
{
// if (!eregi('modules.php', $GLOBALS[PHP_SELF])){die ("You can't access this file directly...");}
$out[ModName] = $modulename;
$out[baseurl] = "modules.php?op=modload&name=$modulename&file=index";
$out[baseurl2] = "modules.php?op=modload&name=$modulename&file=index";
$out[baseurl3] = "modules.php?op=modload&name=$modulename&file=";
$out[basepath] = "modules/$modulename";
$out[adminpath] = "modules/$modulename/admin/modules";
$out[imagepath] = "modules/$modulename/images";
$out[vars] = array_merge($GLOBALS[HTTP_GET_VARS], $GLOBALS[HTTP_POST_VARS]);
$out[index] = $index;
return $out;
}
/*--------------------------------------------------------------------------
* function imgNewGraphic
*--------------------------------------------------------------------------
* purpose Show a "new" image, when $adate is less than 7 days
* input $adate a date
* $atyp adate format: 0 - yyyy-mm-dd
1 - dd. mmm yyyy - hh:mm
* output -
* changes 2002-01-22 [MS] taken from books-module
*--------------------------------------------------------------------------*/
function imgNewGraphic($adate,$atyp=0) {
global $modset;
setlocale ("LC_TIME", "$locale");
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $adate, $tmpdate);
$thisdate = date("d-M-Y",mktime(0,0,0,$tmpdate[2],$tmpdate[3],$tmpdate[1]));
$startdate = time();
$count = 0;
while ($count <= 7) {
$daysold = date("d-M-Y", $startdate);
if ("$daysold" == "$thisdate") {
if ($count<=1) {
echo " <img src=\"images/common/newred.gif\" alt=\""._NEWTODAY."\" border=\"0\"> ";
}
if ($count<=3 && $count>1) {
echo " <img src=\"images/common/newgreen.gif\" alt=\""._LAST3DAYS."\" border=\"0\"> ";
}
if ($count<=7 && $count>3) {
echo " <img src=\"images/common/newblue.gif\" alt=\""._THISWEEK."\" border=\"0\"> ";
}
}
$count++;
$startdate = (time()-(86400 * $count));
}
} // end imgNewGraphic
/*--------------------------------------------------------------------------
* function CheckImgFile
*--------------------------------------------------------------------------
* purpose Check, if file $afile exists. Return valid imagepath.
* input $afile file to check. may be an url
* $default default if file is not found
* output valid imagepath
* changes 2002-01-22 [MS] introduced
* 2002-01-28 [MS] moved to newfunctions.php. Added $default.
* 2002-01-29 [MS] totally changed, due to performance problems
*--------------------------------------------------------------------------*/
function CheckImgFile($afile='', $default='') {
/***** this is much to slow. shall be rivised in the near future
global $nukeurl;
if ($afile > '!') { // there is something ...
if (strpos($afile,'http')===false) { // must be local ...
if (file_exists($afile)) return $afile;
$checkfile = $nukeurl.$afile;
} else { // $afile probably a url
$checkfile = $afile;
}
$fp = @fopen($checkfile,"r"); // try to reach url
if (!$fp) return $default;
else {
@fclose($fp);
return $afile;
}
} else {
return $default;
}
*****/
if ($afile > '!') {
return $afile;
} else {
return $default;
}
}
/************************************************************************/
/* Initialization */
/************************************************************************/
detect_browser(); // set global vars for browser
?>